DS: Add halting
Jeffrey Pfau jeffrey@endrift.com
Wed, 04 Jan 2017 00:46:05 -0800
5 files changed,
36 insertions(+),
2 deletions(-)
M
include/mgba/internal/arm/arm.h
→
include/mgba/internal/arm/arm.h
@@ -254,6 +254,7 @@ void ARMSetPrivilegeMode(struct ARMCore*, enum PrivilegeMode);
void ARMRaiseIRQ(struct ARMCore*); void ARMRaiseSWI(struct ARMCore*); void ARMRaiseUndefined(struct ARMCore*); +void ARMHalt(struct ARMCore*); void ARMv4Run(struct ARMCore* cpu); void ARMv4RunLoop(struct ARMCore* cpu);
M
src/arm/arm.c
→
src/arm/arm.c
@@ -223,6 +223,11 @@ cpu->cpsr.i = 1;
cpu->cycles += currentCycles; } +void ARMHalt(struct ARMCore* cpu) { + cpu->nextEvent = cpu->cycles; + cpu->halted = 1; +} + #define ARM_IMPLEMENT(VERSION) \ static inline void ARM ## VERSION ## Step(struct ARMCore* cpu) { \ uint32_t opcode = cpu->prefetch[0]; \
M
src/ds/ds.c
→
src/ds/ds.c
@@ -508,6 +508,14 @@ mLOG(DS, STUB, "CP15 region configuration write: Region: %i, Insn: %i, Base: %08X, Size: %08X", crm, opcode2, base, size);
} static void _writeCache(struct ARMCore* cpu, int crm, int opcode2, uint32_t value) { + switch (crm) { + case 0: + if (opcode2 == 4) { + ARMHalt(cpu); + return; + } + break; + } mLOG(DS, STUB, "CP15 cache write: CRm: %i, Op2: %i, Value: 0x%08X", crm, opcode2, value); }
M
src/ds/io.c
→
src/ds/io.c
@@ -10,6 +10,23 @@ #include <mgba/internal/ds/ipc.h>
mLOG_DEFINE_CATEGORY(DS_IO, "DS I/O"); +static void _DSHaltCNT(struct DSCommon* dscore, uint8_t value) { + switch (value >> 6) { + case 0: + default: + break; + case 1: + mLOG(DS_IO, STUB, "Enter GBA mode not supported"); + break; + case 2: + ARMHalt(dscore->cpu); + break; + case 3: + mLOG(DS_IO, STUB, "Enter sleep mode not supported"); + break; + } +} + static uint32_t DSIOWrite(struct DSCommon* dscore, uint32_t address, uint16_t value) { switch (address) { // Timers@@ -108,6 +125,10 @@ ds->memory.io7[address >> 1] = value;
} void DS7IOWrite8(struct DS* ds, uint32_t address, uint8_t value) { + if (address == DS7_REG_HALTCNT) { + _DSHaltCNT(&ds->ds7, value); + return; + } if (address < DS7_REG_MAX) { uint16_t value16 = value << (8 * (address & 1)); value16 |= (ds->ds7.memory.io[(address & 0xFFF) >> 1]) & ~(0xFF << (8 * (address & 1)));
M
src/gba/gba.c
→
src/gba/gba.c
@@ -434,8 +434,7 @@ }
} void GBAHalt(struct GBA* gba) { - gba->cpu->nextEvent = gba->cpu->cycles; - gba->cpu->halted = 1; + ARMHalt(gba->cpu); } void GBAStop(struct GBA* gba) {