enemy: guards now use jump tables instead of repeated cmps
authorLukas Krickl <lukas@krickl.dev>
Tue, 28 Oct 2025 04:51:04 +0000 (05:51 +0100)
committerLukas Krickl <lukas@krickl.dev>
Tue, 28 Oct 2025 04:51:04 +0000 (05:51 +0100)
src/enemy.s
src/sys.s

index 123f625573ee7ae72862dd9f7388b219b9b34e48..373dc9590a4db97208b4a794dfe650329d82928a 100644 (file)
@@ -10,6 +10,11 @@ act_enemy_guard:
 
 #define ACT_GUARD_MOVE_FRAMES 40
 
+act_guard_state_table:
+       dw act_guard_walk_right
+       dw act_guard_shoot
+       dw act_guard_walk_left
+
        ; updates the guard enemy
        ; inputs:
        ;               de: actor ptr
@@ -39,14 +44,8 @@ act_guard_update:
        ld hl, act_state
        add hl, de
        ld a, [hl]
-       cp a, ACT_GUARD_WALK_RIGHT
-       jp z, act_guard_walk_right
-
-       cp a, ACT_GUARD_SHOOT
-       jp z, act_guard_shoot
-
-       cp a, ACT_GUARD_WALK_LEFT
-       jp z, act_guard_walk_left
+       ld hl, act_guard_state_table
+       jp call_tbl
 
        ret
 @despawn:
index 871ddedd7215ec7227265ca96b2194faf5b3cd30..c2d41f002e76d6a872d94bfbe702db2876516ed8 100644 (file)
--- a/src/sys.s
+++ b/src/sys.s
@@ -41,11 +41,13 @@ disableinterrutpts:
   ;   a: table index
   ; [hl]: pointer to function ptr table
   ; Note: do not call, just jp
+       ;       uses:
+       ;               hl, a, bc
 call_tbl:
   add a, a ; * 2
-  ld d, 0
-  ld e, a
-  add hl, de ; hl + index * 2
+  ld b, 0
+  ld c, a
+  add hl, bc ; hl + index * 2
 
   ; hl = ptr to routine table 
   ; => load functon ptr into hl