/* 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 .
*/
#include "avr.h"
#include "structures.h"
#include "16550.h"
#include "dac.h"
#include "interrupt.h"
#include "sound.h"
#include "game.h"
#include
#include
#include
#include
#include
/* 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 and the uart */
CTRL_REG |= (1<