cursor: cursor movement is now handeled by the state system
authorLukas Krickl <lukas@krickl.dev>
Thu, 27 Mar 2025 16:59:28 +0000 (17:59 +0100)
committerLukas Krickl <lukas@krickl.dev>
Thu, 27 Mar 2025 16:59:28 +0000 (17:59 +0100)
src/defs.s
src/macros.inc
src/player.s
src/state.s
src/update.s

index f62021c7d9a8cf14bffda0c0fd88860ca10a09d2..6755a593452a787606d1aeb2be24a904b5cdac4e 100644 (file)
 .se 0
   ; time until next state
 .de st_time, 1
-  ; state routine
+  ; state routine (BE)
   ; it can return 0000 in hl
-  ; or a new state address in hl
+  ; or a new state address in hl (LE)
   ; if bc is not 0000 after
   ; the calling state's address
   ; will be set to bc immediatly 
 .de st_routine, 2
-  ; next state
+  ; next state (BE)
 .de st_next, 2
 .de st_size, 0
 
index b136f9abaac5b63e64ecef304f2cc37b40b4ed6d..402312ca56009784e3fe74806944921fe9b6a78d 100644 (file)
@@ -49,8 +49,8 @@
 #endmacro
 
   ; same as dw but 
-  ; stores in big endian
-#macro dwb 
+  ; stores in little endian
+#macro dwl 
 .db ($1 >> 8) & 0xFF 
 .db $1 & 0xFF
 #endmacro
   dw $2
   dw $3
 #endmacro
+
+  ; loads NULL into a 16 bit register
+  ; inputs:
+  ;   $1: register
+#macro ldnull 
+  ld $1, 0
+#endmacro
index d7fb393e47ce3dc811a5c0b7cbc855bc50a42fff..fd6c91dc5fccf22bb820c3a4fad87699fdc13cf9 100644 (file)
@@ -8,7 +8,10 @@
 
   ; init the player 
 player_init:
-
+  ld de, st_cursor
+  ld hl, actor_player
+  ld bc, st_size
+  call memcpy
   ret
 
   ; update the player 
@@ -18,7 +21,6 @@ player_init:
   ; inputs:
   ;   hl: pointer to player memory
 player_update:
-
   ; check cursor movement
   ld a, [cursor_move_timer] 
   cp a, 0
@@ -52,6 +54,7 @@ player_update:
   xor a, a
   ld [hl+], a
 
+  ldnull bc
 
   ret
 
index 0950bc0c47481a6b005e73b7950280e05fc53c3a..03e233c092ab1c66cb37976d5b9098191a574e4b 100644 (file)
@@ -4,14 +4,16 @@
 st_update:
   push de
 
+  inc de
   ld a, [de]
-  ld h, a
+  ld l, a
   inc de
   ld a, [de]
-  ld l, a 
+  ld h, a 
   ; hl = function ptr
 
-  inc de
+  dec de
+  dec de ; de = timer
   ld a, [de] ; a = timer 
   cp a, 0
   ; if timer is 0 update state
@@ -43,7 +45,7 @@ st_update:
   pop de ; de = src
   
   ld bc, st_size
-  jp memset
+  jp memcpy 
 @set_next_state_default:
   
   ; set default state
@@ -52,24 +54,30 @@ st_update:
 
   inc hl
   inc hl
+  inc hl 
   ; hl = st_next
   ld a, [hl+]
-  ld d, a
+  ld e, a
   ld a, [hl]
-  ld e, a ; de = next state ptr
+  ld d, a ; de = next state ptr
 
   pop hl
 
   ld bc, st_size
-  jp memset
+  call memcpy
+  ret
 
   ; null state 
   ; do nothing and return
 st_null_fn:
-  xor a, a
-  ld b, a
-  ld c, a
+  ldnull bc 
   ret
 
 st_null:
   st_def 0xFF, st_null_fn, st_null
+
+st_cursor:
+  st_def 0x00, player_update, st_cursor
+
+st_cursor_delay:
+  st_def CURSOR_MOVE_TIMER, st_null, st_cursor
index 06751b8b7fe0676fea49aa8e6b7090b19c4e1ee3..a8c505a6c6690064bac60712a08a2508db86b103 100644 (file)
@@ -11,7 +11,10 @@ update_game:
   call rand
   call rand_save_srand
 
-  call player_update
+  ld de, actor_player 
+  call st_update
+
+  ; call player_update
   call sim_update 
 
   ret