GB: Actually fix EI this time

This commit is contained in:
Jeffrey Pfau 2016-02-05 02:28:20 -08:00
parent 3863513b2a
commit 770b80f2b2
2 changed files with 14 additions and 9 deletions

View File

@ -57,7 +57,7 @@ static void GBInit(struct LR35902Core* cpu, struct LR35902Component* component)
gb->pristineRomSize = 0; gb->pristineRomSize = 0;
gb->yankedRomSize = 0; gb->yankedRomSize = 0;
gb->diPending = false; gb->eiPending = false;
} }
bool GBLoadROM(struct GB* gb, struct VFile* vf) { bool GBLoadROM(struct GB* gb, struct VFile* vf) {
@ -210,9 +210,13 @@ void GBProcessEvents(struct LR35902Core* cpu) {
int32_t nextEvent = INT_MAX; int32_t nextEvent = INT_MAX;
int32_t testEvent; int32_t testEvent;
if (gb->diPending) { if (gb->eiPending) {
gb->memory.ime = false; gb->eiPending -= cycles;
gb->diPending = false; if (gb->eiPending <= 0) {
gb->memory.ime = true;
GBUpdateIRQs(gb);
gb->eiPending = 0;
}
} }
testEvent = GBVideoProcessEvents(&gb->video, cycles); testEvent = GBVideoProcessEvents(&gb->video, cycles);
@ -246,14 +250,15 @@ void GBProcessEvents(struct LR35902Core* cpu) {
void GBSetInterrupts(struct LR35902Core* cpu, bool enable) { void GBSetInterrupts(struct LR35902Core* cpu, bool enable) {
struct GB* gb = (struct GB*) cpu->master; struct GB* gb = (struct GB*) cpu->master;
if (enable) { if (!enable) {
gb->memory.ime = enable; gb->memory.ime = enable;
gb->eiPending = 0;
GBUpdateIRQs(gb); GBUpdateIRQs(gb);
} else { } else {
if (cpu->nextEvent > 4) { if (cpu->nextEvent > cpu->cycles + 4) {
cpu->nextEvent = 4; cpu->nextEvent = cpu->cycles + 4;
} }
gb->diPending = true; gb->eiPending = cpu->cycles + 4;
} }
} }

View File

@ -61,7 +61,7 @@ struct GB {
struct VFile* romVf; struct VFile* romVf;
struct VFile* sramVf; struct VFile* sramVf;
bool diPending; int32_t eiPending;
}; };
struct GBCartridge { struct GBCartridge {