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 \"/()\" \"___\"`
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
ifdef S9XDEBUGGER

View File

@ -28,7 +28,7 @@
#include <sys/ioctl.h>
#endif
#ifndef NOSOUND
#ifndef NOSOUND
#ifndef ALSA
#include <sys/soundcard.h>
#include <sys/mman.h>
@ -51,6 +51,7 @@
#include "movie.h"
#include "display.h"
#include "conffile.h"
#include "fscompat.h"
#ifdef NETPLAY_SUPPORT
#include "netplay.h"
#endif
@ -359,7 +360,7 @@ void S9xExtraUsage (void)
#endif
#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");
#endif
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 (i + 1 < argc)
strncpy(Settings.CartAName, argv[++i], _MAX_PATH);
strncpy(Settings.CartAName, argv[++i], PATH_MAX);
else
S9xUsage();
}
@ -400,7 +401,7 @@ void S9xParseArg (char **argv, int &i, int argc)
if (!strcasecmp(argv[i], "-cartb"))
{
if (i + 1 < argc)
strncpy(Settings.CartBName, argv[++i], _MAX_PATH);
strncpy(Settings.CartBName, argv[++i], PATH_MAX);
else
S9xUsage();
}
@ -605,7 +606,7 @@ void S9xParsePortConfig (ConfigFile &conf, int pass)
sound_device = conf.GetStringDup("Unix::SoundDevice", "/dev/dsp");
#else
sound_device = conf.GetStringDup("Unix::SoundDevice", "default");
#endif
#endif
keymaps.clear();
if (!conf.GetBool("Unix::ClearAllControls", false))
{
@ -670,78 +671,65 @@ static int make_snes9x_dirs (void)
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])
snprintf(s, PATH_MAX + 1, "%s%s%s", s9x_base_dir, SLASH_STR, dirNames[dirtype]);
if (dirNames[dirtype][0])
return std::string(s9x_base_dir) + SLASH_STR + dirNames[dirtype];
else
{
switch (dirtype)
{
case DEFAULT_DIR:
strncpy(s, s9x_base_dir, PATH_MAX + 1);
s[PATH_MAX] = 0;
retval = s9x_base_dir;
break;
case HOME_DIR:
strncpy(s, getenv("HOME"), PATH_MAX + 1);
s[PATH_MAX] = 0;
retval = std::string(getenv("HOME"));
break;
case ROMFILENAME_DIR:
strncpy(s, Memory.ROMFilename, PATH_MAX + 1);
s[PATH_MAX] = 0;
for (int i = strlen(s); i >= 0; i--)
{
if (s[i] == SLASH_CHAR)
{
s[i] = 0;
break;
}
}
retval = Memory.ROMFilename;
pos = retval.rfind("/");
if (pos != std::string::npos)
retval = retval.substr(pos);
break;
default:
s[0] = 0;
break;
}
}
return (s);
return retval;
}
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];
struct stat buf;
_splitpath(Memory.ROMFilename, drive, dir, fname, ext);
snprintf(s, PATH_MAX + 1, "%s%s%s%s", S9xGetDirectory(dirtype), SLASH_STR, fname, ex);
SplitPath path = splitpath(Memory.ROMFilename);
std::string directory = S9xGetDirectory(dirtype);
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;
_splitpath(Memory.ROMFilename, drive, dir, fname, ext);
d = S9xGetDirectory(dirtype);
if (ex[0] != '.')
{
ex = "." + ex;
}
std::string new_filename;
unsigned int i = 0;
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)
@ -756,26 +744,28 @@ const char * S9xBasename (const char *f)
bool8 S9xOpenSnapshotFile (const char *filename, bool8 read_only, STREAM *file)
{
char s[PATH_MAX + 1];
char drive[_MAX_DRIVE + 1], dir[_MAX_DIR + 1], fname[_MAX_FNAME + 1], ext[_MAX_EXT + 1];
if (read_only)
{
if ((*file = OPEN_STREAM(filename, "rb")))
return (true);
else
fprintf(stderr, "Failed to open file stream for reading.\n");
}
else
{
if ((*file = OPEN_STREAM(filename, "wb")))
{
return (true);
}
else
{
fprintf(stderr, "Couldn't open stream with zlib.\n");
}
}
_splitpath(filename, drive, dir, fname, ext);
fprintf(stderr, "Couldn't open snapshot file:\n%s\n", filename);
if (*drive || *dir == SLASH_CHAR || (strlen(dir) > 1 && *dir == '.' && *(dir + 1) == SLASH_CHAR))
{
strncpy(s, filename, PATH_MAX + 1);
s[PATH_MAX] = 0;
}
else
snprintf(s, PATH_MAX + 1, "%s%s%s", S9xGetDirectory(SNAPSHOT_DIR), SLASH_STR, fname);
if (!*ext && strlen(s) <= PATH_MAX - 4)
strcat(s, ".frz");
if ((*file = OPEN_STREAM(s, read_only ? "rb" : "wb")))
return (TRUE);
return (FALSE);
return false;
}
void S9xCloseSnapshotFile (STREAM file)
@ -813,7 +803,7 @@ void S9xToggleSoundChannel (int c)
void S9xAutoSaveSRAM (void)
{
Memory.SaveSRAM(S9xGetFilename(".srm", SRAM_DIR));
Memory.SaveSRAM(S9xGetFilename(".srm", SRAM_DIR).c_str());
}
void S9xSyncSpeed (void)
@ -1607,7 +1597,7 @@ void S9xExit (void)
delete s_AudioOutput;
#endif
Memory.SaveSRAM(S9xGetFilename(".srm", SRAM_DIR));
Memory.SaveSRAM(S9xGetFilename(".srm", SRAM_DIR).c_str());
S9xResetSaveTimer(FALSE);
S9xSaveCheatFile(S9xGetFilename(".cht", CHEAT_DIR));
S9xUnmapAllControls();
@ -1711,34 +1701,21 @@ int main (int argc, char **argv)
if (!loaded)
{
char s1[PATH_MAX + 1], s2[PATH_MAX + 1];
char drive[_MAX_DRIVE + 1], dir[_MAX_DIR + 1], fname[_MAX_FNAME + 1], ext[_MAX_EXT + 1];
s1[0] = s2[0] = 0;
std::string s1, s2;
if (Settings.CartAName[0])
{
_splitpath(Settings.CartAName, drive, dir, fname, ext);
snprintf(s1, PATH_MAX + 1, "%s%s%s", S9xGetDirectory(ROM_DIR), SLASH_STR, fname);
if (ext[0] && (strlen(s1) <= PATH_MAX - 1 - strlen(ext)))
{
strcat(s1, ".");
strcat(s1, ext);
}
SplitPath path = splitpath(Settings.CartAName);
s1 = makepath("", S9xGetDirectory(ROM_DIR), path.stem, path.ext);
}
if (Settings.CartBName[0])
{
_splitpath(Settings.CartBName, drive, dir, fname, ext);
snprintf(s2, PATH_MAX + 1, "%s%s%s", S9xGetDirectory(ROM_DIR), SLASH_STR, fname);
if (ext[0] && (strlen(s2) <= PATH_MAX - 1 - strlen(ext)))
{
strcat(s2, ".");
strcat(s2, ext);
}
SplitPath path = splitpath(Settings.CartBName);
s2 = makepath("", S9xGetDirectory(ROM_DIR), path.stem, path.ext);
}
loaded = Memory.LoadMultiCart(s1, s2);
loaded = Memory.LoadMultiCart(s1.c_str(), s2.c_str());
}
}
else
@ -1748,18 +1725,9 @@ int main (int argc, char **argv)
if (!loaded && rom_filename[0])
{
char s[PATH_MAX + 1];
char drive[_MAX_DRIVE + 1], dir[_MAX_DIR + 1], fname[_MAX_FNAME + 1], ext[_MAX_EXT + 1];
_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);
SplitPath path = splitpath(rom_filename);
std::string s = makepath("", S9xGetDirectory(ROM_DIR), path.stem, path.ext);
loaded = Memory.LoadROM(s.c_str());
}
}
@ -1772,7 +1740,7 @@ int main (int argc, char **argv)
S9xDeleteCheats();
S9xCheatsEnable();
NSRTControllerSetup();
Memory.LoadSRAM(S9xGetFilename(".srm", SRAM_DIR));
Memory.LoadSRAM(S9xGetFilename(".srm", SRAM_DIR).c_str());
if (Settings.ApplyCheats)
{

View File

@ -622,7 +622,7 @@ static bool8 SetupXvideo()
printf("Selected XvRGB format: %d bpp\n",GUI.xv_bpp);
} else {
// use I420 or YUY2
if(GUI.xv_format == FOURCC_I420) {
if(GUI.xv_format == FOURCC_I420) {
printf("Xvideo I420 image format.\n");
} else {
printf("Xvideo YUY2 image format.\n");
@ -1631,40 +1631,6 @@ void S9xProcessEvents (bool8 block)
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);
}