TK2048/src/main.c
2025-07-17 14:47:57 +02:00

67 lines
1.3 KiB
C

#include <stubs.h>
#include <stdint.h>
#include <string.h>
#include "utility.h"
#include "mem_registers.h"
#include "mem_map.h"
#include "input.h"
#include "game_logic.h"
#include "game_graphics.h"
void __low_level_init(void);
// Low level initialization
void __low_level_init(void) {
POKE(P3_PWRDUP, 0); // Dirty the value checked by the reset vector
PEEK(IO_ROMSEL); // Make sure the ROM is selected
PEEK(IO_DISPLAY_BW); // Disable colors
PEEK(IO_DISPLAY_PAGE1); // Select the first display page
// Clear display memory
memset((void*)DISPLAY_PAGE_1, 0, DISPLAY_PAGE_SIZE);
memset((void*)DISPLAY_PAGE_2, 0, DISPLAY_PAGE_SIZE);
}
__task int main(void) {
game_state state;
while(1){ // Outer loop
reset_game();
draw_game_background();
while(1) { // Game loop
lfsr_update();
switch(read_kb()) {
case K_UP:
state = step_game(UP);
break;
case K_DOWN:
state = step_game(DOWN);
break;
case K_LEFT:
state = step_game(LEFT);
break;
case K_RIGHT:
state = step_game(RIGHT);
break;
default:
continue; // Do nothing, loop again
}
// If we have finished, break out of this loop
if(state.done) break;
// Unable to add a tile. We lost!!!
if(!add_random_tile()) break;
draw_tiles();
}
};
return 0;
}