From 0430405ec386d2b3c69d32d402c5e4e801326018 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Thu, 27 Mar 2025 17:59:28 +0100 Subject: [PATCH] cursor: cursor movement is now handeled by the state system --- src/defs.s | 6 +++--- src/macros.inc | 11 +++++++++-- src/player.s | 7 +++++-- src/state.s | 28 ++++++++++++++++++---------- src/update.s | 5 ++++- 5 files changed, 39 insertions(+), 18 deletions(-) diff --git a/src/defs.s b/src/defs.s index f62021c..6755a59 100644 --- a/src/defs.s +++ b/src/defs.s @@ -74,14 +74,14 @@ .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 diff --git a/src/macros.inc b/src/macros.inc index b136f9a..402312c 100644 --- a/src/macros.inc +++ b/src/macros.inc @@ -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 @@ -118,3 +118,10 @@ dw $2 dw $3 #endmacro + + ; loads NULL into a 16 bit register + ; inputs: + ; $1: register +#macro ldnull + ld $1, 0 +#endmacro diff --git a/src/player.s b/src/player.s index d7fb393..fd6c91d 100644 --- a/src/player.s +++ b/src/player.s @@ -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 diff --git a/src/state.s b/src/state.s index 0950bc0..03e233c 100644 --- a/src/state.s +++ b/src/state.s @@ -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 diff --git a/src/update.s b/src/update.s index 06751b8..a8c505a 100644 --- a/src/update.s +++ b/src/update.s @@ -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 -- 2.30.2