From 67fc6d0aa8fded0f668f8424babdd1416e259efd Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Thu, 1 Sep 2016 00:09:17 +0100 Subject: [PATCH 1/4] Only load firmware when required --- menu.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/menu.c b/menu.c index 4d29bc5a..d32b3bbf 100644 --- a/menu.c +++ b/menu.c @@ -797,8 +797,13 @@ void configure() { if (!(msg & (1 << 14))) { msg |= 1 << 14; evd_writeReg(REG_MAX_MSG, msg); - - bi_load_firmware(firmware); + if (firm == 0x0214) { + int fpf = dfs_open("/firmware.bin"); + firmware = malloc( dfs_size( fpf ) ); + dfs_read( firmware, 1, dfs_size( fpf ), fpf ); + dfs_close( fpf ); + bi_load_firmware(firmware); + } sleep(1); evd_init(); @@ -3012,11 +3017,6 @@ int main(void) { printf("Filesystem failed to start!\n"); } else { - int fpf = dfs_open("/firmware.bin"); - firmware = malloc( dfs_size( fpf ) ); - dfs_read( firmware, 1, dfs_size( fpf ), fpf ); - dfs_close( fpf ); - // everdrive initial function configure(); From 4f67057a1a21f8547097d6f4e0f8c0a2826004bc Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Fri, 2 Sep 2016 14:56:06 +0100 Subject: [PATCH 2/4] minor refactoring of backupSaveData to make it more understandable. (still a lot todo) --- fat.c | 2 +- menu.c | 56 ++++++++++++++++++++++++++++---------------------------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/fat.c b/fat.c index d01ee1ca..92e65cf6 100644 --- a/fat.c +++ b/fat.c @@ -658,7 +658,7 @@ u8 fatGetNextCluster(u32 *cluster) { } -u8 fatOpenFileByeName(u8 *name, u32 wr_sectors) { +u8 fatOpenFileByeName(u8 *name, u32 wr_sectors) { //TODO: spelling mistake //u16 i; u8 resp; diff --git a/menu.c b/menu.c index d32b3bbf..290575ee 100644 --- a/menu.c +++ b/menu.c @@ -1347,65 +1347,64 @@ void loadrom(display_context_t disp, u8 *buff, int fast){ int backupSaveData(display_context_t disp){ //backup cart-save on sd after reboot - u8 fname[32]; - u8 found=0; - int save_t; + u8 config_file_path[32]; + int save_format; - sprintf(fname, "/ED64/%s/LAST.CRT",save_path); - uint8_t cfg_data[512]; + sprintf(config_file_path, "/ED64/%s/LAST.CRT",save_path); + uint8_t cfg_data[512]; //TODO: this should be a strut FatRecord rec_tmpf; - found = fatFindRecord(fname, &rec_tmpf, 0); + u8 file_found = fatFindRecord(config_file_path, &rec_tmpf, 0); //TODO: why does fatFindRecord return 0 for true?! - printText("Save System - please stand by", 3, 4, disp); + printText("Saving Last Played Game State - please wait...", 3, 4, disp); - if(found==0){ + if(file_found==0){ //TODO: fatFindRecord could be moved into the if statement. //found //file to cfg_data buffer u8 resp = 0; - resp = fatOpenFileByeName(fname, 0); - resp = fatReadFile(&cfg_data, 1); + resp = fatOpenFileByeName(config_file_path, 0); //TODO: not sure why we bother setting a response here as it is not used for anything?! + resp = fatReadFile(&cfg_data, 1); //TODO: not sure why we bother setting a response here as it is not used for anything?! //split in save type and cart-id - save_t=cfg_data[0]; + save_format=cfg_data[0]; int last_cic=cfg_data[1]; - scopy(cfg_data+2, rom_filename); + scopy(cfg_data+2, rom_filename); //string copy //set savetype to 0 disable for next boot - if(save_t!=0){ + if(save_format!=0){ //set savetype to off cfg_data[0]=0; u8 tmp[32]; - resp = fatOpenFileByeName(fname, 1); //if sector is set filemode=WR writeable + resp = fatOpenFileByeName(config_file_path, 1); //if sector is set filemode=WR writeable if (debug) { - sprintf(tmp, "fatOpenFileByeName ret=%i",resp); + sprintf(tmp, "FAT_OpenFileByName returned: %i",resp); printText(tmp, 3, -1, disp); } resp = fatWriteFile(&cfg_data, 1); //filemode must be wr if (debug) { - sprintf(tmp, "fatWriteFile ret=%i",resp); + printText("Disabling save for subsequent system reboots", 3, -1, disp); + sprintf(tmp, "FAT_WriteFile returned: %i",resp); printText(tmp, 3, -1, disp); - printText("SaveType-tag has been disabled for next boot", 3, -1, disp); } - volatile u8 save_cfg_stat=0; - volatile u8 val=0; + volatile u8 save_config_state=0; + volatile u8 val=0; //TODO: not sure why we are bothering with the reg response as it is never used. val = evd_readReg(0); - save_cfg_stat = evd_readReg(REG_SAV_CFG); + save_config_state = evd_readReg(REG_SAV_CFG); - if(save_cfg_stat!=0) + if(save_config_state!=0) save_reboot=1; } else { if (debug) - printText("no need to save to sd", 3, -1, disp); + printText("Save not required.", 3, -1, disp); else printText("...ready", 3, -1, disp); @@ -1416,7 +1415,7 @@ int backupSaveData(display_context_t disp){ } else{ if (debug) - printText("last.crt not found", 3, -1, disp); + printText("No previous ROM loaded - the file 'last.crt' was not found!", 3, -1, disp); else printText("...ready", 3, -1, disp); @@ -1429,15 +1428,15 @@ int backupSaveData(display_context_t disp){ //reset with save request if(save_reboot){ - printText("saving...", 3, -1, disp); - if( saveTypeToSd(disp, rom_filename, save_t) ){ + printText("Copying RAM to SD card...", 3, -1, disp); + if( saveTypeToSd(disp, rom_filename, save_format) ){ if (debug) - printText("save upload done...", 3, -1, disp); + printText("Operation completed sucessfully...", 3, -1, disp); else printText("...ready", 3, -1, disp); } else if (debug) - printText("not saved...", 3, -1, disp); + printText("ERROR: the RAM was not successfully saved!", 3, -1, disp); } else { if (debug) @@ -3968,8 +3967,9 @@ int main(void) { printText("About: ", 9, 8, disp); printText(" ", 9, -1, disp); - printText("ALT64: v0.1.8.6-cheat", 9, -1, disp); + printText("ALT64: v0.1.8.6.1", 9, -1, disp); printText("by saturnu", 9, -1, disp); + printText("V3 support by JonesAlmighty", 9, -1, disp); printText(" ", 9, -1, disp); printText("Code engine by:", 9, -1, disp); printText("Jay Oster", 9, -1, disp); From f46562034de6135df2fc867e09c7b2d506e85cc3 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Fri, 2 Sep 2016 23:00:22 +0100 Subject: [PATCH 3/4] V3 saving now working --- menu.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/menu.c b/menu.c index 290575ee..78156add 100644 --- a/menu.c +++ b/menu.c @@ -781,7 +781,7 @@ void configure() { asm_date = memRomRead32(0x38); evd_setCfgBit(ED_CFG_SDRAM_ON, 1); - firm = evd_readReg(REG_VER); + firm = evd_readReg(REG_VER); //TODO: why not just use evd_getFirmVersion() if (streql("ED64 SD boot", buff, 12) && firm >= 0x0116) { sd_mode = 1; @@ -1354,17 +1354,16 @@ int backupSaveData(display_context_t disp){ uint8_t cfg_data[512]; //TODO: this should be a strut FatRecord rec_tmpf; - u8 file_found = fatFindRecord(config_file_path, &rec_tmpf, 0); //TODO: why does fatFindRecord return 0 for true?! - printText("Saving Last Played Game State - please wait...", 3, 4, disp); + printText("Saving Last Played Game State...", 3, 4, disp); - if(file_found==0){ //TODO: fatFindRecord could be moved into the if statement. + if(fatFindRecord(config_file_path, &rec_tmpf, 0) == 0) { //TODO: why does fatFindRecord return 0 for true?! //found //file to cfg_data buffer u8 resp = 0; - resp = fatOpenFileByeName(config_file_path, 0); //TODO: not sure why we bother setting a response here as it is not used for anything?! - resp = fatReadFile(&cfg_data, 1); //TODO: not sure why we bother setting a response here as it is not used for anything?! + fatOpenFileByeName(config_file_path, 0); + fatReadFile(&cfg_data, 1); //split in save type and cart-id save_format=cfg_data[0]; @@ -1395,12 +1394,15 @@ int backupSaveData(display_context_t disp){ } volatile u8 save_config_state=0; - volatile u8 val=0; //TODO: not sure why we are bothering with the reg response as it is never used. - val = evd_readReg(0); + evd_readReg(0); save_config_state = evd_readReg(REG_SAV_CFG); - if(save_config_state!=0) + if(save_config_state!=0 || evd_getFirmVersion() >= 0x0300 ) { //save register set or the firmware is V3 + if(save_config_state==0) {//we are V3 and have had a hard reboot + evd_writeReg(REG_SAV_CFG, 1); //so we need to tell the save register it still has data. + } save_reboot=1; + } } else { if (debug) @@ -1839,7 +1841,7 @@ int saveTypeFromSd(display_context_t disp, char* rom_name, int stype) { } else{ printText("no savegame found", 3, -1, disp); - //todo clear memory arena + //todo clear memory area return 0; } @@ -3021,7 +3023,7 @@ int main(void) { //fast boot for backup-save data int sj = evd_readReg(0); - int save_job = evd_readReg(REG_SAV_CFG); + int save_job = evd_readReg(REG_SAV_CFG); //TODO: or the firmware is V3 if(save_job!=0) fast_boot=1; From 1f6d31a95ae505eba05d2bcb3746ba3eff59f197 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Wed, 7 Sep 2016 15:43:07 +0100 Subject: [PATCH 4/4] Fixed string formatting --- menu.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/menu.c b/menu.c index 78156add..0ed2b71e 100644 --- a/menu.c +++ b/menu.c @@ -3967,11 +3967,10 @@ int main(void) { drawBoxNumber(disp,2); display_show(disp); - printText("About: ", 9, 8, disp); + printText("ALT64: v0.1.8.6.1", 9, 8, disp); printText(" ", 9, -1, disp); - printText("ALT64: v0.1.8.6.1", 9, -1, disp); - printText("by saturnu", 9, -1, disp); - printText("V3 support by JonesAlmighty", 9, -1, disp); + printText("by Saturnu", 9, -1, disp); + printText("& JonesAlmighty", 9, -1, disp); printText(" ", 9, -1, disp); printText("Code engine by:", 9, -1, disp); printText("Jay Oster", 9, -1, disp);