2020-03-14 22:30:05 +01:00
|
|
|
/* Copyright © 2020 tyrolyean
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "avr.h"
|
|
|
|
#include "structures.h"
|
|
|
|
#include "16550.h"
|
|
|
|
#include "dac.h"
|
|
|
|
#include "interrupt.h"
|
2020-03-15 01:28:01 +01:00
|
|
|
#include "sound.h"
|
2020-03-15 22:14:50 +01:00
|
|
|
#include "game.h"
|
2020-03-14 22:30:05 +01:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <avr/wdt.h>
|
|
|
|
#include <avr/interrupt.h>
|
|
|
|
|
|
|
|
|
|
|
|
/* Included early on the prevent the watchdog from killing the already killed
|
|
|
|
* microcontroller because of init delay
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint8_t mcusr_mirror __attribute__ ((section (".noinit")));
|
|
|
|
void get_mcusr(void) \
|
|
|
|
__attribute__((naked)) \
|
|
|
|
__attribute__((section(".init3")));
|
|
|
|
|
|
|
|
void get_mcusr(void)
|
|
|
|
{
|
|
|
|
mcusr_mirror = MCUSR;
|
|
|
|
MCUSR = 0;
|
|
|
|
wdt_disable();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Function used to be more complicated, still remains for readability reasons
|
|
|
|
*/
|
|
|
|
|
|
|
|
void set_addr(uint8_t addr){
|
|
|
|
|
|
|
|
ADDR_REG = addr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset_modules(){
|
|
|
|
|
|
|
|
/* Setup Data Direction Registers and populate with sane default
|
|
|
|
values */
|
|
|
|
DATA_DDR_REG = 0xFF; /* Data Bus */
|
|
|
|
ADDR_DDR_REG = 0xFF; /* Address Bus */
|
|
|
|
CTRL_DDR_REG= 0xFF; /* Control Bus */
|
|
|
|
ADDR_REG = 0x00;
|
|
|
|
DATA_REG = 0x00;
|
|
|
|
CTRL_REG = 0x00;
|
|
|
|
|
|
|
|
/* Cleanly reset the dac uart */
|
|
|
|
CTRL_REG |= (1<<WR_SHIFT) | (1<<RD_SHIFT) | (1<<CS_DAC_SHIFT) |
|
|
|
|
(1<<MR_SHIFT) | (1<<CS_UART_SHIFT);
|
|
|
|
|
|
|
|
|
|
|
|
_delay_us(100);
|
|
|
|
CTRL_REG &= ~(1<<MR_SHIFT);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int routine();
|
|
|
|
int main(){
|
|
|
|
/* Disable interrupts during initialisation phase */
|
|
|
|
cli();
|
|
|
|
reset_modules();
|
|
|
|
init_uart();
|
|
|
|
init_interrupts();
|
2020-03-15 22:14:50 +01:00
|
|
|
current_track = computer_room;
|
2020-03-14 22:30:05 +01:00
|
|
|
sei();
|
2020-03-17 16:31:31 +01:00
|
|
|
println(room_table[0]);
|
2020-03-14 22:30:05 +01:00
|
|
|
/* Enable the hardware watchdog. In case the microcontroller fails to
|
|
|
|
* finish it's task within the specified time, the watchdog will reset
|
|
|
|
* the atmel cookie.
|
|
|
|
*/
|
|
|
|
wdt_enable(WDTO_1S);
|
|
|
|
|
|
|
|
while(1){
|
|
|
|
wdt_reset();
|
|
|
|
routine();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int routine(){
|
|
|
|
routine_dac();
|
2020-03-15 22:14:50 +01:00
|
|
|
routine_uart();
|
|
|
|
routine_game();
|
2020-03-14 22:30:05 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|