Commit 632d603a authored by ds22x's avatar ds22x
Browse files

Sync to upstream

parents d2959e06 0a94eaa6
......@@ -24,6 +24,7 @@ Gtk:
- Use a submodule for glslang, because it doesn't guarantee API stability.
- Switched to GTK's C++ interface, gtkmm3. This effectively drops
GTK+ 2.0 support.
- Joysticks can now be hotplugged. (jraby)
Unix:
- Added audio output threading. (yoffy)
......
This diff is collapsed.
......@@ -929,12 +929,12 @@ static void DSP3_OP1E_D (int16 move, int16 *lo, int16 *hi)
static void DSP3_OP1E_D1 (int16 move, int16 *lo, int16 *hi)
{
const uint16 HiAdd[] =
static const uint16 HiAdd[] =
{
0x00, 0xFF, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x01, 0x00, 0xFF, 0x00
};
const uint16 LoAdd[] =
static const uint16 LoAdd[] =
{
0x00, 0x00, 0x01, 0x01, 0x00, 0xFF, 0xFF, 0x00
};
......
......@@ -90,7 +90,7 @@ static int32 DSP4_READ_DWORD (void)
static int16 DSP4_Inverse (int16 value)
{
// Attention: This lookup table is not verified
const uint16 div_lut[64] =
static const uint16 div_lut[64] =
{
0x0000, 0x8000, 0x4000, 0x2aaa, 0x2000, 0x1999, 0x1555, 0x1249,
0x1000, 0x0e38, 0x0ccc, 0x0ba2, 0x0aaa, 0x09d8, 0x0924, 0x0888,
......@@ -1080,7 +1080,7 @@ static void DSP4_OP09 (void)
static void DSP4_OP0A (int16 n2, int16 *o1, int16 *o2, int16 *o3, int16 *o4)
{
const uint16 OP0A_Values[16] =
static const uint16 OP0A_Values[16] =
{
0x0000, 0x0030, 0x0060, 0x0090, 0x00c0, 0x00f0, 0x0120, 0x0150,
0xfe80, 0xfeb0, 0xfee0, 0xff10, 0xff40, 0xff70, 0xffa0, 0xffd0
......
......@@ -218,8 +218,8 @@ static void FxReset (struct FxInfo_s *psFxInfo)
static void fx_readRegisterSpace (void)
{
static uint32 avHeight[] = { 128, 160, 192, 256 };
static uint32 avMult[] = { 16, 32, 32, 64 };
static const uint32 avHeight[] = { 128, 160, 192, 256 };
static const uint32 avMult[] = { 16, 32, 32, 64 };
uint8 *p;
int n;
......@@ -228,16 +228,12 @@ static void fx_readRegisterSpace (void)
// Update R0-R15
p = GSU.pvRegisters;
for (int i = 0; i < 16; i++)
{
GSU.avReg[i] = *p++;
GSU.avReg[i] += ((uint32) (*p++)) << 8;
}
for (int i = 0; i < 16; i++, p += 2)
GSU.avReg[i] = (uint32) READ_WORD(p);
// Update other registers
p = GSU.pvRegisters;
GSU.vStatusReg = (uint32) p[GSU_SFR];
GSU.vStatusReg |= ((uint32) p[GSU_SFR + 1]) << 8;
GSU.vStatusReg = (uint32) READ_WORD(&p[GSU_SFR]);
GSU.vPrgBankReg = (uint32) p[GSU_PBR];
GSU.vRomBankReg = (uint32) p[GSU_ROMBR];
GSU.vRamBankReg = ((uint32) p[GSU_RAMBR]) & (FX_RAM_BANKS - 1);
......@@ -291,11 +287,8 @@ static void fx_writeRegisterSpace (void)
uint8 *p;
p = GSU.pvRegisters;
for (int i = 0; i < 16; i++)
{
*p++ = (uint8) GSU.avReg[i];
*p++ = (uint8) (GSU.avReg[i] >> 8);
}
for (int i = 0; i < 16; i++, p += 2)
WRITE_WORD(p, GSU.avReg[i]);
// Update status register
if (USEX16(GSU.vZero) == 0)
......@@ -319,13 +312,11 @@ static void fx_writeRegisterSpace (void)
CF(CY);
p = GSU.pvRegisters;
p[GSU_SFR] = (uint8) GSU.vStatusReg;
p[GSU_SFR + 1] = (uint8) (GSU.vStatusReg >> 8);
WRITE_WORD(&p[GSU_SFR], GSU.vStatusReg);
p[GSU_PBR] = (uint8) GSU.vPrgBankReg;
p[GSU_ROMBR] = (uint8) GSU.vRomBankReg;
p[GSU_RAMBR] = (uint8) GSU.vRamBankReg;
p[GSU_CBR] = (uint8) GSU.vCacheBaseReg;
p[GSU_CBR + 1] = (uint8) (GSU.vCacheBaseReg >> 8);
WRITE_WORD(&p[GSU_CBR], GSU.vCacheBaseReg);
//fx_restoreCache();
}
......
......@@ -191,7 +191,7 @@ void S9xStartScreenRefresh (void)
memset(GFX.SubZBuffer, 0, GFX.ScreenSize);
}
if (++IPPU.FrameCount % Memory.ROMFramesPerSecond == 0)
if (++IPPU.FrameCount == (uint32)Memory.ROMFramesPerSecond)
{
IPPU.DisplayedRenderedFrameCount = IPPU.RenderedFramesCount;
IPPU.RenderedFramesCount = 0;
......
......@@ -7,3 +7,4 @@ jristz (es_ES)
Tibério Vítor (pt_BR)
Sergey Basalaev (ru)
Milan Kostić (sr@latin)
StanleyKid-22 (uk)
......@@ -6,4 +6,5 @@ ja
pt_BR
ru
sr@latin
uk
zh_CN
This diff is collapsed.
......@@ -207,24 +207,6 @@ int Snes9xConfig::load_defaults()
return 0;
}
void Snes9xConfig::joystick_register_centers()
{
for (auto &j : joystick)
j.register_centers();
}
void Snes9xConfig::flush_joysticks()
{
for (auto &j : joystick)
j.flush();
}
void Snes9xConfig::set_joystick_mode(int mode)
{
for (auto &j : joystick)
j.mode = mode;
}
int Snes9xConfig::save_config_file()
{
ConfigFile cf;
......
......@@ -58,9 +58,6 @@ class Snes9xConfig
int save_config_file();
int load_defaults();
void rebind_keys();
void flush_joysticks();
void set_joystick_mode(int mode);
void joystick_register_centers();
/* Screen options */
bool full_screen_on_open;
......@@ -168,7 +165,8 @@ class Snes9xConfig
bool use_sync_control;
#endif
std::vector<JoyDevice> joystick;
JoyDevices joysticks;
int joystick_threshold;
};
......
......@@ -426,6 +426,7 @@ s9xcommand_t S9xGetPortCommandT(const char *name)
return cmd;
}
void S9xProcessEvents(bool8 block)
{
JoyEvent event;
......@@ -433,11 +434,12 @@ void S9xProcessEvents(bool8 block)
if (S9xGrabJoysticks())
{
for (size_t i = 0; i < gui_config->joystick.size(); i++)
gui_config->joysticks.poll_events();
for (auto &j : gui_config->joysticks)
{
while (gui_config->joystick[i].get_event(&event))
while (j.second->get_event(&event))
{
binding = Binding(i, event.parameter, 0);
binding = Binding(j.second->joynum, event.parameter, 0);
S9xReportButton(binding.hex(), event.state == JOY_PRESSED ? 1 : 0);
gui_config->screensaver_needs_reset = true;
}
......@@ -447,37 +449,15 @@ void S9xProcessEvents(bool8 block)
}
}
static void poll_joystick_events()
{
SDL_Event event;
while (SDL_PollEvent(&event))
{
if (event.type == SDL_JOYAXISMOTION)
{
gui_config->joystick[event.jaxis.which].handle_event(&event);
}
else if (event.type == SDL_JOYHATMOTION)
{
gui_config->joystick[event.jhat.which].handle_event(&event);
}
else if (event.type == SDL_JOYBUTTONUP ||
event.type == SDL_JOYBUTTONDOWN)
{
gui_config->joystick[event.jbutton.which].handle_event(&event);
}
}
}
void S9xInitInputDevices()
{
SDL_Init(SDL_INIT_JOYSTICK);
size_t num_joysticks = SDL_NumJoysticks();
gui_config->joystick.resize(num_joysticks);
for (size_t i = 0; i < num_joysticks; i++)
{
gui_config->joystick[i].set_sdl_joystick_num(i);
gui_config->joysticks.add(i);
}
//First plug in both, they'll change later as needed
......@@ -487,7 +467,7 @@ void S9xInitInputDevices()
void S9xDeinitInputDevices()
{
gui_config->joystick.clear();
gui_config->joysticks.clear();
SDL_Quit();
}
......@@ -500,26 +480,28 @@ JoyDevice::JoyDevice()
JoyDevice::~JoyDevice()
{
if (enabled)
if (filedes)
{
SDL_JoystickClose(filedes);
}
}
bool JoyDevice::set_sdl_joystick_num(unsigned int device_num)
bool JoyDevice::set_sdl_joystick(unsigned int sdl_device_index, int new_joynum)
{
if ((int)device_num >= SDL_NumJoysticks())
if ((int)sdl_device_index >= SDL_NumJoysticks())
{
enabled = false;
return false;
}
filedes = SDL_JoystickOpen(device_num);
filedes = SDL_JoystickOpen(sdl_device_index);
if (!filedes)
return false;
enabled = true;
instance_id = SDL_JoystickInstanceID(filedes);
joynum = new_joynum;
int num_axes = SDL_JoystickNumAxes(filedes);
int num_hats = SDL_JoystickNumHats(filedes);
......@@ -534,12 +516,14 @@ bool JoyDevice::set_sdl_joystick_num(unsigned int device_num)
calibration[i].center = 0;
}
printf("Joystick %d, %s:\n %d axes, %d buttons, %d hats\n",
device_num + 1,
SDL_JoystickName(filedes),
SDL_JoystickNumButtons(filedes),
num_axes,
num_hats);
description = SDL_JoystickName(filedes);
description += ": ";
description += std::to_string(SDL_JoystickNumButtons(filedes));
description += " buttons, ";
description += std::to_string(num_axes);
description += " axes, ";
description += std::to_string(num_hats);
description += " hats\n";
for (auto &i : axis)
i = 0;
......@@ -732,8 +716,6 @@ void JoyDevice::handle_event(SDL_Event *event)
int JoyDevice::get_event(JoyEvent *event)
{
poll_events();
if (queue.empty())
return 0;
......@@ -745,11 +727,6 @@ int JoyDevice::get_event(JoyEvent *event)
return 1;
}
void JoyDevice::poll_events()
{
poll_joystick_events();
}
void JoyDevice::flush()
{
SDL_Event event;
......@@ -761,3 +738,107 @@ void JoyDevice::flush()
while (!queue.empty())
queue.pop();
}
void JoyDevices::clear()
{
joysticks.clear();
}
bool JoyDevices::add(int sdl_device_index)
{
std::array<bool, NUM_JOYPADS> joynums;
joynums.fill(false);
for (auto &j : joysticks)
{
joynums[j.second->joynum] = true;
}
// New joystick always gets the lowest available joynum
int joynum(0);
for (; joynum < NUM_JOYPADS && joynums[joynum]; ++joynum);
if (joynum == NUM_JOYPADS)
{
printf("Joystick slots are full, cannot add joystick (device index %d)\n", sdl_device_index);
return false;
}
auto ujd = std::make_unique<JoyDevice>();
ujd->set_sdl_joystick(sdl_device_index, joynum);
printf("Joystick %d, %s", ujd->joynum+1, ujd->description.c_str());
joysticks[ujd->instance_id] = std::move(ujd);
return true;
}
bool JoyDevices::remove(SDL_JoystickID instance_id)
{
if (!joysticks.count(instance_id))
{
printf("joystick_remove: invalid instance id %d", instance_id);
return false;
}
printf("Removed joystick %d, %s", joysticks[instance_id]->joynum+1, joysticks[instance_id]->description.c_str());
joysticks.erase(instance_id);
return true;
}
JoyDevice *JoyDevices::get_joystick(SDL_JoystickID instance_id)
{
if (joysticks.count(instance_id)){
return joysticks[instance_id].get();
}
printf("BUG: Event for unknown joystick instance id: %d", instance_id);
return NULL;
}
void JoyDevices::register_centers()
{
for (auto &j : joysticks)
j.second->register_centers();
}
void JoyDevices::flush_events()
{
for (auto &j : joysticks)
j.second->flush();
}
void JoyDevices::set_mode(int mode)
{
for (auto &j : joysticks)
j.second->mode = mode;
}
void JoyDevices::poll_events()
{
SDL_Event event;
JoyDevice *jd{};
while (SDL_PollEvent(&event))
{
switch(event.type) {
case SDL_JOYAXISMOTION:
jd = get_joystick(event.jaxis.which);
break;
case SDL_JOYHATMOTION:
jd = get_joystick(event.jhat.which);
break;
case SDL_JOYBUTTONUP:
case SDL_JOYBUTTONDOWN:
jd = get_joystick(event.jbutton.which);
break;
case SDL_JOYDEVICEADDED:
add(event.jdevice.which);
continue;
case SDL_JOYDEVICEREMOVED:
remove(event.jdevice.which);
continue;
}
if (jd)
{
jd->handle_event(&event);
}
}
}
......@@ -100,9 +100,12 @@ class JoyDevice
void flush();
void handle_event(SDL_Event *event);
void register_centers();
bool set_sdl_joystick_num(unsigned int device_num);
bool set_sdl_joystick(unsigned int device_index, int slot);
static void poll_joystick_events();
std::string description;
SDL_Joystick *filedes;
SDL_JoystickID instance_id;
std::queue<JoyEvent> queue;
int mode;
int joynum;
......@@ -112,10 +115,28 @@ class JoyDevice
bool enabled;
private:
void poll_events();
void add_event(unsigned int parameter, unsigned int state);
};
class JoyDevices
{
public:
void clear();
bool add(int sdl_device_index);
bool remove(SDL_JoystickID instance_id);
void register_centers();
void flush_events();
void set_mode(int mode);
void poll_events();
std::map<SDL_JoystickID, std::unique_ptr<JoyDevice>>::const_iterator begin() const { return joysticks.begin(); }
std::map<SDL_JoystickID, std::unique_ptr<JoyDevice>>::const_iterator end() const { return joysticks.end(); }
private:
JoyDevice *get_joystick(SDL_JoystickID instance_id);
std::map<SDL_JoystickID, std::unique_ptr<JoyDevice>> joysticks;
};
void S9xDeinitInputDevices();
Binding S9xGetBindingByName(const char *name);
bool S9xIsMousePluggedIn();
......
......@@ -178,38 +178,8 @@ static int file_exists(const char *name)
}
}
bool8 S9xOpenSnapshotFile(const char *fname, bool8 read_only, STREAM *file)
bool8 S9xOpenSnapshotFile(const char *filename, bool8 read_only, STREAM *file)
{
char filename[PATH_MAX + 1];
char drive[_MAX_DRIVE + 1];
char dir[_MAX_DIR + 1];
char ext[_MAX_EXT + 1];
_splitpath(fname, drive, dir, filename, ext);
if (*drive || *dir == '/' || (*dir == '.' && (*(dir + 1) == '/')))
{
snprintf(filename, PATH_MAX + 1, "%s", fname);
if (!file_exists(filename))
{
if (!*ext)
strcat(filename, ".s9x");
}
}
else
{
strcpy(filename, S9xGetDirectory(SNAPSHOT_DIR));
strcat(filename, SLASH_STR);
strcat(filename, fname);
if (!file_exists(filename))
{
if (!*ext)
strcat(filename, ".s9x");
}
}
#ifdef ZLIB
if (read_only)
{
......
......@@ -33,11 +33,11 @@ void snes9x_preferences_open(Snes9xWindow *window)
preferences->window->set_transient_for(*window->window.get());
config->set_joystick_mode(JOY_MODE_GLOBAL);
config->joysticks.set_mode(JOY_MODE_GLOBAL);
preferences->show();
window->unpause_from_focus_change();
config->set_joystick_mode(JOY_MODE_INDIVIDUAL);
config->joysticks.set_mode(JOY_MODE_INDIVIDUAL);
config->rebind_keys();
window->update_accelerators();
......@@ -50,22 +50,23 @@ gboolean poll_joystick(gpointer data)
Binding binding;
int focus;
for (size_t i = 0; i < window->config->joystick.size(); i++)
window->config->joysticks.poll_events();
for (auto &j : window->config->joysticks)
{
while (window->config->joystick[i].get_event(&event))
while (j.second->get_event(&event))
{
if (event.state == JOY_PRESSED)
{
if ((focus = window->get_focused_binding()) >= 0)
{
binding = Binding(i,
binding = Binding(j.second->joynum,
event.parameter,
window->config->joystick_threshold);
window->store_binding(b_links[focus].button_name,
binding);
window->config->flush_joysticks();
window->config->joysticks.flush_events();
return true;
}
}
......@@ -948,7 +949,7 @@ void Snes9xPreferences::bindings_to_dialog(int joypad)
void Snes9xPreferences::calibration_dialog()
{
config->joystick_register_centers();
config->joysticks.register_centers();
auto dialog = Gtk::MessageDialog(_("Current joystick centers have been saved."));
dialog.set_title(_("Calibration Complete"));
dialog.run();
......
......@@ -149,7 +149,7 @@ int main(int argc, char *argv[])
if (gui_config->fullscreen)
top_level->enter_fullscreen_mode();
gui_config->flush_joysticks();
gui_config->joysticks.flush_events();
if (rom_filename && *Settings.InitialSnapshotFilename)
S9xUnfreezeGame(Settings.InitialSnapshotFilename);
......@@ -276,7 +276,7 @@ static bool S9xPauseFunc()
if (!Settings.Paused) /* Coming out of pause */
{
/* Clear joystick queues */
gui_config->flush_joysticks();
gui_config->joysticks.flush_events();
S9xSoundStart();
......@@ -318,7 +318,7 @@ static bool S9xIdleFunc()
{
S9xSoundStop();
gui_config->flush_joysticks();
gui_config->joysticks.flush_events();
if (Settings.NetPlay && NetPlay.Connected)
{
......
......@@ -838,7 +838,7 @@ void Snes9xWindow::save_state_dialog()
dialog.add_button(Gtk::StockID("gtk-cancel"), Gtk::RESPONSE_CANCEL);
dialog.add_button(Gtk::StockID("gtk-save"), Gtk::RESPONSE_ACCEPT);
dialog.set_current_folder(S9xGetDirectory(SNAPSHOT_DIR));
dialog.set_current_name(S9xGetFilename(".sst", SNAPSHOT_DIR));
dialog.set_current_name(S9xBasename(S9xGetFilename(".sst", SNAPSHOT_DIR)));
dialog.add_filter(get_save_states_file_filter());
dialog.add_filter(get_all_files_filter());
......
......@@ -118,6 +118,7 @@ struct retro_core_option_v2_definition option_defs_tr[] = {
NULL,
{
{ "4:3", NULL },
{ "4:3 scaled", "4:3 (Korunmuş)" },
{ "uncorrected", "Düzeltilmemiş" },
{ "auto", "Otomatik" },
{ "ntsc", "NTSC" },
......
......@@ -2811,9 +2811,6 @@ void CMemory::map_LoROMSRAM (void)
{
uint32 hi;
if (SRAMSize == 0)
return;
if (ROMSize > 11 || SRAMSize > 5)
hi = 0x7fff;
else
......
......@@ -20,17 +20,25 @@ CWaveOut::~CWaveOut(void)