all repos — mgba @ bac417d270b5259612bee9434e16de744f5e24a4

mGBA Game Boy Advance Emulator

GB: Delay EI
Jeffrey Pfau jeffrey@endrift.com
Tue, 26 Jan 2016 20:56:39 -0800
commit

bac417d270b5259612bee9434e16de744f5e24a4

parent

81f8ad27d5d30f1c7f560edcb3dd7ed8d700e315

2 files changed, 19 insertions(+), 2 deletions(-)

jump to
M src/gb/gb.csrc/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.hsrc/gb/gb.h

@@ -57,6 +57,8 @@ struct VFile* romVf;

struct VFile* sramVf; const char* activeFile; + + bool eiPending; }; struct GBCartridge {