From 785f2510a248fa892531b4b4ecdb4cac9f48e305 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Mon, 7 Jul 2025 09:11:57 +0200 Subject: [PATCH] video: Added fade out and fade in for map transitions --- src/player.s | 19 ++++++++++++++----- src/video.s | 51 +++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 59 insertions(+), 11 deletions(-) diff --git a/src/player.s b/src/player.s index e089bee..e93d821 100644 --- a/src/player.s +++ b/src/player.s @@ -99,6 +99,9 @@ unit_check_exit_hit: ret z ; if not input bail @skip_input_check: + ; fade out + call video_fade_out + ; now we can load the map ; load map ptr @@ -106,8 +109,6 @@ unit_check_exit_hit: ld de, exit_to add hl, de ; hl = map ptr - ; fade out - call video_fade_out ld a, [hl+] ld c, a @@ -117,9 +118,6 @@ unit_check_exit_hit: ld l, a ; hl = map header ptr call map_load - ; fade back in - call video_fade_in - pop bc ; bc = exit table now ; finally adjust player position @@ -153,6 +151,17 @@ unit_check_exit_hit: call z, map_exit_absolute_adjust call nz, map_exit_relative_adjust + + ; scroll to player's position + ld de, player_unit + call unit_scroll_center + call next_vblank_wait + call scroll_write + + ; fade back in + call video_fade_in + + ret ; adjusts player position to aboslute diff --git a/src/video.s b/src/video.s index 5b712ad..7b5fa9d 100644 --- a/src/video.s +++ b/src/video.s @@ -126,34 +126,73 @@ video_wait_n_frames: or a, c jr nz, video_wait_n_frames REL ret - + + ; sets BGP | $1 + ; and then waits + ; inputs: + ; $1: BGP +#macro video_fade_set_bgp + ld a, BGP + and a, $1 + ld [RBGP], a + + ; wait for 5 frames + ld bc, 0x4 + call video_wait_n_frames +#endmacro + ; fades out the background ; interrupts must be enabled ; preserved all registers + ; disables window video_fade_out: - push_all + push_all + + ; disable winodw + ld a, [RLCD] + and a, ~LCDF_WINDOWON & 0xFF + ld [RLCD], a - ld bc, 0xF - call video_wait_n_frames + video_fade_set_bgp 0b11111111 + video_fade_set_bgp 0b11111100 + video_fade_set_bgp 0b11110000 + video_fade_set_bgp 0b11000000 + video_fade_set_bgp 0b00000000 pop_all ret + + ; fades the background in ; sets RBGP to BGP ; interrupts must be enabled ; preserved all registers + ; enables window video_fade_in: push_all - ld bc, 0xF - call video_wait_n_frames + ; disable winodw + ld a, [RLCD] + and a, ~LCDF_WINDOWON & 0xFF + ld [RLCD], a + + video_fade_set_bgp 0b11000000 + video_fade_set_bgp 0b11110000 + video_fade_set_bgp 0b11111100 + video_fade_set_bgp 0b11111111 + + ; re-enable window + ld a, [RLCD] + or a, LCDF_WINDOWON + ld [RLCD], a ld a, BGP ld [RBGP], a pop_all ret +#undefine video_fade_set_bgp ; loads tilesets ; inputs: -- 2.30.2