Unverified Commit 80ba8ad3 authored by kps501's avatar kps501 Committed by GitHub
Browse files

libretro: cleanups, revert polling

parent b14f83a8
......@@ -44,13 +44,13 @@
char g_rom_dir[1024];
char g_basename[1024];
bool hires_blend = false;
bool overclock_cycles = false;
bool reduce_sprite_flicker = false;
bool randomize_memory = false;
int interlace_speed;
int one_c, slow_one_c, two_c;
int macsrifle_adjust_x, macsrifle_adjust_y;
bool hires_blend = false;
retro_log_printf_t log_cb = NULL;
static retro_video_refresh_t video_cb = NULL;
......@@ -200,7 +200,6 @@ void update_geometry(void)
static void update_variables(void)
{
bool reset_sfx = false;
bool geometry_update = false;
char key[256];
struct retro_variable var;
......@@ -218,9 +217,9 @@ static void update_variables(void)
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var))
{
int newval;
if(sscanf(var.value,"%d%",&newval))
Settings.SuperFXClockMultiplier = newval;
int newval;
if(sscanf(var.value,"%d%%",&newval))
Settings.SuperFXClockMultiplier = newval;
}
var.key = "snes9x_up_down_allowed";
......@@ -237,46 +236,46 @@ static void update_variables(void)
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if (strcmp(var.value, "compatible") == 0)
{
if (strcmp(var.value, "compatible") == 0)
{
overclock_cycles = true;
one_c = 4;
slow_one_c = 5;
two_c = 6;
}
else if (strcmp(var.value, "max") == 0)
{
overclock_cycles = true;
one_c = 3;
slow_one_c = 3;
two_c = 3;
}
else
overclock_cycles = false;
overclock_cycles = true;
one_c = 4;
slow_one_c = 5;
two_c = 6;
}
else if (strcmp(var.value, "max") == 0)
{
overclock_cycles = true;
one_c = 3;
slow_one_c = 3;
two_c = 3;
}
else
overclock_cycles = false;
}
var.key = "snes9x_reduce_sprite_flicker";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if (strcmp(var.value, "enabled") == 0)
reduce_sprite_flicker = true;
else
reduce_sprite_flicker = false;
}
{
if (strcmp(var.value, "enabled") == 0)
reduce_sprite_flicker = true;
else
reduce_sprite_flicker = false;
}
var.key = "snes9x_randomize_memory";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if (strcmp(var.value, "enabled") == 0)
randomize_memory = true;
else
randomize_memory = false;
}
{
if (strcmp(var.value, "enabled") == 0)
randomize_memory = true;
else
randomize_memory = false;
}
int disabled_channels=0;
strcpy(key, "snes9x_sndchan_x");
......@@ -290,7 +289,6 @@ static void update_variables(void)
}
S9xSetSoundControl(disabled_channels^0xFF);
int disabled_layers=0;
strcpy(key, "snes9x_layer_x");
for (int i=0;i<5;i++)
......@@ -319,17 +317,17 @@ static void update_variables(void)
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
unsigned newval = 0;
if (strcmp(var.value, "enabled") == 0)
newval = 1;
else if (strcmp(var.value, "disabled") == 0)
newval = 2;
if (newval != crop_overscan_mode)
{
crop_overscan_mode = newval;
geometry_update = true;
}
unsigned newval = 0;
if (strcmp(var.value, "enabled") == 0)
newval = 1;
else if (strcmp(var.value, "disabled") == 0)
newval = 2;
if (newval != crop_overscan_mode)
{
crop_overscan_mode = newval;
geometry_update = true;
}
}
var.key = "snes9x_aspect";
......@@ -338,31 +336,31 @@ static void update_variables(void)
{
unsigned newval = 0;
if (strcmp(var.value, "ntsc") == 0)
newval = 1;
newval = 1;
else if (strcmp(var.value, "pal") == 0)
newval = 2;
newval = 2;
else if (strcmp(var.value, "4:3") == 0)
newval = 3;
newval = 3;
if (newval != aspect_ratio_mode)
{
aspect_ratio_mode = newval;
geometry_update = true;
aspect_ratio_mode = newval;
geometry_update = true;
}
}
var.key="snes9x_macsrifle_adjust_x";
var.value=NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
macsrifle_adjust_x = atoi(var.value);
var.key="snes9x_macsrifle_adjust_x";
var.value=NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
macsrifle_adjust_x = atoi(var.value);
var.key="snes9x_macsrifle_adjust_y";
var.value=NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
macsrifle_adjust_y = atoi(var.value);
var.key="snes9x_macsrifle_adjust_y";
var.value=NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
macsrifle_adjust_y = atoi(var.value);
if (geometry_update)
update_geometry();
update_geometry();
}
static void S9xAudioCallback(void*)
......@@ -375,78 +373,78 @@ static void S9xAudioCallback(void*)
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);
//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;
avail -= BUFFER_SIZE;
}
if (avail > 0)
{
S9xMixSamples((uint8*)audio_buf, avail);
audio_batch_cb(audio_buf, avail >> 1);
S9xMixSamples((uint8*)audio_buf, avail);
audio_batch_cb(audio_buf, avail >> 1);
}
}
void retro_get_system_info(struct retro_system_info *info)
{
memset(info,0,sizeof(retro_system_info));
memset(info,0,sizeof(retro_system_info));
info->library_name = "Snes9x";
info->library_name = "Snes9x";
#ifndef GIT_VERSION
#define GIT_VERSION ""
#endif
info->library_version = VERSION GIT_VERSION;
info->valid_extensions = "smc|sfc|swc|fig";
info->need_fullpath = false;
info->block_extract = false;
info->library_version = VERSION GIT_VERSION;
info->valid_extensions = "smc|sfc|swc|fig";
info->need_fullpath = false;
info->block_extract = false;
}
float get_aspect_ratio(unsigned width, unsigned height)
{
if (aspect_ratio_mode == 3) // 4:3
{
return SNES_4_3;
}
float sample_frequency_ntsc = 135000000.0 / 11.0;
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;
if (aspect_ratio_mode == 1) // ntsc
{
sample_freq = sample_frequency_ntsc;
dot_rate = NTSC_MASTER_CLOCK / 4.0;
}
else if (aspect_ratio_mode == 2) // 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;
if (aspect_ratio_mode == 3) // 4:3
{
return SNES_4_3;
}
float sample_frequency_ntsc = 135000000.0 / 11.0;
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;
if (aspect_ratio_mode == 1) // ntsc
{
sample_freq = sample_frequency_ntsc;
dot_rate = NTSC_MASTER_CLOCK / 4.0;
}
else if (aspect_ratio_mode == 2) // 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;
}
void retro_get_system_av_info(struct retro_system_av_info *info)
{
memset(info,0,sizeof(retro_system_av_info));
unsigned width = SNES_WIDTH;
unsigned height = PPU.ScreenHeight;
if (crop_overscan_mode == 1) // enabled
memset(info,0,sizeof(retro_system_av_info));
unsigned width = SNES_WIDTH;
unsigned height = PPU.ScreenHeight;
if (crop_overscan_mode == 1) // enabled
height = SNES_HEIGHT;
else if (crop_overscan_mode == 2) // disabled
else if (crop_overscan_mode == 2) // disabled
height = SNES_HEIGHT_EXTENDED;
info->geometry.base_width = width;
info->geometry.base_height = height;
info->geometry.max_width = MAX_SNES_WIDTH;
info->geometry.max_height = MAX_SNES_HEIGHT;
info->geometry.aspect_ratio = get_aspect_ratio(width, height);
info->timing.sample_rate = 32040;
info->timing.fps = retro_get_region() == RETRO_REGION_NTSC ? 21477272.0 / 357366.0 : 21281370.0 / 425568.0;
info->geometry.base_width = width;
info->geometry.base_height = height;
info->geometry.max_width = MAX_SNES_WIDTH;
info->geometry.max_height = MAX_SNES_HEIGHT;
info->geometry.aspect_ratio = get_aspect_ratio(width, height);
info->timing.sample_rate = 32040;
info->timing.fps = retro_get_region() == RETRO_REGION_NTSC ? 21477272.0 / 357366.0 : 21281370.0 / 425568.0;
}
unsigned retro_api_version()
......@@ -471,7 +469,7 @@ void retro_set_controller_port_device(unsigned port, unsigned device)
case RETRO_DEVICE_NONE:
S9xSetController(port, CTL_NONE, port, 0, 0, 0);
snes_devices[port] = RETRO_DEVICE_NONE;
break;
break;
case RETRO_DEVICE_JOYPAD:
S9xSetController(port, CTL_JOYPAD, port * offset, 0, 0, 0);
snes_devices[port] = RETRO_DEVICE_JOYPAD;
......@@ -574,41 +572,41 @@ 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 (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];
//printf("test %x/%x\n",a->start,b->start);
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)
{
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)
{
//printf("merge/mirror\n");
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&=~(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)
{
//printf("merge/consec\n");
a->select &=~ len;
a->disconnect &=~ len;
memorydesc_c--;
return true;
}
a->select &=~ len;
a->disconnect &=~ len;
memorydesc_c--;
return true;
}
//printf("nomerge\n");
return false;
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()) {}
//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)
......@@ -727,23 +725,27 @@ bool retro_load_game(const struct retro_game_info *game)
* split second - this happens whenever the game switches from normal
* mode to battle mode and vice versa. */
ChronoTriggerFrameHack = false;
if (Memory.match_nc("CHRONO TRIGGER") || /* Chrono Trigger */
if (Memory.match_nc("CHRONO TRIGGER") || /* Chrono Trigger */
Memory.match_id("ACT") ||
Memory.match_id("AC9J") /* Chrono Trigger (Sample) */
Memory.match_id("AC9J") /* Chrono Trigger (Sample) */
)
ChronoTriggerFrameHack = true;
{
ChronoTriggerFrameHack = true;
}
lufia2_credits_hack = false;
if (Memory.match_id("E9ANIE") ||
Memory.match_id("01ANIP") ||
Memory.match_id("C0ANIJ") ||
Memory.match_id("01ANIS") ||
Memory.match_id("01ANIH") ||
Memory.match_id("01ANID")
Memory.match_id("01ANIP") ||
Memory.match_id("C0ANIJ") ||
Memory.match_id("01ANIS") ||
Memory.match_id("01ANIH") ||
Memory.match_id("01ANID")
)
lufia2_credits_hack = true;
{
lufia2_credits_hack = true;
}
struct retro_memory_map map={ memorydesc+MAX_MAPS-memorydesc_c, memorydesc_c };
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();
......@@ -757,57 +759,57 @@ void retro_unload_game(void)
bool retro_load_game_special(unsigned game_type,
const struct retro_game_info *info, size_t num_info) {
init_descriptors();
memorydesc_c = 0;
update_variables();
switch (game_type) {
case RETRO_GAME_TYPE_BSX:
if(num_info == 1) {
rom_loaded = Memory.LoadROMMem((const uint8_t*)info[0].data,info[0].size);
} else if(num_info == 2) {
memcpy(Memory.BIOSROM,(const uint8_t*)info[0].data,info[0].size);
rom_loaded = Memory.LoadROMMem((const uint8_t*)info[1].data,info[1].size);
}
if (!rom_loaded && log_cb)
log_cb(RETRO_LOG_ERROR, "[libretro]: BSX ROM loading failed...\n");
break;
init_descriptors();
memorydesc_c = 0;
case RETRO_GAME_TYPE_BSX_SLOTTED:
update_variables();
if(num_info == 2)
rom_loaded = Memory.LoadMultiCartMem((const uint8_t*)info[0].data, info[0].size,
(const uint8_t*)info[1].data, info[1].size, NULL, 0);
switch (game_type) {
case RETRO_GAME_TYPE_BSX:
if(num_info == 1) {
rom_loaded = Memory.LoadROMMem((const uint8_t*)info[0].data,info[0].size);
} else if(num_info == 2) {
memcpy(Memory.BIOSROM,(const uint8_t*)info[0].data,info[0].size);
rom_loaded = Memory.LoadROMMem((const uint8_t*)info[1].data,info[1].size);
}
if (!rom_loaded && log_cb)
log_cb(RETRO_LOG_ERROR, "[libretro]: Multirom loading failed...\n");
if (!rom_loaded && log_cb)
log_cb(RETRO_LOG_ERROR, "[libretro]: BSX ROM loading failed...\n");
break;
break;
case RETRO_GAME_TYPE_SUFAMI_TURBO:
case RETRO_GAME_TYPE_BSX_SLOTTED:
if(num_info == 2)
rom_loaded = Memory.LoadMultiCartMem((const uint8_t*)info[0].data, info[0].size,
(const uint8_t*)info[1].data, info[1].size, NULL, 0);
if(num_info == 3)
rom_loaded = Memory.LoadMultiCartMem((const uint8_t*)info[1].data, info[1].size,
(const uint8_t*)info[2].data, info[2].size, (const uint8_t*)info[0].data, info[0].size);
if (!rom_loaded && log_cb)
log_cb(RETRO_LOG_ERROR, "[libretro]: Multirom loading failed...\n");
break;
if (!rom_loaded && log_cb)
log_cb(RETRO_LOG_ERROR, "[libretro]: Sufami Turbo ROM loading failed...\n");
case RETRO_GAME_TYPE_SUFAMI_TURBO:
if(num_info == 3)
rom_loaded = Memory.LoadMultiCartMem((const uint8_t*)info[1].data, info[1].size,
(const uint8_t*)info[2].data, info[2].size, (const uint8_t*)info[0].data, info[0].size);
break;
if (!rom_loaded && log_cb)
log_cb(RETRO_LOG_ERROR, "[libretro]: Sufami Turbo ROM loading failed...\n");
break;
default:
rom_loaded = false;
break;
}
default:
rom_loaded = false;
break;
}
struct retro_memory_map map={ memorydesc+MAX_MAPS-memorydesc_c, memorydesc_c };
if (rom_loaded) environ_cb(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &map);
struct retro_memory_map map={ memorydesc+MAX_MAPS-memorydesc_c, memorydesc_c };
if (rom_loaded) environ_cb(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &map);
return rom_loaded;
return rom_loaded;
}
static void map_buttons();
......@@ -1022,7 +1024,6 @@ static void map_buttons()
MAP_BUTTON(MAKE_BUTTON(PAD_5, BTN_RIGHT), "Joypad5 Right");
MAP_BUTTON(MAKE_BUTTON(PAD_5, BTN_UP), "Joypad5 Up");
MAP_BUTTON(MAKE_BUTTON(PAD_5, BTN_DOWN), "Joypad5 Down");
}
// libretro uses relative values for analogue devices.
......@@ -1036,26 +1037,15 @@ static int16_t snes_macsrifle_state[2] = {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])
{
case RETRO_DEVICE_NONE:
break;
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));
......@@ -1068,22 +1058,18 @@ static void report_buttons()
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);
}
_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;
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);
}
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;
......@@ -1095,11 +1081,8 @@ static void report_buttons()
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);