2019-06-14 11:31:17 +00:00
|
|
|
; SameBoy CGB bootstrap ROM
|
2016-03-30 20:07:55 +00:00
|
|
|
; Todo: use friendly names for HW registers instead of magic numbers
|
|
|
|
SECTION "BootCode", ROM0[$0]
|
|
|
|
Start:
|
|
|
|
; Init stack pointer
|
2018-04-03 17:10:11 +00:00
|
|
|
ld sp, $fffe
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
; Clear memory VRAM
|
2018-04-03 17:10:11 +00:00
|
|
|
ld hl, $8000
|
|
|
|
call ClearMemoryPage
|
2019-06-08 21:53:44 +00:00
|
|
|
ld a, 2
|
|
|
|
ld c, $70
|
|
|
|
ld [c], a
|
|
|
|
; Clear RAM Bank 2 (Like the original boot ROM
|
|
|
|
ld h, $D0
|
|
|
|
xor a
|
2018-04-03 17:10:11 +00:00
|
|
|
call ClearMemoryPage
|
2019-06-08 21:53:44 +00:00
|
|
|
ld [c], a
|
2016-03-30 20:07:55 +00:00
|
|
|
|
2019-06-08 21:53:44 +00:00
|
|
|
; Clear chosen input palette
|
|
|
|
ldh [InputPalette], a
|
|
|
|
; Clear title checksum
|
|
|
|
ldh [TitleChecksum], a
|
|
|
|
|
2016-03-30 20:07:55 +00:00
|
|
|
; Clear OAM
|
2019-06-08 21:53:44 +00:00
|
|
|
ld h, $fe
|
2018-04-03 17:10:11 +00:00
|
|
|
ld c, $a0
|
2016-03-30 20:07:55 +00:00
|
|
|
.clearOAMLoop
|
2018-04-03 17:10:11 +00:00
|
|
|
ldi [hl], a
|
|
|
|
dec c
|
|
|
|
jr nz, .clearOAMLoop
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
; Init Audio
|
2018-04-03 17:10:11 +00:00
|
|
|
ld a, $80
|
|
|
|
ldh [$26], a
|
|
|
|
ldh [$11], a
|
|
|
|
ld a, $f3
|
|
|
|
ldh [$12], a
|
|
|
|
ldh [$25], a
|
|
|
|
ld a, $77
|
|
|
|
ldh [$24], a
|
|
|
|
|
|
|
|
call InitWaveform
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
; Init BG palette
|
2018-04-03 17:10:11 +00:00
|
|
|
ld a, $fc
|
|
|
|
ldh [$47], 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.
|
|
|
|
; These tiles are not used, but are required for DMG compatibility. This is done
|
|
|
|
; by the original CGB Boot ROM as well.
|
2018-04-03 17:10:11 +00:00
|
|
|
ld de, $104 ; Logo start
|
|
|
|
ld hl, $8010 ; This is where we load the tiles in VRAM
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
.loadLogoLoop
|
2018-04-03 17:10:11 +00:00
|
|
|
ld a, [de] ; Read 2 rows
|
|
|
|
ld b, a
|
2019-06-10 15:45:14 +00:00
|
|
|
call DoubleBitsAndWriteRowTwice
|
2018-04-03 17:10:11 +00:00
|
|
|
inc de
|
|
|
|
ld a, e
|
2019-06-10 15:45:14 +00:00
|
|
|
cp $34 ; End of logo
|
2018-04-03 17:10:11 +00:00
|
|
|
jr nz, .loadLogoLoop
|
|
|
|
call ReadTrademarkSymbol
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
; Clear the second VRAM bank
|
2018-04-03 17:10:11 +00:00
|
|
|
ld a, 1
|
|
|
|
ldh [$4F], a
|
|
|
|
xor a
|
|
|
|
ld hl, $8000
|
|
|
|
call ClearMemoryPage
|
2019-06-10 15:45:14 +00:00
|
|
|
call LoadTileset
|
2016-03-30 20:07:55 +00:00
|
|
|
|
2018-04-03 17:10:11 +00:00
|
|
|
ld b, 3
|
2019-05-04 18:15:23 +00:00
|
|
|
IF DEF(FAST)
|
|
|
|
xor a
|
|
|
|
ldh [$4F], a
|
2019-06-09 13:15:08 +00:00
|
|
|
ELSE
|
2019-06-10 15:45:14 +00:00
|
|
|
; Load Tilemap
|
|
|
|
ld hl, $98C2
|
|
|
|
ld d, 3
|
2019-06-09 13:15:08 +00:00
|
|
|
ld a, 8
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
.tilemapLoop
|
2018-04-03 17:10:11 +00:00
|
|
|
ld c, $10
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
.tilemapRowLoop
|
|
|
|
|
2018-04-03 17:10:11 +00:00
|
|
|
push af
|
|
|
|
; Switch to second VRAM Bank
|
|
|
|
ld a, 1
|
|
|
|
ldh [$4F], a
|
2019-06-09 13:15:08 +00:00
|
|
|
ld [hl], 8
|
2018-04-03 17:10:11 +00:00
|
|
|
; Switch to back first VRAM Bank
|
|
|
|
xor a
|
|
|
|
ldh [$4F], a
|
|
|
|
pop af
|
|
|
|
ldi [hl], a
|
2019-06-10 15:45:14 +00:00
|
|
|
add d
|
2018-04-03 17:10:11 +00:00
|
|
|
dec c
|
|
|
|
jr nz, .tilemapRowLoop
|
2019-06-10 15:45:14 +00:00
|
|
|
sub 47
|
|
|
|
push de
|
2018-04-03 17:10:11 +00:00
|
|
|
ld de, $10
|
|
|
|
add hl, de
|
2019-06-10 15:45:14 +00:00
|
|
|
pop de
|
2018-04-03 17:10:11 +00:00
|
|
|
dec b
|
|
|
|
jr nz, .tilemapLoop
|
|
|
|
|
2019-06-10 15:45:14 +00:00
|
|
|
dec d
|
|
|
|
jr z, .endTilemap
|
|
|
|
dec d
|
2018-04-03 17:10:11 +00:00
|
|
|
|
2019-06-10 15:45:14 +00:00
|
|
|
ld a, $38
|
|
|
|
ld l, $a7
|
|
|
|
ld bc, $0107
|
2018-04-03 17:10:11 +00:00
|
|
|
jr .tilemapRowLoop
|
2019-06-10 15:45:14 +00:00
|
|
|
.endTilemap
|
|
|
|
ENDC
|
2016-03-30 20:07:55 +00:00
|
|
|
|
2018-04-03 17:10:11 +00:00
|
|
|
; Expand Palettes
|
|
|
|
ld de, AnimationColors
|
|
|
|
ld c, 8
|
|
|
|
ld hl, BgPalettes
|
|
|
|
xor a
|
2016-03-30 20:07:55 +00:00
|
|
|
.expandPalettesLoop:
|
2018-11-10 19:10:09 +00:00
|
|
|
IF !DEF(FAST)
|
2018-04-03 17:10:11 +00:00
|
|
|
cpl
|
2018-11-10 19:10:09 +00:00
|
|
|
ENDC
|
2018-04-03 17:10:11 +00:00
|
|
|
; One white
|
|
|
|
ldi [hl], a
|
|
|
|
ldi [hl], a
|
|
|
|
|
2018-11-10 19:10:09 +00:00
|
|
|
IF DEF(FAST)
|
|
|
|
; 3 more whites
|
|
|
|
ldi [hl], a
|
|
|
|
ldi [hl], a
|
|
|
|
ldi [hl], a
|
|
|
|
ldi [hl], a
|
|
|
|
ldi [hl], a
|
|
|
|
ldi [hl], a
|
|
|
|
ELSE
|
2018-04-03 17:10:11 +00:00
|
|
|
; The actual color
|
|
|
|
ld a, [de]
|
|
|
|
inc de
|
|
|
|
ldi [hl], a
|
|
|
|
ld a, [de]
|
|
|
|
inc de
|
|
|
|
ldi [hl], a
|
|
|
|
|
|
|
|
xor a
|
|
|
|
; Two blacks
|
|
|
|
ldi [hl], a
|
|
|
|
ldi [hl], a
|
|
|
|
ldi [hl], a
|
|
|
|
ldi [hl], a
|
2018-11-10 19:10:09 +00:00
|
|
|
ENDC
|
2018-04-03 17:10:11 +00:00
|
|
|
|
|
|
|
dec c
|
|
|
|
jr nz, .expandPalettesLoop
|
|
|
|
|
|
|
|
ld hl, BgPalettes
|
2019-06-10 15:45:14 +00:00
|
|
|
call LoadBGPalettes64
|
2018-04-03 17:10:11 +00:00
|
|
|
|
|
|
|
; Turn on LCD
|
|
|
|
ld a, $91
|
|
|
|
ldh [$40], a
|
|
|
|
|
2018-11-10 19:10:09 +00:00
|
|
|
IF !DEF(FAST)
|
2018-04-03 17:10:11 +00:00
|
|
|
call DoIntroAnimation
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
; Wait ~0.75 seconds
|
2018-04-03 17:10:11 +00:00
|
|
|
ld b, 45
|
|
|
|
call WaitBFrames
|
|
|
|
|
|
|
|
; Play first sound
|
|
|
|
ld a, $83
|
|
|
|
call PlaySound
|
|
|
|
ld b, 5
|
|
|
|
call WaitBFrames
|
|
|
|
; Play second sound
|
|
|
|
ld a, $c1
|
|
|
|
call PlaySound
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
; Wait ~0.5 seconds
|
2018-04-03 17:10:11 +00:00
|
|
|
ld a, 30
|
|
|
|
ldh [WaitLoopCounter], a
|
|
|
|
|
2017-06-09 16:52:40 +00:00
|
|
|
.waitLoop
|
2018-04-03 17:10:11 +00:00
|
|
|
call GetInputPaletteIndex
|
|
|
|
call WaitFrame
|
|
|
|
ld hl, WaitLoopCounter
|
|
|
|
dec [hl]
|
|
|
|
jr nz, .waitLoop
|
2018-11-10 19:10:09 +00:00
|
|
|
ELSE
|
|
|
|
ld a, $c1
|
|
|
|
call PlaySound
|
|
|
|
ENDC
|
2018-04-03 17:10:11 +00:00
|
|
|
call Preboot
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
; Will be filled with NOPs
|
|
|
|
|
|
|
|
SECTION "BootGame", ROM0[$fe]
|
|
|
|
BootGame:
|
2018-04-03 17:10:11 +00:00
|
|
|
ldh [$50], a
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
SECTION "MoreStuff", ROM0[$200]
|
|
|
|
|
|
|
|
; Game Palettes Data
|
|
|
|
TitleChecksums:
|
2018-04-03 17:10:11 +00:00
|
|
|
db $00 ; Default
|
|
|
|
db $88 ; ALLEY WAY
|
|
|
|
db $16 ; YAKUMAN
|
|
|
|
db $36 ; BASEBALL, (Game and Watch 2)
|
|
|
|
db $D1 ; TENNIS
|
|
|
|
db $DB ; TETRIS
|
|
|
|
db $F2 ; QIX
|
|
|
|
db $3C ; DR.MARIO
|
|
|
|
db $8C ; RADARMISSION
|
|
|
|
db $92 ; F1RACE
|
|
|
|
db $3D ; YOSSY NO TAMAGO
|
|
|
|
db $5C ;
|
|
|
|
db $58 ; X
|
|
|
|
db $C9 ; MARIOLAND2
|
|
|
|
db $3E ; YOSSY NO COOKIE
|
|
|
|
db $70 ; ZELDA
|
|
|
|
db $1D ;
|
|
|
|
db $59 ;
|
|
|
|
db $69 ; TETRIS FLASH
|
|
|
|
db $19 ; DONKEY KONG
|
|
|
|
db $35 ; MARIO'S PICROSS
|
|
|
|
db $A8 ;
|
|
|
|
db $14 ; POKEMON RED, (GAMEBOYCAMERA G)
|
|
|
|
db $AA ; POKEMON GREEN
|
|
|
|
db $75 ; PICROSS 2
|
|
|
|
db $95 ; YOSSY NO PANEPON
|
|
|
|
db $99 ; KIRAKIRA KIDS
|
|
|
|
db $34 ; GAMEBOY GALLERY
|
|
|
|
db $6F ; POCKETCAMERA
|
|
|
|
db $15 ;
|
|
|
|
db $FF ; BALLOON KID
|
|
|
|
db $97 ; KINGOFTHEZOO
|
|
|
|
db $4B ; DMG FOOTBALL
|
|
|
|
db $90 ; WORLD CUP
|
|
|
|
db $17 ; OTHELLO
|
|
|
|
db $10 ; SUPER RC PRO-AM
|
|
|
|
db $39 ; DYNABLASTER
|
|
|
|
db $F7 ; BOY AND BLOB GB2
|
|
|
|
db $F6 ; MEGAMAN
|
|
|
|
db $A2 ; STAR WARS-NOA
|
|
|
|
db $49 ;
|
|
|
|
db $4E ; WAVERACE
|
|
|
|
db $43 | $80 ;
|
|
|
|
db $68 ; LOLO2
|
|
|
|
db $E0 ; YOSHI'S COOKIE
|
|
|
|
db $8B ; MYSTIC QUEST
|
|
|
|
db $F0 ;
|
|
|
|
db $CE ; TOPRANKINGTENNIS
|
|
|
|
db $0C ; MANSELL
|
|
|
|
db $29 ; MEGAMAN3
|
|
|
|
db $E8 ; SPACE INVADERS
|
|
|
|
db $B7 ; GAME&WATCH
|
|
|
|
db $86 ; DONKEYKONGLAND95
|
|
|
|
db $9A ; ASTEROIDS/MISCMD
|
|
|
|
db $52 ; STREET FIGHTER 2
|
|
|
|
db $01 ; DEFENDER/JOUST
|
|
|
|
db $9D ; KILLERINSTINCT95
|
|
|
|
db $71 ; TETRIS BLAST
|
|
|
|
db $9C ; PINOCCHIO
|
|
|
|
db $BD ;
|
|
|
|
db $5D ; BA.TOSHINDEN
|
|
|
|
db $6D ; NETTOU KOF 95
|
|
|
|
db $67 ;
|
|
|
|
db $3F ; TETRIS PLUS
|
|
|
|
db $6B ; DONKEYKONGLAND 3
|
2016-03-30 20:07:55 +00:00
|
|
|
; For these games, the 4th letter is taken into account
|
|
|
|
FirstChecksumWithDuplicate:
|
2018-04-03 17:10:11 +00:00
|
|
|
; Let's play hangman!
|
|
|
|
db $B3 ; ???[B]????????
|
|
|
|
db $46 ; SUP[E]R MARIOLAND
|
|
|
|
db $28 ; GOL[F]
|
|
|
|
db $A5 ; SOL[A]RSTRIKER
|
|
|
|
db $C6 ; GBW[A]RS
|
|
|
|
db $D3 ; KAE[R]UNOTAMENI
|
|
|
|
db $27 ; ???[B]????????
|
|
|
|
db $61 ; POK[E]MON BLUE
|
|
|
|
db $18 ; DON[K]EYKONGLAND
|
|
|
|
db $66 ; GAM[E]BOY GALLERY2
|
|
|
|
db $6A ; DON[K]EYKONGLAND 2
|
|
|
|
db $BF ; KID[ ]ICARUS
|
|
|
|
db $0D ; TET[R]IS2
|
|
|
|
db $F4 ; ???[-]????????
|
|
|
|
db $B3 ; MOG[U]RANYA
|
|
|
|
db $46 ; ???[R]????????
|
|
|
|
db $28 ; GAL[A]GA&GALAXIAN
|
|
|
|
db $A5 ; BT2[R]AGNAROKWORLD
|
|
|
|
db $C6 ; KEN[ ]GRIFFEY JR
|
|
|
|
db $D3 ; ???[I]????????
|
|
|
|
db $27 ; MAG[N]ETIC SOCCER
|
|
|
|
db $61 ; VEG[A]S STAKES
|
|
|
|
db $18 ; ???[I]????????
|
|
|
|
db $66 ; MIL[L]I/CENTI/PEDE
|
|
|
|
db $6A ; MAR[I]O & YOSHI
|
|
|
|
db $BF ; SOC[C]ER
|
|
|
|
db $0D ; POK[E]BOM
|
|
|
|
db $F4 ; G&W[ ]GALLERY
|
|
|
|
db $B3 ; TET[R]IS ATTACK
|
2016-03-30 20:07:55 +00:00
|
|
|
ChecksumsEnd:
|
|
|
|
|
|
|
|
PalettePerChecksum:
|
2016-04-15 22:14:30 +00:00
|
|
|
; | $80 means game requires DMG boot tilemap
|
2018-04-03 17:10:11 +00:00
|
|
|
db 0 ; Default Palette
|
|
|
|
db 4 ; ALLEY WAY
|
|
|
|
db 5 ; YAKUMAN
|
|
|
|
db 35 ; BASEBALL, (Game and Watch 2)
|
|
|
|
db 34 ; TENNIS
|
|
|
|
db 3 ; TETRIS
|
|
|
|
db 31 ; QIX
|
|
|
|
db 15 ; DR.MARIO
|
|
|
|
db 10 ; RADARMISSION
|
|
|
|
db 5 ; F1RACE
|
|
|
|
db 19 ; YOSSY NO TAMAGO
|
|
|
|
db 36 ;
|
|
|
|
db 7 | $80 ; X
|
|
|
|
db 37 ; MARIOLAND2
|
|
|
|
db 30 ; YOSSY NO COOKIE
|
|
|
|
db 44 ; ZELDA
|
|
|
|
db 21 ;
|
|
|
|
db 32 ;
|
|
|
|
db 31 ; TETRIS FLASH
|
|
|
|
db 20 ; DONKEY KONG
|
|
|
|
db 5 ; MARIO'S PICROSS
|
|
|
|
db 33 ;
|
|
|
|
db 13 ; POKEMON RED, (GAMEBOYCAMERA G)
|
|
|
|
db 14 ; POKEMON GREEN
|
|
|
|
db 5 ; PICROSS 2
|
|
|
|
db 29 ; YOSSY NO PANEPON
|
|
|
|
db 5 ; KIRAKIRA KIDS
|
|
|
|
db 18 ; GAMEBOY GALLERY
|
|
|
|
db 9 ; POCKETCAMERA
|
|
|
|
db 3 ;
|
|
|
|
db 2 ; BALLOON KID
|
|
|
|
db 26 ; KINGOFTHEZOO
|
|
|
|
db 25 ; DMG FOOTBALL
|
|
|
|
db 25 ; WORLD CUP
|
|
|
|
db 41 ; OTHELLO
|
|
|
|
db 42 ; SUPER RC PRO-AM
|
|
|
|
db 26 ; DYNABLASTER
|
|
|
|
db 45 ; BOY AND BLOB GB2
|
|
|
|
db 42 ; MEGAMAN
|
|
|
|
db 45 ; STAR WARS-NOA
|
|
|
|
db 36 ;
|
|
|
|
db 38 ; WAVERACE
|
|
|
|
db 26 ;
|
|
|
|
db 42 ; LOLO2
|
|
|
|
db 30 ; YOSHI'S COOKIE
|
|
|
|
db 41 ; MYSTIC QUEST
|
|
|
|
db 34 ;
|
|
|
|
db 34 ; TOPRANKINGTENNIS
|
|
|
|
db 5 ; MANSELL
|
|
|
|
db 42 ; MEGAMAN3
|
|
|
|
db 6 ; SPACE INVADERS
|
|
|
|
db 5 ; GAME&WATCH
|
|
|
|
db 33 ; DONKEYKONGLAND95
|
|
|
|
db 25 ; ASTEROIDS/MISCMD
|
|
|
|
db 42 ; STREET FIGHTER 2
|
|
|
|
db 42 ; DEFENDER/JOUST
|
|
|
|
db 40 ; KILLERINSTINCT95
|
|
|
|
db 2 ; TETRIS BLAST
|
|
|
|
db 16 ; PINOCCHIO
|
|
|
|
db 25 ;
|
|
|
|
db 42 ; BA.TOSHINDEN
|
|
|
|
db 42 ; NETTOU KOF 95
|
|
|
|
db 5 ;
|
|
|
|
db 0 ; TETRIS PLUS
|
|
|
|
db 39 ; DONKEYKONGLAND 3
|
|
|
|
db 36 ;
|
|
|
|
db 22 ; SUPER MARIOLAND
|
|
|
|
db 25 ; GOLF
|
|
|
|
db 6 ; SOLARSTRIKER
|
|
|
|
db 32 ; GBWARS
|
|
|
|
db 12 ; KAERUNOTAMENI
|
|
|
|
db 36 ;
|
|
|
|
db 11 ; POKEMON BLUE
|
|
|
|
db 39 ; DONKEYKONGLAND
|
|
|
|
db 18 ; GAMEBOY GALLERY2
|
|
|
|
db 39 ; DONKEYKONGLAND 2
|
|
|
|
db 24 ; KID ICARUS
|
|
|
|
db 31 ; TETRIS2
|
|
|
|
db 50 ;
|
|
|
|
db 17 ; MOGURANYA
|
|
|
|
db 46 ;
|
|
|
|
db 6 ; GALAGA&GALAXIAN
|
|
|
|
db 27 ; BT2RAGNAROKWORLD
|
|
|
|
db 0 ; KEN GRIFFEY JR
|
|
|
|
db 47 ;
|
|
|
|
db 41 ; MAGNETIC SOCCER
|
|
|
|
db 41 ; VEGAS STAKES
|
|
|
|
db 0 ;
|
|
|
|
db 0 ; MILLI/CENTI/PEDE
|
|
|
|
db 19 ; MARIO & YOSHI
|
|
|
|
db 34 ; SOCCER
|
|
|
|
db 23 ; POKEBOM
|
|
|
|
db 18 ; G&W GALLERY
|
|
|
|
db 29 ; TETRIS ATTACK
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
Dups4thLetterArray:
|
2018-04-03 17:10:11 +00:00
|
|
|
db "BEFAARBEKEK R-URAR INAILICE R"
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
; We assume the last three arrays fit in the same $100 byte page!
|
|
|
|
|
|
|
|
PaletteCombinations:
|
|
|
|
palette_comb: MACRO ; Obj0, Obj1, Bg
|
2018-11-22 23:09:14 +00:00
|
|
|
db (\1) * 8, (\2) * 8, (\3) *8
|
|
|
|
ENDM
|
|
|
|
raw_palette_comb: MACRO ; Obj0, Obj1, Bg
|
|
|
|
db (\1) * 2, (\2) * 2, (\3) * 2
|
|
|
|
ENDM
|
2018-04-03 17:10:11 +00:00
|
|
|
palette_comb 4, 4, 29
|
|
|
|
palette_comb 18, 18, 18
|
|
|
|
palette_comb 20, 20, 20
|
|
|
|
palette_comb 24, 24, 24
|
|
|
|
palette_comb 9, 9, 9
|
|
|
|
palette_comb 0, 0, 0
|
|
|
|
palette_comb 27, 27, 27
|
|
|
|
palette_comb 5, 5, 5
|
|
|
|
palette_comb 12, 12, 12
|
|
|
|
palette_comb 26, 26, 26
|
|
|
|
palette_comb 16, 8, 8
|
|
|
|
palette_comb 4, 28, 28
|
|
|
|
palette_comb 4, 2, 2
|
|
|
|
palette_comb 3, 4, 4
|
|
|
|
palette_comb 4, 29, 29
|
|
|
|
palette_comb 28, 4, 28
|
|
|
|
palette_comb 2, 17, 2
|
|
|
|
palette_comb 16, 16, 8
|
|
|
|
palette_comb 4, 4, 7
|
|
|
|
palette_comb 4, 4, 18
|
|
|
|
palette_comb 4, 4, 20
|
|
|
|
palette_comb 19, 19, 9
|
2018-11-22 23:09:14 +00:00
|
|
|
raw_palette_comb 4 * 4 - 1, 4 * 4 - 1, 11 * 4
|
2018-04-03 17:10:11 +00:00
|
|
|
palette_comb 17, 17, 2
|
|
|
|
palette_comb 4, 4, 2
|
|
|
|
palette_comb 4, 4, 3
|
|
|
|
palette_comb 28, 28, 0
|
|
|
|
palette_comb 3, 3, 0
|
|
|
|
palette_comb 0, 0, 1
|
|
|
|
palette_comb 18, 22, 18
|
|
|
|
palette_comb 20, 22, 20
|
|
|
|
palette_comb 24, 22, 24
|
|
|
|
palette_comb 16, 22, 8
|
|
|
|
palette_comb 17, 4, 13
|
2018-11-22 23:09:14 +00:00
|
|
|
raw_palette_comb 28 * 4 - 1, 0 * 4, 14 * 4
|
|
|
|
raw_palette_comb 28 * 4 - 1, 4 * 4, 15 * 4
|
2018-04-03 17:10:11 +00:00
|
|
|
palette_comb 19, 22, 9
|
|
|
|
palette_comb 16, 28, 10
|
|
|
|
palette_comb 4, 23, 28
|
|
|
|
palette_comb 17, 22, 2
|
|
|
|
palette_comb 4, 0, 2
|
|
|
|
palette_comb 4, 28, 3
|
|
|
|
palette_comb 28, 3, 0
|
|
|
|
palette_comb 3, 28, 4
|
|
|
|
palette_comb 21, 28, 4
|
|
|
|
palette_comb 3, 28, 0
|
|
|
|
palette_comb 25, 3, 28
|
|
|
|
palette_comb 0, 28, 8
|
|
|
|
palette_comb 4, 3, 28
|
|
|
|
palette_comb 28, 3, 6
|
|
|
|
palette_comb 4, 28, 29
|
2019-06-14 11:31:17 +00:00
|
|
|
; SameBoy "Exclusives"
|
2018-04-03 17:10:11 +00:00
|
|
|
palette_comb 30, 30, 30 ; CGA
|
|
|
|
palette_comb 31, 31, 31 ; DMG LCD
|
|
|
|
palette_comb 28, 4, 1
|
|
|
|
palette_comb 0, 0, 2
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
Palettes:
|
2018-04-03 17:10:11 +00:00
|
|
|
dw $7FFF, $32BF, $00D0, $0000
|
|
|
|
dw $639F, $4279, $15B0, $04CB
|
|
|
|
dw $7FFF, $6E31, $454A, $0000
|
|
|
|
dw $7FFF, $1BEF, $0200, $0000
|
|
|
|
dw $7FFF, $421F, $1CF2, $0000
|
|
|
|
dw $7FFF, $5294, $294A, $0000
|
|
|
|
dw $7FFF, $03FF, $012F, $0000
|
|
|
|
dw $7FFF, $03EF, $01D6, $0000
|
|
|
|
dw $7FFF, $42B5, $3DC8, $0000
|
|
|
|
dw $7E74, $03FF, $0180, $0000
|
|
|
|
dw $67FF, $77AC, $1A13, $2D6B
|
|
|
|
dw $7ED6, $4BFF, $2175, $0000
|
|
|
|
dw $53FF, $4A5F, $7E52, $0000
|
|
|
|
dw $4FFF, $7ED2, $3A4C, $1CE0
|
|
|
|
dw $03ED, $7FFF, $255F, $0000
|
|
|
|
dw $036A, $021F, $03FF, $7FFF
|
|
|
|
dw $7FFF, $01DF, $0112, $0000
|
|
|
|
dw $231F, $035F, $00F2, $0009
|
|
|
|
dw $7FFF, $03EA, $011F, $0000
|
|
|
|
dw $299F, $001A, $000C, $0000
|
|
|
|
dw $7FFF, $027F, $001F, $0000
|
|
|
|
dw $7FFF, $03E0, $0206, $0120
|
|
|
|
dw $7FFF, $7EEB, $001F, $7C00
|
|
|
|
dw $7FFF, $3FFF, $7E00, $001F
|
|
|
|
dw $7FFF, $03FF, $001F, $0000
|
|
|
|
dw $03FF, $001F, $000C, $0000
|
|
|
|
dw $7FFF, $033F, $0193, $0000
|
|
|
|
dw $0000, $4200, $037F, $7FFF
|
|
|
|
dw $7FFF, $7E8C, $7C00, $0000
|
|
|
|
dw $7FFF, $1BEF, $6180, $0000
|
2019-06-14 11:31:17 +00:00
|
|
|
; SameBoy "Exclusives"
|
2018-04-03 17:10:11 +00:00
|
|
|
dw $7FFF, $7FEA, $7D5F, $0000 ; CGA 1
|
|
|
|
dw $4778, $3290, $1D87, $0861 ; DMG LCD
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
KeyCombinationPalettes
|
2018-04-03 17:10:11 +00:00
|
|
|
db 1 ; Right
|
|
|
|
db 48 ; Left
|
|
|
|
db 5 ; Up
|
|
|
|
db 8 ; Down
|
|
|
|
db 0 ; Right + A
|
|
|
|
db 40 ; Left + A
|
|
|
|
db 43 ; Up + A
|
|
|
|
db 3 ; Down + A
|
|
|
|
db 6 ; Right + B
|
|
|
|
db 7 ; Left + B
|
|
|
|
db 28 ; Up + B
|
|
|
|
db 49 ; Down + B
|
2019-06-14 11:31:17 +00:00
|
|
|
; SameBoy "Exclusives"
|
2018-04-03 17:10:11 +00:00
|
|
|
db 51 ; Right + A + B
|
|
|
|
db 52 ; Left + A + B
|
|
|
|
db 53 ; Up + A + B
|
|
|
|
db 54 ; Down + A + B
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
TrademarkSymbol:
|
2018-04-03 17:10:11 +00:00
|
|
|
db $3c,$42,$b9,$a5,$b9,$a5,$42,$3c
|
2016-03-30 20:07:55 +00:00
|
|
|
|
2019-06-14 11:31:17 +00:00
|
|
|
SameBoyLogo:
|
|
|
|
incbin "SameBoyLogo.rle"
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
AnimationColors:
|
2018-04-03 17:10:11 +00:00
|
|
|
dw $7FFF ; White
|
|
|
|
dw $774F ; Cyan
|
|
|
|
dw $22C7 ; Green
|
|
|
|
dw $039F ; Yellow
|
|
|
|
dw $017D ; Orange
|
|
|
|
dw $241D ; Red
|
|
|
|
dw $6D38 ; Purple
|
|
|
|
dw $7102 ; Blue
|
2016-03-30 20:07:55 +00:00
|
|
|
AnimationColorsEnd:
|
|
|
|
|
|
|
|
DMGPalettes:
|
2018-04-03 17:10:11 +00:00
|
|
|
dw $7FFF, $32BF, $00D0, $0000
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
; Helper Functions
|
2019-06-10 15:45:14 +00:00
|
|
|
DoubleBitsAndWriteRowTwice:
|
|
|
|
call .twice
|
|
|
|
.twice
|
2016-03-30 20:07:55 +00:00
|
|
|
; Double the most significant 4 bits, b is shifted by 4
|
2018-04-03 17:10:11 +00:00
|
|
|
ld a, 4
|
|
|
|
ld c, 0
|
2016-03-30 20:07:55 +00:00
|
|
|
.doubleCurrentBit
|
2018-04-03 17:10:11 +00:00
|
|
|
sla b
|
|
|
|
push af
|
|
|
|
rl c
|
|
|
|
pop af
|
|
|
|
rl c
|
|
|
|
dec a
|
|
|
|
jr nz, .doubleCurrentBit
|
|
|
|
ld a, c
|
2016-03-30 20:07:55 +00:00
|
|
|
; Write as two rows
|
2018-04-03 17:10:11 +00:00
|
|
|
ldi [hl], a
|
|
|
|
inc hl
|
|
|
|
ldi [hl], a
|
|
|
|
inc hl
|
|
|
|
ret
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
WaitFrame:
|
2018-04-03 17:10:11 +00:00
|
|
|
push hl
|
|
|
|
ld hl, $FF0F
|
|
|
|
res 0, [hl]
|
2016-03-30 20:07:55 +00:00
|
|
|
.wait
|
2018-04-03 17:10:11 +00:00
|
|
|
bit 0, [hl]
|
|
|
|
jr z, .wait
|
|
|
|
pop hl
|
|
|
|
ret
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
WaitBFrames:
|
2018-04-03 17:10:11 +00:00
|
|
|
call GetInputPaletteIndex
|
|
|
|
call WaitFrame
|
|
|
|
dec b
|
|
|
|
jr nz, WaitBFrames
|
|
|
|
ret
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
PlaySound:
|
2018-04-03 17:10:11 +00:00
|
|
|
ldh [$13], a
|
|
|
|
ld a, $87
|
|
|
|
ldh [$14], a
|
|
|
|
ret
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
; Clear from HL to HL | 0x2000
|
|
|
|
ClearMemoryPage:
|
2018-04-03 17:10:11 +00:00
|
|
|
ldi [hl], a
|
|
|
|
bit 5, h
|
|
|
|
jr z, ClearMemoryPage
|
|
|
|
ret
|
2016-03-30 20:07:55 +00:00
|
|
|
|
2019-06-09 13:15:08 +00:00
|
|
|
ReadTwoTileLines:
|
|
|
|
call ReadTileLine
|
2016-03-30 20:07:55 +00:00
|
|
|
; c = $f0 for even lines, $f for odd lines.
|
|
|
|
ReadTileLine:
|
2018-04-03 17:10:11 +00:00
|
|
|
ld a, [de]
|
|
|
|
and c
|
|
|
|
ld b, a
|
|
|
|
inc e
|
|
|
|
inc e
|
|
|
|
ld a, [de]
|
|
|
|
dec e
|
|
|
|
dec e
|
|
|
|
and c
|
|
|
|
swap a
|
|
|
|
or b
|
|
|
|
bit 0, c
|
|
|
|
jr z, .dontSwap
|
|
|
|
swap a
|
2016-03-30 20:07:55 +00:00
|
|
|
.dontSwap
|
2018-04-03 17:10:11 +00:00
|
|
|
inc hl
|
|
|
|
ldi [hl], a
|
2019-06-09 13:15:08 +00:00
|
|
|
swap c
|
2018-04-03 17:10:11 +00:00
|
|
|
ret
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
ReadCGBLogoHalfTile:
|
2019-06-09 13:15:08 +00:00
|
|
|
call .do_twice
|
|
|
|
.do_twice
|
|
|
|
call ReadTwoTileLines
|
2018-04-03 17:10:11 +00:00
|
|
|
inc e
|
2019-06-09 13:15:08 +00:00
|
|
|
ld a, e
|
2018-04-03 17:10:11 +00:00
|
|
|
ret
|
2016-03-30 20:07:55 +00:00
|
|
|
|
2019-06-10 15:45:14 +00:00
|
|
|
LoadTileset:
|
|
|
|
; Copy SameBoy Logo
|
2019-06-14 11:31:17 +00:00
|
|
|
ld de, SameBoyLogo
|
2019-06-10 15:45:14 +00:00
|
|
|
ld hl, $8080
|
|
|
|
.sameboyLogoLoop
|
|
|
|
ld a, [de]
|
|
|
|
inc de
|
|
|
|
|
|
|
|
ld b, a
|
|
|
|
and $0f
|
|
|
|
jr z, .skipLiteral
|
|
|
|
ld c, a
|
|
|
|
|
|
|
|
.literalLoop
|
|
|
|
ld a, [de]
|
|
|
|
ldi [hl], a
|
|
|
|
inc hl
|
|
|
|
inc de
|
|
|
|
dec c
|
|
|
|
jr nz, .literalLoop
|
|
|
|
.skipLiteral
|
|
|
|
swap b
|
|
|
|
ld a, b
|
|
|
|
and $0f
|
|
|
|
jr z, .sameboyLogoEnd
|
|
|
|
ld c, a
|
|
|
|
ld a, [de]
|
|
|
|
inc de
|
|
|
|
|
|
|
|
.repeatLoop
|
|
|
|
ldi [hl], a
|
|
|
|
inc hl
|
|
|
|
dec c
|
|
|
|
jr nz, .repeatLoop
|
|
|
|
jr .sameboyLogoLoop
|
|
|
|
|
|
|
|
.sameboyLogoEnd
|
|
|
|
; Copy (unresized) ROM logo
|
|
|
|
ld de, $104
|
|
|
|
.CGBROMLogoLoop
|
2019-06-09 13:15:08 +00:00
|
|
|
ld c, $f0
|
2018-04-03 17:10:11 +00:00
|
|
|
call ReadCGBLogoHalfTile
|
|
|
|
add a, 22
|
|
|
|
ld e, a
|
|
|
|
call ReadCGBLogoHalfTile
|
|
|
|
sub a, 22
|
|
|
|
ld e, a
|
2019-06-10 15:45:14 +00:00
|
|
|
cp $1c
|
|
|
|
jr nz, .CGBROMLogoLoop
|
|
|
|
inc hl
|
|
|
|
; fallthrough
|
2016-03-30 20:07:55 +00:00
|
|
|
ReadTrademarkSymbol:
|
2018-04-03 17:10:11 +00:00
|
|
|
ld de, TrademarkSymbol
|
|
|
|
ld c,$08
|
2016-03-30 20:07:55 +00:00
|
|
|
.loadTrademarkSymbolLoop:
|
2018-04-03 17:10:11 +00:00
|
|
|
ld a,[de]
|
|
|
|
inc de
|
|
|
|
ldi [hl],a
|
|
|
|
inc hl
|
|
|
|
dec c
|
|
|
|
jr nz, .loadTrademarkSymbolLoop
|
|
|
|
ret
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
LoadObjPalettes:
|
2018-04-03 17:10:11 +00:00
|
|
|
ld c, $6A
|
|
|
|
jr LoadPalettes
|
2016-03-30 20:07:55 +00:00
|
|
|
|
2019-06-10 15:45:14 +00:00
|
|
|
LoadBGPalettes64:
|
|
|
|
ld d, 64
|
|
|
|
|
2016-03-30 20:07:55 +00:00
|
|
|
LoadBGPalettes:
|
2019-06-10 15:45:14 +00:00
|
|
|
ld e, 0
|
2018-04-03 17:10:11 +00:00
|
|
|
ld c, $68
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
LoadPalettes:
|
2018-04-03 17:10:11 +00:00
|
|
|
ld a, $80
|
|
|
|
or e
|
|
|
|
ld [c], a
|
|
|
|
inc c
|
2016-03-30 20:07:55 +00:00
|
|
|
.loop
|
2018-04-03 17:10:11 +00:00
|
|
|
ld a, [hli]
|
|
|
|
ld [c], a
|
|
|
|
dec d
|
|
|
|
jr nz, .loop
|
|
|
|
ret
|
2016-03-30 20:07:55 +00:00
|
|
|
|
2019-06-09 13:15:08 +00:00
|
|
|
DoIntroAnimation:
|
|
|
|
; Animate the intro
|
|
|
|
ld a, 1
|
|
|
|
ldh [$4F], a
|
|
|
|
ld d, 26
|
|
|
|
.animationLoop
|
|
|
|
ld b, 2
|
|
|
|
call WaitBFrames
|
2018-04-03 17:10:11 +00:00
|
|
|
ld hl, $98C0
|
|
|
|
ld c, 3 ; Row count
|
2016-03-30 20:07:55 +00:00
|
|
|
.loop
|
2018-04-03 17:10:11 +00:00
|
|
|
ld a, [hl]
|
|
|
|
cp $F ; Already blue
|
|
|
|
jr z, .nextTile
|
2019-06-09 13:15:08 +00:00
|
|
|
inc [hl]
|
2018-04-03 17:10:11 +00:00
|
|
|
and $7
|
2019-06-09 13:15:08 +00:00
|
|
|
jr z, .nextLine ; Changed a white tile, go to next line
|
2016-03-30 20:07:55 +00:00
|
|
|
.nextTile
|
2018-04-03 17:10:11 +00:00
|
|
|
inc hl
|
|
|
|
jr .loop
|
2016-03-30 20:07:55 +00:00
|
|
|
.nextLine
|
2018-04-03 17:10:11 +00:00
|
|
|
ld a, l
|
|
|
|
or $1F
|
|
|
|
ld l, a
|
|
|
|
inc hl
|
|
|
|
dec c
|
2019-06-09 13:15:08 +00:00
|
|
|
jr nz, .loop
|
2018-04-03 17:10:11 +00:00
|
|
|
dec d
|
|
|
|
jr nz, .animationLoop
|
|
|
|
ret
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
Preboot:
|
2018-11-10 19:10:09 +00:00
|
|
|
IF !DEF(FAST)
|
2019-06-10 15:45:14 +00:00
|
|
|
ld b, 32 ; 32 times to fade
|
|
|
|
.fadeLoop
|
|
|
|
ld c, 32 ; 32 colors to fade
|
|
|
|
ld hl, BgPalettes
|
|
|
|
.frameLoop
|
|
|
|
push bc
|
|
|
|
call BrightenColor
|
|
|
|
pop bc
|
|
|
|
dec c
|
|
|
|
jr nz, .frameLoop
|
|
|
|
|
|
|
|
call WaitFrame
|
|
|
|
call WaitFrame
|
|
|
|
ld hl, BgPalettes
|
|
|
|
call LoadBGPalettes64
|
|
|
|
dec b
|
|
|
|
jr nz, .fadeLoop
|
2018-11-10 19:10:09 +00:00
|
|
|
ENDC
|
2018-04-03 17:10:11 +00:00
|
|
|
call ClearVRAMViaHDMA
|
|
|
|
; Select the first bank
|
|
|
|
xor a
|
|
|
|
ldh [$4F], a
|
|
|
|
cpl
|
|
|
|
ldh [$00], a
|
|
|
|
call ClearVRAMViaHDMA
|
2018-06-19 20:59:16 +00:00
|
|
|
|
|
|
|
; Final values for CGB mode
|
|
|
|
ld de, $ff56
|
|
|
|
ld l, $0d
|
|
|
|
|
2018-04-03 17:10:11 +00:00
|
|
|
ld a, [$143]
|
|
|
|
bit 7, a
|
2018-06-19 20:59:16 +00:00
|
|
|
call z, EmulateDMG
|
2019-06-08 10:37:49 +00:00
|
|
|
bit 7, a
|
|
|
|
|
2018-07-10 17:28:36 +00:00
|
|
|
ldh [$4C], a
|
2018-06-19 20:59:16 +00:00
|
|
|
ldh a, [TitleChecksum]
|
|
|
|
ld b, a
|
|
|
|
|
2019-06-08 10:37:49 +00:00
|
|
|
jr z, .skipDMGForCGBCheck
|
2018-04-03 17:10:11 +00:00
|
|
|
ldh a, [InputPalette]
|
|
|
|
and a
|
|
|
|
jr nz, .emulateDMGForCGBGame
|
2019-06-08 10:37:49 +00:00
|
|
|
.skipDMGForCGBCheck
|
2018-01-13 11:02:31 +00:00
|
|
|
IF DEF(AGB)
|
2018-04-03 17:10:11 +00:00
|
|
|
; Set registers to match the original AGB-CGB boot
|
2018-06-19 20:59:16 +00:00
|
|
|
; AF = $1100, C = 0
|
|
|
|
xor a
|
|
|
|
ld c, a
|
|
|
|
add a, $11
|
2018-04-03 17:10:11 +00:00
|
|
|
ld h, c
|
|
|
|
ld b, 1
|
2018-01-13 11:02:31 +00:00
|
|
|
ELSE
|
2018-04-03 17:10:11 +00:00
|
|
|
; Set registers to match the original CGB boot
|
2018-06-19 20:59:16 +00:00
|
|
|
; AF = $1180, C = 0
|
|
|
|
xor a
|
|
|
|
ld c, a
|
|
|
|
ld a, $11
|
2018-04-03 17:10:11 +00:00
|
|
|
ld h, c
|
2018-06-19 20:59:16 +00:00
|
|
|
; B is set to the title checksum
|
2018-01-13 11:02:31 +00:00
|
|
|
ENDC
|
2018-04-03 17:10:11 +00:00
|
|
|
ret
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
.emulateDMGForCGBGame
|
2018-04-03 17:10:11 +00:00
|
|
|
call EmulateDMG
|
|
|
|
ldh [$4C], a
|
2019-06-09 13:15:08 +00:00
|
|
|
ld a, $1
|
2018-04-03 17:10:11 +00:00
|
|
|
ret
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
EmulateDMG:
|
2018-04-03 17:10:11 +00:00
|
|
|
ld a, 1
|
|
|
|
ldh [$6C], a ; DMG Emulation
|
|
|
|
call GetPaletteIndex
|
|
|
|
bit 7, a
|
|
|
|
call nz, LoadDMGTilemap
|
|
|
|
and $7F
|
|
|
|
ld b, a
|
|
|
|
ldh a, [InputPalette]
|
|
|
|
and a
|
|
|
|
jr z, .nothingDown
|
|
|
|
ld hl, KeyCombinationPalettes - 1 ; Return value is 1-based, 0 means nothing down
|
|
|
|
ld c ,a
|
|
|
|
ld b, 0
|
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
jr .paletteFromKeys
|
2016-03-30 20:07:55 +00:00
|
|
|
.nothingDown
|
2018-04-03 17:10:11 +00:00
|
|
|
ld a, b
|
2016-03-30 20:07:55 +00:00
|
|
|
.paletteFromKeys
|
2018-04-03 17:10:11 +00:00
|
|
|
call WaitFrame
|
|
|
|
call LoadPalettesFromIndex
|
|
|
|
ld a, 4
|
2018-06-19 20:59:16 +00:00
|
|
|
; Set the final values for DMG mode
|
|
|
|
ld d, 0
|
|
|
|
ld e, $8
|
|
|
|
ld l, $7c
|
2018-04-03 17:10:11 +00:00
|
|
|
ret
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
GetPaletteIndex:
|
2018-06-19 20:59:16 +00:00
|
|
|
ld hl, $14B
|
|
|
|
ld a, [hl] ; Old Licensee
|
2018-04-03 17:10:11 +00:00
|
|
|
cp $33
|
|
|
|
jr z, .newLicensee
|
2019-06-09 13:15:08 +00:00
|
|
|
dec a ; 1 = Nintendo
|
2018-04-03 17:10:11 +00:00
|
|
|
jr nz, .notNintendo
|
|
|
|
jr .doChecksum
|
2016-03-30 20:07:55 +00:00
|
|
|
.newLicensee
|
2018-06-19 20:59:16 +00:00
|
|
|
ld l, $44
|
|
|
|
ld a, [hli]
|
2018-04-03 17:10:11 +00:00
|
|
|
cp "0"
|
|
|
|
jr nz, .notNintendo
|
2018-06-19 20:59:16 +00:00
|
|
|
ld a, [hl]
|
2018-04-03 17:10:11 +00:00
|
|
|
cp "1"
|
|
|
|
jr nz, .notNintendo
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
.doChecksum
|
2018-06-19 20:59:16 +00:00
|
|
|
ld l, $34
|
2018-04-03 17:10:11 +00:00
|
|
|
ld c, $10
|
2019-06-09 13:15:08 +00:00
|
|
|
xor a
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
.checksumLoop
|
2019-06-09 13:15:08 +00:00
|
|
|
add [hl]
|
|
|
|
inc l
|
2018-04-03 17:10:11 +00:00
|
|
|
dec c
|
|
|
|
jr nz, .checksumLoop
|
2019-06-09 13:15:08 +00:00
|
|
|
ld b, a
|
2016-03-30 20:07:55 +00:00
|
|
|
|
2018-04-03 17:10:11 +00:00
|
|
|
; c = 0
|
|
|
|
ld hl, TitleChecksums
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
.searchLoop
|
2018-04-03 17:10:11 +00:00
|
|
|
ld a, l
|
2019-06-09 13:15:08 +00:00
|
|
|
sub LOW(ChecksumsEnd) ; use sub to zero out a
|
|
|
|
ret z
|
2018-04-03 17:10:11 +00:00
|
|
|
ld a, [hli]
|
|
|
|
cp b
|
|
|
|
jr nz, .searchLoop
|
|
|
|
|
|
|
|
; We might have a match, Do duplicate/4th letter check
|
|
|
|
ld a, l
|
|
|
|
sub FirstChecksumWithDuplicate - TitleChecksums
|
|
|
|
jr c, .match ; Does not have a duplicate, must be a match!
|
|
|
|
; Has a duplicate; check 4th letter
|
|
|
|
push hl
|
|
|
|
ld a, l
|
|
|
|
add Dups4thLetterArray - FirstChecksumWithDuplicate - 1 ; -1 since hl was incremented
|
|
|
|
ld l, a
|
|
|
|
ld a, [hl]
|
|
|
|
pop hl
|
|
|
|
ld c, a
|
|
|
|
ld a, [$134 + 3] ; Get 4th letter
|
|
|
|
cp c
|
|
|
|
jr nz, .searchLoop ; Not a match, continue
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
.match
|
2018-04-03 17:10:11 +00:00
|
|
|
ld a, l
|
|
|
|
add PalettePerChecksum - TitleChecksums - 1; -1 since hl was incremented
|
|
|
|
ld l, a
|
2018-06-19 20:59:16 +00:00
|
|
|
ld a, b
|
|
|
|
ldh [TitleChecksum], a
|
2018-04-03 17:10:11 +00:00
|
|
|
ld a, [hl]
|
|
|
|
ret
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
.notNintendo
|
2018-04-03 17:10:11 +00:00
|
|
|
xor a
|
|
|
|
ret
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
LoadPalettesFromIndex: ; a = index of combination
|
2018-04-03 17:10:11 +00:00
|
|
|
ld b, a
|
|
|
|
; Multiply by 3
|
|
|
|
add b
|
|
|
|
add b
|
|
|
|
|
|
|
|
ld hl, PaletteCombinations
|
|
|
|
ld b, 0
|
|
|
|
ld c, a
|
|
|
|
add hl, bc
|
|
|
|
|
|
|
|
; Obj Palettes
|
|
|
|
ld e, 0
|
2016-03-30 20:07:55 +00:00
|
|
|
.loadObjPalette
|
2018-04-03 17:10:11 +00:00
|
|
|
ld a, [hli]
|
|
|
|
push hl
|
|
|
|
ld hl, Palettes
|
|
|
|
ld b, 0
|
|
|
|
ld c, a
|
|
|
|
add hl, bc
|
|
|
|
ld d, 8
|
|
|
|
call LoadObjPalettes
|
|
|
|
pop hl
|
|
|
|
bit 3, e
|
|
|
|
jr nz, .loadBGPalette
|
|
|
|
ld e, 8
|
|
|
|
jr .loadObjPalette
|
2016-03-30 20:07:55 +00:00
|
|
|
.loadBGPalette
|
2018-04-03 17:10:11 +00:00
|
|
|
;BG Palette
|
|
|
|
ld a, [hli]
|
|
|
|
ld hl, Palettes
|
|
|
|
ld b, 0
|
|
|
|
ld c, a
|
|
|
|
add hl, bc
|
|
|
|
ld d, 8
|
2019-06-10 15:45:14 +00:00
|
|
|
jp LoadBGPalettes
|
2016-03-30 20:07:55 +00:00
|
|
|
|
2017-06-09 16:52:40 +00:00
|
|
|
BrightenColor:
|
2018-04-03 17:10:11 +00:00
|
|
|
ld a, [hli]
|
|
|
|
ld e, a
|
|
|
|
ld a, [hld]
|
|
|
|
ld d, a
|
|
|
|
; RGB(1,1,1)
|
|
|
|
ld bc, $421
|
|
|
|
|
|
|
|
; Is blue maxed?
|
|
|
|
ld a, e
|
|
|
|
and $1F
|
|
|
|
cp $1F
|
|
|
|
jr nz, .blueNotMaxed
|
|
|
|
res 0, c
|
2016-03-30 20:07:55 +00:00
|
|
|
.blueNotMaxed
|
|
|
|
|
2018-04-03 17:10:11 +00:00
|
|
|
; Is green maxed?
|
|
|
|
ld a, e
|
|
|
|
and $E0
|
|
|
|
cp $E0
|
|
|
|
jr nz, .greenNotMaxed
|
|
|
|
ld a, d
|
|
|
|
and $3
|
|
|
|
cp $3
|
|
|
|
jr nz, .greenNotMaxed
|
|
|
|
res 5, c
|
2016-03-30 20:07:55 +00:00
|
|
|
.greenNotMaxed
|
|
|
|
|
2018-04-03 17:10:11 +00:00
|
|
|
; Is red maxed?
|
|
|
|
ld a, d
|
|
|
|
and $7C
|
|
|
|
cp $7C
|
|
|
|
jr nz, .redNotMaxed
|
|
|
|
res 2, b
|
2016-03-30 20:07:55 +00:00
|
|
|
.redNotMaxed
|
|
|
|
|
2018-04-03 17:10:11 +00:00
|
|
|
; Add de to bc
|
|
|
|
push hl
|
|
|
|
ld h, d
|
|
|
|
ld l, e
|
|
|
|
add hl, bc
|
|
|
|
ld d, h
|
|
|
|
ld e, l
|
|
|
|
pop hl
|
|
|
|
|
|
|
|
ld a, e
|
|
|
|
ld [hli], a
|
|
|
|
ld a, d
|
|
|
|
ld [hli], a
|
|
|
|
ret
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
ClearVRAMViaHDMA:
|
2018-04-03 17:10:11 +00:00
|
|
|
ld hl, $FF51
|
2016-03-30 20:07:55 +00:00
|
|
|
|
2018-04-03 17:10:11 +00:00
|
|
|
; Src
|
2019-06-08 21:53:44 +00:00
|
|
|
ld a, $88
|
2018-04-03 17:10:11 +00:00
|
|
|
ld [hli], a
|
|
|
|
xor a
|
|
|
|
ld [hli], a
|
2016-03-30 20:07:55 +00:00
|
|
|
|
2018-04-03 17:10:11 +00:00
|
|
|
; Dest
|
|
|
|
ld a, $98
|
|
|
|
ld [hli], a
|
|
|
|
ld a, $A0
|
|
|
|
ld [hli], a
|
2016-03-30 20:07:55 +00:00
|
|
|
|
2018-04-03 17:10:11 +00:00
|
|
|
; Do it
|
2019-06-10 15:45:14 +00:00
|
|
|
ld [hl], $12
|
2018-04-03 17:10:11 +00:00
|
|
|
ret
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
GetInputPaletteIndex:
|
2018-04-03 17:10:11 +00:00
|
|
|
ld a, $20 ; Select directions
|
|
|
|
ldh [$00], a
|
|
|
|
ldh a, [$00]
|
|
|
|
cpl
|
|
|
|
and $F
|
|
|
|
ret z ; No direction keys pressed, no palette
|
|
|
|
push bc
|
|
|
|
ld c, 0
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
.directionLoop
|
2018-04-03 17:10:11 +00:00
|
|
|
inc c
|
|
|
|
rra
|
|
|
|
jr nc, .directionLoop
|
|
|
|
|
|
|
|
; c = 1: Right, 2: Left, 3: Up, 4: Down
|
|
|
|
|
|
|
|
ld a, $10 ; Select buttons
|
|
|
|
ldh [$00], a
|
|
|
|
ldh a, [$00]
|
|
|
|
cpl
|
|
|
|
rla
|
|
|
|
rla
|
|
|
|
and $C
|
|
|
|
add c
|
|
|
|
ld b, a
|
|
|
|
ldh a, [InputPalette]
|
|
|
|
ld c, a
|
|
|
|
ld a, b
|
|
|
|
ldh [InputPalette], a
|
|
|
|
cp c
|
|
|
|
pop bc
|
|
|
|
ret z ; No change, don't load
|
|
|
|
; Slide into change Animation Palette
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
ChangeAnimationPalette:
|
2018-04-03 17:10:11 +00:00
|
|
|
push af
|
|
|
|
push hl
|
|
|
|
push bc
|
|
|
|
push de
|
|
|
|
ld hl, KeyCombinationPalettes - 1 ; Input palettes are 1-based, 0 means nothing down
|
|
|
|
ld c ,a
|
|
|
|
ld b, 0
|
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
ld b, a
|
|
|
|
; Multiply by 3
|
|
|
|
add b
|
|
|
|
add b
|
|
|
|
|
|
|
|
ld hl, PaletteCombinations + 2; Background Palette
|
|
|
|
ld b, 0
|
|
|
|
ld c, a
|
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
ld hl, Palettes + 1
|
|
|
|
ld b, 0
|
|
|
|
ld c, a
|
|
|
|
add hl, bc
|
|
|
|
ld a, [hld]
|
|
|
|
cp $7F ; Is white color?
|
|
|
|
jr nz, .isWhite
|
|
|
|
inc hl
|
|
|
|
inc hl
|
2016-03-30 20:07:55 +00:00
|
|
|
.isWhite
|
2018-04-03 17:10:11 +00:00
|
|
|
push af
|
|
|
|
ld a, [hli]
|
|
|
|
push hl
|
|
|
|
ld hl, BgPalettes ; First color, all palette
|
|
|
|
call ReplaceColorInAllPalettes
|
|
|
|
pop hl
|
|
|
|
ldh [BgPalettes + 2], a ; Second color, first palette
|
|
|
|
|
|
|
|
ld a, [hli]
|
|
|
|
push hl
|
|
|
|
ld hl, BgPalettes + 1 ; First color, all palette
|
|
|
|
call ReplaceColorInAllPalettes
|
|
|
|
pop hl
|
|
|
|
ldh [BgPalettes + 3], a ; Second color, first palette
|
|
|
|
pop af
|
|
|
|
jr z, .isNotWhite
|
|
|
|
inc hl
|
|
|
|
inc hl
|
2016-03-30 20:07:55 +00:00
|
|
|
.isNotWhite
|
2018-04-03 17:10:11 +00:00
|
|
|
ld a, [hli]
|
|
|
|
ldh [BgPalettes + 7 * 8 + 2], a ; Second color, 7th palette
|
|
|
|
ld a, [hli]
|
|
|
|
ldh [BgPalettes + 7 * 8 + 3], a ; Second color, 7th palette
|
|
|
|
ld a, [hli]
|
|
|
|
ldh [BgPalettes + 4], a ; Third color, first palette
|
|
|
|
ld a, [hl]
|
|
|
|
ldh [BgPalettes + 5], a ; Third color, first palette
|
|
|
|
|
|
|
|
call WaitFrame
|
|
|
|
ld hl, BgPalettes
|
2019-06-10 15:45:14 +00:00
|
|
|
call LoadBGPalettes64
|
2018-04-03 17:10:11 +00:00
|
|
|
; Delay the wait loop while the user is selecting a palette
|
|
|
|
ld a, 30
|
|
|
|
ldh [WaitLoopCounter], a
|
|
|
|
pop de
|
|
|
|
pop bc
|
|
|
|
pop hl
|
|
|
|
pop af
|
|
|
|
ret
|
2016-03-30 20:07:55 +00:00
|
|
|
|
|
|
|
ReplaceColorInAllPalettes:
|
2018-04-03 17:10:11 +00:00
|
|
|
ld de, 8
|
|
|
|
ld c, 8
|
2016-03-30 20:07:55 +00:00
|
|
|
.loop
|
2018-04-03 17:10:11 +00:00
|
|
|
ld [hl], a
|
|
|
|
add hl, de
|
|
|
|
dec c
|
|
|
|
jr nz, .loop
|
|
|
|
ret
|
|
|
|
|
2016-04-15 22:14:30 +00:00
|
|
|
LoadDMGTilemap:
|
2018-04-03 17:10:11 +00:00
|
|
|
push af
|
|
|
|
call WaitFrame
|
|
|
|
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
|
2016-04-15 22:14:30 +00:00
|
|
|
.tilemapLoop
|
2018-04-03 17:10:11 +00:00
|
|
|
dec a
|
|
|
|
jr z, .tilemapDone
|
|
|
|
ldd [hl], a
|
|
|
|
dec c
|
|
|
|
jr nz, .tilemapLoop
|
|
|
|
ld l,$0f ; Jump to top row
|
|
|
|
jr .tilemapLoop
|
2016-04-15 22:14:30 +00:00
|
|
|
.tilemapDone
|
2018-04-03 17:10:11 +00:00
|
|
|
pop af
|
|
|
|
ret
|
2016-03-30 20:07:55 +00:00
|
|
|
|
2017-06-09 16:52:40 +00:00
|
|
|
InitWaveform:
|
2018-04-03 17:10:11 +00:00
|
|
|
ld hl, $FF30
|
2017-06-09 16:52:40 +00:00
|
|
|
; Init waveform
|
2018-04-03 17:10:11 +00:00
|
|
|
xor a
|
|
|
|
ld c, $10
|
2017-06-09 16:52:40 +00:00
|
|
|
.waveformLoop
|
2018-04-03 17:10:11 +00:00
|
|
|
ldi [hl], a
|
|
|
|
cpl
|
|
|
|
dec c
|
|
|
|
jr nz, .waveformLoop
|
|
|
|
ret
|
2017-06-09 16:52:40 +00:00
|
|
|
|
2016-03-30 20:07:55 +00:00
|
|
|
SECTION "ROMMax", ROM0[$900]
|
2018-04-03 17:10:11 +00:00
|
|
|
; Prevent us from overflowing
|
|
|
|
ds 1
|
2016-03-30 20:07:55 +00:00
|
|
|
|
2018-04-03 17:10:11 +00:00
|
|
|
SECTION "HRAM", HRAM[$FF80]
|
2018-06-19 20:59:16 +00:00
|
|
|
TitleChecksum:
|
|
|
|
ds 1
|
2016-03-30 20:07:55 +00:00
|
|
|
BgPalettes:
|
2018-04-03 17:10:11 +00:00
|
|
|
ds 8 * 4 * 2
|
2016-03-30 20:07:55 +00:00
|
|
|
InputPalette:
|
2018-04-03 17:10:11 +00:00
|
|
|
ds 1
|
2017-06-09 16:52:40 +00:00
|
|
|
WaitLoopCounter:
|
2019-06-09 13:15:08 +00:00
|
|
|
ds 1
|