Skip to content

Commit 4580286

Browse files
Seamless bootup logo transition
1 parent 4b1c7e5 commit 4580286

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

inc/common.inc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
; Copyright (c) 2025 Dmitry Shechtman
44

55

6+
; https://github.com/gbdev/hardware.inc/pull/75
67
DEF BOOTUP_B_DMG0 EQU $FF
78

89
DEF MAP_LOGO EQU TILEMAP0
@@ -27,10 +28,11 @@ MACRO CLEAR_LONG
2728
ENDM
2829

2930
; @param \1 Page-aligned Tiles prefix
30-
MACRO COPY_1BPP
31+
MACRO COPY_1BPP_SAFE
3132
ASSERT(HIGH(\1Tiles.end - \1Tiles))
3233
ld bc, HIGH(\1Tiles.end - \1Tiles) ; Clear B and set C to the page count
3334
.loop\@
35+
rst WaitVRAM ; Wait for VRAM to become accessible
3436
ld a, [de] ; Load a byte from the address DE points to into the A register
3537
ld [hli], a ; Load the byte in the A register to the address HL points to
3638
ld [hli], a ; Repeat for the second bitplane
@@ -41,7 +43,7 @@ ASSERT(HIGH(\1Tiles.end - \1Tiles))
4143
jr nz, .loop\@ ; Stop if C is zero, otherwise keep looping
4244
ENDM
4345

44-
; @param \1 Page aligned Tiles prefix
46+
; @param \1 Page-aligned Tiles prefix
4547
MACRO COPY_2BPP
4648
ASSERT(HIGH(\1Tiles.end - \1Tiles))
4749
ld bc, HIGH(\1Tiles.end - \1Tiles) ; Clear B and set C to the page count

src/intro/intro.asm

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ include "intro.inc"
99

1010
MACRO INTRO_META_INIT
1111
ld hl, MAP_INTRO_\1 + ROW_INTRO_\1 * TILEMAP_WIDTH + COL_INTRO_\1
12+
rst WaitVRAM ; Wait for VRAM to become accessible
1213
ld a, T_INTRO_\1 ; Load top left tile ID
1314
ld [hli], a ; Set top left tile and advance to the right
1415
ld a, T_INTRO_\1 + 2 ; Load top right tile ID
@@ -51,12 +52,12 @@ ENDM
5152
; License: CC0 1.0 (https://creativecommons.org/publicdomain/zero/1.0/)
5253

5354
SECTION "Start", ROM0[$0100]
54-
di ; Disable interrupts during setup
55-
jr EntryPoint ; Jump past the header space to our actual code
56-
ds $150 - @, 0 ; Allocate space for RGBFIX to insert our ROM header
55+
di ; Disable interrupts during setup
56+
jr EntryPoint ; Jump past the header space to our actual code
57+
ds $150 - @, 0 ; Allocate space for RGBFIX to insert our ROM header
5758

5859
EntryPoint:
59-
ld sp, $E000 ; Set the stack pointer to the end of WRAM
60+
ld sp, $E000 ; Set the stack pointer to the end of WRAM
6061

6162
xor a
6263
ldh [rAUDENA], a ; Shut down audio circuitry
@@ -104,17 +105,9 @@ EntryPoint:
104105
cp OAM_SIZE ; End of OAM reached?
105106
jr nz, .clearOAMLoop ; If not, continue looping
106107

107-
.waitVBlank
108-
ldh a, [rLY] ; Read the LY register to check the current scanline
109-
cp SCREEN_HEIGHT_PX ; Compare the current scanline to the first scanline of VBlank
110-
jr c, .waitVBlank ; Loop as long as the carry flag is set
111-
112-
xor a ; Once we exit the loop we're safely in VBlank
113-
ldh [rLCDC], a ; Disable the LCD (must be done during VBlank to protect the LCD)
114-
115108
ld de, IntroTiles
116109
ld hl, STARTOF(VRAM) | T_INTRO_REG << 4
117-
COPY_1BPP Intro
110+
COPY_1BPP_SAFE Intro
118111

119112
call ClearBackground ; Clear the logo from the background
120113
INTRO_META_INIT BY ; Draw BY on the background
@@ -275,8 +268,9 @@ ClearBackground:
275268

276269
ClearLogo:
277270
ld c, LOGO_WIDTH + 1 ; Clear ®
278-
xor a
279271
.loop
272+
rst WaitVRAM ; Wait for VRAM to become accessible
273+
xor a
280274
ld [hli], a
281275
dec c
282276
jr nz, .loop
@@ -290,16 +284,18 @@ ClearWindow:
290284

291285
SetWindow:
292286
ld hl, TILEMAP1 + 4
293-
ld a, T_LOGO
287+
ld b, T_LOGO
294288
call .logo
295289
ld l, TILEMAP_WIDTH + 4
296290
; Fall through
297291

298292
.logo:
299293
ld c, LOGO_WIDTH
300294
.loop
301-
ld [hli], a
302-
inc a
295+
rst WaitVRAM
296+
ld [hl], b
297+
inc l
298+
inc b
303299
dec c
304300
jr nz, .loop
305301
ret

src/oamdma.asm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
include "hardware.inc"
66

77

8+
SECTION "WaitVRAM", ROM0[$30]
9+
WaitVRAM::
10+
ldh a, [rSTAT] ; Check the STAT register to figure out which mode the LCD is in
11+
and STAT_BUSY ; AND the value to see if VRAM access is safe
12+
jr nz, WaitVRAM ; If not, proceed to loop
13+
nop ; Wait for 1 M-cycle
14+
ret ; Return when VRAM access is safe
15+
16+
817
SECTION "WaitVBlank", ROM0[$38]
918
WaitVBlank::
1019
halt ; Wait for interrupt

0 commit comments

Comments
 (0)