Merge commit 'c678407d1eae9fec625a644506b3cd66654d9b1a'

This commit is contained in:
Lior Halphon 2019-06-14 14:28:36 +03:00
commit a956d58ea1
4 changed files with 182 additions and 128 deletions

Binary file not shown.

View File

@ -57,11 +57,10 @@ Start:
.loadLogoLoop .loadLogoLoop
ld a, [de] ; Read 2 rows ld a, [de] ; Read 2 rows
ld b, a ld b, a
call DoubleBitsAndWriteRow call DoubleBitsAndWriteRowTwice
call DoubleBitsAndWriteRow
inc de inc de
ld a, e ld a, e
xor $34 ; End of logo cp $34 ; End of logo
jr nz, .loadLogoLoop jr nz, .loadLogoLoop
call ReadTrademarkSymbol call ReadTrademarkSymbol
@ -71,79 +70,54 @@ Start:
xor a xor a
ld hl, $8000 ld hl, $8000
call ClearMemoryPage call ClearMemoryPage
call LoadTileset
; Copy SameBoy Logo
ld de, SameboyLogo
ld hl, $8080
ld c, (SameboyLogoEnd - SameboyLogo) / 2
.sameboyLogoLoop
ld a, [de]
ldi [hl], a
inc hl
inc de
ld a, [de]
ldi [hl], a
inc hl
inc de
dec c
jr nz, .sameboyLogoLoop
; Copy (unresized) ROM logo
ld de, $104
ld c, 6
.CGBROMLogoLoop
push bc
call ReadCGBLogoTile
pop bc
dec c
jr nz, .CGBROMLogoLoop
inc hl
call ReadTrademarkSymbol
; Load Tilemap
ld hl, $98C2
ld b, 3 ld b, 3
ld a, 8
IF DEF(FAST) IF DEF(FAST)
xor a xor a
ldh [$4F], a ldh [$4F], a
ENDC ELSE
; Load Tilemap
ld hl, $98C2
ld d, 3
ld a, 8
.tilemapLoop .tilemapLoop
ld c, $10 ld c, $10
.tilemapRowLoop .tilemapRowLoop
ld [hl], a
push af push af
IF !DEF(FAST)
; Switch to second VRAM Bank ; Switch to second VRAM Bank
ld a, 1 ld a, 1
ldh [$4F], a ldh [$4F], a
ld a, 8 ld [hl], 8
ld [hl], a
; Switch to back first VRAM Bank ; Switch to back first VRAM Bank
xor a xor a
ldh [$4F], a ldh [$4F], a
ENDC
pop af pop af
ldi [hl], a ldi [hl], a
inc a add d
dec c dec c
jr nz, .tilemapRowLoop jr nz, .tilemapRowLoop
sub 47
push de
ld de, $10 ld de, $10
add hl, de add hl, de
pop de
dec b dec b
jr nz, .tilemapLoop jr nz, .tilemapLoop
cp $38 dec d
jr nz, .doneTilemap jr z, .endTilemap
dec d
ld hl, $99a7 ld a, $38
ld b, 1 ld l, $a7
ld c, 7 ld bc, $0107
jr .tilemapRowLoop jr .tilemapRowLoop
.doneTilemap .endTilemap
ENDC
; Expand Palettes ; Expand Palettes
ld de, AnimationColors ld de, AnimationColors
@ -187,9 +161,7 @@ ENDC
jr nz, .expandPalettesLoop jr nz, .expandPalettesLoop
ld hl, BgPalettes ld hl, BgPalettes
ld d, 64 ; Length of write call LoadBGPalettes64
ld e, c ; Index of write (C=0)
call LoadBGPalettes
; Turn on LCD ; Turn on LCD
ld a, $91 ld a, $91
@ -560,8 +532,7 @@ TrademarkSymbol:
db $3c,$42,$b9,$a5,$b9,$a5,$42,$3c db $3c,$42,$b9,$a5,$b9,$a5,$42,$3c
SameboyLogo: SameboyLogo:
incbin "SameboyLogo.1bpp" incbin "SameboyLogo.rle"
SameboyLogoEnd:
AnimationColors: AnimationColors:
dw $7FFF ; White dw $7FFF ; White
@ -578,7 +549,9 @@ DMGPalettes:
dw $7FFF, $32BF, $00D0, $0000 dw $7FFF, $32BF, $00D0, $0000
; Helper Functions ; Helper Functions
DoubleBitsAndWriteRow: DoubleBitsAndWriteRowTwice:
call .twice
.twice
; Double the most significant 4 bits, b is shifted by 4 ; Double the most significant 4 bits, b is shifted by 4
ld a, 4 ld a, 4
ld c, 0 ld c, 0
@ -628,6 +601,8 @@ ClearMemoryPage:
jr z, ClearMemoryPage jr z, ClearMemoryPage
ret ret
ReadTwoTileLines:
call ReadTileLine
; c = $f0 for even lines, $f for odd lines. ; c = $f0 for even lines, $f for odd lines.
ReadTileLine: ReadTileLine:
ld a, [de] ld a, [de]
@ -647,34 +622,69 @@ ReadTileLine:
.dontSwap .dontSwap
inc hl inc hl
ldi [hl], a ldi [hl], a
swap c
ret ret
ReadCGBLogoHalfTile: ReadCGBLogoHalfTile:
ld c, $f0 call .do_twice
call ReadTileLine .do_twice
ld c, $f call ReadTwoTileLines
call ReadTileLine
inc e
ld c, $f0
call ReadTileLine
ld c, $f
call ReadTileLine
inc e inc e
ld a, e
ret ret
ReadCGBLogoTile: LoadTileset:
; Copy SameBoy Logo
ld de, SameboyLogo
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
ld c, $f0
call ReadCGBLogoHalfTile call ReadCGBLogoHalfTile
ld a, e
add a, 22 add a, 22
ld e, a ld e, a
call ReadCGBLogoHalfTile call ReadCGBLogoHalfTile
ld a, e
sub a, 22 sub a, 22
ld e, a ld e, a
ret cp $1c
jr nz, .CGBROMLogoLoop
inc hl
; fallthrough
ReadTrademarkSymbol: ReadTrademarkSymbol:
ld de, TrademarkSymbol ld de, TrademarkSymbol
ld c,$08 ld c,$08
@ -691,7 +701,11 @@ LoadObjPalettes:
ld c, $6A ld c, $6A
jr LoadPalettes jr LoadPalettes
LoadBGPalettes64:
ld d, 64
LoadBGPalettes: LoadBGPalettes:
ld e, 0
ld c, $68 ld c, $68
LoadPalettes: LoadPalettes:
@ -706,19 +720,23 @@ LoadPalettes:
jr nz, .loop jr nz, .loop
ret ret
DoIntroAnimation:
AdvanceIntroAnimation: ; Animate the intro
ld a, 1
ldh [$4F], a
ld d, 26
.animationLoop
ld b, 2
call WaitBFrames
ld hl, $98C0 ld hl, $98C0
ld c, 3 ; Row count ld c, 3 ; Row count
.loop .loop
ld a, [hl] ld a, [hl]
cp $F ; Already blue cp $F ; Already blue
jr z, .nextTile jr z, .nextTile
inc a inc [hl]
ld [hl], a
and $7 and $7
cp $1 ; Changed a white tile, go to next line jr z, .nextLine ; Changed a white tile, go to next line
jr z, .nextLine
.nextTile .nextTile
inc hl inc hl
jr .loop jr .loop
@ -728,25 +746,30 @@ AdvanceIntroAnimation:
ld l, a ld l, a
inc hl inc hl
dec c dec c
ret z jr nz, .loop
jr .loop
DoIntroAnimation:
; Animate the intro
ld a, 1
ldh [$4F], a
ld d, 26
.animationLoop
ld b, 2
call WaitBFrames
call AdvanceIntroAnimation
dec d dec d
jr nz, .animationLoop jr nz, .animationLoop
ret ret
Preboot: Preboot:
IF !DEF(FAST) IF !DEF(FAST)
call FadeOut 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
ENDC ENDC
call ClearVRAMViaHDMA call ClearVRAMViaHDMA
; Select the first bank ; Select the first bank
@ -796,7 +819,7 @@ ENDC
.emulateDMGForCGBGame .emulateDMGForCGBGame
call EmulateDMG call EmulateDMG
ldh [$4C], a ldh [$4C], a
ld a, $1; ld a, $1
ret ret
EmulateDMG: EmulateDMG:
@ -833,7 +856,7 @@ GetPaletteIndex:
ld a, [hl] ; Old Licensee ld a, [hl] ; Old Licensee
cp $33 cp $33
jr z, .newLicensee jr z, .newLicensee
cp 1 ; Nintendo dec a ; 1 = Nintendo
jr nz, .notNintendo jr nz, .notNintendo
jr .doChecksum jr .doChecksum
.newLicensee .newLicensee
@ -848,22 +871,22 @@ GetPaletteIndex:
.doChecksum .doChecksum
ld l, $34 ld l, $34
ld c, $10 ld c, $10
ld b, 0 xor a
.checksumLoop .checksumLoop
ld a, [hli] add [hl]
add b inc l
ld b, a
dec c dec c
jr nz, .checksumLoop jr nz, .checksumLoop
ld b, a
; c = 0 ; c = 0
ld hl, TitleChecksums ld hl, TitleChecksums
.searchLoop .searchLoop
ld a, l ld a, l
cp ChecksumsEnd & $FF sub LOW(ChecksumsEnd) ; use sub to zero out a
jr z, .notNintendo ret z
ld a, [hli] ld a, [hli]
cp b cp b
jr nz, .searchLoop jr nz, .searchLoop
@ -932,9 +955,7 @@ LoadPalettesFromIndex: ; a = index of combination
ld c, a ld c, a
add hl, bc add hl, bc
ld d, 8 ld d, 8
ld e, 0 jp LoadBGPalettes
call LoadBGPalettes
ret
BrightenColor: BrightenColor:
ld a, [hli] ld a, [hli]
@ -987,28 +1008,6 @@ BrightenColor:
ld [hli], a ld [hli], a
ret ret
FadeOut:
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
ld d, 64 ; Length of write
ld e, 0 ; Index of write
call LoadBGPalettes
dec b
ret z
jr .fadeLoop
ClearVRAMViaHDMA: ClearVRAMViaHDMA:
ld hl, $FF51 ld hl, $FF51
@ -1025,8 +1024,7 @@ ClearVRAMViaHDMA:
ld [hli], a ld [hli], a
; Do it ; Do it
ld a, $12 ld [hl], $12
ld [hl], a
ret ret
GetInputPaletteIndex: GetInputPaletteIndex:
@ -1124,9 +1122,7 @@ ChangeAnimationPalette:
call WaitFrame call WaitFrame
ld hl, BgPalettes ld hl, BgPalettes
ld d, 64 ; Length of write call LoadBGPalettes64
ld e, 0 ; Index of write
call LoadBGPalettes
; Delay the wait loop while the user is selecting a palette ; Delay the wait loop while the user is selecting a palette
ld a, 30 ld a, 30
ldh [WaitLoopCounter], a ldh [WaitLoopCounter], a

48
BootROMs/logo-compress.c Normal file
View File

@ -0,0 +1,48 @@
#include <assert.h>
#include <inttypes.h>
#include <stdio.h>
void pair(size_t count, uint8_t byte) {
static size_t unique_count = 0;
static uint8_t unique_data[15];
if (count == 1) {
unique_data[unique_count++] = byte;
assert(unique_count <= 15);
} else {
assert(count <= 15);
uint8_t control = (count << 4) | unique_count;
putchar(control);
for (size_t i = 0; i < unique_count; i++) {
putchar(unique_data[i]);
}
if (count != 0) {
putchar(byte);
} else {
assert(control == 0);
}
unique_count = 0;
}
}
int main(int argc, char *argv[]) {
size_t count = 1;
uint8_t byte = getchar();
int new;
size_t position = 0;
while ((new = getchar()) != EOF) {
if (byte == new) {
count++;
} else {
pair(count, byte);
byte = new;
count = 1;
}
}
pair(count, byte);
pair(0, 0);
}

View File

@ -322,13 +322,23 @@ $(BIN)/SDL/Shaders: Shaders
# Boot ROMs # Boot ROMs
$(OBJ)/%.1bpp: %.png
-@$(MKDIR) -p $(dir $@)
rgbgfx -d 1 -h -o $@ $<
$(OBJ)/BootROMs/SameboyLogo.rle: $(OBJ)/BootROMs/SameboyLogo.1bpp build/logo-compress
build/logo-compress < $< > $@
build/logo-compress: BootROMs/logo-compress.c
$(CC) $< -o $@
$(BIN)/BootROMs/agb_boot.bin: BootROMs/cgb_boot.asm $(BIN)/BootROMs/agb_boot.bin: BootROMs/cgb_boot.asm
$(BIN)/BootROMs/cgb_boot_fast.bin: BootROMs/cgb_boot.asm $(BIN)/BootROMs/cgb_boot_fast.bin: BootROMs/cgb_boot.asm
$(BIN)/BootROMs/sgb2_boot: BootROMs/sgb_boot.asm $(BIN)/BootROMs/sgb2_boot: BootROMs/sgb_boot.asm
$(BIN)/BootROMs/%.bin: BootROMs/%.asm $(BIN)/BootROMs/%.bin: BootROMs/%.asm $(OBJ)/BootROMs/SameboyLogo.rle
-@$(MKDIR) -p $(dir $@) -@$(MKDIR) -p $(dir $@)
cd BootROMs && rgbasm -o ../$@.tmp ../$< rgbasm -i $(OBJ)/BootROMs/ -i BootROMs/ -o $@.tmp $<
rgblink -o $@.tmp2 $@.tmp rgblink -o $@.tmp2 $@.tmp
dd if=$@.tmp2 of=$@ count=1 bs=$(if $(findstring dmg,$@)$(findstring sgb,$@),256,2304) dd if=$@.tmp2 of=$@ count=1 bs=$(if $(findstring dmg,$@)$(findstring sgb,$@),256,2304)
@rm $@.tmp $@.tmp2 @rm $@.tmp $@.tmp2