From: Lukas Krickl Date: Sat, 20 Sep 2025 04:22:11 +0000 (+0200) Subject: actor: wip 16 bit positions X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=99706a63292f53b645198815eb2f1574f0622f0b;p=gbrg%2F.git actor: wip 16 bit positions --- diff --git a/src/actor.s b/src/actor.s index 8fe56ac..6aafc46 100644 --- a/src/actor.s +++ b/src/actor.s @@ -28,13 +28,16 @@ actor_draw: swap a ; a = y offset ld b, a ld a, [de] + add a, OBJ_OFF_Y + inc de ; de = y_hi add a, b ; a = y postion ld b, a ld a, [scroll_y] add a, b - - ; TODO: deal with row offset + ld b, a + ld a, [de] ; a = y_hi + adjust_y_row inc de ; de = x pos @@ -48,6 +51,7 @@ actor_draw: ld b, a ld a, [de] add a, b ; b = x position + add a, OBJ_OFF_X ld [hl+], a diff --git a/src/defs.s b/src/defs.s index 43bdf52..3876289 100644 --- a/src/defs.s +++ b/src/defs.s @@ -45,6 +45,7 @@ .de act_flags, 1 .de act_pos_y, 1 ; y/x position +.de act_pos_y_hi, 1 ; high byte of 16 bit y position .de act_pos_x, 1 ; custom parameter diff --git a/src/macros.inc b/src/macros.inc index a12aabe..0a05537 100644 --- a/src/macros.inc +++ b/src/macros.inc @@ -178,9 +178,9 @@ $1: ; $5: armor #macro actdef .db $1, $2, $3 - ; placeholder for y and x + ; placeholder for y, row and x ; since those are set at runtime - .db 0, 0 + .db 0, 0, 0 .db $4, $5 #endmacro @@ -193,4 +193,28 @@ $1: ; $5: dat2 #macro modef .db $1, $2, $3, $4, $5 +#endmacro + + ; adjusts an input position + ; to draw correctly based on the current map row + ; inputs: + ; a: hi y position + ; b: unadjusted lo y position + ; returns: + ; a: real y position (or 0 if out of bounds) + ; uses: a, b, c +#macro adjust_y_row +.beginscope + ld c, a + ld a, [map_curr_row] + div16 a ; 16 rows per screen page -> row count to hi y position + cp a, c + jr c, @zero REL + + ld a, b + jr @done REL +@zero: + xor a, a +@done: +.endscope #endmacro diff --git a/src/player.s b/src/player.s index f05c71e..2b5b478 100644 --- a/src/player.s +++ b/src/player.s @@ -5,6 +5,9 @@ player_init: ld [player+act_pos_y], a ld a, 24 ld [player+act_pos_x], a + + ld a, 0 + ld [player+act_pos_y_hi], a ret ; updates the special player actor