@@ -781,7 +781,7 @@ void configure() {
781781 asm_date = memRomRead32 (0x38 );
782782 evd_setCfgBit (ED_CFG_SDRAM_ON , 1 );
783783
784- firm = evd_readReg (REG_VER );
784+ firm = evd_readReg (REG_VER ); //TODO: why not just use evd_getFirmVersion()
785785
786786 if (streql ("ED64 SD boot" , buff , 12 ) && firm >= 0x0116 ) {
787787 sd_mode = 1 ;
@@ -797,8 +797,13 @@ void configure() {
797797 if (!(msg & (1 << 14 ))) {
798798 msg |= 1 << 14 ;
799799 evd_writeReg (REG_MAX_MSG , msg );
800-
801- bi_load_firmware (firmware );
800+ if (firm == 0x0214 ) {
801+ int fpf = dfs_open ("/firmware.bin" );
802+ firmware = malloc ( dfs_size ( fpf ) );
803+ dfs_read ( firmware , 1 , dfs_size ( fpf ), fpf );
804+ dfs_close ( fpf );
805+ bi_load_firmware (firmware );
806+ }
802807
803808 sleep (1 );
804809 evd_init ();
@@ -1342,65 +1347,66 @@ void loadrom(display_context_t disp, u8 *buff, int fast){
13421347
13431348int backupSaveData (display_context_t disp ){
13441349 //backup cart-save on sd after reboot
1345- u8 fname [32 ];
1346- u8 found = 0 ;
1347- int save_t ;
1350+ u8 config_file_path [32 ];
1351+ int save_format ;
13481352
1349- sprintf (fname , "/ED64/%s/LAST.CRT" ,save_path );
1350- uint8_t cfg_data [512 ];
1353+ sprintf (config_file_path , "/ED64/%s/LAST.CRT" ,save_path );
1354+ uint8_t cfg_data [512 ]; //TODO: this should be a strut
13511355
13521356 FatRecord rec_tmpf ;
1353- found = fatFindRecord (fname , & rec_tmpf , 0 );
13541357
1355- printText ("Save System - please stand by " , 3 , 4 , disp );
1358+ printText ("Saving Last Played Game State... " , 3 , 4 , disp );
13561359
1357- if (found == 0 ){
1360+ if (fatFindRecord ( config_file_path , & rec_tmpf , 0 ) == 0 ) { //TODO: why does fatFindRecord return 0 for true?!
13581361 //found
13591362
13601363 //file to cfg_data buffer
13611364 u8 resp = 0 ;
1362- resp = fatOpenFileByeName (fname , 0 );
1363- resp = fatReadFile (& cfg_data , 1 );
1365+ fatOpenFileByeName (config_file_path , 0 );
1366+ fatReadFile (& cfg_data , 1 );
13641367
13651368 //split in save type and cart-id
1366- save_t = cfg_data [0 ];
1369+ save_format = cfg_data [0 ];
13671370 int last_cic = cfg_data [1 ];
1368- scopy (cfg_data + 2 , rom_filename );
1371+ scopy (cfg_data + 2 , rom_filename ); //string copy
13691372
13701373 //set savetype to 0 disable for next boot
1371- if (save_t != 0 ){
1374+ if (save_format != 0 ){
13721375 //set savetype to off
13731376 cfg_data [0 ]= 0 ;
13741377
13751378 u8 tmp [32 ];
13761379
1377- resp = fatOpenFileByeName (fname , 1 ); //if sector is set filemode=WR writeable
1380+ resp = fatOpenFileByeName (config_file_path , 1 ); //if sector is set filemode=WR writeable
13781381
13791382 if (debug ) {
1380- sprintf (tmp , "fatOpenFileByeName ret= %i" ,resp );
1383+ sprintf (tmp , "FAT_OpenFileByName returned: %i" ,resp );
13811384 printText (tmp , 3 , -1 , disp );
13821385 }
13831386
13841387 resp = fatWriteFile (& cfg_data , 1 ); //filemode must be wr
13851388
13861389 if (debug ) {
1387- sprintf (tmp , "fatWriteFile ret=%i" ,resp );
1390+ printText ("Disabling save for subsequent system reboots" , 3 , -1 , disp );
1391+ sprintf (tmp , "FAT_WriteFile returned: %i" ,resp );
13881392 printText (tmp , 3 , -1 , disp );
13891393
1390- printText ("SaveType-tag has been disabled for next boot" , 3 , -1 , disp );
13911394 }
13921395
1393- volatile u8 save_cfg_stat = 0 ;
1394- volatile u8 val = 0 ;
1395- val = evd_readReg (0 );
1396- save_cfg_stat = evd_readReg (REG_SAV_CFG );
1396+ volatile u8 save_config_state = 0 ;
1397+ evd_readReg (0 );
1398+ save_config_state = evd_readReg (REG_SAV_CFG );
13971399
1398- if (save_cfg_stat != 0 )
1400+ if (save_config_state != 0 || evd_getFirmVersion () >= 0x0300 ) { //save register set or the firmware is V3
1401+ if (save_config_state == 0 ) {//we are V3 and have had a hard reboot
1402+ evd_writeReg (REG_SAV_CFG , 1 ); //so we need to tell the save register it still has data.
1403+ }
13991404 save_reboot = 1 ;
1405+ }
14001406 }
14011407 else {
14021408 if (debug )
1403- printText ("no need to save to sd " , 3 , -1 , disp );
1409+ printText ("Save not required. " , 3 , -1 , disp );
14041410 else
14051411 printText ("...ready" , 3 , -1 , disp );
14061412
@@ -1411,7 +1417,7 @@ int backupSaveData(display_context_t disp){
14111417 }
14121418 else {
14131419 if (debug )
1414- printText ("last.crt not found" , 3 , -1 , disp );
1420+ printText ("No previous ROM loaded - the file ' last.crt' was not found! " , 3 , -1 , disp );
14151421 else
14161422 printText ("...ready" , 3 , -1 , disp );
14171423
@@ -1424,15 +1430,15 @@ int backupSaveData(display_context_t disp){
14241430
14251431 //reset with save request
14261432 if (save_reboot ){
1427- printText ("saving ..." , 3 , -1 , disp );
1428- if ( saveTypeToSd (disp , rom_filename , save_t ) ){
1433+ printText ("Copying RAM to SD card ..." , 3 , -1 , disp );
1434+ if ( saveTypeToSd (disp , rom_filename , save_format ) ){
14291435 if (debug )
1430- printText ("save upload done ..." , 3 , -1 , disp );
1436+ printText ("Operation completed sucessfully ..." , 3 , -1 , disp );
14311437 else
14321438 printText ("...ready" , 3 , -1 , disp );
14331439 }
14341440 else if (debug )
1435- printText ("not saved... " , 3 , -1 , disp );
1441+ printText ("ERROR: the RAM was not successfully saved! " , 3 , -1 , disp );
14361442 }
14371443 else {
14381444 if (debug )
@@ -1835,7 +1841,7 @@ int saveTypeFromSd(display_context_t disp, char* rom_name, int stype) {
18351841 }
18361842 else {
18371843 printText ("no savegame found" , 3 , -1 , disp );
1838- //todo clear memory arena
1844+ //todo clear memory area
18391845
18401846 return 0 ;
18411847 }
@@ -3012,17 +3018,12 @@ int main(void) {
30123018 printf ("Filesystem failed to start!\n" );
30133019 }
30143020 else {
3015- int fpf = dfs_open ("/firmware.bin" );
3016- firmware = malloc ( dfs_size ( fpf ) );
3017- dfs_read ( firmware , 1 , dfs_size ( fpf ), fpf );
3018- dfs_close ( fpf );
3019-
30203021 // everdrive initial function
30213022 configure ();
30223023
30233024 //fast boot for backup-save data
30243025 int sj = evd_readReg (0 );
3025- int save_job = evd_readReg (REG_SAV_CFG );
3026+ int save_job = evd_readReg (REG_SAV_CFG ); //TODO: or the firmware is V3
30263027
30273028 if (save_job != 0 )
30283029 fast_boot = 1 ;
@@ -3966,10 +3967,10 @@ int main(void) {
39663967 drawBoxNumber (disp ,2 );
39673968 display_show (disp );
39683969
3969- printText ("About: " , 9 , 8 , disp );
3970+ printText ("ALT64: v0.1.8.6.1 " , 9 , 8 , disp );
39703971 printText (" " , 9 , -1 , disp );
3971- printText ("ALT64: v0.1.8.6-cheat " , 9 , -1 , disp );
3972- printText ("by saturnu " , 9 , -1 , disp );
3972+ printText ("by Saturnu " , 9 , -1 , disp );
3973+ printText ("& JonesAlmighty " , 9 , -1 , disp );
39733974 printText (" " , 9 , -1 , disp );
39743975 printText ("Code engine by:" , 9 , -1 , disp );
39753976 printText ("Jay Oster" , 9 , -1 , disp );
0 commit comments