Add initial main loop logic

This commit is contained in:
hkz 2025-07-17 07:54:46 +02:00
commit 5fe7310d14
5 changed files with 38 additions and 10 deletions

View file

@ -24,6 +24,7 @@ all: $(PRG).wav
cc6502 --core=6502 -O2 --list-file=$(@:%.o=obj/%.lst) --char-is-unsigned --pedantic-errors -o obj/$@ $<
$(PRG).hex: $(OBJS)
# (cd obj ; ln6502 -g ../linker-files/linker.scm $^ -o ../out/$@ $(LIBS) -l --cross-reference --cstartup=tk2k --no-automatic-placement-rules --output-format intel-hex --hosted)
(cd obj ; ln6502 -g ../linker-files/linker.scm $^ -o ../out/$@ $(LIBS) -l --cross-reference --cstartup=tk2k --no-automatic-placement-rules --output-format intel-hex)
$(PRG).bin: $(PRG).hex

View file

@ -6,8 +6,10 @@
(memory program (address (#x801 . #x1fff)) (type ram)
(section (programStart #x801) (startup #x80e) code))
(memory displayPage1 (address (#x2000 . #x3fff)) (type ram))
(memory datamem (address (#x4000 . #x91ff)) (type ram) (section idata cdata data_init_table)) ;;; usermem goes from 0x4000 to 0x9FFFF (included), we are splitting it
(memory upperData (address (#x9200 . #x9fff)) (section cstack zdata data heap))
;;; (memory datamem (address (#x4000 . #x91ff)) (type ram) (section cstack zdata heap)) ;;; usermem goes from 0x4000 to 0x9FFFF (included), we are splitting it
;;; (memory upperData (address (#x9200 . #x9fff)) (section switch idata cdata data data_init_table))
(memory datamem (address (#x4000 . #x91ff)) (type ram) (section cstack zdata data heap)) ;;; usermem goes from 0x4000 to 0x9FFFF (included), we are splitting it
(memory upperData (address (#x9200 . #x9fff)) (section switch idata cdata data_init_table))
(memory displayPage2 (address (#xa000 . #xbfff)) (type ram))
(memory io (address (#xc000 . #xc0ff)) (type ram))
(memory rombank (address (#xc100 . #xffff)) (type rom))

View file

@ -83,7 +83,6 @@ game_state step_game(step_direction dir) {
column_step = 1;
row_step = GRID_SIDE;
break;
break;
case RIGHT:
start_offset = GRID_SIDE - 1;
column_step = -1;

View file

@ -6,7 +6,7 @@
#define GRID_SIDE 5
typedef enum {
UP,
UP = 0,
DOWN,
LEFT,
RIGHT

View file

@ -8,6 +8,7 @@
#include "mem_map.h"
#include "input.h"
#include "game_logic.h"
#include "game_graphics.h"
void __low_level_init(void);
@ -25,13 +26,38 @@ void __low_level_init(void) {
}
__task int main(void) {
key k;
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
}
reset_game();
while(1){
lfsr_update();
k = read_kb();
// If we have finished, break out of this loop
if(state.done) break;
add_random_tile();
}
};
return 0;