wip: state machine for cursor
authorLukas Krickl <lukas@krickl.dev>
Thu, 27 Mar 2025 11:56:04 +0000 (12:56 +0100)
committerLukas Krickl <lukas@krickl.dev>
Thu, 27 Mar 2025 11:56:04 +0000 (12:56 +0100)
src/defs.s
src/state.s
src/sys.s

index f76d1f3569003f056be19dc405d1cbc1babf4069..f62021c7d9a8cf14bffda0c0fd88860ca10a09d2 100644 (file)
 
   ; state struct 
 .se 0
-  ; time until next state 
+  ; time until next state
 .de st_time, 1
   ; state routine
   ; it can return 0000 in hl
   ; or a new state address in hl
-  ; if hl is not 0000 after
+  ; if bc is not 0000 after
   ; the calling state's address
-  ; will be set to hl immediatly 
+  ; will be set to bc immediatly 
 .de st_routine, 2
   ; next state
 .de st_next, 2
 .de st_size, 0
 
   ; actor struct 
+  ; actor structs are basically just states
 .se 0
-  ; current state
-.de act_state, 2
-  ; state timer
-  ; when it hits 0 
-  ; goto next
-.de act_time, 1
+  ; copy of current state
+.de act_state, st_size
   ; custom parameter
 .de act_p0, 1
 .de act_size, 0
index f1fddb41e14605f5b29d9daa6e889c6ecbfc4a8e..136ebe9911072d4fec5bffac19c58da2c914539e 100644 (file)
@@ -1,7 +1,38 @@
   ; updates the state of an actor
   ; inputs:
-  ;   hl: actor
+  ;   de: actor
 st_update:
+  push de
+
+  ld a, [de]
+  ld h, a
+  inc de
+  ld a, [de]
+  ld l, a 
+  ; hl = function ptr
+
+  inc de
+  ld a, [de] ; a = timer 
+  cp a, 0
+  ; if timer is 0 update state
+  jr z, @update REL
+
+  ; otherwise timer--
+  dec a
+  ld [de], a
+
+  pop de
+  ret
+@update:
+  call call_hl
+
+  ; if routine returns 
+  ; a new ptr in bc 
+  ; set state to this pointer
+  ; otherwise use state's next 
+
+  pop de
   ret
 
 st_null_fn:
index c30a158853bf923a61f4133a3f674c0c1c5ee3f2..64ac1e254ff97818dd5eb3a0ed2bad28ec112bbf 100644 (file)
--- a/src/sys.s
+++ b/src/sys.s
@@ -48,4 +48,7 @@ call_tbl:
   ld l, a
   ; hl = function value 
   jp hl
-  
+
+  ; simple call to hl
+call_hl:
+  jp hl