diff --git a/desmume/src/NDSSystem.cpp b/desmume/src/NDSSystem.cpp index 2054b61c8..3a7cd560a 100644 --- a/desmume/src/NDSSystem.cpp +++ b/desmume/src/NDSSystem.cpp @@ -235,8 +235,8 @@ NDS_header * NDS_getROMHeader(void) { offsetof(NDS_header,ARM9OverlaySize), 4}, { offsetof(NDS_header,ARM7OverlayOff), 4}, { offsetof(NDS_header,ARM7OverlaySize), 4}, - { offsetof(NDS_header,unknown2a), 4}, - { offsetof(NDS_header,unknown2b), 4}, + { offsetof(NDS_header,normalCmd), 4}, + { offsetof(NDS_header,Key1Cmd), 4}, { offsetof(NDS_header,IconOff), 4}, { offsetof(NDS_header,CRC16), 2}, @@ -586,13 +586,20 @@ int NDS_LoadROM(const char *filename, const char *physicalName, const char *logi gameInfo.populate(); gameInfo.crc = crc32(0,(u8*)gameInfo.romdata,gameInfo.romsize); - // 1st byte - Manufacturer (C2h = Macronix) - // 2nd byte - Chip size in megabytes minus 1 (eg. 0Fh = 16MB) - // 3rd byte - Reserved/zero (probably upper bits of chip size) - // 4th byte - Bit7: Secure Area Block transfer mode (8x200h or 1000h) + gameInfo.chipID = 0xC2; // The Manufacturer ID is defined by JEDEC (C2h = Macronix) + gameInfo.chipID |= ((((128 << gameInfo.header.cardSize) / 1024) - 1) << 8); // Chip size in megabytes minus 1 + // (07h = 8MB, 0Fh = 16MB, 1Fh = 32MB, 3Fh = 64MB, 7Fh = 128MB) - // It doesnt look like the chip size is important. - gameInfo.chipID = 0x00000000 | 0x00000000 | 0x00000F00 | 0x000000C2; + // flags + // 0: Unknown + // 1: Unknown + // 2: Unknown + // 3: Unknown + // 4: Unknown + // 5: DSi? (if set to 1 then DSi Enhanced games send command D6h to Slot1) + // 6: Unknown + // 7: ROM speed (Secure Area Block transfer mode (trasfer 8x200h or 1000h bytes) + gameInfo.chipID |= (0x00 << 24); INFO("\nROM game code: %c%c%c%c\n", gameInfo.header.gameCode[0], gameInfo.header.gameCode[1], gameInfo.header.gameCode[2], gameInfo.header.gameCode[3]); INFO("ROM crc: %08X\n", gameInfo.crc); diff --git a/desmume/src/NDSSystem.h b/desmume/src/NDSSystem.h index 2436e17f4..43a400cd5 100644 --- a/desmume/src/NDSSystem.h +++ b/desmume/src/NDSSystem.h @@ -91,55 +91,55 @@ extern CFIRMWARE *firmware; #include "PACKED.h" struct NDS_header { - char gameTile[12]; // 000 - Game Title (uppercase ASCII, padded with 00h) - char gameCode[4]; // 00C - Gamecode (uppercase ASCII, NTR-, 0=homebrew) - u16 makerCode; // 010 - Makercode (uppercase ASCII, 0=homebrew) - u8 unitCode; // 012 - Unitcode (00h=Nintendo DS) - u8 deviceCode; // 013 - Encryption Seed Select (00..07h, usually 00h) - u8 cardSize; // 014 - Devicecapacity (Chipsize = 128KB SHL nn) (eg. 7 = 16MB) - u8 cardInfo[8]; // 015 - ??? --> reversed (padded 00h) - u8 flags; // 01D - ??? | - u8 romversion; // 01E - ROM Version (usually 00h) - u8 autostart; // 01F - Autostart (Bit2: Skip "Press Button" after Health and Safety) - // (Also skips bootmenu, even in Manual mode & even Start pressed) - u32 ARM9src; // 020 - - u32 ARM9exe; // 024 - - u32 ARM9cpy; // 028 - - u32 ARM9binSize; // 02C - - - u32 ARM7src; // 030 - - u32 ARM7exe; // 034 - - u32 ARM7cpy; // 038 - - u32 ARM7binSize; // 03C - - - u32 FNameTblOff; // 040 - - u32 FNameTblSize; // 044 - + char gameTile[12]; // 000 - Game Title (uppercase ASCII, padded with 00h) + char gameCode[4]; // 00C - Gamecode (uppercase ASCII, NTR-, 0=homebrew) + u16 makerCode; // 010 - Makercode (uppercase ASCII, 0=homebrew) + u8 unitCode; // 012 - Unitcode (00h=Nintendo DS) + u8 deviceCode; // 013 - Encryption Seed Select (00..07h, usually 00h) + u8 cardSize; // 014 - Devicecapacity (Chipsize = 128KB SHL nn) (eg. 7 = 16MB) + u8 cardInfo[8]; // 015 - ??? --> reversed (padded 00h) + u8 flags; // 01D - ??? | + u8 romversion; // 01E - ROM Version (usually 00h) + u8 autostart; // 01F - Autostart (Bit2: Skip "Press Button" after Health and Safety) + // (Also skips bootmenu, even in Manual mode & even Start pressed) + u32 ARM9src; // 020 - ARM9 rom_offset (4000h and up, align 1000h) + u32 ARM9exe; // 024 - ARM9 entry_address (2000000h..23BFE00h) + u32 ARM9cpy; // 028 - ARM9 ram_address (2000000h..23BFE00h) + u32 ARM9binSize; // 02C - ARM9 size (max 3BFE00h) (3839.5KB) - u32 FATOff; // 048 - - u32 FATSize; // 04C - + u32 ARM7src; // 030 - ARM7 rom_offset (8000h and up) + u32 ARM7exe; // 034 - ARM7 entry_address (2000000h..23BFE00h, or 37F8000h..3807E00h) + u32 ARM7cpy; // 038 - ARM7 ram_address (2000000h..23BFE00h, or 37F8000h..3807E00h) + u32 ARM7binSize; // 03C - ARM7 size (max 3BFE00h, or FE00h) (3839.5KB, 63.5KB) - u32 ARM9OverlayOff; // 050 - - u32 ARM9OverlaySize; // 054 - - u32 ARM7OverlayOff; // 058 - - u32 ARM7OverlaySize; // 05C - - - u32 unknown2a; // 060 - Port 40001A4h setting for normal commands (usually 00586000h) - u32 unknown2b; // 064 - Port 40001A4h setting for KEY1 commands (usually 001808F8h) - - u32 IconOff; // 068 - - u16 CRC16; // 06C - - u16 ROMtimeout; // 06E - - u32 ARM9unk; // 070 - - u32 ARM7unk; // 074 - - - u8 unknown3c[8]; // 078 - Secure Area Disable (by encrypted "NmMdOnly") (usually zero) - u32 ROMSize; // 080 - Total Used ROM size (remaining/unused bytes usually FFh-padded) - u32 HeaderSize; // 084 - ROM Header Size (4000h) - u8 unknown5[56]; // 088 - Reserved (zero filled) - "PASS" is contained within here? - u8 logo[156]; // 0C0 - Nintendo Logo (compressed bitmap, same as in GBA Headers) - u16 logoCRC16; // 15C - Nintendo Logo Checksum, CRC-16 of [0C0h-15Bh], fixed CF56h - u16 headerCRC16; // 15E - Header Checksum, CRC-16 of [000h-15Dh] - u8 reserved[160]; // + u32 FNameTblOff; // 040 - File Name Table (FNT) offset + u32 FNameTblSize; // 044 - File Name Table (FNT) size + + u32 FATOff; // 048 - File Allocation Table (FAT) offset + u32 FATSize; // 04C - File Allocation Table (FAT) size + + u32 ARM9OverlayOff; // 050 - File ARM9 overlay_offset + u32 ARM9OverlaySize; // 054 - File ARM9 overlay_size + u32 ARM7OverlayOff; // 058 - File ARM7 overlay_offset + u32 ARM7OverlaySize; // 05C - File ARM7 overlay_size + + u32 normalCmd; // 060 - Port 40001A4h setting for normal commands (usually 00586000h) + u32 Key1Cmd; // 064 - Port 40001A4h setting for KEY1 commands (usually 001808F8h) + + u32 IconOff; // 068 - Icon_title_offset (0=None) (8000h and up) + u16 CRC16; // 06C - Secure Area Checksum, CRC-16 of [ [20h]..7FFFh] + u16 ROMtimeout; // 06E - Secure Area Loading Timeout (usually 051Eh) + u32 ARM9unk; // 070 - + u32 ARM7unk; // 074 - + + u8 secAreaDisable[8]; // 078 - Secure Area Disable (by encrypted "NmMdOnly") (usually zero) + u32 ROMSize; // 080 - Total Used ROM size (remaining/unused bytes usually FFh-padded) + u32 HeaderSize; // 084 - ROM Header Size (4000h) + u8 unknown5[56]; // 088 - Reserved (zero filled) - "PASS" is contained within here? + u8 logo[156]; // 0C0 - Nintendo Logo (compressed bitmap, same as in GBA Headers) + u16 logoCRC16; // 15C - Nintendo Logo Checksum, CRC-16 of [0C0h-15Bh], fixed CF56h + u16 headerCRC16; // 15E - Header Checksum, CRC-16 of [000h-15Dh] + u8 reserved[160]; // }; #include "PACKED_END.h" diff --git a/desmume/src/addons/slot1_retail.cpp b/desmume/src/addons/slot1_retail.cpp index b32bc1945..813e15549 100644 --- a/desmume/src/addons/slot1_retail.cpp +++ b/desmume/src/addons/slot1_retail.cpp @@ -71,15 +71,6 @@ private: case 0x90: // 1st Get ROM Chip ID - len 4 bytes case 0xB8: // 3rd Get ROM Chip ID - len 4 bytes { - // Returns RAW unencrypted Chip ID (eg. C2h,0Fh,00h,00h), repeated every 4 bytes. - // - // 1st byte - Manufacturer (C2h = Macronix) - // 2nd byte - Chip size in megabytes minus 1 (eg. 0Fh = 16MB) - // 3rd byte - Reserved/zero (probably upper bits of chip size) - // 4th byte - Bit7: Secure Area Block transfer mode (8x200h or 1000h) - - // It doesnt look like the chip size is important. - // Note: the BIOS stores the chip ID in main memory // Most games continuously compare the chip ID with // the value in memory, probably to know if the card @@ -127,9 +118,7 @@ private: } break; default: - #ifdef _NEW_BOOT - printf("ARM%c: SLOT1 invalid command %02X (read)\n", PROCNUM?'7':'9', cmd); - #endif + //printf("ARM%c: SLOT1 invalid command %02X (read)\n", PROCNUM?'7':'9', cmd); return 0; } //switch(card.command[0]) } //read32_GCDATAIN diff --git a/desmume/src/arm_instructions.cpp b/desmume/src/arm_instructions.cpp index a4a550b97..828ac8d0a 100644 --- a/desmume/src/arm_instructions.cpp +++ b/desmume/src/arm_instructions.cpp @@ -32,6 +32,7 @@ #include "armcpu.h" #include "NDSSystem.h" #include "MMU_timing.h" +#include "bios.h" #define cpu (&ARMPROC) #define TEMPLATE template @@ -6191,10 +6192,11 @@ TEMPLATE static u32 FASTCALL OP_SWI(const u32 i) (cpu->intVector == 0x00000000 && PROCNUM==0) || (cpu->intVector == 0xFFFF0000 && PROCNUM==1); + //printf("ARM%c SWI %02X\t; %s\n", PROCNUM?'7':'9', (swinum & 0x1F), ARM_swi_names[PROCNUM][(swinum & 0x1F)]); + if(cpu->swi_tab && !bypassBuiltinSWI) { swinum &= 0x1F; - //printf("%d ARM SWI %d \n",PROCNUM,swinum); return cpu->swi_tab[swinum]() + 3; } else diff --git a/desmume/src/bios.cpp b/desmume/src/bios.cpp index 2e48c89be..29671946a 100644 --- a/desmume/src/bios.cpp +++ b/desmume/src/bios.cpp @@ -1210,3 +1210,76 @@ u32 (* ARM_swi_tab[2][32])()={ CustomHalt, // 0x1F } }; + +#define BIOS_NOP "bios_nop" +char* ARM_swi_names[2][32] = { + { + "SoftReset", // 0x00 + BIOS_NOP, // 0x01 + BIOS_NOP, // 0x02 + "WaitByLoop", // 0x03 + "IntrWait", // 0x04 + "VBlankIntrWait", // 0x05 + "Halt", // 0x06 + BIOS_NOP, // 0x07 + BIOS_NOP, // 0x08 + "Div", // 0x09 + BIOS_NOP, // 0x0A + "CpuSet", // 0x0B + "CpuFastSet", // 0x0C + "Sqrt", // 0x0D + "GetCRC16", // 0x0E + "IsDebugger", // 0x0F + "BitUnPack", // 0x10 + "LZ77UnCompWram", // 0x11 + "LZ77UnCompVram", // 0x12 + "HuffUnComp", // 0x13 + "RLUnCompWram", // 0x14 + "RLUnCompVram", // 0x15 + "Diff8bitUnFilterWram", // 0x16 + BIOS_NOP, // 0x17 + "Diff16bitUnFilter", // 0x18 + BIOS_NOP, // 0x19 + BIOS_NOP, // 0x1A + BIOS_NOP, // 0x1B + BIOS_NOP, // 0x1C + BIOS_NOP, // 0x1D + BIOS_NOP, // 0x1E + "CustomPost", // 0x1F + }, + { + "SoftReset", // 0x00 + BIOS_NOP, // 0x01 + BIOS_NOP, // 0x02 + "WaitByLoop", // 0x03 + "IntrWait", // 0x04 + "VBlankIntrWait", // 0x05 + "Halt", // 0x06 + "Sleep", // 0x07 + "SoundBias", // 0x08 + "Div", // 0x09 + BIOS_NOP, // 0x0A + "CpuSet", // 0x0B + "CpuFastSet", // 0x0C + "Sqrt", // 0x0D + "GetCRC16", // 0x0E + "IsDebugger", // 0x0F + "BitUnPack", // 0x10 + "LZ77UnCompWram", // 0x11 + "LZ77UnCompVram", // 0x12 + "HuffUnComp", // 0x13 + "RLUnCompWram", // 0x14 + "RLUnCompVram", // 0x15 + BIOS_NOP, // 0x16 + BIOS_NOP, // 0x17 + BIOS_NOP, // 0x18 + BIOS_NOP, // 0x19 + "GetSineTable", // 0x1A + "GetPitchTable", // 0x1B + "GetVolumeTable", // 0x1C + "GetBootProcs", // 0x1D + BIOS_NOP, // 0x1E + "CustomHalt", // 0x1F + } +}; +#undef BIOS_NOP diff --git a/desmume/src/bios.h b/desmume/src/bios.h index b68bb609c..6ccaff00c 100644 --- a/desmume/src/bios.h +++ b/desmume/src/bios.h @@ -21,7 +21,8 @@ #include "armcpu.h" -extern u32 (* ARM_swi_tab[2][32])();; +extern u32 (* ARM_swi_tab[2][32])(); +extern char* ARM_swi_names[2][32]; #endif diff --git a/desmume/src/thumb_instructions.cpp b/desmume/src/thumb_instructions.cpp index 6d2a27724..f24027649 100644 --- a/desmume/src/thumb_instructions.cpp +++ b/desmume/src/thumb_instructions.cpp @@ -1023,13 +1023,14 @@ TEMPLATE static u32 FASTCALL OP_SWI_THUMB(const u32 i) (cpu->intVector == 0x00000000 && PROCNUM==0) || (cpu->intVector == 0xFFFF0000 && PROCNUM==1); + //printf("THUMB%c SWI %02X\t; %s\n", PROCNUM?'7':'9', (swinum & 0x1F), ARM_swi_names[PROCNUM][(swinum & 0x1F)]); + if(cpu->swi_tab && !bypassBuiltinSWI) { //zero 25-dec-2008 - in arm, we were masking to 0x1F. //this is probably safer since an invalid opcode could crash the emu //zero 30-jun-2009 - but they say that the ideas 0xFF should crash the device... //u32 swinum = cpu->instruction & 0xFF; swinum &= 0x1F; - //printf("%d ARM SWI %d\n",PROCNUM,swinum); return cpu->swi_tab[swinum]() + 3; } else {