all repos — mgba @ e6eea9462691b8f464fe2bc3f330dacf90d1568c

mGBA Game Boy Advance Emulator

Revert "Move halting code out from below the ARM emulator"

This reverts commit 3b74b61862da06b71d6cb256754f48feec409f7f.
Jeffrey Pfau jeffrey@endrift.com
Thu, 14 Nov 2013 23:16:34 -0800
commit

e6eea9462691b8f464fe2bc3f330dacf90d1568c

parent

0bc5c4a69e8540874025f3de970a72fcb4926c6d

2 files changed, 49 insertions(+), 41 deletions(-)

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

@@ -115,7 +115,6 @@

gba->timersEnabled = 0; memset(gba->timers, 0, sizeof(gba->timers)); - gba->halted = 0; gba->springIRQ = 0; gba->keySource = 0; gba->rotationSource = 0;

@@ -153,47 +152,37 @@ }

static void GBAProcessEvents(struct ARMBoard* board) { struct GBABoard* gbaBoard = (struct GBABoard*) board; - do { - int32_t cycles = board->cpu->cycles; - int32_t nextEvent = INT_MAX; - int32_t testEvent; + int32_t cycles = board->cpu->cycles; + int32_t nextEvent = INT_MAX; + int32_t testEvent; - if (gbaBoard->p->springIRQ) { - ARMRaiseIRQ(&gbaBoard->p->cpu); - gbaBoard->p->springIRQ = 0; - } + if (gbaBoard->p->springIRQ) { + ARMRaiseIRQ(&gbaBoard->p->cpu); + gbaBoard->p->springIRQ = 0; + } - testEvent = GBAVideoProcessEvents(&gbaBoard->p->video, cycles); - if (testEvent < nextEvent) { - nextEvent = testEvent; - } + testEvent = GBAVideoProcessEvents(&gbaBoard->p->video, cycles); + if (testEvent < nextEvent) { + nextEvent = testEvent; + } - testEvent = GBAAudioProcessEvents(&gbaBoard->p->audio, cycles); - if (testEvent < nextEvent) { - nextEvent = testEvent; - } + testEvent = GBAAudioProcessEvents(&gbaBoard->p->audio, cycles); + if (testEvent < nextEvent) { + nextEvent = testEvent; + } - testEvent = GBAMemoryProcessEvents(&gbaBoard->p->memory, cycles); - if (testEvent < nextEvent) { - nextEvent = testEvent; - } + testEvent = GBAMemoryProcessEvents(&gbaBoard->p->memory, cycles); + if (testEvent < nextEvent) { + nextEvent = testEvent; + } - testEvent = GBATimersProcessEvents(gbaBoard->p, cycles); - if (testEvent < nextEvent) { - nextEvent = testEvent; - } - - board->cpu->cycles = 0; - board->cpu->nextEvent = nextEvent; + testEvent = GBATimersProcessEvents(gbaBoard->p, cycles); + if (testEvent < nextEvent) { + nextEvent = testEvent; + } - if (gbaBoard->p->halted) { - gbaBoard->p->halted = !(gbaBoard->p->memory.io[REG_IF >> 1] & gbaBoard->p->memory.io[REG_IE >> 1]); - board->cpu->cycles = nextEvent; - if (nextEvent == INT_MAX) { - break; - } - } - } while (gbaBoard->p->halted); + board->cpu->cycles = 0; + board->cpu->nextEvent = nextEvent; } static int32_t GBATimersProcessEvents(struct GBA* gba, int32_t cycles) {

@@ -467,9 +456,28 @@ gba->cpu.nextEvent = 0;

} } -void GBAHalt(struct GBA* gba) { - gba->cpu.cycles = gba->cpu.nextEvent; - gba->halted = 1; +int GBAWaitForIRQ(struct GBA* gba) { + int irqs = gba->memory.io[REG_IF >> 1]; + int newIRQs = 0; + gba->memory.io[REG_IF >> 1] = 0; + while (1) { + if (gba->cpu.nextEvent == INT_MAX) { + break; + } else { + gba->cpu.cycles = gba->cpu.nextEvent; + GBAProcessEvents(&gba->board.d); + if (gba->memory.io[REG_IF >> 1]) { + newIRQs = gba->memory.io[REG_IF >> 1]; + break; + } + } + } + gba->memory.io[REG_IF >> 1] = newIRQs | irqs; + return newIRQs; +} + +int GBAHalt(struct GBA* gba) { + return GBAWaitForIRQ(gba); } void GBALog(struct GBA* gba, enum GBALogLevel level, const char* format, ...) {
M src/gba/gba.hsrc/gba/gba.h

@@ -85,7 +85,6 @@ unsigned doIrq : 1;

unsigned enable : 1; } timers[4]; - int halted; int springIRQ; int* keySource; struct GBARotationSource* rotationSource;

@@ -128,7 +127,8 @@ void GBAWriteIE(struct GBA* gba, uint16_t value);

void GBAWriteIME(struct GBA* gba, uint16_t value); void GBARaiseIRQ(struct GBA* gba, enum GBAIRQ irq); void GBATestIRQ(struct ARMBoard* board); -void GBAHalt(struct GBA* gba); +int GBAWaitForIRQ(struct GBA* gba); +int GBAHalt(struct GBA* gba); void GBAAttachDebugger(struct GBA* gba, struct ARMDebugger* debugger);