Move includes into source/ directory, some small cleanups

This commit is contained in:
archshift 2015-05-10 00:14:42 -07:00
parent 2c131f4c63
commit bc5aa24d4f
12 changed files with 83 additions and 114 deletions

View File

@ -20,7 +20,7 @@ export TARGET := $(shell basename $(CURDIR))
BUILD := build
SOURCES := source source/fatfs
DATA := data
INCLUDES := include source
INCLUDES := source
#---------------------------------------------------------------------------------
# Setup some defines

View File

@ -11,7 +11,6 @@
void ioDelay(u32 us);
extern u8* bottomScreen;
int CartInited=0;
int CartID = -1;
u32 CartType = 0;
int A0_Response = -1;
@ -20,7 +19,10 @@ u32 rand1 = 0;
u32 rand2 = 0;
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?
@ -297,7 +299,11 @@ int Cart_IsInserted()
void Cart_ReadSectorSD(u8* aBuffer,u32 aSector)
{
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 );
}
@ -308,9 +314,6 @@ u32 Cart_GetID()
void Cart_Init()
{
//Skip init if its already been done
//if(CartInited) return;
GatewayCartInit(); //Seems to reset the cart slot?
REG_CTRCARDSECCNT &= 0xFFFFFFFB;
@ -349,34 +352,15 @@ void Cart_Init()
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 )
{
u32 read_cmd[4] = { (0xBF000000 | (u32)(sector>>23)), (u32)((sector<<9) & 0xFFFFFFFF), 0x00000000, 0x00000000 };
u32 read_cmd[4] = {
(0xBF000000 | (u32)(sector>>23)),
(u32)((sector<<9) & 0xFFFFFFFF),
0x00000000, 0x00000000
};
CTR_SendCommand(read_cmd, length, blocks, 0x100822C, buffer);
}

View File

@ -67,8 +67,6 @@ int main() {
Debug("Successfully f_mounted");
Debug("cleared stuff! Initializing game card...", 1, 1, 0xFF);
// ROM DUMPING CODE STARTS HERE
Cart_Init();
@ -82,18 +80,6 @@ int main() {
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
/* 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];
Cart_Secure_Init((u32*)header,sec_keys);
@ -111,13 +97,14 @@ int main() {
wait_key();
Debug("File name: \"%s\"", String2);
unsigned flags = FA_READ | FA_WRITE | FA_CREATE_ALWAYS;
ret = (f_open(&file, String2, flags) == FR_OK);
if (!ret) {
if (f_open(&file, String2, flags) != FR_OK) {
Debug("Failed to create file...");
wait_key();
return 0;
}
f_lseek(&file, 0);
f_sync(&file);
Debug("Successfully created file");
@ -131,20 +118,18 @@ int main() {
wait_key();
u32 cartSize = (*((u32*)&target[0x104]));
u32 cartSize = *(u32*)(&target[0x104]);
Debug("Cart size: %d MB", cartSize * 0x200 / 1024/1024);
wait_key();
// Dump remaining data
for(u32 adr=0x20; adr<cartSize; adr+=ramCache)
{
for(u32 adr=0x20; adr<cartSize; adr+=ramCache) {
ClearTop();
Debug("Wrote 0x%x bytes, e.g. %08x",bytes_written, *(u32*)target);
u32 dumped = cartSize - adr;
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 percent = ((currentSector*100)/cartSize);
if ((adr2 % (blocks*3)) == blocks*2)