actor: adjusting actors with scroll
authorLukas Krickl <lukas@krickl.dev>
Sat, 20 Sep 2025 15:01:19 +0000 (17:01 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sat, 20 Sep 2025 15:01:19 +0000 (17:01 +0200)
Fixed map row draw not wrapping when reaching end of scrn0

src/actor.s
src/defs.s
src/map.s
src/mapobj.s
src/player.s
src/video.s

index aa5396e12c967282a64167b37479d5fdbd90a6e4..29632a39a7f10224695340ed5e03ed938a951282 100644 (file)
@@ -31,9 +31,6 @@ actor_draw:
        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
 
        ld b, a
        ld a, [de] ; a = y_hi
@@ -120,7 +117,7 @@ actor_load_test:
        call memcpy
 
        ; set a test position
-       ld a, 130
+       ld a, 30
        ld [actors+act_pos_y], a
        ld [actors+act_pos_x], a
 
index 319a96b37c2c9c6e31b9131faa583aa3b11c4af8..dab08a275743fa88bb2c83ec134e846e2568f64d 100644 (file)
@@ -93,6 +93,7 @@
 
        ; map object types
 .se 0
+.de MOT_NOP, 1
 .de MOT_SET_PAT, 1
 .de MOT_DISABLE_SCROLL, 1
 .de MOT_ENABLE_SCROLL, 1
index 5c593843f86b04873fab48e29bd125d402788311..09b1c5c7dbf76635b66f8645c3252a38b137026e 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -180,6 +180,16 @@ map_advance_row:
        ld a, h
        ld [map_scrn_ptr+1], a
        
+       ; check if we reached the last row of scrn0
+       cp a, 0x97 
+       jr nz, @not_end_of_scrn0 REL
+               ; end of scrn0 - wrap around back to first row
+               ld a, SCRN0_END LO
+               ld [map_scrn_ptr], a
+               ld a, SCRN0_END HI
+               ld [map_scrn_ptr+1], a
+@not_end_of_scrn0:
+       
        ; move to next row
        ld a, [map_curr_row]
        inc a
@@ -227,3 +237,4 @@ l1_map:
 l1_objs:
        modef MOT_SET_PAT, 0, 3, pat_center_grass 
        modef MOT_SET_PAT, 0, 5, pat_empty
+       modef MOT_NOP, 0, 0xFF, 0
index fbd0c33edcb905fc209266680ab20ad8af36b033..2ceab5d0a7d4f458c24af1e800b0f0f744359a3e 100644 (file)
@@ -6,12 +6,16 @@
 ; when an object is off-screen it is unloded
 
 mo_routines:
+        dw mo_nop
         dw mo_set_pat
         dw mo_disable_scroll
         dw mo_enable_scroll
         dw mo_rect
         dw mo_actor_spawner
        
+mo_nop:
+       ret
+
        ; executes all map objects in the map object list 
        ; until the mo's row != current row
        ; advances mo ptr
index e0eb4f5d3975c5bcf9f4f82ff82a81f1a5643c42..5949dcd7feebc94788b2db2806f89a38b24c5471 100644 (file)
@@ -3,15 +3,15 @@
        ; sets up the player actor
 player_init:
        ; initial position
-       ld a, 132
+       ld a, 0
        ld [player+act_pos_y], a
-       ld a, 24
+       ld a, 0
        ld [player+act_pos_x], a
 
        ld a, 0 
        ld [player+act_pos_y_hi], a
 
-       ld a, 0xA0 ; initial next scroll
+       ld a, 0x30 ; initial next scroll
        ld [player_next_scroll_y], a
        ret
        
index 7a223904c2f25316f26d08ea0f5aa7a8d6804183..8b4dc6260db81aae48b5d709dfc54817cc6d1987 100644 (file)
@@ -10,11 +10,12 @@ vblank:
   ld a, [RLCD]
   or a, LCDCF_OBJON
   ld [RLCD], a
+       
+       call video_map_perform_scroll
   
   ; dma previous frame's oam
   call OAMDMAFN
 
-       call video_map_perform_scroll
 
   call scroll_write
   
@@ -37,17 +38,47 @@ video_map_perform_scroll:
        ld [scroll_y], a
 
        ld a, [player_next_scroll_y]
-       sub a, MAP_ROW_H
+       ; sub a, MAP_ROW_H/2
        ld [player_next_scroll_y], a
        
        call map_advance_row
 
+       call scroll_up_adjust
+
        ; unset flag
        ld a, [game_flags]
        and a, ~GPF_SCROLL & 0xFF
        ld [game_flags], a
        ret
+       
+       ; adjusts all actors and rectangles positions
+       ; when a scroll occurs
+scroll_up_adjust:
+       ld b, ACTS_MAX
+       ld hl, actors
+
+@act_loop:
+       push hl
+
+       ld de, act_pos_y
+       add hl, de
+       ld a, [hl]
+       add a, MAP_ROW_H
+       ld [hl+], a ; hl = page y pos hi
+
+       ld a, [hl]
+       adc a, 0
+       ld [hl], a
+
+       pop hl
+       
+       dec b
+       ld de, act_size
+       add hl, de
+       jr nz, @act_loop REL
 
+       ; TODO: adjust rectangles
+       ret
 
   ; writes scroll to scroll registers
   ; only call during blank