From db7bfdb1852ab7b672e65d22ace31996ab6cfe75 Mon Sep 17 00:00:00 2001 From: Alexander B <4866817+MathyFurret@users.noreply.github.com> Date: Tue, 21 Sep 2021 12:10:58 -0500 Subject: [PATCH] Disassembler: Fix LDR/STR immediate offset --- desmume/src/frontend/modules/Disassembler.cpp | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/desmume/src/frontend/modules/Disassembler.cpp b/desmume/src/frontend/modules/Disassembler.cpp index dcedc3e6d..8dbe881cd 100644 --- a/desmume/src/frontend/modules/Disassembler.cpp +++ b/desmume/src/frontend/modules/Disassembler.cpp @@ -2118,17 +2118,17 @@ return txt;} static char * OP_LDR_P_IMM_OFF(u32 adr, u32 i, char * txt) { if(REG_POS(i,16) == 15) - sprintf(txt, "LDR%s %s, [%08X]", Condition[CONDITION(i)], Registre[REG_POS(i,12)], (adr + 8 + (int)(i&0x7FF))); + sprintf(txt, "LDR%s %s, [%08X]", Condition[CONDITION(i)], Registre[REG_POS(i,12)], (adr + 8 + (int)(i&0xFFF))); else - sprintf(txt, "LDR%s %s, [%s, #%X]", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0x7FF)); + sprintf(txt, "LDR%s %s, [%s, #%X]", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0xFFF)); return txt;} static char * OP_LDR_M_IMM_OFF(u32 adr, u32 i, char * txt) { if(REG_POS(i,16) == 15) - sprintf(txt, "LDR%s %s, [%08X]", Condition[CONDITION(i)], Registre[REG_POS(i,12)], (adr + 8 - (int)(i&0x7FF))); + sprintf(txt, "LDR%s %s, [%08X]", Condition[CONDITION(i)], Registre[REG_POS(i,12)], (adr + 8 - (int)(i&0xFFF))); else - sprintf(txt, "LDR%s %s, [%s, -#%X]", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0x7FF)); + sprintf(txt, "LDR%s %s, [%s, -#%X]", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0xFFF)); return txt;} static char * OP_LDREX(u32 adr, u32 i, char * txt) @@ -2178,12 +2178,12 @@ return txt;} static char * OP_LDR_P_IMM_OFF_PREIND(u32 adr, u32 i, char * txt) { - sprintf(txt, "LDR%s %s, [%s, #%X]!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0x7FF)); + sprintf(txt, "LDR%s %s, [%s, #%X]!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0xFFF)); return txt;} static char * OP_LDR_M_IMM_OFF_PREIND(u32 adr, u32 i, char * txt) { - sprintf(txt, "LDR%s %s, [%s, -#%X]!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0x7FF)); + sprintf(txt, "LDR%s %s, [%s, -#%X]!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0xFFF)); return txt;} static char * OP_LDR_P_LSL_IMM_OFF_PREIND(u32 adr, u32 i, char * txt) @@ -2228,17 +2228,17 @@ return txt;} static char * OP_LDR_P_IMM_OFF_POSTIND(u32 adr, u32 i, char * txt) { - sprintf(txt, "LDR%s %s, [%s], #%X!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0x7FF)); + sprintf(txt, "LDR%s %s, [%s], #%X!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0xFFF)); return txt;} static char * OP_LDR_P_IMM_OFF_POSTIND2(u32 adr, u32 i, char * txt) { - sprintf(txt, "LDR%s %s, [%s], #%X!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0x7FF)); + sprintf(txt, "LDR%s %s, [%s], #%X!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0xFFF)); return txt;} static char * OP_LDR_M_IMM_OFF_POSTIND(u32 adr, u32 i, char * txt) { - sprintf(txt, "LDR%s %s, [%s], -#%X!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0x7FF)); + sprintf(txt, "LDR%s %s, [%s], -#%X!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0xFFF)); return txt;} static char * OP_LDR_P_LSL_IMM_OFF_POSTIND(u32 adr, u32 i, char * txt) @@ -2285,12 +2285,12 @@ return txt;} static char * OP_LDRB_P_IMM_OFF(u32 adr, u32 i, char * txt) { - sprintf(txt, "LDRB%s %s, [%s, #%X]", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0x7FF)); + sprintf(txt, "LDRB%s %s, [%s, #%X]", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0xFFF)); return txt;} static char * OP_LDRB_M_IMM_OFF(u32 adr, u32 i, char * txt) { - sprintf(txt, "LDRB%s %s, [%s, -#%X]", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0x7FF)); + sprintf(txt, "LDRB%s %s, [%s, -#%X]", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0xFFF)); return txt;} static char * OP_LDRB_P_LSL_IMM_OFF(u32 adr, u32 i, char * txt) @@ -2335,12 +2335,12 @@ return txt;} static char * OP_LDRB_P_IMM_OFF_PREIND(u32 adr, u32 i, char * txt) { - sprintf(txt, "LDRB%s %s, [%s, #%X]!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0x7FF)); + sprintf(txt, "LDRB%s %s, [%s, #%X]!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0xFFF)); return txt;} static char * OP_LDRB_M_IMM_OFF_PREIND(u32 adr, u32 i, char * txt) { - sprintf(txt, "LDRB%s %s, [%s, -#%X]!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0x7FF)); + sprintf(txt, "LDRB%s %s, [%s, -#%X]!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0xFFF)); return txt;} static char * OP_LDRB_P_LSL_IMM_OFF_PREIND(u32 adr, u32 i, char * txt) @@ -2385,12 +2385,12 @@ return txt;} static char * OP_LDRB_P_IMM_OFF_POSTIND(u32 adr, u32 i, char * txt) { - sprintf(txt, "LDRB%s %s, [%s], #%X!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0x7FF)); + sprintf(txt, "LDRB%s %s, [%s], #%X!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0xFFF)); return txt;} static char * OP_LDRB_M_IMM_OFF_POSTIND(u32 adr, u32 i, char * txt) { - sprintf(txt, "LDRB%s %s, [%s], -#%X!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0x7FF)); + sprintf(txt, "LDRB%s %s, [%s], -#%X!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0xFFF)); return txt;} static char * OP_LDRB_P_LSL_IMM_OFF_POSTIND(u32 adr, u32 i, char * txt) @@ -2437,12 +2437,12 @@ return txt;} static char * OP_STR_P_IMM_OFF(u32 adr, u32 i, char * txt) { - sprintf(txt, "STR%s %s, [%s, #%X]", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0x7FF)); + sprintf(txt, "STR%s %s, [%s, #%X]", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0xFFF)); return txt;} static char * OP_STR_M_IMM_OFF(u32 adr, u32 i, char * txt) { - sprintf(txt, "STR%s %s, [%s, -#%X]", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0x7FF)); + sprintf(txt, "STR%s %s, [%s, -#%X]", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0xFFF)); return txt;} static char * OP_STREX(u32 adr, u32 i, char * txt) @@ -2492,12 +2492,12 @@ return txt;} static char * OP_STR_P_IMM_OFF_PREIND(u32 adr, u32 i, char * txt) { - sprintf(txt, "STR%s %s, [%s, #%X]!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0x7FF)); + sprintf(txt, "STR%s %s, [%s, #%X]!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0xFFF)); return txt;} static char * OP_STR_M_IMM_OFF_PREIND(u32 adr, u32 i, char * txt) { - sprintf(txt, "STR%s %s, [%s, -#%X]!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0x7FF)); + sprintf(txt, "STR%s %s, [%s, -#%X]!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0xFFF)); return txt;} static char * OP_STR_P_LSL_IMM_OFF_PREIND(u32 adr, u32 i, char * txt) @@ -2542,12 +2542,12 @@ return txt;} static char * OP_STR_P_IMM_OFF_POSTIND(u32 adr, u32 i, char * txt) { - sprintf(txt, "STR%s %s, [%s], #%X!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0x7FF)); + sprintf(txt, "STR%s %s, [%s], #%X!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0xFFF)); return txt;} static char * OP_STR_M_IMM_OFF_POSTIND(u32 adr, u32 i, char * txt) { - sprintf(txt, "STR%s %s, [%s], -#%X!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0x7FF)); + sprintf(txt, "STR%s %s, [%s], -#%X!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0xFFF)); return txt;} static char * OP_STR_P_LSL_IMM_OFF_POSTIND(u32 adr, u32 i, char * txt) @@ -2594,12 +2594,12 @@ return txt;} static char * OP_STRB_P_IMM_OFF(u32 adr, u32 i, char * txt) { - sprintf(txt, "STRB%s %s, [%s, #%X]", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0x7FF)); + sprintf(txt, "STRB%s %s, [%s, #%X]", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0xFFF)); return txt;} static char * OP_STRB_M_IMM_OFF(u32 adr, u32 i, char * txt) { - sprintf(txt, "STRB%s %s, [%s, -#%X]", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0x7FF)); + sprintf(txt, "STRB%s %s, [%s, -#%X]", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0xFFF)); return txt;} static char * OP_STRB_P_LSL_IMM_OFF(u32 adr, u32 i, char * txt) @@ -2644,12 +2644,12 @@ return txt;} static char * OP_STRB_P_IMM_OFF_PREIND(u32 adr, u32 i, char * txt) { - sprintf(txt, "STRB%s %s, [%s, #%X]!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0x7FF)); + sprintf(txt, "STRB%s %s, [%s, #%X]!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0xFFF)); return txt;} static char * OP_STRB_M_IMM_OFF_PREIND(u32 adr, u32 i, char * txt) { - sprintf(txt, "STRB%s %s, [%s, -#%X]!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0x7FF)); + sprintf(txt, "STRB%s %s, [%s, -#%X]!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0xFFF)); return txt;} static char * OP_STRB_P_LSL_IMM_OFF_PREIND(u32 adr, u32 i, char * txt) @@ -2694,12 +2694,12 @@ return txt;} static char * OP_STRB_P_IMM_OFF_POSTIND(u32 adr, u32 i, char * txt) { - sprintf(txt, "STRB%s %s, [%s], #%X!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0x7FF)); + sprintf(txt, "STRB%s %s, [%s], #%X!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0xFFF)); return txt;} static char * OP_STRB_M_IMM_OFF_POSTIND(u32 adr, u32 i, char * txt) { - sprintf(txt, "STRB%s %s, [%s], -#%X!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0x7FF)); + sprintf(txt, "STRB%s %s, [%s], -#%X!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0xFFF)); return txt;} static char * OP_STRB_P_LSL_IMM_OFF_POSTIND(u32 adr, u32 i, char * txt) @@ -2747,12 +2747,12 @@ return txt;} #if 0 static char * OP_LDRBT_P_IMM_OFF_POSTIND(u32 adr, u32 i, char * txt) { - sprintf(txt, "LDRBT%s %s, [%s], #%X!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0x7FF)); + sprintf(txt, "LDRBT%s %s, [%s], #%X!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0xFFF)); return txt;} static char * OP_LDRBT_M_IMM_OFF_POSTIND(u32 adr, u32 i, char * txt) { - sprintf(txt, "LDRBT%s %s, [%s], -#%X!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0x7FF)); + sprintf(txt, "LDRBT%s %s, [%s], -#%X!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0xFFF)); return txt;} static char * OP_LDRBT_P_LSL_IMM_OFF_POSTIND(u32 adr, u32 i, char * txt) @@ -2799,12 +2799,12 @@ return txt;} static char * OP_STRBT_P_IMM_OFF_POSTIND(u32 adr, u32 i, char * txt) { - sprintf(txt, "STRBT%s %s, [%s], #%X!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0x7FF)); + sprintf(txt, "STRBT%s %s, [%s], #%X!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0xFFF)); return txt;} static char * OP_STRBT_M_IMM_OFF_POSTIND(u32 adr, u32 i, char * txt) { - sprintf(txt, "STRBT%s %s, [%s], -#%X!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0x7FF)); + sprintf(txt, "STRBT%s %s, [%s], -#%X!", Condition[CONDITION(i)], Registre[REG_POS(i,12)], Registre[REG_POS(i,16)], (int)(i&0xFFF)); return txt;} static char * OP_STRBT_P_LSL_IMM_OFF_POSTIND(u32 adr, u32 i, char * txt)