all repos — mgba @ 770b80f2b21333ffbae641d4d8d7d598b56d9a7c

mGBA Game Boy Advance Emulator

GB: Actually fix EI this time
Jeffrey Pfau jeffrey@endrift.com
Fri, 05 Feb 2016 02:28:20 -0800
commit

770b80f2b21333ffbae641d4d8d7d598b56d9a7c

parent

3863513b2ae9aaf70c9011720f7e48b3e07bcdbf

2 files changed, 14 insertions(+), 9 deletions(-)

jump to
M src/gb/gb.csrc/gb/gb.c

@@ -57,7 +57,7 @@ gb->pristineRom = 0;

gb->pristineRomSize = 0; gb->yankedRomSize = 0; - gb->diPending = false; + gb->eiPending = false; } bool GBLoadROM(struct GB* gb, struct VFile* vf) {

@@ -210,9 +210,13 @@ int32_t cycles = cpu->nextEvent;

int32_t nextEvent = INT_MAX; int32_t testEvent; - if (gb->diPending) { - gb->memory.ime = false; - gb->diPending = false; + if (gb->eiPending) { + gb->eiPending -= cycles; + if (gb->eiPending <= 0) { + gb->memory.ime = true; + GBUpdateIRQs(gb); + gb->eiPending = 0; + } } testEvent = GBVideoProcessEvents(&gb->video, cycles);

@@ -246,14 +250,15 @@ }

void GBSetInterrupts(struct LR35902Core* cpu, bool enable) { struct GB* gb = (struct GB*) cpu->master; - if (enable) { + if (!enable) { gb->memory.ime = enable; + gb->eiPending = 0; GBUpdateIRQs(gb); } else { - if (cpu->nextEvent > 4) { - cpu->nextEvent = 4; + if (cpu->nextEvent > cpu->cycles + 4) { + cpu->nextEvent = cpu->cycles + 4; } - gb->diPending = true; + gb->eiPending = cpu->cycles + 4; } }
M src/gb/gb.hsrc/gb/gb.h

@@ -61,7 +61,7 @@ uint32_t romCrc32;

struct VFile* romVf; struct VFile* sramVf; - bool diPending; + int32_t eiPending; }; struct GBCartridge {