Update bootrom code with the latest hardware.inc

This commit is contained in:
Rangi42 2024-06-20 01:30:54 -04:00
parent 3116f63e37
commit 9588cf44aa
11 changed files with 704 additions and 492 deletions

View File

@ -1,2 +1,2 @@
DEF AGB = 1
include "cgb_boot.asm"
DEF AGB = 1
include "cgb_boot.asm"

View File

@ -1,2 +1,2 @@
DEF CGB0 = 1
include "cgb_boot.asm"
DEF CGB0 = 1
include "cgb_boot.asm"

File diff suppressed because it is too large Load Diff

View File

@ -1,2 +1,2 @@
DEF FAST = 1
include "cgb_boot.asm"
DEF FAST = 1
include "cgb_boot.asm"

View File

@ -1,14 +1,14 @@
; SameBoy DMG bootstrap ROM
INCLUDE "hardware.inc"
include "sameboot.inc"
SECTION "BootCode", ROM0[$0]
SECTION "BootCode", ROM0[$0000]
Start:
; Init stack pointer
ld sp, $fffe
ld sp, $FFFE
; Clear memory VRAM
ld hl, $8000
ld hl, _VRAM
xor a
.clearVRAMLoop
@ -17,24 +17,25 @@ Start:
jr z, .clearVRAMLoop
; Init Audio
ld a, $80
ld a, AUDENA_ON
ldh [rNR52], a
assert AUDENA_ON == AUDLEN_DUTY_50
ldh [rNR11], a
ld a, $f3
ldh [rNR12], a
ldh [rNR51], a
ld a, $F3
ldh [rNR12], a ; Envelope $F, decreasing, sweep $3
ldh [rNR51], a ; Channels 1+2+3+4 left, channels 1+2 right
ld a, $77
ldh [rNR50], a
ldh [rNR50], a ; Volume $7, left and right
; Init BG palette
ld a, $54
ld a, %01_01_01_00
ldh [rBGP], a
; 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.
ld de, $104 ; Logo start
ld hl, $8010 ; This is where we load the tiles in VRAM
ld de, NintendoLogo
ld hl, _VRAM + $10 ; This is where we load the tiles in VRAM
.loadLogoLoop
ld a, [de] ; Read 2 rows
@ -43,45 +44,45 @@ Start:
call DoubleBitsAndWriteRow
inc de
ld a, e
xor $34 ; End of logo
xor LOW(NintendoLogoEnd)
jr nz, .loadLogoLoop
; Load trademark symbol
ld de, TrademarkSymbol
ld c,$08
ld c, TrademarkSymbolEnd - TrademarkSymbol
.loadTrademarkSymbolLoop:
ld a,[de]
ld a, [de]
inc de
ldi [hl],a
ldi [hl], a
inc hl
dec c
jr nz, .loadTrademarkSymbolLoop
; Set up tilemap
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
ld a, $19 ; Trademark symbol tile ID
ld [_SCRN0 + 8 * SCRN_VX_B + 16], a ; ... put in the superscript position
ld hl, _SCRN0 + 9 * SCRN_VX_B + 15 ; Bottom right corner of the logo
ld c, 12 ; Tiles in a logo row
.tilemapLoop
dec a
jr z, .tilemapDone
ldd [hl], a
dec c
jr nz, .tilemapLoop
ld l,$0f ; Jump to top row
ld l, $0F ; Jump to top row
jr .tilemapLoop
.tilemapDone
ld a, 30
ldh [rSCY], a
; Turn on LCD
ld a, $91
ld a, LCDCF_ON | LCDCF_BLK01 | LCDCF_BGON
ldh [rLCDC], a
ld d, (-119) & $FF
ld d, LOW(-119)
ld c, 15
.animate
call WaitFrame
ld a, d
@ -94,41 +95,41 @@ Start:
ld a, c
cp 8
jr nz, .noPaletteChange
ld a, $A8
ld a, %10_10_10_00
ldh [rBGP], a
.noPaletteChange
dec c
jr nz, .animate
ld a, $fc
ld a, %11_11_11_00
ldh [rBGP], a
; Play first sound
ld a, $83
call PlaySound
ld b, 5
call WaitBFrames
; Play second sound
ld a, $c1
ld a, $C1
call PlaySound
; Wait ~1 second
ld b, 60
call WaitBFrames
; Set registers to match the original DMG boot
IF DEF(MGB)
ld hl, $FFB0
ld hl, (BOOTUP_A_MGB << 8) | $B0
ELSE
ld hl, $01B0
ld hl, (BOOTUP_A_DMG << 8) | $B0
ENDC
push hl
pop af
ld hl, $014D
ld bc, $0013
ld de, $00D8
ld hl, HeaderChecksum
lb bc, 0, LOW(rNR13) ; $0013
lb de, 0, $D8 ; $00D8
; Boot the game
jp BootGame
@ -155,7 +156,7 @@ DoubleBitsAndWriteRow:
WaitFrame:
push hl
ld hl, $FF0F
ld hl, rIF
res 0, [hl]
.wait
bit 0, [hl]
@ -171,14 +172,25 @@ WaitBFrames:
PlaySound:
ldh [rNR13], a
ld a, $87
ld a, AUDHIGH_RESTART | $7
ldh [rNR14], a
ret
TrademarkSymbol:
db $3c,$42,$b9,$a5,$b9,$a5,$42,$3c
pusho
opt b.X
db %..XXXX..
db %.X....X.
db %X.XXX..X
db %X.X..X.X
db %X.XXX..X
db %X.X..X.X
db %.X....X.
db %..XXXX..
popo
TrademarkSymbolEnd:
SECTION "BootGame", ROM0[$fe]
SECTION "BootGame", ROM0[$00FE]
BootGame:
ldh [rBANK], a ; unmap boot ROM
ldh [rBANK], a ; unmap boot ROM

View File

@ -1,9 +1,16 @@
;*
;* Gameboy Hardware definitions
;* https://github.com/gbdev/hardware.inc
;*
;* Based on Jones' hardware.inc
;* And based on Carsten Sorensen's ideas.
;*
;* To the extent possible under law, the authors of this work have
;* waived all copyright and related or neighboring rights to the work.
;* See https://creativecommons.org/publicdomain/zero/1.0/ for details.
;*
;* SPDX-License-Identifier: CC0-1.0
;*
;* Rev 1.1 - 15-Jul-97 : Added define check
;* Rev 1.2 - 18-Jul-97 : Added revision check macro
;* Rev 1.3 - 19-Jul-97 : Modified for RGBASM V1.05
@ -31,6 +38,17 @@
;* Rev 4.3 - 07-Nov-21 : Deprecate VRAM address constants (Eievui)
;* Rev 4.4 - 11-Jan-22 : Deprecate VRAM CART_SRAM_2KB constant (avivace)
;* Rev 4.5 - 03-Mar-22 : Added bit number definitions for OCPS, BCPS and LCDC (sukus)
;* Rev 4.6 - 15-Jun-22 : Added MBC3 registers and special values
;* Rev 4.7.0 - 27-Jun-22 : Added alternate names for some constants
;* Rev 4.7.1 - 05-Jul-22 : Added RPB_LED_ON constant
;* Rev 4.8.0 - 25-Oct-22 : Changed background addressing constants (zlago)
;* Rev 4.8.1 - 29-Apr-23 : Added rOPRI (rbong)
;* Rev 4.9.0 - 24-Jun-23 : Added definitions for interrupt vectors (sukus)
;* Rev 4.9.1 - 11-Sep-23 : Added repository link and CC0 waiver notice
; NOTE: REVISION NUMBER CHANGES MUST BE REFLECTED
; IN `rev_Check_hardware_inc` BELOW!
IF __RGBDS_MAJOR__ == 0 && __RGBDS_MINOR__ < 5
FAIL "This version of 'hardware.inc' requires RGBDS version 0.5.0 or later."
@ -41,14 +59,31 @@ ENDC
IF !DEF(HARDWARE_INC)
DEF HARDWARE_INC EQU 1
; Usage: rev_Check_hardware_inc <min_ver>
; Examples: rev_Check_hardware_inc 4.1.2
; rev_Check_hardware_inc 4.1 (equivalent to 4.1.0)
; rev_Check_hardware_inc 4 (equivalent to 4.0.0)
MACRO rev_Check_hardware_inc
;NOTE: REVISION NUMBER CHANGES MUST BE ADDED
;TO SECOND PARAMETER IN FOLLOWING LINE.
IF \1 > 4.5 ;PUT REVISION NUMBER HERE
WARN "Version \1 or later of 'hardware.inc' is required."
DEF CUR_VER equs "4,9,1" ; ** UPDATE THIS LINE WHEN CHANGING THE REVISION NUMBER **
DEF MIN_VER equs STRRPL("\1", ".", ",")
DEF INTERNAL_CHK equs """MACRO ___internal
IF \\1 != \\4 || \\2 < \\5 || (\\2 == \\5 && \\3 < \\6)
FAIL "Version \\1.\\2.\\3 of 'hardware.inc' is incompatible with requested version \\4.\\5.\\6"
ENDC
\nENDM"""
INTERNAL_CHK
___internal {CUR_VER}, {MIN_VER},0,0
PURGE CUR_VER, MIN_VER, INTERNAL_CHK, ___internal
ENDM
;***************************************************************************
;*
;* General memory region constants
;*
;***************************************************************************
DEF _VRAM EQU $8000 ; $8000->$9FFF
DEF _SCRN0 EQU $9800 ; $9800->$9BFF
DEF _SCRN1 EQU $9C00 ; $9C00->$9FFF
@ -60,17 +95,80 @@ DEF _IO EQU $FF00 ; $FF00->$FF7F,$FFFF
DEF _AUD3WAVERAM EQU $FF30 ; $FF30->$FF3F
DEF _HRAM EQU $FF80 ; $FF80->$FFFE
; *** MBC5 Equates ***
DEF rRAMG EQU $0000 ; $0000->$1fff
DEF rROMB0 EQU $2000 ; $2000->$2fff
DEF rROMB1 EQU $3000 ; $3000->$3fff - If more than 256 ROM banks are present.
DEF rRAMB EQU $4000 ; $4000->$5fff - Bit 3 enables rumble (if present)
;***************************************************************************
;*
;* MBC registers
;*
;***************************************************************************
; *** Common ***
; --
; -- RAMG ($0000-$1FFF)
; -- Controls whether access to SRAM (and the MBC3 RTC registers) is allowed (W)
; --
DEF rRAMG EQU $0000
DEF CART_SRAM_ENABLE EQU $0A
DEF CART_SRAM_DISABLE EQU $00
; --
; -- ROMB0 ($2000-$3FFF)
; -- Selects which ROM bank is mapped to the ROMX space ($4000-$7FFF) (W)
; --
; -- The range of accepted values, as well as the behavior of writing $00,
; -- varies depending on the MBC.
; --
DEF rROMB0 EQU $2000
; --
; -- RAMB ($4000-$5FFF)
; -- Selects which SRAM bank is mapped to the SRAM space ($A000-$BFFF) (W)
; --
; -- The range of accepted values varies depending on the cartridge configuration.
; --
DEF rRAMB EQU $4000
; *** MBC3-specific registers ***
; Write one of these to rRAMG to map the corresponding RTC register to all SRAM space
DEF RTC_S EQU $08 ; Seconds (0-59)
DEF RTC_M EQU $09 ; Minutes (0-59)
DEF RTC_H EQU $0A ; Hours (0-23)
DEF RTC_DL EQU $0B ; Lower 8 bits of Day Counter ($00-$FF)
DEF RTC_DH EQU $0C ; Bit 7 - Day Counter Carry Bit (1=Counter Overflow)
; Bit 6 - Halt (0=Active, 1=Stop Timer)
; Bit 0 - Most significant bit of Day Counter (Bit 8)
; --
; -- RTCLATCH ($6000-$7FFF)
; -- Write $00 then $01 to latch the current time into the RTC registers (W)
; --
DEF rRTCLATCH EQU $6000
; *** MBC5-specific register ***
; --
; -- ROMB1 ($3000-$3FFF)
; -- A 9th bit that "extends" ROMB0 if more than 256 banks are present (W)
; --
; -- Also note that rROMB0 thus only spans $2000-$2FFF.
; --
DEF rROMB1 EQU $3000
; Bit 3 of RAMB enables the rumble motor (if any)
DEF CART_RUMBLE_ON EQU 1 << 3
;***************************************************************************
;*
;* Custom registers
;* Memory-mapped registers
;*
;***************************************************************************
@ -105,9 +203,9 @@ DEF rSB EQU $FF01
; --
DEF rSC EQU $FF02
DEF SCF_START EQU %10000000 ;Transfer Start Flag (1=Transfer in progress, or requested)
DEF SCF_SPEED EQU %00000010 ;Clock Speed (0=Normal, 1=Fast) ** CGB Mode Only **
DEF SCF_SOURCE EQU %00000001 ;Shift Clock (0=External Clock, 1=Internal Clock)
DEF SCF_START EQU %10000000 ; Transfer Start Flag (1=Transfer in progress, or requested)
DEF SCF_SPEED EQU %00000010 ; Clock Speed (0=Normal, 1=Fast) ** CGB Mode Only **
DEF SCF_SOURCE EQU %00000001 ; Shift Clock (0=External Clock, 1=Internal Clock)
DEF SCB_START EQU 7
DEF SCB_SPEED EQU 1
@ -444,8 +542,8 @@ DEF LCDCF_WIN9800 EQU %00000000 ; Window Tile Map Display Select
DEF LCDCF_WIN9C00 EQU %01000000 ; Window Tile Map Display Select
DEF LCDCF_WINOFF EQU %00000000 ; Window Display
DEF LCDCF_WINON EQU %00100000 ; Window Display
DEF LCDCF_BG8800 EQU %00000000 ; BG & Window Tile Data Select
DEF LCDCF_BG8000 EQU %00010000 ; BG & Window Tile Data Select
DEF LCDCF_BLK21 EQU %00000000 ; BG & Window Tile Data Select
DEF LCDCF_BLK01 EQU %00010000 ; BG & Window Tile Data Select
DEF LCDCF_BG9800 EQU %00000000 ; BG Tile Map Display Select
DEF LCDCF_BG9C00 EQU %00001000 ; BG Tile Map Display Select
DEF LCDCF_OBJ8 EQU %00000000 ; OBJ Construction
@ -458,7 +556,7 @@ DEF LCDCF_BGON EQU %00000001 ; BG Display
DEF LCDCB_ON EQU 7 ; LCD Control Operation
DEF LCDCB_WIN9C00 EQU 6 ; Window Tile Map Display Select
DEF LCDCB_WINON EQU 5 ; Window Display
DEF LCDCB_BG8000 EQU 4 ; BG & Window Tile Data Select
DEF LCDCB_BLKS EQU 4 ; BG & Window Tile Data Select
DEF LCDCB_BG9C00 EQU 3 ; BG Tile Map Display Select
DEF LCDCB_OBJ16 EQU 2 ; OBJ Construction
DEF LCDCB_OBJON EQU 1 ; OBJ Display
@ -661,39 +759,65 @@ DEF RPF_DATAIN EQU %00000010 ; 0=Receiving IR Signal, 1=Normal
DEF RPF_WRITE_HI EQU %00000001
DEF RPF_WRITE_LO EQU %00000000
DEF RPB_LED_ON EQU 0
DEF RPB_DATAIN EQU 1
; --
; -- BCPS ($FF68)
; -- Background Color Palette Specification (R/W)
; -- BCPS/BGPI ($FF68)
; -- Background Color Palette Specification (aka Background Palette Index) (R/W)
; --
DEF rBCPS EQU $FF68
DEF rBGPI EQU rBCPS
DEF BCPSF_AUTOINC EQU %10000000 ; Auto Increment (0=Disabled, 1=Increment after Writing)
DEF BCPSB_AUTOINC EQU 7
DEF BGPIF_AUTOINC EQU BCPSF_AUTOINC
DEF BGPIB_AUTOINC EQU BCPSB_AUTOINC
; --
; -- BCPD ($FF69)
; -- Background Color Palette Data (R/W)
; -- BCPD/BGPD ($FF69)
; -- Background Color Palette Data (aka Background Palette Data) (R/W)
; --
DEF rBCPD EQU $FF69
DEF rBGPD EQU rBCPD
; --
; -- OCPS ($FF6A)
; -- Object Color Palette Specification (R/W)
; -- OCPS/OBPI ($FF6A)
; -- Object Color Palette Specification (aka Object Background Palette Index) (R/W)
; --
DEF rOCPS EQU $FF6A
DEF rOBPI EQU rOCPS
DEF OCPSF_AUTOINC EQU %10000000 ; Auto Increment (0=Disabled, 1=Increment after Writing)
DEF OCPSB_AUTOINC EQU 7
DEF OBPIF_AUTOINC EQU OCPSF_AUTOINC
DEF OBPIB_AUTOINC EQU OCPSB_AUTOINC
; --
; -- OCPD ($FF6B)
; -- Object Color Palette Data (R/W)
; -- OCPD/OBPD ($FF6B)
; -- Object Color Palette Data (aka Object Background Palette Data) (R/W)
; --
DEF rOCPD EQU $FF6B
DEF rOBPD EQU rOCPD
; --
; -- OPRI ($FF6C)
; -- Object Priority Mode (R/W)
; -- CGB Only
; --
; -- Priority can be changed only from the boot ROM
; --
DEF rOPRI EQU $FF6C
DEF OPRI_OAM EQU 0 ; Prioritize objects by location in OAM (CGB Mode default)
DEF OPRI_COORD EQU 1 ; Prioritize objects by x-coordinate (Non-CGB Mode default)
; --
@ -726,17 +850,6 @@ DEF rPCM12 EQU $FF76
DEF rPCM34 EQU $FF77
; SameBoy additions
DEF rKEY0 EQU $FF4C
DEF rBANK EQU $FF50
DEF rOPRI EQU $FF6C
DEF rJOYP EQU rP1
DEF rBGPI EQU rBCPS
DEF rBGPD EQU rBCPD
DEF rOBPI EQU rOCPS
DEF rOBPD EQU rOCPD
; --
; -- IE ($FFFF)
; -- Interrupt Enable (R/W)
@ -790,7 +903,6 @@ DEF AUDENV_DOWN EQU %00000000
; -- Can be used with AUD1HIGH, AUD2HIGH, AUD3HIGH
; -- See AUD1HIGH for more info
; --
DEF AUDHIGH_RESTART EQU %10000000
DEF AUDHIGH_LENGTH_ON EQU %01000000
DEF AUDHIGH_LENGTH_OFF EQU %00000000
@ -814,10 +926,33 @@ DEF BOOTUP_B_AGB EQU %00000001 ; GBA, GBA SP, Game Boy Player, or New GBA S
;***************************************************************************
;*
;* Cart related
;* Interrupt vector addresses
;*
;***************************************************************************
DEF INT_HANDLER_VBLANK EQU $0040
DEF INT_HANDLER_STAT EQU $0048
DEF INT_HANDLER_TIMER EQU $0050
DEF INT_HANDLER_SERIAL EQU $0058
DEF INT_HANDLER_JOYPAD EQU $0060
;***************************************************************************
;*
;* Header
;*
;***************************************************************************
;*
;* Nintendo scrolling logo
;* (Code won't work on a real GameBoy)
;* (if next lines are altered.)
MACRO NINTENDO_LOGO
DB $CE,$ED,$66,$66,$CC,$0D,$00,$0B,$03,$73,$00,$83,$00,$0C,$00,$0D
DB $00,$08,$11,$1F,$88,$89,$00,$0E,$DC,$CC,$6E,$E6,$DD,$DD,$D9,$99
DB $BB,$BB,$67,$63,$6E,$0E,$EC,$CC,$DD,$DC,$99,$9F,$BB,$B9,$33,$3E
ENDM
; $0143 Color GameBoy compatibility code
DEF CART_COMPATIBLE_DMG EQU $00
DEF CART_COMPATIBLE_DMG_GBC EQU $80
@ -878,9 +1013,6 @@ DEF CART_SRAM_8KB EQU 2 ; 1 bank
DEF CART_SRAM_32KB EQU 3 ; 4 banks
DEF CART_SRAM_128KB EQU 4 ; 16 banks
DEF CART_SRAM_ENABLE EQU $0A
DEF CART_SRAM_DISABLE EQU $00
; $014A Destination code
DEF CART_DEST_JAPANESE EQU $00
DEF CART_DEST_NON_JAPANESE EQU $01
@ -918,7 +1050,7 @@ DEF PADB_A EQU $0
;***************************************************************************
DEF SCRN_X EQU 160 ; Width of screen in pixels
DEF SCRN_Y EQU 144 ; Height of screen in pixels
DEF SCRN_Y EQU 144 ; Height of screen in pixels. Also corresponds to the value in LY at the beginning of VBlank.
DEF SCRN_X_B EQU 20 ; Width of screen in bytes
DEF SCRN_Y_B EQU 18 ; Height of screen in bytes
@ -966,16 +1098,6 @@ DEF OAMB_PAL1 EQU 4 ; Palette number; 0,1 (DMG)
DEF OAMB_BANK1 EQU 3 ; Bank number; 0,1 (GBC)
;*
;* Nintendo scrolling logo
;* (Code won't work on a real GameBoy)
;* (if next lines are altered.)
MACRO NINTENDO_LOGO
DB $CE,$ED,$66,$66,$CC,$0D,$00,$0B,$03,$73,$00,$83,$00,$0C,$00,$0D
DB $00,$08,$11,$1F,$88,$89,$00,$0E,$DC,$CC,$6E,$E6,$DD,$DD,$D9,$99
DB $BB,$BB,$67,$63,$6E,$0E,$EC,$CC,$DD,$DC,$99,$9F,$BB,$B9,$33,$3E
ENDM
; Deprecated constants. Please avoid using.
DEF IEF_LCDC EQU %00000010 ; LCDC (see STAT)
@ -983,6 +1105,9 @@ DEF _VRAM8000 EQU _VRAM
DEF _VRAM8800 EQU _VRAM+$800
DEF _VRAM9000 EQU _VRAM+$1000
DEF CART_SRAM_2KB EQU 1 ; 1 incomplete bank
DEF LCDCF_BG8800 EQU %00000000 ; BG & Window Tile Data Select
DEF LCDCF_BG8000 EQU %00010000 ; BG & Window Tile Data Select
DEF LCDCB_BG8000 EQU 4 ; BG & Window Tile Data Select
ENDC ;HARDWARE_INC

View File

@ -1,2 +1,2 @@
DEF MGB = 1
include "dmg_boot.asm"
DEF MGB = 1
include "dmg_boot.asm"

40
BootROMs/sameboot.inc Normal file
View File

@ -0,0 +1,40 @@
IF !DEF(SAMEBOY_INC)
DEF SAMEBOY_INC EQU 1
include "hardware.inc"
DEF rKEY0 EQU $FF4C
DEF rBANK EQU $FF50
DEF rJOYP EQU rP1
MACRO lb ; r16, high, low
ld \1, LOW(\2) << 8 | LOW(\3)
ENDM
MACRO header_section ; name, address
PUSHS
SECTION "\1", ROM0[\2]
\1:
POPS
ENDM
header_section EntryPoint, $0100
header_section NintendoLogo, $0104
header_section NintendoLogoEnd, $0134
header_section Title, $0134
header_section ManufacturerCode, $013F
header_section CgbFlag, $0143
header_section NewLicenseeCode, $0144
header_section SgbFlag, $0146
header_section CartridgeType, $0147
header_section RomSize, $0148
header_section RamSize, $0149
header_section DestinationCode, $014A
header_section OldLicenseeCode, $014B
header_section MaskRomVersion, $014C
header_section HeaderChecksum, $014D
header_section GlobalChecksum, $014E
ENDC

View File

@ -1,2 +1,2 @@
DEF SGB2 = 1
include "sgb_boot.asm"
DEF SGB2 = 1
include "sgb_boot.asm"

View File

@ -1,14 +1,14 @@
; SameBoy SGB bootstrap ROM
INCLUDE "hardware.inc"
include "sameboot.inc"
SECTION "BootCode", ROM0[$0]
SECTION "BootCode", ROM0[$0000]
Start:
; Init stack pointer
ld sp, $fffe
ld sp, $FFFE
; Clear memory VRAM
ld hl, $8000
ld hl, _VRAM
xor a
.clearVRAMLoop
@ -17,24 +17,25 @@ Start:
jr z, .clearVRAMLoop
; Init Audio
ld a, $80
ld a, AUDENA_ON
ldh [rNR52], a
assert AUDENA_ON == AUDLEN_DUTY_50
ldh [rNR11], a
ld a, $f3
ldh [rNR12], a
ldh [rNR51], a
ld a, $F3
ldh [rNR12], a ; Envelope $F, decreasing, sweep $3
ldh [rNR51], a ; Channels 1+2+3+4 left, channels 1+2 right
ld a, $77
ldh [rNR50], a
ldh [rNR50], a ; Volume $7, left and right
; Init BG palette to white
ld a, $0
ld a, %00_00_00_00
ldh [rBGP], a
; 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.
ld de, $104 ; Logo start
ld hl, $8010 ; This is where we load the tiles in VRAM
ld de, NintendoLogo
ld hl, _VRAM + $10 ; This is where we load the tiles in VRAM
.loadLogoLoop
ld a, [de] ; Read 2 rows
@ -43,43 +44,43 @@ Start:
call DoubleBitsAndWriteRow
inc de
ld a, e
xor $34 ; End of logo
xor LOW(NintendoLogoEnd)
jr nz, .loadLogoLoop
; Load trademark symbol
ld de, TrademarkSymbol
ld c,$08
ld c, TrademarkSymbolEnd - TrademarkSymbol
.loadTrademarkSymbolLoop:
ld a,[de]
ld a, [de]
inc de
ldi [hl],a
ldi [hl], a
inc hl
dec c
jr nz, .loadTrademarkSymbolLoop
; Set up tilemap
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
ld a, $19 ; Trademark symbol tile ID
ld [_SCRN0 + 8 * SCRN_VX_B + 16], a ; ... put in the superscript position
ld hl, _SCRN0 + 9 * SCRN_VX_B + 15 ; Bottom right corner of the logo
ld c, 12 ; Tiles in a logo row
.tilemapLoop
dec a
jr z, .tilemapDone
ldd [hl], a
dec c
jr nz, .tilemapLoop
ld l,$0f ; Jump to top row
ld l, $0F ; Jump to top row
jr .tilemapLoop
.tilemapDone
; Turn on LCD
ld a, $91
ld a, LCDCF_ON | LCDCF_BLK01 | LCDCF_BGON
ldh [rLCDC], a
ld a, $f1 ; Packet magic, increases by 2 for every packet
ldh [_HRAM], a
ld hl, $104 ; Header start
ld a, $F1 ; Packet magic, increases by 2 for every packet
ldh [hCommand], a
ld hl, NintendoLogo ; Header start
xor a
ld c, a ; JOYP
@ -88,37 +89,37 @@ Start:
ld [c], a
ld a, $30
ld [c], a
ldh a, [_HRAM]
ldh a, [hCommand]
call SendByte
push hl
ld b, $e
ld b, 14
ld d, 0
.checksumLoop
call ReadHeaderByte
add d
ld d, a
dec b
jr nz, .checksumLoop
; Send checksum
call SendByte
pop hl
ld b, $e
ld b, 14
.sendLoop
call ReadHeaderByte
call SendByte
dec b
jr nz, .sendLoop
; Done bit
ld a, $20
ld [c], a
ld a, $30
ld [c], a
; Wait 4 frames
ld e, 4
ld a, 1
@ -126,41 +127,41 @@ Start:
xor a
.waitLoop
ldh [rIF], a
db $76 ; halt, compatible with rgbds 0.5-0.8
halt
nop
dec e
jr nz, .waitLoop
ldh [rIE], a
; Update command
ldh a, [_HRAM]
ldh a, [hCommand]
add 2
ldh [_HRAM], a
ldh [hCommand], a
ld a, $58
cp l
jr nz, .sendCommand
; Write to sound registers for DMG compatibility
ld c, $13
ld a, $c1
ld c, LOW(rNR13)
ld a, $C1
ld [c], a
inc c
ld a, 7
ld a, $7
ld [c], a
; Init BG palette
ld a, $fc
ld a, %11_11_11_00
ldh [rBGP], a
; Set registers to match the original SGB boot
IF DEF(SGB2)
ld a, $FF
ld a, BOOTUP_A_MGB
ELSE
ld a, 1
ld a, BOOTUP_A_DMG
ENDC
ld hl, $c060
ld hl, $C060
; Boot the game
jp BootGame
@ -212,8 +213,23 @@ DoubleBitsAndWriteRow:
ret
TrademarkSymbol:
db $3c,$42,$b9,$a5,$b9,$a5,$42,$3c
pusho
opt b.X
db %..XXXX..
db %.X....X.
db %X.XXX..X
db %X.X..X.X
db %X.XXX..X
db %X.X..X.X
db %.X....X.
db %..XXXX..
popo
TrademarkSymbolEnd:
SECTION "BootGame", ROM0[$fe]
SECTION "BootGame", ROM0[$00FE]
BootGame:
ldh [rBANK], a
ldh [rBANK], a
SECTION "HRAM", HRAM[_HRAM]
hCommand:
ds 1

View File

@ -387,7 +387,7 @@ endif
$(OBJ)/SDL/%.dep: SDL/%
-@$(MKDIR) -p $(dir $@)
$(CC) $(CFLAGS) $(SDL_CFLAGS) $(GL_CFLAGS) -MT $(OBJ)/$^.o -M $^ -c -o $@
$(OBJ)/OpenDialog/%.dep: OpenDialog/%
-@$(MKDIR) -p $(dir $@)
$(CC) $(CFLAGS) $(SDL_CFLAGS) $(GL_CFLAGS) -MT $(OBJ)/$^.o -M $^ -c -o $@
@ -414,16 +414,16 @@ $(OBJ)/OpenDialog/%.c.o: OpenDialog/%.c
$(OBJ)/%.c.o: %.c
-@$(MKDIR) -p $(dir $@)
$(CC) $(CFLAGS) $(FRONTEND_CFLAGS) $(FAT_FLAGS) -c $< -o $@
# HexFiend requires more flags
$(OBJ)/HexFiend/%.m.o: HexFiend/%.m
-@$(MKDIR) -p $(dir $@)
$(CC) $(CFLAGS) $(FRONTEND_CFLAGS) $(FAT_FLAGS) $(OCFLAGS) -c $< -o $@ -fno-objc-arc -include HexFiend/HexFiend_2_Framework_Prefix.pch
$(OBJ)/%.m.o: %.m
-@$(MKDIR) -p $(dir $@)
$(CC) $(CFLAGS) $(FRONTEND_CFLAGS) $(FAT_FLAGS) $(OCFLAGS) -c $< -o $@
# iOS Port
$(BIN)/SameBoy-iOS.app: $(BIN)/SameBoy-iOS.app/SameBoy \
@ -495,7 +495,7 @@ endif
$(BIN)/SameBoy.app/Contents/Resources/%.nib: Cocoa/%.xib
ibtool --target-device mac --minimum-deployment-target 10.9 --compile $@ $^ 2>&1 | cat -
$(BIN)/SameBoy-iOS.app/%.storyboardc: iOS/%.storyboard
ibtool --target-device iphone --target-device ipad --minimum-deployment-target $(IOS_MIN) --compile $@ $^ 2>&1 | cat -
@ -526,7 +526,7 @@ endif
$(BIN)/SameBoy.qlgenerator/Contents/Resources/cgb_boot_fast.bin: $(BIN)/BootROMs/cgb_boot_fast.bin
-@$(MKDIR) -p $(dir $@)
cp -f $^ $@
# SDL Port
# Unix versions build only one binary
@ -611,7 +611,7 @@ $(BIN)/SDL/background.bmp: SDL/background.bmp
$(BIN)/SDL/Shaders: Shaders
-@$(MKDIR) -p $@
cp -rf Shaders/*.fsh $@
$(BIN)/SDL/Palettes: Misc/Palettes
-@$(MKDIR) -p $@
cp -rf Misc/Palettes/*.sbp $@
@ -620,12 +620,12 @@ $(BIN)/SDL/Palettes: Misc/Palettes
$(OBJ)/%.2bpp: %.png
-@$(MKDIR) -p $(dir $@)
$(RGBGFX) $(if $(filter $(shell echo 'print __RGBDS_MAJOR__ || (!__RGBDS_MAJOR__ && __RGBDS_MINOR__ > 5)' | $(RGBASM) -), $$0), -h -u, -Z -u -c embedded) -o $@ $<
$(RGBGFX) $(if $(filter $(shell echo 'println __RGBDS_MAJOR__ || (!__RGBDS_MAJOR__ && __RGBDS_MINOR__ > 5)' | $(RGBASM) -), $$0), -h -u, -Z -u -c embedded) -o $@ $<
$(OBJ)/BootROMs/SameBoyLogo.pb12: $(OBJ)/BootROMs/SameBoyLogo.2bpp $(PB12_COMPRESS)
-@$(MKDIR) -p $(dir $@)
"$(realpath $(PB12_COMPRESS))" < $< > $@
$(PB12_COMPRESS): BootROMs/pb12.c
-@$(MKDIR) -p $(dir $@)
$(NATIVE_CC) -std=c99 -Wall -Werror $< -o $@
@ -633,11 +633,11 @@ $(PB12_COMPRESS): BootROMs/pb12.c
$(BIN)/BootROMs/cgb0_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/sgb2_boot: BootROMs/sgb_boot.asm
$(BIN)/BootROMs/sgb2_boot.bin: BootROMs/sgb_boot.asm
$(BIN)/BootROMs/%.bin: BootROMs/%.asm $(OBJ)/BootROMs/SameBoyLogo.pb12
-@$(MKDIR) -p $(dir $@)
$(RGBASM) -i $(OBJ)/BootROMs/ -i BootROMs/ -o $@.tmp $<
$(RGBASM) $(if $(filter $(shell echo 'println __RGBDS_MAJOR__ || (!__RGBDS_MAJOR__ && __RGBDS_MINOR__ > 6)' | $(RGBASM) -), $$0), -h,) --include $(OBJ)/BootROMs/ --include BootROMs/ -o $@.tmp $<
$(RGBLINK) -x -o $@ $@.tmp
@rm $@.tmp
@ -690,7 +690,7 @@ endif
ios:
@$(MAKE) _ios
$(BIN)/SameBoy-iOS.ipa: ios iOS/sideload.entitlements
$(MKDIR) -p $(OBJ)/Payload
cp -rf $(BIN)/SameBoy-iOS.app $(OBJ)/Payload/SameBoy-iOS.app
@ -698,11 +698,11 @@ $(BIN)/SameBoy-iOS.ipa: ios iOS/sideload.entitlements
(cd $(OBJ) && zip -q $(abspath $@) -r Payload)
rm -rf $(OBJ)/Payload
$(BIN)/SameBoy-iOS.deb: $(OBJ)/debian-binary $(OBJ)/control.tar.gz $(OBJ)/data.tar.gz
-@$(MKDIR) -p $(dir $@)
(cd $(OBJ) && ar cr $(abspath $@) $(notdir $^))
$(OBJ)/data.tar.gz: ios iOS/jailbreak.entitlements iOS/installer.entitlements
$(MKDIR) -p $(OBJ)/private/var/containers/
cp -rf $(BIN)/SameBoy-iOS.app $(OBJ)/private/var/containers/SameBoy-iOS.app
@ -711,7 +711,7 @@ $(OBJ)/data.tar.gz: ios iOS/jailbreak.entitlements iOS/installer.entitlements
codesign -fs - --entitlements iOS/jailbreak.entitlements $(OBJ)/private/var/containers/SameBoy-iOS.app
(cd $(OBJ) && tar -czf $(abspath $@) --format ustar --uid 501 --gid 501 --numeric-owner ./private)
rm -rf $(OBJ)/private/
$(OBJ)/control.tar.gz: iOS/deb-postinst iOS/deb-prerm iOS/deb-control
-@$(MKDIR) -p $(dir $@)
sed "s/@VERSION/$(VERSION)/" < iOS/deb-control > $(OBJ)/control
@ -719,11 +719,11 @@ $(OBJ)/control.tar.gz: iOS/deb-postinst iOS/deb-prerm iOS/deb-control
ln iOS/deb-prerm $(OBJ)/prerm
(cd $(OBJ) && tar -czf $(abspath $@) --format ustar --uid 501 --gid 501 --numeric-owner ./control ./postinst ./prerm)
rm $(OBJ)/control $(OBJ)/postinst $(OBJ)/prerm
$(OBJ)/debian-binary:
-@$(MKDIR) -p $(dir $@)
echo 2.0 > $@
$(LIBDIR)/libsameboy.o: $(CORE_OBJECTS)
-@$(MKDIR) -p $(dir $@)
@# This is a somewhat simple hack to force Clang and GCC to build a native object file out of one or many LTO objects
@ -731,12 +731,12 @@ $(LIBDIR)/libsameboy.o: $(CORE_OBJECTS)
@# And this is a somewhat complicated hack to invoke the correct LTO-enabled LD command in a mostly cross-platform nature
$(CC) $(FAT_FLAGS) $(CFLAGS) $(LIBFLAGS) $^ $(OBJ)/lto_hack.o -o $@
-@rm $(OBJ)/lto_hack.o
$(LIBDIR)/libsameboy.a: $(LIBDIR)/libsameboy.o
-@$(MKDIR) -p $(dir $@)
-@rm -f $@
ar -crs $@ $^
$(INC)/%.h: Core/%.h
-@$(MKDIR) -p $(dir $@)
-@# CPPP doesn't like multibyte characters, so we replace the single quote character before processing so it doesn't complain
@ -745,7 +745,7 @@ $(INC)/%.h: Core/%.h
lib-unsupported:
@echo Due to limitations of lld-link, compiling SameBoy as a library on Windows is not supported.
@false
# Clean
clean:
rm -rf build