textadv/src/main.c

113 lines
2.5 KiB
C

/* 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"
#include "sound.h"
#include "game.h"
#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 and the 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();
init_game();
current_track = intro_track;
memset(room_visited_table, 0, NUM_ROOMS);
memset(inventory, 0, NUM_ITEMS);
describe_room(current_room,false);
sei();
/* 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_8S);
while(1){
wdt_reset();
routine();
}
return 0;
}
int routine(){
routine_dac();
routine_uart();
routine_game();
return 0;
}