From 8dda68b22ea16c9ab72342817fdf185105a5e132 Mon Sep 17 00:00:00 2001 From: retro-wertz Date: Sat, 9 Sep 2017 14:29:44 +0800 Subject: [PATCH 1/9] Use 48000 Hz as default sample rate --- src/drivers/libretro/libretro.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/drivers/libretro/libretro.c b/src/drivers/libretro/libretro.c index a9d237a..3ff6acc 100644 --- a/src/drivers/libretro/libretro.c +++ b/src/drivers/libretro/libretro.c @@ -582,7 +582,7 @@ void retro_get_system_av_info(struct retro_system_av_info *info) info->geometry.max_width = width; info->geometry.max_height = height; info->geometry.aspect_ratio = use_par ? NES_8_7_PAR : NES_4_3; - info->timing.sample_rate = 32050.0; + info->timing.sample_rate = 48000.0; if (FSettings.PAL || dendy) info->timing.fps = 838977920.0/16777215.0; else @@ -637,7 +637,7 @@ static void retro_set_custom_palette(void) * -ntsccol : sets ntsc to default palette. * If none of the above are true, then * default palette will be used. - * VS.System should always use default palette. + * VS Uniystem should always use default palette. */ return; } @@ -1595,7 +1595,7 @@ bool retro_load_game(const struct retro_game_info *game) FCEUI_Initialize(); FCEUI_SetSoundVolume(256); - FCEUI_Sound(32050); + FCEUI_Sound(48000); GameInfo = (FCEUGI*)FCEUI_LoadGame(game->path, (uint8_t*)game->data, game->size); if (!GameInfo) @@ -1621,7 +1621,7 @@ bool retro_load_game(const struct retro_game_info *game) FCEU_PrintError("Cannot find nes.pal from system directory.\n"); if (GameInfo->type == GIT_VSUNI) - FCEU_PrintError("VS.System rom loaded, will use default palette.\n"); + FCEU_PrintError("VS Unisystem rom loaded, will use default palette.\n"); retro_set_custom_palette(); From 67fe19858a4cc388801ded9eebc26fb6d5fcd7e3 Mon Sep 17 00:00:00 2001 From: retro-wertz Date: Sat, 9 Sep 2017 14:54:02 +0800 Subject: [PATCH 2/9] Add Core Option "Sound Quality" --- src/drivers/libretro/libretro.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/drivers/libretro/libretro.c b/src/drivers/libretro/libretro.c index 3ff6acc..9916aa1 100644 --- a/src/drivers/libretro/libretro.c +++ b/src/drivers/libretro/libretro.c @@ -76,6 +76,9 @@ static uint16_t* fceu_video_out; /* Some timing-related variables. */ static int soundo = 1; +unsigned sndsamplerate = 48000; +unsigned sndquality = 0; +unsigned sndvolume = 150; static volatile int nofocus = 0; @@ -179,7 +182,7 @@ void FCEUD_NetworkClose(void) void FCEUD_SoundToggle (void) { - FCEUI_SetSoundVolume(100); + FCEUI_SetSoundVolume(sndvolume); } void FCEUD_VideoChanged (void) @@ -548,6 +551,7 @@ void retro_set_environment(retro_environment_t cb) { "fceumm_turbo_delay", "Turbo Delay (in frames); 3|5|10|15|30|60|1|2" }, { "fceumm_aspect", "Preferred aspect ratio; 8:7 PAR|4:3" }, { "fceumm_region", "Region Override; Auto|NTSC|PAL|Dendy" }, + { "fceumm_sndquality", "Sound Quality; Low|High|Very High" }, { NULL, NULL }, }; @@ -582,7 +586,7 @@ void retro_get_system_av_info(struct retro_system_av_info *info) info->geometry.max_width = width; info->geometry.max_height = height; info->geometry.aspect_ratio = use_par ? NES_8_7_PAR : NES_4_3; - info->timing.sample_rate = 48000.0; + info->timing.sample_rate = (float)sndsamplerate; if (FSettings.PAL || dendy) info->timing.fps = 838977920.0/16777215.0; else @@ -959,6 +963,21 @@ static void check_variables(bool startup) } } + var.key = "fceumm_sndquality"; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + unsigned oldval = sndquality; + if (!strcmp(var.value, "Low")) + sndquality = 0; + else if (!strcmp(var.value, "High")) + sndquality = 1; + else if (!strcmp(var.value, "Very High")) + sndquality = 2; + if (sndquality != oldval) + FCEUI_SetSoundQuality(sndquality); + } + if (geometry_update) { retro_get_system_av_info(&av_info); @@ -1594,8 +1613,8 @@ bool retro_load_game(const struct retro_game_info *game) FCEUI_Initialize(); - FCEUI_SetSoundVolume(256); - FCEUI_Sound(48000); + FCEUI_SetSoundVolume(sndvolume); + FCEUI_Sound(sndsamplerate); GameInfo = (FCEUGI*)FCEUI_LoadGame(game->path, (uint8_t*)game->data, game->size); if (!GameInfo) From 521f1a5c02c4208019972fbc5846822d72c52d11 Mon Sep 17 00:00:00 2001 From: retro-wertz Date: Sat, 9 Sep 2017 16:16:12 +0800 Subject: [PATCH 3/9] Add ZAPPER input device support (wip) --- src/drivers/libretro/libretro.c | 80 ++++++++++++++++++++++++++++++--- src/video.c | 1 + 2 files changed, 76 insertions(+), 5 deletions(-) diff --git a/src/drivers/libretro/libretro.c b/src/drivers/libretro/libretro.c index 9916aa1..f49f308 100644 --- a/src/drivers/libretro/libretro.c +++ b/src/drivers/libretro/libretro.c @@ -84,6 +84,7 @@ static volatile int nofocus = 0; static int32_t *sound = 0; static uint32_t JSReturn[2]; +static uint32_t MouseData[2]; static uint32_t current_palette = 0; int PPUViewScanline=0; @@ -530,8 +531,18 @@ void retro_set_input_state(retro_input_state_t cb) input_cb = cb; } -void retro_set_controller_port_device(unsigned a, unsigned b) -{} +void retro_set_controller_port_device(unsigned port, unsigned device) +{ + switch(device) + { + case RETRO_DEVICE_JOYPAD: + FCEUI_SetInput(port, SI_GAMEPAD, &JSReturn[0], 0); + break; + case RETRO_DEVICE_MOUSE: + FCEUI_SetInput(port, SI_ZAPPER, &MouseData[0], 1); + break; + } +} void retro_set_environment(retro_environment_t cb) @@ -555,8 +566,20 @@ void retro_set_environment(retro_environment_t cb) { NULL, NULL }, }; + static const struct retro_controller_description pads[] = { + { "NES Gamepad", RETRO_DEVICE_JOYPAD }, + { "Zapper", RETRO_DEVICE_MOUSE }, + }; + + static const struct retro_controller_info ports[] = { + { pads, 2 }, + { pads, 2 }, + { 0 }, + }; + environ_cb = cb; cb(RETRO_ENVIRONMENT_SET_VARIABLES, (void*)vars); + cb(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void*)ports); } void retro_get_system_info(struct retro_system_info *info) @@ -564,7 +587,7 @@ void retro_get_system_info(struct retro_system_info *info) info->need_fullpath = false; info->valid_extensions = "fds|nes|unf|unif"; #ifdef GIT_VERSION - info->library_version = "git" GIT_VERSION; + info->library_version = "(SVN)" GIT_VERSION; #else info->library_version = "(SVN)"; #endif @@ -711,9 +734,10 @@ void FCEUD_RegionOverride(int region) FCEUPPU_SetVideoSystem(w || dendy); SetSoundVariables(); - /* Update the geometry */ + /* Update the timing(fps) in frontend */ retro_get_system_av_info(&av_info); - environ_cb(RETRO_ENVIRONMENT_SET_GEOMETRY, &av_info); + /* not needed in current implementation to update fps */ + /* environ_cb(RETRO_ENVIRONMENT_SET_GEOMETRY, &av_info); */ } void retro_deinit (void) @@ -985,6 +1009,50 @@ static void check_variables(bool startup) } } +static int mouse_x, mouse_y, mzx, mzy; +void GetMouseData(uint32_t *zapdata) +{ + static int right, bottom, adjx, adjy, offscreen, port; + right = 256; + bottom = 240; + offscreen = 0; +#ifdef PSP + adjx = use_overscan ? 8:0; + adjy = use_overscan ? 8:0; +#else + adjx = overscan_h ? 8:0; + adjy = overscan_v ? 8:0; +#endif + + if (GameInfo->input[0] != SI_ZAPPER && GameInfo->input[1] != SI_ZAPPER) + return; + + port = (GameInfo->type == GIT_VSUNI) ? 1 : 0; + + /* TODO: Add some sort of mouse sensitivity */ + mouse_x = input_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_X); + mouse_y = input_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_Y); + + mzx += mouse_x; + mzy += mouse_y; + + /* Set crosshair within the limits of game's resolution */ + if (mzx > right - adjx + offscreen) + mzx = right - adjx + offscreen; + else if (mzx <= 1 + adjx) + mzx = 1 + adjx; + + if (mzy > bottom - adjy + offscreen) + mzy = bottom - adjy + offscreen; + else if (mzy <= 1 + adjy) + mzy = 1 + adjy; + + zapdata[0] = mzx; + zapdata[1] = mzy; + zapdata[2] = input_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT) ? 1 : 0 + | input_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_RIGHT) ? 2 : 0; +} + /* * Flags to keep track of whether turbo * was toggled on or off @@ -1076,6 +1144,8 @@ static void FCEUD_UpdateInput(void) JSReturn[0] = pad[0] | (pad[1] << 8); + GetMouseData(&MouseData[0]); + if (input_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2)) FCEU_VSUniCoin(); /* Insert Coin VS System */ diff --git a/src/video.c b/src/video.c index eee6d5c..8de5a65 100644 --- a/src/video.c +++ b/src/video.c @@ -74,6 +74,7 @@ void FCEU_PutImage(void) FCEU_VSUniDraw(XBuf); } if (howlong) howlong--; + FCEU_DrawInput(XBuf); } void FCEU_PutImageDummy(void) From d551d3fa14c4fbbd1575e82dc6a3ee523e769d2d Mon Sep 17 00:00:00 2001 From: retro-wertz Date: Sat, 9 Sep 2017 17:14:44 +0800 Subject: [PATCH 4/9] fix input for player 3/4 --- src/drivers/libretro/libretro.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/drivers/libretro/libretro.c b/src/drivers/libretro/libretro.c index f49f308..daa9e94 100644 --- a/src/drivers/libretro/libretro.c +++ b/src/drivers/libretro/libretro.c @@ -1069,13 +1069,13 @@ unsigned char turbo_p1_toggle[] = { 0, 0 }; static void FCEUD_UpdateInput(void) { unsigned p, i; - unsigned char pad[2]; + unsigned char pad[4]; - pad[0] = pad[1] = 0; + pad[0] = pad[1] = pad[2] = pad[3] = 0; poll_cb(); - for (p = 0; p < 2; p++) + for (p = 0; p < 4; p++) { for ( i = 0; i < 8; i++) pad[p] |= input_cb(p, RETRO_DEVICE_JOYPAD, 0, bindmap[i].retro) ? bindmap[i].nes : 0; @@ -1142,7 +1142,7 @@ static void FCEUD_UpdateInput(void) if (GameInfo->type == GIT_VSUNI) FCEU_VSUniSwap(&pad[0], &pad[1]); - JSReturn[0] = pad[0] | (pad[1] << 8); + JSReturn[0] = pad[0] | (pad[1] << 8) | (pad[1] << 16 | (pad[1] << 24); GetMouseData(&MouseData[0]); From 539ac8b995ca02e3a05694067d9168242d91eff1 Mon Sep 17 00:00:00 2001 From: retro-wertz Date: Sat, 9 Sep 2017 17:45:41 +0800 Subject: [PATCH 5/9] cleanup --- src/drivers/libretro/libretro.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/drivers/libretro/libretro.c b/src/drivers/libretro/libretro.c index daa9e94..48dde84 100644 --- a/src/drivers/libretro/libretro.c +++ b/src/drivers/libretro/libretro.c @@ -1017,8 +1017,7 @@ void GetMouseData(uint32_t *zapdata) bottom = 240; offscreen = 0; #ifdef PSP - adjx = use_overscan ? 8:0; - adjy = use_overscan ? 8:0; + adjx = adjy = use_overscan ? 8:0; #else adjx = overscan_h ? 8:0; adjy = overscan_v ? 8:0; @@ -1142,7 +1141,7 @@ static void FCEUD_UpdateInput(void) if (GameInfo->type == GIT_VSUNI) FCEU_VSUniSwap(&pad[0], &pad[1]); - JSReturn[0] = pad[0] | (pad[1] << 8) | (pad[1] << 16 | (pad[1] << 24); + JSReturn[0] = pad[0] | (pad[1] << 8) | (pad[2] << 16) | (pad[3] << 24); GetMouseData(&MouseData[0]); From aaabbd8a50602063c657c6f8d775784b94d6cbdf Mon Sep 17 00:00:00 2001 From: retro-wertz Date: Sat, 9 Sep 2017 20:36:09 +0800 Subject: [PATCH 6/9] Buildfix --- src/drivers/libretro/libretro.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drivers/libretro/libretro.c b/src/drivers/libretro/libretro.c index 48dde84..4b0acfd 100644 --- a/src/drivers/libretro/libretro.c +++ b/src/drivers/libretro/libretro.c @@ -84,7 +84,7 @@ static volatile int nofocus = 0; static int32_t *sound = 0; static uint32_t JSReturn[2]; -static uint32_t MouseData[2]; +static uint32_t MouseData[3]; static uint32_t current_palette = 0; int PPUViewScanline=0; From 418ae5a4f937229591da554a35846ee8367ce4f6 Mon Sep 17 00:00:00 2001 From: Tatsuya79 Date: Sat, 9 Sep 2017 15:57:12 +0200 Subject: [PATCH 7/9] Internal Sound Volume Option --- src/drivers/libretro/libretro.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/drivers/libretro/libretro.c b/src/drivers/libretro/libretro.c index 4b0acfd..9520207 100644 --- a/src/drivers/libretro/libretro.c +++ b/src/drivers/libretro/libretro.c @@ -563,6 +563,7 @@ void retro_set_environment(retro_environment_t cb) { "fceumm_aspect", "Preferred aspect ratio; 8:7 PAR|4:3" }, { "fceumm_region", "Region Override; Auto|NTSC|PAL|Dendy" }, { "fceumm_sndquality", "Sound Quality; Low|High|Very High" }, + { "fceumm_sndvolume", "Sound Volume; 150|160|170|180|190|200|210|220|230|240|250|0|10|20|30|40|50|60|70|80|90|100|110|120|130|140" }, { NULL, NULL }, }; @@ -1002,6 +1003,14 @@ static void check_variables(bool startup) FCEUI_SetSoundQuality(sndquality); } + var.key = "fceumm_sndvolume"; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + sndvolume = atoi(var.value); + FCEUD_SoundToggle(); + } + if (geometry_update) { retro_get_system_av_info(&av_info); From 1895b9cb36305fb466920450f27e7d64547d36d9 Mon Sep 17 00:00:00 2001 From: retro-wertz Date: Sun, 10 Sep 2017 09:08:25 +0800 Subject: [PATCH 8/9] Buildfix --- src/drivers/libretro/libretro.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drivers/libretro/libretro.c b/src/drivers/libretro/libretro.c index 4b0acfd..83b6556 100644 --- a/src/drivers/libretro/libretro.c +++ b/src/drivers/libretro/libretro.c @@ -83,7 +83,7 @@ unsigned sndvolume = 150; static volatile int nofocus = 0; static int32_t *sound = 0; -static uint32_t JSReturn[2]; +static uint32_t JSReturn[4]; static uint32_t MouseData[3]; static uint32_t current_palette = 0; From 40496686204143c3726c71c5e2bf2a1524f29b87 Mon Sep 17 00:00:00 2001 From: retro-wertz Date: Sun, 10 Sep 2017 13:30:56 +0800 Subject: [PATCH 9/9] Fix crashing when trying to connect a netplay session --- src/drivers/libretro/libretro.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/drivers/libretro/libretro.c b/src/drivers/libretro/libretro.c index 99ff704..29fbf75 100644 --- a/src/drivers/libretro/libretro.c +++ b/src/drivers/libretro/libretro.c @@ -533,18 +533,20 @@ void retro_set_input_state(retro_input_state_t cb) void retro_set_controller_port_device(unsigned port, unsigned device) { - switch(device) + if (port < 2) /* port #0 = player1/player3, port #1 = player2/player4 */ { - case RETRO_DEVICE_JOYPAD: - FCEUI_SetInput(port, SI_GAMEPAD, &JSReturn[0], 0); - break; - case RETRO_DEVICE_MOUSE: - FCEUI_SetInput(port, SI_ZAPPER, &MouseData[0], 1); - break; + switch(device) + { + case RETRO_DEVICE_JOYPAD: + FCEUI_SetInput(port, SI_GAMEPAD, &JSReturn[0], 0); + break; + case RETRO_DEVICE_MOUSE: + FCEUI_SetInput(port, SI_ZAPPER, &MouseData[0], 1); + break; + } } } - void retro_set_environment(retro_environment_t cb) { static const struct retro_variable vars[] = {