aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraliaspider2014-11-02 06:31:17 +0100
committeraliaspider2014-11-02 06:31:17 +0100
commit188fe860e0af98aa51a727dbda794f479a665617 (patch)
treec15282a958dc0250e12533d63f36447d379a4cc3
parent95b02f090c236201951795b2544bfb471e299fcd (diff)
downloadsnesemu-188fe860e0af98aa51a727dbda794f479a665617.tar.gz
snesemu-188fe860e0af98aa51a727dbda794f479a665617.tar.bz2
snesemu-188fe860e0af98aa51a727dbda794f479a665617.zip
implement rom loading from memory.
-rw-r--r--Makefile6
-rw-r--r--libretro.c8
-rw-r--r--source/memmap.c183
-rw-r--r--source/memmap.h4
-rw-r--r--source/snes9x.h3
5 files changed, 55 insertions, 149 deletions
diff --git a/Makefile b/Makefile
index 826b382..8545a2c 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,7 @@
DEBUG = 0
PERF_TEST = 1
HAVE_GRIFFIN = 1
+LOAD_FROM_MEMORY_TEST = 1
ifeq ($(platform),)
platform = unix
@@ -147,6 +148,11 @@ ifeq ($(PERF_TEST),1)
FLAGS += -DPERF_TEST
endif
+
+ifeq ($(LOAD_FROM_MEMORY_TEST),1)
+FLAGS += -DLOAD_FROM_MEMORY_TEST
+endif
+
LDFLAGS += $(fpic) -lz $(SHARED)
FLAGS += $(fpic)
FLAGS += $(INCFLAGS)
diff --git a/libretro.c b/libretro.c
index 2cb5b00..38a268c 100644
--- a/libretro.c
+++ b/libretro.c
@@ -553,7 +553,11 @@ unsigned retro_get_region(void)
}
void retro_get_system_info(struct retro_system_info* info)
{
+#ifdef LOAD_FROM_MEMORY_TEST
+ info->need_fullpath = false;
+#else
info->need_fullpath = true;
+#endif
info->valid_extensions = "smc|fig|sfc|gd3|gd7|dx2|bsx|swc";
info->library_version = "v1.4";
info->library_name = "SNES9x(CATSFC)";
@@ -728,7 +732,11 @@ bool retro_load_game(const struct retro_game_info* game)
{
CPU.Flags = 0;
+#ifdef LOAD_FROM_MEMORY_TEST
+ if (!LoadROM(game))
+#else
if (!LoadROM(game->path))
+#endif
return false;
Settings.FrameTime = (Settings.PAL ? Settings.FrameTimePAL :
diff --git a/source/memmap.c b/source/memmap.c
index 09149f2..c058002 100644
--- a/source/memmap.c
+++ b/source/memmap.c
@@ -578,7 +578,11 @@ void FreeSDD1Data()
/* This function loads a Snes-Backup image */
/**********************************************************************************************/
+#ifdef LOAD_FROM_MEMORY_TEST
+bool LoadROM(const struct retro_game_info* game)
+#else
bool8 LoadROM(const char* filename)
+#endif
{
int32 TotalFileSize = 0;
bool8 Interleaved = FALSE;
@@ -605,13 +609,41 @@ again:
Settings.DisplayColor = 0xffff;
SET_UI_COLOR(255, 255, 255);
+#ifdef LOAD_FROM_MEMORY_TEST
+ strncpy(Memory.ROMFilename, game->path, sizeof(Memory.ROMFilename));
+
+ Memory.HeaderCount = 0;
+ TotalFileSize = game->size;
+ const uint8_t* src = game->data;
+ Memory.HeaderCount = 0;
+
+ if ((((game->size & 0x1FFF) == 0x200) && !Settings.ForceNoHeader)
+ || Settings.ForceHeader)
+ {
+ S9xMessage(S9X_INFO, S9X_HEADERS_INFO,
+ "Found ROM file header (and ignored it).");
+ TotalFileSize -= 0x200;
+ src += 0x200;
+ Memory.HeaderCount = 1;
+
+ }
+ else
+ {
+ S9xMessage(S9X_INFO, S9X_HEADERS_INFO, "No ROM file header found.");
+ }
+ if (TotalFileSize > MAX_ROM_SIZE)
+ return false;
+
+ memcpy(Memory.ROM, src, TotalFileSize);
+
+#else
TotalFileSize = FileLoader(Memory.ROM, filename, MAX_ROM_SIZE);
if (!TotalFileSize)
return FALSE; // it ends here
else if (!Settings.NoPatch)
CheckForIPSPatch(filename, Memory.HeaderCount != 0, &TotalFileSize);
-
+#endif
//fix hacked games here.
if ((strncmp("HONKAKUHA IGO GOSEI", (char*)&Memory.ROM[0x7FC0], 19) == 0)
&& (Memory.ROM[0x7FD5] != 0x31))
@@ -641,7 +673,8 @@ again:
S9xMessage(S9X_ERROR, S9X_ROM_CONFUSING_FORMAT_INFO, "Warning! Hacked Dump!");
}
- int hi_score, lo_score;
+ int hi_score=ScoreHiROM(TRUE, 0);
+ int lo_score=ScoreLoROM(TRUE, 0);
if (Memory.HeaderCount == 0 && !Settings.ForceNoHeader &&
((hi_score > lo_score && ScoreHiROM(TRUE, 0) > hi_score) ||
@@ -886,6 +919,7 @@ again:
return (TRUE);
}
+#ifndef LOAD_FROM_MEMORY_TEST
uint32 FileLoader(uint8* buffer, const char* filename, int32 maxsize)
{
@@ -1005,151 +1039,6 @@ uint32 FileLoader(uint8* buffer, const char* filename, int32 maxsize)
return TotalFileSize;
}
-
-#if 0
-/**********************************************************************************************/
-/* LoadMulti() */
-/* This function loads a Slotted SNES-Backup image and fills the slot. */
-/**********************************************************************************************/
-
-bool8 LoadMulti(const char* basename, const char* slot1name,
- const char* slot2name)
-{
- unsigned long FileSize = 0;
-
- if (*basename == '\0')
- return FALSE;
-
- SufamiTurbo = TRUE;
-
- int32 offset;
-
- memset(&SNESGameFixes, 0, sizeof(SNESGameFixes));
- SNESGameFixes.SRAMInitialValue = 0x60;
-
- memset(bytes0x2000, 0, 0x2000);
-
- CalculatedSize = 0;
-
- Settings.DisplayColor = 0xffff;
- SET_UI_COLOR(255, 255, 255);
-
- int32 TotalFileSize = FileLoader(ROM, basename, MAX_ROM_SIZE);
-
- if (0 == TotalFileSize)
- return FALSE;
- else CheckForIPSPatch(basename, HeaderCount != 0, TotalFileSize);
-
- CalculatedSize = TotalFileSize;
-
- for (offset = 0; offset < TotalFileSize; offset += 0x100000);
-
- //insert base type test here.
-
- if (slot1name[0] != '\0')
- {
-
- TotalFileSize = FileLoader(ROM + offset, slot1name, MAX_ROM_SIZE);
-
- if (0 == TotalFileSize)
- return FALSE;
- else CheckForIPSPatch(slot1name, HeaderCount != 0, TotalFileSize);
- ROMOffset1 = &ROM[offset];
- Slot1Size = TotalFileSize;
- }
- int32 temp = offset;
- for (; offset < temp + TotalFileSize; offset += 0x100000);
-
- if (slot2name[0] != '\0')
- {
- TotalFileSize = FileLoader(ROM + offset, slot2name, MAX_ROM_SIZE);
-
- if (0 == TotalFileSize)
- return FALSE;
- else CheckForIPSPatch(slot2name, HeaderCount != 0, TotalFileSize);
- ROMOffset2 = &ROM[offset];
- Slot2Size = TotalFileSize;
- }
-
- InitROM(FALSE);
- S9xLoadCheatFile(S9xGetFilename(".cht"));
- S9xInitCheatData();
- S9xApplyCheats();
-
- S9xReset();
-
- return (TRUE);
-}
-
-bool8 SufamiTurboBIOSSig(uint8* file, int32 size)
-{
- if (!strcmp((char*)file, "BANDAI SFC-ADX")
- && !strcmp((char*)(file + 0x10), "SFC-ADX BACKUP"))
- {
- //possible match.
- //check size
- if (size != 0x40000)
- return FALSE;
- //and CRC32
- if (0x9B4CA911 == caCRC32(file, size, 0xFFFFFFFF))
- return TRUE;
-
- }
- return FALSE;
-}
-
-bool8 SufamiTurboCartSig(uint8* file, int32 size)
-{
- //test not a BIOS
- if (!strcmp((char*)file, "BANDAI SFC-ADX")
- && strcmp((char*)(file + 0x10), "SFC-ADX BACKUP"))
- {
- //possible match.
- //check size
- if (size > 0x100000 || size < 0x80000)
- return FALSE;
- //probably a minicart
- return TRUE;
- }
- return FALSE;
-}
-
-bool8 SameGameSig(uint8* file, int32 size)
-{
- //preheader sig
- if (strcmp((char*)(file + 0xFFA0), "1995/12/16 10:2018ZS5J"))
- return FALSE;
- if (size != 0x100000)
- return FALSE;
- if (0x133E1C5B == caCRC32(file, size, 0xFFFFFFFF))
- return TRUE;
- return FALSE;
-}
-bool8 GNextSig(uint8* file, int32 size)
-{
- //preheader sig
- if (strcmp((char*)(file + 0xFFAA), "GNEXT B2ZX3J"))
- return FALSE;
- if (size != 0x180000)
- return FALSE;
- if (0x845E420D == caCRC32(file, size, 0xFFFFFFFF))
- return TRUE;
- return FALSE;
-}
-int MultiType(uint8* file, int32 size)
-{
- //check for ST signiture
- if (SufamiTurboBIOSSig(file, size))
- return 1;
- //check for Same Game signiture
- if (SameGameSig(file, size))
- return 2;
- //check for G-Next signiture
- if (GNextSig(file, size))
- return 3;
- return 0;
-}
-
#endif
//compatibility wrapper
diff --git a/source/memmap.h b/source/memmap.h
index d5d89b1..4614e83 100644
--- a/source/memmap.h
+++ b/source/memmap.h
@@ -137,8 +137,12 @@
#define BIGFIRST 2
#define SMALLFIRST 3
+#ifdef LOAD_FROM_MEMORY_TEST
+bool LoadROM(const struct retro_game_info* game);
+#else
bool8 LoadROM(const char*);
uint32 FileLoader(uint8* buffer, const char* filename, int32 maxsize);
+#endif
void InitROM(bool8);
bool8 LoadSRAM(const char*);
bool8 SaveSRAM(const char*);
diff --git a/source/snes9x.h b/source/snes9x.h
index 7d94fc7..912f101 100644
--- a/source/snes9x.h
+++ b/source/snes9x.h
@@ -95,8 +95,7 @@
#include <stdlib.h>
#include <stdint.h>
-//#include "fs_api.h"
-//#include "ds2_malloc.h"
+#include <libretro.h>
extern int cprintf(const char* fmt, ...);