actors: Added actor table state machine code
authorLukas Krickl <lukas@krickl.dev>
Sun, 4 May 2025 14:35:12 +0000 (16:35 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sun, 4 May 2025 14:35:12 +0000 (16:35 +0200)
src/defs.s
src/map.s
src/mem.s
src/unit.s

index 63080d55a2d61acb5296e40814be6dd9bc2e530c..f822ac2073fb296b1c91c7790b5290bdab78cd23 100644 (file)
@@ -67,6 +67,7 @@
 
   ; actor type enum
 .se 0
+.de ACT_T_NULL, 1
 .de ACT_T_CURSOR, 1
 
   ; actor struct 
index 88d2a2ca8b4189f9e71f6409b85b2753d7087bf1..eefe0c75ee4459e303afc5c0e94ab7e1e6dd604c 100644 (file)
--- 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"
index e4473f47e23bfbd6b0cc0a62a5c3c0e6e0156b6b..64d93ee1a5033dce58b965f74966f85db2b86b98 100644 (file)
--- 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:
index 9d6886edb58c56c148ef4e4dff150cf5b6522e9d..15d06c7b30cdbae454e0fa06563a693520a4a792 100644 (file)
@@ -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