From 63297e4238046fd3f6e95234c84146d8fb088a74 Mon Sep 17 00:00:00 2001 From: kwyxz Date: Mon, 22 Jan 2018 10:49:13 -0800 Subject: [PATCH 01/15] Allow Solaris build --- libretro/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libretro/Makefile b/libretro/Makefile index 75c6f453..e6ea40eb 100644 --- a/libretro/Makefile +++ b/libretro/Makefile @@ -56,7 +56,7 @@ ifneq (,$(findstring unix,$(platform))) CC = gcc SHARED := -shared -z defs else - SHARED := -shared -Wl,--version-script=link.T -Wl,-z,defs + SHARED := -shared -Wl,--version-script=link.T endif ifneq ($(findstring Haiku,$(shell uname -a)),) LIBS := From 247699123c4c9b3e33cd7faac49513c33d646fb8 Mon Sep 17 00:00:00 2001 From: Alberto Fustinoni Date: Tue, 29 May 2018 16:27:58 +0900 Subject: [PATCH 02/15] logic --- libretro/Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libretro/Makefile b/libretro/Makefile index e6ea40eb..ce4792ca 100644 --- a/libretro/Makefile +++ b/libretro/Makefile @@ -252,7 +252,7 @@ else ifneq (,$(findstring windows_msvc2017,$(platform))) LIBS += kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib else ifneq (,$(findstring uwp,$(PlatformSuffix))) WinPartition = uwp - MSVC2017CompileFlags = -DWINAPI_FAMILY=WINAPI_FAMILY_APP -DWINDLL -D_UNICODE -DUNICODE -DWRL_NO_DEFAULT_LIB + MSVC2017CompileFlags = -DWINAPI_FAMILY=WINAPI_FAMILY_APP -D_WINDLL -D_UNICODE -DUNICODE -D__WRL_NO_DEFAULT_LIB__ -ZW:nostdlib -EHsc LDFLAGS += -APPCONTAINER -NXCOMPAT -DYNAMICBASE -MANIFEST:NO -LTCG -OPT:REF -SUBSYSTEM:CONSOLE -MANIFESTUAC:NO -OPT:ICF -ERRORREPORT:PROMPT -NOLOGO -TLBID:1 -DEBUG:FULL -WINMD:NO LIBS += WindowsApp.lib endif @@ -320,6 +320,9 @@ else ifneq (,$(findstring windows_msvc2017,$(platform))) PATH := $(PATH):$(shell IFS=$$'\n'; cygpath "$(VsInstallRoot)/Common7/IDE") INCLUDE := $(shell IFS=$$'\n'; cygpath -w "$(VcCompilerToolsDir)/include") LIB := $(shell IFS=$$'\n'; cygpath -w "$(VcCompilerToolsDir)/lib/$(TargetArchMoniker)") + ifneq (,$(findstring uwp,$(PlatformSuffix))) + LIB := $(shell IFS=$$'\n'; cygpath -w "$(LIB)/store") + endif export INCLUDE := $(INCLUDE);$(WindowsSDKSharedIncludeDir);$(WindowsSDKUCRTIncludeDir);$(WindowsSDKUMIncludeDir) export LIB := $(LIB);$(WindowsSDKUCRTLibDir);$(WindowsSDKUMLibDir) From 73e9e8e4c31f0af5bdecb006974c59e8eb9bb2c5 Mon Sep 17 00:00:00 2001 From: Alberto Fustinoni Date: Tue, 29 May 2018 16:43:25 +0900 Subject: [PATCH 03/15] Remove linker warnings --- libretro/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libretro/Makefile b/libretro/Makefile index ce4792ca..c091e4b9 100644 --- a/libretro/Makefile +++ b/libretro/Makefile @@ -257,6 +257,8 @@ else ifneq (,$(findstring windows_msvc2017,$(platform))) LIBS += WindowsApp.lib endif + MSVC2017CompileFlags += -D__WIN32__ + CFLAGS += $(MSVC2017CompileFlags) CXXFLAGS += $(MSVC2017CompileFlags) From fbc8e4a9362fe1593cf632132879b26f73b86a99 Mon Sep 17 00:00:00 2001 From: Alberto Fustinoni Date: Tue, 29 May 2018 16:53:33 +0900 Subject: [PATCH 04/15] Comments --- libretro/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/libretro/Makefile b/libretro/Makefile index c091e4b9..52d05f48 100644 --- a/libretro/Makefile +++ b/libretro/Makefile @@ -257,6 +257,7 @@ else ifneq (,$(findstring windows_msvc2017,$(platform))) LIBS += WindowsApp.lib endif + # Specific to this core MSVC2017CompileFlags += -D__WIN32__ CFLAGS += $(MSVC2017CompileFlags) From 540c4bfec7be5c09300ae232de80d4554a1aeb8c Mon Sep 17 00:00:00 2001 From: Alberto Fustinoni Date: Tue, 29 May 2018 16:56:05 +0900 Subject: [PATCH 05/15] Formatting --- libretro/Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libretro/Makefile b/libretro/Makefile index 52d05f48..829dc61c 100644 --- a/libretro/Makefile +++ b/libretro/Makefile @@ -257,8 +257,8 @@ else ifneq (,$(findstring windows_msvc2017,$(platform))) LIBS += WindowsApp.lib endif - # Specific to this core - MSVC2017CompileFlags += -D__WIN32__ + # Specific to this core + MSVC2017CompileFlags += -D__WIN32__ CFLAGS += $(MSVC2017CompileFlags) CXXFLAGS += $(MSVC2017CompileFlags) @@ -323,9 +323,9 @@ else ifneq (,$(findstring windows_msvc2017,$(platform))) PATH := $(PATH):$(shell IFS=$$'\n'; cygpath "$(VsInstallRoot)/Common7/IDE") INCLUDE := $(shell IFS=$$'\n'; cygpath -w "$(VcCompilerToolsDir)/include") LIB := $(shell IFS=$$'\n'; cygpath -w "$(VcCompilerToolsDir)/lib/$(TargetArchMoniker)") - ifneq (,$(findstring uwp,$(PlatformSuffix))) - LIB := $(shell IFS=$$'\n'; cygpath -w "$(LIB)/store") - endif + ifneq (,$(findstring uwp,$(PlatformSuffix))) + LIB := $(shell IFS=$$'\n'; cygpath -w "$(LIB)/store") + endif export INCLUDE := $(INCLUDE);$(WindowsSDKSharedIncludeDir);$(WindowsSDKUCRTIncludeDir);$(WindowsSDKUMIncludeDir) export LIB := $(LIB);$(WindowsSDKUCRTLibDir);$(WindowsSDKUMLibDir) From 0f4824a16cda9e911a7c84f8423f4f28785ce7eb Mon Sep 17 00:00:00 2001 From: kps501 <39468366+kps501@users.noreply.github.com> Date: Fri, 8 Jun 2018 01:42:21 +0000 Subject: [PATCH 06/15] backport hires blending --- libretro/libretro.cpp | 85 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 74 insertions(+), 11 deletions(-) diff --git a/libretro/libretro.cpp b/libretro/libretro.cpp index d6d36c5f..ad0d31c9 100644 --- a/libretro/libretro.cpp +++ b/libretro/libretro.cpp @@ -45,6 +45,7 @@ char g_rom_dir[1024]; char g_basename[1024]; +bool hires_blend = false; retro_log_printf_t log_cb = NULL; static retro_video_refresh_t video_cb = NULL; @@ -137,6 +138,7 @@ void retro_set_environment(retro_environment_t cb) // Changing "Show layer 1" is fine, but don't change "layer_1"/etc or the possible values ("Yes|No"). // Adding more variables and rearranging them is safe. { "snes9x_up_down_allowed", "Allow Opposing Directions; disabled|enabled" }, + { "snes9x_hires_blend", "Hires Blending; disabled|enabled" }, { "snes9x_overclock", "SuperFX Frequency; 100%|200%|400%|600%|800%|1000%" }, //{ "snes9x_overclock_cycles", "Reduce Slowdown (Hack, Unsafe); disabled|compatible|max" }, //{ "snes9x_reduce_sprite_flicker", "Reduce Flickering (Hack, Unsafe); disabled|enabled" }, @@ -198,7 +200,16 @@ static void update_variables(void) bool geometry_update = false; char key[256]; struct retro_variable var; - var.key = "snes9x_overclock"; + + var.key = "snes9x_hires_blend"; + var.value = NULL; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var)) + hires_blend = !strcmp(var.value, "disabled") ? false : true; + else + hires_blend = false; + + var.key = "snes9x_overclock_superfx"; var.value = NULL; if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var)) @@ -207,6 +218,14 @@ static void update_variables(void) Settings.SuperFXClockMultiplier = freq; } + var.key = "snes9x_hires_blend"; + var.value = NULL; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var)) + hires_blend = !strcmp(var.value, "disabled") ? false : true; + else + hires_blend = false; + var.key = "snes9x_up_down_allowed"; var.value = NULL; @@ -846,13 +865,25 @@ static void map_buttons() // libretro uses relative values for analogue devices. // S9x seems to use absolute values, but do convert these into relative values in the core. (Why?!) // Hack around it. :) + static int16_t snes_mouse_state[2][2] = {{0}, {0}}; static int16_t snes_scope_state[2] = {0}; static int16_t snes_justifier_state[2][2] = {{0}, {0}}; static void report_buttons() { - int _x, _y; int offset = snes_devices[0] == RETRO_DEVICE_JOYPAD_MULTITAP ? 4 : 1; + + int runahead_poll = 0; + int result = -1; + if(environ_cb(RETRO_ENVIRONMENT_GET_AUDIO_VIDEO_ENABLE, &result)) + { + // runahead off: 3 + // runahead secondary off: 0,0,0,0,0,3 + runahead_poll = (result & 0x0b)==3; + + // runahead secondary on: 2,8,8,8,8,9 (messy sync problems) + } + for (int port = 0; port <= 1; port++) { switch (snes_devices[port]) @@ -869,18 +900,22 @@ static void report_buttons() break; case RETRO_DEVICE_MOUSE: - _x = input_state_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_X); - _y = input_state_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_Y); - snes_mouse_state[port][0] += _x; - snes_mouse_state[port][1] += _y; + if(runahead_poll) + { + snes_mouse_state[port][0] = input_state_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_X); + snes_mouse_state[port][1] = input_state_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_Y); + } S9xReportPointer(BTN_POINTER + port, snes_mouse_state[port][0], snes_mouse_state[port][1]); for (int i = MOUSE_LEFT; i <= MOUSE_LAST; i++) S9xReportButton(MAKE_BUTTON(port + 1, i), input_state_cb(port, RETRO_DEVICE_MOUSE, 0, i)); break; case RETRO_DEVICE_LIGHTGUN_SUPER_SCOPE: - snes_scope_state[0] += input_state_cb(port, RETRO_DEVICE_LIGHTGUN_SUPER_SCOPE, 0, RETRO_DEVICE_ID_LIGHTGUN_X); - snes_scope_state[1] += input_state_cb(port, RETRO_DEVICE_LIGHTGUN_SUPER_SCOPE, 0, RETRO_DEVICE_ID_LIGHTGUN_Y); + if(runahead_poll) + { + snes_scope_state[0] += input_state_cb(port, RETRO_DEVICE_LIGHTGUN_SUPER_SCOPE, 0, RETRO_DEVICE_ID_LIGHTGUN_X); + snes_scope_state[1] += input_state_cb(port, RETRO_DEVICE_LIGHTGUN_SUPER_SCOPE, 0, RETRO_DEVICE_ID_LIGHTGUN_Y); + } if (snes_scope_state[0] < 0) snes_scope_state[0] = 0; else if (snes_scope_state[0] > (SNES_WIDTH-1)) snes_scope_state[0] = SNES_WIDTH-1; if (snes_scope_state[1] < 0) snes_scope_state[1] = 0; @@ -892,8 +927,11 @@ static void report_buttons() case RETRO_DEVICE_LIGHTGUN_JUSTIFIER: case RETRO_DEVICE_LIGHTGUN_JUSTIFIERS: - snes_justifier_state[port][0] += input_state_cb(port, RETRO_DEVICE_LIGHTGUN_JUSTIFIER, 0, RETRO_DEVICE_ID_LIGHTGUN_X); - snes_justifier_state[port][1] += input_state_cb(port, RETRO_DEVICE_LIGHTGUN_JUSTIFIER, 0, RETRO_DEVICE_ID_LIGHTGUN_Y); + if(runahead_poll) + { + snes_justifier_state[port][0] += input_state_cb(port, RETRO_DEVICE_LIGHTGUN_JUSTIFIER, 0, RETRO_DEVICE_ID_LIGHTGUN_X); + snes_justifier_state[port][1] += input_state_cb(port, RETRO_DEVICE_LIGHTGUN_JUSTIFIER, 0, RETRO_DEVICE_ID_LIGHTGUN_Y); + } if (snes_justifier_state[port][0] < 0) snes_justifier_state[port][0] = 0; else if (snes_justifier_state[port][0] > (SNES_WIDTH-1)) snes_justifier_state[port][0] = SNES_WIDTH-1; if (snes_justifier_state[port][1] < 0) snes_justifier_state[port][1] = 0; @@ -906,7 +944,6 @@ static void report_buttons() default: if (log_cb) log_cb(RETRO_LOG_ERROR, "[libretro]: Unknown device...\n"); - } } } @@ -1076,12 +1113,38 @@ bool8 S9xDeinitUpdate(int width, int height) } } + + if(width==MAX_SNES_WIDTH && hires_blend) + { +#define AVERAGE_565(el0, el1) (((el0) & (el1)) + ((((el0) ^ (el1)) & 0xF7DE) >> 1)) + for (register int y = 0; y < height; y++) + { + register uint16 *input = (uint16 *) ((uint8 *) GFX.Screen + y * GFX.Pitch); + register uint16 *output = (uint16 *) ((uint8 *) GFX.Screen + y * GFX.Pitch); + register uint16 l, r; + + l = 0; + for (register int x = 0; x < (width >> 1); x++) + { + r = *input++; + *output++ = AVERAGE_565 (l, r); + l = r; + + r = *input++; + *output++ = AVERAGE_565 (l, r); + l = r; + } + } + } + + video_cb(GFX.Screen, width, height, GFX.Pitch); return TRUE; } bool8 S9xContinueUpdate(int width, int height) { + S9xDeinitUpdate(width, height); return true; } From 951da61b5f75f849c5fc6860fce57c603442c9fa Mon Sep 17 00:00:00 2001 From: kps501 <39468366+kps501@users.noreply.github.com> Date: Fri, 8 Jun 2018 21:28:12 +0000 Subject: [PATCH 07/15] libretro: hires blending buffer --- libretro/libretro.cpp | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/libretro/libretro.cpp b/libretro/libretro.cpp index ad0d31c9..9fa8397d 100644 --- a/libretro/libretro.cpp +++ b/libretro/libretro.cpp @@ -46,6 +46,7 @@ char g_rom_dir[1024]; char g_basename[1024]; bool hires_blend = false; +static uint16 *gfx_blend; retro_log_printf_t log_cb = NULL; static retro_video_refresh_t video_cb = NULL; @@ -725,6 +726,7 @@ void retro_init(void) GFX.Pitch = MAX_SNES_WIDTH * sizeof(uint16); GFX.Screen = (uint16*) calloc(1, GFX.Pitch * MAX_SNES_HEIGHT); + gfx_blend = (uint16*) calloc(1, GFX.Pitch * MAX_SNES_HEIGHT); S9xGraphicsInit(); S9xInitInputDevices(); @@ -989,6 +991,7 @@ void retro_deinit() S9xUnmapAllControls(); free(GFX.Screen); + free(gfx_blend); } @@ -1118,27 +1121,31 @@ bool8 S9xDeinitUpdate(int width, int height) { #define AVERAGE_565(el0, el1) (((el0) & (el1)) + ((((el0) ^ (el1)) & 0xF7DE) >> 1)) for (register int y = 0; y < height; y++) - { - register uint16 *input = (uint16 *) ((uint8 *) GFX.Screen + y * GFX.Pitch); - register uint16 *output = (uint16 *) ((uint8 *) GFX.Screen + y * GFX.Pitch); - register uint16 l, r; + { + register uint16 *input = (uint16 *) ((uint8 *) GFX.Screen + y * GFX.Pitch); + register uint16 *output = (uint16 *) ((uint8 *) gfx_blend + y * GFX.Pitch); + register uint16 l, r; - l = 0; - for (register int x = 0; x < (width >> 1); x++) - { - r = *input++; - *output++ = AVERAGE_565 (l, r); - l = r; + l = 0; + for (register int x = 0; x < (width >> 1); x++) + { + r = *input++; + *output++ = AVERAGE_565 (l, r); + l = r; - r = *input++; - *output++ = AVERAGE_565 (l, r); - l = r; - } - } - } + r = *input++; + *output++ = AVERAGE_565 (l, r); + l = r; + } + } + video_cb(gfx_blend, width, height, GFX.Pitch); + } + else + { + video_cb(GFX.Screen, width, height, GFX.Pitch); + } - video_cb(GFX.Screen, width, height, GFX.Pitch); return TRUE; } From 4e04cbfe90e9e19af86611b96c7abf3a8dc6298c Mon Sep 17 00:00:00 2001 From: radius Date: Sat, 30 Jun 2018 17:11:15 -0500 Subject: [PATCH 08/15] backport bsx, multicart --- libretro/libretro.cpp | 363 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 311 insertions(+), 52 deletions(-) diff --git a/libretro/libretro.cpp b/libretro/libretro.cpp index 9fa8397d..ff25321f 100644 --- a/libretro/libretro.cpp +++ b/libretro/libretro.cpp @@ -35,19 +35,25 @@ #define RETRO_MEMORY_SNES_GAME_BOY_RAM ((5 << 8) | RETRO_MEMORY_SAVE_RAM) #define RETRO_MEMORY_SNES_GAME_BOY_RTC ((6 << 8) | RETRO_MEMORY_RTC) -#define RETRO_GAME_TYPE_BSX 0x101 -#define RETRO_GAME_TYPE_BSX_SLOTTED 0x102 -#define RETRO_GAME_TYPE_SUFAMI_TURBO 0x103 -#define RETRO_GAME_TYPE_SUPER_GAME_BOY 0x104 +#define RETRO_GAME_TYPE_BSX 0x101 | 0x1000 +#define RETRO_GAME_TYPE_BSX_SLOTTED 0x102 | 0x1000 +#define RETRO_GAME_TYPE_SUFAMI_TURBO 0x103 | 0x1000 +#define RETRO_GAME_TYPE_SUPER_GAME_BOY 0x104 | 0x1000 +#define RETRO_GAME_TYPE_MULTI_CART 0x105 | 0x1000 + #define SNES_4_3 4.0f / 3.0f #define SNES_8_7 8.0f / 7.0f char g_rom_dir[1024]; char g_basename[1024]; + bool hires_blend = false; static uint16 *gfx_blend; +char retro_system_directory[4096]; +char retro_save_directory[4096]; + retro_log_printf_t log_cb = NULL; static retro_video_refresh_t video_cb = NULL; static retro_audio_sample_t audio_cb = NULL; @@ -101,7 +107,7 @@ void retro_set_audio_sample(retro_audio_sample_t cb) void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb) { - audio_batch_cb = cb; + audio_batch_cb = cb; } void retro_set_input_poll(retro_input_poll_t cb) @@ -130,10 +136,32 @@ static retro_environment_t environ_cb; static overscan_mode crop_overscan_mode = OVERSCAN_CROP_ON; // default to crop static aspect_mode aspect_ratio_mode = ASPECT_RATIO_4_3; // default to 4:3 static bool rom_loaded = false; + void retro_set_environment(retro_environment_t cb) { environ_cb = cb; + static const struct retro_subsystem_memory_info multi_a_memory[] = { + { "srm", RETRO_MEMORY_SNES_SUFAMI_TURBO_A_RAM }, + }; + + static const struct retro_subsystem_memory_info multi_b_memory[] = { + { "srm", RETRO_MEMORY_SNES_SUFAMI_TURBO_B_RAM }, + }; + + static const struct retro_subsystem_rom_info multicart_roms[] = { + { "Cart A", "smc|sfc|swc|fig|bs", false, false, false, multi_a_memory, 1 }, + { "Add-On B", "smc|sfc|swc|fig|bs", false, false, false, multi_b_memory, 1 }, + }; + + static const struct retro_subsystem_info subsystems[] = { + { "Multi-Cart Link", "multicart_addon", multicart_roms, 2, RETRO_GAME_TYPE_MULTI_CART }, + {} + }; + + cb(RETRO_ENVIRONMENT_SET_SUBSYSTEM_INFO, (void*)subsystems); + + struct retro_variable variables[] = { // These variable names and possible values constitute an ABI with ZMZ (ZSNES Libretro player). // Changing "Show layer 1" is fine, but don't change "layer_1"/etc or the possible values ("Yes|No"). @@ -189,11 +217,11 @@ void retro_set_environment(retro_environment_t cb) environ_cb(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void*)ports); } -void update_geometry() +void update_geometry(void) { - struct retro_system_av_info av_info; - retro_get_system_av_info(&av_info); - environ_cb(RETRO_ENVIRONMENT_SET_GEOMETRY, &av_info); + struct retro_system_av_info av_info; + retro_get_system_av_info(&av_info); + environ_cb(RETRO_ENVIRONMENT_SET_GEOMETRY, &av_info); } static void update_variables(void) @@ -348,7 +376,7 @@ void retro_get_system_info(struct retro_system_info *info) #define GIT_VERSION "" #endif info->library_version = VERSION GIT_VERSION; - info->valid_extensions = "smc|sfc|swc|fig"; + info->valid_extensions = "smc|sfc|swc|fig|bs"; info->need_fullpath = false; info->block_extract = false; } @@ -495,6 +523,46 @@ void retro_cheat_set(unsigned index, bool enabled, const char *codeline) S9xCheatsEnable(); } +#define MAX_MAPS 32 +static struct retro_memory_descriptor memorydesc[MAX_MAPS]; +static unsigned memorydesc_c; + +static bool merge_mapping() +{ + if (memorydesc_c==1) return false;//can't merge the only one + struct retro_memory_descriptor * a=&memorydesc[MAX_MAPS - (memorydesc_c-1)]; + struct retro_memory_descriptor * b=&memorydesc[MAX_MAPS - memorydesc_c]; + + if (a->flags != b->flags) return false; + if (a->disconnect != b->disconnect) return false; + if (a->len != b->len) return false; + if (a->addrspace || b->addrspace) return false;//we don't use these + if (((char*)a->ptr)+a->offset==((char*)b->ptr)+b->offset && a->select==b->select) + { + a->select&=~(a->start^b->start); + memorydesc_c--; + return true; + } + uint32 len=a->len; + if (!len) len=(0x1000000 - a->select); + if (len && ((len-1) & (len | a->disconnect))==0 && ((char*)a->ptr)+a->offset+len == ((char*)b->ptr)+b->offset) + { + a->select &=~ len; + a->disconnect &=~ len; + memorydesc_c--; + return true; + } + return false; +} + +void S9xAppendMapping(struct retro_memory_descriptor *desc) +{ + //do it backwards - snes9x defines the last one to win, while we define the first one to win + //printf("add %x\n",desc->start); + memcpy(&memorydesc[MAX_MAPS - (++memorydesc_c)], desc, sizeof(struct retro_memory_descriptor)); + while (merge_mapping()) {} +} + static void init_descriptors(void) { struct retro_input_descriptor desc[] = { @@ -569,6 +637,121 @@ static void init_descriptors(void) environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc); } +static bool valid_normal_bank (uint8 bankbyte) +{ + switch (bankbyte) + { + case 32: case 33: case 48: case 49: + return (true); + } + + return (false); +} + +static int is_bsx (uint8 *p) +{ + if ((p[26] == 0x33 || p[26] == 0xFF) && (!p[21] || (p[21] & 131) == 128) && valid_normal_bank(p[24])) + { + unsigned char m = p[22]; + + if (!m && !p[23]) + return (2); + + if ((m == 0xFF && p[23] == 0xFF) || (!(m & 0xF) && ((m >> 4) - 1 < 12))) + return (1); + } + + return (0); +} + +static void Remove_Header(uint8_t *&romptr, size_t &romsize, bool multicart_sufami) +{ + if (romptr==0 || romsize==0) return; + + uint32 calc_size = (romsize / 0x2000) * 0x2000; + if ((romsize - calc_size == 512 && !Settings.ForceNoHeader) || Settings.ForceHeader) + { + romptr += 512; + romsize -= 512; + + if(log_cb) log_cb(RETRO_LOG_INFO,"[libretro]: ROM header removed\n"); + } + + if (multicart_sufami) + { + if (strncmp((const char*)(romptr+0x100000), "BANDAI SFC-ADX", 14) == 0 && + strncmp((const char*)(romptr+0x000000), "BANDAI SFC-ADX", 14) == 0) + { + romptr += 0x100000; + romsize -= 0x100000; + + if(log_cb) log_cb(RETRO_LOG_INFO,"[libretro]: Sufami Turbo Multi-ROM bios removed\n"); + } + } +} + +static bool8 LoadBIOS(uint8 *biosrom, char *biosname, int biossize) +{ + FILE *fp; + char name[PATH_MAX + 1]; + bool8 r = FALSE; + + strcpy(name, S9xGetDirectory(ROMFILENAME_DIR)); + strcat(name, SLASH_STR); + strcat(name, biosname); + + fp = fopen(name, "rb"); + if (!fp) + { + strcpy(name, S9xGetDirectory(BIOS_DIR)); + strcat(name, SLASH_STR); + strcat(name, biosname); + + fp = fopen(name, "rb"); + } + + if (fp) + { + size_t size; + + size = fread((void *) biosrom, 1, biossize, fp); + fclose(fp); + if (size == biossize) + r = TRUE; + } + + return (r); +} + +static bool8 is_SufamiTurbo_Cart (const uint8 *data, uint32 size) +{ + if (size >= 0x80000 && size <= 0x100000 && + strncmp((char *) data, "BANDAI SFC-ADX", 14) == 0 && strncmp((char * ) (data + 0x10), "SFC-ADX BACKUP", 14) != 0) + return (TRUE); + else + return (FALSE); +} + +void retro_load_init_reset() +{ + struct retro_memory_map map={ memorydesc+MAX_MAPS-memorydesc_c, memorydesc_c }; + if (rom_loaded) environ_cb(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &map); + + int pixel_format = RGB555; + if(environ_cb) { + pixel_format = RGB565; + enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565; + if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) + pixel_format = RGB555; + } + S9xGraphicsDeinit(); + S9xSetRenderPixelFormat(pixel_format); + S9xGraphicsInit(); + + update_geometry(); + audio_interp_max = 32768; +} + bool retro_load_game(const struct retro_game_info *game) { init_descriptors(); @@ -579,13 +762,29 @@ bool retro_load_game(const struct retro_game_info *game) rom_loaded = Memory.LoadROM(game->path); else { + uint8 *biosrom = new uint8[0x100000]; + if (game->path != NULL) { - extract_basename(g_basename, game->path, sizeof(g_basename)); + extract_basename(g_basename, game->path, sizeof(g_basename)); extract_directory(g_rom_dir, game->path, sizeof(g_rom_dir)); } - rom_loaded = Memory.LoadROMMem((const uint8_t*)game->data ,game->size); + if (is_SufamiTurbo_Cart((uint8 *) game->data, game->size)) { + if (rom_loaded = LoadBIOS(biosrom,"STBIOS.bin",0x40000)) + rom_loaded = Memory.LoadMultiCartMem((const uint8_t*)game->data, game->size, 0, 0, biosrom, 0x40000); + } + + else + if ((is_bsx((uint8 *) game->data + 0x7fc0)==1) | (is_bsx((uint8 *) game->data + 0xffc0)==1)) { + if (rom_loaded = LoadBIOS(biosrom,"BS-X.bin",0x100000)) + rom_loaded = Memory.LoadMultiCartMem(biosrom, 0x100000, (const uint8_t*)game->data, game->size, 0, 0); + } + + else + rom_loaded = Memory.LoadROMMem((const uint8_t*)game->data ,game->size); + + if(biosrom) delete[] biosrom; } int pixel_format = RGB555; @@ -602,62 +801,105 @@ bool retro_load_game(const struct retro_game_info *game) if (!rom_loaded && log_cb) log_cb(RETRO_LOG_ERROR, "[libretro]: Rom loading failed...\n"); + struct retro_memory_map map={ memorydesc+MAX_MAPS-memorydesc_c, memorydesc_c }; + if (rom_loaded) environ_cb(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &map); + + update_geometry(); + return rom_loaded; } void retro_unload_game(void) {} -bool retro_load_game_special(unsigned game_type, - const struct retro_game_info *info, size_t num_info) { +bool retro_load_game_special(unsigned game_type, const struct retro_game_info *info, size_t num_info) +{ + uint8_t *romptr[3]; + size_t romsize[3]; - init_descriptors(); + for(size_t lcv=0; lcv (SNES_HEIGHT-1)) snes_scope_state[1] = SNES_HEIGHT-1; S9xReportPointer(BTN_POINTER, snes_scope_state[0], snes_scope_state[1]); for (int i = SCOPE_TRIGGER; i <= SCOPE_LAST; i++) - S9xReportButton(MAKE_BUTTON(2, i), input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, i)); + S9xReportButton(MAKE_BUTTON(2, i), input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, i)); break; case RETRO_DEVICE_LIGHTGUN_JUSTIFIER: @@ -1044,7 +1302,7 @@ size_t retro_get_memory_size(unsigned type) size = 0x20000; break; case RETRO_MEMORY_SNES_SUFAMI_TURBO_B_RAM: - size = (unsigned) (Multi.cartType && Multi.sramSizeB ? (1 << (Multi.sramSizeB + 3)) * 128 : 0); + size = (unsigned) (Multi.cartType==4 && Multi.sramSizeB ? (1 << (Multi.sramSizeB + 3)) * 128 : 0); break; case RETRO_MEMORY_RTC: size = (Settings.SRTC || Settings.SPC7110RTC)?20:0; @@ -1105,7 +1363,7 @@ bool8 S9xDeinitUpdate(int width, int height) if (height > SNES_HEIGHT_EXTENDED) { if (height < SNES_HEIGHT_EXTENDED << 1) - memset(GFX.Screen + (GFX.Pitch >> 1) * height,0,GFX.Pitch * ((SNES_HEIGHT_EXTENDED << 1) - height)); + memset(GFX.Screen + (GFX.Pitch >> 1) * height,0,GFX.Pitch * ((SNES_HEIGHT_EXTENDED << 1) - height)); height = SNES_HEIGHT_EXTENDED << 1; } else @@ -1175,8 +1433,7 @@ const char* S9xGetFilename(const char* in, s9x_getdirtype type) switch (type) { case ROMFILENAME_DIR: - sprintf(newpath, "%s%c%s%s", - g_rom_dir, SLASH, g_basename, in); + sprintf(newpath, "%s%c%s%s", g_rom_dir, SLASH, g_basename, in); return newpath; default: break; @@ -1191,6 +1448,8 @@ const char* S9xGetDirectory(s9x_getdirtype type) { case ROMFILENAME_DIR: return g_rom_dir; + case BIOS_DIR: + return retro_system_directory; default: break; } From f6ea61b41fc09af9b34bb28c9a685f1c4a6432f5 Mon Sep 17 00:00:00 2001 From: radius Date: Sat, 30 Jun 2018 18:06:41 -0500 Subject: [PATCH 09/15] cleanups --- libretro/libretro.cpp | 61 ++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/libretro/libretro.cpp b/libretro/libretro.cpp index ff25321f..c8e616d8 100644 --- a/libretro/libretro.cpp +++ b/libretro/libretro.cpp @@ -732,26 +732,6 @@ static bool8 is_SufamiTurbo_Cart (const uint8 *data, uint32 size) return (FALSE); } -void retro_load_init_reset() -{ - struct retro_memory_map map={ memorydesc+MAX_MAPS-memorydesc_c, memorydesc_c }; - if (rom_loaded) environ_cb(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &map); - - int pixel_format = RGB555; - if(environ_cb) { - pixel_format = RGB565; - enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565; - if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) - pixel_format = RGB555; - } - S9xGraphicsDeinit(); - S9xSetRenderPixelFormat(pixel_format); - S9xGraphicsInit(); - - update_geometry(); - audio_interp_max = 32768; -} - bool retro_load_game(const struct retro_game_info *game) { init_descriptors(); @@ -788,7 +768,8 @@ bool retro_load_game(const struct retro_game_info *game) } int pixel_format = RGB555; - if(environ_cb) { + if(environ_cb) + { pixel_format = RGB565; enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565; if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) @@ -798,20 +779,19 @@ bool retro_load_game(const struct retro_game_info *game) S9xSetRenderPixelFormat(pixel_format); S9xGraphicsInit(); + struct retro_memory_map map={ memorydesc+MAX_MAPS-memorydesc_c, memorydesc_c }; + if (rom_loaded) + { + environ_cb(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &map); + update_geometry(); + } + if (!rom_loaded && log_cb) log_cb(RETRO_LOG_ERROR, "[libretro]: Rom loading failed...\n"); - struct retro_memory_map map={ memorydesc+MAX_MAPS-memorydesc_c, memorydesc_c }; - if (rom_loaded) environ_cb(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &map); - - update_geometry(); - return rom_loaded; } -void retro_unload_game(void) -{} - bool retro_load_game_special(unsigned game_type, const struct retro_game_info *info, size_t num_info) { uint8_t *romptr[3]; @@ -897,11 +877,32 @@ bool retro_load_game_special(unsigned game_type, const struct retro_game_info *i break; } - if (rom_loaded) retro_load_init_reset(); + if (rom_loaded) + { + int pixel_format = RGB555; + if(environ_cb) + { + pixel_format = RGB565; + enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565; + if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) + pixel_format = RGB555; + } + S9xGraphicsDeinit(); + S9xSetRenderPixelFormat(pixel_format); + S9xGraphicsInit(); + + struct retro_memory_map map={ memorydesc+MAX_MAPS-memorydesc_c, memorydesc_c }; + environ_cb(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &map); + update_geometry(); + audio_interp_max = 32768; + } return rom_loaded; } +void retro_unload_game(void) +{} + static void map_buttons(); static void check_system_specs(void) From 3b16426dbabd33a0ceb9fbdbcfdadfda5037fc37 Mon Sep 17 00:00:00 2001 From: radius Date: Sat, 30 Jun 2018 18:31:47 -0500 Subject: [PATCH 10/15] standarize indentation --- libretro/libretro.cpp | 1806 ++++++++++++++++++++--------------------- 1 file changed, 903 insertions(+), 903 deletions(-) diff --git a/libretro/libretro.cpp b/libretro/libretro.cpp index c8e616d8..758180eb 100644 --- a/libretro/libretro.cpp +++ b/libretro/libretro.cpp @@ -35,11 +35,11 @@ #define RETRO_MEMORY_SNES_GAME_BOY_RAM ((5 << 8) | RETRO_MEMORY_SAVE_RAM) #define RETRO_MEMORY_SNES_GAME_BOY_RTC ((6 << 8) | RETRO_MEMORY_RTC) -#define RETRO_GAME_TYPE_BSX 0x101 | 0x1000 -#define RETRO_GAME_TYPE_BSX_SLOTTED 0x102 | 0x1000 -#define RETRO_GAME_TYPE_SUFAMI_TURBO 0x103 | 0x1000 +#define RETRO_GAME_TYPE_BSX 0x101 | 0x1000 +#define RETRO_GAME_TYPE_BSX_SLOTTED 0x102 | 0x1000 +#define RETRO_GAME_TYPE_SUFAMI_TURBO 0x103 | 0x1000 #define RETRO_GAME_TYPE_SUPER_GAME_BOY 0x104 | 0x1000 -#define RETRO_GAME_TYPE_MULTI_CART 0x105 | 0x1000 +#define RETRO_GAME_TYPE_MULTI_CART 0x105 | 0x1000 #define SNES_4_3 4.0f / 3.0f @@ -63,61 +63,61 @@ static retro_input_state_t input_state_cb = NULL; static void extract_basename(char *buf, const char *path, size_t size) { - const char *base = strrchr(path, '/'); - if (!base) - base = strrchr(path, '\\'); - if (!base) - base = path; + const char *base = strrchr(path, '/'); + if (!base) + base = strrchr(path, '\\'); + if (!base) + base = path; - if (*base == '\\' || *base == '/') - base++; + if (*base == '\\' || *base == '/') + base++; - strncpy(buf, base, size - 1); - buf[size - 1] = '\0'; + strncpy(buf, base, size - 1); + buf[size - 1] = '\0'; - char *ext = strrchr(buf, '.'); - if (ext) - *ext = '\0'; + char *ext = strrchr(buf, '.'); + if (ext) + *ext = '\0'; } static void extract_directory(char *buf, const char *path, size_t size) { - strncpy(buf, path, size - 1); - buf[size - 1] = '\0'; + strncpy(buf, path, size - 1); + buf[size - 1] = '\0'; - char *base = strrchr(buf, '/'); - if (!base) - base = strrchr(buf, '\\'); + char *base = strrchr(buf, '/'); + if (!base) + base = strrchr(buf, '\\'); - if (base) - *base = '\0'; - else - buf[0] = '\0'; + if (base) + *base = '\0'; + else + buf[0] = '\0'; } void retro_set_video_refresh(retro_video_refresh_t cb) { - video_cb = cb; + video_cb = cb; } void retro_set_audio_sample(retro_audio_sample_t cb) { - audio_cb = cb; + audio_cb = cb; } void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb) { - audio_batch_cb = cb; + audio_batch_cb = cb; } void retro_set_input_poll(retro_input_poll_t cb) { - poll_cb = cb; + poll_cb = cb; } void retro_set_input_state(retro_input_state_t cb) { - input_state_cb = cb; + input_state_cb = cb; } enum overscan_mode { @@ -139,232 +139,232 @@ static bool rom_loaded = false; void retro_set_environment(retro_environment_t cb) { - environ_cb = cb; + environ_cb = cb; - static const struct retro_subsystem_memory_info multi_a_memory[] = { - { "srm", RETRO_MEMORY_SNES_SUFAMI_TURBO_A_RAM }, - }; + static const struct retro_subsystem_memory_info multi_a_memory[] = { + { "srm", RETRO_MEMORY_SNES_SUFAMI_TURBO_A_RAM }, + }; - static const struct retro_subsystem_memory_info multi_b_memory[] = { - { "srm", RETRO_MEMORY_SNES_SUFAMI_TURBO_B_RAM }, - }; + static const struct retro_subsystem_memory_info multi_b_memory[] = { + { "srm", RETRO_MEMORY_SNES_SUFAMI_TURBO_B_RAM }, + }; - static const struct retro_subsystem_rom_info multicart_roms[] = { - { "Cart A", "smc|sfc|swc|fig|bs", false, false, false, multi_a_memory, 1 }, - { "Add-On B", "smc|sfc|swc|fig|bs", false, false, false, multi_b_memory, 1 }, - }; + static const struct retro_subsystem_rom_info multicart_roms[] = { + { "Cart A", "smc|sfc|swc|fig|bs", false, false, false, multi_a_memory, 1 }, + { "Add-On B", "smc|sfc|swc|fig|bs", false, false, false, multi_b_memory, 1 }, + }; - static const struct retro_subsystem_info subsystems[] = { - { "Multi-Cart Link", "multicart_addon", multicart_roms, 2, RETRO_GAME_TYPE_MULTI_CART }, - {} - }; + static const struct retro_subsystem_info subsystems[] = { + { "Multi-Cart Link", "multicart_addon", multicart_roms, 2, RETRO_GAME_TYPE_MULTI_CART }, + {} + }; - cb(RETRO_ENVIRONMENT_SET_SUBSYSTEM_INFO, (void*)subsystems); + cb(RETRO_ENVIRONMENT_SET_SUBSYSTEM_INFO, (void*)subsystems); - struct retro_variable variables[] = { - // These variable names and possible values constitute an ABI with ZMZ (ZSNES Libretro player). - // Changing "Show layer 1" is fine, but don't change "layer_1"/etc or the possible values ("Yes|No"). - // Adding more variables and rearranging them is safe. - { "snes9x_up_down_allowed", "Allow Opposing Directions; disabled|enabled" }, - { "snes9x_hires_blend", "Hires Blending; disabled|enabled" }, - { "snes9x_overclock", "SuperFX Frequency; 100%|200%|400%|600%|800%|1000%" }, - //{ "snes9x_overclock_cycles", "Reduce Slowdown (Hack, Unsafe); disabled|compatible|max" }, - //{ "snes9x_reduce_sprite_flicker", "Reduce Flickering (Hack, Unsafe); disabled|enabled" }, - { "snes9x_layer_1", "Show layer 1; enabled|disabled" }, - { "snes9x_layer_2", "Show layer 2; enabled|disabled" }, - { "snes9x_layer_3", "Show layer 3; enabled|disabled" }, - { "snes9x_layer_4", "Show layer 4; enabled|disabled" }, - { "snes9x_layer_5", "Show sprite layer; enabled|disabled" }, - { "snes9x_gfx_clip", "Enable graphic clip windows; enabled|disabled" }, - { "snes9x_gfx_transp", "Enable transparency effects; enabled|disabled" }, - { "snes9x_gfx_hires", "Enable hires mode; enabled|disabled" }, - { "snes9x_sndchan_1", "Enable sound channel 1; enabled|disabled" }, - { "snes9x_sndchan_2", "Enable sound channel 2; enabled|disabled" }, - { "snes9x_sndchan_3", "Enable sound channel 3; enabled|disabled" }, - { "snes9x_sndchan_4", "Enable sound channel 4; enabled|disabled" }, - { "snes9x_sndchan_5", "Enable sound channel 5; enabled|disabled" }, - { "snes9x_sndchan_6", "Enable sound channel 6; enabled|disabled" }, - { "snes9x_sndchan_7", "Enable sound channel 7; enabled|disabled" }, - { "snes9x_sndchan_8", "Enable sound channel 8; enabled|disabled" }, - { "snes9x_overscan", "Crop overscan; enabled|disabled|auto" }, - { "snes9x_aspect", "Preferred aspect ratio; 4:3|8:7|auto|ntsc|pal" }, - { NULL, NULL }, - }; + struct retro_variable variables[] = { + // These variable names and possible values constitute an ABI with ZMZ (ZSNES Libretro player). + // Changing "Show layer 1" is fine, but don't change "layer_1"/etc or the possible values ("Yes|No"). + // Adding more variables and rearranging them is safe. + { "snes9x_up_down_allowed", "Allow Opposing Directions; disabled|enabled" }, + { "snes9x_hires_blend", "Hires Blending; disabled|enabled" }, + { "snes9x_overclock", "SuperFX Frequency; 100%|200%|400%|600%|800%|1000%" }, + //{ "snes9x_overclock_cycles", "Reduce Slowdown (Hack, Unsafe); disabled|compatible|max" }, + //{ "snes9x_reduce_sprite_flicker", "Reduce Flickering (Hack, Unsafe); disabled|enabled" }, + { "snes9x_layer_1", "Show layer 1; enabled|disabled" }, + { "snes9x_layer_2", "Show layer 2; enabled|disabled" }, + { "snes9x_layer_3", "Show layer 3; enabled|disabled" }, + { "snes9x_layer_4", "Show layer 4; enabled|disabled" }, + { "snes9x_layer_5", "Show sprite layer; enabled|disabled" }, + { "snes9x_gfx_clip", "Enable graphic clip windows; enabled|disabled" }, + { "snes9x_gfx_transp", "Enable transparency effects; enabled|disabled" }, + { "snes9x_gfx_hires", "Enable hires mode; enabled|disabled" }, + { "snes9x_sndchan_1", "Enable sound channel 1; enabled|disabled" }, + { "snes9x_sndchan_2", "Enable sound channel 2; enabled|disabled" }, + { "snes9x_sndchan_3", "Enable sound channel 3; enabled|disabled" }, + { "snes9x_sndchan_4", "Enable sound channel 4; enabled|disabled" }, + { "snes9x_sndchan_5", "Enable sound channel 5; enabled|disabled" }, + { "snes9x_sndchan_6", "Enable sound channel 6; enabled|disabled" }, + { "snes9x_sndchan_7", "Enable sound channel 7; enabled|disabled" }, + { "snes9x_sndchan_8", "Enable sound channel 8; enabled|disabled" }, + { "snes9x_overscan", "Crop overscan; enabled|disabled|auto" }, + { "snes9x_aspect", "Preferred aspect ratio; 4:3|8:7|auto|ntsc|pal" }, + { NULL, NULL }, + }; - environ_cb(RETRO_ENVIRONMENT_SET_VARIABLES, variables); + environ_cb(RETRO_ENVIRONMENT_SET_VARIABLES, variables); - const struct retro_controller_description port_1[] = { - { "SNES Joypad", RETRO_DEVICE_JOYPAD }, - { "SNES Mouse", RETRO_DEVICE_MOUSE }, - { "Multitap", RETRO_DEVICE_JOYPAD_MULTITAP }, - }; + const struct retro_controller_description port_1[] = { + { "SNES Joypad", RETRO_DEVICE_JOYPAD }, + { "SNES Mouse", RETRO_DEVICE_MOUSE }, + { "Multitap", RETRO_DEVICE_JOYPAD_MULTITAP }, + }; - const struct retro_controller_description port_2[] = { - { "SNES Joypad", RETRO_DEVICE_JOYPAD }, - { "SNES Mouse", RETRO_DEVICE_MOUSE }, - { "Multitap", RETRO_DEVICE_JOYPAD_MULTITAP }, - { "SuperScope", RETRO_DEVICE_LIGHTGUN_SUPER_SCOPE }, - { "Justifier", RETRO_DEVICE_LIGHTGUN_JUSTIFIER }, - }; + const struct retro_controller_description port_2[] = { + { "SNES Joypad", RETRO_DEVICE_JOYPAD }, + { "SNES Mouse", RETRO_DEVICE_MOUSE }, + { "Multitap", RETRO_DEVICE_JOYPAD_MULTITAP }, + { "SuperScope", RETRO_DEVICE_LIGHTGUN_SUPER_SCOPE }, + { "Justifier", RETRO_DEVICE_LIGHTGUN_JUSTIFIER }, + }; - const struct retro_controller_info ports[] = { - { port_1, 3 }, - { port_2, 5 }, - { 0, 0 }, - }; + const struct retro_controller_info ports[] = { + { port_1, 3 }, + { port_2, 5 }, + { 0, 0 }, + }; - environ_cb(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void*)ports); + environ_cb(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void*)ports); } void update_geometry(void) { - struct retro_system_av_info av_info; - retro_get_system_av_info(&av_info); - environ_cb(RETRO_ENVIRONMENT_SET_GEOMETRY, &av_info); + struct retro_system_av_info av_info; + retro_get_system_av_info(&av_info); + environ_cb(RETRO_ENVIRONMENT_SET_GEOMETRY, &av_info); } static void update_variables(void) { - bool geometry_update = false; - char key[256]; - struct retro_variable var; + bool geometry_update = false; + char key[256]; + struct retro_variable var; - var.key = "snes9x_hires_blend"; - var.value = NULL; + var.key = "snes9x_hires_blend"; + var.value = NULL; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var)) - hires_blend = !strcmp(var.value, "disabled") ? false : true; - else - hires_blend = false; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var)) + hires_blend = !strcmp(var.value, "disabled") ? false : true; + else + hires_blend = false; - var.key = "snes9x_overclock_superfx"; - var.value = NULL; + var.key = "snes9x_overclock_superfx"; + var.value = NULL; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var)) - { - int freq = atoi(var.value); - Settings.SuperFXClockMultiplier = freq; - } + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var)) + { + int freq = atoi(var.value); + Settings.SuperFXClockMultiplier = freq; + } - var.key = "snes9x_hires_blend"; - var.value = NULL; + var.key = "snes9x_hires_blend"; + var.value = NULL; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var)) - hires_blend = !strcmp(var.value, "disabled") ? false : true; - else - hires_blend = false; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var)) + hires_blend = !strcmp(var.value, "disabled") ? false : true; + else + hires_blend = false; - var.key = "snes9x_up_down_allowed"; - var.value = NULL; + var.key = "snes9x_up_down_allowed"; + var.value = NULL; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var)) - { - Settings.UpAndDown = !strcmp(var.value, "disabled") ? false : true; - } - else - Settings.UpAndDown = false; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var)) + { + Settings.UpAndDown = !strcmp(var.value, "disabled") ? false : true; + } + else + Settings.UpAndDown = false; - int disabled_channels=0; - strcpy(key, "snes9x_sndchan_x"); - var.key=key; - for (int i=0;i<8;i++) - { - key[strlen("snes9x_sndchan_")]='1'+i; - var.value=NULL; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && !strcmp("disabled", var.value)) - disabled_channels|=1<= BUFFER_SIZE) - { - //this loop will never be entered, but handle oversized sample counts just in case - S9xMixSamples((uint8*)audio_buf, BUFFER_SIZE); - audio_batch_cb(audio_buf, BUFFER_SIZE >> 1); + S9xFinalizeSamples(); + size_t avail = S9xGetSampleCount(); + while (avail >= BUFFER_SIZE) + { + //this loop will never be entered, but handle oversized sample counts just in case + S9xMixSamples((uint8*)audio_buf, BUFFER_SIZE); + audio_batch_cb(audio_buf, BUFFER_SIZE >> 1); - avail -= BUFFER_SIZE; - } - if (avail > 0) - { - S9xMixSamples((uint8*)audio_buf, avail); - audio_batch_cb(audio_buf, avail >> 1); - } + avail -= BUFFER_SIZE; + } + if (avail > 0) + { + S9xMixSamples((uint8*)audio_buf, avail); + audio_batch_cb(audio_buf, avail >> 1); + } } void retro_get_system_info(struct retro_system_info *info) @@ -383,35 +383,35 @@ void retro_get_system_info(struct retro_system_info *info) float get_aspect_ratio(unsigned width, unsigned height) { - if (aspect_ratio_mode == ASPECT_RATIO_4_3) - { - return SNES_4_3; - } - else if (aspect_ratio_mode == ASPECT_RATIO_8_7) - { - return SNES_8_7; - } + if (aspect_ratio_mode == ASPECT_RATIO_4_3) + { + return SNES_4_3; + } + else if (aspect_ratio_mode == ASPECT_RATIO_8_7) + { + return SNES_8_7; + } - // OV2: not sure if these really make sense - NTSC is similar to 4:3, PAL looks weird - float sample_frequency_ntsc = 135000000.0f / 11.0f; - float sample_frequency_pal = 14750000.0; + // OV2: not sure if these really make sense - NTSC is similar to 4:3, PAL looks weird + float sample_frequency_ntsc = 135000000.0f / 11.0f; + float sample_frequency_pal = 14750000.0; - float sample_freq = retro_get_region() == RETRO_REGION_NTSC ? sample_frequency_ntsc : sample_frequency_pal; - float dot_rate = SNES::cpu.frequency / 4.0; + float sample_freq = retro_get_region() == RETRO_REGION_NTSC ? sample_frequency_ntsc : sample_frequency_pal; + float dot_rate = SNES::cpu.frequency / 4.0; - if (aspect_ratio_mode == ASPECT_RATIO_NTSC) // ntsc - { - sample_freq = sample_frequency_ntsc; - dot_rate = NTSC_MASTER_CLOCK / 4.0; - } - else if (aspect_ratio_mode == ASPECT_RATIO_PAL) // pal - { - sample_freq = sample_frequency_pal; - dot_rate = PAL_MASTER_CLOCK / 4.0; - } + if (aspect_ratio_mode == ASPECT_RATIO_NTSC) // ntsc + { + sample_freq = sample_frequency_ntsc; + dot_rate = NTSC_MASTER_CLOCK / 4.0; + } + else if (aspect_ratio_mode == ASPECT_RATIO_PAL) // pal + { + sample_freq = sample_frequency_pal; + dot_rate = PAL_MASTER_CLOCK / 4.0; + } - float par = sample_freq / 2.0 / dot_rate; - return (float)width * par / (float)height; + float par = sample_freq / 2.0 / dot_rate; + return (float)width * par / (float)height; } void retro_get_system_av_info(struct retro_system_av_info *info) @@ -420,9 +420,9 @@ void retro_get_system_av_info(struct retro_system_av_info *info) unsigned width = SNES_WIDTH; unsigned height = PPU.ScreenHeight; if (crop_overscan_mode == OVERSCAN_CROP_ON) - height = SNES_HEIGHT; + height = SNES_HEIGHT; else if (crop_overscan_mode == OVERSCAN_CROP_OFF) - height = SNES_HEIGHT_EXTENDED; + height = SNES_HEIGHT_EXTENDED; info->geometry.base_width = width; info->geometry.base_height = height; @@ -435,92 +435,92 @@ void retro_get_system_av_info(struct retro_system_av_info *info) unsigned retro_api_version() { - return RETRO_API_VERSION; + return RETRO_API_VERSION; } void retro_reset() { - S9xSoftReset(); + S9xSoftReset(); } static unsigned snes_devices[2]; void retro_set_controller_port_device(unsigned port, unsigned device) { - if (port < 2) - { - int offset = snes_devices[0] == RETRO_DEVICE_JOYPAD_MULTITAP ? 4 : 1; - switch (device) - { - case RETRO_DEVICE_JOYPAD: + if (port < 2) + { + int offset = snes_devices[0] == RETRO_DEVICE_JOYPAD_MULTITAP ? 4 : 1; + switch (device) + { + case RETRO_DEVICE_JOYPAD: S9xSetController(port, CTL_JOYPAD, port * offset, 0, 0, 0); snes_devices[port] = RETRO_DEVICE_JOYPAD; break; - case RETRO_DEVICE_JOYPAD_MULTITAP: + case RETRO_DEVICE_JOYPAD_MULTITAP: S9xSetController(port, CTL_MP5, port * offset, port * offset + 1, port * offset + 2, port * offset + 3); snes_devices[port] = RETRO_DEVICE_JOYPAD_MULTITAP; break; - case RETRO_DEVICE_MOUSE: + case RETRO_DEVICE_MOUSE: S9xSetController(port, CTL_MOUSE, port, 0, 0, 0); snes_devices[port] = RETRO_DEVICE_MOUSE; break; - case RETRO_DEVICE_LIGHTGUN_SUPER_SCOPE: + case RETRO_DEVICE_LIGHTGUN_SUPER_SCOPE: S9xSetController(port, CTL_SUPERSCOPE, 0, 0, 0, 0); snes_devices[port] = RETRO_DEVICE_LIGHTGUN_SUPER_SCOPE; break; - case RETRO_DEVICE_LIGHTGUN_JUSTIFIER: + case RETRO_DEVICE_LIGHTGUN_JUSTIFIER: S9xSetController(port, CTL_JUSTIFIER, 0, 0, 0, 0); snes_devices[port] = RETRO_DEVICE_LIGHTGUN_JUSTIFIER; break; - default: + default: if (log_cb) log_cb(RETRO_LOG_ERROR, "[libretro]: Invalid device (%d).\n", device); - } - if (!port) - retro_set_controller_port_device(1, snes_devices[1]); - } - else if(device != RETRO_DEVICE_NONE) - log_cb(RETRO_LOG_INFO, "[libretro]: Nonexistent Port (%d).\n", port); + } + if (!port) + retro_set_controller_port_device(1, snes_devices[1]); + } + else if(device != RETRO_DEVICE_NONE) + log_cb(RETRO_LOG_INFO, "[libretro]: Nonexistent Port (%d).\n", port); } void retro_cheat_reset() { - S9xDeleteCheats(); + S9xDeleteCheats(); } void retro_cheat_set(unsigned index, bool enabled, const char *codeline) { - char codeCopy[256]; - char* code; + char codeCopy[256]; + char* code; - if (codeline == (char *)'\0') return; + if (codeline == (char *)'\0') return; - strcpy(codeCopy,codeline); - code=strtok(codeCopy,"+,.; "); - while (code != NULL) { - //Convert GH RAW to PAR - if (strlen(code)==9 && code[6]==':') - { - code[6]=code[7]; - code[7]=code[8]; - code[8]='\0'; - } + strcpy(codeCopy,codeline); + code=strtok(codeCopy,"+,.; "); + while (code != NULL) { + //Convert GH RAW to PAR + if (strlen(code)==9 && code[6]==':') + { + code[6]=code[7]; + code[7]=code[8]; + code[8]='\0'; + } - /* Goldfinger was broken and nobody noticed. Removed */ - if (S9xAddCheatGroup ("retro", code) >= 0) - { - if (enabled) - S9xEnableCheatGroup (Cheat.g.size () - 1); - } - else - { - printf("CHEAT: Failed to recognize %s\n",code); - } + /* Goldfinger was broken and nobody noticed. Removed */ + if (S9xAddCheatGroup ("retro", code) >= 0) + { + if (enabled) + S9xEnableCheatGroup (Cheat.g.size () - 1); + } + else + { + printf("CHEAT: Failed to recognize %s\n",code); + } - code=strtok(NULL,"+,.; "); // bad code, ignore - } + code=strtok(NULL,"+,.; "); // bad code, ignore + } - S9xCheatsEnable(); + S9xCheatsEnable(); } #define MAX_MAPS 32 @@ -565,322 +565,322 @@ void S9xAppendMapping(struct retro_memory_descriptor *desc) static void init_descriptors(void) { - struct retro_input_descriptor desc[] = { - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "B" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "A" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "X" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Y" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, + struct retro_input_descriptor desc[] = { + { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, + { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, + { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, + { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, + { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "B" }, + { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "A" }, + { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "X" }, + { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Y" }, + { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L" }, + { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R" }, + { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, + { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "B" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "A" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "X" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Y" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, + { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, + { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, + { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, + { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, + { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "B" }, + { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "A" }, + { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "X" }, + { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Y" }, + { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L" }, + { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R" }, + { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, + { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "B" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "A" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "X" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Y" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, + { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, + { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, + { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, + { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, + { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "B" }, + { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "A" }, + { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "X" }, + { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Y" }, + { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L" }, + { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R" }, + { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, + { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "B" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "A" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "X" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Y" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, + { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, + { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, + { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, + { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, + { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "B" }, + { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "A" }, + { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "X" }, + { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Y" }, + { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L" }, + { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R" }, + { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, + { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "B" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "A" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "X" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Y" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, + { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, + { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, + { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, + { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, + { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "B" }, + { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "A" }, + { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "X" }, + { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Y" }, + { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L" }, + { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R" }, + { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, + { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, - { 0, 0, 0, 0, NULL }, - }; + { 0, 0, 0, 0, NULL }, + }; - environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc); + environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc); } static bool valid_normal_bank (uint8 bankbyte) { - switch (bankbyte) - { - case 32: case 33: case 48: case 49: - return (true); - } + switch (bankbyte) + { + case 32: case 33: case 48: case 49: + return (true); + } - return (false); + return (false); } static int is_bsx (uint8 *p) { - if ((p[26] == 0x33 || p[26] == 0xFF) && (!p[21] || (p[21] & 131) == 128) && valid_normal_bank(p[24])) - { - unsigned char m = p[22]; + if ((p[26] == 0x33 || p[26] == 0xFF) && (!p[21] || (p[21] & 131) == 128) && valid_normal_bank(p[24])) + { + unsigned char m = p[22]; - if (!m && !p[23]) - return (2); + if (!m && !p[23]) + return (2); - if ((m == 0xFF && p[23] == 0xFF) || (!(m & 0xF) && ((m >> 4) - 1 < 12))) - return (1); - } + if ((m == 0xFF && p[23] == 0xFF) || (!(m & 0xF) && ((m >> 4) - 1 < 12))) + return (1); + } - return (0); + return (0); } static void Remove_Header(uint8_t *&romptr, size_t &romsize, bool multicart_sufami) { - if (romptr==0 || romsize==0) return; + if (romptr==0 || romsize==0) return; - uint32 calc_size = (romsize / 0x2000) * 0x2000; - if ((romsize - calc_size == 512 && !Settings.ForceNoHeader) || Settings.ForceHeader) - { - romptr += 512; - romsize -= 512; + uint32 calc_size = (romsize / 0x2000) * 0x2000; + if ((romsize - calc_size == 512 && !Settings.ForceNoHeader) || Settings.ForceHeader) + { + romptr += 512; + romsize -= 512; - if(log_cb) log_cb(RETRO_LOG_INFO,"[libretro]: ROM header removed\n"); - } + if(log_cb) log_cb(RETRO_LOG_INFO,"[libretro]: ROM header removed\n"); + } - if (multicart_sufami) - { - if (strncmp((const char*)(romptr+0x100000), "BANDAI SFC-ADX", 14) == 0 && - strncmp((const char*)(romptr+0x000000), "BANDAI SFC-ADX", 14) == 0) - { - romptr += 0x100000; - romsize -= 0x100000; + if (multicart_sufami) + { + if (strncmp((const char*)(romptr+0x100000), "BANDAI SFC-ADX", 14) == 0 && + strncmp((const char*)(romptr+0x000000), "BANDAI SFC-ADX", 14) == 0) + { + romptr += 0x100000; + romsize -= 0x100000; - if(log_cb) log_cb(RETRO_LOG_INFO,"[libretro]: Sufami Turbo Multi-ROM bios removed\n"); - } - } + if(log_cb) log_cb(RETRO_LOG_INFO,"[libretro]: Sufami Turbo Multi-ROM bios removed\n"); + } + } } static bool8 LoadBIOS(uint8 *biosrom, char *biosname, int biossize) { - FILE *fp; - char name[PATH_MAX + 1]; - bool8 r = FALSE; + FILE *fp; + char name[PATH_MAX + 1]; + bool8 r = FALSE; - strcpy(name, S9xGetDirectory(ROMFILENAME_DIR)); - strcat(name, SLASH_STR); - strcat(name, biosname); + strcpy(name, S9xGetDirectory(ROMFILENAME_DIR)); + strcat(name, SLASH_STR); + strcat(name, biosname); - fp = fopen(name, "rb"); - if (!fp) - { - strcpy(name, S9xGetDirectory(BIOS_DIR)); - strcat(name, SLASH_STR); - strcat(name, biosname); + fp = fopen(name, "rb"); + if (!fp) + { + strcpy(name, S9xGetDirectory(BIOS_DIR)); + strcat(name, SLASH_STR); + strcat(name, biosname); - fp = fopen(name, "rb"); - } + fp = fopen(name, "rb"); + } - if (fp) - { - size_t size; + if (fp) + { + size_t size; - size = fread((void *) biosrom, 1, biossize, fp); - fclose(fp); - if (size == biossize) - r = TRUE; - } + size = fread((void *) biosrom, 1, biossize, fp); + fclose(fp); + if (size == biossize) + r = TRUE; + } - return (r); + return (r); } static bool8 is_SufamiTurbo_Cart (const uint8 *data, uint32 size) { - if (size >= 0x80000 && size <= 0x100000 && - strncmp((char *) data, "BANDAI SFC-ADX", 14) == 0 && strncmp((char * ) (data + 0x10), "SFC-ADX BACKUP", 14) != 0) - return (TRUE); - else - return (FALSE); + if (size >= 0x80000 && size <= 0x100000 && + strncmp((char *) data, "BANDAI SFC-ADX", 14) == 0 && strncmp((char * ) (data + 0x10), "SFC-ADX BACKUP", 14) != 0) + return (TRUE); + else + return (FALSE); } bool retro_load_game(const struct retro_game_info *game) { - init_descriptors(); + init_descriptors(); - update_variables(); + update_variables(); - if(game->data == NULL && game->size == 0 && game->path != NULL) - rom_loaded = Memory.LoadROM(game->path); - else - { - uint8 *biosrom = new uint8[0x100000]; + if(game->data == NULL && game->size == 0 && game->path != NULL) + rom_loaded = Memory.LoadROM(game->path); + else + { + uint8 *biosrom = new uint8[0x100000]; - if (game->path != NULL) - { - extract_basename(g_basename, game->path, sizeof(g_basename)); - extract_directory(g_rom_dir, game->path, sizeof(g_rom_dir)); - } + if (game->path != NULL) + { + extract_basename(g_basename, game->path, sizeof(g_basename)); + extract_directory(g_rom_dir, game->path, sizeof(g_rom_dir)); + } - if (is_SufamiTurbo_Cart((uint8 *) game->data, game->size)) { - if (rom_loaded = LoadBIOS(biosrom,"STBIOS.bin",0x40000)) + if (is_SufamiTurbo_Cart((uint8 *) game->data, game->size)) { + if (rom_loaded = LoadBIOS(biosrom,"STBIOS.bin",0x40000)) rom_loaded = Memory.LoadMultiCartMem((const uint8_t*)game->data, game->size, 0, 0, biosrom, 0x40000); - } + } - else - if ((is_bsx((uint8 *) game->data + 0x7fc0)==1) | (is_bsx((uint8 *) game->data + 0xffc0)==1)) { - if (rom_loaded = LoadBIOS(biosrom,"BS-X.bin",0x100000)) + else + if ((is_bsx((uint8 *) game->data + 0x7fc0)==1) | (is_bsx((uint8 *) game->data + 0xffc0)==1)) { + if (rom_loaded = LoadBIOS(biosrom,"BS-X.bin",0x100000)) rom_loaded = Memory.LoadMultiCartMem(biosrom, 0x100000, (const uint8_t*)game->data, game->size, 0, 0); - } + } - else - rom_loaded = Memory.LoadROMMem((const uint8_t*)game->data ,game->size); + else + rom_loaded = Memory.LoadROMMem((const uint8_t*)game->data ,game->size); - if(biosrom) delete[] biosrom; - } + if(biosrom) delete[] biosrom; + } - int pixel_format = RGB555; - if(environ_cb) - { - pixel_format = RGB565; - enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565; - if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) - pixel_format = RGB555; - } - S9xGraphicsDeinit(); - S9xSetRenderPixelFormat(pixel_format); - S9xGraphicsInit(); + int pixel_format = RGB555; + if(environ_cb) + { + pixel_format = RGB565; + enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565; + if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) + pixel_format = RGB555; + } + S9xGraphicsDeinit(); + S9xSetRenderPixelFormat(pixel_format); + S9xGraphicsInit(); - struct retro_memory_map map={ memorydesc+MAX_MAPS-memorydesc_c, memorydesc_c }; - if (rom_loaded) - { - environ_cb(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &map); - update_geometry(); - } + struct retro_memory_map map={ memorydesc+MAX_MAPS-memorydesc_c, memorydesc_c }; + if (rom_loaded) + { + environ_cb(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &map); + update_geometry(); + } - if (!rom_loaded && log_cb) - log_cb(RETRO_LOG_ERROR, "[libretro]: Rom loading failed...\n"); + if (!rom_loaded && log_cb) + log_cb(RETRO_LOG_ERROR, "[libretro]: Rom loading failed...\n"); - return rom_loaded; + return rom_loaded; } bool retro_load_game_special(unsigned game_type, const struct retro_game_info *info, size_t num_info) { - uint8_t *romptr[3]; - size_t romsize[3]; + uint8_t *romptr[3]; + size_t romsize[3]; - for(size_t lcv=0; lcv (SNES_WIDTH-1)) snes_scope_state[0] = SNES_WIDTH-1; @@ -1183,15 +1183,15 @@ static void report_buttons() else if (snes_scope_state[1] > (SNES_HEIGHT-1)) snes_scope_state[1] = SNES_HEIGHT-1; S9xReportPointer(BTN_POINTER, snes_scope_state[0], snes_scope_state[1]); for (int i = SCOPE_TRIGGER; i <= SCOPE_LAST; i++) - S9xReportButton(MAKE_BUTTON(2, i), input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, i)); + S9xReportButton(MAKE_BUTTON(2, i), input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, i)); break; - case RETRO_DEVICE_LIGHTGUN_JUSTIFIER: - case RETRO_DEVICE_LIGHTGUN_JUSTIFIERS: + case RETRO_DEVICE_LIGHTGUN_JUSTIFIER: + case RETRO_DEVICE_LIGHTGUN_JUSTIFIERS: if(runahead_poll) { - snes_justifier_state[port][0] += input_state_cb(port, RETRO_DEVICE_LIGHTGUN_JUSTIFIER, 0, RETRO_DEVICE_ID_LIGHTGUN_X); - snes_justifier_state[port][1] += input_state_cb(port, RETRO_DEVICE_LIGHTGUN_JUSTIFIER, 0, RETRO_DEVICE_ID_LIGHTGUN_Y); + snes_justifier_state[port][0] += input_state_cb(port, RETRO_DEVICE_LIGHTGUN_JUSTIFIER, 0, RETRO_DEVICE_ID_LIGHTGUN_X); + snes_justifier_state[port][1] += input_state_cb(port, RETRO_DEVICE_LIGHTGUN_JUSTIFIER, 0, RETRO_DEVICE_ID_LIGHTGUN_Y); } if (snes_justifier_state[port][0] < 0) snes_justifier_state[port][0] = 0; else if (snes_justifier_state[port][0] > (SNES_WIDTH-1)) snes_justifier_state[port][0] = SNES_WIDTH-1; @@ -1199,195 +1199,195 @@ static void report_buttons() else if (snes_justifier_state[port][1] > (SNES_HEIGHT-1)) snes_justifier_state[port][1] = SNES_HEIGHT-1; S9xReportPointer(BTN_POINTER, snes_justifier_state[port][0], snes_justifier_state[port][1]); for (int i = JUSTIFIER_TRIGGER; i <= JUSTIFIER_LAST; i++) - S9xReportButton(MAKE_BUTTON(2, i), input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, i)); + S9xReportButton(MAKE_BUTTON(2, i), input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, i)); break; - default: + default: if (log_cb) - log_cb(RETRO_LOG_ERROR, "[libretro]: Unknown device...\n"); - } - } + log_cb(RETRO_LOG_ERROR, "[libretro]: Unknown device...\n"); + } + } } void retro_run() { - static uint16 height = PPU.ScreenHeight; - bool updated = false; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated) - update_variables(); - if (height != PPU.ScreenHeight) - { - update_geometry(); - height = PPU.ScreenHeight; - } + static uint16 height = PPU.ScreenHeight; + bool updated = false; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated) + update_variables(); + if (height != PPU.ScreenHeight) + { + update_geometry(); + height = PPU.ScreenHeight; + } - int result = -1; - bool okay = environ_cb(RETRO_ENVIRONMENT_GET_AUDIO_VIDEO_ENABLE, &result); - if (okay) - { - bool audioEnabled = 0 != (result & 2); - bool videoEnabled = 0 != (result & 1); - IPPU.RenderThisFrame = videoEnabled; - S9xSetSoundMute(!audioEnabled); - } - else - { - IPPU.RenderThisFrame = true; - S9xSetSoundMute(false); - } + int result = -1; + bool okay = environ_cb(RETRO_ENVIRONMENT_GET_AUDIO_VIDEO_ENABLE, &result); + if (okay) + { + bool audioEnabled = 0 != (result & 2); + bool videoEnabled = 0 != (result & 1); + IPPU.RenderThisFrame = videoEnabled; + S9xSetSoundMute(!audioEnabled); + } + else + { + IPPU.RenderThisFrame = true; + S9xSetSoundMute(false); + } - poll_cb(); - report_buttons(); - S9xMainLoop(); - S9xAudioCallback(NULL); + poll_cb(); + report_buttons(); + S9xMainLoop(); + S9xAudioCallback(NULL); } void retro_deinit() { - S9xDeinitAPU(); - Memory.Deinit(); - S9xGraphicsDeinit(); - S9xUnmapAllControls(); + S9xDeinitAPU(); + Memory.Deinit(); + S9xGraphicsDeinit(); + S9xUnmapAllControls(); - free(GFX.Screen); - free(gfx_blend); + free(GFX.Screen); + free(gfx_blend); } unsigned retro_get_region() { - return Settings.PAL ? RETRO_REGION_PAL : RETRO_REGION_NTSC; + return Settings.PAL ? RETRO_REGION_PAL : RETRO_REGION_NTSC; } void* retro_get_memory_data(unsigned type) { - void* data; + void* data; - switch(type) { - case RETRO_MEMORY_SNES_SUFAMI_TURBO_A_RAM: - case RETRO_MEMORY_SAVE_RAM: - data = Memory.SRAM; - break; - case RETRO_MEMORY_SNES_SUFAMI_TURBO_B_RAM: - data = Multi.sramB; - break; - case RETRO_MEMORY_RTC: - data = RTCData.reg; - break; - case RETRO_MEMORY_SYSTEM_RAM: + switch(type) { + case RETRO_MEMORY_SNES_SUFAMI_TURBO_A_RAM: + case RETRO_MEMORY_SAVE_RAM: + data = Memory.SRAM; + break; + case RETRO_MEMORY_SNES_SUFAMI_TURBO_B_RAM: + data = Multi.sramB; + break; + case RETRO_MEMORY_RTC: + data = RTCData.reg; + break; + case RETRO_MEMORY_SYSTEM_RAM: data = Memory.RAM; break; - case RETRO_MEMORY_VIDEO_RAM: + case RETRO_MEMORY_VIDEO_RAM: data = Memory.VRAM; break; - //case RETRO_MEMORY_ROM: - // data = Memory.ROM; - // break; - default: - data = NULL; - break; - } + //case RETRO_MEMORY_ROM: + // data = Memory.ROM; + // break; + default: + data = NULL; + break; + } - return data; + return data; } size_t retro_get_memory_size(unsigned type) { - size_t size; + size_t size; - switch(type) { - case RETRO_MEMORY_SNES_SUFAMI_TURBO_A_RAM: - case RETRO_MEMORY_SAVE_RAM: - size = (unsigned) (Memory.SRAMSize ? (1 << (Memory.SRAMSize + 3)) * 128 : 0); - if (size > 0x20000) - size = 0x20000; - break; - case RETRO_MEMORY_SNES_SUFAMI_TURBO_B_RAM: - size = (unsigned) (Multi.cartType==4 && Multi.sramSizeB ? (1 << (Multi.sramSizeB + 3)) * 128 : 0); - break; - case RETRO_MEMORY_RTC: - size = (Settings.SRTC || Settings.SPC7110RTC)?20:0; - break; - case RETRO_MEMORY_SYSTEM_RAM: - size = 128 * 1024; - break; - case RETRO_MEMORY_VIDEO_RAM: - size = 64 * 1024; - break; - //case RETRO_MEMORY_ROM: - // size = Memory.CalculatedSize; - // break; - default: - size = 0; - break; - } + switch(type) { + case RETRO_MEMORY_SNES_SUFAMI_TURBO_A_RAM: + case RETRO_MEMORY_SAVE_RAM: + size = (unsigned) (Memory.SRAMSize ? (1 << (Memory.SRAMSize + 3)) * 128 : 0); + if (size > 0x20000) + size = 0x20000; + break; + case RETRO_MEMORY_SNES_SUFAMI_TURBO_B_RAM: + size = (unsigned) (Multi.cartType==4 && Multi.sramSizeB ? (1 << (Multi.sramSizeB + 3)) * 128 : 0); + break; + case RETRO_MEMORY_RTC: + size = (Settings.SRTC || Settings.SPC7110RTC)?20:0; + break; + case RETRO_MEMORY_SYSTEM_RAM: + size = 128 * 1024; + break; + case RETRO_MEMORY_VIDEO_RAM: + size = 64 * 1024; + break; + //case RETRO_MEMORY_ROM: + // size = Memory.CalculatedSize; + // break; + default: + size = 0; + break; + } - return size; + return size; } size_t retro_serialize_size() { - return rom_loaded ? S9xFreezeSize() : 0; + return rom_loaded ? S9xFreezeSize() : 0; } bool retro_serialize(void *data, size_t size) { - if (S9xFreezeGameMem((uint8_t*)data,size) == FALSE) - return false; + if (S9xFreezeGameMem((uint8_t*)data,size) == FALSE) + return false; - return true; + return true; } bool retro_unserialize(const void* data, size_t size) { - if (S9xUnfreezeGameMem((const uint8_t*)data,size) != SUCCESS) - return false; + if (S9xUnfreezeGameMem((const uint8_t*)data,size) != SUCCESS) + return false; - return true; + return true; } bool8 S9xDeinitUpdate(int width, int height) { - if (crop_overscan_mode == OVERSCAN_CROP_ON) - { - if (height >= SNES_HEIGHT << 1) - { - height = SNES_HEIGHT << 1; - } - else - { - height = SNES_HEIGHT; - } - } - else if (crop_overscan_mode == OVERSCAN_CROP_OFF) - { - if (height > SNES_HEIGHT_EXTENDED) - { - if (height < SNES_HEIGHT_EXTENDED << 1) + if (crop_overscan_mode == OVERSCAN_CROP_ON) + { + if (height >= SNES_HEIGHT << 1) + { + height = SNES_HEIGHT << 1; + } + else + { + height = SNES_HEIGHT; + } + } + else if (crop_overscan_mode == OVERSCAN_CROP_OFF) + { + if (height > SNES_HEIGHT_EXTENDED) + { + if (height < SNES_HEIGHT_EXTENDED << 1) memset(GFX.Screen + (GFX.Pitch >> 1) * height,0,GFX.Pitch * ((SNES_HEIGHT_EXTENDED << 1) - height)); - height = SNES_HEIGHT_EXTENDED << 1; - } - else - { - if (height < SNES_HEIGHT_EXTENDED) + height = SNES_HEIGHT_EXTENDED << 1; + } + else + { + if (height < SNES_HEIGHT_EXTENDED) memset(GFX.Screen + (GFX.Pitch >> 1) * height,0,GFX.Pitch * (SNES_HEIGHT_EXTENDED - height)); - height = SNES_HEIGHT_EXTENDED; - } - } + height = SNES_HEIGHT_EXTENDED; + } + } - if(width==MAX_SNES_WIDTH && hires_blend) - { + if(width==MAX_SNES_WIDTH && hires_blend) + { #define AVERAGE_565(el0, el1) (((el0) & (el1)) + ((((el0) ^ (el1)) & 0xF7DE) >> 1)) - for (register int y = 0; y < height; y++) - { - register uint16 *input = (uint16 *) ((uint8 *) GFX.Screen + y * GFX.Pitch); - register uint16 *output = (uint16 *) ((uint8 *) gfx_blend + y * GFX.Pitch); - register uint16 l, r; + for (register int y = 0; y < height; y++) + { + register uint16 *input = (uint16 *) ((uint8 *) GFX.Screen + y * GFX.Pitch); + register uint16 *output = (uint16 *) ((uint8 *) gfx_blend + y * GFX.Pitch); + register uint16 l, r; - l = 0; - for (register int x = 0; x < (width >> 1); x++) - { + l = 0; + for (register int x = 0; x < (width >> 1); x++) + { r = *input++; *output++ = AVERAGE_565 (l, r); l = r; @@ -1395,23 +1395,23 @@ bool8 S9xDeinitUpdate(int width, int height) r = *input++; *output++ = AVERAGE_565 (l, r); l = r; - } - } + } + } - video_cb(gfx_blend, width, height, GFX.Pitch); - } - else - { - video_cb(GFX.Screen, width, height, GFX.Pitch); - } + video_cb(gfx_blend, width, height, GFX.Pitch); + } + else + { + video_cb(GFX.Screen, width, height, GFX.Pitch); + } - return TRUE; + return TRUE; } bool8 S9xContinueUpdate(int width, int height) { - S9xDeinitUpdate(width, height); - return true; + S9xDeinitUpdate(width, height); + return true; } // Dummy functions that should probably be implemented correctly later. @@ -1427,35 +1427,35 @@ const char* S9xStringInput(const char* in) { return in; } const char* S9xGetFilename(const char* in, s9x_getdirtype type) { - static char newpath[2048]; + static char newpath[2048]; - newpath[0] = '\0'; + newpath[0] = '\0'; - switch (type) - { - case ROMFILENAME_DIR: - sprintf(newpath, "%s%c%s%s", g_rom_dir, SLASH, g_basename, in); - return newpath; - default: - break; - } + switch (type) + { + case ROMFILENAME_DIR: + sprintf(newpath, "%s%c%s%s", g_rom_dir, SLASH, g_basename, in); + return newpath; + default: + break; + } - return in; + return in; } const char* S9xGetDirectory(s9x_getdirtype type) { - switch (type) - { - case ROMFILENAME_DIR: - return g_rom_dir; - case BIOS_DIR: - return retro_system_directory; - default: - break; - } + switch (type) + { + case ROMFILENAME_DIR: + return g_rom_dir; + case BIOS_DIR: + return retro_system_directory; + default: + break; + } - return ""; + return ""; } void S9xInitInputDevices() {} const char* S9xChooseFilename(unsigned char) { return ""; } @@ -1476,116 +1476,116 @@ bool S9xPollPointer(unsigned int, short*, short*) { return false; } const char *S9xChooseMovieFilename(unsigned char) { return NULL; } void S9xMessage(int type, int, const char* s) { - if (!log_cb) return; + if (!log_cb) return; - switch (type) - { - case S9X_DEBUG: - log_cb(RETRO_LOG_DEBUG, "%s\n", s); - break; - case S9X_WARNING: - log_cb(RETRO_LOG_WARN, "%s\n", s); - break; - case S9X_INFO: - log_cb(RETRO_LOG_INFO, "%s\n", s); - break; - case S9X_ERROR: - log_cb(RETRO_LOG_ERROR, "%s\n", s); - break; - default: - log_cb(RETRO_LOG_DEBUG, "%s\n", s); - break; - } + switch (type) + { + case S9X_DEBUG: + log_cb(RETRO_LOG_DEBUG, "%s\n", s); + break; + case S9X_WARNING: + log_cb(RETRO_LOG_WARN, "%s\n", s); + break; + case S9X_INFO: + log_cb(RETRO_LOG_INFO, "%s\n", s); + break; + case S9X_ERROR: + log_cb(RETRO_LOG_ERROR, "%s\n", s); + break; + default: + log_cb(RETRO_LOG_DEBUG, "%s\n", s); + break; + } } bool8 S9xOpenSnapshotFile(const char* filepath, bool8 read_only, STREAM *file) { - if(read_only) - { - if((*file = OPEN_STREAM(filepath, "rb")) != 0) - { - return (TRUE); - } - } - else - { - if((*file = OPEN_STREAM(filepath, "wb")) != 0) - { - return (TRUE); - } - } - return (FALSE); + if(read_only) + { + if((*file = OPEN_STREAM(filepath, "rb")) != 0) + { + return (TRUE); + } + } + else + { + if((*file = OPEN_STREAM(filepath, "wb")) != 0) + { + return (TRUE); + } + } + return (FALSE); } void S9xCloseSnapshotFile(STREAM file) { - CLOSE_STREAM(file); + CLOSE_STREAM(file); } void S9xAutoSaveSRAM() { - return; + return; } #ifndef __WIN32__ // S9x weirdness. void _splitpath (const char *path, char *drive, char *dir, char *fname, char *ext) { - *drive = 0; + *drive = 0; - const char *slash = strrchr(path, SLASH_CHAR), - *dot = strrchr(path, '.'); + const char *slash = strrchr(path, SLASH_CHAR), + *dot = strrchr(path, '.'); - if (dot && slash && dot < slash) - dot = NULL; + if (dot && slash && dot < slash) + dot = NULL; - if (!slash) - { - *dir = 0; + if (!slash) + { + *dir = 0; - strcpy(fname, path); + strcpy(fname, path); - if (dot) - { - fname[dot - path] = 0; - strcpy(ext, dot + 1); - } - else - *ext = 0; - } - else - { - strcpy(dir, path); - dir[slash - path] = 0; + 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); + strcpy(fname, slash + 1); - if (dot) - { - fname[dot - slash - 1] = 0; - strcpy(ext, dot + 1); - } - else - *ext = 0; - } + if (dot) + { + fname[dot - slash - 1] = 0; + strcpy(ext, dot + 1); + } + else + *ext = 0; + } } void _makepath (char *path, const char *, const char *dir, const char *fname, const char *ext) { - if (dir && *dir) - { - strcpy(path, dir); - strcat(path, SLASH_STR); - } - else - *path = 0; + if (dir && *dir) + { + strcpy(path, dir); + strcat(path, SLASH_STR); + } + else + *path = 0; - strcat(path, fname); + strcat(path, fname); - if (ext && *ext) - { - strcat(path, "."); - strcat(path, ext); - } + if (ext && *ext) + { + strcat(path, "."); + strcat(path, ext); + } } #endif // __WIN32__ From 6edc57db55b0d4fb262fd3b228b204283bce07cd Mon Sep 17 00:00:00 2001 From: radius Date: Sat, 30 Jun 2018 19:11:20 -0500 Subject: [PATCH 11/15] fix indentation --- libretro/libretro.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libretro/libretro.cpp b/libretro/libretro.cpp index 758180eb..8dfd7a3e 100644 --- a/libretro/libretro.cpp +++ b/libretro/libretro.cpp @@ -35,11 +35,11 @@ #define RETRO_MEMORY_SNES_GAME_BOY_RAM ((5 << 8) | RETRO_MEMORY_SAVE_RAM) #define RETRO_MEMORY_SNES_GAME_BOY_RTC ((6 << 8) | RETRO_MEMORY_RTC) -#define RETRO_GAME_TYPE_BSX 0x101 | 0x1000 -#define RETRO_GAME_TYPE_BSX_SLOTTED 0x102 | 0x1000 -#define RETRO_GAME_TYPE_SUFAMI_TURBO 0x103 | 0x1000 +#define RETRO_GAME_TYPE_BSX 0x101 | 0x1000 +#define RETRO_GAME_TYPE_BSX_SLOTTED 0x102 | 0x1000 +#define RETRO_GAME_TYPE_SUFAMI_TURBO 0x103 | 0x1000 #define RETRO_GAME_TYPE_SUPER_GAME_BOY 0x104 | 0x1000 -#define RETRO_GAME_TYPE_MULTI_CART 0x105 | 0x1000 +#define RETRO_GAME_TYPE_MULTI_CART 0x105 | 0x1000 #define SNES_4_3 4.0f / 3.0f From c85d9812013a5392d111f6b39e13b968436bd86a Mon Sep 17 00:00:00 2001 From: radius Date: Sun, 1 Jul 2018 10:00:30 -0500 Subject: [PATCH 12/15] build fix, fix sfx overclock --- libretro/libretro.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libretro/libretro.cpp b/libretro/libretro.cpp index 8dfd7a3e..b625df12 100644 --- a/libretro/libretro.cpp +++ b/libretro/libretro.cpp @@ -168,7 +168,7 @@ void retro_set_environment(retro_environment_t cb) // Adding more variables and rearranging them is safe. { "snes9x_up_down_allowed", "Allow Opposing Directions; disabled|enabled" }, { "snes9x_hires_blend", "Hires Blending; disabled|enabled" }, - { "snes9x_overclock", "SuperFX Frequency; 100%|200%|400%|600%|800%|1000%" }, + { "snes9x_overclock_superfx", "SuperFX Overclocking; 100%|150%|200%|250%|300%|350%|400%|450%|500%|50%" }, //{ "snes9x_overclock_cycles", "Reduce Slowdown (Hack, Unsafe); disabled|compatible|max" }, //{ "snes9x_reduce_sprite_flicker", "Reduce Flickering (Hack, Unsafe); disabled|enabled" }, { "snes9x_layer_1", "Show layer 1; enabled|disabled" }, @@ -894,7 +894,6 @@ bool retro_load_game_special(unsigned game_type, const struct retro_game_info *i struct retro_memory_map map={ memorydesc+MAX_MAPS-memorydesc_c, memorydesc_c }; environ_cb(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &map); update_geometry(); - audio_interp_max = 32768; } return rom_loaded; From 5a75d5dec8be27921fd8425c1081b0da079c8ec6 Mon Sep 17 00:00:00 2001 From: radius Date: Sun, 1 Jul 2018 10:20:01 -0500 Subject: [PATCH 13/15] fix controller assignment --- libretro/libretro.cpp | 159 +++++++++++++++++++++++------------------- 1 file changed, 89 insertions(+), 70 deletions(-) diff --git a/libretro/libretro.cpp b/libretro/libretro.cpp index b625df12..127739b9 100644 --- a/libretro/libretro.cpp +++ b/libretro/libretro.cpp @@ -194,13 +194,15 @@ void retro_set_environment(retro_environment_t cb) environ_cb(RETRO_ENVIRONMENT_SET_VARIABLES, variables); - const struct retro_controller_description port_1[] = { + static const struct retro_controller_description port_1[] = { + { "None", RETRO_DEVICE_NONE }, { "SNES Joypad", RETRO_DEVICE_JOYPAD }, { "SNES Mouse", RETRO_DEVICE_MOUSE }, { "Multitap", RETRO_DEVICE_JOYPAD_MULTITAP }, }; - const struct retro_controller_description port_2[] = { + static const struct retro_controller_description port_2[] = { + { "None", RETRO_DEVICE_NONE }, { "SNES Joypad", RETRO_DEVICE_JOYPAD }, { "SNES Mouse", RETRO_DEVICE_MOUSE }, { "Multitap", RETRO_DEVICE_JOYPAD_MULTITAP }, @@ -208,10 +210,21 @@ void retro_set_environment(retro_environment_t cb) { "Justifier", RETRO_DEVICE_LIGHTGUN_JUSTIFIER }, }; - const struct retro_controller_info ports[] = { - { port_1, 3 }, - { port_2, 5 }, - { 0, 0 }, + static const struct retro_controller_description port_3[] = { + { "None", RETRO_DEVICE_NONE }, + { "SNES Joypad", RETRO_DEVICE_JOYPAD }, + }; + + static const struct retro_controller_info ports[] = { + { port_1, 4 }, + { port_2, 6 }, + { port_3, 2 }, + { port_3, 2 }, + { port_3, 2 }, + { port_3, 2 }, + { port_3, 2 }, + { port_3, 2 }, + {}, }; environ_cb(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void*)ports); @@ -447,37 +460,40 @@ void retro_reset() static unsigned snes_devices[2]; void retro_set_controller_port_device(unsigned port, unsigned device) { - if (port < 2) + if (port < 8) { int offset = snes_devices[0] == RETRO_DEVICE_JOYPAD_MULTITAP ? 4 : 1; switch (device) { case RETRO_DEVICE_JOYPAD: - S9xSetController(port, CTL_JOYPAD, port * offset, 0, 0, 0); - snes_devices[port] = RETRO_DEVICE_JOYPAD; - break; + S9xSetController(port, CTL_JOYPAD, port * offset, 0, 0, 0); + snes_devices[port] = RETRO_DEVICE_JOYPAD; + break; case RETRO_DEVICE_JOYPAD_MULTITAP: - S9xSetController(port, CTL_MP5, port * offset, port * offset + 1, port * offset + 2, port * offset + 3); - snes_devices[port] = RETRO_DEVICE_JOYPAD_MULTITAP; - break; + S9xSetController(port, CTL_MP5, port * offset, port * offset + 1, port * offset + 2, port * offset + 3); + snes_devices[port] = RETRO_DEVICE_JOYPAD_MULTITAP; + break; case RETRO_DEVICE_MOUSE: - S9xSetController(port, CTL_MOUSE, port, 0, 0, 0); - snes_devices[port] = RETRO_DEVICE_MOUSE; - break; + S9xSetController(port, CTL_MOUSE, port, 0, 0, 0); + snes_devices[port] = RETRO_DEVICE_MOUSE; + break; case RETRO_DEVICE_LIGHTGUN_SUPER_SCOPE: - S9xSetController(port, CTL_SUPERSCOPE, 0, 0, 0, 0); - snes_devices[port] = RETRO_DEVICE_LIGHTGUN_SUPER_SCOPE; - break; + S9xSetController(port, CTL_SUPERSCOPE, 0, 0, 0, 0); + snes_devices[port] = RETRO_DEVICE_LIGHTGUN_SUPER_SCOPE; + break; case RETRO_DEVICE_LIGHTGUN_JUSTIFIER: - S9xSetController(port, CTL_JUSTIFIER, 0, 0, 0, 0); - snes_devices[port] = RETRO_DEVICE_LIGHTGUN_JUSTIFIER; - break; + S9xSetController(port, CTL_JUSTIFIER, 0, 0, 0, 0); + snes_devices[port] = RETRO_DEVICE_LIGHTGUN_JUSTIFIER; + break; + case RETRO_DEVICE_NONE: + S9xSetController(port, CTL_NONE, 0, 0, 0, 0); + snes_devices[port] = RETRO_DEVICE_NONE; + break; default: - if (log_cb) - log_cb(RETRO_LOG_ERROR, "[libretro]: Invalid device (%d).\n", device); + if (log_cb) + log_cb(RETRO_LOG_ERROR, "[libretro]: Invalid device (%d).\n", device); + break; } - if (!port) - retro_set_controller_port_device(1, snes_devices[1]); } else if(device != RETRO_DEVICE_NONE) log_cb(RETRO_LOG_INFO, "[libretro]: Nonexistent Port (%d).\n", port); @@ -1149,61 +1165,64 @@ static void report_buttons() switch (snes_devices[port]) { case RETRO_DEVICE_JOYPAD: - for (int i = BTN_FIRST; i <= BTN_LAST; i++) - S9xReportButton(MAKE_BUTTON(port * offset + 1, i), input_state_cb(port * offset, RETRO_DEVICE_JOYPAD, 0, i)); - break; + for (int i = BTN_FIRST; i <= BTN_LAST; i++) + S9xReportButton(MAKE_BUTTON(port * offset + 1, i), input_state_cb(port * offset, RETRO_DEVICE_JOYPAD, 0, i)); + break; case RETRO_DEVICE_JOYPAD_MULTITAP: - for (int j = 0; j < 4; j++) - for (int i = BTN_FIRST; i <= BTN_LAST; i++) - S9xReportButton(MAKE_BUTTON(port * offset + j + 1, i), input_state_cb(port * offset + j, RETRO_DEVICE_JOYPAD, 0, i)); - break; + for (int j = 0; j < 4; j++) + for (int i = BTN_FIRST; i <= BTN_LAST; i++) + S9xReportButton(MAKE_BUTTON(port * offset + j + 1, i), input_state_cb(port * offset + j, RETRO_DEVICE_JOYPAD, 0, i)); + break; case RETRO_DEVICE_MOUSE: - if(runahead_poll) - { - snes_mouse_state[port][0] = input_state_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_X); - snes_mouse_state[port][1] = input_state_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_Y); - } - S9xReportPointer(BTN_POINTER + port, snes_mouse_state[port][0], snes_mouse_state[port][1]); - for (int i = MOUSE_LEFT; i <= MOUSE_LAST; i++) - S9xReportButton(MAKE_BUTTON(port + 1, i), input_state_cb(port, RETRO_DEVICE_MOUSE, 0, i)); - break; + if(runahead_poll) + { + snes_mouse_state[port][0] = input_state_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_X); + snes_mouse_state[port][1] = input_state_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_Y); + } + S9xReportPointer(BTN_POINTER + port, snes_mouse_state[port][0], snes_mouse_state[port][1]); + for (int i = MOUSE_LEFT; i <= MOUSE_LAST; i++) + S9xReportButton(MAKE_BUTTON(port + 1, i), input_state_cb(port, RETRO_DEVICE_MOUSE, 0, i)); + break; case RETRO_DEVICE_LIGHTGUN_SUPER_SCOPE: - if(runahead_poll) - { - snes_scope_state[0] += input_state_cb(port, RETRO_DEVICE_LIGHTGUN_SUPER_SCOPE, 0, RETRO_DEVICE_ID_LIGHTGUN_X); - snes_scope_state[1] += input_state_cb(port, RETRO_DEVICE_LIGHTGUN_SUPER_SCOPE, 0, RETRO_DEVICE_ID_LIGHTGUN_Y); - } - if (snes_scope_state[0] < 0) snes_scope_state[0] = 0; - else if (snes_scope_state[0] > (SNES_WIDTH-1)) snes_scope_state[0] = SNES_WIDTH-1; - if (snes_scope_state[1] < 0) snes_scope_state[1] = 0; - else if (snes_scope_state[1] > (SNES_HEIGHT-1)) snes_scope_state[1] = SNES_HEIGHT-1; - S9xReportPointer(BTN_POINTER, snes_scope_state[0], snes_scope_state[1]); - for (int i = SCOPE_TRIGGER; i <= SCOPE_LAST; i++) - S9xReportButton(MAKE_BUTTON(2, i), input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, i)); - break; + if(runahead_poll) + { + snes_scope_state[0] += input_state_cb(port, RETRO_DEVICE_LIGHTGUN_SUPER_SCOPE, 0, RETRO_DEVICE_ID_LIGHTGUN_X); + snes_scope_state[1] += input_state_cb(port, RETRO_DEVICE_LIGHTGUN_SUPER_SCOPE, 0, RETRO_DEVICE_ID_LIGHTGUN_Y); + } + if (snes_scope_state[0] < 0) snes_scope_state[0] = 0; + else if (snes_scope_state[0] > (SNES_WIDTH-1)) snes_scope_state[0] = SNES_WIDTH-1; + if (snes_scope_state[1] < 0) snes_scope_state[1] = 0; + else if (snes_scope_state[1] > (SNES_HEIGHT-1)) snes_scope_state[1] = SNES_HEIGHT-1; + S9xReportPointer(BTN_POINTER, snes_scope_state[0], snes_scope_state[1]); + for (int i = SCOPE_TRIGGER; i <= SCOPE_LAST; i++) + S9xReportButton(MAKE_BUTTON(2, i), input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, i)); + break; case RETRO_DEVICE_LIGHTGUN_JUSTIFIER: case RETRO_DEVICE_LIGHTGUN_JUSTIFIERS: - if(runahead_poll) - { - snes_justifier_state[port][0] += input_state_cb(port, RETRO_DEVICE_LIGHTGUN_JUSTIFIER, 0, RETRO_DEVICE_ID_LIGHTGUN_X); - snes_justifier_state[port][1] += input_state_cb(port, RETRO_DEVICE_LIGHTGUN_JUSTIFIER, 0, RETRO_DEVICE_ID_LIGHTGUN_Y); - } - if (snes_justifier_state[port][0] < 0) snes_justifier_state[port][0] = 0; - else if (snes_justifier_state[port][0] > (SNES_WIDTH-1)) snes_justifier_state[port][0] = SNES_WIDTH-1; - if (snes_justifier_state[port][1] < 0) snes_justifier_state[port][1] = 0; - else if (snes_justifier_state[port][1] > (SNES_HEIGHT-1)) snes_justifier_state[port][1] = SNES_HEIGHT-1; - S9xReportPointer(BTN_POINTER, snes_justifier_state[port][0], snes_justifier_state[port][1]); - for (int i = JUSTIFIER_TRIGGER; i <= JUSTIFIER_LAST; i++) - S9xReportButton(MAKE_BUTTON(2, i), input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, i)); - break; + if(runahead_poll) + { + snes_justifier_state[port][0] += input_state_cb(port, RETRO_DEVICE_LIGHTGUN_JUSTIFIER, 0, RETRO_DEVICE_ID_LIGHTGUN_X); + snes_justifier_state[port][1] += input_state_cb(port, RETRO_DEVICE_LIGHTGUN_JUSTIFIER, 0, RETRO_DEVICE_ID_LIGHTGUN_Y); + } + if (snes_justifier_state[port][0] < 0) snes_justifier_state[port][0] = 0; + else if (snes_justifier_state[port][0] > (SNES_WIDTH-1)) snes_justifier_state[port][0] = SNES_WIDTH-1; + if (snes_justifier_state[port][1] < 0) snes_justifier_state[port][1] = 0; + else if (snes_justifier_state[port][1] > (SNES_HEIGHT-1)) snes_justifier_state[port][1] = SNES_HEIGHT-1; + S9xReportPointer(BTN_POINTER, snes_justifier_state[port][0], snes_justifier_state[port][1]); + for (int i = JUSTIFIER_TRIGGER; i <= JUSTIFIER_LAST; i++) + S9xReportButton(MAKE_BUTTON(2, i), input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, i)); + break; + + case RETRO_DEVICE_NONE: + break; default: - if (log_cb) - log_cb(RETRO_LOG_ERROR, "[libretro]: Unknown device...\n"); + if (log_cb) + log_cb(RETRO_LOG_ERROR, "[libretro]: Unknown device...\n"); } } } From 4154e6b3ddc782c23e429afa994dff889b1e5d0c Mon Sep 17 00:00:00 2001 From: radius Date: Sun, 1 Jul 2018 12:16:37 -0500 Subject: [PATCH 14/15] fix multicart link --- libretro/libretro.cpp | 147 ++++++++++++++++++++++-------------------- 1 file changed, 77 insertions(+), 70 deletions(-) diff --git a/libretro/libretro.cpp b/libretro/libretro.cpp index 127739b9..7f89a5cb 100644 --- a/libretro/libretro.cpp +++ b/libretro/libretro.cpp @@ -680,32 +680,6 @@ static int is_bsx (uint8 *p) return (0); } -static void Remove_Header(uint8_t *&romptr, size_t &romsize, bool multicart_sufami) -{ - if (romptr==0 || romsize==0) return; - - uint32 calc_size = (romsize / 0x2000) * 0x2000; - if ((romsize - calc_size == 512 && !Settings.ForceNoHeader) || Settings.ForceHeader) - { - romptr += 512; - romsize -= 512; - - if(log_cb) log_cb(RETRO_LOG_INFO,"[libretro]: ROM header removed\n"); - } - - if (multicart_sufami) - { - if (strncmp((const char*)(romptr+0x100000), "BANDAI SFC-ADX", 14) == 0 && - strncmp((const char*)(romptr+0x000000), "BANDAI SFC-ADX", 14) == 0) - { - romptr += 0x100000; - romsize -= 0x100000; - - if(log_cb) log_cb(RETRO_LOG_INFO,"[libretro]: Sufami Turbo Multi-ROM bios removed\n"); - } - } -} - static bool8 LoadBIOS(uint8 *biosrom, char *biosname, int biossize) { FILE *fp; @@ -808,17 +782,42 @@ bool retro_load_game(const struct retro_game_info *game) return rom_loaded; } +static void remove_header(uint8_t *&romptr, size_t &romsize, bool multicart_sufami) +{ + if (romptr==0 || romsize==0) return; + + uint32 calc_size = (romsize / 0x2000) * 0x2000; + if ((romsize - calc_size == 512 && !Settings.ForceNoHeader) || Settings.ForceHeader) + { + romptr += 512; + romsize -= 512; + + if(log_cb) log_cb(RETRO_LOG_INFO,"[libretro]: ROM header removed\n"); + } + + if (multicart_sufami && (romptr + romsize) >= (romptr + 0x100000)) + { + if (strncmp((const char*)(romptr + 0x100000), "BANDAI SFC-ADX", 14) == 0 && + strncmp((const char*)(romptr + 0x000000), "BANDAI SFC-ADX", 14) == 0) + { + romptr += 0x100000; + romsize -= 0x100000; + + if(log_cb) log_cb(RETRO_LOG_INFO,"[libretro]: Sufami Turbo Multi-ROM bios removed\n"); + } + } +} + bool retro_load_game_special(unsigned game_type, const struct retro_game_info *info, size_t num_info) { uint8_t *romptr[3]; size_t romsize[3]; - for(size_t lcv=0; lcv Date: Sun, 1 Jul 2018 18:11:13 -0500 Subject: [PATCH 15/15] remove incomplete memory_maps implementation cleanup logs fix possible overflow cleanup --- libretro/libretro.cpp | 77 ++++++++----------------------------------- 1 file changed, 14 insertions(+), 63 deletions(-) diff --git a/libretro/libretro.cpp b/libretro/libretro.cpp index 7f89a5cb..c5b9714d 100644 --- a/libretro/libretro.cpp +++ b/libretro/libretro.cpp @@ -167,10 +167,8 @@ void retro_set_environment(retro_environment_t cb) // Changing "Show layer 1" is fine, but don't change "layer_1"/etc or the possible values ("Yes|No"). // Adding more variables and rearranging them is safe. { "snes9x_up_down_allowed", "Allow Opposing Directions; disabled|enabled" }, - { "snes9x_hires_blend", "Hires Blending; disabled|enabled" }, { "snes9x_overclock_superfx", "SuperFX Overclocking; 100%|150%|200%|250%|300%|350%|400%|450%|500%|50%" }, - //{ "snes9x_overclock_cycles", "Reduce Slowdown (Hack, Unsafe); disabled|compatible|max" }, - //{ "snes9x_reduce_sprite_flicker", "Reduce Flickering (Hack, Unsafe); disabled|enabled" }, + { "snes9x_hires_blend", "Hires Blending; disabled|enabled" }, { "snes9x_layer_1", "Show layer 1; enabled|disabled" }, { "snes9x_layer_2", "Show layer 2; enabled|disabled" }, { "snes9x_layer_3", "Show layer 3; enabled|disabled" }, @@ -457,7 +455,7 @@ void retro_reset() S9xSoftReset(); } -static unsigned snes_devices[2]; +static unsigned snes_devices[8]; void retro_set_controller_port_device(unsigned port, unsigned device) { if (port < 8) @@ -491,12 +489,12 @@ void retro_set_controller_port_device(unsigned port, unsigned device) break; default: if (log_cb) - log_cb(RETRO_LOG_ERROR, "[libretro]: Invalid device (%d).\n", device); + log_cb(RETRO_LOG_ERROR, "Invalid device (%d).\n", device); break; } } else if(device != RETRO_DEVICE_NONE) - log_cb(RETRO_LOG_INFO, "[libretro]: Nonexistent Port (%d).\n", port); + log_cb(RETRO_LOG_INFO, "Nonexistent Port (%d).\n", port); } void retro_cheat_reset() @@ -539,46 +537,6 @@ void retro_cheat_set(unsigned index, bool enabled, const char *codeline) S9xCheatsEnable(); } -#define MAX_MAPS 32 -static struct retro_memory_descriptor memorydesc[MAX_MAPS]; -static unsigned memorydesc_c; - -static bool merge_mapping() -{ - if (memorydesc_c==1) return false;//can't merge the only one - struct retro_memory_descriptor * a=&memorydesc[MAX_MAPS - (memorydesc_c-1)]; - struct retro_memory_descriptor * b=&memorydesc[MAX_MAPS - memorydesc_c]; - - if (a->flags != b->flags) return false; - if (a->disconnect != b->disconnect) return false; - if (a->len != b->len) return false; - if (a->addrspace || b->addrspace) return false;//we don't use these - if (((char*)a->ptr)+a->offset==((char*)b->ptr)+b->offset && a->select==b->select) - { - a->select&=~(a->start^b->start); - memorydesc_c--; - return true; - } - uint32 len=a->len; - if (!len) len=(0x1000000 - a->select); - if (len && ((len-1) & (len | a->disconnect))==0 && ((char*)a->ptr)+a->offset+len == ((char*)b->ptr)+b->offset) - { - a->select &=~ len; - a->disconnect &=~ len; - memorydesc_c--; - return true; - } - return false; -} - -void S9xAppendMapping(struct retro_memory_descriptor *desc) -{ - //do it backwards - snes9x defines the last one to win, while we define the first one to win - //printf("add %x\n",desc->start); - memcpy(&memorydesc[MAX_MAPS - (++memorydesc_c)], desc, sizeof(struct retro_memory_descriptor)); - while (merge_mapping()) {} -} - static void init_descriptors(void) { struct retro_input_descriptor desc[] = { @@ -769,15 +727,11 @@ bool retro_load_game(const struct retro_game_info *game) S9xSetRenderPixelFormat(pixel_format); S9xGraphicsInit(); - struct retro_memory_map map={ memorydesc+MAX_MAPS-memorydesc_c, memorydesc_c }; if (rom_loaded) - { - environ_cb(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &map); update_geometry(); - } if (!rom_loaded && log_cb) - log_cb(RETRO_LOG_ERROR, "[libretro]: Rom loading failed...\n"); + log_cb(RETRO_LOG_ERROR, "ROM loading failed...\n"); return rom_loaded; } @@ -792,7 +746,7 @@ static void remove_header(uint8_t *&romptr, size_t &romsize, bool multicart_sufa romptr += 512; romsize -= 512; - if(log_cb) log_cb(RETRO_LOG_INFO,"[libretro]: ROM header removed\n"); + if(log_cb) log_cb(RETRO_LOG_INFO,"ROM header removed\n"); } if (multicart_sufami && (romptr + romsize) >= (romptr + 0x100000)) @@ -803,7 +757,7 @@ static void remove_header(uint8_t *&romptr, size_t &romsize, bool multicart_sufa romptr += 0x100000; romsize -= 0x100000; - if(log_cb) log_cb(RETRO_LOG_INFO,"[libretro]: Sufami Turbo Multi-ROM bios removed\n"); + if(log_cb) log_cb(RETRO_LOG_INFO,"Sufami Turbo Multi-ROM bios removed\n"); } } } @@ -821,7 +775,6 @@ bool retro_load_game_special(unsigned game_type, const struct retro_game_info *i } init_descriptors(); - memorydesc_c = 0; rom_loaded = false; update_variables(); @@ -839,7 +792,7 @@ bool retro_load_game_special(unsigned game_type, const struct retro_game_info *i } if (!rom_loaded && log_cb) - log_cb(RETRO_LOG_ERROR, "[libretro]: BSX ROM loading failed...\n"); + log_cb(RETRO_LOG_ERROR, "BSX ROM loading failed...\n"); break; case RETRO_GAME_TYPE_BSX_SLOTTED: case RETRO_GAME_TYPE_MULTI_CART: @@ -866,7 +819,7 @@ bool retro_load_game_special(unsigned game_type, const struct retro_game_info *i else { if (log_cb) - log_cb(RETRO_LOG_INFO, "[libretro]: Loading Multi-Cart link game\n"); + log_cb(RETRO_LOG_INFO, "Loading Multi-Cart link game\n"); rom_loaded = Memory.LoadMultiCartMem((const uint8_t*)romptr[0], romsize[0], (const uint8_t*)romptr[1], romsize[1], NULL, 0); @@ -874,7 +827,7 @@ bool retro_load_game_special(unsigned game_type, const struct retro_game_info *i } if (!rom_loaded && log_cb) - log_cb(RETRO_LOG_ERROR, "[libretro]: Multirom loading failed...\n"); + log_cb(RETRO_LOG_ERROR, "Multirom loading failed...\n"); break; case RETRO_GAME_TYPE_SUFAMI_TURBO: @@ -891,12 +844,12 @@ bool retro_load_game_special(unsigned game_type, const struct retro_game_info *i } if (!rom_loaded && log_cb) - log_cb(RETRO_LOG_ERROR, "[libretro]: Sufami Turbo ROM loading failed...\n"); + log_cb(RETRO_LOG_ERROR, "Sufami Turbo ROM loading failed...\n"); break; default: rom_loaded = false; - log_cb(RETRO_LOG_ERROR, "[libretro]: Multi-cart ROM loading failed...\n"); + log_cb(RETRO_LOG_ERROR, "Multi-cart ROM loading failed...\n"); break; } @@ -914,8 +867,6 @@ bool retro_load_game_special(unsigned game_type, const struct retro_game_info *i S9xSetRenderPixelFormat(pixel_format); S9xGraphicsInit(); - struct retro_memory_map map={ memorydesc+MAX_MAPS-memorydesc_c, memorydesc_c }; - environ_cb(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &map); update_geometry(); } @@ -989,7 +940,7 @@ void retro_init(void) S9xDeinitAPU(); if (log_cb) - log_cb(RETRO_LOG_ERROR, "[libretro]: Failed to init Memory or APU.\n"); + log_cb(RETRO_LOG_ERROR, "Failed to init Memory or APU.\n"); exit(1); } @@ -1229,7 +1180,7 @@ static void report_buttons() default: if (log_cb) - log_cb(RETRO_LOG_ERROR, "[libretro]: Unknown device...\n"); + log_cb(RETRO_LOG_ERROR, "Unknown device...\n"); } } }