video: made scroll smooth
authorLukas Krickl <lukas@krickl.dev>
Sat, 20 Sep 2025 16:01:20 +0000 (18:01 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sat, 20 Sep 2025 16:01:20 +0000 (18:01 +0200)
src/video.s
src/wram.s

index 8b4dc6260db81aae48b5d709dfc54817cc6d1987..657c927e8083f853946c286ee860b41a367f0854 100644 (file)
@@ -22,33 +22,48 @@ vblank:
   ; get inputs 
   call poll_inputs
 
+       call video_map_adjust_scroll
+
   ld a, 1
   ld [frame_ready], a
   pop_all
   ret
        
        ; scrolls if the flag is set
+       ; loads a new map row and sets the scroll
+       ; timer
 video_map_perform_scroll:
        ld a, [game_flags]
        and a, GPF_SCROLL
        ret z
 
-       ld a, [scroll_y]
-       sub a, MAP_ROW_H
-       ld [scroll_y], a
-
-       ld a, [player_next_scroll_y]
-       ; 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
+
+       ld a, MAP_ROW_H
+       ld [scroll_timer], a
+       ret
+       
+       ; adjusts the scroll slowly 1 pixel each frame
+       ; until the timer reaches 0
+video_map_adjust_scroll:
+       ld a, [scroll_timer]
+       cp a, 0
+       ret z
+
+       dec a
+       ld [scroll_timer], a
+
+
+       ld a, [scroll_y]
+       dec a
+       ld [scroll_y], a
+
+       call scroll_up_adjust
        ret
        
        ; adjusts all actors and rectangles positions
@@ -63,7 +78,7 @@ scroll_up_adjust:
        ld de, act_pos_y
        add hl, de
        ld a, [hl]
-       add a, MAP_ROW_H
+       add a, 1
        ld [hl+], a ; hl = page y pos hi
 
        ld a, [hl]
@@ -77,6 +92,16 @@ scroll_up_adjust:
        add hl, de
        jr nz, @act_loop REL
 
+       ; adjust player
+
+       ld a, [player+act_pos_y]
+       add a, 1
+       ld [player+act_pos_y], a
+
+       ld a, [player+act_pos_y_hi]
+       adc a, 0
+       ld [player+act_pos_y_hi], a
+
        ; TODO: adjust rectangles
        ret
 
index adb6125f0de1502bbc207849db1ba98f54d3fc58..9728ae847c45823a52707c0d59ad3069e7fdec6d 100644 (file)
@@ -43,6 +43,8 @@ demo_inputs: .adv 2
        ; gameplay control flags
 game_flags: .adv 1
 
+scroll_timer: .adv 1
+
 ; dummy oam 
 ; same memory as empty_unit
 empty_oam: .adv oamsize