From d64f4da14fc82c178edd1670b46e1680bfddb74c Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sun, 4 May 2025 16:35:12 +0200 Subject: [PATCH] actors: Added actor table state machine code --- src/defs.s | 1 + src/map.s | 7 ++++++- src/mem.s | 2 +- src/unit.s | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/defs.s b/src/defs.s index 63080d5..f822ac2 100644 --- a/src/defs.s +++ b/src/defs.s @@ -67,6 +67,7 @@ ; actor type enum .se 0 +.de ACT_T_NULL, 1 .de ACT_T_CURSOR, 1 ; actor struct diff --git a/src/map.s b/src/map.s index 88d2a2c..eefe0c7 100644 --- a/src/map.s +++ b/src/map.s @@ -6,6 +6,9 @@ map_init: call cells_draw_all + ; TOOD: remove demo unit load + call map_load_demo_actors + ret ; loads a tile map into cells @@ -84,6 +87,8 @@ cells_draw_all: ret - + ; sets up some actors for debug purposes +map_load_demo_actors: + ret #include "default_map.s" diff --git a/src/mem.s b/src/mem.s index e4473f4..64d93ee 100644 --- a/src/mem.s +++ b/src/mem.s @@ -16,7 +16,7 @@ mem_init: ; set up game mode call game_init call mbc1_init - + ret game_init: diff --git a/src/unit.s b/src/unit.s index 9d6886e..15d06c7 100644 --- a/src/unit.s +++ b/src/unit.s @@ -1,8 +1,42 @@ ; updates a unit table ; runs state for each unit + ; does not update if actor is ACT_T_NULL ; inputs: ; hl: unit table (p0/p1) units_update: + ; loop counter + ld a, UNITS_MAX + +@loop: + push af ; store loop counter + + push hl + ld de, act_type + add hl, de ; hl = act_type + + ; a = type + ld a, [hl] + pop hl ; restore hl + cp a, ACT_T_NULL ; do not update type NULL + jr z, @skip REL + + ; save hl again + ; hl = act_state state machine + push hl + push hl + pop de ; need hl in de for parameter + call st_update + +@skip: + ; next actor + ld de, act_size + add hl, de + + ; a-- + pop af + dec a + jr nz, @loop REL + ret -- 2.30.2