; 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
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
+; 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
; 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