Skip to content

Commit 247cb19

Browse files
committed
Actually screw the useSaveFolder config. "/3ds/open_agb_firm/saves" is the new location for savegames and future per-game configs.
Added code for savegame slots. Currently not configurable.
1 parent 35243ab commit 247cb19

File tree

4 files changed

+69
-49
lines changed

4 files changed

+69
-49
lines changed

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ General settings.
4747
`bool useGbaDb` - Use `gba_db.bin` to get save types
4848
* Default: `true`
4949

50-
`bool useSaveFolder` - Store savegames and config files in `/3ds/open_agb_firm/saves`
51-
* Default: `false`
52-
5350
### Video
5451
Video-related settings.
5552

libn3ds/include/error_codes.h

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,29 @@ enum
3737
RES_OUT_OF_MEM = 4u,
3838
RES_OUT_OF_RANGE = 5u,
3939
RES_NOT_FOUND = 6u,
40+
RES_PATH_TOO_LONG = 7u,
4041

4142
// fatfs errors.
4243
// Caution: Update fres2Res() in fs.c on ARM9 if this changes!
43-
RES_FR_DISK_ERR = 7u, /* (1) A hard error occurred in the low level disk I/O layer */
44-
RES_FR_INT_ERR = 8u, /* (2) Assertion failed */
45-
RES_FR_NOT_READY = 9u, /* (3) The physical drive cannot work */
46-
RES_FR_NO_FILE = 10u, /* (4) Could not find the file */
47-
RES_FR_NO_PATH = 11u, /* (5) Could not find the path */
48-
RES_FR_INVALID_NAME = 12u, /* (6) The path name format is invalid */
49-
RES_FR_DENIED = 13u, /* (7) Access denied due to prohibited access or directory full */
50-
RES_FR_EXIST = 14u, /* (8) Access denied due to prohibited access */
51-
RES_FR_INVALID_OBJECT = 15u, /* (9) The file/directory object is invalid */
52-
RES_FR_WRITE_PROTECTED = 16u, /* (10) The physical drive is write protected */
53-
RES_FR_INVALID_DRIVE = 17u, /* (11) The logical drive number is invalid */
54-
RES_FR_NOT_ENABLED = 18u, /* (12) The volume has no work area */
55-
RES_FR_NO_FILESYSTEM = 19u, /* (13) There is no valid FAT volume */
56-
RES_FR_MKFS_ABORTED = 20u, /* (14) The f_mkfs() aborted due to any problem */
57-
RES_FR_TIMEOUT = 21u, /* (15) Could not get a grant to access the volume within defined period */
58-
RES_FR_LOCKED = 22u, /* (16) The operation is rejected according to the file sharing policy */
59-
RES_FR_NOT_ENOUGH_CORE = 23u, /* (17) LFN working buffer could not be allocated */
60-
RES_FR_TOO_MANY_OPEN_FILES = 24u, /* (18) Number of open files > FF_FS_LOCK */
61-
RES_FR_INVALID_PARAMETER = 25u, /* (19) Given parameter is invalid */
44+
RES_FR_DISK_ERR = 8u, /* (1) A hard error occurred in the low level disk I/O layer */
45+
RES_FR_INT_ERR = 9u, /* (2) Assertion failed */
46+
RES_FR_NOT_READY = 10u, /* (3) The physical drive cannot work */
47+
RES_FR_NO_FILE = 11u, /* (4) Could not find the file */
48+
RES_FR_NO_PATH = 12u, /* (5) Could not find the path */
49+
RES_FR_INVALID_NAME = 13u, /* (6) The path name format is invalid */
50+
RES_FR_DENIED = 14u, /* (7) Access denied due to prohibited access or directory full */
51+
RES_FR_EXIST = 15u, /* (8) Access denied due to prohibited access */
52+
RES_FR_INVALID_OBJECT = 16u, /* (9) The file/directory object is invalid */
53+
RES_FR_WRITE_PROTECTED = 17u, /* (10) The physical drive is write protected */
54+
RES_FR_INVALID_DRIVE = 18u, /* (11) The logical drive number is invalid */
55+
RES_FR_NOT_ENABLED = 19u, /* (12) The volume has no work area */
56+
RES_FR_NO_FILESYSTEM = 20u, /* (13) There is no valid FAT volume */
57+
RES_FR_MKFS_ABORTED = 21u, /* (14) The f_mkfs() aborted due to any problem */
58+
RES_FR_TIMEOUT = 22u, /* (15) Could not get a grant to access the volume within defined period */
59+
RES_FR_LOCKED = 23u, /* (16) The operation is rejected according to the file sharing policy */
60+
RES_FR_NOT_ENOUGH_CORE = 24u, /* (17) LFN working buffer could not be allocated */
61+
RES_FR_TOO_MANY_OPEN_FILES = 25u, /* (18) Number of open files > FF_FS_LOCK */
62+
RES_FR_INVALID_PARAMETER = 26u, /* (19) Given parameter is invalid */
6263

6364
// Custom errors.
6465
RES_ROM_TOO_BIG = MAKE_CUSTOM_ERR(0),

libn3ds/source/error_codes.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
#ifdef ARM11
3030
void printError(Result res)
3131
{
32-
GFX_setBrightness(15, 15);
33-
3432
static const char *const common[] =
3533
{
3634
"OK",
@@ -40,6 +38,7 @@ void printError(Result res)
4038
"Out of memory",
4139
"Out of range",
4240
"Not found",
41+
"Path too long",
4342

4443
// fatfs errors.
4544
"fatfs disk error",

source/arm11/open_agb_firm.c

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@
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

Comments
 (0)