GB: Delay EI
Jeffrey Pfau jeffrey@endrift.com
Tue, 26 Jan 2016 20:56:39 -0800
2 files changed,
19 insertions(+),
2 deletions(-)
M
src/gb/gb.c
→
src/gb/gb.c
@@ -52,6 +52,8 @@
gb->pristineRom = 0; gb->pristineRomSize = 0; gb->yankedRomSize = 0; + + gb->eiPending = false; } bool GBLoadROM(struct GB* gb, struct VFile* vf, struct VFile* sav, const char* fname) {@@ -198,6 +200,12 @@ int32_t cycles = cpu->nextEvent;
int32_t nextEvent = INT_MAX; int32_t testEvent; + if (gb->eiPending) { + gb->memory.ime = true; + GBUpdateIRQs(gb); + gb->eiPending = false; + } + testEvent = GBVideoProcessEvents(&gb->video, cycles); if (testEvent < nextEvent) { nextEvent = testEvent;@@ -224,8 +232,15 @@ }
void GBSetInterrupts(struct LR35902Core* cpu, bool enable) { struct GB* gb = (struct GB*) cpu->master; - gb->memory.ime = enable; - GBUpdateIRQs(gb); + if (!enable) { + gb->memory.ime = enable; + GBUpdateIRQs(gb); + } else { + if (cpu->nextEvent > 4) { + cpu->nextEvent = 4; + } + gb->eiPending = true; + } } void GBHalt(struct LR35902Core* cpu) {
M
src/gb/gb.h
→
src/gb/gb.h
@@ -57,6 +57,8 @@ struct VFile* romVf;
struct VFile* sramVf; const char* activeFile; + + bool eiPending; }; struct GBCartridge {