GB: Boot register fixes

This commit is contained in:
Vicki Pfau 2017-08-05 16:45:51 -07:00
parent 558055277f
commit 4a83ae2007
4 changed files with 41 additions and 15 deletions

View File

@ -153,6 +153,10 @@ void GBAudioReset(struct GBAudio* audio) {
audio->playingCh2 = false; audio->playingCh2 = false;
audio->playingCh3 = false; audio->playingCh3 = false;
audio->playingCh4 = 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) { void GBAudioResizeBuffer(struct GBAudio* audio, size_t samples) {

View File

@ -432,6 +432,8 @@ void GBReset(struct LR35902Core* cpu) {
cpu->b = 0; cpu->b = 0;
cpu->d = 0; cpu->d = 0;
gb->timer.internalDiv = 0;
int nextDiv = 0;
if (!gb->biosVf) { if (!gb->biosVf) {
switch (gb->model) { switch (gb->model) {
case GB_MODEL_AUTODETECT: // Silence warnings case GB_MODEL_AUTODETECT: // Silence warnings
@ -443,7 +445,8 @@ void GBReset(struct LR35902Core* cpu) {
cpu->e = 0xD8; cpu->e = 0xD8;
cpu->h = 1; cpu->h = 1;
cpu->l = 0x4D; cpu->l = 0x4D;
gb->timer.internalDiv = 0x2AF3; gb->timer.internalDiv = 0xABC;
nextDiv = 4;
break; break;
case GB_MODEL_SGB: case GB_MODEL_SGB:
cpu->a = 1; cpu->a = 1;
@ -452,7 +455,8 @@ void GBReset(struct LR35902Core* cpu) {
cpu->e = 0x00; cpu->e = 0x00;
cpu->h = 0xC0; cpu->h = 0xC0;
cpu->l = 0x60; cpu->l = 0x60;
gb->timer.internalDiv = 0x2AF3; gb->timer.internalDiv = 0xABC;
nextDiv = 4;
break; break;
case GB_MODEL_MGB: case GB_MODEL_MGB:
cpu->a = 0xFF; cpu->a = 0xFF;
@ -461,7 +465,8 @@ void GBReset(struct LR35902Core* cpu) {
cpu->e = 0xD8; cpu->e = 0xD8;
cpu->h = 1; cpu->h = 1;
cpu->l = 0x4D; cpu->l = 0x4D;
gb->timer.internalDiv = 0x2AF3; gb->timer.internalDiv = 0xABC;
nextDiv = 4;
break; break;
case GB_MODEL_SGB2: case GB_MODEL_SGB2:
cpu->a = 0xFF; cpu->a = 0xFF;
@ -470,11 +475,20 @@ void GBReset(struct LR35902Core* cpu) {
cpu->e = 0x00; cpu->e = 0x00;
cpu->h = 0xC0; cpu->h = 0xC0;
cpu->l = 0x60; cpu->l = 0x60;
gb->timer.internalDiv = 0x2AF3; gb->timer.internalDiv = 0xABC;
nextDiv = 4;
break; break;
case GB_MODEL_AGB: case GB_MODEL_AGB:
cpu->a = 0x11;
cpu->b = 1; 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: case GB_MODEL_CGB:
cpu->a = 0x11; cpu->a = 0x11;
cpu->f.packed = 0x80; cpu->f.packed = 0x80;
@ -482,7 +496,8 @@ void GBReset(struct LR35902Core* cpu) {
cpu->e = 0x08; cpu->e = 0x08;
cpu->h = 0; cpu->h = 0;
cpu->l = 0x7C; cpu->l = 0x7C;
gb->timer.internalDiv = 0x7A8; gb->timer.internalDiv = 0x1EA;
nextDiv = 0xC;
break; break;
} }
@ -510,10 +525,10 @@ void GBReset(struct LR35902Core* cpu) {
GBMemoryReset(gb); GBMemoryReset(gb);
GBVideoReset(&gb->video); GBVideoReset(&gb->video);
GBTimerReset(&gb->timer); 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); GBIOReset(gb);
GBAudioReset(&gb->audio);
GBSIOReset(&gb->sio); GBSIOReset(&gb->sio);
GBSavedataUnmask(gb); GBSavedataUnmask(gb);

View File

@ -144,19 +144,19 @@ void GBIOReset(struct GB* gb) {
GBIOWrite(gb, REG_TAC, 0); GBIOWrite(gb, REG_TAC, 0);
GBIOWrite(gb, REG_IF, 1); GBIOWrite(gb, REG_IF, 1);
GBIOWrite(gb, REG_NR52, 0xF1); GBIOWrite(gb, REG_NR52, 0xF1);
GBIOWrite(gb, REG_NR14, 0xBF); GBIOWrite(gb, REG_NR14, 0x3F);
GBIOWrite(gb, REG_NR10, 0x80); GBIOWrite(gb, REG_NR10, 0x80);
GBIOWrite(gb, REG_NR11, 0xBF); GBIOWrite(gb, REG_NR11, 0xBF);
GBIOWrite(gb, REG_NR12, 0xF3); GBIOWrite(gb, REG_NR12, 0xF3);
GBIOWrite(gb, REG_NR13, 0xF3); GBIOWrite(gb, REG_NR13, 0xF3);
GBIOWrite(gb, REG_NR24, 0xBF); GBIOWrite(gb, REG_NR24, 0x3F);
GBIOWrite(gb, REG_NR21, 0x3F); GBIOWrite(gb, REG_NR21, 0x3F);
GBIOWrite(gb, REG_NR22, 0x00); GBIOWrite(gb, REG_NR22, 0x00);
GBIOWrite(gb, REG_NR34, 0xBF); GBIOWrite(gb, REG_NR34, 0x3F);
GBIOWrite(gb, REG_NR30, 0x7F); GBIOWrite(gb, REG_NR30, 0x7F);
GBIOWrite(gb, REG_NR31, 0xFF); GBIOWrite(gb, REG_NR31, 0xFF);
GBIOWrite(gb, REG_NR32, 0x9F); GBIOWrite(gb, REG_NR32, 0x9F);
GBIOWrite(gb, REG_NR44, 0xBF); GBIOWrite(gb, REG_NR44, 0x3F);
GBIOWrite(gb, REG_NR41, 0xFF); GBIOWrite(gb, REG_NR41, 0xFF);
GBIOWrite(gb, REG_NR42, 0x00); GBIOWrite(gb, REG_NR42, 0x00);
GBIOWrite(gb, REG_NR43, 0x00); GBIOWrite(gb, REG_NR43, 0x00);
@ -167,11 +167,14 @@ void GBIOReset(struct GB* gb) {
GBIOWrite(gb, REG_SCX, 0x00); GBIOWrite(gb, REG_SCX, 0x00);
GBIOWrite(gb, REG_LYC, 0x00); GBIOWrite(gb, REG_LYC, 0x00);
GBIOWrite(gb, REG_BGP, 0xFC); GBIOWrite(gb, REG_BGP, 0xFC);
if (gb->model < GB_MODEL_CGB) {
GBIOWrite(gb, REG_OBP0, 0xFF); GBIOWrite(gb, REG_OBP0, 0xFF);
GBIOWrite(gb, REG_OBP1, 0xFF); GBIOWrite(gb, REG_OBP1, 0xFF);
}
GBIOWrite(gb, REG_WY, 0x00); GBIOWrite(gb, REG_WY, 0x00);
GBIOWrite(gb, REG_WX, 0x00); GBIOWrite(gb, REG_WX, 0x00);
if (gb->model >= GB_MODEL_CGB) { if (gb->model >= GB_MODEL_CGB) {
GBIOWrite(gb, REG_JOYP, 0xFF);
GBIOWrite(gb, REG_VBK, 0); GBIOWrite(gb, REG_VBK, 0);
GBIOWrite(gb, REG_BCPS, 0); GBIOWrite(gb, REG_BCPS, 0);
GBIOWrite(gb, REG_OCPS, 0); GBIOWrite(gb, REG_OCPS, 0);
@ -181,6 +184,8 @@ void GBIOReset(struct GB* gb) {
GBIOWrite(gb, REG_HDMA3, 0xFF); GBIOWrite(gb, REG_HDMA3, 0xFF);
GBIOWrite(gb, REG_HDMA4, 0xFF); GBIOWrite(gb, REG_HDMA4, 0xFF);
gb->memory.io[REG_HDMA5] = 0xFF; gb->memory.io[REG_HDMA5] = 0xFF;
} else if (gb->model == GB_MODEL_SGB) {
GBIOWrite(gb, REG_JOYP, 0xFF);
} }
GBIOWrite(gb, REG_IE, 0x00); GBIOWrite(gb, REG_IE, 0x00);
} }
@ -587,6 +592,9 @@ uint8_t GBIORead(struct GB* gb, unsigned address) {
case REG_SVBK: case REG_SVBK:
// Handled transparently by the registers // Handled transparently by the registers
goto success; goto success;
case REG_DMA:
mLOG(GB_IO, STUB, "Reading from unknown register FF%02X", address);
return 0;
default: default:
break; break;
} }

View File

@ -64,7 +64,6 @@ void GBTimerReset(struct GBTimer* timer) {
timer->nextDiv = GB_DMG_DIV_PERIOD; // TODO: GBC differences timer->nextDiv = GB_DMG_DIV_PERIOD; // TODO: GBC differences
timer->timaPeriod = 1024 >> 4; timer->timaPeriod = 1024 >> 4;
timer->internalDiv = 0;
} }
void GBTimerDivReset(struct GBTimer* timer) { void GBTimerDivReset(struct GBTimer* timer) {