Skip to content

Commit

Permalink
Implementato il pieno supporto alle XInput.
Browse files Browse the repository at this point in the history
Con questo commit ho eliminato anche il lag dell'input che
in alcune circostanze poteva esserci nella versione windows.
  • Loading branch information
punesemu committed Mar 31, 2017
1 parent fe9b866 commit e7226c6
Show file tree
Hide file tree
Showing 14 changed files with 1,614 additions and 703 deletions.
4 changes: 2 additions & 2 deletions src/core/emu.c
Expand Up @@ -638,7 +638,7 @@ BYTE emu_turn_on(void) {
input_init(NO_SET_CURSOR);

/* joystick */
js_init();
js_init(TRUE);

/* gestione grafica */
if (gfx_init()) {
Expand Down Expand Up @@ -875,7 +875,7 @@ void emu_quit(BYTE exit_code) {

timeline_quit();

js_quit();
js_quit(TRUE);

uncomp_quit();

Expand Down
26 changes: 20 additions & 6 deletions src/core/input.h
Expand Up @@ -19,6 +19,11 @@
#ifndef INPUT_H_
#define INPUT_H_

#if defined (__WIN32__)
#define INITGUID
#include <guiddef.h>
#undef INITGUID
#endif
#include "common.h"

#define SET_DECODE_EVENT(id, funct) input_decode_event[id] = funct
Expand Down Expand Up @@ -59,22 +64,31 @@ enum port_controllers {
PORT_MAX
};

typedef struct {
typedef struct _config_input {
BYTE permit_updown_leftright;
BYTE controller_mode;
#if defined (__WIN32__)
GUID shcjoy_id;
#else
BYTE shcjoy_id;
#endif
} _config_input;
typedef struct {
typedef struct _r4016 {
BYTE value;
} _r4016;
typedef struct {
typedef struct _turbo_button {
BYTE frequency;
BYTE active;
BYTE counter;
} _turbo_button;
typedef struct {
typedef struct _port {
BYTE type;
#if defined (__WIN32__)
GUID joy_id;
#else
BYTE joy_id;
#endif

/* standard controller */
BYTE type_pad;
BYTE index;
Expand All @@ -85,10 +99,10 @@ typedef struct {
/* zapper */
BYTE zapper;
} _port;
typedef struct {
typedef struct _four_score {
BYTE count;
} _four_score;
typedef struct {
typedef struct _array_pointers_port {
_port *port[PORT_MAX];
} _array_pointers_port;

Expand Down
2 changes: 2 additions & 0 deletions src/core/unicode_def.h
Expand Up @@ -63,6 +63,7 @@ typedef wchar_t uTCHAR;
#define ugetcwd _wgetcwd
#define umemcpy wmemcpy
#define ustrchr wcschr
#define ustrdup _wcsdup

// linux
#else
Expand Down Expand Up @@ -103,6 +104,7 @@ typedef char uTCHAR;
#define ugetcwd getcwd
#define umemcpy memcpy
#define ustrchr strchr
#define ustrdup strdup

#endif

Expand Down
19 changes: 11 additions & 8 deletions src/gui/dlgInput.cpp
Expand Up @@ -80,6 +80,8 @@ dlgInput::dlgInput(QWidget *parent = 0) : QDialog(parent) {
installEventFilter(this);

emu_pause(TRUE);

js_update_detected_devices();
}
dlgInput::~dlgInput() {}
bool dlgInput::eventFilter(QObject *obj, QEvent *event) {
Expand Down Expand Up @@ -108,6 +110,7 @@ bool dlgInput::eventFilter(QObject *obj, QEvent *event) {
case QEvent::LanguageChange:
Input_dialog::retranslateUi(this);
update_dialog();
break;
case QEvent::KeyPress:
return (keypressEvent(event));
default:
Expand Down Expand Up @@ -290,7 +293,7 @@ void dlgInput::combo_joy_id_init() {
continue;
}

if (id == data.settings.shcjoy_id) {
if (js_is_this(id, &data.settings.shcjoy_id)) {
current_line = count;
}

Expand All @@ -313,8 +316,7 @@ void dlgInput::combo_joy_id_init() {
}

if (count > 0) {
if (data.settings.shcjoy_id == name_to_jsn(uL("NULL"))
|| (current_line == name_to_jsn(uL("NULL")))) {
if (js_is_null(&data.settings.shcjoy_id) || (current_line == name_to_jsn(uL("NULL")))) {
comboBox_joy_ID->setCurrentIndex(disabled_line);
} else {
comboBox_joy_ID->setCurrentIndex(current_line);
Expand Down Expand Up @@ -586,7 +588,7 @@ void dlgInput::s_checkbox_state_changed(int state) {
void dlgInput::s_combobox_joy_activated(int index) {
unsigned int id = ((QComboBox *)sender())->itemData(index).toInt();

data.settings.shcjoy_id = id;
js_set_id(&data.settings.shcjoy_id, id);
update_groupbox_shortcuts(UPDATE_ALL, NO_ACTION, NO_ACTION);
}
void dlgInput::s_shortcut_clicked(bool checked) {
Expand Down Expand Up @@ -659,7 +661,7 @@ void dlgInput::s_joy_shortcut_unset(bool checked) {
tableWidget_Shortcuts->cellWidget(row, 2)->findChild<QPushButton *>("value")->setText("NULL");
}
void dlgInput::s_joy_read_timer() {
DBWORD value = js_read_in_dialog(data.settings.shcjoy_id, shcut.joy.fd);
DBWORD value = js_read_in_dialog(&data.settings.shcjoy_id, shcut.joy.fd);

if (shcut.joy.value && !value) {
#if defined (__linux__)
Expand Down Expand Up @@ -699,7 +701,8 @@ void dlgInput::s_default_clicked(bool checked) {

settings_inp_all_default(&data.settings, &array);

data.settings.shcjoy_id = name_to_jsn(uL("NULL"));
js_set_id(&data.settings.shcjoy_id, name_to_jsn(uL("NULL")));

comboBox_joy_ID->setCurrentIndex(comboBox_joy_ID->count() - 1);
for (int i = 0; i < SET_MAX_NUM_SC; i++) {
shcut.text[KEYBOARD].replace(i,
Expand Down Expand Up @@ -742,8 +745,8 @@ void dlgInput::s_apply_clicked(bool checked) {

input_init(SET_CURSOR);

js_quit();
js_init();
js_quit(FALSE);
js_init(FALSE);

close();
}
Expand Down
13 changes: 7 additions & 6 deletions src/gui/dlgStdPad.cpp
Expand Up @@ -147,6 +147,8 @@ dlgStdPad::dlgStdPad(_cfg_port *cfg_port, QWidget *parent = 0) : QDialog(parent)
connect(data.seq.timer, SIGNAL(timeout()), this, SLOT(s_pad_in_sequence_timer()));

installEventFilter(this);

js_update_detected_devices();
}
dlgStdPad::~dlgStdPad() {}
void dlgStdPad::update_dialog() {
Expand Down Expand Up @@ -212,7 +214,7 @@ void dlgStdPad::combo_id_init() {
continue;
}

if (id == data.cfg.port.joy_id) {
if (js_is_this(id, &data.cfg.port.joy_id)) {
current_line = count;
}

Expand All @@ -238,8 +240,7 @@ void dlgStdPad::combo_id_init() {
}

if (count > 0) {
if (data.cfg.port.joy_id == name_to_jsn(uL("NULL"))
|| (current_line == name_to_jsn(uL("NULL")))) {
if (js_is_null(&data.cfg.port.joy_id) || (current_line == name_to_jsn(uL("NULL")))) {
comboBox_joy_ID->setCurrentIndex(disabled_line);
} else {
comboBox_joy_ID->setCurrentIndex(current_line);
Expand Down Expand Up @@ -293,7 +294,7 @@ void dlgStdPad::js_press_event() {

type = data.vbutton / MAX_STD_PAD_BUTTONS;

if (data.cfg.port.joy_id == name_to_jsn(uL("NULL"))) {
if (js_is_null(&data.cfg.port.joy_id)) {
info_entry_print(type, tr("Select device first"));
update_dialog();
return;
Expand Down Expand Up @@ -415,7 +416,7 @@ bool dlgStdPad::keypressEvent(QEvent *event) {
void dlgStdPad::s_combobox_joy_activated(int index) {
unsigned int id = ((QComboBox *)sender())->itemData(index).toInt();

data.cfg.port.joy_id = id;
js_set_id(&data.cfg.port.joy_id, id);
update_dialog();
}
void dlgStdPad::s_input_clicked(bool checked) {
Expand Down Expand Up @@ -517,7 +518,7 @@ void dlgStdPad::s_slider_td_value_changed(int value) {
td_update_label(type, value);
}
void dlgStdPad::s_pad_joy_read_timer() {
DBWORD value = js_read_in_dialog(data.cfg.port.joy_id, data.joy.fd);
DBWORD value = js_read_in_dialog(&data.cfg.port.joy_id, data.joy.fd);

if (data.joy.value && !value) {
unsigned int type, vbutton;
Expand Down
77 changes: 54 additions & 23 deletions src/gui/linux/jstick.c
Expand Up @@ -27,6 +27,7 @@
#include "jstick.h"
#include "input.h"
#include "gui.h"
#include "conf.h"

#define _js_start(jid, op)\
if (jid == name_to_jsn(uL("NULL"))) {\
Expand Down Expand Up @@ -76,7 +77,10 @@
}\
}

void js_init(void) {
static void js_open(_js *joy);
static void js_close(_js *joy);

void js_init(BYTE first_time) {
BYTE i;

for (i = PORT1; i < PORT_MAX; i++) {
Expand All @@ -91,15 +95,14 @@ void js_init(void) {
js_open(&js[i]);
}
}
void js_open(_js *joy) {
joy->fd = 0;
if (joy->dev[0] && ustrcmp(joy->dev, uL("NULL"))) {
joy->fd = uopen(joy->dev, O_RDONLY | O_NONBLOCK);
if (joy->fd < 0) {
joy->fd = 0;
}
void js_quit(BYTE last_time) {
BYTE i;

for (i = PORT1; i < PORT_MAX; i++) {
js_close(&js[i]);
}
}
void js_update_detected_devices(void) {}
void js_control(_js *joy, _port *port) {
static const SWORD sensibility = (PLUS / 100) * 20;
_js_event jse;
Expand All @@ -116,19 +119,7 @@ void js_control(_js *joy, _port *port) {
}
}
}
void js_close(_js *joy) {
if (joy->fd) {
close(joy->fd);
}
joy->fd = 0;
}
void js_quit(void) {
BYTE i;

for (i = PORT1; i < PORT_MAX; i++) {
js_close(&js[i]);
}
}
BYTE js_is_connected(int dev) {
uTCHAR path_dev[30];
int fd;
Expand All @@ -142,6 +133,15 @@ BYTE js_is_connected(int dev) {
close(fd);
return (EXIT_OK);
}
BYTE js_is_this(BYTE dev, BYTE *id) {
return (dev == (*id));
}
BYTE js_is_null(BYTE *id) {
return ((*id) == name_to_jsn(uL("NULL")));
}
void js_set_id(BYTE *id, int dev) {
(*id) = dev;
}
uTCHAR *js_name_device(int dev) {
static uTCHAR name[128];
uTCHAR path_dev[30];
Expand Down Expand Up @@ -199,7 +199,7 @@ DBWORD js_from_name(const uTCHAR *name, const _js_element *list, const DBWORD le
}
return (js);
}
DBWORD js_read_in_dialog(int dev, int fd) {
DBWORD js_read_in_dialog(BYTE *id, int fd) {
static const WORD sensibility = (PLUS / 100) * 75;
_js_event jse;
ssize_t size = sizeof(jse);
Expand Down Expand Up @@ -232,13 +232,28 @@ DBWORD js_read_in_dialog(int dev, int fd) {

return (value);
}
BYTE js_shcut_read(_js_sch *js_sch, _js *joy, int id) {

void js_shcut_init(void) {
memset(&js_shcut, 0x00, sizeof(_js));
usnprintf(js_shcut.dev, usizeof(js_shcut.dev), uL("" JS_DEV_PATH "%d"), cfg->input.shcjoy_id);
if ((js_shcut.fd = open(js_shcut.dev, O_RDONLY | O_NONBLOCK)) == -1) {
js_shcut.fd = 0;
}
}
void js_shcut_stop(void) {
if (js_shcut.fd) {
close(js_shcut.fd);
js_shcut.fd = 0;
}
}
BYTE js_shcut_read(_js_sch *js_sch) {
static const SWORD sensibility = (PLUS / 100) * 50;
DBWORD value = 0;
BYTE mode = 0;
_js_event jse;
_js *joy = &js_shcut;

_js_start(id, return (EXIT_ERROR))
_js_start(cfg->input.shcjoy_id, return (EXIT_ERROR))

while (!js_read_event(&jse, joy)) {
_js_control()
Expand All @@ -254,3 +269,19 @@ BYTE js_shcut_read(_js_sch *js_sch, _js *joy, int id) {

return (EXIT_ERROR);
}

static void js_open(_js *joy) {
joy->fd = 0;
if (joy->dev[0] && ustrcmp(joy->dev, uL("NULL"))) {
joy->fd = uopen(joy->dev, O_RDONLY | O_NONBLOCK);
if (joy->fd < 0) {
joy->fd = 0;
}
}
}
static void js_close(_js *joy) {
if (joy->fd) {
close(joy->fd);
}
joy->fd = 0;
}

0 comments on commit e7226c6

Please sign in to comment.