wip: state update routine
authorLukas Krickl <lukas@krickl.dev>
Thu, 27 Mar 2025 12:59:23 +0000 (13:59 +0100)
committerLukas Krickl <lukas@krickl.dev>
Thu, 27 Mar 2025 12:59:23 +0000 (13:59 +0100)
src/state.s

index 136ebe9911072d4fec5bffac19c58da2c914539e..0950bc0c47481a6b005e73b7950280e05fc53c3a 100644 (file)
@@ -27,15 +27,48 @@ st_update:
  
   call call_hl
 
+  pop hl ; hl = original actor ptr = dst
+
   ; if routine returns 
   ; a new ptr in bc 
   ; set state to this pointer
   ; otherwise use state's next 
+  ld a, b
+  or a, c
+  cp a, 0
+  jr z, @set_next_state_default REL
 
-  pop de
-  ret
+  ; set returned state 
+  push bc
+  pop de ; de = src
+  
+  ld bc, st_size
+  jp memset
+@set_next_state_default:
+  
+  ; set default state
+  ; hl = actor ptr
+  push hl
+
+  inc hl
+  inc hl
+  ; hl = st_next
+  ld a, [hl+]
+  ld d, a
+  ld a, [hl]
+  ld e, a ; de = next state ptr
+
+  pop hl
+
+  ld bc, st_size
+  jp memset
 
+  ; null state 
+  ; do nothing and return
 st_null_fn:
+  xor a, a
+  ld b, a
+  ld c, a
   ret
 
 st_null: