aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libretro.c79
-rw-r--r--source/cheats.h12
-rw-r--r--source/cheats2.c75
-rw-r--r--source/display.h2
-rw-r--r--source/memmap.c127
-rw-r--r--source/port.h3
-rw-r--r--source/spc7110.c2
7 files changed, 86 insertions, 214 deletions
diff --git a/libretro.c b/libretro.c
index 2cccd7f..9c289e7 100644
--- a/libretro.c
+++ b/libretro.c
@@ -247,82 +247,7 @@ void S9xInitDisplay(void)
GFX.Delta = (GFX.SubScreen - GFX.Screen) >> 1;
}
-#ifndef _WIN32
-void _makepath(char* path, const char* drive, const char* dir, const char* fname, const char* ext)
-{
- (void) drive;
-
- if (dir && *dir)
- {
- strcpy(path, dir);
- strcat(path, "/");
- }
- else
- *path = 0;
-
- if (fname)
- strcat(path, fname);
-
- if (ext && *ext)
- {
- strcat(path, ".");
- strcat(path, ext);
- }
-}
-
-void _splitpath (const char* path, char* drive, char* dir, char* fname, char* ext)
-{
- const char* slash = strrchr(path, '/');
- const char* dot = strrchr(path, '.');
- (void) drive;
-
- if (!slash)
- slash = strrchr((char*)path, '\\');
-
- if (dot && slash && dot < slash)
- dot = NULL;
-
- if (!slash)
- {
- *dir = 0;
- strcpy(fname, path);
- if (dot)
- {
- fname[dot - path] = 0;
- strcpy(ext, dot + 1);
- }
- else
- *ext = 0;
- }
- else
- {
- strcpy(dir, path);
- dir[slash - path] = 0;
- strcpy(fname, slash + 1);
- if (dot)
- {
- fname[dot - slash - 1] = 0;
- strcpy(ext, dot + 1);
- }
- else
- *ext = 0;
- }
-}
-#endif
-
-const char* S9xGetFilename(const char* in)
-{
- static char filename [PATH_MAX + 1];
- char drive [_MAX_DRIVE + 1];
- char dir [_MAX_DIR + 1];
- char fname [_MAX_FNAME + 1];
- char ext [_MAX_EXT + 1];
- _splitpath(Memory.ROMFilename, drive, dir, fname, ext);
- _makepath(filename, drive, dir, fname, in);
- return filename;
-}
-
-void init_sfc_setting(void)
+static void init_sfc_setting(void)
{
memset(&Settings, 0, sizeof(Settings));
Settings.JoystickEnabled = false;
@@ -349,7 +274,7 @@ void init_sfc_setting(void)
}
#ifdef USE_BLARGG_APU
-static void S9xAudioCallback()
+static void S9xAudioCallback(void)
{
size_t avail;
/* Just pick a big buffer. We won't use it all. */
diff --git a/source/cheats.h b/source/cheats.h
index df8a9a6..94caf2b 100644
--- a/source/cheats.h
+++ b/source/cheats.h
@@ -42,21 +42,19 @@ typedef enum
S9X_8_BITS, S9X_16_BITS, S9X_24_BITS, S9X_32_BITS
} S9xCheatDataSize;
-void S9xInitCheatData();
+void S9xInitCheatData(void);
const char* S9xGameGenieToRaw(const char* code, uint32_t* address, uint8_t* byte);
const char* S9xProActionReplayToRaw(const char* code, uint32_t* address, uint8_t* byte);
const char* S9xGoldFingerToRaw(const char* code, uint32_t* address, bool* sram, uint8_t* num_bytes, uint8_t bytes[3]);
-void S9xApplyCheats();
+void S9xApplyCheats(void);
void S9xApplyCheat(uint32_t which1);
-void S9xRemoveCheats();
+void S9xRemoveCheats(void);
void S9xRemoveCheat(uint32_t which1);
void S9xEnableCheat(uint32_t which1);
void S9xDisableCheat(uint32_t which1);
-void S9xDisableAllCheat();
+void S9xDisableAllCheat(void);
void S9xAddCheat(bool enable, bool save_current_value, uint32_t address, uint8_t byte);
-void S9xDeleteCheats();
+void S9xDeleteCheats(void);
void S9xDeleteCheat(uint32_t which1);
-bool S9xLoadCheatFile(const char* filename);
-bool S9xSaveCheatFile(const char* filename);
#endif
diff --git a/source/cheats2.c b/source/cheats2.c
index 067a929..11595e2 100644
--- a/source/cheats2.c
+++ b/source/cheats2.c
@@ -124,78 +124,3 @@ void S9xRemoveCheats(void)
if (Cheat.c [i].enabled)
S9xRemoveCheat(i);
}
-
-bool S9xLoadCheatFile(const char* filename)
-{
- uint8_t data [8 + MAX_SFCCHEAT_NAME];
- FILE* fs = fopen(filename, "rb");
- Cheat.num_cheats = 0;
-
- if (!fs)
- return false;
-
- while (fread((void*) data, 1, 8 + MAX_SFCCHEAT_NAME, fs) == 8 + MAX_SFCCHEAT_NAME)
- {
- if (data[6] != 254 || data[7] != 252)
- {
- fclose(fs);
- return false;
- }
- Cheat.c [Cheat.num_cheats].enabled = (data [0] & 4) == 0;
- Cheat.c [Cheat.num_cheats].byte = data [1];
- Cheat.c [Cheat.num_cheats].address = data [2] | (data [3] << 8) | (data [4] << 16);
- Cheat.c [Cheat.num_cheats].saved_byte = data [5];
- Cheat.c [Cheat.num_cheats].saved = (data [0] & 8) != 0;
- memcpy(Cheat.c [Cheat.num_cheats].name, &data [8], MAX_SFCCHEAT_NAME - 1);
- Cheat.c [Cheat.num_cheats++].name [MAX_SFCCHEAT_NAME - 1] = 0;
- }
- fclose(fs);
-
- return true;
-}
-
-bool S9xSaveCheatFile(const char* filename)
-{
- uint32_t i;
- uint8_t data [8 + MAX_SFCCHEAT_NAME];
- FILE* fs;
-
- if (Cheat.num_cheats == 0)
- {
- (void) remove(filename);
- return true;
- }
-
- fs = fopen(filename, "wb");
-
- if (!fs)
- return false;
-
- for (i = 0; i < Cheat.num_cheats; i++)
- {
- memset(data, 0, 8 + MAX_SFCCHEAT_NAME);
- data [6] = 254;
- data [7] = 252;
- if (!Cheat.c [i].enabled)
- data [0] |= 4;
-
- if (Cheat.c [i].saved)
- data [0] |= 8;
-
- data [1] = Cheat.c [i].byte;
- data [2] = (uint8_t) Cheat.c [i].address;
- data [3] = (uint8_t)(Cheat.c [i].address >> 8);
- data [4] = (uint8_t)(Cheat.c [i].address >> 16);
- data [5] = Cheat.c [i].saved_byte;
-
- memcpy(&data [8], Cheat.c [i].name, MAX_SFCCHEAT_NAME - 1);
- if (fwrite(data, 8 + MAX_SFCCHEAT_NAME, 1, fs) != 1)
- {
- fclose(fs);
- return false;
- }
- }
-
- fclose(fs);
- return true;
-}
diff --git a/source/display.h b/source/display.h
index 213955b..ee40183 100644
--- a/source/display.h
+++ b/source/display.h
@@ -12,6 +12,4 @@ void S9xInitDisplay(void);
void S9xDeinitDisplay(void);
void S9xToggleSoundChannel(int32_t channel);
void S9xNextController(void);
-
-const char* S9xGetFilename(const char* extension);
#endif
diff --git a/source/memmap.c b/source/memmap.c
index da04eb4..f382066 100644
--- a/source/memmap.c
+++ b/source/memmap.c
@@ -350,6 +350,66 @@ void S9xDeinitMemory(void)
}
#ifndef LOAD_FROM_MEMORY
+static void _makepath(char* path,
+ const char* dir, const char* fname, const char* ext)
+{
+ if (dir && *dir)
+ {
+ strcpy(path, dir);
+ strcat(path, "/");
+ }
+ else
+ *path = 0;
+
+ if (fname)
+ strcat(path, fname);
+
+ if (ext && *ext)
+ {
+ strcat(path, ".");
+ strcat(path, ext);
+ }
+}
+
+static void _splitpath (const char* path,
+ char* dir, char* fname, char* ext)
+{
+ const char* slash = strrchr(path, '/');
+ const char* dot = strrchr(path, '.');
+
+ if (!slash)
+ slash = strrchr((char*)path, '\\');
+
+ if (dot && slash && dot < slash)
+ dot = NULL;
+
+ if (!slash)
+ {
+ *dir = 0;
+ strcpy(fname, path);
+ if (dot)
+ {
+ fname[dot - path] = 0;
+ strcpy(ext, dot + 1);
+ }
+ else
+ *ext = 0;
+ }
+ else
+ {
+ strcpy(dir, path);
+ dir[slash - path] = 0;
+ strcpy(fname, slash + 1);
+ if (dot)
+ {
+ fname[dot - slash - 1] = 0;
+ strcpy(ext, dot + 1);
+ }
+ else
+ *ext = 0;
+ }
+}
+
/* Read variable size MSB int from a file */
static int32_t ReadInt(FILE* f, uint32_t nbytes)
{
@@ -364,20 +424,30 @@ static int32_t ReadInt(FILE* f, uint32_t nbytes)
return v;
}
+static const char* S9xGetFilename(const char* in)
+{
+ static char filename [PATH_MAX + 1];
+ char dir [_MAX_DIR + 1];
+ char fname [_MAX_FNAME + 1];
+ char ext [_MAX_EXT + 1];
+ _splitpath(Memory.ROMFilename, dir, fname, ext);
+ _makepath(filename, dir, fname, in);
+ return filename;
+}
+
#define IPS_EOF 0x00454F46l
static void CheckForIPSPatch(const char* rom_filename, bool header, int32_t* rom_size)
{
char dir [_MAX_DIR + 1];
- char drive [_MAX_DRIVE + 1];
char name [_MAX_FNAME + 1];
char ext [_MAX_EXT + 1];
char fname [_MAX_PATH + 1];
FILE* patch_file = NULL;
int32_t offset = header ? 512 : 0;
- _splitpath(rom_filename, drive, dir, name, ext);
- _makepath(fname, drive, dir, name, "ips");
+ _splitpath(rom_filename, dir, name, ext);
+ _makepath(fname, dir, name, "ips");
if (!(patch_file = fopen(fname, "rb")))
if (!(patch_file = fopen(S9xGetFilename("ips"), "rb")))
@@ -462,19 +532,17 @@ err_eof:
static uint32_t FileLoader(uint8_t* buffer, const char* filename, int32_t maxsize)
{
FILE* ROMFile;
- int32_t TotalFileSize = 0;
int32_t len = 0;
char dir [_MAX_DIR + 1];
- char drive [_MAX_DRIVE + 1];
char name [_MAX_FNAME + 1];
char ext [_MAX_EXT + 1];
char fname [_MAX_PATH + 1];
uint32_t FileSize = 0;
- _splitpath(filename, drive, dir, name, ext);
- _makepath(fname, drive, dir, name, ext);
+ _splitpath(filename, dir, name, ext);
+ _makepath(fname, dir, name, ext);
#ifdef _WIN32
/* memmove required: Overlapping addresses [Neb] */
@@ -484,20 +552,17 @@ static uint32_t FileLoader(uint8_t* buffer, const char* filename, int32_t maxsiz
if ((ROMFile = fopen(fname, "rb")) == NULL)
return 0;
- strcpy(Memory.ROMFilename, fname);
-
Memory.HeaderCount = 0;
uint8_t* ptr = buffer;
- bool more = false;
- do
{
int32_t calc_size;
FileSize = fread(ptr, 1, maxsize + 0x200 - (ptr - Memory.ROM), ROMFile);
fclose(ROMFile);
calc_size = FileSize & ~0x1FFF; /* round to the lower 0x2000 */
- if ((FileSize - calc_size == 512 && !Settings.ForceNoHeader) || Settings.ForceHeader)
+ if ((FileSize - calc_size == 512 && !Settings.ForceNoHeader)
+ || Settings.ForceHeader)
{
/* memmove required: Overlapping addresses [Neb] */
/* DS2 DMA notes: Can be split into 512-byte DMA blocks [Neb] */
@@ -519,41 +584,10 @@ static uint32_t FileLoader(uint8_t* buffer, const char* filename, int32_t maxsiz
FileSize -= 512;
}
- ptr += FileSize;
- TotalFileSize += FileSize;
-
-
- /* check for multi file roms */
-
- if ((ptr - Memory.ROM) < (maxsize + 0x200) && (isdigit(ext [0]) && ext [1] == 0 && ext [0] < '9'))
- {
- more = true;
- ext [0]++;
-#ifdef _WIN32
- /* memmove required: Overlapping addresses [Neb] */
- memmove(&ext [1], &ext [0], 4);
- ext [0] = '.';
-#endif
- _makepath(fname, drive, dir, name, ext);
- }
- else if (ptr - Memory.ROM < maxsize + 0x200 && (((len = strlen(name)) == 7 || len == 8) && strncasecmp(name, "sf", 2) == 0 && isdigit(name [2]) && isdigit(name [3]) && isdigit(name [4]) && isdigit(name [5]) && isalpha(name [len - 1])))
- {
- more = true;
- name [len - 1]++;
-#ifdef _WIN32
- /* memmove required: Overlapping addresses [Neb] */
- memmove(&ext [1], &ext [0], 4);
- ext [0] = '.';
-#endif
- _makepath(fname, drive, dir, name, ext);
- }
- else
- more = false;
-
+ ptr += FileSize;
}
- while (more && (ROMFile = fopen(fname, "rb")) != NULL);
- return TotalFileSize;
+ return FileSize;
}
#endif
@@ -589,8 +623,6 @@ bool LoadROM(
again:
#ifdef LOAD_FROM_MEMORY
- strncpy(Memory.ROMFilename, game->path, sizeof(Memory.ROMFilename));
-
Memory.HeaderCount = 0;
TotalFileSize = game->size;
src = game->data;
@@ -927,7 +959,6 @@ again:
Tales = true;
InitROM(Tales);
- S9xLoadCheatFile(S9xGetFilename("cht"));
S9xInitCheatData();
S9xApplyCheats();
S9xReset();
diff --git a/source/port.h b/source/port.h
index fcfe836..5defb76 100644
--- a/source/port.h
+++ b/source/port.h
@@ -43,9 +43,6 @@
#ifndef _MAX_PATH
#define _MAX_PATH PATH_MAX
#endif
-
-void _makepath(char* path, const char* drive, const char* dir, const char* fname, const char* ext);
-void _splitpath(const char* path, char* drive, char* dir, char* fname, char* ext);
#else /* _WIN32 */
#define strcasecmp stricmp
#define strncasecmp strnicmp
diff --git a/source/spc7110.c b/source/spc7110.c
index 249bbc9..67fd068 100644
--- a/source/spc7110.c
+++ b/source/spc7110.c
@@ -5,8 +5,6 @@
#include "memmap.h"
#include <time.h>
-const char* S9xGetFilename(const char*);
-
SPC7110Regs s7r; /* SPC7110 registers, about 33KB */
S7RTC rtc_f9; /* FEOEZ (and Shounen Jump no SHou) RTC */
void S9xUpdateRTC(void); /* S-RTC function hacked to work with the RTC */