CGB-0 support

This commit is contained in:
Lior Halphon 2021-11-04 00:32:15 +02:00
parent 6cd13be624
commit f237b1e9b9
13 changed files with 41 additions and 28 deletions

2
BootROMs/cgb0_boot.asm Normal file
View File

@ -0,0 +1,2 @@
CGB0 EQU 1
include "cgb_boot.asm"

View File

@ -23,6 +23,7 @@ Start:
dec c dec c
jr nz, .clearOAMLoop jr nz, .clearOAMLoop
IF !DEF(CGB0)
; Init waveform ; Init waveform
ld c, $10 ld c, $10
ld hl, $FF30 ld hl, $FF30
@ -31,6 +32,7 @@ Start:
cpl cpl
dec c dec c
jr nz, .waveformLoop jr nz, .waveformLoop
ENDC
; Clear chosen input palette ; Clear chosen input palette
ldh [InputPalette], a ldh [InputPalette], a

View File

@ -576,12 +576,12 @@ static unsigned *multiplication_table_for_frequency(unsigned frequency)
- (void) loadBootROM: (GB_boot_rom_t)type - (void) loadBootROM: (GB_boot_rom_t)type
{ {
static NSString *const names[] = { static NSString *const names[] = {
[GB_BOOT_ROM_DMG0] = @"dmg0_boot", [GB_BOOT_ROM_DMG_0] = @"dmg0_boot",
[GB_BOOT_ROM_DMG] = @"dmg_boot", [GB_BOOT_ROM_DMG] = @"dmg_boot",
[GB_BOOT_ROM_MGB] = @"mgb_boot", [GB_BOOT_ROM_MGB] = @"mgb_boot",
[GB_BOOT_ROM_SGB] = @"sgb_boot", [GB_BOOT_ROM_SGB] = @"sgb_boot",
[GB_BOOT_ROM_SGB2] = @"sgb2_boot", [GB_BOOT_ROM_SGB2] = @"sgb2_boot",
[GB_BOOT_ROM_CGB0] = @"cgb0_boot", [GB_BOOT_ROM_CGB_0] = @"cgb0_boot",
[GB_BOOT_ROM_CGB] = @"cgb_boot", [GB_BOOT_ROM_CGB] = @"cgb_boot",
[GB_BOOT_ROM_AGB] = @"agb_boot", [GB_BOOT_ROM_AGB] = @"agb_boot",
}; };

View File

@ -397,7 +397,7 @@
<font key="font" metaFont="menu"/> <font key="font" metaFont="menu"/>
<menu key="menu" autoenablesItems="NO" id="bbF-hB-Hv7"> <menu key="menu" autoenablesItems="NO" id="bbF-hB-Hv7">
<items> <items>
<menuItem title="CPU-CGB 0" tag="512" enabled="NO" id="2Uk-u3-6Gw"/> <menuItem title="CPU-CGB 0 (Experimental)" tag="512" id="2Uk-u3-6Gw"/>
<menuItem title="CPU-CGB A" tag="513" enabled="NO" id="axv-yk-RWM"/> <menuItem title="CPU-CGB A" tag="513" enabled="NO" id="axv-yk-RWM"/>
<menuItem title="CPU-CGB B (Experimental)" tag="514" id="NtJ-oo-IM2"/> <menuItem title="CPU-CGB B (Experimental)" tag="514" id="NtJ-oo-IM2"/>
<menuItem title="CPU-CGB C (Experimental)" tag="515" id="9YL-u8-12z"/> <menuItem title="CPU-CGB C (Experimental)" tag="515" id="9YL-u8-12z"/>

View File

@ -868,7 +868,7 @@ static inline uint16_t effective_channel4_counter(GB_gameboy_t *gb)
case GB_MODEL_SGB_PAL_NO_SFC: case GB_MODEL_SGB_PAL_NO_SFC:
case GB_MODEL_SGB2: case GB_MODEL_SGB2:
case GB_MODEL_SGB2_NO_SFC: case GB_MODEL_SGB2_NO_SFC:
// case GB_MODEL_CGB_0: case GB_MODEL_CGB_0:
// case GB_MODEL_CGB_A: // case GB_MODEL_CGB_A:
case GB_MODEL_CGB_C: case GB_MODEL_CGB_C:
if (effective_counter & 8) { if (effective_counter & 8) {

View File

@ -164,6 +164,9 @@ static void display_vblank(GB_gameboy_t *gb)
0x1050, 0x3C84, 0x0E07, 0x0E18, 0x2964, 0x1050, 0x3C84, 0x0E07, 0x0E18, 0x2964,
}; };
unsigned index = gb->rom? gb->rom[0x14e] % 5 : 0; unsigned index = gb->rom? gb->rom[0x14e] % 5 : 0;
if (gb->model == GB_MODEL_CGB_0) {
index = 1; // CGB 0 was only available in Indigo!
}
gb->borrowed_border.palette[0] = LE16(colors[index]); gb->borrowed_border.palette[0] = LE16(colors[index]);
gb->borrowed_border.palette[10] = LE16(colors[5 + index]); gb->borrowed_border.palette[10] = LE16(colors[5 + index]);
gb->borrowed_border.palette[14] = LE16(colors[10 + index]); gb->borrowed_border.palette[14] = LE16(colors[10 + index]);

View File

@ -1462,7 +1462,8 @@ static void reset_ram(GB_gameboy_t *gb)
gb->ram[i] ^= GB_random() & GB_random() & GB_random(); gb->ram[i] ^= GB_random() & GB_random() & GB_random();
} }
break; break;
case GB_MODEL_CGB_0:
case GB_MODEL_CGB_B: case GB_MODEL_CGB_B:
case GB_MODEL_CGB_C: case GB_MODEL_CGB_C:
for (unsigned i = 0; i < gb->ram_size; i++) { for (unsigned i = 0; i < gb->ram_size; i++) {
@ -1489,6 +1490,7 @@ static void reset_ram(GB_gameboy_t *gb)
/* HRAM */ /* HRAM */
switch (gb->model) { switch (gb->model) {
case GB_MODEL_CGB_0:
case GB_MODEL_CGB_B: case GB_MODEL_CGB_B:
case GB_MODEL_CGB_C: case GB_MODEL_CGB_C:
case GB_MODEL_CGB_D: case GB_MODEL_CGB_D:
@ -1520,6 +1522,7 @@ static void reset_ram(GB_gameboy_t *gb)
/* OAM */ /* OAM */
switch (gb->model) { switch (gb->model) {
case GB_MODEL_CGB_0:
case GB_MODEL_CGB_B: case GB_MODEL_CGB_B:
case GB_MODEL_CGB_C: case GB_MODEL_CGB_C:
case GB_MODEL_CGB_D: case GB_MODEL_CGB_D:
@ -1552,12 +1555,13 @@ static void reset_ram(GB_gameboy_t *gb)
/* Wave RAM */ /* Wave RAM */
switch (gb->model) { switch (gb->model) {
case GB_MODEL_CGB_0:
case GB_MODEL_CGB_B: case GB_MODEL_CGB_B:
case GB_MODEL_CGB_C: case GB_MODEL_CGB_C:
case GB_MODEL_CGB_D: case GB_MODEL_CGB_D:
case GB_MODEL_CGB_E: case GB_MODEL_CGB_E:
case GB_MODEL_AGB: case GB_MODEL_AGB:
/* Initialized by CGB-A and newer, 0s in CGB-0*/ /* Initialized by CGB-A and newer, 0s in CGB-0 */
break; break;
case GB_MODEL_MGB: { case GB_MODEL_MGB: {
for (unsigned i = 0; i < GB_IO_WAV_END - GB_IO_WAV_START; i++) { for (unsigned i = 0; i < GB_IO_WAV_END - GB_IO_WAV_START; i++) {
@ -1626,6 +1630,9 @@ static void request_boot_rom(GB_gameboy_t *gb)
case GB_MODEL_SGB2_NO_SFC: case GB_MODEL_SGB2_NO_SFC:
type = GB_BOOT_ROM_SGB2; type = GB_BOOT_ROM_SGB2;
break; break;
case GB_MODEL_CGB_0:
type = GB_BOOT_ROM_CGB_0;
break;
case GB_MODEL_CGB_B: case GB_MODEL_CGB_B:
case GB_MODEL_CGB_C: case GB_MODEL_CGB_C:
case GB_MODEL_CGB_D: case GB_MODEL_CGB_D:

View File

@ -131,7 +131,7 @@ typedef enum {
GB_MODEL_MGB = 0x100, GB_MODEL_MGB = 0x100,
GB_MODEL_SGB2 = 0x101, GB_MODEL_SGB2 = 0x101,
GB_MODEL_SGB2_NO_SFC = GB_MODEL_SGB2 | GB_MODEL_NO_SFC_BIT, GB_MODEL_SGB2_NO_SFC = GB_MODEL_SGB2 | GB_MODEL_NO_SFC_BIT,
// GB_MODEL_CGB_0 = 0x200, GB_MODEL_CGB_0 = 0x200,
// GB_MODEL_CGB_A = 0x201, // GB_MODEL_CGB_A = 0x201,
GB_MODEL_CGB_B = 0x202, GB_MODEL_CGB_B = 0x202,
GB_MODEL_CGB_C = 0x203, GB_MODEL_CGB_C = 0x203,
@ -277,12 +277,12 @@ typedef enum {
} GB_log_attributes; } GB_log_attributes;
typedef enum { typedef enum {
GB_BOOT_ROM_DMG0, GB_BOOT_ROM_DMG_0,
GB_BOOT_ROM_DMG, GB_BOOT_ROM_DMG,
GB_BOOT_ROM_MGB, GB_BOOT_ROM_MGB,
GB_BOOT_ROM_SGB, GB_BOOT_ROM_SGB,
GB_BOOT_ROM_SGB2, GB_BOOT_ROM_SGB2,
GB_BOOT_ROM_CGB0, GB_BOOT_ROM_CGB_0,
GB_BOOT_ROM_CGB, GB_BOOT_ROM_CGB,
GB_BOOT_ROM_AGB, GB_BOOT_ROM_AGB,
} GB_boot_rom_t; } GB_boot_rom_t;

View File

@ -504,10 +504,8 @@ static uint8_t read_high_memory(GB_gameboy_t *gb, uint16_t addr)
case GB_MODEL_CGB_C: case GB_MODEL_CGB_C:
case GB_MODEL_CGB_B: case GB_MODEL_CGB_B:
/* // case GB_MODEL_CGB_A:
case GB_MODEL_CGB_A:
case GB_MODEL_CGB_0: case GB_MODEL_CGB_0:
*/
addr &= ~0x18; addr &= ~0x18;
return gb->extra_oam[addr - 0xfea0]; return gb->extra_oam[addr - 0xfea0];
@ -1010,10 +1008,8 @@ static void write_high_memory(GB_gameboy_t *gb, uint16_t addr, uint8_t value)
break; break;
case GB_MODEL_CGB_C: case GB_MODEL_CGB_C:
case GB_MODEL_CGB_B: case GB_MODEL_CGB_B:
/* // case GB_MODEL_CGB_A:
case GB_MODEL_CGB_A: case GB_MODEL_CGB_0:
case GB_MODEL_CGB_0:
*/
addr &= ~0x18; addr &= ~0x18;
gb->extra_oam[addr - 0xfea0] = value; gb->extra_oam[addr - 0xfea0] = value;
break; break;

View File

@ -347,6 +347,7 @@ static bool verify_and_update_state_compatibility(GB_gameboy_t *gb, GB_gameboy_t
case GB_MODEL_MGB: return true; case GB_MODEL_MGB: return true;
case GB_MODEL_SGB2: return true; case GB_MODEL_SGB2: return true;
case GB_MODEL_SGB2_NO_SFC: return true; case GB_MODEL_SGB2_NO_SFC: return true;
case GB_MODEL_CGB_0: return true;
case GB_MODEL_CGB_B: return true; case GB_MODEL_CGB_B: return true;
case GB_MODEL_CGB_C: return true; case GB_MODEL_CGB_C: return true;
case GB_MODEL_CGB_D: return true; case GB_MODEL_CGB_D: return true;
@ -648,6 +649,7 @@ static int save_state_internal(GB_gameboy_t *gb, virtual_file_t *file, bool appe
case GB_MODEL_SGB2: case GB_MODEL_SGB2:
bess_core.full_model = BE32('S2 '); break; bess_core.full_model = BE32('S2 '); break;
case GB_MODEL_CGB_0: bess_core.full_model = BE32('CC0 '); break;
case GB_MODEL_CGB_B: bess_core.full_model = BE32('CCB '); break; case GB_MODEL_CGB_B: bess_core.full_model = BE32('CCB '); break;
case GB_MODEL_CGB_C: bess_core.full_model = BE32('CCC '); break; case GB_MODEL_CGB_C: bess_core.full_model = BE32('CCC '); break;
case GB_MODEL_CGB_D: bess_core.full_model = BE32('CCD '); break; case GB_MODEL_CGB_D: bess_core.full_model = BE32('CCD '); break;

View File

@ -199,9 +199,9 @@ endif
cocoa: $(BIN)/SameBoy.app cocoa: $(BIN)/SameBoy.app
quicklook: $(BIN)/SameBoy.qlgenerator quicklook: $(BIN)/SameBoy.qlgenerator
sdl: $(SDL_TARGET) $(BIN)/SDL/dmg_boot.bin $(BIN)/SDL/mgb_boot.bin $(BIN)/SDL/cgb_boot.bin $(BIN)/SDL/agb_boot.bin $(BIN)/SDL/sgb_boot.bin $(BIN)/SDL/sgb2_boot.bin $(BIN)/SDL/LICENSE $(BIN)/SDL/registers.sym $(BIN)/SDL/background.bmp $(BIN)/SDL/Shaders sdl: $(SDL_TARGET) $(BIN)/SDL/dmg_boot.bin $(BIN)/SDL/cgb0_boot.bin $(BIN)/SDL/cgb_boot.bin $(BIN)/SDL/agb_boot.bin $(BIN)/SDL/sgb_boot.bin $(BIN)/SDL/sgb2_boot.bin $(BIN)/SDL/LICENSE $(BIN)/SDL/registers.sym $(BIN)/SDL/background.bmp $(BIN)/SDL/Shaders
bootroms: $(BIN)/BootROMs/agb_boot.bin $(BIN)/BootROMs/mgb_boot.bin $(BIN)/BootROMs/cgb_boot.bin $(BIN)/BootROMs/dmg_boot.bin $(BIN)/BootROMs/sgb_boot.bin $(BIN)/BootROMs/sgb2_boot.bin bootroms: $(BIN)/BootROMs/agb_boot.bin $(BIN)/BootROMs/cgb_boot.bin $(BIN)/BootROMs/cgb0_boot.bin $(BIN)/BootROMs/dmg_boot.bin $(BIN)/BootROMs/sgb_boot.bin $(BIN)/BootROMs/sgb2_boot.bin
tester: $(TESTER_TARGET) $(BIN)/tester/dmg_boot.bin $(BIN)/tester/mgb_boot.bin $(BIN)/tester/cgb_boot.bin $(BIN)/tester/agb_boot.bin $(BIN)/tester/sgb_boot.bin $(BIN)/tester/sgb2_boot.bin tester: $(TESTER_TARGET) $(BIN)/tester/dmg_boot.bin $(BIN)/tester/cgb_boot.bin $(BIN)/tester/agb_boot.bin $(BIN)/tester/sgb_boot.bin $(BIN)/tester/sgb2_boot.bin
all: cocoa sdl tester libretro all: cocoa sdl tester libretro
# Get a list of our source files and their respective object file targets # Get a list of our source files and their respective object file targets
@ -280,6 +280,7 @@ $(BIN)/SameBoy.app: $(BIN)/SameBoy.app/Contents/MacOS/SameBoy \
Misc/registers.sym \ Misc/registers.sym \
$(BIN)/SameBoy.app/Contents/Resources/dmg_boot.bin \ $(BIN)/SameBoy.app/Contents/Resources/dmg_boot.bin \
$(BIN)/SameBoy.app/Contents/Resources/mgb_boot.bin \ $(BIN)/SameBoy.app/Contents/Resources/mgb_boot.bin \
$(BIN)/SameBoy.app/Contents/Resources/cgb0_boot.bin \
$(BIN)/SameBoy.app/Contents/Resources/cgb_boot.bin \ $(BIN)/SameBoy.app/Contents/Resources/cgb_boot.bin \
$(BIN)/SameBoy.app/Contents/Resources/agb_boot.bin \ $(BIN)/SameBoy.app/Contents/Resources/agb_boot.bin \
$(BIN)/SameBoy.app/Contents/Resources/sgb_boot.bin \ $(BIN)/SameBoy.app/Contents/Resources/sgb_boot.bin \
@ -418,7 +419,7 @@ $(OBJ)/BootROMs/SameBoyLogo.pb12: $(OBJ)/BootROMs/SameBoyLogo.2bpp $(PB12_COMPRE
$(PB12_COMPRESS): BootROMs/pb12.c $(PB12_COMPRESS): BootROMs/pb12.c
$(NATIVE_CC) -std=c99 -Wall -Werror $< -o $@ $(NATIVE_CC) -std=c99 -Wall -Werror $< -o $@
$(BIN)/BootROMs/mgb_boot.bin: BootROMs/mgb_boot.asm $(BIN)/BootROMs/cgb0_boot.bin: BootROMs/cgb_boot.asm
$(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

View File

@ -590,12 +590,12 @@ static bool handle_pending_command(void)
static void load_boot_rom(GB_gameboy_t *gb, GB_boot_rom_t type) static void load_boot_rom(GB_gameboy_t *gb, GB_boot_rom_t type)
{ {
static const char *const names[] = { static const char *const names[] = {
[GB_BOOT_ROM_DMG0] = "dmg0_boot.bin", [GB_BOOT_ROM_DMG_0] = "dmg0_boot.bin",
[GB_BOOT_ROM_DMG] = "dmg_boot.bin", [GB_BOOT_ROM_DMG] = "dmg_boot.bin",
[GB_BOOT_ROM_MGB] = "mgb_boot.bin", [GB_BOOT_ROM_MGB] = "mgb_boot.bin",
[GB_BOOT_ROM_SGB] = "sgb_boot.bin", [GB_BOOT_ROM_SGB] = "sgb_boot.bin",
[GB_BOOT_ROM_SGB2] = "sgb2_boot.bin", [GB_BOOT_ROM_SGB2] = "sgb2_boot.bin",
[GB_BOOT_ROM_CGB0] = "cgb0_boot.bin", [GB_BOOT_ROM_CGB_0] = "cgb0_boot.bin",
[GB_BOOT_ROM_CGB] = "cgb_boot.bin", [GB_BOOT_ROM_CGB] = "cgb_boot.bin",
[GB_BOOT_ROM_AGB] = "agb_boot.bin", [GB_BOOT_ROM_AGB] = "agb_boot.bin",
}; };

View File

@ -418,34 +418,34 @@ static void set_link_cable_state(bool state)
static void boot_rom_load(GB_gameboy_t *gb, GB_boot_rom_t type) static void boot_rom_load(GB_gameboy_t *gb, GB_boot_rom_t type)
{ {
const char *model_name = (char *[]) { const char *model_name = (char *[]) {
[GB_BOOT_ROM_DMG0] = "dmg0", [GB_BOOT_ROM_DMG_0] = "dmg0",
[GB_BOOT_ROM_DMG] = "dmg", [GB_BOOT_ROM_DMG] = "dmg",
[GB_BOOT_ROM_MGB] = "mgb", [GB_BOOT_ROM_MGB] = "mgb",
[GB_BOOT_ROM_SGB] = "sgb", [GB_BOOT_ROM_SGB] = "sgb",
[GB_BOOT_ROM_SGB2] = "sgb2", [GB_BOOT_ROM_SGB2] = "sgb2",
[GB_BOOT_ROM_CGB0] = "cgb0", [GB_BOOT_ROM_CGB_0] = "cgb0",
[GB_BOOT_ROM_CGB] = "cgb", [GB_BOOT_ROM_CGB] = "cgb",
[GB_BOOT_ROM_AGB] = "agb", [GB_BOOT_ROM_AGB] = "agb",
}[type]; }[type];
const uint8_t *boot_code = (const unsigned char *[]) { const uint8_t *boot_code = (const unsigned char *[]) {
[GB_BOOT_ROM_DMG0] = dmg_boot, // dmg0 not implemented yet [GB_BOOT_ROM_DMG_0] = dmg_boot, // DMG_0 not implemented yet
[GB_BOOT_ROM_DMG] = dmg_boot, [GB_BOOT_ROM_DMG] = dmg_boot,
[GB_BOOT_ROM_MGB] = dmg_boot, // mgb not implemented yet [GB_BOOT_ROM_MGB] = dmg_boot, // mgb not implemented yet
[GB_BOOT_ROM_SGB] = sgb_boot, [GB_BOOT_ROM_SGB] = sgb_boot,
[GB_BOOT_ROM_SGB2] = sgb2_boot, [GB_BOOT_ROM_SGB2] = sgb2_boot,
[GB_BOOT_ROM_CGB0] = cgb_boot, // cgb0 not implemented yet [GB_BOOT_ROM_CGB_0] = cgb_boot, // CGB_0 not implemented yet
[GB_BOOT_ROM_CGB] = cgb_boot, [GB_BOOT_ROM_CGB] = cgb_boot,
[GB_BOOT_ROM_AGB] = agb_boot, [GB_BOOT_ROM_AGB] = agb_boot,
}[type]; }[type];
unsigned boot_length = (unsigned []) { unsigned boot_length = (unsigned []) {
[GB_BOOT_ROM_DMG0] = dmg_boot_length, // dmg0 not implemented yet [GB_BOOT_ROM_DMG_0] = dmg_boot_length, // DMG_0 not implemented yet
[GB_BOOT_ROM_DMG] = dmg_boot_length, [GB_BOOT_ROM_DMG] = dmg_boot_length,
[GB_BOOT_ROM_MGB] = dmg_boot_length, // mgb not implemented yet [GB_BOOT_ROM_MGB] = dmg_boot_length, // mgb not implemented yet
[GB_BOOT_ROM_SGB] = sgb_boot_length, [GB_BOOT_ROM_SGB] = sgb_boot_length,
[GB_BOOT_ROM_SGB2] = sgb2_boot_length, [GB_BOOT_ROM_SGB2] = sgb2_boot_length,
[GB_BOOT_ROM_CGB0] = cgb_boot_length, // cgb0 not implemented yet [GB_BOOT_ROM_CGB_0] = cgb_boot_length, // CGB_0 not implemented yet
[GB_BOOT_ROM_CGB] = cgb_boot_length, [GB_BOOT_ROM_CGB] = cgb_boot_length,
[GB_BOOT_ROM_AGB] = agb_boot_length, [GB_BOOT_ROM_AGB] = agb_boot_length,
}[type]; }[type];