state machine: working on a simple state machine
authorLukas Krickl <lukas@krickl.dev>
Thu, 27 Mar 2025 10:45:39 +0000 (11:45 +0100)
committerLukas Krickl <lukas@krickl.dev>
Thu, 27 Mar 2025 10:45:39 +0000 (11:45 +0100)
This can be used for simple cursor actions

src/defs.s
src/macros.inc
src/main.s
src/state.s [new file with mode: 0644]
src/wram.s

index cc23cb16ebcb39b34ffd18a23449e23671dab0ca..3a672f0353993f85508fc5221c8ef33959e951f0 100644 (file)
 #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
index 970075ee4d68dc0657315518b5ceb7409c183c5f..b136f9abaac5b63e64ecef304f2cc37b40b4ed6d 100644 (file)
     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
index e4db4616e19928b5c67adfcaa488af4ca5d534f6..87541bac918b28b5b700063e48d9020ada7f7601 100644 (file)
@@ -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 (file)
index 0000000..f1fddb4
--- /dev/null
@@ -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
index 8009c4384436919c15530d5a6461ba821032acfa..4a6a3b2ac4263107c87a64204bdd7c9560147054 100644 (file)
@@ -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