Rename Cart.cpp/h to gamecart.c/h, actually use its header file

This commit is contained in:
archshift 2015-05-09 23:42:30 -07:00
parent c4959d20a5
commit 2c131f4c63
4 changed files with 40 additions and 46 deletions

View File

@ -1,12 +0,0 @@
#pragma once
#include "types.h"
void Cart_Init();
int Cart_IsInserted();
void Cart_ReadSectorSD(uint8_t* aBuffer,uint32_t aSector);
u32 SendReadCommand( uint32_t adr, uint32_t length, uint32_t blocks, void * buffer );
u32 GetHeader( void * buffer );
u32 CTR_SendCommand( uint32_t command[4], uint32_t pageSize, uint32_t blocks, uint32_t latency, void * buffer );
int Cart_Nin_Init();
uint32_t Cart_GetID();
// void Cart_Secure_Init(uint32_t *buf,uint32_t *out);

12
include/gamecart.h Normal file
View File

@ -0,0 +1,12 @@
#pragma once
#include "common.h"
void Cart_Init();
int Cart_IsInserted();
void Cart_ReadSectorSD(u8* aBuffer, u32 aSector);
u32 SendReadCommand(u32 adr, u32 length, u32 blocks, void * buffer);
u32 GetHeader(void* buffer);
u32 CTR_SendCommand(u32 command[4], u32 pageSize, u32 blocks, u32 latency, void* buffer);
int Cart_Nin_Init();
u32 Cart_GetID();
void Cart_Secure_Init(u32* buf, u32* out);

View File

@ -8,7 +8,7 @@
//#include "DrawCharacter.h" //#include "DrawCharacter.h"
#include "misc.h" #include "misc.h"
extern "C" void ioDelay( u32 us ); void ioDelay( u32 us );
extern u8* bottomScreen; extern u8* bottomScreen;
int CartInited=0; int CartInited=0;
@ -163,7 +163,7 @@ void NTR_SendCommand( u32 command[2], u32 pageSize, u32 latency, void * buffer )
//lastCmd[0] = command[0];lastCmd[1] = command[1]; //lastCmd[0] = command[0];lastCmd[1] = command[1];
} }
extern "C" void CTR_SendCommand( u32 command[4], u32 pageSize, u32 blocks, u32 latency, void * buffer ) void CTR_SendCommand( u32 command[4], u32 pageSize, u32 blocks, u32 latency, void * buffer )
{ {
REG_CTRCARDCMD[0] = command[3]; REG_CTRCARDCMD[0] = command[3];
REG_CTRCARDCMD[1] = command[2]; REG_CTRCARDCMD[1] = command[2];
@ -301,12 +301,12 @@ void Cart_ReadSectorSD(u8* aBuffer,u32 aSector)
CTR_SendCommand( readheader_cmd, 0x200, 1, 0x100802C, aBuffer ); CTR_SendCommand( readheader_cmd, 0x200, 1, 0x100802C, aBuffer );
} }
extern "C" u32 Cart_GetID() u32 Cart_GetID()
{ {
return CartID; return CartID;
} }
extern "C" void Cart_Init() void Cart_Init()
{ {
//Skip init if its already been done //Skip init if its already been done
//if(CartInited) return; //if(CartInited) return;
@ -374,13 +374,13 @@ extern "C" void Cart_Init()
CartInited = 1; CartInited = 1;
} }
extern "C" 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] = { (0xBF000000 | (u32)(sector>>23)), (u32)((sector<<9) & 0xFFFFFFFF), 0x00000000, 0x00000000 };
CTR_SendCommand( read_cmd, length, blocks, 0x100822C, buffer ); CTR_SendCommand( read_cmd, length, blocks, 0x100822C, buffer );
} }
extern "C" 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 );
@ -438,9 +438,11 @@ void ctr_set_sec_seed(u32 *seed, bool flag) {
} }
} }
extern "C" void AES_SetKeyControl(u32 a); void AES_SetKeyControl(u32 a) {
*((volatile u8*)0x10009011) = a | 0x80;
}
extern "C" void Cart_Secure_Init(u32 *buf,u32 *out) void Cart_Secure_Init(u32 *buf,u32 *out)
{ {
AES_SetKeyControl(0x3B); AES_SetKeyControl(0x3B);

View File

@ -6,6 +6,7 @@
#include "framebuffer.h" #include "framebuffer.h"
#include "hid.h" #include "hid.h"
#include "fatfs/ff.h" #include "fatfs/ff.h"
#include "gamecart.h"
extern s32 CartID; extern s32 CartID;
extern s32 CartID2; extern s32 CartID2;
@ -26,22 +27,13 @@ void wait_key() {
InputWait(); InputWait();
} }
void AES_SetKeyControl(u32 a) {
*((volatile u8*)0x10009011) = a | 0x80;
}
void print_status(u8 *Str, u32 x, u32 y, u8 color)
{
Debug(Str);
}
int main() { int main() {
// Setup boring stuff - clear the screen, initialize SD output, etc... // Setup boring stuff - clear the screen, initialize SD output, etc...
ClearTop(); ClearTop();
Debug(""); Debug("");
Debug("Hello world from ARM9!"); Debug("Hello world from ARM9!");
print_status("ROM dump tool v0.2", 1, 1, 0xFF); Debug("ROM dump tool v0.2", 1, 1, 0xFF);
wait_key(); wait_key();
u8 file_path[38]; u8 file_path[38];
@ -59,7 +51,7 @@ int main() {
volatile u8* header = (vu8*)0x23000000; volatile u8* header = (vu8*)0x23000000;
u32 *ptr = (u32*)(target + 0x0100); u32 *ptr = (u32*)(target + 0x0100);
print_status("ROM dump tool v0.2", 1, 1, 0xFF); Debug("ROM dump tool v0.2", 1, 1, 0xFF);
memset((u8*)target, 0x00, 0x100000); // Clear our 1 MB buffer memset((u8*)target, 0x00, 0x100000); // Clear our 1 MB buffer
// clear_screens(0x00); // clear_screens(0x00);
@ -73,7 +65,7 @@ int main() {
return 0; return 0;
} }
Debug("Successfully f_mounted"); Debug("Successfully f_mounted");
print_status("cleared stuff! Initializing game card...", 1, 1, 0xFF); Debug("cleared stuff! Initializing game card...", 1, 1, 0xFF);
@ -84,7 +76,7 @@ int main() {
Debug("Done! Cart id is %08x, press A...", (u32)Cart_GetID()); Debug("Done! Cart id is %08x, press A...", (u32)Cart_GetID());
while((*((vu16*)0x10146000) & 1)); // Wait for button A while((*((vu16*)0x10146000) & 1)); // Wait for button A
print_status("Done waiting :)...", 1, 1, 0xFF); Debug("Done waiting :)...", 1, 1, 0xFF);
GetHeader(header); GetHeader(header);
Debug("Done reading header: %08x :)...", *(u32*)&header[0x100]); Debug("Done reading header: %08x :)...", *(u32*)&header[0x100]);
@ -97,19 +89,19 @@ int main() {
wait_key(); wait_key();
return 0; return 0;
} }
print_status("Done checking NCSD magic:)...", 1, 1, 0xFF); Debug("Done checking NCSD magic:)...", 1, 1, 0xFF);
*/ */
uint32_t sec_keys[4]; u32 sec_keys[4];
Cart_Secure_Init((u32*)header,sec_keys); Cart_Secure_Init((u32*)header,sec_keys);
uint32_t mediaUnit = 0x200; u32 mediaUnit = 0x200;
uint32_t ramCache = 0xC000; //24MB/s - 0x1000000 u32 ramCache = 0xC000; //24MB/s - 0x1000000
uint32_t dumpSize = 0x100000; //1MB u32 dumpSize = 0x100000; //1MB
uint32_t blocks = dumpSize / mediaUnit; //1MB of blocks u32 blocks = dumpSize / mediaUnit; //1MB of blocks
// Read out the header 0x0000-0x1000 // Read out the header 0x0000-0x1000
SendReadCommand( 0, mediaUnit, 8, (void*)(target) ); SendReadCommand( 0, mediaUnit, 8, (void*)(target) );
@ -132,29 +124,29 @@ int main() {
wait_key(); wait_key();
// Write header to file // Write header to file
uint32_t written = 0; u32 written = 0;
f_write(&file, target, 0x4000, &written); f_write(&file, target, 0x4000, &written);
f_sync(&file); f_sync(&file);
Debug("Wrote header"); Debug("Wrote header");
wait_key(); wait_key();
uint32_t cartSize = (*((uint32_t*)&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(uint32_t 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);
uint32_t dumped = cartSize - adr; u32 dumped = cartSize - adr;
if(dumped > ramCache) dumped = ramCache; if(dumped > ramCache) dumped = ramCache;
for(uint32_t adr2=0; (adr2 < dumped); adr2+=blocks) for(u32 adr2=0; (adr2 < dumped); adr2+=blocks)
{ {
uint32_t currentSector = (adr+adr2); u32 currentSector = (adr+adr2);
uint32_t 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);