all repos — mgba @ cfc3ec4f3b5bfe769ac502b97da24a54f17707ca

mGBA Game Boy Advance Emulator

Implement ROR
Jeffrey Pfau jeffrey@endrift.com
Thu, 25 Apr 2013 00:53:24 -0700
commit

cfc3ec4f3b5bfe769ac502b97da24a54f17707ca

parent

21490dcf511b7e0d640bf779c02c0ba53c4e99f4

2 files changed, 13 insertions(+), 2 deletions(-)

jump to
M src/arm/isa-inlines.hsrc/arm/isa-inlines.h

@@ -45,7 +45,7 @@ #define ARM_COND_LE (cpu->cpsr.z || !cpu->cpsr.n != !cpu->cpsr.v)

#define ARM_COND_AL 1 #define ARM_SIGN(I) ((I) >> 31) -#define ARM_ROR(I, ROTATE) (((I) >> ROTATE) | (I << (32 - ROTATE))) +#define ARM_ROR(I, ROTATE) ((((uint32_t) (I)) >> ROTATE) | (I << (32 - ROTATE))) #define ARM_CARRY_FROM(M, N, D) ((ARM_SIGN((M) | (N))) && !(ARM_SIGN(D))) #define ARM_BORROW_FROM(M, N, D) (((uint32_t) (M)) >= ((uint32_t) (N)))
M src/arm/isa-thumb.csrc/arm/isa-thumb.c

@@ -249,7 +249,18 @@ THUMB_NEUTRAL_S( , , cpu->gprs[rd]))

DEFINE_DATA_FORM_5_INSTRUCTION_THUMB(ADC, ARM_STUB) DEFINE_DATA_FORM_5_INSTRUCTION_THUMB(SBC, ARM_STUB) -DEFINE_DATA_FORM_5_INSTRUCTION_THUMB(ROR, ARM_STUB) +DEFINE_DATA_FORM_5_INSTRUCTION_THUMB(ROR, + int rs = cpu->gprs[rn] & 0xFF; + if (rs) { + int r4 = rs & 0x1F; + if (r4 > 0) { + cpu->cpsr.c = cpu->gprs[rd] & (1 << (r4 - 1)); + cpu->gprs[rd] = ARM_ROR(cpu->gprs[rd], r4); + } else { + cpu->cpsr.c = ARM_SIGN(cpu->gprs[rd]); + } + } + THUMB_NEUTRAL_S( , , cpu->gprs[rd]);) DEFINE_DATA_FORM_5_INSTRUCTION_THUMB(TST, ARM_STUB) DEFINE_DATA_FORM_5_INSTRUCTION_THUMB(NEG, THUMB_SUBTRACTION(cpu->gprs[rd], 0, cpu->gprs[rn])) DEFINE_DATA_FORM_5_INSTRUCTION_THUMB(CMP2, int32_t aluOut = cpu->gprs[rd] - cpu->gprs[rn]; THUMB_SUBTRACTION_S(cpu->gprs[rd], cpu->gprs[rn], aluOut))