Skip to content

Commit

Permalink
Start simplifying filesystem stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
bearoso committed Mar 7, 2023
1 parent 4a3f7b4 commit 596e84a
Show file tree
Hide file tree
Showing 20 changed files with 513 additions and 720 deletions.
2 changes: 1 addition & 1 deletion apu/apu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ void S9xDumpSPCSnapshot(void)

static void SPCSnapshotCallback(void)
{
S9xSPCDump(S9xGetFilenameInc((".spc"), SPC_DIR));
S9xSPCDump(S9xGetFilenameInc((".spc"), SPC_DIR).c_str());
printf("Dumped key-on triggered spc snapshot.\n");
}

Expand Down
34 changes: 13 additions & 21 deletions bsx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,13 +738,11 @@ void S9xBSXSetStream1 (uint8 count)
if (BSX.sat_stream1.is_open())
BSX.sat_stream1.close(); //If Stream already opened for one file: Close it.

char path[PATH_MAX + 1], name[PATH_MAX + 1];
std::string path = S9xGetDirectory(SAT_DIR) + SLASH_STR;

strcpy(path, S9xGetDirectory(SAT_DIR));
strcat(path, SLASH_STR);

snprintf(name, PATH_MAX + 1, "BSX%04X-%d.bin", (BSX.PPU[0x2188 - BSXPPUBASE] | (BSX.PPU[0x2189 - BSXPPUBASE] * 256)), count); //BSXHHHH-DDD.bin
strcat(path, name);
char name[PATH_MAX];
snprintf(name, PATH_MAX, "BSX%04X-%d.bin", (BSX.PPU[0x2188 - BSXPPUBASE] | (BSX.PPU[0x2189 - BSXPPUBASE] * 256)), count); //BSXHHHH-DDD.bin
path += name;

BSX.sat_stream1.clear();
BSX.sat_stream1.open(path, std::ios::in | std::ios::binary);
Expand All @@ -770,13 +768,12 @@ void S9xBSXSetStream2 (uint8 count)
if (BSX.sat_stream2.is_open())
BSX.sat_stream2.close(); //If Stream already opened for one file: Close it.

char path[PATH_MAX + 1], name[PATH_MAX + 1];

strcpy(path, S9xGetDirectory(SAT_DIR));
strcat(path, SLASH_STR);
std::string path = S9xGetDirectory(SAT_DIR) + SLASH_STR;

snprintf(name, PATH_MAX + 1, "BSX%04X-%d.bin", (BSX.PPU[0x218E - BSXPPUBASE] | (BSX.PPU[0x218F - BSXPPUBASE] * 256)), count); //BSXHHHH-DDD.bin
strcat(path, name);
char name[PATH_MAX];
snprintf(name, PATH_MAX, "BSX%04X-%d.bin", (BSX.PPU[0x218E - BSXPPUBASE] | (BSX.PPU[0x218F - BSXPPUBASE] * 256)), count); //BSXHHHH-DDD.bin
path += name;

BSX.sat_stream2.clear();
BSX.sat_stream2.open(path, std::ios::in | std::ios::binary);
Expand Down Expand Up @@ -1207,20 +1204,15 @@ uint8 * S9xGetBasePointerBSX (uint32 address)
static bool8 BSX_LoadBIOS (void)
{
FILE *fp;
char path[PATH_MAX + 1], name[PATH_MAX + 1];
bool8 r = FALSE;

strcpy(path, S9xGetDirectory(BIOS_DIR));
strcat(path, SLASH_STR);
strcpy(name, path);
strcat(name, "BS-X.bin");
std::string name = S9xGetDirectory(BIOS_DIR) + SLASH_STR + "BS-X.bin";

fp = fopen(name, "rb");
fp = fopen(name.c_str(), "rb");
if (!fp)
{
strcpy(name, path);
strcat(name, "BS-X.bios");
fp = fopen(name, "rb");
name = S9xGetDirectory(BIOS_DIR) + SLASH_STR + "BS-X.bios";
fp = fopen(name.c_str(), "rb");
}

if (fp)
Expand Down Expand Up @@ -1255,7 +1247,7 @@ void S9xInitBSX (void)
{
Settings.BS = FALSE;

if (is_BSX_BIOS(Memory.ROM,Memory.CalculatedSize))
if (is_BSX_BIOS(Memory.ROM,Memory.CalculatedSize))
{
// BS-X itself

Expand Down
67 changes: 0 additions & 67 deletions compat.cpp

This file was deleted.

30 changes: 15 additions & 15 deletions controls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2259,11 +2259,11 @@ void S9xApplyCommand (s9xcommand_t cmd, int16 data1, int16 data2)

case LoadOopsFile:
{
const char *filename = S9xGetFilename("oops", SNAPSHOT_DIR);
std::string filename = S9xGetFilename("oops", SNAPSHOT_DIR);

if (S9xUnfreezeGame(filename))
if (S9xUnfreezeGame(filename.c_str()))
{
snprintf(buf, 256, "%.240s.oops loaded", S9xBasename(Memory.ROMFilename));
snprintf(buf, 256, "%.240s.oops loaded", S9xBasename(Memory.ROMFilename).c_str());
S9xSetInfoString(buf);
}
else
Expand Down Expand Up @@ -2292,15 +2292,15 @@ void S9xApplyCommand (s9xcommand_t cmd, int16 data1, int16 data2)
case QuickLoad009:
case QuickLoad010:
{
char filename[PATH_MAX + 1];
char drive[_MAX_DRIVE + 1], dir[_MAX_DIR + 1], def[_MAX_FNAME + 1], ext[_MAX_EXT + 1];
std::string ext = std::to_string(i - QuickLoad000);
while (ext.length() < 3)
ext = '0' + ext;

_splitpath(Memory.ROMFilename, drive, dir, def, ext);
snprintf(filename, PATH_MAX + 1, "%.2s%.512s%.512s.%03d", S9xGetDirectory(SNAPSHOT_DIR), SLASH_STR, def, i - QuickLoad000);
auto filename = S9xGetFilename(ext, SNAPSHOT_DIR);

if (S9xUnfreezeGame(filename))
if (S9xUnfreezeGame(filename.c_str()))
{
snprintf(buf, 256, "%.240s.%03d loaded", def, i - QuickLoad000);
snprintf(buf, 256, "Quick save-state %s loaded", ext.c_str());
S9xSetInfoString(buf);
}
else
Expand All @@ -2321,16 +2321,16 @@ void S9xApplyCommand (s9xcommand_t cmd, int16 data1, int16 data2)
case QuickSave009:
case QuickSave010:
{
char filename[PATH_MAX + 1];
char drive[_MAX_DRIVE + 1], dir[_MAX_DIR + 1], def[_MAX_FNAME + 1], ext[_MAX_EXT + 1];
std::string ext = std::to_string(i - QuickLoad000);
while (ext.length() < 3)
ext = '0' + ext;

_splitpath(Memory.ROMFilename, drive, dir, def, ext);
snprintf(filename, PATH_MAX + 1, "%.2s%.512s%.512s.%03d", S9xGetDirectory(SNAPSHOT_DIR), SLASH_STR, def, i - QuickSave000);
auto filename = S9xGetFilename(ext, SNAPSHOT_DIR);

snprintf(buf, 256, "%.240s.%03d saved", def, i - QuickSave000);
snprintf(buf, 256, "Quick save-state %s saved", ext.c_str());
S9xSetInfoString(buf);

S9xFreezeGame(filename);
S9xFreezeGame(filename.c_str());
break;
}

Expand Down
8 changes: 4 additions & 4 deletions display.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ void S9xToggleSoundChannel (int);
bool8 S9xOpenSnapshotFile (const char *, bool8, STREAM *);
void S9xCloseSnapshotFile (STREAM);
const char * S9xStringInput (const char *);
const char * S9xGetDirectory (enum s9x_getdirtype);
const char * S9xGetFilename (const char *, enum s9x_getdirtype);
const char * S9xGetFilenameInc (const char *, enum s9x_getdirtype);
const char * S9xBasename (const char *);
std::string S9xGetDirectory (enum s9x_getdirtype);
std::string S9xGetFilename (std::string, enum s9x_getdirtype);
std::string S9xGetFilenameInc (std::string, enum s9x_getdirtype);
std::string S9xBasename (std::string);

// Routines the port has to implement if it uses command-line

Expand Down
Loading

0 comments on commit 596e84a

Please sign in to comment.