From 3556445660de35afe11411bfe49f811e7afff172 Mon Sep 17 00:00:00 2001 From: Themaister Date: Fri, 2 Dec 2011 19:12:47 +0100 Subject: [PATCH] Add new extension support. --- dynamic.c | 17 +++++++++++++---- file.c | 31 +++++++++++++++++++++++-------- general.h | 1 + libsnes.hpp | 35 +++++++++++++++++++++++++++-------- 4 files changed, 64 insertions(+), 20 deletions(-) diff --git a/dynamic.c b/dynamic.c index ce113f6832..9546336bc7 100644 --- a/dynamic.c +++ b/dynamic.c @@ -285,14 +285,14 @@ static bool environment_cb(unsigned cmd, void *data) { case SNES_ENVIRONMENT_GET_FULLPATH: *(const char**)data = g_extern.system.fullpath; - SSNES_LOG("FULLPATH: \"%s\"\n", g_extern.system.fullpath); + SSNES_LOG("Environ FULLPATH: \"%s\"\n", g_extern.system.fullpath); break; case SNES_ENVIRONMENT_SET_GEOMETRY: g_extern.system.geom = *(const struct snes_geometry*)data; g_extern.system.geom.max_width = next_pow2(g_extern.system.geom.max_width); g_extern.system.geom.max_height = next_pow2(g_extern.system.geom.max_height); - SSNES_LOG("SET_GEOMETRY: (%ux%u) / (%ux%u)\n", + SSNES_LOG("Environ SET_GEOMETRY: (%ux%u) / (%ux%u)\n", g_extern.system.geom.base_width, g_extern.system.geom.base_height, g_extern.system.geom.max_width, @@ -301,24 +301,32 @@ static bool environment_cb(unsigned cmd, void *data) case SNES_ENVIRONMENT_SET_PITCH: g_extern.system.pitch = *(const unsigned*)data; - SSNES_LOG("SET_PITCH: %u\n", g_extern.system.pitch); + SSNES_LOG("Environ SET_PITCH: %u\n", g_extern.system.pitch); break; case SNES_ENVIRONMENT_GET_OVERSCAN: *(bool*)data = !g_settings.video.crop_overscan; - SSNES_LOG("GET_OVERSCAN: %u\n", (unsigned)!g_settings.video.crop_overscan); + SSNES_LOG("Environ GET_OVERSCAN: %u\n", (unsigned)!g_settings.video.crop_overscan); break; case SNES_ENVIRONMENT_SET_TIMING: g_extern.system.timing = *(const struct snes_system_timing*)data; g_extern.system.timing_set = true; + SSNES_LOG("Environ SET_TIMING: %.3lf Hz/ %.3lf Hz\n", g_extern.system.timing.fps, g_extern.system.timing.sample_rate); break; case SNES_ENVIRONMENT_GET_CAN_DUPE: *(bool*)data = true; + SSNES_LOG("Environ GET_CAN_DUPE: true\n"); + break; + + case SNES_ENVIRONMENT_SET_NEED_FULLPATH: + g_extern.system.need_fullpath = *(const bool*)data; + SSNES_LOG("Environ SET_NEED_FULLPATH: %s\n", g_extern.system.need_fullpath ? "true" : "false"); break; default: + SSNES_LOG("Environ UNSUPPORTED (#%u)!\n", cmd); return false; } @@ -345,6 +353,7 @@ static void set_environment(void) // Assume SNES as defaults. static void set_environment_defaults(void) { + SSNES_LOG("Setting environment defaults (SNES)\n"); g_extern.system.pitch = 0; // 0 is classic libsnes semantics. g_extern.system.geom = (struct snes_geometry) { .base_width = 256, diff --git a/file.c b/file.c index 0248d6588f..a064c69adc 100644 --- a/file.c +++ b/file.c @@ -735,19 +735,34 @@ static bool load_normal_rom(void) void *rom_buf = NULL; ssize_t rom_len = 0; - if ((rom_len = read_rom_file(g_extern.rom_file, &rom_buf)) == -1) + if (!g_extern.system.need_fullpath) { - SSNES_ERR("Could not read ROM file.\n"); - return false; + if ((rom_len = read_rom_file(g_extern.rom_file, &rom_buf)) == -1) + { + SSNES_ERR("Could not read ROM file.\n"); + return false; + } + + if (g_extern.rom_file) + fclose(g_extern.rom_file); + + SSNES_LOG("ROM size: %d bytes\n", (int)rom_len); + } + else + { + if (!g_extern.rom_file) + { + SSNES_ERR("Implementation requires a full path to be set, cannot load ROM from stdin. Aborting ...\n"); + exit(1); + } - if (g_extern.rom_file != NULL) fclose(g_extern.rom_file); - - SSNES_LOG("ROM size: %d bytes\n", (int)rom_len); - - char *xml_buf = load_xml_map(g_extern.xml_name); + SSNES_LOG("ROM loading skipped. Implementation will load it on its own.\n"); + } + char *xml_buf = load_xml_map(g_extern.xml_name); + if (!psnes_load_cartridge_normal(xml_buf, rom_buf, rom_len)) { SSNES_ERR("ROM file is not valid!\n"); diff --git a/general.h b/general.h index cc6eab9af4..46e59c0576 100644 --- a/general.h +++ b/general.h @@ -219,6 +219,7 @@ struct global char fullpath[MAXPATHLEN]; struct snes_system_timing timing; bool timing_set; + bool need_fullpath; } system; struct diff --git a/libsnes.hpp b/libsnes.hpp index 07483e8258..68a34a62fa 100755 --- a/libsnes.hpp +++ b/libsnes.hpp @@ -67,14 +67,33 @@ extern "C" { #define SNES_MEMORY_CGRAM 104 // SSNES extension. Not required to be implemented for a working implementation. -#define SNES_ENVIRONMENT_GET_FULLPATH 0 // const char ** -- Full path of game loaded. -#define SNES_ENVIRONMENT_SET_GEOMETRY 1 // const struct snes_geometry * -- Window geometry information for the system/game. -#define SNES_ENVIRONMENT_SET_PITCH 2 // const unsigned * -- Pitch of game image. -#define SNES_ENVIRONMENT_GET_OVERSCAN 3 // bool * -- Boolean value whether or not the implementation should use overscan. -#define SNES_ENVIRONMENT_SET_TIMING 4 // const struct snes_system_timing * -- Set exact timings of the system. - // Used primarily for video recording. -#define SNES_ENVIRONMENT_GET_CAN_DUPE 5 // bool * -- Boolean value whether or not SSNES supports frame duping, - // passing NULL to video frame callback. +#define SNES_ENVIRONMENT_GET_FULLPATH 0 // const char ** -- + // Full path of game loaded. + // +#define SNES_ENVIRONMENT_SET_GEOMETRY 1 // const struct snes_geometry * -- + // Window geometry information for the system/game. + // +#define SNES_ENVIRONMENT_SET_PITCH 2 // const unsigned * -- + // Pitch of game image. + // +#define SNES_ENVIRONMENT_GET_OVERSCAN 3 // bool * -- + // Boolean value whether or not the implementation should use overscan. + // +#define SNES_ENVIRONMENT_SET_TIMING 4 // const struct snes_system_timing * -- + // Set exact timings of the system. Used primarily for video recording. + // +#define SNES_ENVIRONMENT_GET_CAN_DUPE 5 // bool * -- + // Boolean value whether or not SSNES supports frame duping, + // passing NULL to video frame callback. + // + // +#define SNES_ENVIRONMENT_SET_NEED_FULLPATH 6 // const bool * -- + // Boolean value telling if implementation needs a valid fullpath to be able to run. + // If this is the case, SSNES will not open the rom directly, + // and pass NULL to rom data. + // Implementation must then use SNES_ENVIRONMENT_GET_FULLPATH. + // This is useful for implementations with very large roms, + // which are impractical to load fully into RAM. struct snes_geometry {