From: Lukas Krickl Date: Thu, 27 Mar 2025 11:56:04 +0000 (+0100) Subject: wip: state machine for cursor X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=ab3613d2c279a85226aad68e7918378a491c8c92;p=gbrg%2F.git wip: state machine for cursor --- diff --git a/src/defs.s b/src/defs.s index f76d1f3..f62021c 100644 --- a/src/defs.s +++ b/src/defs.s @@ -72,27 +72,24 @@ ; 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 diff --git a/src/state.s b/src/state.s index f1fddb4..136ebe9 100644 --- a/src/state.s +++ b/src/state.s @@ -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: diff --git a/src/sys.s b/src/sys.s index c30a158..64ac1e2 100644 --- 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