cursor: moved cursor movement to macro
authorLukas Krickl <lukas@krickl.dev>
Tue, 18 Mar 2025 16:11:43 +0000 (17:11 +0100)
committerLukas Krickl <lukas@krickl.dev>
Tue, 18 Mar 2025 16:11:43 +0000 (17:11 +0100)
src/macros.inc
src/player.s

index be23d698014ff4bb51e81c1f9aa97b16af5022f6..0a367b6e6f0a56bea9d69037cdfc27f9efb25aed 100644 (file)
 #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
index f559bcf8fc836f59229c969e107f89cfe70a952e..0a4ac402cf7249a0c0c6e01dce7270ec9e8064eb 100644 (file)
@@ -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: