diff --git a/src/arm/arm.c b/src/arm/arm.c index 559a4aee4..61aabba97 100644 --- a/src/arm/arm.c +++ b/src/arm/arm.c @@ -111,6 +111,25 @@ void ARMReset(struct ARMCore* cpu) { cpu->board->reset(cpu->board); } +void ARMRaiseIRQ(struct ARMCore* cpu) { + if (cpu->cpsr.i) { + return; + } + union PSR cpsr = cpu->cpsr; + int instructionWidth; + if (cpu->executionMode == MODE_THUMB) { + instructionWidth = WORD_SIZE_THUMB; + } else { + instructionWidth = WORD_SIZE_ARM; + } + ARMSetPrivilegeMode(cpu, MODE_IRQ); + cpu->spsr = cpsr; + cpu->gprs[ARM_LR] = cpu->gprs[ARM_PC] - instructionWidth + WORD_SIZE_ARM; + cpu->gprs[ARM_PC] = BASE_IRQ + WORD_SIZE_ARM; + _ARMSetMode(cpu, MODE_ARM); + cpu->cpsr.i = 1; +} + void ARMRun(struct ARMCore* cpu) { if (cpu->executionMode == MODE_THUMB) { ThumbStep(cpu); diff --git a/src/arm/arm.h b/src/arm/arm.h index b8ecafe08..8b607770b 100644 --- a/src/arm/arm.h +++ b/src/arm/arm.h @@ -121,6 +121,7 @@ void ARMAssociateBoard(struct ARMCore* cpu, struct ARMBoard* board); void ARMReset(struct ARMCore* cpu); void ARMSetPrivilegeMode(struct ARMCore*, enum PrivilegeMode); +void ARMRaiseIRQ(struct ARMCore*); void ARMRun(struct ARMCore* cpu); diff --git a/src/gba/gba.c b/src/gba/gba.c index 6751118fb..37a90111a 100644 --- a/src/gba/gba.c +++ b/src/gba/gba.c @@ -109,13 +109,13 @@ void GBAWriteIE(struct GBA* gba, uint16_t value) { } if (gba->memory.io[REG_IME >> 1] && value & gba->memory.io[REG_IF >> 1]) { - //ARMRaiseIRQ(&gba.cpu); + ARMRaiseIRQ(&gba->cpu); } } void GBAWriteIME(struct GBA* gba, uint16_t value) { if (value && gba->memory.io[REG_IE >> 1] & gba->memory.io[REG_IF >> 1]) { - //ARMRaiseIRQ(&gba.cpu); + ARMRaiseIRQ(&gba->cpu); } } @@ -123,7 +123,7 @@ void GBARaiseIRQ(struct GBA* gba, enum GBAIRQ irq) { gba->memory.io[REG_IF >> 1] |= 1 << irq; if (gba->memory.io[REG_IME >> 1] && (gba->memory.io[REG_IE >> 1] & 1 << irq)) { - //ARMRaiseIRQ(); + ARMRaiseIRQ(&gba->cpu); } }