game_state: game state updates now use the same state machine as actors
authorLukas Krickl <lukas@krickl.dev>
Fri, 28 Mar 2025 13:28:39 +0000 (14:28 +0100)
committerLukas Krickl <lukas@krickl.dev>
Fri, 28 Mar 2025 13:28:39 +0000 (14:28 +0100)
src/defs.s
src/mem.s
src/state.s
src/update.s
src/wram.s

index 6755a593452a787606d1aeb2be24a904b5cdac4e..a8fc737fa80628d359c6cd113c962963196459f1 100644 (file)
 #define WINDOW_Y 120
 #define WINDOW_X 1
 
-  ; game modes
-  ; this is a direct index
-  ; into a pointer array
-  ; for update functions
-.se 0
-.de GM_GAME, 1
-.de GM_PAUSE, 1
-
   ; game state cell struct 
   ; this holds all the information 
   ; a cell on the map has 
index 8136c5b153aa78938d41db54d8d613a742a61ee7..40037ad5ec40006bdf30261b5cd82c1d631ca7d5 100644 (file)
--- a/src/mem.s
+++ b/src/mem.s
@@ -14,13 +14,18 @@ mem_init:
   call memcpy
 
   ; set up game mode 
-  ld a, GM_GAME
-  ld [game_mode], a
+  call game_init 
 
   call mbc1_init
 
   ret
 
+game_init:
+  ld de, st_update_game
+  ld hl, game_mode
+  ld bc, st_size
+  jp memcpy
+
 ; copies memory from one location to another 
 ; inputs:
 ;   de: source
index 8f103dc0d9a3a60812da233fa7191aedaf6160b5..2b3c13618bb56b8202be94e2fc17d3b21a22f01f 100644 (file)
@@ -85,3 +85,12 @@ st_cursor_draw:
   st_def 0x00, player_draw_cursor, st_cursor
 st_cursor_delay:
   st_def CURSOR_MOVE_TIMER, st_null_fn, st_cursor
+
+st_update_game:
+  st_def 0x00, update_game, st_update_game
+
+st_update_pause:
+  st_def 0x00, update_pause, st_update_pause
+  
+st_update_game_over:
+  st_def 0x00, update_game_over, st_update_game_over
index a8c505a6c6690064bac60712a08a2508db86b103..ce47edd088b8feb5dfeb18d6d00a5ebeb4d0b92a 100644 (file)
@@ -17,10 +17,12 @@ update_game:
   ; call player_update
   call sim_update 
 
+  ldnull bc
   ret
 
 update_pause:
   call player_update
+  ldnull bc
   ret
 
   ; called after vblank
@@ -29,8 +31,8 @@ update:
   inc a
   ld [frame_count], a
   
-  ld hl, update_table
-  ld a, [game_mode]
-  jp call_tbl
+  ld de, game_mode
+  jp st_update
+
   
 
index e93cfc55fe1ca7a22611a60444226316c79273e6..db32aabff1b3aaf88a38a51297729e18a58361a6 100644 (file)
@@ -13,7 +13,7 @@ prev_inputs: .adv 1
 
 
 
-game_mode: .adv 1
+game_mode: .adv st_size
 
   ; 16 bit srand seed
   ; seed must never be 0