1
0
mirror of https://github.com/mist-devel/mist-firmware.git synced 2026-04-27 04:47:22 +00:00

xboxusb: fix incorrect joysticks indexing

xboxusb.c behaviour is aligned with hid.c: all OSD state* functions use raw jindex, user_io_* functions use mapped index
This commit is contained in:
Eugene Lozovoy
2024-08-21 21:09:21 +03:00
parent 521e9c1ff1
commit 0405f16a77

View File

@@ -134,12 +134,14 @@ uint8_t usb_xbox_init(usb_device_t *dev, usb_device_descriptor_t *dev_desc) {
iprintf("XBOX: error setting conf value (%d)\n", rcode);
return rcode;
}
usb_debugf("add xbox joystick #%d", joystick_count());
dev->xbox_info.jindex = joystick_add();
dev->xbox_info.bPollEnable = true;
return 0;
}
uint8_t usb_xbox_release(usb_device_t *dev) {
usb_debugf("releasing xbox joystick #%d, renumbering", dev->xbox_info.jindex);
joystick_release(dev->xbox_info.jindex);
return 0;
}
@@ -153,17 +155,6 @@ static void usb_xbox_read_report(usb_device_t *dev, uint16_t len, uint8_t *buf)
}
uint32_t buttons = (swp2(buf[2], 0xc) >> 2) | (swp2(buf[2], 0x3) << 2) | swp2(buf[3], 0x30) | (swp2(buf[2], 0x30) << 2) | ((buf[3] & 0x03) << 10) | (swp2(buf[3], 0xc0) << 2);
uint8_t idx = dev->xbox_info.jindex;
// swap joystick 0 and 1 since 1 is the one.
// used primarily on most systems (most = Amiga and ST...need to get rid of this)
if(idx == 0) idx = 1;
else if(idx == 1) idx = 0;
// if real DB9 mouse is preffered, switch the id back to 1
idx = (idx == 0) && mist_cfg.joystick0_prefer_db9 ? 1 : idx;
StateUsbIdSet(dev->vid, dev->pid, 8, idx);
StateJoySetAnalogue( buf[7], buf[9], buf[11], buf[13], idx );
user_io_analog_joystick(idx, buf[7], ~buf[9], buf[11], ~buf[13]);
// Handle analogue parts (discard low order byte)
uint8_t jmap = 0;
@@ -180,25 +171,34 @@ static void usb_xbox_read_report(usb_device_t *dev, uint16_t len, uint8_t *buf)
if((buf[13]+128) > JOYSTICK_AXIS_TRIGGER_MAX) jmap |= JOY_UP;
buttons |= (jmap << 16);
// map virtual joypad
uint32_t vjoy = virtual_joystick_mapping(dev->vid, dev->pid, buttons);
// add right stick (no remap)
vjoy |= (jmap << 16);
uint8_t idx = dev->xbox_info.jindex;
StateUsbIdSet(dev->vid, dev->pid, 8, idx);
StateUsbJoySet(buttons, buttons>>8, idx);
StateJoySet(vjoy, idx);
StateJoySetExtra(vjoy>>8, idx);
StateJoySetAnalogue( buf[7], buf[9], buf[11], buf[13], idx );
// swap joystick 0 and 1 since 1 is the one.
// used primarily on most systems (most = Amiga and ST...need to get rid of this)
if(!mist_cfg.joystick_disable_swap || user_io_core_type() != CORE_TYPE_8BIT) {
if(idx == 0) idx = 1;
else if(idx == 1) idx = 0;
}
// if real DB9 mouse is preffered, switch the id back to 1
idx = (idx == 0) && mist_cfg.joystick0_prefer_db9 ? 1 : idx;
if(buttons != dev->xbox_info.oldButtons) {
StateUsbJoySet(buttons, buttons>>8, idx);
uint32_t vjoy = virtual_joystick_mapping(dev->vid, dev->pid, buttons);
// add right stick (no remap)
vjoy |= (jmap << 16);
StateJoySet(vjoy, idx);
StateJoySetExtra( vjoy>>8, idx);
user_io_digital_joystick(idx, vjoy & 0xFF);
// new API with all extra buttons
user_io_digital_joystick_ext(idx, vjoy);
virtual_joystick_keyboard( vjoy );
dev->xbox_info.oldButtons = buttons;
}
user_io_analog_joystick(idx, buf[7], ~buf[9], buf[11], ~buf[13]);
}
uint8_t usb_xbox_poll(usb_device_t *dev) {