.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
#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
; init the player
player_init:
-
+ ld de, st_cursor
+ ld hl, actor_player
+ ld bc, st_size
+ call memcpy
ret
; update the player
; inputs:
; hl: pointer to player memory
player_update:
-
; check cursor movement
ld a, [cursor_move_timer]
cp a, 0
xor a, a
ld [hl+], a
+ ldnull bc
ret
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
pop de ; de = src
ld bc, st_size
- jp memset
+ jp memcpy
@set_next_state_default:
; set default state
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
call rand
call rand_save_srand
- call player_update
+ ld de, actor_player
+ call st_update
+
+ ; call player_update
call sim_update
ret