Implement HALT
Jeffrey Pfau jeffrey@endrift.com
Tue, 16 Apr 2013 23:14:16 -0700
4 files changed,
16 insertions(+),
24 deletions(-)
M
src/gba/gba-bios.c
→
src/gba/gba-bios.c
@@ -49,6 +49,9 @@
void GBASwi16(struct ARMBoard* board, int immediate) { struct GBA* gba = ((struct GBABoard*) board)->p; switch (immediate) { + case 0x2: + GBAHalt(gba); + break; case 0xB: _CpuSet(gba); break;
M
src/gba/gba-io.c
→
src/gba/gba-io.c
@@ -41,6 +41,14 @@ break;
case REG_IME: GBAWriteIME(gba, value); break; + case REG_HALTCNT: + value &= 0x80; + if (!value) { + GBAHalt(gba); + } else { + GBALog(GBA_LOG_STUB, "Stop unimplemented"); + } + return; default: GBALog(GBA_LOG_STUB, "Stub I/O register write: %03x", address); break;
M
src/gba/gba.c
→
src/gba/gba.c
@@ -130,12 +130,6 @@ ARMRaiseIRQ(&gba->cpu);
} } -void GBAPollNextEvent(struct GBA* gba) { - int32_t nextEvent = gba->video.nextEvent; - - gba->cpu.nextEvent = nextEvent; -} - int GBATestIRQ(struct GBA* gba) { if (gba->memory.io[REG_IME >> 1] && gba->memory.io[REG_IE >> 1] & gba->memory.io[REG_IF >> 1]) { gba->springIRQ = 1;@@ -146,24 +140,7 @@ return 0;
} int GBAWaitForIRQ(struct GBA* gba) { - int irqPending = GBATestIRQ(gba) || gba->video.hblankIRQ || gba->video.vblankIRQ || gba->video.vcounterIRQ; - /*if (this.timersEnabled) { - timer = this.timers[0]; - irqPending = irqPending || timer.doIrq; - timer = this.timers[1]; - irqPending = irqPending || timer.doIrq; - timer = this.timers[2]; - irqPending = irqPending || timer.doIrq; - timer = this.timers[3]; - irqPending = irqPending || timer.doIrq; - }*/ - if (!irqPending) { - return 0; - } - while (1) { - GBAPollNextEvent(gba); - if (gba->cpu.nextEvent == INT_MAX) { return 0; } else {@@ -174,6 +151,10 @@ return 1;
} } } +} + +int GBAHalt(struct GBA* gba) { + return GBAWaitForIRQ(gba); } void GBALog(int level, const char* format, ...) {
M
src/gba/gba.h
→
src/gba/gba.h
@@ -64,9 +64,9 @@
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 GBAPollNextEvent(struct GBA* gba); int GBATestIRQ(struct GBA* gba); int GBAWaitForIRQ(struct GBA* gba); +int GBAHalt(struct GBA* gba); void GBAAttachDebugger(struct GBA* gba, struct ARMDebugger* debugger);