Skip to content

Commit

Permalink
Merge branch 'chore/boot-improvements' into 'master'
Browse files Browse the repository at this point in the history
Boot ROM improvements

See merge request joamag/boytacean!47
  • Loading branch information
joamag committed Jul 17, 2024
2 parents 475998b + d9e2ae8 commit f8d33d9
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 32 deletions.
8 changes: 8 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ stages:
- deploy

before_script:
- source ./.gitlab/common.sh
- apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y -q pkg-config g++ cmake
- curl -sf -L https://static.rust-lang.org/rustup.sh | sh -s -- -y
- export PATH=$PATH:$HOME/.cargo/bin
Expand Down Expand Up @@ -68,6 +69,13 @@ build-pyo3:
- cargo build --features python
- cargo build --release --features python

build-boot:
stage: build
script:
- install_rgbds
- cd src/boot
- make

test-rust:
stage: test
parallel:
Expand Down
11 changes: 11 additions & 0 deletions .gitlab/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
install_rgbds() {
version=${1:-"0.8.0"}
curl -L -o rgbds.tar.xz https://github.com/gbdev/rgbds/releases/download/v$version/rgbds-$version-linux-x86_64.tar.xz
mkdir -p rgbds
mv rgbds.tar.xz rgbds/
pushd rgbds
tar -xf rgbds.tar.xz
popd
export PATH="$CI_PROJECT_DIR/rgbds:$PATH"
rgbasm --version
}
8 changes: 7 additions & 1 deletion src/boot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ The source code for the Boot ROMs has been forked from the [SameBoy](https://git

Special thanks to the original creators and maintainers of [SameBoy](https://github.com/LIJI32/SameBoy) for their work and contributions to the open source community. Their work has been invaluable to the development of the Boytacean project.

## 2bpp file format
## Dependencies

* [rgbds](https://rgbds.gbdev.io)
* [GNU make](https://www.gnu.org/software/make/manual/make.html)
* [Python](https://www.python.org)

## 2BPP file format

To convert a PNG into the 2BPP format, use the following command:

Expand Down
62 changes: 31 additions & 31 deletions src/boot/cgb_boot.asm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; Boytacean CGB bootstrap ROM
; Boostraped from the Sameboy code
; Boostraped from the Sameboy code (https://github.com/LIJI32/SameBoy)

include "common.inc"

Expand Down Expand Up @@ -133,7 +133,7 @@ ELSE
.endTilemap
ENDC

; Expand Palettes
; Expand Palettes
ld de, AnimationColors
ld c, 8
ld hl, hBgPalettes
Expand Down Expand Up @@ -720,7 +720,7 @@ LoadTileset:
cp $1C
jr nz, .CGBROMLogoLoop
inc hl
; fallthrough
; fallthrough
ReadTrademarkSymbol:
ld de, TrademarkSymbol
ld c, TrademarkSymbolEnd - TrademarkSymbol
Expand All @@ -734,22 +734,22 @@ ReadTrademarkSymbol:
ret

DoIntroAnimation:
; Animate the intro
; Animate the intro
ld a, 1
ldh [rVBK], a
ld d, 26
.animationLoop
ld b, 2
call WaitBFrames
ld hl, _SCRN0 + 6 * SCRN_VX_B + 0
ld c, 3 ; Row count
ld c, 3 ; row count
.loop
ld a, [hl]
cp $F ; Already blue
cp $F ; already blue
jr z, .nextTile
inc [hl]
and $7
jr z, .nextLine ; Changed a white tile, go to next line
jr z, .nextLine ; changes a white tile, go to next line
.nextTile
inc hl
jr .loop
Expand All @@ -773,23 +773,23 @@ IF !DEF(FAST)
.frameLoop
push bc

; Brighten Color
; Brighten Color
ld a, [hli]
ld e, a
ld a, [hld]
ld d, a
; RGB(1,1,1)
ld bc, $0421

; Is blue maxed?
; Is blue maxed?
ld a, e
and $1F
cp $1F
jr nz, .blueNotMaxed
dec c
.blueNotMaxed

; Is green maxed?
; Is green maxed?
ld a, e
cp $E0
jr c, .greenNotMaxed
Expand All @@ -800,7 +800,7 @@ IF !DEF(FAST)
res 5, c
.greenNotMaxed

; Is red maxed?
; Is red maxed?
ld a, d
and $7C
cp $7C
Expand All @@ -827,7 +827,7 @@ IF !DEF(FAST)
ENDC
ld a, 2
ldh [rSVBK], a
; Clear RAM Bank 2 (Like the original boot ROM)
; Clear RAM Bank 2 (Like the original boot ROM)
ld hl, _RAMBANK
call ClearMemoryPage
inc a
Expand All @@ -839,7 +839,7 @@ ENDC
cpl
ldh [rJOYP], a

; Final values for CGB mode
; Final values for CGB mode
ld d, a
ld e, c
ld l, $0D
Expand All @@ -859,21 +859,21 @@ ENDC
jr nz, .emulateDMGForCGBGame
.skipDMGForCGBCheck
IF DEF(AGB)
; Set registers to match the original AGB-CGB boot
; AF = $1100, C = 0
; Set registers to match the original AGB-CGB boot
; AF = $1100, C = 0
xor a
ld c, a
add a, BOOTUP_A_CGB
ld h, c
; B is set to BOOTUP_B_AGB (1) after ret
; B is set to BOOTUP_B_AGB (1) after ret
ELSE
; Set registers to match the original CGB boot
; AF = $1180, C = 0
; Set registers to match the original CGB boot
; AF = $1180, C = 0
xor a
ld c, a
ld a, BOOTUP_A_CGB
ld h, c
; B is set to the title checksum (BOOTUP_B_CGB, 0)
; B is set to the title checksum (BOOTUP_B_CGB, 0)
ENDC
ret

Expand All @@ -884,7 +884,7 @@ ENDC
ret

GetKeyComboPalette:
ld hl, KeyCombinationPalettes - 1 ; Return value is 1-based, 0 means nothing down
ld hl, KeyCombinationPalettes - 1 ; return value is 1-based, 0 means nothing down
ld c, a
ld b, 0
add hl, bc
Expand Down Expand Up @@ -913,7 +913,7 @@ EmulateDMG:
call WaitFrame
call LoadPalettesFromIndex
ld a, 4
; Set the final values for DMG mode
; Set the final values for DMG mode
ld de, 8
ld l, $7C
ret
Expand Down Expand Up @@ -958,11 +958,11 @@ GetPaletteIndex:
cp b
jr nz, .searchLoop

; We might have a match, Do duplicate/4th letter check
; We might have a match, Do duplicate/4th letter check
ld a, l
sub FirstChecksumWithDuplicate - TitleChecksums + 1
jr c, .match ; Does not have a duplicate, must be a match!
; Has a duplicate; check 4th letter
; Has a duplicate; check 4th letter
push hl
ld a, l
add Dups4thLetterArray - FirstChecksumWithDuplicate - 1 ; -1 since hl was incremented
Expand All @@ -987,7 +987,7 @@ GetPaletteIndex:
xor a
ret

; optimizations in callers rely on this returning with b = 0
; Optimizations in callers rely on this returning with b = 0
GetPaletteCombo:
ld hl, PaletteCombinations
ld b, 0
Expand All @@ -998,13 +998,13 @@ GetPaletteCombo:
LoadPalettesFromIndex: ; a = index of combination
call GetPaletteCombo

; Obj Palettes
; Obj Palettes
ld e, 0
.loadObjPalette
ld a, [hli]
push hl
ld hl, Palettes
; b is already 0
; b is already 0
ld c, a
add hl, bc
ld d, 4 * 2
Expand All @@ -1016,9 +1016,9 @@ LoadPalettesFromIndex: ; a = index of combination
ld e, OAMF_BANK1
jr .loadObjPalette
.loadBGPalette
;BG Palette
; BG Palette
ld c, [hl]
; b is already 0
; b is already 0
ld hl, Palettes
add hl, bc
ld d, 8
Expand Down Expand Up @@ -1072,7 +1072,7 @@ GetInputPaletteIndex:
rra
jr nc, .directionLoop

; c = 1: Right, 2: Left, 3: Up, 4: Down
; c = 1: Right, 2: Left, 3: Up, 4: Down

ld a, P1F_GET_BTN
ldh [rJOYP], a
Expand All @@ -1088,7 +1088,7 @@ GetInputPaletteIndex:
ret z ; No change, don't load
ld a, l
ldh [hInputPalette], a
; Slide into change Animation Palette
; Slide into change Animation Palette

ChangeAnimationPalette:
push bc
Expand Down Expand Up @@ -1131,7 +1131,7 @@ ChangeAnimationPalette:
inc hl
inc hl
.isNotWhite
; Mixing code by ISSOtm
; Mixing code by ISSOtm
ldh a, [hBgPalettes + 7 * 8 + 2]
and ~$21
ld b, a
Expand Down
3 changes: 3 additions & 0 deletions src/boot/util/lre.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys

STRIP_EXTRA = False
Expand Down

0 comments on commit f8d33d9

Please sign in to comment.