Moved ptr tbl call to its own sub routine
authorLukas Krickl <lukas@krickl.dev>
Thu, 10 Oct 2024 03:25:38 +0000 (05:25 +0200)
committerLukas Krickl <lukas@krickl.dev>
Thu, 10 Oct 2024 03:25:38 +0000 (05:25 +0200)
src/sys.s
src/update.s
src/wram.s

index f058b4b0a93c4dca027cf5cb3f16851e86db3b3d..7502077488ceb21a22cf693fe76786acad8f85c5 100644 (file)
--- a/src/sys.s
+++ b/src/sys.s
@@ -16,3 +16,25 @@ disableinterrutpts:
   ld [IE], a
   di
   ret
+
+  ; call a function from a table
+  ; inputs:
+  ;   a: table index
+  ; [hl]: pointer to function ptr table
+  ; Note: do not call, just jp
+call_tbl:
+  sla a ; * 2
+  ld d, 0
+  ld e, a
+  add hl, de ; hl + index * 2
+
+  ; 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
+  
index 381a63b6b30b70a1a56c7136d6441444b86d2d46..de56efb4028e9b5ef8f6804ff8aa1564b5fea405 100644 (file)
@@ -19,20 +19,8 @@ update:
   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
-
-  ; 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
+  ld a, [game_mode]
+  jp call_tbl
+  
 
index 392f56a74ffb6d32275d68839fc9eb81ec67f9ce..aa2346adf2d929b1d02df839604935a5928ac079 100644 (file)
@@ -107,8 +107,12 @@ itmp: .adv 16
 game_over_timer: .adv 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
+.de GAME_OVER, 1
 
 game_mode: .adv 1