forked from Ports/perfect_dark
port: allow specifying path to eeprom file
--eeprom-file file.bin
This commit is contained in:
1 parent
78ff5683ce
commit
6a1b0a474c
3 files changed
+44
-5
No files matched your search
@@ -10,6 +10,9 @@ s32 fsInit(void);
|
||||
|
||||
const char *fsFullPath(const char *relPath);
|
||||
|
||||
s32 fsPathIsAbsolute(const char *path);
|
||||
s32 fsPathIsCwdRelative(const char *path);
|
||||
|
||||
void *fsFileLoad(const char *name, u32 *outSize);
|
||||
s32 fsFileSize(const char *name);
|
||||
|
||||
|
||||
+14
-2
@@ -18,7 +18,8 @@ static char saveDir[FS_MAXPATH + 1]; // replaces $S
|
||||
static char homeDir[FS_MAXPATH + 1]; // replaces $H
|
||||
static char exeDir[FS_MAXPATH + 1]; // replaces $E
|
||||
|
||||
static s32 fsPathIsWritable(const char *path) {
|
||||
static s32 fsPathIsWritable(const char *path)
|
||||
{
|
||||
#ifdef PLATFORM_WIN32
|
||||
// on windows access() on directories will only check if the directory exists, so
|
||||
char tmp[FS_MAXPATH + 1] = { 0 };
|
||||
@@ -35,6 +36,17 @@ static s32 fsPathIsWritable(const char *path) {
|
||||
#endif
|
||||
}
|
||||
|
||||
s32 fsPathIsAbsolute(const char *path)
|
||||
{
|
||||
return (path[0] == '/' || (isalpha(path[0]) && path[1] == ':'));
|
||||
}
|
||||
|
||||
s32 fsPathIsCwdRelative(const char *path)
|
||||
{
|
||||
// ., .., ./, ../
|
||||
return (path[0] == '.' && (path[1] == '.' || path[1] == '/' || path[1] == '\\' || path[1] == '\0'));
|
||||
}
|
||||
|
||||
const char *fsFullPath(const char *relPath)
|
||||
{
|
||||
static char pathBuf[FS_MAXPATH + 1];
|
||||
@@ -59,7 +71,7 @@ const char *fsFullPath(const char *relPath)
|
||||
}
|
||||
// couldn't expand anything, return as is
|
||||
return relPath;
|
||||
} else if (!dataDir[0] || relPath[0] == '.' || relPath[0] == '/' || (isalpha(relPath[0]) && relPath[1] == ':')) {
|
||||
} else if (!dataDir[0] || fsPathIsAbsolute(relPath) || fsPathIsCwdRelative(relPath)) {
|
||||
// user explicitly wants working directory or this is an absolute path or we have no dataDir set up yet
|
||||
return relPath;
|
||||
}
|
||||
|
||||
+27
-3
@@ -27,6 +27,7 @@ s32 osResetType = 0; /* 0 = cold reset */
|
||||
s32 osViClock = VI_NTSC_CLOCK;
|
||||
|
||||
static u8 eeprom[EEPROM_SIZE];
|
||||
static char eepromPath[FS_MAXPATH + 1];
|
||||
static s32 eepromLoaded = 0;
|
||||
|
||||
/* Time */
|
||||
@@ -252,6 +253,21 @@ s32 __osMotorAccess(OSPfs *pfs, s32 cmd)
|
||||
|
||||
/* Eeprom */
|
||||
|
||||
static inline void osEepromSetPath(void)
|
||||
{
|
||||
const char *extPath = sysArgGetString("--eeprom-file");
|
||||
if (extPath && extPath[0]) {
|
||||
if (extPath[0] == '$' || fsPathIsAbsolute(extPath) || fsPathIsCwdRelative(extPath)) {
|
||||
strncpy(eepromPath, extPath, FS_MAXPATH);
|
||||
} else {
|
||||
// just a filename, look for it in the save dir
|
||||
snprintf(eepromPath, FS_MAXPATH, "$S/%s", extPath);
|
||||
}
|
||||
} else {
|
||||
strncpy(eepromPath, EEPROM_PATH, FS_MAXPATH);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void osEeepromLoad(const char *fname)
|
||||
{
|
||||
if (!eepromLoaded) {
|
||||
@@ -284,7 +300,11 @@ s32 osEepromProbe(OSMesgQueue *mq)
|
||||
|
||||
s32 osEepromLongRead(OSMesgQueue *mq, u8 address, u8 *buffer, int nbytes)
|
||||
{
|
||||
osEeepromLoad(EEPROM_PATH);
|
||||
if (!eepromPath[0]) {
|
||||
osEepromSetPath();
|
||||
}
|
||||
|
||||
osEeepromLoad(eepromPath);
|
||||
|
||||
memcpy(buffer, eeprom + address * 8, nbytes);
|
||||
|
||||
@@ -293,11 +313,15 @@ s32 osEepromLongRead(OSMesgQueue *mq, u8 address, u8 *buffer, int nbytes)
|
||||
|
||||
s32 osEepromLongWrite(OSMesgQueue *mq, u8 address, u8 *buffer, int nbytes)
|
||||
{
|
||||
osEeepromLoad(EEPROM_PATH);
|
||||
if (!eepromPath[0]) {
|
||||
osEepromSetPath();
|
||||
}
|
||||
|
||||
osEeepromLoad(eepromPath);
|
||||
|
||||
memcpy(eeprom + address * 8, buffer, nbytes);
|
||||
|
||||
osEeepromSave(EEPROM_PATH);
|
||||
osEeepromSave(eepromPath);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user