From a496ddc0723c9b6f78901576578abe096d3afb8f Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sat, 5 Aug 2017 07:57:23 -0700 Subject: [PATCH] GB: Start building up MGB --- include/mgba/internal/gb/audio.h | 1 + src/gb/gb.c | 38 ++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/include/mgba/internal/gb/audio.h b/include/mgba/internal/gb/audio.h index b1e86e299..6165f6f4c 100644 --- a/include/mgba/internal/gb/audio.h +++ b/include/mgba/internal/gb/audio.h @@ -142,6 +142,7 @@ struct GBAudioNoiseChannel { enum GBAudioStyle { GB_AUDIO_DMG, + GB_AUDIO_MGB = GB_AUDIO_DMG, // TODO GB_AUDIO_CGB, GB_AUDIO_AGB, // GB in GBA GB_AUDIO_GBA, // GBA PSG diff --git a/src/gb/gb.c b/src/gb/gb.c index 3ce090655..3a24868ab 100644 --- a/src/gb/gb.c +++ b/src/gb/gb.c @@ -28,6 +28,7 @@ static const uint8_t _knownHeader[4] = { 0xCE, 0xED, 0x66, 0x66}; #define DMG_BIOS_CHECKSUM 0xC2F5CC97 #define DMG_2_BIOS_CHECKSUM 0x59C8598E +#define MGB_BIOS_CHECKSUM 0xE6920754 #define SGB_BIOS_CHECKSUM 0xEC8A83B9 #define CGB_BIOS_CHECKSUM 0x41884E46 @@ -390,6 +391,7 @@ bool GBIsBIOS(struct VFile* vf) { switch (_GBBiosCRC32(vf)) { case DMG_BIOS_CHECKSUM: case DMG_2_BIOS_CHECKSUM: + case MGB_BIOS_CHECKSUM: case SGB_BIOS_CHECKSUM: case CGB_BIOS_CHECKSUM: return true; @@ -434,8 +436,6 @@ void GBReset(struct LR35902Core* cpu) { switch (gb->model) { case GB_MODEL_AUTODETECT: // Silence warnings gb->model = GB_MODEL_DMG; - // TODO: SGB registers - case GB_MODEL_SGB: case GB_MODEL_DMG: cpu->a = 1; cpu->f.packed = 0xB0; @@ -445,6 +445,33 @@ void GBReset(struct LR35902Core* cpu) { cpu->l = 0x4D; gb->timer.internalDiv = 0x2AF3; break; + case GB_MODEL_SGB: + cpu->a = 1; + cpu->f.packed = 0x00; + cpu->c = 0x14; + cpu->e = 0x00; + cpu->h = 0xC0; + cpu->l = 0x60; + gb->timer.internalDiv = 0x2AF3; + break; + case GB_MODEL_MGB: + cpu->a = 0xFF; + cpu->f.packed = 0xB0; + cpu->c = 0x13; + cpu->e = 0xD8; + cpu->h = 1; + cpu->l = 0x4D; + gb->timer.internalDiv = 0x2AF3; + break; + case GB_MODEL_SGB2: + cpu->a = 0xFF; + cpu->f.packed = 0x00; + cpu->c = 0x14; + cpu->e = 0x00; + cpu->h = 0xC0; + cpu->l = 0x60; + gb->timer.internalDiv = 0x2AF3; + break; case GB_MODEL_AGB: cpu->b = 1; // Fall through @@ -502,6 +529,9 @@ void GBDetectModel(struct GB* gb) { case DMG_2_BIOS_CHECKSUM: gb->model = GB_MODEL_DMG; break; + case MGB_BIOS_CHECKSUM: + gb->model = GB_MODEL_MGB; + break; case SGB_BIOS_CHECKSUM: gb->model = GB_MODEL_SGB; break; @@ -530,6 +560,10 @@ void GBDetectModel(struct GB* gb) { case GB_MODEL_AUTODETECT: //Silence warnings gb->audio.style = GB_AUDIO_DMG; break; + case GB_MODEL_MGB: + case GB_MODEL_SGB2: + gb->audio.style = GB_AUDIO_MGB; + break; case GB_MODEL_AGB: case GB_MODEL_CGB: gb->audio.style = GB_AUDIO_CGB;