From 50de085aa7cbed8a7f21a5bf183965008f979ae1 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Thu, 27 Mar 2025 11:45:39 +0100 Subject: [PATCH] state machine: working on a simple state machine This can be used for simple cursor actions --- src/defs.s | 24 +++++++++++++++++++++++- src/macros.inc | 11 +++++++++++ src/main.s | 2 +- src/state.s | 11 +++++++++++ src/wram.s | 5 +++++ 5 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 src/state.s diff --git a/src/defs.s b/src/defs.s index cc23cb1..3a672f0 100644 --- a/src/defs.s +++ b/src/defs.s @@ -68,4 +68,26 @@ #define CURSOR_MIN_X 0 #define CURSOR_MAX_X 0xF8 #define CURSOR_MIN_Y 0 -#define CURSOR_MAX_Y 0xB8 +#define CURSOR_MAX_Y 0xB8 + + ; state struct +.se 0 + ; time until next state +.de st_time, 1 + ; state routine +.de st_routine, 2 + ; next state +.de st_next, 2 +.de st_size, 0 + + ; actor struct +.se 0 + ; current state +.de act_state, 2 + ; state timer + ; when it hits 0 + ; goto next +.de act_time, 1 + ; custom parameter +.de act_p0, 1 +.de act_size, 0 diff --git a/src/macros.inc b/src/macros.inc index 970075e..b136f9a 100644 --- a/src/macros.inc +++ b/src/macros.inc @@ -107,3 +107,14 @@ ld [$1], a #endmacro + ; defines a state + ; to be used by actors + ; inputs: + ; $1 timer + ; $2 routine + ; $3 next +#macro st_def + .db $1 + dw $2 + dw $3 +#endmacro diff --git a/src/main.s b/src/main.s index e4db461..87541ba 100644 --- a/src/main.s +++ b/src/main.s @@ -64,7 +64,7 @@ main: #include "audio.s" #include "map.s" #include "simulation.s" - +#include "state.s" #include "tiles.inc" ; fill bank diff --git a/src/state.s b/src/state.s new file mode 100644 index 0000000..f1fddb4 --- /dev/null +++ b/src/state.s @@ -0,0 +1,11 @@ + ; updates the state of an actor + ; inputs: + ; hl: actor +st_update: + ret + +st_null_fn: + ret + +st_null: + st_def 0xFF, st_null_fn, st_null diff --git a/src/wram.s b/src/wram.s index 8009c43..4a6a3b2 100644 --- a/src/wram.s +++ b/src/wram.s @@ -19,6 +19,11 @@ game_mode: .adv 1 ; seed must never be 0 srand: .adv 2 + ; actors + ; actors are state machines + ; they get updated once a frame +actor_player: .adv act_size + ; game state ; this region holds the entire game state ; everything thats needed for a savme game should be -- 2.30.2