This commit is contained in:
Jasmine Iwanek
2025-01-11 01:31:57 -05:00
parent 035b8deee2
commit 3b092bcdb2
6 changed files with 155 additions and 174 deletions

View File

@@ -475,8 +475,6 @@ load_input_devices(void)
{ {
ini_section_t cat = ini_find_section(config, "Input devices"); ini_section_t cat = ini_find_section(config, "Input devices");
char temp[512]; char temp[512];
int c;
int d;
char *p; char *p;
p = ini_section_get_string(cat, "mouse_type", NULL); p = ini_section_get_string(cat, "mouse_type", NULL);
@@ -495,8 +493,8 @@ load_input_devices(void)
/* Workaround for ini_section_get_int returning 0 on non-integer data */ /* Workaround for ini_section_get_int returning 0 on non-integer data */
joystick_type = joystick_get_from_internal_name("2axis_2button"); joystick_type = joystick_get_from_internal_name("2axis_2button");
else { else {
c = ini_section_get_int(cat, "joystick_type", 8); int js = ini_section_get_int(cat, "joystick_type", 8);
switch (c) { switch (js) {
case JS_TYPE_2AXIS_4BUTTON: case JS_TYPE_2AXIS_4BUTTON:
joystick_type = joystick_get_from_internal_name("2axis_4button"); joystick_type = joystick_get_from_internal_name("2axis_4button");
break; break;
@@ -527,25 +525,25 @@ load_input_devices(void)
} else } else
joystick_type = JS_TYPE_NONE; joystick_type = JS_TYPE_NONE;
for (c = 0; c < joystick_get_max_joysticks(joystick_type); c++) { for (int js = 0; js < joystick_get_max_joysticks(joystick_type); js++) {
sprintf(temp, "joystick_%i_nr", c); sprintf(temp, "joystick_%i_nr", js);
joystick_state[c].plat_joystick_nr = ini_section_get_int(cat, temp, 0); joystick_state[js].plat_joystick_nr = ini_section_get_int(cat, temp, 0);
if (joystick_state[c].plat_joystick_nr) { if (joystick_state[js].plat_joystick_nr) {
for (d = 0; d < joystick_get_axis_count(joystick_type); d++) { for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++) {
sprintf(temp, "joystick_%i_axis_%i", c, d); sprintf(temp, "joystick_%i_axis_%i", js, axis_nr);
joystick_state[c].axis_mapping[d] = ini_section_get_int(cat, temp, d); joystick_state[js].axis_mapping[axis_nr] = ini_section_get_int(cat, temp, axis_nr);
} }
for (d = 0; d < joystick_get_button_count(joystick_type); d++) { for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++) {
sprintf(temp, "joystick_%i_button_%i", c, d); sprintf(temp, "joystick_%i_button_%i", js, button_nr);
joystick_state[c].button_mapping[d] = ini_section_get_int(cat, temp, d); joystick_state[js].button_mapping[button_nr] = ini_section_get_int(cat, temp, button_nr);
} }
for (d = 0; d < joystick_get_pov_count(joystick_type); d++) { for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) {
sprintf(temp, "joystick_%i_pov_%i", c, d); sprintf(temp, "joystick_%i_pov_%i", js, pov_nr);
p = ini_section_get_string(cat, temp, "0, 0"); p = ini_section_get_string(cat, temp, "0, 0");
joystick_state[c].pov_mapping[d][0] = joystick_state[c].pov_mapping[d][1] = 0; joystick_state[js].pov_mapping[js][pov_nr] = joystick_state[js].pov_mapping[pov_nr][1] = 0;
sscanf(p, "%i, %i", &joystick_state[c].pov_mapping[d][0], sscanf(p, "%i, %i", &joystick_state[js].pov_mapping[pov_nr][0],
&joystick_state[c].pov_mapping[d][1]); &joystick_state[js].pov_mapping[pov_nr][1]);
} }
} }
} }
@@ -743,11 +741,9 @@ load_ports(void)
ini_section_t cat = ini_find_section(config, "Ports (COM & LPT)"); ini_section_t cat = ini_find_section(config, "Ports (COM & LPT)");
char *p; char *p;
char temp[512]; char temp[512];
int c;
memset(temp, 0, sizeof(temp)); memset(temp, 0, sizeof(temp));
for (c = 0; c < SERIAL_MAX; c++) { for (int c = 0; c < SERIAL_MAX; c++) {
sprintf(temp, "serial%d_enabled", c + 1); sprintf(temp, "serial%d_enabled", c + 1);
com_ports[c].enabled = !!ini_section_get_int(cat, temp, (c >= 2) ? 0 : 1); com_ports[c].enabled = !!ini_section_get_int(cat, temp, (c >= 2) ? 0 : 1);
@@ -758,7 +754,7 @@ load_ports(void)
config_log("Serial Port %d: passthrough enabled.\n\n", c + 1); config_log("Serial Port %d: passthrough enabled.\n\n", c + 1);
} }
for (c = 0; c < PARALLEL_MAX; c++) { for (int c = 0; c < PARALLEL_MAX; c++) {
sprintf(temp, "lpt%d_enabled", c + 1); sprintf(temp, "lpt%d_enabled", c + 1);
lpt_ports[c].enabled = !!ini_section_get_int(cat, temp, (c == 0) ? 1 : 0); lpt_ports[c].enabled = !!ini_section_get_int(cat, temp, (c == 0) ? 1 : 0);
@@ -776,11 +772,10 @@ load_storage_controllers(void)
ini_section_t migration_cat; ini_section_t migration_cat;
char *p; char *p;
char temp[512]; char temp[512];
int c;
int min = 0; int min = 0;
int free_p = 0; int free_p = 0;
for (c = min; c < SCSI_CARD_MAX; c++) { for (int c = min; c < SCSI_CARD_MAX; c++) {
sprintf(temp, "scsicard_%d", c + 1); sprintf(temp, "scsicard_%d", c + 1);
p = ini_section_get_string(cat, temp, NULL); p = ini_section_get_string(cat, temp, NULL);
@@ -932,7 +927,7 @@ load_storage_controllers(void)
ini_section_delete_var(cat, "cassette_ui_writeprot"); ini_section_delete_var(cat, "cassette_ui_writeprot");
} }
for (c = 0; c < 2; c++) { for (int c = 0; c < 2; c++) {
sprintf(temp, "cartridge_%02i_fn", c + 1); sprintf(temp, "cartridge_%02i_fn", c + 1);
p = ini_section_get_string(cat, temp, ""); p = ini_section_get_string(cat, temp, "");
@@ -2140,50 +2135,49 @@ save_input_devices(void)
ini_section_t cat = ini_find_or_create_section(config, "Input devices"); ini_section_t cat = ini_find_or_create_section(config, "Input devices");
char temp[512]; char temp[512];
char tmp2[512]; char tmp2[512];
int c;
int d;
ini_section_set_string(cat, "mouse_type", mouse_get_internal_name(mouse_type)); ini_section_set_string(cat, "mouse_type", mouse_get_internal_name(mouse_type));
if (!joystick_type) { if (!joystick_type) {
ini_section_delete_var(cat, "joystick_type"); ini_section_delete_var(cat, "joystick_type");
for (c = 0; c < 16; c++) { for (int js = 0; js < MAX_PLAT_JOYSTICKS; js++) {
sprintf(tmp2, "joystick_%i_nr", c); sprintf(tmp2, "joystick_%i_nr", js);
ini_section_delete_var(cat, tmp2); ini_section_delete_var(cat, tmp2);
for (d = 0; d < 16; d++) { for (int axis_nr = 0; axis_nr < 16; axis_nr++) {
sprintf(tmp2, "joystick_%i_axis_%i", c, d); sprintf(tmp2, "joystick_%i_axis_%i", js, axis_nr);
ini_section_delete_var(cat, tmp2); ini_section_delete_var(cat, tmp2);
} }
for (d = 0; d < 16; d++) { for (int button_nr = 0; button_nr < 16; button_nr++) {
sprintf(tmp2, "joystick_%i_button_%i", c, d); sprintf(tmp2, "joystick_%i_button_%i", js, button_nr);
ini_section_delete_var(cat, tmp2); ini_section_delete_var(cat, tmp2);
} }
for (d = 0; d < 16; d++) { for (int pov_nr = 0; pov_nr < 16; pov_nr++) {
sprintf(tmp2, "joystick_%i_pov_%i", c, d); sprintf(tmp2, "joystick_%i_pov_%i", js, pov_nr);
ini_section_delete_var(cat, tmp2); ini_section_delete_var(cat, tmp2);
} }
} }
} else { } else {
ini_section_set_string(cat, "joystick_type", joystick_get_internal_name(joystick_type)); ini_section_set_string(cat, "joystick_type", joystick_get_internal_name(joystick_type));
for (c = 0; c < joystick_get_max_joysticks(joystick_type); c++) { for (int js = 0; js < joystick_get_max_joysticks(joystick_type); js++) {
sprintf(tmp2, "joystick_%i_nr", c); sprintf(tmp2, "joystick_%i_nr", js);
ini_section_set_int(cat, tmp2, joystick_state[c].plat_joystick_nr); ini_section_set_int(cat, tmp2, joystick_state[js].plat_joystick_nr);
if (joystick_state[c].plat_joystick_nr) { if (joystick_state[js].plat_joystick_nr) {
for (d = 0; d < joystick_get_axis_count(joystick_type); d++) { for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++) {
sprintf(tmp2, "joystick_%i_axis_%i", c, d); sprintf(tmp2, "joystick_%i_axis_%i", js, axis_nr);
ini_section_set_int(cat, tmp2, joystick_state[c].axis_mapping[d]); ini_section_set_int(cat, tmp2, joystick_state[js].axis_mapping[axis_nr]);
} }
for (d = 0; d < joystick_get_button_count(joystick_type); d++) { for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++) {
sprintf(tmp2, "joystick_%i_button_%i", c, d); sprintf(tmp2, "joystick_%i_button_%i", js, button_nr);
ini_section_set_int(cat, tmp2, joystick_state[c].button_mapping[d]); ini_section_set_int(cat, tmp2, joystick_state[js].button_mapping[button_nr]);
} }
for (d = 0; d < joystick_get_pov_count(joystick_type); d++) { for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) {
sprintf(tmp2, "joystick_%i_pov_%i", c, d); sprintf(tmp2, "joystick_%i_pov_%i", js, pov_nr);
sprintf(temp, "%i, %i", joystick_state[c].pov_mapping[d][0], joystick_state[c].pov_mapping[d][1]); sprintf(temp, "%i, %i", joystick_state[js].pov_mapping[pov_nr][0],
joystick_state[js].pov_mapping[pov_nr][1]);
ini_section_set_string(cat, tmp2, temp); ini_section_set_string(cat, tmp2, temp);
} }
} }
@@ -2341,10 +2335,8 @@ save_ports(void)
{ {
ini_section_t cat = ini_find_or_create_section(config, "Ports (COM & LPT)"); ini_section_t cat = ini_find_or_create_section(config, "Ports (COM & LPT)");
char temp[512]; char temp[512];
int c;
int d;
for (c = 0; c < SERIAL_MAX; c++) { for (int c = 0; c < SERIAL_MAX; c++) {
sprintf(temp, "serial%d_enabled", c + 1); sprintf(temp, "serial%d_enabled", c + 1);
if (((c < 2) && com_ports[c].enabled) || ((c >= 2) && !com_ports[c].enabled)) if (((c < 2) && com_ports[c].enabled) || ((c >= 2) && !com_ports[c].enabled))
ini_section_delete_var(cat, temp); ini_section_delete_var(cat, temp);
@@ -2358,9 +2350,9 @@ save_ports(void)
ini_section_delete_var(cat, temp); ini_section_delete_var(cat, temp);
} }
for (c = 0; c < PARALLEL_MAX; c++) { for (int c = 0; c < PARALLEL_MAX; c++) {
sprintf(temp, "lpt%d_enabled", c + 1); sprintf(temp, "lpt%d_enabled", c + 1);
d = (c == 0) ? 1 : 0; int d = (c == 0) ? 1 : 0;
if (lpt_ports[c].enabled == d) if (lpt_ports[c].enabled == d)
ini_section_delete_var(cat, temp); ini_section_delete_var(cat, temp);
else else

View File

@@ -62,17 +62,13 @@ joystick_standard_read(UNUSED(void *priv))
{ {
uint8_t ret = 0xf0; uint8_t ret = 0xf0;
if (JOYSTICK_PRESENT(0)) { for (int js = 0; js < 2; js++) {
if (joystick_state[0].button[0]) if (JOYSTICK_PRESENT(js)) {
ret &= ~0x10; if (joystick_state[js].button[0])
if (joystick_state[0].button[1]) ret &= ~0x10;
ret &= ~0x20; if (joystick_state[js].button[1])
} ret &= ~0x20;
if (JOYSTICK_PRESENT(1)) { }
if (joystick_state[1].button[0])
ret &= ~0x40;
if (joystick_state[1].button[1])
ret &= ~0x80;
} }
return ret; return ret;
@@ -140,9 +136,7 @@ joystick_standard_read_axis_4button(UNUSED(void *priv), int axis)
case 1: case 1:
return joystick_state[0].axis[1]; return joystick_state[0].axis[1];
case 2: case 2:
return 0;
case 3: case 3:
return 0;
default: default:
return 0; return 0;
} }
@@ -162,7 +156,6 @@ joystick_standard_read_axis_3axis(UNUSED(void *priv), int axis)
case 2: case 2:
return joystick_state[0].axis[2]; return joystick_state[0].axis[2];
case 3: case 3:
return 0;
default: default:
return 0; return 0;
} }

View File

@@ -119,8 +119,7 @@ sw_parity(uint16_t data)
static void * static void *
sw_init(void) sw_init(void)
{ {
sw_data *sw = (sw_data *) malloc(sizeof(sw_data)); sw_data *sw = (sw_data *) calloc(1, sizeof(sw_data));
memset(sw, 0, sizeof(sw_data));
timer_add(&sw->poll_timer, sw_timer_over, sw, 0); timer_add(&sw->poll_timer, sw_timer_over, sw, 0);
timer_add(&sw->trigger_timer, sw_trigger_timer_over, sw, 0); timer_add(&sw->trigger_timer, sw_trigger_timer_over, sw, 0);
@@ -191,24 +190,24 @@ sw_write(void *priv)
sw->poll_data = 1; sw->poll_data = 1;
} }
for (uint8_t c = 0; c < 4; c++) { for (uint8_t js = 0; js < MAX_JOYSTICKS; js++) {
uint16_t data = 0x3fff; uint16_t data = 0x3fff;
if (!JOYSTICK_PRESENT(c)) if (!JOYSTICK_PRESENT(js))
break; break;
if (joystick_state[c].axis[1] < -16383) if (joystick_state[js].axis[1] < -16383)
data &= ~1; data &= ~1;
if (joystick_state[c].axis[1] > 16383) if (joystick_state[js].axis[1] > 16383)
data &= ~2; data &= ~2;
if (joystick_state[c].axis[0] > 16383) if (joystick_state[js].axis[0] > 16383)
data &= ~4; data &= ~4;
if (joystick_state[c].axis[0] < -16383) if (joystick_state[js].axis[0] < -16383)
data &= ~8; data &= ~8;
for (uint8_t b = 0; b < 10; b++) { for (uint8_t button_nr = 0; button_nr < 10; button_nr++) {
if (joystick_state[c].button[b]) if (joystick_state[js].button[button_nr])
data &= ~(1 << (b + 4)); data &= ~(1 << (button_nr + 4));
} }
if (sw_parity(data)) if (sw_parity(data))
@@ -216,10 +215,10 @@ sw_write(void *priv)
if (sw->poll_mode) { if (sw->poll_mode) {
sw->poll_left += 5; sw->poll_left += 5;
sw->poll_data |= (data << (c * 15 + 3)); sw->poll_data |= (data << (js * 15 + 3));
} else { } else {
sw->poll_left += 15; sw->poll_left += 15;
sw->poll_data |= (data << (c * 15 + 1)); sw->poll_data |= (data << (js * 15 + 1));
} }
} }
} }

View File

@@ -178,15 +178,17 @@ updateJoystickConfig(int type, int joystick_nr, QWidget *parent)
joystick_state[joystick_nr].plat_joystick_nr = jc.selectedDevice(); joystick_state[joystick_nr].plat_joystick_nr = jc.selectedDevice();
if (joystick_state[joystick_nr].plat_joystick_nr) { if (joystick_state[joystick_nr].plat_joystick_nr) {
for (int c = 0; c < joystick_get_axis_count(type); c++) { for (int axis_nr = 0; axis_nr < joystick_get_axis_count(type); axis_nr++) {
joystick_state[joystick_nr].axis_mapping[c] = get_axis(jc, c, joystick_nr); joystick_state[joystick_nr].axis_mapping[axis_nr] = get_axis(jc, axis_nr, joystick_nr);
} }
for (int c = 0; c < joystick_get_button_count(type); c++) {
joystick_state[joystick_nr].button_mapping[c] = jc.selectedButton(c); for (int button_nr = 0; button_nr < joystick_get_button_count(type); button_nr++) {
joystick_state[joystick_nr].button_mapping[button_nr] = jc.selectedButton(button_nr);
} }
for (int c = 0; c < joystick_get_pov_count(type) * 2; c += 2) {
joystick_state[joystick_nr].pov_mapping[c][0] = get_pov(jc, c, joystick_nr); for (int pov_nr = 0; pov_nr < joystick_get_pov_count(type) * 2; pov_nr += 2) {
joystick_state[joystick_nr].pov_mapping[c][1] = get_pov(jc, c + 1, joystick_nr); joystick_state[joystick_nr].pov_mapping[pov_nr][0] = get_pov(jc, pov_nr, joystick_nr);
joystick_state[joystick_nr].pov_mapping[pov_nr][1] = get_pov(jc, pov_nr + 1, joystick_nr);
} }
} }
} }

View File

@@ -54,28 +54,26 @@ joystick_init(void)
joysticks_present = SDL_NumJoysticks(); joysticks_present = SDL_NumJoysticks();
memset(sdl_joy, 0, sizeof(sdl_joy)); memset(sdl_joy, 0, sizeof(sdl_joy));
for (int c = 0; c < joysticks_present; c++) { for (int js = 0; js < joysticks_present; js++) {
sdl_joy[c] = SDL_JoystickOpen(c); sdl_joy[js] = SDL_JoystickOpen(js);
if (sdl_joy[c]) { if (sdl_joy[js]) {
int d; strncpy(plat_joystick_state[js].name, SDL_JoystickNameForIndex(js), 64);
plat_joystick_state[js].nr_axes = MIN(SDL_JoystickNumAxes(sdl_joy[js]), MAX_JOY_AXES);
plat_joystick_state[js].nr_buttons = MIN(SDL_JoystickNumButtons(sdl_joy[js]), MAX_JOY_BUTTONS);
plat_joystick_state[js].nr_povs = MIN(SDL_JoystickNumHats(sdl_joy[js]), MAX_JOY_POVS);
strncpy(plat_joystick_state[c].name, SDL_JoystickNameForIndex(c), 64); for (int axis_nr = 0; axis_nr < plat_joystick_state[js].nr_axes; axis_nr++) {
plat_joystick_state[c].nr_axes = MIN(SDL_JoystickNumAxes(sdl_joy[c]), MAX_JOY_AXES); snprintf(plat_joystick_state[js].axis[axis_nr].name, sizeof(plat_joystick_state[js].axis[axis_nr].name), "Axis %i", axis_nr);
plat_joystick_state[c].nr_buttons = MIN(SDL_JoystickNumButtons(sdl_joy[c]), MAX_JOY_BUTTONS); plat_joystick_state[js].axis[axis_nr].id = axis_nr;
plat_joystick_state[c].nr_povs = MIN(SDL_JoystickNumHats(sdl_joy[c]), MAX_JOY_POVS);
for (d = 0; d < plat_joystick_state[c].nr_axes; d++) {
snprintf(plat_joystick_state[c].axis[d].name, sizeof(plat_joystick_state[c].axis[d].name), "Axis %i", d);
plat_joystick_state[c].axis[d].id = d;
} }
for (d = 0; d < plat_joystick_state[c].nr_buttons; d++) { for (int buttons_nr = 0; buttons_nr < plat_joystick_state[js].nr_buttons; buttons_nr++) {
snprintf(plat_joystick_state[c].button[d].name, sizeof(plat_joystick_state[c].button[d].name), "Button %i", d); snprintf(plat_joystick_state[js].button[buttons_nr].name, sizeof(plat_joystick_state[js].button[buttons_nr].name), "Button %i", buttons_nr);
plat_joystick_state[c].button[d].id = d; plat_joystick_state[js].button[buttons_nr].id = buttons_nr;
} }
for (d = 0; d < plat_joystick_state[c].nr_povs; d++) { for (int pov_nr = 0; pov_nr < plat_joystick_state[js].nr_povs; pov_nr++) {
snprintf(plat_joystick_state[c].pov[d].name, sizeof(plat_joystick_state[c].pov[d].name), "POV %i", d); snprintf(plat_joystick_state[js].pov[pov_nr].name, sizeof(plat_joystick_state[js].pov[pov_nr].name), "POV %i", pov_nr);
plat_joystick_state[c].pov[d].id = d; plat_joystick_state[js].pov[pov_nr].id = pov_nr;
} }
} }
} }
@@ -84,11 +82,9 @@ joystick_init(void)
void void
joystick_close(void) joystick_close(void)
{ {
int c; for (int js = 0; js < joysticks_present; js++) {
if (sdl_joy[js])
for (c = 0; c < joysticks_present; c++) { SDL_JoystickClose(sdl_joy[js]);
if (sdl_joy[c])
SDL_JoystickClose(sdl_joy[c]);
} }
} }
@@ -132,57 +128,55 @@ joystick_get_axis(int joystick_nr, int mapping)
void void
joystick_process(void) joystick_process(void)
{ {
int c;
int d;
if (!joystick_type) if (!joystick_type)
return; return;
SDL_JoystickUpdate(); SDL_JoystickUpdate();
for (c = 0; c < joysticks_present; c++) { for (int js = 0; js < joysticks_present; js++) {
int b; for (int axis_nr = 0; axis_nr < plat_joystick_state[js].nr_axes; axis_nr++)
plat_joystick_state[js].a[axis_nr] = SDL_JoystickGetAxis(sdl_joy[js], axis_nr);
for (b = 0; b < plat_joystick_state[c].nr_axes; b++) for (int button_nr = 0; button_nr < plat_joystick_state[js].nr_buttons; button_nr++)
plat_joystick_state[c].a[b] = SDL_JoystickGetAxis(sdl_joy[c], b); plat_joystick_state[js].b[button_nr] = SDL_JoystickGetButton(sdl_joy[js], button_nr);
for (b = 0; b < plat_joystick_state[c].nr_buttons; b++) for (int pov_nr = 0; pov_nr < plat_joystick_state[js].nr_povs; pov_nr++)
plat_joystick_state[c].b[b] = SDL_JoystickGetButton(sdl_joy[c], b); plat_joystick_state[js].p[pov_nr] = SDL_JoystickGetHat(sdl_joy[js], pov_nr);
for (b = 0; b < plat_joystick_state[c].nr_povs; b++) #if 0
plat_joystick_state[c].p[b] = SDL_JoystickGetHat(sdl_joy[c], b); pclog("joystick %i - x=%i y=%i b[0]=%i b[1]=%i %i\n", js, joystick_state[js].x, joystick_state[js].y, joystick_state[js].b[0], joystick_state[js].b[1], joysticks_present);
// pclog("joystick %i - x=%i y=%i b[0]=%i b[1]=%i %i\n", c, joystick_state[c].x, joystick_state[c].y, joystick_state[c].b[0], joystick_state[c].b[1], joysticks_present); #endif
} }
for (c = 0; c < joystick_get_max_joysticks(joystick_type); c++) { for (int js = 0; js < joystick_get_max_joysticks(joystick_type); js++) {
if (joystick_state[c].plat_joystick_nr) { if (joystick_state[js].plat_joystick_nr) {
int joystick_nr = joystick_state[c].plat_joystick_nr - 1; int joystick_nr = joystick_state[js].plat_joystick_nr - 1;
for (d = 0; d < joystick_get_axis_count(joystick_type); d++) for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++)
joystick_state[c].axis[d] = joystick_get_axis(joystick_nr, joystick_state[c].axis_mapping[d]); joystick_state[js].axis[axis_nr] = joystick_get_axis(joystick_nr, joystick_state[js].axis_mapping[axis_nr]);
for (d = 0; d < joystick_get_button_count(joystick_type); d++)
joystick_state[c].button[d] = plat_joystick_state[joystick_nr].b[joystick_state[c].button_mapping[d]];
for (d = 0; d < joystick_get_pov_count(joystick_type); d++) {
int x, y;
double angle, magnitude;
x = joystick_get_axis(joystick_nr, joystick_state[c].pov_mapping[d][0]); for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++)
y = joystick_get_axis(joystick_nr, joystick_state[c].pov_mapping[d][1]); joystick_state[js].button[button_nr] = plat_joystick_state[joystick_nr].b[joystick_state[js].button_mapping[button_nr]];
angle = (atan2((double) y, (double) x) * 360.0) / (2 * M_PI); for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) {
magnitude = sqrt((double) x * (double) x + (double) y * (double) y); int x = joystick_get_axis(joystick_nr, joystick_state[js].pov_mapping[pov_nr][0]);
int y = joystick_get_axis(joystick_nr, joystick_state[js].pov_mapping[pov_nr][1]);
double angle = (atan2((double) y, (double) x) * 360.0) / (2 * M_PI);
double magnitude = sqrt((double) x * (double) x + (double) y * (double) y);
if (magnitude < 16384) if (magnitude < 16384)
joystick_state[c].pov[d] = -1; joystick_state[js].pov[pov_nr] = -1;
else else
joystick_state[c].pov[d] = ((int) angle + 90 + 360) % 360; joystick_state[js].pov[pov_nr] = ((int) angle + 90 + 360) % 360;
} }
} else { } else {
for (d = 0; d < joystick_get_axis_count(joystick_type); d++) for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++)
joystick_state[c].axis[d] = 0; joystick_state[js].axis[axis_nr] = 0;
for (d = 0; d < joystick_get_button_count(joystick_type); d++)
joystick_state[c].button[d] = 0; for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++)
for (d = 0; d < joystick_get_pov_count(joystick_type); d++) joystick_state[js].button[button_nr] = 0;
joystick_state[c].pov[d] = -1;
for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++)
joystick_state[js].pov[pov_nr] = -1;
} }
} }
} }

View File

@@ -412,7 +412,7 @@ win_joystick_handle(PRAWINPUT raw)
/* Read buttons */ /* Read buttons */
USAGE usage_list[128] = { 0 }; USAGE usage_list[128] = { 0 };
ULONG usage_length = plat_joystick_state[j].nr_buttons; ULONG usage_length = plat_joystick_state[j].nr_buttons;
memset(plat_joystick_state[j].b, 0, 32 * sizeof(int)); memset(plat_joystick_state[j].b, 0, MAX_JOY_BUTTONS * sizeof(int));
r = HidP_GetUsages(HidP_Input, HID_USAGE_PAGE_BUTTON, 0, usage_list, &usage_length, r = HidP_GetUsages(HidP_Input, HID_USAGE_PAGE_BUTTON, 0, usage_list, &usage_length,
raw_joystick_state[j].data, (PCHAR) raw->data.hid.bRawData, raw->data.hid.dwSizeHid); raw_joystick_state[j].data, (PCHAR) raw->data.hid.bRawData, raw->data.hid.dwSizeHid);
@@ -425,8 +425,8 @@ win_joystick_handle(PRAWINPUT raw)
} }
/* Read axes */ /* Read axes */
for (int a = 0; a < plat_joystick_state[j].nr_axes; a++) { for (int axis_nr = 0; axis_nr < plat_joystick_state[j].nr_axes; axis_nr++) {
const struct raw_axis_t *axis = &raw_joystick_state[j].axis[a]; const struct raw_axis_t *axis = &raw_joystick_state[j].axis[axis_nr];
ULONG uvalue = 0; ULONG uvalue = 0;
LONG value = 0; LONG value = 0;
LONG center = (axis->max - axis->min + 1) / 2; LONG center = (axis->max - axis->min + 1) / 2;
@@ -453,15 +453,15 @@ win_joystick_handle(PRAWINPUT raw)
value = value * 32768 / center; value = value * 32768 / center;
} }
plat_joystick_state[j].a[a] = value; plat_joystick_state[j].a[axis_nr] = value;
#if 0 #if 0
joystick_log("%s %-06d ", plat_joystick_state[j].axis[a].name, plat_joystick_state[j].a[a]); joystick_log("%s %-06d ", plat_joystick_state[j].axis[axis_nr].name, plat_joystick_state[j].a[axis_nr]);
#endif #endif
} }
/* read povs */ /* read povs */
for (int p = 0; p < plat_joystick_state[j].nr_povs; p++) { for (int pov_nr = 0; pov_nr < plat_joystick_state[j].nr_povs; pov_nr++) {
const struct raw_pov_t *pov = &raw_joystick_state[j].pov[p]; const struct raw_pov_t *pov = &raw_joystick_state[j].pov[pov_nr];
ULONG uvalue = 0; ULONG uvalue = 0;
LONG value = -1; LONG value = -1;
@@ -474,10 +474,10 @@ win_joystick_handle(PRAWINPUT raw)
value %= 36000; value %= 36000;
} }
plat_joystick_state[j].p[p] = value; plat_joystick_state[j].p[pov_nr] = value;
#if 0 #if 0
joystick_log("%s %-3d ", plat_joystick_state[j].pov[p].name, plat_joystick_state[j].p[p]); joystick_log("%s %-3d ", plat_joystick_state[j].pov[pov_nr].name, plat_joystick_state[j].p[pov_nr]);
#endif #endif
} }
#if 0 #if 0
@@ -508,44 +508,45 @@ joystick_get_axis(int joystick_nr, int mapping)
void void
joystick_process(void) joystick_process(void)
{ {
int d;
if (joystick_type == JS_TYPE_NONE) if (joystick_type == JS_TYPE_NONE)
return; return;
for (int c = 0; c < joystick_get_max_joysticks(joystick_type); c++) { for (int js = 0; js < joystick_get_max_joysticks(joystick_type); js++) {
if (joystick_state[c].plat_joystick_nr) { if (joystick_state[js].plat_joystick_nr) {
int joystick_nr = joystick_state[c].plat_joystick_nr - 1; int joystick_nr = joystick_state[js].plat_joystick_nr - 1;
for (d = 0; d < joystick_get_axis_count(joystick_type); d++) for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++)
joystick_state[c].axis[d] = joystick_get_axis(joystick_nr, joystick_state[c].axis_mapping[d]); joystick_state[js].axis[axis_nr] = joystick_get_axis(joystick_nr, joystick_state[js].axis_mapping[axis_nr]);
for (d = 0; d < joystick_get_button_count(joystick_type); d++)
joystick_state[c].button[d] = plat_joystick_state[joystick_nr].b[joystick_state[c].button_mapping[d]];
for (d = 0; d < joystick_get_pov_count(joystick_type); d++) { for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++)
joystick_state[js].button[button_nr] = plat_joystick_state[joystick_nr].b[joystick_state[js].button_mapping[button_nr]];
for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) {
int x; int x;
int y; int y;
double angle; double angle;
double magnitude; double magnitude;
x = joystick_get_axis(joystick_nr, joystick_state[c].pov_mapping[d][0]); x = joystick_get_axis(joystick_nr, joystick_state[js].pov_mapping[pov_nr][0]);
y = joystick_get_axis(joystick_nr, joystick_state[c].pov_mapping[d][1]); y = joystick_get_axis(joystick_nr, joystick_state[js].pov_mapping[pov_nr][1]);
angle = (atan2((double) y, (double) x) * 360.0) / (2 * M_PI); angle = (atan2((double) y, (double) x) * 360.0) / (2 * M_PI);
magnitude = sqrt((double) x * (double) x + (double) y * (double) y); magnitude = sqrt((double) x * (double) x + (double) y * (double) y);
if (magnitude < 16384) if (magnitude < 16384)
joystick_state[c].pov[d] = -1; joystick_state[js].pov[pov_nr] = -1;
else else
joystick_state[c].pov[d] = ((int) angle + 90 + 360) % 360; joystick_state[js].pov[pov_nr] = ((int) angle + 90 + 360) % 360;
} }
} else { } else {
for (d = 0; d < joystick_get_axis_count(joystick_type); d++) for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++)
joystick_state[c].axis[d] = 0; joystick_state[js].axis[axis_nr] = 0;
for (d = 0; d < joystick_get_button_count(joystick_type); d++)
joystick_state[c].button[d] = 0; for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++)
for (d = 0; d < joystick_get_pov_count(joystick_type); d++) joystick_state[js].button[button_nr] = 0;
joystick_state[c].pov[d] = -1;
for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++)
joystick_state[js].pov[pov_nr] = -1;
} }
} }
} }