GB: Skip BIOS option now works
Vicki Pfau vi@endrift.com
Mon, 08 Jan 2018 08:39:26 -0800
5 files changed,
103 insertions(+),
78 deletions(-)
M
include/mgba/internal/gb/gb.h
→
include/mgba/internal/gb/gb.h
@@ -145,6 +145,8 @@ void GBCreate(struct GB* gb);
void GBDestroy(struct GB* gb); void GBReset(struct LR35902Core* cpu); +void GBSkipBIOS(struct GB* gb); +void GBUnmapBIOS(struct GB* gb); void GBDetectModel(struct GB* gb); void GBUpdateIRQs(struct GB* gb);
M
src/gb/core.c
→
src/gb/core.c
@@ -451,6 +451,10 @@ }
#endif LR35902Reset(core->cpu); + + if (core->opts.skipBios) { + GBSkipBIOS(core->board); + } } static void _GBCoreRunFrame(struct mCore* core) {
M
src/gb/gb.c
→
src/gb/gb.c
@@ -435,83 +435,10 @@ 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 - gb->model = GB_MODEL_DMG; - case GB_MODEL_DMG: - cpu->a = 1; - cpu->f.packed = 0xB0; - cpu->c = 0x13; - cpu->e = 0xD8; - cpu->h = 1; - cpu->l = 0x4D; - gb->timer.internalDiv = 0xABC; - nextDiv = 4; - 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 = 0xABC; - nextDiv = 4; - 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 = 0xABC; - nextDiv = 4; - 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 = 0xABC; - nextDiv = 4; - break; - case GB_MODEL_AGB: - cpu->a = 0x11; - cpu->b = 1; - 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; - cpu->c = 0; - cpu->e = 0x08; - cpu->h = 0; - cpu->l = 0x7C; - gb->timer.internalDiv = 0x1EA; - nextDiv = 0xC; - break; - } - - cpu->sp = 0xFFFE; - cpu->pc = 0x100; - } gb->cpuBlocked = false; gb->earlyExit = false; gb->doubleSpeed = 0; - - cpu->memory.setActiveRegion(cpu, cpu->pc); if (gb->yankedRomSize) { gb->memory.romSize = gb->yankedRomSize;@@ -527,13 +454,107 @@
GBMemoryReset(gb); GBVideoReset(&gb->video); GBTimerReset(&gb->timer); - mTimingSchedule(&gb->timing, &gb->timer.event, nextDiv); + if (!gb->biosVf) { + GBSkipBIOS(gb); + } else { + mTimingSchedule(&gb->timing, &gb->timer.event, 0); + } GBIOReset(gb); GBAudioReset(&gb->audio); GBSIOReset(&gb->sio); + cpu->memory.setActiveRegion(cpu, cpu->pc); + GBSavedataUnmask(gb); +} + +void GBSkipBIOS(struct GB* gb) { + struct LR35902Core* cpu = gb->cpu; + int nextDiv = 0; + + switch (gb->model) { + case GB_MODEL_AUTODETECT: // Silence warnings + gb->model = GB_MODEL_DMG; + case GB_MODEL_DMG: + cpu->a = 1; + cpu->f.packed = 0xB0; + cpu->c = 0x13; + cpu->e = 0xD8; + cpu->h = 1; + cpu->l = 0x4D; + gb->timer.internalDiv = 0xABC; + nextDiv = 4; + 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 = 0xABC; + nextDiv = 4; + 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 = 0xABC; + nextDiv = 4; + 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 = 0xABC; + nextDiv = 4; + break; + case GB_MODEL_AGB: + cpu->a = 0x11; + cpu->b = 1; + 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; + cpu->c = 0; + cpu->e = 0x08; + cpu->h = 0; + cpu->l = 0x7C; + gb->timer.internalDiv = 0x1EA; + nextDiv = 0xC; + break; + } + + cpu->sp = 0xFFFE; + cpu->pc = 0x100; + + mTimingDeschedule(&gb->timing, &gb->timer.event); + mTimingSchedule(&gb->timing, &gb->timer.event, 0); + + if (gb->biosVf) { + GBUnmapBIOS(gb); + } +} + +void GBUnmapBIOS(struct GB* gb) { + if (gb->memory.romBase < gb->memory.rom || gb->memory.romBase > &gb->memory.rom[gb->memory.romSize - 1]) { + free(gb->memory.romBase); + gb->memory.romBase = gb->memory.rom; + } } void GBDetectModel(struct GB* gb) {
M
src/gb/io.c
→
src/gb/io.c
@@ -420,10 +420,7 @@ GBVideoWriteSTAT(&gb->video, value);
value = gb->video.stat; break; case 0x50: - if (gb->memory.romBase < gb->memory.rom || gb->memory.romBase > &gb->memory.rom[gb->memory.romSize - 1]) { - free(gb->memory.romBase); - gb->memory.romBase = gb->memory.rom; - } + GBUnmapBIOS(gb); if (gb->model >= GB_MODEL_CGB && gb->memory.io[REG_UNK4C] < 0x80) { gb->model = GB_MODEL_DMG; GBVideoDisableCGB(&gb->video);