all repos — mgba @ 8c03c20019afb3a1099c9ea90d66d2c9f10aa6ac

mGBA Game Boy Advance Emulator

Implement HALT
Jeffrey Pfau jeffrey@endrift.com
Tue, 16 Apr 2013 23:14:16 -0700
commit

8c03c20019afb3a1099c9ea90d66d2c9f10aa6ac

parent

e88d1775827589a15eb41511802a0b6fb16dec1e

4 files changed, 16 insertions(+), 24 deletions(-)

jump to
M src/gba/gba-bios.csrc/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.csrc/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.csrc/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.hsrc/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);