From 775e417cc6781ceb30520c85c968d198efb87429 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Wed, 16 Apr 2014 23:05:44 -0700 Subject: [PATCH] Move halting functionality out of GBAHalt --- src/arm/arm.h | 1 + src/gba/gba.c | 30 ++++++++---------------------- src/gba/gba.h | 3 +-- 3 files changed, 10 insertions(+), 24 deletions(-) diff --git a/src/arm/arm.h b/src/arm/arm.h index b47c50cdb..f10cb7fee 100644 --- a/src/arm/arm.h +++ b/src/arm/arm.h @@ -118,6 +118,7 @@ struct ARMCore { int32_t cycles; int32_t nextEvent; + int halted; int32_t bankedRegisters[6][7]; int32_t bankedSPSRs[6]; diff --git a/src/gba/gba.c b/src/gba/gba.c index 2f92d26b8..06944fc28 100644 --- a/src/gba/gba.c +++ b/src/gba/gba.c @@ -203,6 +203,10 @@ static void GBAProcessEvents(struct ARMBoard* board) { board->cpu->cycles -= cycles; board->cpu->nextEvent = nextEvent; + + if (board->cpu->halted) { + board->cpu->cycles = board->cpu->nextEvent; + } } while (board->cpu->cycles >= board->cpu->nextEvent); } @@ -471,6 +475,7 @@ void GBAWriteIME(struct GBA* gba, uint16_t value) { void GBARaiseIRQ(struct GBA* gba, enum GBAIRQ irq) { gba->memory.io[REG_IF >> 1] |= 1 << irq; + gba->cpu.halted = 0; if (gba->memory.io[REG_IME >> 1] && (gba->memory.io[REG_IE >> 1] & 1 << irq)) { ARMRaiseIRQ(&gba->cpu); @@ -486,28 +491,9 @@ void GBATestIRQ(struct ARMBoard* board) { } } -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 GBAHalt(struct GBA* gba) { + gba->cpu.nextEvent = 0; + gba->cpu.halted = 1; } static void _GBAVLog(struct GBA* gba, enum GBALogLevel level, const char* format, va_list args) { diff --git a/src/gba/gba.h b/src/gba/gba.h index 3e0e085f2..a7b13d0bf 100644 --- a/src/gba/gba.h +++ b/src/gba/gba.h @@ -139,8 +139,7 @@ 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); -int GBAWaitForIRQ(struct GBA* gba); -int GBAHalt(struct GBA* gba); +void GBAHalt(struct GBA* gba); void GBAAttachDebugger(struct GBA* gba, struct ARMDebugger* debugger); void GBADetachDebugger(struct GBA* gba);