From: Lukas Krickl Date: Thu, 10 Apr 2025 12:04:29 +0000 (+0200) Subject: player: Added code to calculate cursor building offset when pressing a X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=8c24222c9d14efc060f81f96817f9961dc4d1b3a;p=gbrg%2F.git player: Added code to calculate cursor building offset when pressing a --- diff --git a/src/macros.inc b/src/macros.inc index 8c80e81..4f82d8a 100644 --- a/src/macros.inc +++ b/src/macros.inc @@ -60,14 +60,13 @@ - ; divides a regiser by 16 + ; divides a regiser by 8 ; 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 diff --git a/src/player.s b/src/player.s index 3330c89..39b8758 100644 --- a/src/player.s +++ b/src/player.s @@ -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