From: Lukas Krickl Date: Tue, 28 Oct 2025 04:51:04 +0000 (+0100) Subject: enemy: guards now use jump tables instead of repeated cmps X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=5b03bb851b974cf128f9321ae1d8ed9bb729f76e;p=gbrg%2F.git enemy: guards now use jump tables instead of repeated cmps --- diff --git a/src/enemy.s b/src/enemy.s index 123f625..373dc95 100644 --- a/src/enemy.s +++ b/src/enemy.s @@ -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: diff --git a/src/sys.s b/src/sys.s index 871dded..c2d41f0 100644 --- 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