From: Lukas Krickl Date: Thu, 10 Oct 2024 03:25:38 +0000 (+0200) Subject: Moved ptr tbl call to its own sub routine X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=5c1f586e401e59c20493acd72aba407a5f1d1c5c;p=gbrg%2F.git Moved ptr tbl call to its own sub routine --- diff --git a/src/sys.s b/src/sys.s index f058b4b..7502077 100644 --- 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 + diff --git a/src/update.s b/src/update.s index 381a63b..de56efb 100644 --- a/src/update.s +++ b/src/update.s @@ -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 + diff --git a/src/wram.s b/src/wram.s index 392f56a..aa2346a 100644 --- a/src/wram.s +++ b/src/wram.s @@ -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