Permalink
Browse files

GB: Skip BIOS option now works

  • Loading branch information...
endrift committed Jan 8, 2018
1 parent 2050622 commit caea7e070015060014409ce804e1851f4983f800
Showing with 103 additions and 78 deletions.
  1. +1 −0 CHANGES
  2. +2 −0 include/mgba/internal/gb/gb.h
  3. +4 −0 src/gb/core.c
  4. +95 −74 src/gb/gb.c
  5. +1 −4 src/gb/io.c
View
@@ -50,6 +50,7 @@ Misc:
- GBA: Improve multiboot image detection
- GB MBC: Remove erroneous bank 0 wrapping
- GBA Cheats: Allow multiple ROM patches in the same slot
+ - GB: Skip BIOS option now works
0.6.1: (2017-10-01)
Bugfixes:
@@ -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);
View
@@ -451,6 +451,10 @@ static void _GBCoreReset(struct mCore* core) {
#endif
LR35902Reset(core->cpu);
+
+ if (core->opts.skipBios) {
+ GBSkipBIOS(core->board);
+ }
}
static void _GBCoreRunFrame(struct mCore* core) {
View
@@ -435,84 +435,11 @@ void GBReset(struct LR35902Core* cpu) {
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;
gb->yankedRomSize = 0;
@@ -527,15 +454,109 @@ void GBReset(struct LR35902Core* cpu) {
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) {
if (gb->model != GB_MODEL_AUTODETECT) {
return;
View
@@ -420,10 +420,7 @@ void GBIOWrite(struct GB* gb, unsigned address, uint8_t 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);

0 comments on commit caea7e0

Please sign in to comment.