mirror of https://github.com/mgba-emu/mgba.git
Move halting functionality out of GBAHalt
This commit is contained in:
parent
b8ecabbaa9
commit
775e417cc6
|
@ -118,6 +118,7 @@ struct ARMCore {
|
||||||
|
|
||||||
int32_t cycles;
|
int32_t cycles;
|
||||||
int32_t nextEvent;
|
int32_t nextEvent;
|
||||||
|
int halted;
|
||||||
|
|
||||||
int32_t bankedRegisters[6][7];
|
int32_t bankedRegisters[6][7];
|
||||||
int32_t bankedSPSRs[6];
|
int32_t bankedSPSRs[6];
|
||||||
|
|
|
@ -203,6 +203,10 @@ static void GBAProcessEvents(struct ARMBoard* board) {
|
||||||
|
|
||||||
board->cpu->cycles -= cycles;
|
board->cpu->cycles -= cycles;
|
||||||
board->cpu->nextEvent = nextEvent;
|
board->cpu->nextEvent = nextEvent;
|
||||||
|
|
||||||
|
if (board->cpu->halted) {
|
||||||
|
board->cpu->cycles = board->cpu->nextEvent;
|
||||||
|
}
|
||||||
} while (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) {
|
void GBARaiseIRQ(struct GBA* gba, enum GBAIRQ irq) {
|
||||||
gba->memory.io[REG_IF >> 1] |= 1 << 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)) {
|
if (gba->memory.io[REG_IME >> 1] && (gba->memory.io[REG_IE >> 1] & 1 << irq)) {
|
||||||
ARMRaiseIRQ(&gba->cpu);
|
ARMRaiseIRQ(&gba->cpu);
|
||||||
|
@ -486,28 +491,9 @@ void GBATestIRQ(struct ARMBoard* board) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int GBAWaitForIRQ(struct GBA* gba) {
|
void GBAHalt(struct GBA* gba) {
|
||||||
int irqs = gba->memory.io[REG_IF >> 1];
|
gba->cpu.nextEvent = 0;
|
||||||
int newIRQs = 0;
|
gba->cpu.halted = 1;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _GBAVLog(struct GBA* gba, enum GBALogLevel level, const char* format, va_list args) {
|
static void _GBAVLog(struct GBA* gba, enum GBALogLevel level, const char* format, va_list args) {
|
||||||
|
|
|
@ -139,8 +139,7 @@ void GBAWriteIE(struct GBA* gba, uint16_t value);
|
||||||
void GBAWriteIME(struct GBA* gba, uint16_t value);
|
void GBAWriteIME(struct GBA* gba, uint16_t value);
|
||||||
void GBARaiseIRQ(struct GBA* gba, enum GBAIRQ irq);
|
void GBARaiseIRQ(struct GBA* gba, enum GBAIRQ irq);
|
||||||
void GBATestIRQ(struct ARMBoard* board);
|
void GBATestIRQ(struct ARMBoard* board);
|
||||||
int GBAWaitForIRQ(struct GBA* gba);
|
void GBAHalt(struct GBA* gba);
|
||||||
int GBAHalt(struct GBA* gba);
|
|
||||||
|
|
||||||
void GBAAttachDebugger(struct GBA* gba, struct ARMDebugger* debugger);
|
void GBAAttachDebugger(struct GBA* gba, struct ARMDebugger* debugger);
|
||||||
void GBADetachDebugger(struct GBA* gba);
|
void GBADetachDebugger(struct GBA* gba);
|
||||||
|
|
Loading…
Reference in New Issue