From: Lukas Krickl Date: Tue, 18 Mar 2025 16:11:43 +0000 (+0100) Subject: cursor: moved cursor movement to macro X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=dc76122045f8ae4d293f2c6b5bbe525d36c5a9e8;p=gbrg%2F.git cursor: moved cursor movement to macro --- diff --git a/src/macros.inc b/src/macros.inc index be23d69..0a367b6 100644 --- a/src/macros.inc +++ b/src/macros.inc @@ -79,3 +79,27 @@ #endmacro + ; adjust player scroll + ; inputs: + ; $1: add/sub + ; $2: scroll_move_y/x + ; uses: a +#macro cursor_adjust_scroll + ld a, [$2] + $1 a, 1 + ld [$2], a +#endmacro + + ; move cursor + ; inputs: + ; $1: cursor_move_y/x -> move + ; $2: cursor_move_y/x -> clear + ; $2: -1/1 +#macro cursor_move_direction + xor a, a + ld [$2], a + ld a, CURSOR_MOVE_TIMER + ld [cursor_move_timer], a + ld a, CURSOR_MOVE_SPEED * $3 + ld [$1], a +#endmacro diff --git a/src/player.s b/src/player.s index f559bcf..0a4ac40 100644 --- a/src/player.s +++ b/src/player.s @@ -59,18 +59,10 @@ handle_inputs: input_held BTNDOWN jr z, @notdown REL - xor a, a - ld [cursor_move_x], a - ld a, CURSOR_MOVE_TIMER - ld [cursor_move_timer], a - ld a, CURSOR_MOVE_SPEED - ld [cursor_move_y], a - + cursor_move_direction cursor_move_y, cursor_move_x, 1 ; adjust scroll - ld a, [scroll_move_y] - add a, 1 - ld [scroll_move_y], a + cursor_adjust_scroll add, scroll_move_y ret @notdown: @@ -78,17 +70,10 @@ handle_inputs: input_held BTNUP jr z, @notup REL - xor a, a - ld [cursor_move_x], a - ld a, CURSOR_MOVE_TIMER - ld [cursor_move_timer], a - ld a, CURSOR_MOVE_SPEED * NEGATE - ld [cursor_move_y], a + cursor_move_direction cursor_move_y, cursor_move_x, NEGATE ; adjust scroll - ld a, [scroll_move_y] - sub a, 1 - ld [scroll_move_y], a + cursor_adjust_scroll sub, scroll_move_y ret @notup: @@ -96,17 +81,10 @@ handle_inputs: input_held BTNLEFT jr z, @notleft REL - xor a, a - ld [cursor_move_y], a - ld a, CURSOR_MOVE_TIMER - ld [cursor_move_timer], a - ld a, CURSOR_MOVE_SPEED * NEGATE - ld [cursor_move_x], a + cursor_move_direction cursor_move_x, cursor_move_y, NEGATE ; adjust scroll - ld a, [scroll_move_x] - sub a, 1 - ld [scroll_move_x], a + cursor_adjust_scroll sub, scroll_move_x ret @notleft: @@ -114,17 +92,10 @@ handle_inputs: input_held BTNRIGHT jr z, @notright REL - xor a, a - ld [cursor_move_y], a - ld a, CURSOR_MOVE_TIMER - ld [cursor_move_timer], a - ld a, CURSOR_MOVE_SPEED - ld [cursor_move_x], a + cursor_move_direction cursor_move_x, cursor_move_y, 1 ; adjust scroll - ld a, [scroll_move_x] - add a, 1 - ld [scroll_move_x], a + cursor_adjust_scroll add, scroll_move_x @notright: