; check cursor movement
ld a, [cursor_move_timer]
cp a, 0
- call nz, cursor_move
+ call nz, cursor_move_delay
call z, handle_inputs
cursor_move_direction cursor_move_y, cursor_move_x, 1
- ld a, [cursor_y]
- cp a, 0
; adjust scroll
cursor_adjust_scroll add, scroll_move_y
+ call cursor_move
ret
@notdown:
input_held BTNUP
jr z, @notup REL
+ call try_abort_move_up
+ ret z
+
cursor_move_direction cursor_move_y, cursor_move_x, NEGATE
- ld a, [cursor_y]
- cp a, 0
; adjust scroll
cursor_adjust_scroll sub, scroll_move_y
+ call cursor_move
ret
@notup:
input_held BTNLEFT
jr z, @notleft REL
+ call try_abort_move_left
+ ret z
+
cursor_move_direction cursor_move_x, cursor_move_y, NEGATE
- ld a, [cursor_x]
- cp a, 0
; adjust scroll
cursor_adjust_scroll sub, scroll_move_x
+ call cursor_move
ret
@notleft:
cursor_move_direction cursor_move_x, cursor_move_y, 1
- ld a, [cursor_x]
- cp a, 0
; adjust scroll
cursor_adjust_scroll add, scroll_move_x
-
+
+ call cursor_move
@notright:
ret
-cursor_move:
- push af
-
-
+ ; updates cursor move delay
+ ; cursor move delay timer--
+cursor_move_delay:
ld a, [cursor_move_timer]
dec a
ld [cursor_move_timer], a
- cp a, 0
- jr nz, @done REL
+ ret
- ; if timer is 0 apply movement
- ; and jump to next tile
- call try_abort_move
- jp z, @done
+cursor_move:
+ ld a, [cursor_y]
+ ld b, a
- ld a, [cursor_y]
- ld b, a
+ ld a, [cursor_move_y]
+ add a, b
+ ld [cursor_y], a
- ld a, [cursor_move_y]
- add a, b
- ld [cursor_y], a
+ ld a, [cursor_x]
+ ld b, a
- ld a, [cursor_x]
- ld b, a
+ ld a, [cursor_move_x]
+ add a, b
+ ld [cursor_x], a
- ld a, [cursor_move_x]
- add a, b
- ld [cursor_x], a
-
- call scroll_update
-@done:
- pop af
+ call scroll_update
ret
-try_abort_move:
+try_abort_move_left:
ld b, CURSOR_MIN_X
- ld c, CURSOR_MOVE_SPEED * NEGATE
ld hl, cursor_x
- ld de, cursor_move_x
- call try_abort_move_at
- ret z
+ jp try_abort_move_at
- ; TODO check other directions here
- ret
+try_abort_move_up:
+ ld b, CURSOR_MIN_Y
+ ld hl, cursor_y
+ jp try_abort_move_at
; aborts a move direciton
; inputs:
; b: compare variable (e.g. min or max value)
- ; c: move direction compare value (e.g. move + or -)
; hl: position ptr
- ; de: move variable to set to 0
; returns: z == 0 if move was aborted
try_abort_move_at:
; do not abort if position is wrong
ld a, [hl]
cp a, b
- ret nz
-
- ; do not abort if direction is wrong
- ld a, [de]
- cp a, c
- ret nz
-
- xor a, a
- ld [de], a
-
- ; z = 0 due to xor a, a
ret
ret
; updates scroll based on scroll_move_y/x
- ; do nothing if scroll would move oob
scroll_update:
- ld a, [cursor_move_timer]
- cp a, 0
- ret nz
-
ld a, [scroll_move_y]
cp a, 0x0F
jr nz, @no_scroll_down REL
jr @done REL
@no_scroll_up:
-
ld a, [scroll_move_x]
cp a, 0x14
jr nz, @no_scroll_right REL