loadrom now using fatfs
fixes issues loading roms #14 #18 fixes loading fragmented files
This commit is contained in:
parent
756fbc15ce
commit
8045aea0e0
196
src/main.c
196
src/main.c
@ -1301,58 +1301,46 @@ void loadrom(display_context_t disp, u8 *buff, int fast)
|
|||||||
clearScreen(disp);
|
clearScreen(disp);
|
||||||
display_show(disp);
|
display_show(disp);
|
||||||
|
|
||||||
if (!fast)
|
printText("Loading ROM, Please wait:", 3, 4, disp);
|
||||||
printText("Restoring:", 3, 4, disp);
|
|
||||||
|
|
||||||
//sleep(1000); //needless waiting :>
|
|
||||||
|
|
||||||
TRACE(disp, "timing done");
|
TRACE(disp, "timing done");
|
||||||
|
|
||||||
u8 tmp[32];
|
|
||||||
u8 filename[64];
|
u8 filename[64];
|
||||||
u8 ok = 0;
|
|
||||||
|
|
||||||
sprintf(filename, "%s", buff);
|
sprintf(filename, "%s", buff);
|
||||||
|
|
||||||
|
FRESULT result;
|
||||||
|
FIL file;
|
||||||
|
UINT bytesread = 0;
|
||||||
|
result = f_open(&file, filename, FA_READ);
|
||||||
|
|
||||||
|
if (result == FR_OK)
|
||||||
|
{
|
||||||
int swapped = 0;
|
int swapped = 0;
|
||||||
|
int headerfsize = 512; //rom-headersize 4096 but the bootcode is not needed
|
||||||
|
unsigned char headerdata[headerfsize]; //1*512
|
||||||
|
int fsize = f_size(&file);
|
||||||
|
int fsizeMB = fsize /1048576; //Bytes in a MB
|
||||||
|
|
||||||
TRACE(disp, buff);
|
result =
|
||||||
|
f_read (
|
||||||
|
&file, /* [IN] File object */
|
||||||
|
&headerdata, /* [OUT] Buffer to store read data */
|
||||||
|
headerfsize, /* [IN] Number of bytes to read */
|
||||||
|
&bytesread /* [OUT] Number of bytes read */
|
||||||
|
);
|
||||||
|
|
||||||
FatRecord rec_tmpf;
|
result = f_close(&file);
|
||||||
//not needed any longer :>
|
|
||||||
//file IS there, it's selected at this point
|
|
||||||
ok = fatFindRecord(filename, &rec_tmpf, 0);
|
|
||||||
|
|
||||||
TRACE(disp, "found");
|
|
||||||
|
|
||||||
u8 resp = 0;
|
|
||||||
|
|
||||||
resp = fatOpenFileByName(filename, 0); //err if not found ^^
|
|
||||||
|
|
||||||
TRACE(disp, "opened");
|
|
||||||
|
|
||||||
int mb = file.sec_available / 2048;
|
|
||||||
int file_sectors = file.sec_available;
|
|
||||||
int block_offset = 0;
|
|
||||||
u32 cart_buff_offset = 0;
|
|
||||||
u32 begin_sector = file.sector;
|
|
||||||
|
|
||||||
//filesize -> readfile / 512
|
|
||||||
int fsize = 512; //rom-headersize 4096 but the bootcode is not needed
|
|
||||||
unsigned char headerdata[fsize]; //1*512
|
|
||||||
|
|
||||||
resp = fatReadFile(&headerdata, fsize / 512); //1 cluster
|
|
||||||
|
|
||||||
int sw_type = is_valid_rom(headerdata);
|
int sw_type = is_valid_rom(headerdata);
|
||||||
|
|
||||||
if (sw_type != 0)
|
if (sw_type != 0)
|
||||||
{
|
{
|
||||||
if (!fast)
|
|
||||||
printText("byteswapped file", 3, -1, disp);
|
|
||||||
|
|
||||||
swapped = 1;
|
swapped = 1;
|
||||||
swap_header(headerdata, 512);
|
swap_header(headerdata, 512);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fast != 1)
|
||||||
|
{
|
||||||
//char 32-51 name
|
//char 32-51 name
|
||||||
unsigned char rom_name[32];
|
unsigned char rom_name[32];
|
||||||
|
|
||||||
@ -1363,16 +1351,21 @@ void loadrom(display_context_t disp, u8 *buff, int fast)
|
|||||||
else
|
else
|
||||||
sprintf(rom_name, "%c", headerdata[32 + u]);
|
sprintf(rom_name, "%c", headerdata[32 + u]);
|
||||||
}
|
}
|
||||||
//trim right spaces
|
|
||||||
//romname=trimmed rom name for filename
|
|
||||||
sprintf(rom_name, "%s", trim(rom_name));
|
|
||||||
|
|
||||||
if (!fast)
|
//rom name
|
||||||
|
sprintf(rom_name, "%s", trim(rom_name));
|
||||||
printText(rom_name, 3, -1, disp);
|
printText(rom_name, 3, -1, disp);
|
||||||
|
|
||||||
//unique cart id for gametype
|
//rom size
|
||||||
|
sprintf(rom_name, "Size: %iMB", fsizeMB);
|
||||||
|
printText(rom_name, 3, -1, disp);
|
||||||
|
|
||||||
sprintf(cartID, "%c%c%c%c", headerdata[0x3B], headerdata[0x3C], headerdata[0x3D], headerdata[0x3E]);
|
|
||||||
|
//unique cart id for gametype
|
||||||
|
unsigned char cartID_str[12];
|
||||||
|
sprintf(cartID_str, "ID: %c%c%c%c", headerdata[0x3B], headerdata[0x3C], headerdata[0x3D], headerdata[0x3E]);
|
||||||
|
printText(cartID_str, 3, -1, disp);
|
||||||
|
}
|
||||||
|
|
||||||
int cic, save;
|
int cic, save;
|
||||||
|
|
||||||
@ -1383,13 +1376,33 @@ void loadrom(display_context_t disp, u8 *buff, int fast)
|
|||||||
|
|
||||||
if (get_cic_save(cartID_short, &cic, &save))
|
if (get_cic_save(cartID_short, &cic, &save))
|
||||||
{
|
{
|
||||||
if (!fast)
|
if (fast != 1)
|
||||||
|
{
|
||||||
printText("found in db", 3, -1, disp);
|
printText("found in db", 3, -1, disp);
|
||||||
//thanks for the db :>
|
unsigned char save_type_str[12];
|
||||||
// cart was found, use CIC and SaveRAM type
|
sprintf(save_type_str, "Save: %s", saveTypeToExtension(save, ext_type));
|
||||||
|
printText(save_type_str, 3, -1, disp);
|
||||||
|
|
||||||
|
unsigned char cic_type_str[12];
|
||||||
|
|
||||||
|
switch (cic)
|
||||||
|
{
|
||||||
|
case 4:
|
||||||
|
sprintf(cic_type_str, "CIC: CIC-5101", cic);
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
sprintf(cic_type_str, "CIC: CIC-5167", cic);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
sprintf(cic_type_str, "CIC: CIC-610%i", cic);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
TRACEF(disp, "Info: cic=%i save=%i", cic, save);
|
printText(cic_type_str, 3, -1, disp);
|
||||||
|
}
|
||||||
|
//thanks for the db :>
|
||||||
|
//cart was found, use CIC and SaveRAM type
|
||||||
|
}
|
||||||
|
|
||||||
//new rom_config
|
//new rom_config
|
||||||
boot_cic = rom_config[1] + 1;
|
boot_cic = rom_config[1] + 1;
|
||||||
@ -1402,73 +1415,74 @@ void loadrom(display_context_t disp, u8 *buff, int fast)
|
|||||||
if (gbload == 1)
|
if (gbload == 1)
|
||||||
boot_save = 1;
|
boot_save = 1;
|
||||||
|
|
||||||
else if (resp) //TODO: if response is certain ones we should show the error and stop the boot...
|
// TRACE(disp, "Checking SD mode");
|
||||||
{
|
|
||||||
sprintf(tmp, "Response: %i", resp);
|
|
||||||
printText(tmp, 3, -1, disp);
|
|
||||||
sleep(2000);
|
|
||||||
}
|
|
||||||
|
|
||||||
TRACE(disp, "Checking SD mode");
|
// int resp = evd_isSDMode();
|
||||||
|
|
||||||
resp = evd_isSDMode();
|
// TRACEF(disp, "SD mode: %i", resp);
|
||||||
|
// TRACE(disp, "Loading:");
|
||||||
TRACEF(disp, "SD mode: %i", resp);
|
|
||||||
TRACEF(disp, "Size: %i", file.sec_available);
|
|
||||||
TRACEF(disp, "File sector: %i", file.sector);
|
|
||||||
TRACE(disp, "Loading:");
|
|
||||||
|
|
||||||
sleep(10);
|
|
||||||
|
|
||||||
if (swapped == 1)
|
if (swapped == 1)
|
||||||
{
|
{
|
||||||
while (evd_isDmaBusy())
|
while (evd_isDmaBusy())
|
||||||
;
|
;
|
||||||
sleep(400);
|
sleep(400); //Is this necessary?
|
||||||
evd_mmcSetDmaSwap(1);
|
evd_mmcSetDmaSwap(1);
|
||||||
|
|
||||||
TRACE(disp, "swapping on");
|
TRACE(disp, "swapping on");
|
||||||
|
|
||||||
sleep(10);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fast)
|
bytesread = 0;
|
||||||
printText("loading please wait...", 3, -1, disp);
|
result = f_open(&file, filename, FA_READ);
|
||||||
else
|
if (fsizeMB <= 32)
|
||||||
printText("loading please wait...", 3, 4, disp);
|
|
||||||
|
|
||||||
sleep(10);
|
|
||||||
|
|
||||||
int lower_half = 2048 * 32;
|
|
||||||
|
|
||||||
if (mb <= 32)
|
|
||||||
{
|
{
|
||||||
resp = sdRead(begin_sector, (void *)0xb0000000, file_sectors); //2048 cluster 1Mb
|
result =
|
||||||
|
f_read (
|
||||||
|
&file, /* [IN] File object */
|
||||||
|
(void *)0xb0000000, /* [OUT] Buffer to store read data */
|
||||||
|
fsize, /* [IN] Number of bytes to read */
|
||||||
|
&bytesread /* [OUT] Number of bytes read */
|
||||||
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
resp = sdRead(begin_sector, (void *)0xb0000000, lower_half);
|
result =
|
||||||
resp = sdRead(begin_sector + lower_half, (void *)0xb2000000, file_sectors - lower_half);
|
f_read (
|
||||||
}
|
&file, /* [IN] File object */
|
||||||
|
(void *)0xb0000000, /* [OUT] Buffer to store read data */
|
||||||
if (resp)
|
32 * 1048576, /* [IN] Number of bytes to read */
|
||||||
|
&bytesread /* [OUT] Number of bytes read */
|
||||||
|
);
|
||||||
|
if(result == FR_OK)
|
||||||
{
|
{
|
||||||
TRACEF(disp, "mmcToCart: %i", resp);
|
result =
|
||||||
|
f_read (
|
||||||
|
&file, /* [IN] File object */
|
||||||
|
(void *)0xb2000000, /* [OUT] Buffer to store read data */
|
||||||
|
fsize - bytesread, /* [IN] Number of bytes to read */
|
||||||
|
&bytesread /* [OUT] Number of bytes read */
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(result == FR_OK)
|
||||||
|
{
|
||||||
|
printText("Rom loaded", 3, -1, disp);
|
||||||
//if (debug) {
|
//if (debug) {
|
||||||
for (int i = 0; i < 4; i++)
|
// for (int i = 0; i < 4; i++)
|
||||||
{
|
// {
|
||||||
u8 buff[16];
|
// u8 buff[16];
|
||||||
dma_read_s(buff, 0xb0000000 + 0x00100000 * i, 1);
|
// dma_read_s(buff, 0xb0000000 + 0x00100000 * i, 1);
|
||||||
TRACEF(disp, "probe: %hhx", buff[0]);
|
|
||||||
}
|
// unsigned char probe_str[12];
|
||||||
|
// TRACEF(disp, "probe: %hhx", buff[0]);
|
||||||
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
// sleep(1000);
|
||||||
|
|
||||||
if (!fast)
|
if (!fast)
|
||||||
{
|
{
|
||||||
sleep(200);
|
|
||||||
|
|
||||||
printText(" ", 3, -1, disp);
|
printText(" ", 3, -1, disp);
|
||||||
printText("(C-UP to activate cheats)", 3, -1, disp);
|
printText("(C-UP to activate cheats)", 3, -1, disp);
|
||||||
printText("(C-RIGHT to force menu tv mode)", 3, -1, disp);
|
printText("(C-RIGHT to force menu tv mode)", 3, -1, disp);
|
||||||
@ -1478,6 +1492,12 @@ void loadrom(display_context_t disp, u8 *buff, int fast)
|
|||||||
{
|
{
|
||||||
bootRom(disp, 1);
|
bootRom(disp, 1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printText("file open error", 3, -1, disp);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int backupSaveData(display_context_t disp)
|
int backupSaveData(display_context_t disp)
|
||||||
|
Loading…
Reference in New Issue
Block a user