2019-06-14 11:31:17 +00:00
|
|
|
; SameBoy DMG bootstrap ROM
|
2022-04-18 16:09:16 +00:00
|
|
|
|
|
|
|
INCLUDE "hardware.inc"
|
|
|
|
|
|
|
|
; Registers used only by the boot ROM
|
|
|
|
|
|
|
|
DEF rBANK EQU $FF50
|
|
|
|
|
2016-03-30 20:07:55 +00:00
|
|
|
SECTION "BootCode", ROM0[$0]
|
|
|
|
Start:
|
|
|
|
; Init stack pointer
|
|
|
|
ld sp, $fffe
|
|
|
|
|
|
|
|
; Clear memory VRAM
|
|
|
|
ld hl, $8000
|
|
|
|
|
|
|
|
.clearVRAMLoop
|
|
|
|
ldi [hl], a
|
|
|
|
bit 5, h
|
|
|
|
jr z, .clearVRAMLoop
|
|
|
|
|
|
|
|
; Init Audio
|
|
|
|
ld a, $80
|
2022-04-18 16:09:16 +00:00
|
|
|
ldh [rNR52], a
|
|
|
|
ldh [rNR11], a
|
2016-03-30 20:07:55 +00:00
|
|
|
ld a, $f3
|
2022-04-18 16:09:16 +00:00
|
|
|
ldh [rNR12], a
|
|
|
|
ldh [rNR51], a
|
2016-03-30 20:07:55 +00:00
|
|
|
ld a, $77
|
2022-04-18 16:09:16 +00:00
|
|
|
ldh [rNR50], a
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
; Init BG palette
|
2020-03-06 15:37:18 +00:00
|
|
|
ld a, $54
|
2022-04-18 16:09:16 +00:00
|
|
|
ldh [rBGP], a
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
; Load logo from ROM.
|
|
|
|
; A nibble represents a 4-pixels line, 2 bytes represent a 4x4 tile, scaled to 8x8.
|
|
|
|
; Tiles are ordered left to right, top to bottom.
|
|
|
|
ld de, $104 ; Logo start
|
|
|
|
ld hl, $8010 ; This is where we load the tiles in VRAM
|
|
|
|
|
|
|
|
.loadLogoLoop
|
|
|
|
ld a, [de] ; Read 2 rows
|
|
|
|
ld b, a
|
|
|
|
call DoubleBitsAndWriteRow
|
|
|
|
call DoubleBitsAndWriteRow
|
|
|
|
inc de
|
|
|
|
ld a, e
|
|
|
|
xor $34 ; End of logo
|
|
|
|
jr nz, .loadLogoLoop
|
|
|
|
|
|
|
|
; Load trademark symbol
|
|
|
|
ld de, TrademarkSymbol
|
|
|
|
ld c,$08
|
|
|
|
.loadTrademarkSymbolLoop:
|
|
|
|
ld a,[de]
|
|
|
|
inc de
|
|
|
|
ldi [hl],a
|
|
|
|
inc hl
|
|
|
|
dec c
|
|
|
|
jr nz, .loadTrademarkSymbolLoop
|
|
|
|
|
|
|
|
; Set up tilemap
|
|
|
|
ld a,$19 ; Trademark symbol
|
|
|
|
ld [$9910], a ; ... put in the superscript position
|
|
|
|
ld hl,$992f ; Bottom right corner of the logo
|
|
|
|
ld c,$c ; Tiles in a logo row
|
|
|
|
.tilemapLoop
|
|
|
|
dec a
|
|
|
|
jr z, .tilemapDone
|
|
|
|
ldd [hl], a
|
|
|
|
dec c
|
|
|
|
jr nz, .tilemapLoop
|
|
|
|
ld l,$0f ; Jump to top row
|
|
|
|
jr .tilemapLoop
|
|
|
|
.tilemapDone
|
|
|
|
|
2020-03-06 15:37:18 +00:00
|
|
|
ld a, 30
|
2022-04-18 16:09:16 +00:00
|
|
|
ldh [rSCY], a
|
2020-03-06 15:37:18 +00:00
|
|
|
|
2016-03-30 20:07:55 +00:00
|
|
|
; Turn on LCD
|
|
|
|
ld a, $91
|
2022-04-18 16:09:16 +00:00
|
|
|
ldh [rLCDC], a
|
2016-03-30 20:07:55 +00:00
|
|
|
|
2020-03-06 15:37:18 +00:00
|
|
|
ld d, (-119) & $FF
|
|
|
|
ld c, 15
|
|
|
|
|
|
|
|
.animate
|
|
|
|
call WaitFrame
|
|
|
|
ld a, d
|
|
|
|
sra a
|
|
|
|
sra a
|
2022-04-18 16:09:16 +00:00
|
|
|
ldh [rSCY], a
|
2020-03-06 15:37:18 +00:00
|
|
|
ld a, d
|
|
|
|
add c
|
|
|
|
ld d, a
|
|
|
|
ld a, c
|
|
|
|
cp 8
|
|
|
|
jr nz, .noPaletteChange
|
|
|
|
ld a, $A8
|
2022-04-18 16:09:16 +00:00
|
|
|
ldh [rBGP], a
|
2020-03-06 15:37:18 +00:00
|
|
|
.noPaletteChange
|
|
|
|
dec c
|
|
|
|
jr nz, .animate
|
|
|
|
ld a, $fc
|
2022-04-18 16:09:16 +00:00
|
|
|
ldh [rBGP], a
|
2020-03-06 15:37:18 +00:00
|
|
|
|
2016-03-30 20:07:55 +00:00
|
|
|
; Play first sound
|
|
|
|
ld a, $83
|
|
|
|
call PlaySound
|
2017-12-31 21:02:28 +00:00
|
|
|
ld b, 5
|
2016-03-30 20:07:55 +00:00
|
|
|
call WaitBFrames
|
|
|
|
; Play second sound
|
|
|
|
ld a, $c1
|
|
|
|
call PlaySound
|
2020-03-06 15:37:18 +00:00
|
|
|
|
|
|
|
|
2016-03-30 20:07:55 +00:00
|
|
|
|
2020-03-06 15:37:18 +00:00
|
|
|
; Wait ~1 second
|
|
|
|
ld b, 60
|
2016-03-30 20:07:55 +00:00
|
|
|
call WaitBFrames
|
2016-08-06 16:03:59 +00:00
|
|
|
|
|
|
|
; Set registers to match the original DMG boot
|
2021-10-23 20:28:54 +00:00
|
|
|
IF DEF(MGB)
|
|
|
|
ld hl, $FFB0
|
|
|
|
ELSE
|
2016-08-06 16:03:59 +00:00
|
|
|
ld hl, $01B0
|
2021-10-23 20:28:54 +00:00
|
|
|
ENDC
|
2016-08-06 16:03:59 +00:00
|
|
|
push hl
|
|
|
|
pop af
|
|
|
|
ld hl, $014D
|
|
|
|
ld bc, $0013
|
|
|
|
ld de, $00D8
|
|
|
|
|
2016-03-30 20:07:55 +00:00
|
|
|
; Boot the game
|
|
|
|
jp BootGame
|
|
|
|
|
|
|
|
|
|
|
|
DoubleBitsAndWriteRow:
|
|
|
|
; Double the most significant 4 bits, b is shifted by 4
|
|
|
|
ld a, 4
|
|
|
|
ld c, 0
|
|
|
|
.doubleCurrentBit
|
|
|
|
sla b
|
|
|
|
push af
|
|
|
|
rl c
|
|
|
|
pop af
|
|
|
|
rl c
|
|
|
|
dec a
|
|
|
|
jr nz, .doubleCurrentBit
|
|
|
|
ld a, c
|
|
|
|
; Write as two rows
|
|
|
|
ldi [hl], a
|
|
|
|
inc hl
|
|
|
|
ldi [hl], a
|
|
|
|
inc hl
|
|
|
|
ret
|
|
|
|
|
|
|
|
WaitFrame:
|
2017-12-31 21:02:28 +00:00
|
|
|
push hl
|
|
|
|
ld hl, $FF0F
|
2018-03-29 18:06:53 +00:00
|
|
|
res 0, [hl]
|
2017-12-31 21:02:28 +00:00
|
|
|
.wait
|
|
|
|
bit 0, [hl]
|
|
|
|
jr z, .wait
|
|
|
|
pop hl
|
2016-03-30 20:07:55 +00:00
|
|
|
ret
|
|
|
|
|
|
|
|
WaitBFrames:
|
|
|
|
call WaitFrame
|
|
|
|
dec b
|
|
|
|
jr nz, WaitBFrames
|
|
|
|
ret
|
|
|
|
|
|
|
|
PlaySound:
|
2022-04-18 16:09:16 +00:00
|
|
|
ldh [rNR13], a
|
2016-03-30 20:07:55 +00:00
|
|
|
ld a, $87
|
2022-04-18 16:09:16 +00:00
|
|
|
ldh [rNR14], a
|
2016-03-30 20:07:55 +00:00
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
TrademarkSymbol:
|
|
|
|
db $3c,$42,$b9,$a5,$b9,$a5,$42,$3c
|
|
|
|
|
2016-08-06 16:03:59 +00:00
|
|
|
SECTION "BootGame", ROM0[$fe]
|
2016-03-30 20:07:55 +00:00
|
|
|
BootGame:
|
2022-04-18 16:09:16 +00:00
|
|
|
ldh [rBANK], a ; unmap boot ROM
|