Compress the Sameboy logo. 117 bytes are now free

This commit is contained in:
Jakub Kądziołka 2019-06-10 17:45:14 +02:00
parent 8386aaf12f
commit c678407d1e
No known key found for this signature in database
GPG Key ID: E315A75846131564
4 changed files with 151 additions and 86 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,53 +70,24 @@ 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
IF DEF(FAST) IF DEF(FAST)
xor a xor a
ldh [$4F], a ldh [$4F], a
ELSE ELSE
; Load Tilemap
ld hl, $98C2
ld d, 3
ld a, 8 ld a, 8
ENDC
.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
@ -125,25 +95,29 @@ IF !DEF(FAST)
; 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
@ -661,7 +634,46 @@ ReadCGBLogoHalfTile:
ld a, 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 ld c, $f0
call ReadCGBLogoHalfTile call ReadCGBLogoHalfTile
add a, 22 add a, 22
@ -669,8 +681,10 @@ ReadCGBLogoTile:
call ReadCGBLogoHalfTile call ReadCGBLogoHalfTile
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
@ -687,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:
@ -735,7 +753,23 @@ DoIntroAnimation:
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
@ -921,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]
@ -976,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
@ -1014,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:
@ -1113,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