all repos — mgba @ 186068adfe9d680e9017479bf71cf0aceacd5c2b

mGBA Game Boy Advance Emulator

Start filling in ARMBoard
Jeffrey Pfau jeffrey@endrift.com
Sun, 07 Apr 2013 13:25:45 -0700
commit

186068adfe9d680e9017479bf71cf0aceacd5c2b

parent

120b85713d96a0a02befa9f3d51cce340ea673e0

4 files changed, 52 insertions(+), 11 deletions(-)

jump to
M src/arm.csrc/arm.c

@@ -4,17 +4,16 @@ #define ARM_SIGN(I) ((I) >> 31)

#define ARM_ROR(I, ROTATE) (((I) >> ROTATE) | (I << (32 - ROTATE))) static inline void _ARMSetMode(struct ARMCore*, enum ExecutionMode); -static void _ARMSetPrivilegeMode(struct ARMCore*, enum PrivilegeMode); static ARMInstruction _ARMLoadInstructionARM(struct ARMMemory*, uint32_t address, uint32_t* opcodeOut); static ARMInstruction _ARMLoadInstructionThumb(struct ARMMemory*, uint32_t address, uint32_t* opcodeOut); static inline enum RegisterBank _ARMSelectBank(enum PrivilegeMode); static inline void _ARMReadCPSR(struct ARMCore* cpu) { _ARMSetMode(cpu, cpu->cpsr.t); - _ARMSetPrivilegeMode(cpu, cpu->cpsr.priv); + ARMSetPrivilegeMode(cpu, cpu->cpsr.priv); } -static void _ARMSetPrivilegeMode(struct ARMCore* cpu, enum PrivilegeMode mode) { +void ARMSetPrivilegeMode(struct ARMCore* cpu, enum PrivilegeMode mode) { if (mode == cpu->privilegeMode) { // Not switching modes after all return;

@@ -127,6 +126,20 @@ return 0;

} void ARMInit(struct ARMCore* cpu) { + cpu->memory = 0; + cpu->board = 0; +} + +void ARMAssociateMemory(struct ARMCore* cpu, struct ARMMemory* memory) { + cpu->memory = memory; +} + +void ARMAssociateBoard(struct ARMCore* cpu, struct ARMBoard* board) { + cpu->board = board; + board->cpu = cpu; +} + +void ARMReset(struct ARMCore* cpu) { int i; for (i = 0; i < 16; ++i) { cpu->gprs[i] = 0;

@@ -150,15 +163,10 @@

cpu->shifterOperand = 0; cpu->shifterCarryOut = 0; - cpu->memory = 0; - cpu->board = 0; - cpu->executionMode = MODE_THUMB; _ARMSetMode(cpu, MODE_ARM); -} -void ARMAssociateMemory(struct ARMCore* cpu, struct ARMMemory* memory) { - cpu->memory = memory; + cpu->board->reset(cpu->board); } void ARMStep(struct ARMCore* cpu) {
M src/arm.hsrc/arm.h

@@ -80,7 +80,8 @@ void (*store8)(struct ARMMemory*, uint32_t address, int8_t value);

}; struct ARMBoard { - // TODO + struct ARMCore* cpu; + void (*reset)(struct ARMBoard* board); }; struct ARMCore {

@@ -108,7 +109,10 @@ };

void ARMInit(struct ARMCore* cpu); void ARMAssociateMemory(struct ARMCore* cpu, struct ARMMemory* memory); +void ARMAssociateBoard(struct ARMCore* cpu, struct ARMBoard* board); +void ARMReset(struct ARMCore* cpu); void ARMStep(struct ARMCore* cpu); +void ARMSetPrivilegeMode(struct ARMCore*, enum PrivilegeMode); #endif
M src/gba.csrc/gba.c

@@ -14,6 +14,11 @@

gba->memory.p = gba; GBAMemoryInit(&gba->memory); ARMAssociateMemory(&gba->cpu, &gba->memory.d); + + GBABoardInit(&gba->board); + ARMAssociateBoard(&gba->cpu, &gba->board.d); + + ARMReset(&gba->cpu); } void GBADeinit(struct GBA* gba) {

@@ -45,6 +50,20 @@

void GBAMemoryDeinit(struct GBAMemory* memory) { munmap(memory->wram, SIZE_WORKING_RAM); munmap(memory->iwram, SIZE_WORKING_IRAM); +} + +void GBABoardInit(struct GBABoard* board) { + board->d.reset = GBABoardReset; +} + +void GBABoardReset(struct ARMBoard* board) { + struct ARMCore* cpu = board->cpu; + ARMSetPrivilegeMode(cpu, MODE_IRQ); + cpu->gprs[ARM_SP] = SP_BASE_IRQ; + ARMSetPrivilegeMode(cpu, MODE_SUPERVISOR); + cpu->gprs[ARM_SP] = SP_BASE_SUPERVISOR; + ARMSetPrivilegeMode(cpu, MODE_SYSTEM); + cpu->gprs[ARM_SP] = SP_BASE_SYSTEM; } void GBALoadROM(struct GBA* gba, int fd) {
M src/gba.hsrc/gba.h

@@ -41,6 +41,7 @@ BASE_CART2 = 0x0C000000,

BASE_CART2_EX = 0x0D000000, BASE_CART_SRAM = 0x0E000000 }; + enum { SIZE_BIOS = 0x00004000, SIZE_WORKING_RAM = 0x00040000,

@@ -59,6 +60,12 @@ SIZE_CART_EEPROM = 0x00002000

}; enum { + SP_BASE_SYSTEM = 0x03FFFF00, + SP_BASE_IRQ = 0x03FFFFA0, + SP_BASE_SUPERVISOR = 0x03FFFFE0 +}; + +enum { OFFSET_MASK = 0x00FFFFFF };

@@ -73,7 +80,7 @@ int32_t* rom;

}; struct GBABoard { - struct ARMBoard board; + struct ARMBoard d; }; struct GBA {

@@ -90,6 +97,9 @@ void GBADeinit(struct GBA* gba);

void GBAMemoryInit(struct GBAMemory* memory); void GBAMemoryDeinit(struct GBAMemory* memory); + +void GBABoardInit(struct GBABoard* board); +void GBABoardReset(struct ARMBoard* board); void GBALoadROM(struct GBA* gba, int fd);