Added simple game mode switch
authorLukas Krickl <lukas@krickl.dev>
Wed, 9 Oct 2024 10:46:47 +0000 (12:46 +0200)
committerLukas Krickl <lukas@krickl.dev>
Wed, 9 Oct 2024 10:46:47 +0000 (12:46 +0200)
src/macros.inc
src/mem.s
src/update.s
src/wram.s

index 9edc2d01adc5c1f6ea61127abe99d425f82a2ece..887ddbdac6ca7034cb4a9d8ebdf81bcdd3abdb2c 100644 (file)
 
 ; relative jump: jr <label> RELB 
 #define REL - $ - 2 & 0xFF 
+
+#macro dblo 
+.db $1 & 0xFF
+#endmacro 
+
+#macro dbhi
+.db ($1 >> 8) & 0xFF 
+#endmacro 
+
+#macro dw 
+.db $1 & 0xFF
+.db ($1 >> 8) & 0xFF 
+#endmacro
index 4a9dbdd4e7e8d6f83589fb2658556c5e7256a440..e536848dc93e577460f06587513fdbe61eb45ee8 100644 (file)
--- a/src/mem.s
+++ b/src/mem.s
@@ -10,6 +10,11 @@ mem_init:
   ld hl, OAMDMAFN
   ld bc, shadow_oam_to_oam_end - shadow_oam_to_oam 
   call memcpy
+
+  ; set up game mode 
+  ld a, GM_GAME
+  ld [game_mode], a
+
   ret
 
 ; copies memory from one location to another 
index aafc22071338c52bb6eed2f7146963f0010fbcbd..381a63b6b30b70a1a56c7136d6441444b86d2d46 100644 (file)
@@ -1,11 +1,38 @@
+; update function table 
+update_table:
+dw update_game
+dw update_pause
+
+update_game:
+  ; update player
+  ld hl, player
+  call player_update
+
+  ret
+
+update_pause:
+  ret
+
   ; called after vblank
 update:
   ld a, [frame_count]
   inc a
   ld [frame_count], a
+  
+  ld a, [game_mode]
+  sla a ; * 2
+  ld d, 0
+  ld e, a
+  ld hl, update_table
+  add hl, de ; hl + index * 2
 
-  ; update player
-  ld hl, player
-  call player_update
+  ; hl = ptr to update routine 
+  ; => load functon ptr into hl
+  ld a, [hl+]
+  ld d, a
+  ld a, [hl]
+  ld l, d
+  ld h, a
+  ; hl = function value 
+  jp hl
 
-  ret
index 8a9c8e1a20927a7a4bc51d959c0fc14d3190afe8..392f56a74ffb6d32275d68839fc9eb81ec67f9ce 100644 (file)
@@ -105,3 +105,10 @@ itmp: .adv 16
   ; timer for game over. when 
   ; it reaches 0 re-start game
 game_over_timer: .adv 1
+
+  ; game modes
+.se 0
+.de GM_GAME, 1
+.de GM_PAUSE, 1
+
+game_mode: .adv 1