GB: Boot register fixes
Vicki Pfau vi@endrift.com
Sat, 05 Aug 2017 16:45:51 -0700
4 files changed,
41 insertions(+),
15 deletions(-)
M
src/gb/audio.c
→
src/gb/audio.c
@@ -153,6 +153,10 @@ audio->playingCh1 = false;
audio->playingCh2 = false; audio->playingCh3 = false; audio->playingCh4 = false; + if (audio->p && (audio->p->model == GB_MODEL_DMG || audio->p->model == GB_MODEL_CGB)) { + audio->playingCh1 = true; + *audio->nr52 |= 0x01; + } } void GBAudioResizeBuffer(struct GBAudio* audio, size_t samples) {
M
src/gb/gb.c
→
src/gb/gb.c
@@ -432,6 +432,8 @@
cpu->b = 0; cpu->d = 0; + gb->timer.internalDiv = 0; + int nextDiv = 0; if (!gb->biosVf) { switch (gb->model) { case GB_MODEL_AUTODETECT: // Silence warnings@@ -443,7 +445,8 @@ cpu->c = 0x13;
cpu->e = 0xD8; cpu->h = 1; cpu->l = 0x4D; - gb->timer.internalDiv = 0x2AF3; + gb->timer.internalDiv = 0xABC; + nextDiv = 4; break; case GB_MODEL_SGB: cpu->a = 1;@@ -452,7 +455,8 @@ cpu->c = 0x14;
cpu->e = 0x00; cpu->h = 0xC0; cpu->l = 0x60; - gb->timer.internalDiv = 0x2AF3; + gb->timer.internalDiv = 0xABC; + nextDiv = 4; break; case GB_MODEL_MGB: cpu->a = 0xFF;@@ -461,7 +465,8 @@ cpu->c = 0x13;
cpu->e = 0xD8; cpu->h = 1; cpu->l = 0x4D; - gb->timer.internalDiv = 0x2AF3; + gb->timer.internalDiv = 0xABC; + nextDiv = 4; break; case GB_MODEL_SGB2: cpu->a = 0xFF;@@ -470,11 +475,20 @@ cpu->c = 0x14;
cpu->e = 0x00; cpu->h = 0xC0; cpu->l = 0x60; - gb->timer.internalDiv = 0x2AF3; + gb->timer.internalDiv = 0xABC; + nextDiv = 4; break; case GB_MODEL_AGB: + cpu->a = 0x11; cpu->b = 1; - // Fall through + cpu->f.packed = 0x00; + cpu->c = 0; + cpu->e = 0x08; + cpu->h = 0; + cpu->l = 0x7C; + gb->timer.internalDiv = 0x1EA; + nextDiv = 0xC; + break; case GB_MODEL_CGB: cpu->a = 0x11; cpu->f.packed = 0x80;@@ -482,7 +496,8 @@ cpu->c = 0;
cpu->e = 0x08; cpu->h = 0; cpu->l = 0x7C; - gb->timer.internalDiv = 0x7A8; + gb->timer.internalDiv = 0x1EA; + nextDiv = 0xC; break; }@@ -510,10 +525,10 @@
GBMemoryReset(gb); GBVideoReset(&gb->video); GBTimerReset(&gb->timer); - mTimingSchedule(&gb->timing, &gb->timer.event, GB_DMG_DIV_PERIOD); + mTimingSchedule(&gb->timing, &gb->timer.event, nextDiv); - GBAudioReset(&gb->audio); GBIOReset(gb); + GBAudioReset(&gb->audio); GBSIOReset(&gb->sio); GBSavedataUnmask(gb);
M
src/gb/io.c
→
src/gb/io.c
@@ -144,19 +144,19 @@ GBIOWrite(gb, REG_TMA, 0);
GBIOWrite(gb, REG_TAC, 0); GBIOWrite(gb, REG_IF, 1); GBIOWrite(gb, REG_NR52, 0xF1); - GBIOWrite(gb, REG_NR14, 0xBF); + GBIOWrite(gb, REG_NR14, 0x3F); GBIOWrite(gb, REG_NR10, 0x80); GBIOWrite(gb, REG_NR11, 0xBF); GBIOWrite(gb, REG_NR12, 0xF3); GBIOWrite(gb, REG_NR13, 0xF3); - GBIOWrite(gb, REG_NR24, 0xBF); + GBIOWrite(gb, REG_NR24, 0x3F); GBIOWrite(gb, REG_NR21, 0x3F); GBIOWrite(gb, REG_NR22, 0x00); - GBIOWrite(gb, REG_NR34, 0xBF); + GBIOWrite(gb, REG_NR34, 0x3F); GBIOWrite(gb, REG_NR30, 0x7F); GBIOWrite(gb, REG_NR31, 0xFF); GBIOWrite(gb, REG_NR32, 0x9F); - GBIOWrite(gb, REG_NR44, 0xBF); + GBIOWrite(gb, REG_NR44, 0x3F); GBIOWrite(gb, REG_NR41, 0xFF); GBIOWrite(gb, REG_NR42, 0x00); GBIOWrite(gb, REG_NR43, 0x00);@@ -167,11 +167,14 @@ GBIOWrite(gb, REG_SCY, 0x00);
GBIOWrite(gb, REG_SCX, 0x00); GBIOWrite(gb, REG_LYC, 0x00); GBIOWrite(gb, REG_BGP, 0xFC); - GBIOWrite(gb, REG_OBP0, 0xFF); - GBIOWrite(gb, REG_OBP1, 0xFF); + if (gb->model < GB_MODEL_CGB) { + GBIOWrite(gb, REG_OBP0, 0xFF); + GBIOWrite(gb, REG_OBP1, 0xFF); + } GBIOWrite(gb, REG_WY, 0x00); GBIOWrite(gb, REG_WX, 0x00); if (gb->model >= GB_MODEL_CGB) { + GBIOWrite(gb, REG_JOYP, 0xFF); GBIOWrite(gb, REG_VBK, 0); GBIOWrite(gb, REG_BCPS, 0); GBIOWrite(gb, REG_OCPS, 0);@@ -181,6 +184,8 @@ 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) { + GBIOWrite(gb, REG_JOYP, 0xFF); } GBIOWrite(gb, REG_IE, 0x00); }@@ -587,6 +592,9 @@ case REG_OCPD:
case REG_SVBK: // Handled transparently by the registers goto success; + case REG_DMA: + mLOG(GB_IO, STUB, "Reading from unknown register FF%02X", address); + return 0; default: break; }
M
src/gb/timer.c
→
src/gb/timer.c
@@ -64,7 +64,6 @@ timer->event.priority = 0x21;
timer->nextDiv = GB_DMG_DIV_PERIOD; // TODO: GBC differences timer->timaPeriod = 1024 >> 4; - timer->internalDiv = 0; } void GBTimerDivReset(struct GBTimer* timer) {