converted more functions
This commit is contained in:
parent
5442139ff4
commit
a66f2b12f5
127
src/main.c
127
src/main.c
@ -1433,17 +1433,17 @@ int backupSaveData(display_context_t disp)
|
||||
{
|
||||
//backup cart-save on sd after reboot
|
||||
u8 config_file_path[32];
|
||||
int save_format;
|
||||
|
||||
sprintf(config_file_path, "/ED64/%s/LAST.CRT", save_path);
|
||||
uint8_t cfg_data[512]; //TODO: this should be a strut
|
||||
|
||||
int save_format;
|
||||
uint8_t cfg_data[512]; //TODO: this should be a strut?
|
||||
|
||||
FatRecord rec_tmpf;
|
||||
|
||||
printText("Saving last game session...", 3, 4, disp);
|
||||
|
||||
if (fatFindRecord(config_file_path, &rec_tmpf, 0) == 0) //file exists?
|
||||
{
|
||||
printText("updating last played game record...", 3, 4, disp);
|
||||
|
||||
//file to cfg_data buffer
|
||||
u8 resp = 0;
|
||||
fatOpenFileByName(config_file_path, 0);
|
||||
@ -1460,8 +1460,6 @@ int backupSaveData(display_context_t disp)
|
||||
//set savetype to off
|
||||
cfg_data[0] = 0;
|
||||
|
||||
u8 tmp[32];
|
||||
|
||||
resp = fatOpenFileByName(config_file_path, 1); //if sector is set filemode=WR writeable
|
||||
|
||||
TRACEF(disp, "FAT_OpenFileByName returned: %i", resp);
|
||||
@ -1509,7 +1507,7 @@ int backupSaveData(display_context_t disp)
|
||||
//reset with save request
|
||||
if (save_after_reboot)
|
||||
{
|
||||
printText("Copying RAM to SD card...", 3, -1, disp);
|
||||
printText("Copying save RAM to SD card...", 3, -1, disp);
|
||||
if (saveTypeToSd(disp, rom_filename, save_format))
|
||||
{
|
||||
printText("Operation completed sucessfully...", 3, -1, disp);
|
||||
@ -1522,7 +1520,7 @@ int backupSaveData(display_context_t disp)
|
||||
else
|
||||
{
|
||||
TRACE(disp, "no reset - save request");
|
||||
printText("...ready", 3, -1, disp);
|
||||
printText("...done", 3, -1, disp);
|
||||
|
||||
sleep(300);
|
||||
}
|
||||
@ -1531,47 +1529,41 @@ int backupSaveData(display_context_t disp)
|
||||
}
|
||||
|
||||
//before boot_simulation
|
||||
//writes a cart-save from a file to the fpga/cart
|
||||
//write a cart-save from a file to the fpga/cart
|
||||
int saveTypeFromSd(display_context_t disp, char *rom_name, int stype)
|
||||
{
|
||||
rom_load_y();
|
||||
|
||||
u8 tmp[32];
|
||||
u8 fname[128];
|
||||
u8 found = 0;
|
||||
|
||||
int size;
|
||||
size = saveTypeToSize(stype); // int byte
|
||||
|
||||
sprintf(fname, "/ED64/%s/%s.%s", save_path, rom_name, saveTypeToExtension(stype, ext_type));
|
||||
|
||||
int size = saveTypeToSize(stype); // int byte
|
||||
uint8_t cartsave_data[size];
|
||||
|
||||
//if (debug) {
|
||||
TRACE(disp, fname);
|
||||
//sleep(2000);
|
||||
//}
|
||||
FRESULT result;
|
||||
FIL file;
|
||||
UINT bytesread;
|
||||
result = f_open(&file, fname, FA_READ);
|
||||
|
||||
FatRecord rec_tmpf;
|
||||
found = fatFindRecord(fname, &rec_tmpf, 0);
|
||||
|
||||
TRACEF(disp, "fatFindRecord returned: %i", found);
|
||||
|
||||
if (found == 0)
|
||||
if (result == FR_OK)
|
||||
{
|
||||
u8 resp = 0;
|
||||
resp = fatOpenFileByName(fname, 0);
|
||||
int fsize = f_size(&file);
|
||||
|
||||
TRACEF(disp, "fatOpenFileByName returned: %i", resp);
|
||||
result =
|
||||
f_read (
|
||||
&file, /* [IN] File object */
|
||||
&cartsave_data, /* [OUT] Buffer to store read data */
|
||||
size, /* [IN] Number of bytes to read */
|
||||
&bytesread /* [OUT] Number of bytes read */
|
||||
);
|
||||
|
||||
resp = fatReadFile(cartsave_data, size / 512);
|
||||
|
||||
TRACEF(disp, "fatReadFile returned: %i", resp);
|
||||
result = f_close(&file);
|
||||
}
|
||||
else
|
||||
{
|
||||
printText("no savegame found", 3, -1, disp);
|
||||
//todo clear memory area
|
||||
printText("no save found", 3, -1, disp);
|
||||
sleep(1000);
|
||||
//todo: clear memory area
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -1580,13 +1572,11 @@ int saveTypeFromSd(display_context_t disp, char *rom_name, int stype)
|
||||
{
|
||||
if (pushSaveToCart(stype, cartsave_data))
|
||||
{
|
||||
|
||||
printText("save upload done...", 3, -1, disp);
|
||||
printText("transferred save data...", 3, -1, disp);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
printText("pushSaveToCart error", 3, -1, disp);
|
||||
printText("error transfering save data", 3, -1, disp);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1663,27 +1653,32 @@ int saveTypeToSd(display_context_t disp, char *rom_name, int stype)
|
||||
}
|
||||
|
||||
//check out the userfriendly ini file for config-information
|
||||
|
||||
int readConfigFile(void)
|
||||
{
|
||||
//var file readin
|
||||
u8 tmp[32];
|
||||
u8 filename[32];
|
||||
u8 ok = 0;
|
||||
|
||||
//config filename
|
||||
sprintf(filename, "/ED64/ALT64.INI");
|
||||
FatRecord rec_tmpf;
|
||||
ok = fatFindRecord(filename, &rec_tmpf, 0);
|
||||
|
||||
u8 resp = 0;
|
||||
resp = fatOpenFileByName(filename, 0);
|
||||
FRESULT result;
|
||||
FIL file;
|
||||
UINT bytesread;
|
||||
result = f_open(&file, filename, FA_READ);
|
||||
|
||||
if (result == FR_OK)
|
||||
{
|
||||
int fsize = f_size(&file);
|
||||
|
||||
//filesize of the opend file -> is the readfile / 512
|
||||
int fsize = file.sec_available * 512;
|
||||
char config_rawdata[fsize];
|
||||
|
||||
resp = fatReadFile(&config_rawdata, fsize / 512); //1 cluster
|
||||
result =
|
||||
f_read (
|
||||
&file, /* [IN] File object */
|
||||
&config_rawdata, /* [OUT] Buffer to store read data */
|
||||
fsize, /* [IN] Number of bytes to read */
|
||||
&bytesread /* [OUT] Number of bytes read */
|
||||
);
|
||||
|
||||
result = f_close(&file);
|
||||
|
||||
configuration config;
|
||||
|
||||
if (ini_parse_str(config_rawdata, configHandler, &config) < 0)
|
||||
@ -1718,6 +1713,7 @@ int readConfigFile(void)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int str2int(char data)
|
||||
{
|
||||
@ -3283,23 +3279,33 @@ void handleInput(display_context_t disp, sprite_t *contr)
|
||||
//quick boot
|
||||
if (quick_boot)
|
||||
{
|
||||
FatRecord rec_last;
|
||||
uint8_t lastrom_cfg_data[512];
|
||||
|
||||
if (fatFindRecord("/ED64/LASTROM.CFG", &rec_last, 0) == 0)
|
||||
{
|
||||
u8 resp = 0;
|
||||
resp = fatOpenFileByName("/ED64/LASTROM.CFG", 0);
|
||||
resp = fatReadFile(&lastrom_cfg_data, 1);
|
||||
FRESULT result;
|
||||
FIL file;
|
||||
UINT bytesread;
|
||||
result = f_open(&file, "/ED64/LASTROM.CFG", FA_READ);
|
||||
|
||||
u8 *short_s;
|
||||
short_s = strrchr(lastrom_cfg_data, '/');
|
||||
if (result == FR_OK)
|
||||
{
|
||||
int fsize = f_size(&file);
|
||||
|
||||
result =
|
||||
f_read (
|
||||
&file, /* [IN] File object */
|
||||
&lastrom_cfg_data, /* [OUT] Buffer to store read data */
|
||||
fsize, /* [IN] Number of bytes to read */
|
||||
&bytesread /* [OUT] Number of bytes read */
|
||||
);
|
||||
|
||||
result = f_close(&file);
|
||||
|
||||
u8 *short_s = strrchr(lastrom_cfg_data, '/');
|
||||
|
||||
while (!(disp = display_lock()))
|
||||
;
|
||||
clearScreen(disp);
|
||||
|
||||
sleep(100);
|
||||
evd_ulockRegs();
|
||||
sleep(100);
|
||||
|
||||
@ -3310,7 +3316,6 @@ void handleInput(display_context_t disp, sprite_t *contr)
|
||||
loadrom(disp, lastrom_cfg_data, 1);
|
||||
display_show(disp);
|
||||
}
|
||||
//nothing else :>
|
||||
|
||||
drawShortInfoBox(disp, " rom not found", 0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user