4141
4242
4343#define OAF_WORK_DIR "sdmc:/3ds/open_agb_firm"
44+ #define OAF_SAVE_DIR "saves" // Relative to work dir.
4445#define INI_BUF_SIZE (1024u)
45- #define DEFAULT_CONFIG "[general]\n" \
46- "backlight=64\n" \
47- "directBoot=false\n" \
48- "useGbaDb=true\n" \
49- "useSaveFolder=false\n\n" \
50- "[video]\n" \
51- "gbaGamma=2.2\n" \
52- "lcdGamma=1.54\n" \
53- "contrast=1.0\n" \
54- "brightness=0.0\n\n" \
55- "[advanced]\n" \
56- "saveOverride=false\n" \
46+ #define DEFAULT_CONFIG "[general]\n" \
47+ "backlight=64\n" \
48+ "directBoot=false\n" \
49+ "useGbaDb=true\n\n" \
50+ "[video]\n" \
51+ "gbaGamma=2.2\n" \
52+ "lcdGamma=1.54\n" \
53+ "contrast=1.0\n" \
54+ "brightness=0.0\n\n" \
55+ "[advanced]\n" \
56+ "saveOverride=false\n" \
5757 "defaultSave=14"
5858
5959
@@ -63,7 +63,6 @@ typedef struct
6363 u8 backlight ; // Both LCDs.
6464 bool directBoot ;
6565 bool useGbaDb ;
66- bool useSaveFolder ;
6766
6867 // [video]
6968 float gbaGamma ;
@@ -92,7 +91,6 @@ static OafConfig g_oafConfig =
9291 64 , // backlight
9392 false, // directBoot
9493 true, // useGbaDb
95- false, // useSaveFolder
9694
9795 // [video]
9896 2.2f , // gbaGamma
@@ -506,8 +504,6 @@ static int confIniHandler(void* user, const char* section, const char* name, con
506504 config -> directBoot = (strcmp (value , "false" ) == 0 ? false : true);
507505 else if (strcmp (name , "useGbaDb" ) == 0 )
508506 config -> useGbaDb = (strcmp (value , "true" ) == 0 ? true : false);
509- else if (strcmp (name , "useSaveFolder" ) == 0 )
510- config -> useSaveFolder = (strcmp (value , "false" ) == 0 ? false : true);
511507 }
512508 else if (strcmp (section , "video" ) == 0 )
513509 {
@@ -595,18 +591,45 @@ static Result showFileBrowser(char romAndSavePath[512])
595591 return res ;
596592}
597593
598- Result oafParseConfigEarly ( void )
594+ static void rom2SavePath ( char romPath [ 512 ], const u8 saveSlot )
599595{
600- // Create the work dir and switch to it before parsing the config.
601- Result res = fsMakePath (OAF_WORK_DIR );
602- if (res == RES_OK || res == RES_FR_EXIST )
596+ if (saveSlot > 9 )
603597 {
604- if ((res = fChdir (OAF_WORK_DIR )) == RES_OK )
605- {
606- res = parseConfig ("config.ini" , & g_oafConfig );
607- }
598+ * romPath = '\0' ; // Prevent using the ROM as save file.
599+ return ;
608600 }
609601
602+ char tmpSaveFileName [256 ];
603+ static char numberedExt [7 ] = {'.' , 'X' , '.' , 's' , 'a' , 'v' , '\0' };
604+
605+ numberedExt [1 ] = '0' + saveSlot ;
606+
607+ // Extract the file name and change the extension.
608+ // The numbered extension is 2 chars longer than unnumbered.
609+ safeStrcpy (tmpSaveFileName , strrchr (romPath , '/' ) + 1 , 256 - 2 );
610+ strcpy (tmpSaveFileName + strlen (tmpSaveFileName ) - 4 , (saveSlot == 0 ? ".sav" : numberedExt ));
611+
612+ // Construct the new path.
613+ strcpy (romPath , OAF_SAVE_DIR "/" );
614+ strcat (romPath , tmpSaveFileName );
615+ }
616+
617+ Result oafParseConfigEarly (void )
618+ {
619+ Result res ;
620+ do
621+ {
622+ // Create the work dir and switch to it.
623+ if ((res = fsMakePath (OAF_WORK_DIR )) != RES_OK && res != RES_FR_EXIST ) break ;
624+ if ((res = fChdir (OAF_WORK_DIR )) != RES_OK ) break ;
625+
626+ // Create the saves folder.
627+ if ((res = fMkdir (OAF_SAVE_DIR )) != RES_OK && res != RES_FR_EXIST ) break ;
628+
629+ // Parse the config.
630+ res = parseConfig ("config.ini" , & g_oafConfig );
631+ } while (0 );
632+
610633 return res ;
611634}
612635
@@ -634,7 +657,7 @@ Result oafInitAndRun(void)
634657 if ((res = loadGbaRom (romAndSavePath , & romSize )) != RES_OK ) break ;
635658
636659 // Adjust path for the save file and get save type.
637- strcpy (romAndSavePath + strlen ( romAndSavePath ) - 4 , ".sav" );
660+ rom2SavePath (romAndSavePath , 0 ); // TODO: Save slot config.
638661 u16 saveType ;
639662 if (g_oafConfig .useGbaDb || g_oafConfig .saveOverride )
640663 saveType = getSaveType (romSize , romAndSavePath );
0 commit comments