Move includes into source/ directory, some small cleanups
This commit is contained in:
parent
2c131f4c63
commit
bc5aa24d4f
2
Makefile
2
Makefile
@ -20,7 +20,7 @@ export TARGET := $(shell basename $(CURDIR))
|
|||||||
BUILD := build
|
BUILD := build
|
||||||
SOURCES := source source/fatfs
|
SOURCES := source source/fatfs
|
||||||
DATA := data
|
DATA := data
|
||||||
INCLUDES := include source
|
INCLUDES := source
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
# Setup some defines
|
# Setup some defines
|
||||||
|
@ -8,19 +8,21 @@
|
|||||||
//#include "DrawCharacter.h"
|
//#include "DrawCharacter.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
|
||||||
void ioDelay( u32 us );
|
void ioDelay(u32 us);
|
||||||
extern u8* bottomScreen;
|
extern u8* bottomScreen;
|
||||||
|
|
||||||
int CartInited=0;
|
int CartID = -1;
|
||||||
int CartID=-1;
|
u32 CartType = 0;
|
||||||
u32 CartType=0;
|
int A0_Response = -1;
|
||||||
int A0_Response=-1;
|
|
||||||
|
|
||||||
u32 rand1 = 0;
|
u32 rand1 = 0;
|
||||||
u32 rand2 = 0;
|
u32 rand2 = 0;
|
||||||
|
|
||||||
u32 BSWAP32(u32 val) {
|
u32 BSWAP32(u32 val) {
|
||||||
return (((val >> 24) & 0xFF)) | (((val >> 16) & 0xFF) << 8) | (((val >> 8) & 0xFF) << 16) | (((val) & 0xFF)<<24);
|
return (((val >> 24) & 0xFF)) |
|
||||||
|
(((val >> 16) & 0xFF) << 8) |
|
||||||
|
(((val >> 8) & 0xFF) << 16) |
|
||||||
|
((val & 0xFF) << 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Reset the cart slot?
|
//Reset the cart slot?
|
||||||
@ -285,7 +287,7 @@ u32 Cart_GetSecureID()
|
|||||||
{
|
{
|
||||||
u32 id = 0;
|
u32 id = 0;
|
||||||
u32 getid_cmd[4] = { 0xA2000000, 0x00000000, rand1, rand2 };
|
u32 getid_cmd[4] = { 0xA2000000, 0x00000000, rand1, rand2 };
|
||||||
CTR_SendCommand( getid_cmd, 0x4, 1, 0x100802C, &id );
|
CTR_SendCommand(getid_cmd, 0x4, 1, 0x100802C, &id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,7 +299,11 @@ int Cart_IsInserted()
|
|||||||
void Cart_ReadSectorSD(u8* aBuffer,u32 aSector)
|
void Cart_ReadSectorSD(u8* aBuffer,u32 aSector)
|
||||||
{
|
{
|
||||||
u64 adr = ((u64)0xBF << 56) | (aSector * 0x200);
|
u64 adr = ((u64)0xBF << 56) | (aSector * 0x200);
|
||||||
u32 readheader_cmd[4] = { (u32)(adr>>32), (u32)(adr&0xFFFFFFFF), 0x00000000, 0x00000000 };
|
u32 readheader_cmd[4] = {
|
||||||
|
(u32)(adr >> 32),
|
||||||
|
(u32)(adr&0xFFFFFFFF),
|
||||||
|
0x00000000, 0x00000000
|
||||||
|
};
|
||||||
CTR_SendCommand( readheader_cmd, 0x200, 1, 0x100802C, aBuffer );
|
CTR_SendCommand( readheader_cmd, 0x200, 1, 0x100802C, aBuffer );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,9 +314,6 @@ u32 Cart_GetID()
|
|||||||
|
|
||||||
void Cart_Init()
|
void Cart_Init()
|
||||||
{
|
{
|
||||||
//Skip init if its already been done
|
|
||||||
//if(CartInited) return;
|
|
||||||
|
|
||||||
GatewayCartInit(); //Seems to reset the cart slot?
|
GatewayCartInit(); //Seems to reset the cart slot?
|
||||||
|
|
||||||
REG_CTRCARDSECCNT &= 0xFFFFFFFB;
|
REG_CTRCARDSECCNT &= 0xFFFFFFFB;
|
||||||
@ -326,22 +329,22 @@ void Cart_Init()
|
|||||||
ioDelay(167550);
|
ioDelay(167550);
|
||||||
REG_NTRCARDMCNT |= (NTRCARD_CR1_ENABLE | NTRCARD_CR1_IRQ);
|
REG_NTRCARDMCNT |= (NTRCARD_CR1_ENABLE | NTRCARD_CR1_IRQ);
|
||||||
REG_NTRCARDROMCNT = NTRCARD_nRESET | NTRCARD_SEC_SEED;
|
REG_NTRCARDROMCNT = NTRCARD_nRESET | NTRCARD_SEC_SEED;
|
||||||
while(REG_NTRCARDROMCNT & NTRCARD_BUSY);
|
while (REG_NTRCARDROMCNT & NTRCARD_BUSY);
|
||||||
|
|
||||||
//Reset
|
// Reset
|
||||||
u32 reset_cmd[2] = { 0x9F000000, 0x00000000 };
|
u32 reset_cmd[2] = { 0x9F000000, 0x00000000 };
|
||||||
NTR_SendCommand( reset_cmd, 0x2000, NTRCARD_CLK_SLOW|NTRCARD_DELAY1(0x1FFF)|NTRCARD_DELAY2(0x18), NULL );
|
NTR_SendCommand(reset_cmd, 0x2000, NTRCARD_CLK_SLOW | NTRCARD_DELAY1(0x1FFF) | NTRCARD_DELAY2(0x18), NULL);
|
||||||
|
|
||||||
u32 getid_cmd[2] = { 0x90000000, 0x00000000 };
|
u32 getid_cmd[2] = { 0x90000000, 0x00000000 };
|
||||||
NTR_SendCommand( getid_cmd, 0x4, NTRCARD_CLK_SLOW|NTRCARD_DELAY1(0x1FFF)|NTRCARD_DELAY2(0x18), &CartID );
|
NTR_SendCommand(getid_cmd, 0x4, NTRCARD_CLK_SLOW | NTRCARD_DELAY1(0x1FFF) | NTRCARD_DELAY2(0x18), &CartID);
|
||||||
|
|
||||||
if((CartID & 0x10000000)) //3ds
|
if ((CartID & 0x10000000)) // 3ds
|
||||||
{
|
{
|
||||||
u32 unknowna0_cmd[2] = { 0xA0000000, 0x00000000 };
|
u32 unknowna0_cmd[2] = { 0xA0000000, 0x00000000 };
|
||||||
NTR_SendCommand( unknowna0_cmd, 0x4, 0, &A0_Response );
|
NTR_SendCommand(unknowna0_cmd, 0x4, 0, &A0_Response);
|
||||||
|
|
||||||
u32 enter16bytemode_cmd[2] = { 0x3E000000, 0x00000000 };
|
u32 enter16bytemode_cmd[2] = { 0x3E000000, 0x00000000 };
|
||||||
NTR_SendCommand( enter16bytemode_cmd, 0x0, 0, NULL );
|
NTR_SendCommand(enter16bytemode_cmd, 0x0, 0, NULL);
|
||||||
|
|
||||||
SwitchToCTRCARD();
|
SwitchToCTRCARD();
|
||||||
|
|
||||||
@ -349,41 +352,22 @@ void Cart_Init()
|
|||||||
|
|
||||||
REG_CTRCARDBLKCNT = 0;
|
REG_CTRCARDBLKCNT = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*u8 data[0x200];
|
|
||||||
u32 readheader_cmd[4] = { 0x82000000, 0x00000000, 0x00000000, 0x00000000 };
|
|
||||||
CTR_SendCommand( readheader_cmd, 0x200, 1, 0x802C, &data );*/
|
|
||||||
|
|
||||||
/*char test[200];
|
|
||||||
for(int i=0; i<16*16; i+=16)
|
|
||||||
{
|
|
||||||
int j = 16*16 + i;
|
|
||||||
sprintf(test,"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
|
|
||||||
data[j+0],data[j+1],data[j+2],data[j+3],data[j+4],data[j+5],data[j+6],data[j+7],
|
|
||||||
data[j+8],data[j+9],data[j+10],data[j+11],data[j+12],data[j+13],data[j+14],data[j+15]);
|
|
||||||
DrawString((unsigned char *)0x20184E60, test, 4, 70+i/2, RGB(40, 40, 40), RGB(208, 208, 208));
|
|
||||||
sprintf(test,"%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",
|
|
||||||
data[j+0],data[j+1],data[j+2],data[j+3],data[j+4],data[j+5],data[j+6],data[j+7],
|
|
||||||
data[j+8],data[j+9],data[j+10],data[j+11],data[j+12],data[j+13],data[j+14],data[j+15]);
|
|
||||||
DrawString((unsigned char *)0x20184E60, test, 266, 70+i/2, RGB(40, 40, 40), RGB(208, 208, 208));
|
|
||||||
}*/
|
|
||||||
|
|
||||||
//sprintf(test,"0x100 = %02x%02x%02x%02x (NCSD)",data[0x100],data[0x101],data[0x102],data[0x103]);
|
|
||||||
//DrawString((unsigned char *)0x20184E60, test, 10, 80, RGB(40, 40, 40), RGB(208, 208, 208));
|
|
||||||
|
|
||||||
CartInited = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendReadCommand( u32 sector, u32 length, u32 blocks, void * buffer )
|
void SendReadCommand( u32 sector, u32 length, u32 blocks, void * buffer )
|
||||||
{
|
{
|
||||||
u32 read_cmd[4] = { (0xBF000000 | (u32)(sector>>23)), (u32)((sector<<9) & 0xFFFFFFFF), 0x00000000, 0x00000000 };
|
u32 read_cmd[4] = {
|
||||||
CTR_SendCommand( read_cmd, length, blocks, 0x100822C, buffer );
|
(0xBF000000 | (u32)(sector>>23)),
|
||||||
|
(u32)((sector<<9) & 0xFFFFFFFF),
|
||||||
|
0x00000000, 0x00000000
|
||||||
|
};
|
||||||
|
CTR_SendCommand(read_cmd, length, blocks, 0x100822C, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetHeader( void * buffer )
|
void GetHeader(void * buffer)
|
||||||
{
|
{
|
||||||
u32 readheader_cmd[4] = { 0x82000000, 0x00000000, 0x00000000, 0x00000000 };
|
u32 readheader_cmd[4] = { 0x82000000, 0x00000000, 0x00000000, 0x00000000 };
|
||||||
CTR_SendCommand( readheader_cmd, 0x200, 1, 0x4802C, buffer );
|
CTR_SendCommand(readheader_cmd, 0x200, 1, 0x4802C, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
//returns 1 if MAC valid otherwise 0
|
//returns 1 if MAC valid otherwise 0
|
||||||
|
@ -67,8 +67,6 @@ int main() {
|
|||||||
Debug("Successfully f_mounted");
|
Debug("Successfully f_mounted");
|
||||||
Debug("cleared stuff! Initializing game card...", 1, 1, 0xFF);
|
Debug("cleared stuff! Initializing game card...", 1, 1, 0xFF);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ROM DUMPING CODE STARTS HERE
|
// ROM DUMPING CODE STARTS HERE
|
||||||
|
|
||||||
Cart_Init();
|
Cart_Init();
|
||||||
@ -82,18 +80,6 @@ int main() {
|
|||||||
Debug("Done reading header: %08x :)...", *(u32*)&header[0x100]);
|
Debug("Done reading header: %08x :)...", *(u32*)&header[0x100]);
|
||||||
|
|
||||||
// TODO: Check first header bytes for "NCSD" or other magic words which should be there for valid NCCHs
|
// TODO: Check first header bytes for "NCSD" or other magic words which should be there for valid NCCHs
|
||||||
/* if(*ptr != 0x4453434E) // Check for "NCSD" magic
|
|
||||||
{
|
|
||||||
Debug("Bad header read! Got %08x, expected %08x", *ptr, 0x4453434E);
|
|
||||||
svcSleepThread(150000000LL);
|
|
||||||
wait_key();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
Debug("Done checking NCSD magic:)...", 1, 1, 0xFF);
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
u32 sec_keys[4];
|
u32 sec_keys[4];
|
||||||
Cart_Secure_Init((u32*)header,sec_keys);
|
Cart_Secure_Init((u32*)header,sec_keys);
|
||||||
|
|
||||||
@ -111,13 +97,14 @@ int main() {
|
|||||||
|
|
||||||
wait_key();
|
wait_key();
|
||||||
Debug("File name: \"%s\"", String2);
|
Debug("File name: \"%s\"", String2);
|
||||||
|
|
||||||
unsigned flags = FA_READ | FA_WRITE | FA_CREATE_ALWAYS;
|
unsigned flags = FA_READ | FA_WRITE | FA_CREATE_ALWAYS;
|
||||||
ret = (f_open(&file, String2, flags) == FR_OK);
|
if (f_open(&file, String2, flags) != FR_OK) {
|
||||||
if (!ret) {
|
|
||||||
Debug("Failed to create file...");
|
Debug("Failed to create file...");
|
||||||
wait_key();
|
wait_key();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
f_lseek(&file, 0);
|
f_lseek(&file, 0);
|
||||||
f_sync(&file);
|
f_sync(&file);
|
||||||
Debug("Successfully created file");
|
Debug("Successfully created file");
|
||||||
@ -131,26 +118,24 @@ int main() {
|
|||||||
wait_key();
|
wait_key();
|
||||||
|
|
||||||
|
|
||||||
u32 cartSize = (*((u32*)&target[0x104]));
|
u32 cartSize = *(u32*)(&target[0x104]);
|
||||||
Debug("Cart size: %d MB", cartSize * 0x200 / 1024/1024);
|
Debug("Cart size: %d MB", cartSize * 0x200 / 1024/1024);
|
||||||
wait_key();
|
wait_key();
|
||||||
|
|
||||||
// Dump remaining data
|
// Dump remaining data
|
||||||
for(u32 adr=0x20; adr<cartSize; adr+=ramCache)
|
for(u32 adr=0x20; adr<cartSize; adr+=ramCache) {
|
||||||
{
|
|
||||||
ClearTop();
|
ClearTop();
|
||||||
Debug("Wrote 0x%x bytes, e.g. %08x",bytes_written, *(u32*)target);
|
Debug("Wrote 0x%x bytes, e.g. %08x",bytes_written, *(u32*)target);
|
||||||
u32 dumped = cartSize - adr;
|
u32 dumped = cartSize - adr;
|
||||||
if(dumped > ramCache) dumped = ramCache;
|
if(dumped > ramCache) dumped = ramCache;
|
||||||
|
|
||||||
for(u32 adr2=0; (adr2 < dumped); adr2+=blocks)
|
for(u32 adr2=0; (adr2 < dumped); adr2+=blocks) {
|
||||||
{
|
|
||||||
u32 currentSector = (adr+adr2);
|
u32 currentSector = (adr+adr2);
|
||||||
u32 percent = ((currentSector*100)/cartSize);
|
u32 percent = ((currentSector*100)/cartSize);
|
||||||
if ((adr2 % (blocks*3)) == blocks*2)
|
if ((adr2 % (blocks*3)) == blocks*2)
|
||||||
Debug("Dumping %08X / %08X - %03d%%",currentSector,cartSize,percent);
|
Debug("Dumping %08X / %08X - %03d%%",currentSector,cartSize,percent);
|
||||||
|
|
||||||
SendReadCommand( currentSector, mediaUnit, blocks, (void*)(target+(adr2*mediaUnit)) );
|
SendReadCommand(currentSector, mediaUnit, blocks, (void*)(target + (adr2 * mediaUnit)));
|
||||||
}
|
}
|
||||||
f_write(&file, target, dumped * mediaUnit, &bytes_written);
|
f_write(&file, target, dumped * mediaUnit, &bytes_written);
|
||||||
f_sync(&file);
|
f_sync(&file);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user