; 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
; 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: