Skip to content
Permalink
Browse files

Implementato il pieno supporto alle XInput.

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 e7226c67675487a12d3c20fc05c3b473b83e95ce
@@ -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()) {
@@ -875,7 +875,7 @@ void emu_quit(BYTE exit_code) {

timeline_quit();

js_quit();
js_quit(TRUE);

uncomp_quit();

@@ -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
@@ -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;
@@ -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;

@@ -63,6 +63,7 @@ typedef wchar_t uTCHAR;
#define ugetcwd _wgetcwd
#define umemcpy wmemcpy
#define ustrchr wcschr
#define ustrdup _wcsdup

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

#endif

@@ -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) {
@@ -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:
@@ -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;
}

@@ -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);
@@ -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) {
@@ -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__)
@@ -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,
@@ -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();
}
@@ -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() {
@@ -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;
}

@@ -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);
@@ -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;
@@ -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) {
@@ -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;
@@ -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"))) {\
@@ -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++) {
@@ -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;
@@ -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;
@@ -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];
@@ -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);
@@ -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()
@@ -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.