actor: wip 16 bit positions origin/movement-rework
authorLukas Krickl <lukas@krickl.dev>
Sat, 20 Sep 2025 04:22:11 +0000 (06:22 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sat, 20 Sep 2025 04:22:11 +0000 (06:22 +0200)
src/actor.s
src/defs.s
src/macros.inc
src/player.s

index 8fe56ac4caf26c7f7d010f440c419c8cb9da34e9..6aafc46aee7eb6954b273b19929fc673f8323534 100644 (file)
@@ -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
 
index 43bdf5255c5b874ce56e4f4871bb2918e8f58ecb..3876289702f5fe52ac9345d65b720c501f73c1e8 100644 (file)
@@ -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
index a12aabe06b8d057f629b1059bbcb3fa346cd5de7..0a0553752bbc01fb18d86fd051e1aff9d71a8ff4 100644 (file)
@@ -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
index f05c71e312099b2090d6c9ec1dd70b5bac57b6d2..2b5b478849e9ca3d9c77b6ea25b6a63ef9f32fda 100644 (file)
@@ -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