state: Added state machine stub for future acotr/player updates
authorLukas Krickl <lukas@krickl.dev>
Sat, 1 Feb 2025 12:07:30 +0000 (13:07 +0100)
committerLukas Krickl <lukas@krickl.dev>
Sat, 1 Feb 2025 12:07:30 +0000 (13:07 +0100)
src/actor.s
src/animation.s
src/defs.s
src/main.s
src/mem.s
src/player.s
src/state.s [new file with mode: 0644]
src/wram.s

index b5036e190d102106ab5629b6f6b2978a39881ccb..29357d65a6127a748871e5fc3f69141532366ee1 100644 (file)
@@ -527,8 +527,4 @@ who_next:
 @no_player:
   ld [who], a
 
-  ; advance some other values 
-  ; related to the next turn starting 
-  call anim_next
-
   ret
index e30f763076b1714331ecc9cedcc05af1ae316f76..f432c89420f2ae095f914c7762dbb84d7c5a2b1c 100644 (file)
@@ -2,42 +2,6 @@
 ; each frame the latest animation is 
 ; updated
 
-  ; animation functions:
-  ; inputs: 
-  ;   hl: actor ptr
-  ;   bc: anim ptr
-
-  ; sets up animation ptr 
-anim_init:
-  ld hl, anim_table
-  ld a, l
-  ld [anim_ptr], a
-  ld a, h
-  ld [anim_ptr+1], a
-  ret
-
-  ; advances animation ptr to
-  ; its next value 
-anim_next:
-  ld a, [who]
-  cp a, 0
-  jp z, anim_init
-
-  ld a, [anim_ptr]
-  ld l, a
-  ld a, [anim_ptr+1]
-  ld h, a
-
-  ld de, anim_size
-  add hl, de ; hl = next animation ptr
-
-  ld a, l
-  ld [anim_ptr], a
-  ld a, h
-  ld [anim_ptr+1], a
-
-  ret
-
 anim_walk_north:
   ret
 
index fe2b933be189fe78391817df1c12404c538d16b5..41ec347db84c5a1ba0c04248925245ef2b0f5410 100644 (file)
 .de GM_PAUSE, 1
 .de GAME_OVER, 1
 
-
-  ; animation flags enum 
-.se 1
-
-
-; animation table entries 
+  ; struct state 
 .se 0
-.de ANIM_TNOP, 1
-.de ANIM_TWALK_SIMPLE, 1
+.de sm_state, 1
+.de sm_param, 2
+.de sm_size, 0
 
-  ; anim entry struct 
-.se 0
-.de anim_type, 1
-.de anim_step, 1
-.de anim_flags, 1
-.de anim_p0, 1
-.de anim_size, 0
+; state table entries 
+.se 1
+.de smt_end_turn, 1
index 21bf3a7bb277fb415d41994c6c9cdea47db0075d..ca38790bcc37d31a08e52156cd10140c5102daad 100644 (file)
@@ -66,6 +66,7 @@ main:
 #include "audio.s"
 #include "animation.s"
 #include "combat.s"
+#include "state.s"
 
 #include "tiles.inc"
 
index df73aa6676a12cb6e4cc6ac9d5fe52ca1f28256f..7e24aabe73d999868377c5096e4a72faa790652a 100644 (file)
--- a/src/mem.s
+++ b/src/mem.s
@@ -6,7 +6,6 @@ mem_init:
   call memset
   
   call rand_init
-  call anim_init 
 
   ; copy shadow oam dma function 
   ld de, shadow_oam_to_oam 
index 5a048ee2aabd1a896837a68ec512d8f7590fa997..1e0a216469f7009f4cc8ed354bcfee3eb5b31d39 100644 (file)
@@ -219,6 +219,7 @@ player_update:
   ld e, a ; e = target x + 8 to center on tile 
   call player_collision_check
 
+@update_end:
 @skip_input:
   ; hl should be player_y here 
 
diff --git a/src/state.s b/src/state.s
new file mode 100644 (file)
index 0000000..259fd76
--- /dev/null
@@ -0,0 +1,23 @@
+; the state machine can be used by the current actor (who)
+; to store their current state and call small re-usable routines 
+
+  ; table of all states 
+state_table:
+  dw sm_nop
+  dw sm_end_turn
+
+sm_nop:
+  ret
+
+sm_end_turn:
+  call sm_clear
+  ret
+
+  ; clears the state machine 
+sm_clear:
+  xor a, a
+  ld hl, state_machine 
+  ld a, [hl+]
+  ld a, [hl+]
+  ld a, [hl+]
+  ret
index 2ab803b1bdd81947b726414d5a39c92a142807c4..1ec0924f3a114f5db90ee9cde6c5e45ac27ef4ed 100644 (file)
@@ -103,12 +103,7 @@ anim_step_x: .adv 1
 anim_target_y: .adv 1
 anim_target_x: .adv 1
 
-  ; pointing to current animation 
-  ; advanced in who_next 
-  ; l/h ptr
-anim_ptr: .adv 2
-  ; 1 animation buffer for each actor + player
-anim_table: .adv anim_size * (ACTORS_MAX + 1)
+state_machine: .adv sm_size 
 
   ; collision tile tmp values  
 ct_poy: .adv 1