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