all repos — mgba @ ab2a8c1e62c94c4b7c14af06a9e4647d982459f3

mGBA Game Boy Advance Emulator

ARM: Fix STR storing PC after address calculation
Vicki Pfau vi@endrift.com
Fri, 24 Jan 2020 01:46:56 -0800
commit

ab2a8c1e62c94c4b7c14af06a9e4647d982459f3

parent

27882fbded835ca52b6b128da57b12e23cf715ba

2 files changed, 8 insertions(+), 3 deletions(-)

jump to
M CHANGESCHANGES

@@ -1,6 +1,7 @@

0.9.0: (Future) Emulation fixes: - ARM: Fix ALU reading PC after shifting + - ARM: Fix STR storing PC after address calculation - GBA Memory: Misaligned SRAM writes are ignored Other fixes: - Qt: Only dynamically reset video scale if a game is running
M src/arm/isa-arm.csrc/arm/isa-arm.c

@@ -376,6 +376,10 @@ DEFINE_INSTRUCTION_ARM(NAME, \

uint32_t address; \ int rn = (opcode >> 16) & 0xF; \ int rd = (opcode >> 12) & 0xF; \ + int32_t d = cpu->gprs[rd]; \ + if (UNLIKELY(rd == ARM_PC)) { \ + d += WORD_SIZE_ARM; \ + } \ int rm = opcode & 0xF; \ UNUSED(rm); \ address = ADDRESS; \

@@ -559,9 +563,9 @@ DEFINE_LOAD_STORE_INSTRUCTION_ARM(LDRB, LOAD, cpu->gprs[rd] = cpu->memory.load8(cpu, address, &currentCycles); ARM_LOAD_POST_BODY;)

DEFINE_LOAD_STORE_MODE_3_INSTRUCTION_ARM(LDRH, LOAD, cpu->gprs[rd] = cpu->memory.load16(cpu, address, &currentCycles); ARM_LOAD_POST_BODY;) DEFINE_LOAD_STORE_MODE_3_INSTRUCTION_ARM(LDRSB, LOAD, cpu->gprs[rd] = ARM_SXT_8(cpu->memory.load8(cpu, address, &currentCycles)); ARM_LOAD_POST_BODY;) DEFINE_LOAD_STORE_MODE_3_INSTRUCTION_ARM(LDRSH, LOAD, cpu->gprs[rd] = address & 1 ? ARM_SXT_8(cpu->memory.load16(cpu, address, &currentCycles)) : ARM_SXT_16(cpu->memory.load16(cpu, address, &currentCycles)); ARM_LOAD_POST_BODY;) -DEFINE_LOAD_STORE_INSTRUCTION_ARM(STR, STORE, cpu->memory.store32(cpu, address, cpu->gprs[rd], &currentCycles); ARM_STORE_POST_BODY;) -DEFINE_LOAD_STORE_INSTRUCTION_ARM(STRB, STORE, cpu->memory.store8(cpu, address, cpu->gprs[rd], &currentCycles); ARM_STORE_POST_BODY;) -DEFINE_LOAD_STORE_MODE_3_INSTRUCTION_ARM(STRH, STORE, cpu->memory.store16(cpu, address, cpu->gprs[rd], &currentCycles); ARM_STORE_POST_BODY;) +DEFINE_LOAD_STORE_INSTRUCTION_ARM(STR, STORE, cpu->memory.store32(cpu, address, d, &currentCycles); ARM_STORE_POST_BODY;) +DEFINE_LOAD_STORE_INSTRUCTION_ARM(STRB, STORE, cpu->memory.store8(cpu, address, d, &currentCycles); ARM_STORE_POST_BODY;) +DEFINE_LOAD_STORE_MODE_3_INSTRUCTION_ARM(STRH, STORE, cpu->memory.store16(cpu, address, d, &currentCycles); ARM_STORE_POST_BODY;) DEFINE_LOAD_STORE_T_INSTRUCTION_ARM(LDRBT, LOAD, enum PrivilegeMode priv = cpu->privilegeMode;