GB: Improved SGB2 support
@@ -124,6 +124,7 @@ - Wii: Define _GNU_SOURCE (fixes mgba.io/i/1106)
- Wii: Expose stretch configuration in settings - Wii: Stretch now sets pixel-accurate mode size cap - Qt: Ensure camera image is valid + - GB: Improved SGB2 support 0.7 beta 1: (2018-09-24) - Initial beta for 0.7
@@ -150,7 +150,7 @@ audio->playingCh1 = false;
audio->playingCh2 = false; audio->playingCh3 = false; audio->playingCh4 = false; - if (audio->p && audio->p->model != GB_MODEL_SGB) { + if (audio->p && !(audio->p->model & GB_MODEL_SGB)) { audio->playingCh1 = true; audio->enable = true; *audio->nr52 |= 0x01;
@@ -229,7 +229,7 @@ }
static void _GBCoreDesiredVideoDimensions(struct mCore* core, unsigned* width, unsigned* height) { struct GB* gb = core->board; - if (gb && (gb->model != GB_MODEL_SGB || !gb->video.sgbBorders)) { + if (gb && (!(gb->model & GB_MODEL_SGB) || !gb->video.sgbBorders)) { *width = GB_VIDEO_HORIZONTAL_PIXELS; *height = GB_VIDEO_VERTICAL_PIXELS; } else {@@ -373,9 +373,9 @@ if (modelGB || modelCGB || modelSGB) {
GBDetectModel(gb); if (gb->model == GB_MODEL_DMG && modelGB) { gb->model = GBNameToModel(modelGB); - } else if (gb->model == GB_MODEL_CGB && modelCGB) { + } else if ((gb->model & GB_MODEL_CGB) && modelCGB) { gb->model = GBNameToModel(modelCGB); - } else if (gb->model == GB_MODEL_SGB && modelSGB) { + } else if ((gb->model & GB_MODEL_SGB) && modelSGB) { gb->model = GBNameToModel(modelSGB); } }
@@ -30,6 +30,7 @@ #define DMG_BIOS_CHECKSUM 0xC2F5CC97
#define DMG_2_BIOS_CHECKSUM 0x59C8598E #define MGB_BIOS_CHECKSUM 0xE6920754 #define SGB_BIOS_CHECKSUM 0xEC8A83B9 +#define SGB2_BIOS_CHECKSUM 0X53D0DD63 #define CGB_BIOS_CHECKSUM 0x41884E46 mLOG_DEFINE_CATEGORY(GB, "GB", "gb");@@ -400,6 +401,7 @@ case DMG_BIOS_CHECKSUM:
case DMG_2_BIOS_CHECKSUM: case MGB_BIOS_CHECKSUM: case SGB_BIOS_CHECKSUM: + case SGB2_BIOS_CHECKSUM: case CGB_BIOS_CHECKSUM: return true; default:@@ -587,6 +589,9 @@ gb->model = GB_MODEL_MGB;
break; case SGB_BIOS_CHECKSUM: gb->model = GB_MODEL_SGB; + break; + case SGB2_BIOS_CHECKSUM: + gb->model = GB_MODEL_SGB2; break; case CGB_BIOS_CHECKSUM: gb->model = GB_MODEL_CGB;
@@ -199,7 +199,7 @@ GBIOWrite(gb, REG_OBP1, 0xFF);
} GBIOWrite(gb, REG_WY, 0x00); GBIOWrite(gb, REG_WX, 0x00); - if (gb->model >= GB_MODEL_CGB) { + if (gb->model & GB_MODEL_CGB) { GBIOWrite(gb, REG_UNK4C, 0); GBIOWrite(gb, REG_JOYP, 0xFF); GBIOWrite(gb, REG_VBK, 0);@@ -211,7 +211,7 @@ GBIOWrite(gb, REG_HDMA2, 0xFF);
GBIOWrite(gb, REG_HDMA3, 0xFF); GBIOWrite(gb, REG_HDMA4, 0xFF); gb->memory.io[REG_HDMA5] = 0xFF; - } else if (gb->model == GB_MODEL_SGB) { + } else if (gb->model & GB_MODEL_SGB) { GBIOWrite(gb, REG_JOYP, 0xFF); } GBIOWrite(gb, REG_IE, 0x00);@@ -404,7 +404,7 @@ break;
case REG_JOYP: gb->memory.io[REG_JOYP] = value | 0x0F; _readKeys(gb); - if (gb->model == GB_MODEL_SGB) { + if (gb->model & GB_MODEL_SGB) { _writeSGBBits(gb, (value >> 4) & 3); } return;@@ -719,7 +719,7 @@ gb->video.renderer->writeVideoRegister(gb->video.renderer, REG_SCY, state->io[REG_SCY]);
gb->video.renderer->writeVideoRegister(gb->video.renderer, REG_SCX, state->io[REG_SCX]); gb->video.renderer->writeVideoRegister(gb->video.renderer, REG_WY, state->io[REG_WY]); gb->video.renderer->writeVideoRegister(gb->video.renderer, REG_WX, state->io[REG_WX]); - if (gb->model == GB_MODEL_SGB) { + if (gb->model & GB_MODEL_SGB) { gb->video.renderer->writeVideoRegister(gb->video.renderer, REG_BGP, state->io[REG_BGP]); gb->video.renderer->writeVideoRegister(gb->video.renderer, REG_OBP0, state->io[REG_OBP0]); gb->video.renderer->writeVideoRegister(gb->video.renderer, REG_OBP1, state->io[REG_OBP1]);
@@ -196,7 +196,7 @@ softwareRenderer->currentWy = 0;
softwareRenderer->lastY = GB_VIDEO_VERTICAL_PIXELS; softwareRenderer->hasWindow = false; softwareRenderer->wx = 0; - softwareRenderer->model = model; + softwareRenderer->model = model & ~GB_MODEL_MGB; softwareRenderer->sgbTransfer = 0; softwareRenderer->sgbCommandHeader = 0; softwareRenderer->sgbBorders = sgbBorders;
@@ -64,7 +64,7 @@ GBVideoSerialize(&gb->video, state);
GBTimerSerialize(&gb->timer, state); GBAudioSerialize(&gb->audio, state); - if (gb->model == GB_MODEL_SGB) { + if (gb->model & GB_MODEL_SGB) { GBSGBSerialize(gb, state); } }@@ -187,7 +187,7 @@ GBIODeserialize(gb, state);
GBTimerDeserialize(&gb->timer, state); GBAudioDeserialize(&gb->audio, state); - if (gb->model == GB_MODEL_SGB && canSgb) { + if (gb->model & GB_MODEL_SGB && canSgb) { GBSGBDeserialize(gb, state); }
@@ -107,7 +107,7 @@ memset(&video->oam, 0, sizeof(video->oam));
video->renderer->oam = &video->oam; memset(&video->palette, 0, sizeof(video->palette)); - if (video->p->model == GB_MODEL_SGB) { + if (video->p->model & GB_MODEL_SGB) { video->renderer->sgbCharRam = anonymousMemoryMap(SGB_SIZE_CHAR_RAM); video->renderer->sgbMapRam = anonymousMemoryMap(SGB_SIZE_MAP_RAM); video->renderer->sgbPalRam = anonymousMemoryMap(SGB_SIZE_PAL_RAM);@@ -491,7 +491,7 @@ video->renderer->writePalette(video->renderer, 9 * 4 + 2, video->palette[9 * 4 + 2]);
video->renderer->writePalette(video->renderer, 9 * 4 + 3, video->palette[9 * 4 + 3]); break; } - } else if (video->p->model == GB_MODEL_SGB) { + } else if (video->p->model & GB_MODEL_SGB) { video->renderer->writeVideoRegister(video->renderer, address, value); } else { switch (address) {