diff --git a/src/gb/audio.c b/src/gb/audio.c index adaa44ff4..106e64a54 100644 --- a/src/gb/audio.c +++ b/src/gb/audio.c @@ -153,6 +153,10 @@ void GBAudioReset(struct GBAudio* audio) { 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) { diff --git a/src/gb/gb.c b/src/gb/gb.c index 3a24868ab..d4a5c3268 100644 --- a/src/gb/gb.c +++ b/src/gb/gb.c @@ -432,6 +432,8 @@ void GBReset(struct LR35902Core* cpu) { 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 @@ void GBReset(struct LR35902Core* cpu) { 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 @@ void GBReset(struct LR35902Core* cpu) { 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 @@ void GBReset(struct LR35902Core* cpu) { 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 @@ void GBReset(struct LR35902Core* cpu) { 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 @@ void GBReset(struct LR35902Core* cpu) { cpu->e = 0x08; cpu->h = 0; cpu->l = 0x7C; - gb->timer.internalDiv = 0x7A8; + gb->timer.internalDiv = 0x1EA; + nextDiv = 0xC; break; } @@ -510,10 +525,10 @@ void GBReset(struct LR35902Core* cpu) { 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); diff --git a/src/gb/io.c b/src/gb/io.c index d8494a569..74adc850f 100644 --- a/src/gb/io.c +++ b/src/gb/io.c @@ -144,19 +144,19 @@ void GBIOReset(struct GB* gb) { 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 @@ void GBIOReset(struct GB* gb) { 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 @@ void GBIOReset(struct GB* gb) { 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 @@ uint8_t GBIORead(struct GB* gb, unsigned address) { 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; } diff --git a/src/gb/timer.c b/src/gb/timer.c index 0e587410d..061fc8f2e 100644 --- a/src/gb/timer.c +++ b/src/gb/timer.c @@ -64,7 +64,6 @@ void GBTimerReset(struct GBTimer* timer) { timer->nextDiv = GB_DMG_DIV_PERIOD; // TODO: GBC differences timer->timaPeriod = 1024 >> 4; - timer->internalDiv = 0; } void GBTimerDivReset(struct GBTimer* timer) {