From d2d18907c39b5e9093d5a5c95840ff2f184851e4 Mon Sep 17 00:00:00 2001 From: normmatt234 Date: Tue, 6 Apr 2010 16:20:48 +0000 Subject: [PATCH] fix a couple of thumb opcode regressions. allow ds, ds/dsi hybrid and dsi only nds files to be opened. --- desmume/src/thumb_instructions.cpp | 10 ++++++++-- desmume/src/utils/decrypt/header.cpp | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/desmume/src/thumb_instructions.cpp b/desmume/src/thumb_instructions.cpp index fb086b512..003f148b5 100644 --- a/desmume/src/thumb_instructions.cpp +++ b/desmume/src/thumb_instructions.cpp @@ -784,7 +784,10 @@ TEMPLATE static u32 FASTCALL OP_STR_IMM_OFF(const u32 i) TEMPLATE static u32 FASTCALL OP_LDR_IMM_OFF(const u32 i) { u32 adr = cpu->R[REG_NUM(i, 3)] + ((i>>4)&0x7C); - cpu->R[REG_NUM(i, 0)] = READ32(cpu->mem_if->data, adr); + u32 tempValue = READ32(cpu->mem_if->data, adr); + adr = (adr&3)*8; + tempValue = (tempValue>>adr) | (tempValue<<(32-adr)); + cpu->R[REG_NUM(i, 0)] = tempValue; return MMU_aluMemAccessCycles(3, adr); } @@ -801,7 +804,10 @@ TEMPLATE static u32 FASTCALL OP_STR_REG_OFF(const u32 i) TEMPLATE static u32 FASTCALL OP_LDR_REG_OFF(const u32 i) { u32 adr = (cpu->R[REG_NUM(i, 3)] + cpu->R[REG_NUM(i, 6)]); - cpu->R[REG_NUM(i, 0)] = READ32(cpu->mem_if->data, adr); + u32 tempValue = READ32(cpu->mem_if->data, adr); + adr = (adr&3)*8; + tempValue = (tempValue>>adr) | (tempValue<<(32-adr)); + cpu->R[REG_NUM(i, 0)] = tempValue; return MMU_aluMemAccessCycles(3, adr); } diff --git a/desmume/src/utils/decrypt/header.cpp b/desmume/src/utils/decrypt/header.cpp index c64dd7730..1dccd7fa6 100644 --- a/desmume/src/utils/decrypt/header.cpp +++ b/desmume/src/utils/decrypt/header.cpp @@ -71,7 +71,7 @@ int DetectRomType(const Header& header, char* romdata) unsigned int * data = (unsigned int*)(romdata + 0x4000); //this is attempting to check for an utterly invalid nds header - if(header.unitcode != 0 && header.unitcode != 2) return ROMTYPE_INVALID; + if(header.unitcode < 0 && header.unitcode > 3) return ROMTYPE_INVALID; if (header.arm9_rom_offset < 0x4000) return ROMTYPE_HOMEBREW; if (data[0] == 0x00000000 && data[1] == 0x00000000) return ROMTYPE_MULTIBOOT;