player: Added code to calculate cursor building offset when pressing a
authorLukas Krickl <lukas@krickl.dev>
Thu, 10 Apr 2025 12:04:29 +0000 (14:04 +0200)
committerLukas Krickl <lukas@krickl.dev>
Thu, 10 Apr 2025 12:04:29 +0000 (14:04 +0200)
src/macros.inc
src/player.s

index 8c80e8188215a7423651a4be56e54e73d0aa240f..4f82d8a2c1ea07cd40ea90455311a5ae364d516e 100644 (file)
 
 
 
-  ; divides a regiser by 16
+  ; divides a regiser by 
   ; inputs:
   ;   $1: the register 
-#macro div16 
+#macro div8 
   srl $1 ; / 2
   srl $1 ; / 4
   srl $1 ; / 8
-  srl $1 ; / 16
 #endmacro 
 
   ; multiplies a regiser with 8 
index 3330c899a84583235613522ec27d318fdbda2577..39b875830e7bcfe8135983b1db2027c3a9fa33d9 100644 (file)
@@ -218,5 +218,33 @@ try_abort_move_at:
   ; at cursor_y/x 
   ; aborts if the tiel will not fit 
 cursor_place_tile:
+  ; find the cell the cursor has selected 
+  ld hl, state_cells
+
+  ; move y rows down
+  ld de, MAP_W * c_size
+  ld a, [cursor_y]
+  div8 a 
+  cp a, 0
+  jr z, @not_y_loop REL
+@y_loop:
+    add hl, de
+    dec a
+    cp a, 0
+    jr nz, @y_loop REL
+@not_y_loop:
+
+  ; move x cells 
+  ld de, c_size
+  ld a, [cursor_x]
+  div8 a
+  cp a, 0
+  jr z, @not_x_loop REL
+@x_loop:
+    add hl, de
+    dec a
+    cp a, 0
+    jr nz, @x_loop REL
+@not_x_loop:
 
   ret