unix: Make port compile.

This commit is contained in:
BearOso 2023-02-06 15:56:02 -06:00
parent b7704733ec
commit 13eefd9944
3 changed files with 72 additions and 138 deletions

View File

@ -8,7 +8,7 @@
OS = `uname -s -r -m|sed \"s/ /-/g\"|tr \"[A-Z]\" \"[a-z]\"|tr \"/()\" \"___\"` OS = `uname -s -r -m|sed \"s/ /-/g\"|tr \"[A-Z]\" \"[a-z]\"|tr \"/()\" \"___\"`
BUILDDIR = . BUILDDIR = .
OBJECTS = ../apu/apu.o ../apu/bapu/dsp/sdsp.o ../apu/bapu/smp/smp.o ../apu/bapu/smp/smp_state.o ../bsx.o ../c4.o ../c4emu.o ../cheats.o ../cheats2.o ../clip.o ../conffile.o ../controls.o ../cpu.o ../cpuexec.o ../cpuops.o ../crosshairs.o ../dma.o ../dsp.o ../dsp1.o ../dsp2.o ../dsp3.o ../dsp4.o ../fxinst.o ../fxemu.o ../gfx.o ../globals.o ../memmap.o ../msu1.o ../movie.o ../obc1.o ../ppu.o ../stream.o ../sa1.o ../sa1cpu.o ../screenshot.o ../sdd1.o ../sdd1emu.o ../seta.o ../seta010.o ../seta011.o ../seta018.o ../snapshot.o ../snes9x.o ../spc7110.o ../srtc.o ../tile.o ../tileimpl-n1x1.o ../tileimpl-n2x1.o ../tileimpl-h2x1.o ../filter/2xsai.o ../filter/blit.o ../filter/epx.o ../filter/hq2x.o ../filter/snes_ntsc.o ../statemanager.o ../sha256.o ../bml.o ../compat.o unix.o x11.o OBJECTS = ../apu/apu.o ../apu/bapu/dsp/sdsp.o ../apu/bapu/smp/smp.o ../apu/bapu/smp/smp_state.o ../bsx.o ../c4.o ../c4emu.o ../cheats.o ../cheats2.o ../clip.o ../conffile.o ../controls.o ../cpu.o ../cpuexec.o ../cpuops.o ../crosshairs.o ../dma.o ../dsp.o ../dsp1.o ../dsp2.o ../dsp3.o ../dsp4.o ../fxinst.o ../fxemu.o ../gfx.o ../globals.o ../memmap.o ../msu1.o ../movie.o ../obc1.o ../ppu.o ../stream.o ../sa1.o ../sa1cpu.o ../screenshot.o ../sdd1.o ../sdd1emu.o ../seta.o ../seta010.o ../seta011.o ../seta018.o ../snapshot.o ../snes9x.o ../spc7110.o ../srtc.o ../tile.o ../tileimpl-n1x1.o ../tileimpl-n2x1.o ../tileimpl-h2x1.o ../filter/2xsai.o ../filter/blit.o ../filter/epx.o ../filter/hq2x.o ../filter/snes_ntsc.o ../statemanager.o ../sha256.o ../bml.o ../fscompat.o unix.o x11.o
DEFS = -DMITSHM DEFS = -DMITSHM
ifdef S9XDEBUGGER ifdef S9XDEBUGGER

View File

@ -51,6 +51,7 @@
#include "movie.h" #include "movie.h"
#include "display.h" #include "display.h"
#include "conffile.h" #include "conffile.h"
#include "fscompat.h"
#ifdef NETPLAY_SUPPORT #ifdef NETPLAY_SUPPORT
#include "netplay.h" #include "netplay.h"
#endif #endif
@ -359,7 +360,7 @@ void S9xExtraUsage (void)
#endif #endif
#ifndef NOSOUND #ifndef NOSOUND
#ifdef USE_THREADS && ! defined(ALSA) #if defined(USE_THREADS) && !defined(ALSA)
S9xMessage(S9X_INFO, S9X_USAGE, "-threadsound Use a separate thread to output sound"); S9xMessage(S9X_INFO, S9X_USAGE, "-threadsound Use a separate thread to output sound");
#endif #endif
S9xMessage(S9X_INFO, S9X_USAGE, "-buffersize Sound generating buffer size in millisecond"); S9xMessage(S9X_INFO, S9X_USAGE, "-buffersize Sound generating buffer size in millisecond");
@ -392,7 +393,7 @@ void S9xParseArg (char **argv, int &i, int argc)
if (!strcasecmp(argv[i], "-carta")) if (!strcasecmp(argv[i], "-carta"))
{ {
if (i + 1 < argc) if (i + 1 < argc)
strncpy(Settings.CartAName, argv[++i], _MAX_PATH); strncpy(Settings.CartAName, argv[++i], PATH_MAX);
else else
S9xUsage(); S9xUsage();
} }
@ -400,7 +401,7 @@ void S9xParseArg (char **argv, int &i, int argc)
if (!strcasecmp(argv[i], "-cartb")) if (!strcasecmp(argv[i], "-cartb"))
{ {
if (i + 1 < argc) if (i + 1 < argc)
strncpy(Settings.CartBName, argv[++i], _MAX_PATH); strncpy(Settings.CartBName, argv[++i], PATH_MAX);
else else
S9xUsage(); S9xUsage();
} }
@ -670,78 +671,65 @@ static int make_snes9x_dirs (void)
return (0); return (0);
} }
const char * S9xGetDirectory (enum s9x_getdirtype dirtype) std::string S9xGetDirectory (enum s9x_getdirtype dirtype)
{ {
static char s[PATH_MAX + 1]; std::string retval = Memory.ROMFilename;
size_t pos;
if (dirNames[dirtype][0]) if (dirNames[dirtype][0])
snprintf(s, PATH_MAX + 1, "%s%s%s", s9x_base_dir, SLASH_STR, dirNames[dirtype]); return std::string(s9x_base_dir) + SLASH_STR + dirNames[dirtype];
else else
{ {
switch (dirtype) switch (dirtype)
{ {
case DEFAULT_DIR: case DEFAULT_DIR:
strncpy(s, s9x_base_dir, PATH_MAX + 1); retval = s9x_base_dir;
s[PATH_MAX] = 0;
break; break;
case HOME_DIR: case HOME_DIR:
strncpy(s, getenv("HOME"), PATH_MAX + 1); retval = std::string(getenv("HOME"));
s[PATH_MAX] = 0;
break; break;
case ROMFILENAME_DIR: case ROMFILENAME_DIR:
strncpy(s, Memory.ROMFilename, PATH_MAX + 1); retval = Memory.ROMFilename;
s[PATH_MAX] = 0; pos = retval.rfind("/");
if (pos != std::string::npos)
for (int i = strlen(s); i >= 0; i--) retval = retval.substr(pos);
{
if (s[i] == SLASH_CHAR)
{
s[i] = 0;
break;
}
}
break; break;
default: default:
s[0] = 0;
break; break;
} }
} }
return retval;
return (s);
} }
const char * S9xGetFilename (const char *ex, enum s9x_getdirtype dirtype) std::string S9xGetFilenameInc (std::string ex, enum s9x_getdirtype dirtype)
{ {
static char s[PATH_MAX + 1];
char drive[_MAX_DRIVE + 1], dir[_MAX_DIR + 1], fname[_MAX_FNAME + 1], ext[_MAX_EXT + 1];
_splitpath(Memory.ROMFilename, drive, dir, fname, ext);
snprintf(s, PATH_MAX + 1, "%s%s%s%s", S9xGetDirectory(dirtype), SLASH_STR, fname, ex);
return (s);
}
const char * S9xGetFilenameInc (const char *ex, enum s9x_getdirtype dirtype)
{
static char s[PATH_MAX + 1];
char drive[_MAX_DRIVE + 1], dir[_MAX_DIR + 1], fname[_MAX_FNAME + 1], ext[_MAX_EXT + 1];
unsigned int i = 0;
const char *d;
struct stat buf; struct stat buf;
_splitpath(Memory.ROMFilename, drive, dir, fname, ext); SplitPath path = splitpath(Memory.ROMFilename);
d = S9xGetDirectory(dirtype); std::string directory = S9xGetDirectory(dirtype);
if (ex[0] != '.')
{
ex = "." + ex;
}
std::string new_filename;
unsigned int i = 0;
do do
snprintf(s, PATH_MAX + 1, "%s%s%s.%03d%s", d, SLASH_STR, fname, i++, ex); {
while (stat(s, &buf) == 0 && i < 1000); std::string new_extension = std::to_string(i);
while (new_extension.length() < 3)
new_extension = "0" + new_extension;
new_extension += ex;
return (s); new_filename = path.stem + new_extension;
i++;
} while (stat(new_filename.c_str(), &buf) == 0 && i < 1000);
return new_filename;
} }
const char * S9xBasename (const char *f) const char * S9xBasename (const char *f)
@ -756,26 +744,28 @@ const char * S9xBasename (const char *f)
bool8 S9xOpenSnapshotFile (const char *filename, bool8 read_only, STREAM *file) bool8 S9xOpenSnapshotFile (const char *filename, bool8 read_only, STREAM *file)
{ {
char s[PATH_MAX + 1]; if (read_only)
char drive[_MAX_DRIVE + 1], dir[_MAX_DIR + 1], fname[_MAX_FNAME + 1], ext[_MAX_EXT + 1];
_splitpath(filename, drive, dir, fname, ext);
if (*drive || *dir == SLASH_CHAR || (strlen(dir) > 1 && *dir == '.' && *(dir + 1) == SLASH_CHAR))
{ {
strncpy(s, filename, PATH_MAX + 1); if ((*file = OPEN_STREAM(filename, "rb")))
s[PATH_MAX] = 0; return (true);
else
fprintf(stderr, "Failed to open file stream for reading.\n");
} }
else else
snprintf(s, PATH_MAX + 1, "%s%s%s", S9xGetDirectory(SNAPSHOT_DIR), SLASH_STR, fname); {
if ((*file = OPEN_STREAM(filename, "wb")))
{
return (true);
}
else
{
fprintf(stderr, "Couldn't open stream with zlib.\n");
}
}
if (!*ext && strlen(s) <= PATH_MAX - 4) fprintf(stderr, "Couldn't open snapshot file:\n%s\n", filename);
strcat(s, ".frz");
if ((*file = OPEN_STREAM(s, read_only ? "rb" : "wb"))) return false;
return (TRUE);
return (FALSE);
} }
void S9xCloseSnapshotFile (STREAM file) void S9xCloseSnapshotFile (STREAM file)
@ -813,7 +803,7 @@ void S9xToggleSoundChannel (int c)
void S9xAutoSaveSRAM (void) void S9xAutoSaveSRAM (void)
{ {
Memory.SaveSRAM(S9xGetFilename(".srm", SRAM_DIR)); Memory.SaveSRAM(S9xGetFilename(".srm", SRAM_DIR).c_str());
} }
void S9xSyncSpeed (void) void S9xSyncSpeed (void)
@ -1607,7 +1597,7 @@ void S9xExit (void)
delete s_AudioOutput; delete s_AudioOutput;
#endif #endif
Memory.SaveSRAM(S9xGetFilename(".srm", SRAM_DIR)); Memory.SaveSRAM(S9xGetFilename(".srm", SRAM_DIR).c_str());
S9xResetSaveTimer(FALSE); S9xResetSaveTimer(FALSE);
S9xSaveCheatFile(S9xGetFilename(".cht", CHEAT_DIR)); S9xSaveCheatFile(S9xGetFilename(".cht", CHEAT_DIR));
S9xUnmapAllControls(); S9xUnmapAllControls();
@ -1711,34 +1701,21 @@ int main (int argc, char **argv)
if (!loaded) if (!loaded)
{ {
char s1[PATH_MAX + 1], s2[PATH_MAX + 1]; std::string s1, s2;
char drive[_MAX_DRIVE + 1], dir[_MAX_DIR + 1], fname[_MAX_FNAME + 1], ext[_MAX_EXT + 1];
s1[0] = s2[0] = 0;
if (Settings.CartAName[0]) if (Settings.CartAName[0])
{ {
_splitpath(Settings.CartAName, drive, dir, fname, ext); SplitPath path = splitpath(Settings.CartAName);
snprintf(s1, PATH_MAX + 1, "%s%s%s", S9xGetDirectory(ROM_DIR), SLASH_STR, fname); s1 = makepath("", S9xGetDirectory(ROM_DIR), path.stem, path.ext);
if (ext[0] && (strlen(s1) <= PATH_MAX - 1 - strlen(ext)))
{
strcat(s1, ".");
strcat(s1, ext);
}
} }
if (Settings.CartBName[0]) if (Settings.CartBName[0])
{ {
_splitpath(Settings.CartBName, drive, dir, fname, ext); SplitPath path = splitpath(Settings.CartBName);
snprintf(s2, PATH_MAX + 1, "%s%s%s", S9xGetDirectory(ROM_DIR), SLASH_STR, fname); s2 = makepath("", S9xGetDirectory(ROM_DIR), path.stem, path.ext);
if (ext[0] && (strlen(s2) <= PATH_MAX - 1 - strlen(ext)))
{
strcat(s2, ".");
strcat(s2, ext);
}
} }
loaded = Memory.LoadMultiCart(s1, s2); loaded = Memory.LoadMultiCart(s1.c_str(), s2.c_str());
} }
} }
else else
@ -1748,18 +1725,9 @@ int main (int argc, char **argv)
if (!loaded && rom_filename[0]) if (!loaded && rom_filename[0])
{ {
char s[PATH_MAX + 1]; SplitPath path = splitpath(rom_filename);
char drive[_MAX_DRIVE + 1], dir[_MAX_DIR + 1], fname[_MAX_FNAME + 1], ext[_MAX_EXT + 1]; std::string s = makepath("", S9xGetDirectory(ROM_DIR), path.stem, path.ext);
loaded = Memory.LoadROM(s.c_str());
_splitpath(rom_filename, drive, dir, fname, ext);
snprintf(s, PATH_MAX + 1, "%s%s%s", S9xGetDirectory(ROM_DIR), SLASH_STR, fname);
if (ext[0] && (strlen(s) <= PATH_MAX - 1 - strlen(ext)))
{
strcat(s, ".");
strcat(s, ext);
}
loaded = Memory.LoadROM(s);
} }
} }
@ -1772,7 +1740,7 @@ int main (int argc, char **argv)
S9xDeleteCheats(); S9xDeleteCheats();
S9xCheatsEnable(); S9xCheatsEnable();
NSRTControllerSetup(); NSRTControllerSetup();
Memory.LoadSRAM(S9xGetFilename(".srm", SRAM_DIR)); Memory.LoadSRAM(S9xGetFilename(".srm", SRAM_DIR).c_str());
if (Settings.ApplyCheats) if (Settings.ApplyCheats)
{ {

View File

@ -1631,40 +1631,6 @@ void S9xProcessEvents (bool8 block)
const char * S9xSelectFilename (const char *def, const char *dir1, const char *ext1, const char *title) const char * S9xSelectFilename (const char *def, const char *dir1, const char *ext1, const char *title)
{ {
static char s[PATH_MAX + 1];
char buffer[PATH_MAX + 1];
SetXRepeat(TRUE);
printf("\n%s (default: %s): ", title, def);
fflush(stdout);
SetXRepeat(FALSE);
if (fgets(buffer, PATH_MAX + 1, stdin))
{
char drive[_MAX_DRIVE + 1], dir[_MAX_DIR + 1], fname[_MAX_FNAME + 1], ext[_MAX_EXT + 1];
char *p = buffer;
while (isspace(*p))
p++;
if (!*p)
{
strncpy(buffer, def, PATH_MAX + 1);
buffer[PATH_MAX] = 0;
p = buffer;
}
char *q = strrchr(p, '\n');
if (q)
*q = 0;
_splitpath(p, drive, dir, fname, ext);
_makepath(s, drive, *dir ? dir : dir1, fname, *ext ? ext : ext1);
return (s);
}
return (NULL); return (NULL);
} }