vice-emu-commit Mailing List for VICE (Page 12)
Versatile Commodore Emulator
Brought to you by:
blackystardust,
gpz
You can subscribe to this list here.
| 2008 |
Jan
|
Feb
|
Mar
|
Apr
(38) |
May
(60) |
Jun
(122) |
Jul
(148) |
Aug
(178) |
Sep
(151) |
Oct
(131) |
Nov
(208) |
Dec
(129) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2009 |
Jan
(193) |
Feb
(209) |
Mar
(221) |
Apr
(243) |
May
(165) |
Jun
(168) |
Jul
(198) |
Aug
(161) |
Sep
(103) |
Oct
(98) |
Nov
(168) |
Dec
(99) |
| 2010 |
Jan
(263) |
Feb
(156) |
Mar
(57) |
Apr
(93) |
May
(85) |
Jun
(124) |
Jul
(57) |
Aug
(58) |
Sep
(113) |
Oct
(148) |
Nov
(114) |
Dec
(193) |
| 2011 |
Jan
(200) |
Feb
(207) |
Mar
(91) |
Apr
(91) |
May
(142) |
Jun
(104) |
Jul
(115) |
Aug
(137) |
Sep
(266) |
Oct
(91) |
Nov
(85) |
Dec
(186) |
| 2012 |
Jan
(98) |
Feb
(146) |
Mar
(160) |
Apr
(99) |
May
(59) |
Jun
(257) |
Jul
(84) |
Aug
(103) |
Sep
(169) |
Oct
(206) |
Nov
(90) |
Dec
(296) |
| 2013 |
Jan
(294) |
Feb
(130) |
Mar
(36) |
Apr
(14) |
May
(51) |
Jun
(74) |
Jul
(180) |
Aug
(85) |
Sep
(26) |
Oct
(45) |
Nov
(29) |
Dec
(21) |
| 2014 |
Jan
(56) |
Feb
(40) |
Mar
(57) |
Apr
(30) |
May
(31) |
Jun
(11) |
Jul
(107) |
Aug
(135) |
Sep
(142) |
Oct
(195) |
Nov
(139) |
Dec
(133) |
| 2015 |
Jan
(293) |
Feb
(161) |
Mar
(146) |
Apr
(85) |
May
(139) |
Jun
(51) |
Jul
(21) |
Aug
(24) |
Sep
(29) |
Oct
(136) |
Nov
(212) |
Dec
(118) |
| 2016 |
Jan
(119) |
Feb
(165) |
Mar
(229) |
Apr
(219) |
May
(134) |
Jun
(119) |
Jul
(134) |
Aug
(236) |
Sep
(203) |
Oct
(215) |
Nov
(300) |
Dec
(140) |
| 2017 |
Jan
(188) |
Feb
(20) |
Mar
(147) |
Apr
(198) |
May
(26) |
Jun
(21) |
Jul
(67) |
Aug
(219) |
Sep
(209) |
Oct
(194) |
Nov
(144) |
Dec
(99) |
| 2018 |
Jan
(139) |
Feb
(122) |
Mar
(116) |
Apr
(85) |
May
(232) |
Jun
(181) |
Jul
(190) |
Aug
(105) |
Sep
(92) |
Oct
(178) |
Nov
(105) |
Dec
(86) |
| 2019 |
Jan
(119) |
Feb
(79) |
Mar
(74) |
Apr
(117) |
May
(115) |
Jun
(307) |
Jul
(107) |
Aug
(131) |
Sep
(103) |
Oct
(60) |
Nov
(118) |
Dec
(70) |
| 2020 |
Jan
(114) |
Feb
(103) |
Mar
(77) |
Apr
(121) |
May
(193) |
Jun
(110) |
Jul
(214) |
Aug
(210) |
Sep
(179) |
Oct
(260) |
Nov
(237) |
Dec
(334) |
| 2021 |
Jan
(163) |
Feb
(186) |
Mar
(58) |
Apr
(81) |
May
(108) |
Jun
(175) |
Jul
(154) |
Aug
(180) |
Sep
(217) |
Oct
(204) |
Nov
(232) |
Dec
(190) |
| 2022 |
Jan
(253) |
Feb
(134) |
Mar
(229) |
Apr
(190) |
May
(125) |
Jun
(70) |
Jul
(8) |
Aug
(22) |
Sep
(19) |
Oct
(33) |
Nov
(94) |
Dec
(164) |
| 2023 |
Jan
(158) |
Feb
(366) |
Mar
(272) |
Apr
(109) |
May
(198) |
Jun
(226) |
Jul
(200) |
Aug
(94) |
Sep
(108) |
Oct
(62) |
Nov
(175) |
Dec
(116) |
| 2024 |
Jan
(35) |
Feb
(40) |
Mar
(51) |
Apr
(89) |
May
(24) |
Jun
(26) |
Jul
(53) |
Aug
(71) |
Sep
(23) |
Oct
(11) |
Nov
(22) |
Dec
(58) |
| 2025 |
Jan
(26) |
Feb
(40) |
Mar
(107) |
Apr
(39) |
May
(35) |
Jun
(20) |
Jul
(11) |
Aug
(24) |
Sep
(35) |
Oct
(28) |
Nov
|
Dec
|
|
From: <co...@us...> - 2025-03-16 16:20:10
|
Revision: 45533
http://sourceforge.net/p/vice-emu/code/45533
Author: compyx
Date: 2025-03-16 16:20:07 +0000 (Sun, 16 Mar 2025)
Log Message:
-----------
Joystick: SDL: use new API to register devices
Still need to get rid of SDL-specific things like `extern VICE_SDL_JoystickID
*joy_ordinal_to_id` (we store the SDL joystick instance ID in the `priv` member
of the joystick devices now).
Modified Paths:
--------------
branches/compyx/joymap-001/vice/src/arch/sdl/joy.c
Modified: branches/compyx/joymap-001/vice/src/arch/sdl/joy.c
===================================================================
--- branches/compyx/joymap-001/vice/src/arch/sdl/joy.c 2025-03-16 08:19:14 UTC (rev 45532)
+++ branches/compyx/joymap-001/vice/src/arch/sdl/joy.c 2025-03-16 16:20:07 UTC (rev 45533)
@@ -164,17 +164,56 @@
/* ------------------------------------------------------------------------- */
-static void sdl_joystick_poll(int joyport, void* joystick) {}
-static void sdl_joystick_close(void* joystick)
+static bool sdl_joystick_open(int joyport, joystick_device_t *joydev)
{
+ return true;
+}
+
+static void sdl_joystick_poll(int joyport, joystick_device_t *joydev)
+{
+ /* NOP: handled in SDL event loop */
+}
+
+static void sdl_joystick_close(joystick_device_t *joystick)
+{
+#if 0
SDL_JoystickClose(joystick);
lib_free(joy_ordinal_to_id);
joy_ordinal_to_id = NULL;
+#endif
}
+
+typedef struct joy_priv_s {
+ SDL_JoystickGUID guid;
+ SDL_Joystick *sdldev;
+ VICE_SDL_JoystickID id;
+ int joynum;
+} joy_priv_t;
+
+
+static joy_priv_t *joy_priv_new(SDL_Joystick *sdldev, int joynum)
+{
+ joy_priv_t *priv = lib_malloc(sizeof *priv);
+
+ priv->sdldev = sdldev;
+ priv->joynum = joynum;
+ priv->guid = SDL_JoystickGetGUID(sdldev);
+ priv->id = SDL_JoystickInstanceID(sdldev);
+ return priv;
+}
+
+static void joy_priv_free(void *priv)
+{
+ lib_free(priv);
+}
+
+
static joystick_driver_t sdl_joystick_driver = {
- .poll = sdl_joystick_poll,
- .close = sdl_joystick_close
+ .open = sdl_joystick_open,
+ .poll = sdl_joystick_poll,
+ .close = sdl_joystick_close,
+ .priv_free = joy_priv_free
};
#ifdef HAVE_SDL_NUMJOYSTICKS
@@ -182,6 +221,9 @@
/**********************************************************
* Generic high level joy routine *
**********************************************************/
+
+static bool sdljoy_get_devices(void);
+
int joy_sdl_init(void)
{
sdljoy_log = log_open("SDLJoystick");
@@ -191,15 +233,121 @@
return -1;
}
- sdljoy_rescan();
+ joystick_driver_register(&sdl_joystick_driver);
+ sdljoy_get_devices();
+
+
+// sdljoy_rescan();
+
return 0;
}
+static joystick_device_t *scan_device(SDL_Joystick *sdldev, int index)
+{
+ joystick_device_t *joydev = joystick_device_new();
+ joy_priv_t *priv = joy_priv_new(sdldev, index);
+ const char *name;
+ char buffer[64];
+ int i;
+
+ name = SDL_JoystickName(sdldev);
+ if (name != NULL) {
+ joydev->name = lib_strdup(name);
+ } else {
+ log_warning(sdljoy_log,
+ "couldn't retrieve joystick name: %s.", SDL_GetError());
+ joydev->name = lib_msprintf("Joystick_%d", index + 1);
+ }
+ joydev->vendor = SDL_JoystickGetVendor(sdldev);
+ joydev->product = SDL_JoystickGetProduct(sdldev);
+ joydev->priv = priv;
+
+ /* enumerate axes */
+ for (i = 0; i < SDL_JoystickNumAxes(sdldev); i++) {
+ joystick_axis_t *axis;
+
+ snprintf(buffer, sizeof buffer, "Axis_%d", i + 1);
+ axis = joystick_axis_new(buffer);
+ axis->code = i;
+ axis->minimum = SDL_JOYSTICK_AXIS_MIN;
+ axis->maximum = SDL_JOYSTICK_AXIS_MAX;
+ joystick_device_add_axis(joydev, axis);
+ }
+
+ /* enumerate buttons */
+ for (i = 0; i < SDL_JoystickNumButtons(sdldev); i++) {
+ joystick_button_t *button;
+
+ snprintf(buffer, sizeof buffer, "Button_%d", i + 1);
+ button = joystick_button_new(buffer);
+ button->code = i;
+ joystick_device_add_button(joydev, button);
+ }
+
+ /* enumerate hats */
+ for (i = 0; i < SDL_JoystickNumHats(sdldev); i++) {
+ joystick_hat_t *hat;
+
+ snprintf(buffer, sizeof buffer, "Hat_%d", i + 1);
+ hat = joystick_hat_new(buffer);
+ hat->code = i;
+ joystick_device_add_hat(joydev, hat);
+ }
+ return joydev;
+}
+
+static bool sdljoy_get_devices(void)
+{
+ int num;
+ int njoys = SDL_NumJoysticks();
+
+ if (njoys < 0) {
+ log_error(sdljoy_log, "Could not get number of joysticks: %s.", SDL_GetError());
+ return false;
+ } else if (njoys == 0) {
+ log_message(sdljoy_log, "No joysticks found.");
+ return true;
+ }
+
+ log_message(sdljoy_log, "Got %d potential devices.", njoys);
+ for (num = 0; num < njoys; num++) {
+ log_message(sdljoy_log,
+ "SDL_JoystickNameForIndex(%d) = \"%s\"",
+ num, SDL_JoystickNameForIndex(num));
+ }
+ for (num = 0; num < njoys; num++) {
+ SDL_Joystick *sdldev = SDL_JoystickOpen(num);
+
+ if (sdldev == NULL) {
+ log_warning(sdljoy_log, "failed to open device %d: %s", num, SDL_GetError());
+ } else {
+ joystick_device_t *joydev = scan_device(sdldev, num);
+
+ if (joydev != NULL) {
+ joystick_device_register(joydev);
+ }
+#if 0
+ SDL_JoystickClose(sdldev);
+#endif
+ }
+
+ }
+ return true;
+}
+
+
+
+
+
+/* TODO: Get rid of this, use the generic joystick API to obtain the SDL-specific
+ * joystick ID.
+ */
VICE_SDL_JoystickID *joy_ordinal_to_id = NULL;
int sdljoy_rescan(void)
{
+#if 0
int i, axis, button, hat, ball;
SDL_Joystick *joy;
char *name;
@@ -249,6 +397,7 @@
joy_ordinal_to_id[num_valid_joysticks] = -1;
SDL_JoystickEventState(SDL_ENABLE);
+#endif
return 0;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <co...@us...> - 2025-03-16 08:19:26
|
Revision: 45532
http://sourceforge.net/p/vice-emu/code/45532
Author: compyx
Date: 2025-03-16 08:19:14 +0000 (Sun, 16 Mar 2025)
Log Message:
-----------
Hotkeys: add key codes for special multimedia keys
See bug #2132.
Modified Paths:
--------------
trunk/vice/src/arch/shared/hotkeys/vhkkeysyms.h
Modified: trunk/vice/src/arch/shared/hotkeys/vhkkeysyms.h
===================================================================
--- trunk/vice/src/arch/shared/hotkeys/vhkkeysyms.h 2025-03-14 18:26:09 UTC (rev 45531)
+++ trunk/vice/src/arch/shared/hotkeys/vhkkeysyms.h 2025-03-16 08:19:14 UTC (rev 45532)
@@ -358,6 +358,170 @@
#define VHK_KEY_thorn 0x00fe /* U+00FE LATIN SMALL LETTER THORN */
#define VHK_KEY_ydiaeresis 0x00ff /* U+00FF LATIN SMALL LETTER Y WITH DIAERESIS */
+/* Special "multimedia" keys, not present in the X11 header, but present in the
+ * GDk header. See https://sourceforge.net/p/vice-emu/bugs/2132/
+ */
+#define VHK_KEY_ModeLock 0x1008ff01
+#define VHK_KEY_MonBrightnessUp 0x1008ff02
+#define VHK_KEY_MonBrightnessDown 0x1008ff03
+#define VHK_KEY_KbdLightOnOff 0x1008ff04
+#define VHK_KEY_KbdBrightnessUp 0x1008ff05
+#define VHK_KEY_KbdBrightnessDown 0x1008ff06
+#define VHK_KEY_Standby 0x1008ff10
+#define VHK_KEY_AudioLowerVolume 0x1008ff11
+#define VHK_KEY_AudioMute 0x1008ff12
+#define VHK_KEY_AudioRaiseVolume 0x1008ff13
+#define VHK_KEY_AudioPlay 0x1008ff14
+#define VHK_KEY_AudioStop 0x1008ff15
+#define VHK_KEY_AudioPrev 0x1008ff16
+#define VHK_KEY_AudioNext 0x1008ff17
+#define VHK_KEY_HomePage 0x1008ff18
+#define VHK_KEY_Mail 0x1008ff19
+#define VHK_KEY_Start 0x1008ff1a
+#define VHK_KEY_Search 0x1008ff1b
+#define VHK_KEY_AudioRecord 0x1008ff1c
+#define VHK_KEY_Calculator 0x1008ff1d
+#define VHK_KEY_Memo 0x1008ff1e
+#define VHK_KEY_ToDoList 0x1008ff1f
+#define VHK_KEY_Calendar 0x1008ff20
+#define VHK_KEY_PowerDown 0x1008ff21
+#define VHK_KEY_ContrastAdjust 0x1008ff22
+#define VHK_KEY_RockerUp 0x1008ff23
+#define VHK_KEY_RockerDown 0x1008ff24
+#define VHK_KEY_RockerEnter 0x1008ff25
+#define VHK_KEY_Back 0x1008ff26
+#define VHK_KEY_Forward 0x1008ff27
+#define VHK_KEY_Stop 0x1008ff28
+#define VHK_KEY_Refresh 0x1008ff29
+#define VHK_KEY_PowerOff 0x1008ff2a
+#define VHK_KEY_WakeUp 0x1008ff2b
+#define VHK_KEY_Eject 0x1008ff2c
+#define VHK_KEY_ScreenSaver 0x1008ff2d
+#define VHK_KEY_WWW 0x1008ff2e
+#define VHK_KEY_Sleep 0x1008ff2f
+#define VHK_KEY_Favorites 0x1008ff30
+#define VHK_KEY_AudioPause 0x1008ff31
+#define VHK_KEY_AudioMedia 0x1008ff32
+#define VHK_KEY_MyComputer 0x1008ff33
+#define VHK_KEY_VendorHome 0x1008ff34
+#define VHK_KEY_LightBulb 0x1008ff35
+#define VHK_KEY_Shop 0x1008ff36
+#define VHK_KEY_History 0x1008ff37
+#define VHK_KEY_OpenURL 0x1008ff38
+#define VHK_KEY_AddFavorite 0x1008ff39
+#define VHK_KEY_HotLinks 0x1008ff3a
+#define VHK_KEY_BrightnessAdjust 0x1008ff3b
+#define VHK_KEY_Finance 0x1008ff3c
+#define VHK_KEY_Community 0x1008ff3d
+#define VHK_KEY_AudioRewind 0x1008ff3e
+#define VHK_KEY_BackForward 0x1008ff3f
+#define VHK_KEY_Launch0 0x1008ff40
+#define VHK_KEY_Launch1 0x1008ff41
+#define VHK_KEY_Launch2 0x1008ff42
+#define VHK_KEY_Launch3 0x1008ff43
+#define VHK_KEY_Launch4 0x1008ff44
+#define VHK_KEY_Launch5 0x1008ff45
+#define VHK_KEY_Launch6 0x1008ff46
+#define VHK_KEY_Launch7 0x1008ff47
+#define VHK_KEY_Launch8 0x1008ff48
+#define VHK_KEY_Launch9 0x1008ff49
+#define VHK_KEY_LaunchA 0x1008ff4a
+#define VHK_KEY_LaunchB 0x1008ff4b
+#define VHK_KEY_LaunchC 0x1008ff4c
+#define VHK_KEY_LaunchD 0x1008ff4d
+#define VHK_KEY_LaunchE 0x1008ff4e
+#define VHK_KEY_LaunchF 0x1008ff4f
+#define VHK_KEY_ApplicationLeft 0x1008ff50
+#define VHK_KEY_ApplicationRight 0x1008ff51
+#define VHK_KEY_Book 0x1008ff52
+#define VHK_KEY_CD 0x1008ff53
+#define VHK_KEY_WindowClear 0x1008ff55
+#define VHK_KEY_Close 0x1008ff56
+#define VHK_KEY_Copy 0x1008ff57
+#define VHK_KEY_Cut 0x1008ff58
+#define VHK_KEY_Display 0x1008ff59
+#define VHK_KEY_DOS 0x1008ff5a
+#define VHK_KEY_Documents 0x1008ff5b
+#define VHK_KEY_Excel 0x1008ff5c
+#define VHK_KEY_Explorer 0x1008ff5d
+#define VHK_KEY_Game 0x1008ff5e
+#define VHK_KEY_Go 0x1008ff5f
+#define VHK_KEY_iTouch 0x1008ff60
+#define VHK_KEY_LogOff 0x1008ff61
+#define VHK_KEY_Market 0x1008ff62
+#define VHK_KEY_Meeting 0x1008ff63
+#define VHK_KEY_MenuKB 0x1008ff65
+#define VHK_KEY_MenuPB 0x1008ff66
+#define VHK_KEY_MySites 0x1008ff67
+#define VHK_KEY_New 0x1008ff68
+#define VHK_KEY_News 0x1008ff69
+#define VHK_KEY_OfficeHome 0x1008ff6a
+#define VHK_KEY_Open 0x1008ff6b
+#define VHK_KEY_Option 0x1008ff6c
+#define VHK_KEY_Paste 0x1008ff6d
+#define VHK_KEY_Phone 0x1008ff6e
+#define VHK_KEY_Reply 0x1008ff72
+#define VHK_KEY_Reload 0x1008ff73
+#define VHK_KEY_RotateWindows 0x1008ff74
+#define VHK_KEY_RotationPB 0x1008ff75
+#define VHK_KEY_RotationKB 0x1008ff76
+#define VHK_KEY_Save 0x1008ff77
+#define VHK_KEY_ScrollUp 0x1008ff78
+#define VHK_KEY_ScrollDown 0x1008ff79
+#define VHK_KEY_ScrollClick 0x1008ff7a
+#define VHK_KEY_Send 0x1008ff7b
+#define VHK_KEY_Spell 0x1008ff7c
+#define VHK_KEY_SplitScreen 0x1008ff7d
+#define VHK_KEY_Support 0x1008ff7e
+#define VHK_KEY_TaskPane 0x1008ff7f
+#define VHK_KEY_Terminal 0x1008ff80
+#define VHK_KEY_Tools 0x1008ff81
+#define VHK_KEY_Travel 0x1008ff82
+#define VHK_KEY_UserPB 0x1008ff84
+#define VHK_KEY_User1KB 0x1008ff85
+#define VHK_KEY_User2KB 0x1008ff86
+#define VHK_KEY_Video 0x1008ff87
+#define VHK_KEY_WheelButton 0x1008ff88
+#define VHK_KEY_Word 0x1008ff89
+#define VHK_KEY_Xfer 0x1008ff8a
+#define VHK_KEY_ZoomIn 0x1008ff8b
+#define VHK_KEY_ZoomOut 0x1008ff8c
+#define VHK_KEY_Away 0x1008ff8d
+#define VHK_KEY_Messenger 0x1008ff8e
+#define VHK_KEY_WebCam 0x1008ff8f
+#define VHK_KEY_MailForward 0x1008ff90
+#define VHK_KEY_Pictures 0x1008ff91
+#define VHK_KEY_Music 0x1008ff92
+#define VHK_KEY_Battery 0x1008ff93
+#define VHK_KEY_Bluetooth 0x1008ff94
+#define VHK_KEY_WLAN 0x1008ff95
+#define VHK_KEY_UWB 0x1008ff96
+#define VHK_KEY_AudioForward 0x1008ff97
+#define VHK_KEY_AudioRepeat 0x1008ff98
+#define VHK_KEY_AudioRandomPlay 0x1008ff99
+#define VHK_KEY_Subtitle 0x1008ff9a
+#define VHK_KEY_AudioCycleTrack 0x1008ff9b
+#define VHK_KEY_CycleAngle 0x1008ff9c
+#define VHK_KEY_FrameBack 0x1008ff9d
+#define VHK_KEY_FrameForward 0x1008ff9e
+#define VHK_KEY_Time 0x1008ff9f
+#define VHK_KEY_SelectButton 0x1008ffa0
+#define VHK_KEY_View 0x1008ffa1
+#define VHK_KEY_TopMenu 0x1008ffa2
+#define VHK_KEY_Red 0x1008ffa3
+#define VHK_KEY_Green 0x1008ffa4
+#define VHK_KEY_Yellow 0x1008ffa5
+#define VHK_KEY_Blue 0x1008ffa6
+#define VHK_KEY_Suspend 0x1008ffa7
+#define VHK_KEY_Hibernate 0x1008ffa8
+#define VHK_KEY_TouchpadToggle 0x1008ffa9
+#define VHK_KEY_TouchpadOn 0x1008ffb0
+#define VHK_KEY_TouchpadOff 0x1008ffb1
+#define VHK_KEY_AudioMicMute 0x1008ffb2
+#define VHK_KEY_Keyboard 0x1008ffb3
+#define VHK_KEY_WWAN 0x1008ffb4
+#define VHK_KEY_RFKill 0x1008ffb5
+#define VHK_KEY_AudioPreset 0x1008ffb6
/* Key modifier masks */
#define VHK_MOD_NONE 0x0000
#define VHK_MOD_ALT 0x0001
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <co...@us...> - 2025-03-14 18:26:21
|
Revision: 45531
http://sourceforge.net/p/vice-emu/code/45531
Author: compyx
Date: 2025-03-14 18:26:09 +0000 (Fri, 14 Mar 2025)
Log Message:
-----------
Joystick: fix shared joystick code which is mysteriously SDL-only
Fix code in `src/joyport/joystick.c` to use the updated data structures. The
code is guarded by `#ifdef HAVE_SDL_NUMJOYSTICKS` for unknown (undocumented)
reasons. SDL's driver in `src/arch/sdl/joy.c` will be fixed next.
Modified Paths:
--------------
branches/compyx/joymap-001/vice/src/joyport/joystick.c
Modified: branches/compyx/joymap-001/vice/src/joyport/joystick.c
===================================================================
--- branches/compyx/joymap-001/vice/src/joyport/joystick.c 2025-03-14 12:03:50 UTC (rev 45530)
+++ branches/compyx/joymap-001/vice/src/joyport/joystick.c 2025-03-14 18:26:09 UTC (rev 45531)
@@ -1203,49 +1203,56 @@
#if (defined USE_SDLUI ||defined USE_SDL2UI)
void joy_delete_extra_mapping(int type)
{
- int i, j;
- joystick_action_t t;
+ int i;
for (i = 0; i < num_joystick_devices; i++) {
- for (j = 0; j < joystick_devices[i]->num_axes; j++) {
- t = joystick_devices[i]->axis_mapping[j].positive_direction.action;
- if (t == (type ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
- joystick_devices[i]->axis_mapping[j].positive_direction.action = JOY_ACTION_NONE;
- joystick_devices[i]->axis_mapping[j].positive_direction.value.ui_action = ACTION_NONE;
+ joystick_device_t *joydev = joystick_devices[i];
+ int j;
+
+ for (j = 0; j < joydev->num_axes; j++) {
+ joystick_mapping_t *positive = &joydev->axes[j]->mapping.positive;
+ joystick_mapping_t *negative = &joydev->axes[j]->mapping.negative;
+
+ if (positive->action == (type ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
+ positive->action = JOY_ACTION_NONE;
+ positive->value.ui_action = ACTION_NONE;
}
- t = joystick_devices[i]->axis_mapping[j].negative_direction.action;
- if (t == (type ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
- joystick_devices[i]->axis_mapping[j].negative_direction.action = JOY_ACTION_NONE;
- joystick_devices[i]->axis_mapping[j].negative_direction.value.ui_action = ACTION_NONE;
+ if (negative->action == (type ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
+ negative->action = JOY_ACTION_NONE;
+ negative->value.ui_action = ACTION_NONE;
}
}
- for (j = 0; j < joystick_devices[i]->num_buttons; j++) {
- t = joystick_devices[i]->button_mapping[j].mapping.action;
- if (t == (type ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
- joystick_devices[i]->button_mapping[j].mapping.action = JOY_ACTION_NONE;
- joystick_devices[i]->button_mapping[j].mapping.value.ui_action = ACTION_NONE;
+
+ for (j = 0; j < joydev->num_buttons; j++) {
+ joystick_mapping_t *mapping = &joydev->buttons[j]->mapping;
+
+ if (mapping->action == (type ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
+ mapping->action = JOY_ACTION_NONE;
+ mapping->value.ui_action = ACTION_NONE;
}
}
+
for (j = 0; j < joystick_devices[i]->num_hats; j++) {
- t = joystick_devices[i]->hat_mapping[j].up.action;
- if (t == (type ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
- joystick_devices[i]->hat_mapping[j].up.action = JOY_ACTION_NONE;
- joystick_devices[i]->hat_mapping[j].up.value.ui_action = ACTION_NONE;
+ joystick_mapping_t *up = &joydev->hats[j]->mapping.up;
+ joystick_mapping_t *down = &joydev->hats[j]->mapping.down;
+ joystick_mapping_t *left = &joydev->hats[j]->mapping.left;
+ joystick_mapping_t *right = &joydev->hats[j]->mapping.right;
+
+ if (up->action == (type ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
+ up->action = JOY_ACTION_NONE;
+ up->value.ui_action = ACTION_NONE;
}
- t = joystick_devices[i]->hat_mapping[j].down.action;
- if (t == (type ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
- joystick_devices[i]->hat_mapping[j].down.action = JOY_ACTION_NONE;
- joystick_devices[i]->hat_mapping[j].down.value.ui_action = ACTION_NONE;
+ if (down->action == (type ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
+ down->action = JOY_ACTION_NONE;
+ down->value.ui_action = ACTION_NONE;
}
- t = joystick_devices[i].hat_mapping[j].left.action;
- if (t == (type ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
- joystick_devices[i]->hat_mapping[j].left.action = JOY_ACTION_NONE;
- joystick_devices[i]->hat_mapping[j].left.value.ui_action = ACTION_NONE;
+ if (left->action == (type ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
+ left->action = JOY_ACTION_NONE;
+ left->value.ui_action = ACTION_NONE;
}
- t = joystick_devices[i]->hat_mapping[j].right.action;
- if (t == (type ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
- joystick_devices[i]->hat_mapping[j].right.action = JOY_ACTION_NONE;
- joystick_devices[i]->hat_mapping[j].right.value.ui_action = ACTION_NONE;
+ if (right->action == (type ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
+ right->action = JOY_ACTION_NONE;
+ right->value.ui_action = ACTION_NONE;
}
}
}
@@ -3096,7 +3103,7 @@
#ifdef HAVE_SDL_NUMJOYSTICKS
joystick_axis_value_t joy_axis_prev(uint8_t joynum, uint8_t axis)
{
- return joystick_devices[joynum].axis_mapping[axis].prev;
+ return joystick_devices[joynum]->axes[axis]->prev;
}
joystick_mapping_t *joy_get_axis_mapping(uint8_t joynum,
@@ -3105,10 +3112,10 @@
joystick_axis_value_t *prev)
{
joystick_mapping_t *retval = joy_get_axis_mapping_not_setting_value(
- joynum, axis, joystick_devices[joynum].axis_mapping[axis].prev);
+ joynum, axis, joystick_devices[joynum]->axes[axis]->prev);
if (prev)
- *prev = joystick_devices[joynum].axis_mapping[axis].prev;
- joystick_devices[joynum].axis_mapping[axis].prev = value;
+ *prev = joystick_devices[joynum]->axes[axis]->prev;
+ joystick_devices[joynum]->axes[axis]->prev = value;
return retval;
}
@@ -3117,10 +3124,10 @@
joystick_axis_value_t value)
{
if (value == JOY_AXIS_POSITIVE) {
- return &joystick_devices[joynum].axis_mapping[axis].positive_direction;
+ return &joystick_devices[joynum]->axes[axis]->mapping.positive;
}
if (value == JOY_AXIS_NEGATIVE) {
- return &joystick_devices[joynum].axis_mapping[axis].negative_direction;
+ return &joystick_devices[joynum]->axes[axis]->mapping.negative;
}
return NULL;
}
@@ -3131,10 +3138,10 @@
uint8_t *prev)
{
joystick_mapping_t *retval = joy_get_button_mapping_not_setting_value(
- joynum, button, joystick_devices[joynum].button_mapping[button].prev);
+ joynum, button, joystick_devices[joynum]->buttons[button]->prev);
if (prev)
- *prev = joystick_devices[joynum].button_mapping[button].prev;
- joystick_devices[joynum].button_mapping[button].prev = value;
+ *prev = joystick_devices[joynum]->buttons[button]->prev;
+ joystick_devices[joynum]->buttons[button]->prev = value;
return retval;
}
@@ -3143,12 +3150,13 @@
uint8_t value)
{
if (value)
- return &joystick_devices[joynum].button_mapping[button].mapping;
+ return &joystick_devices[joynum]->buttons[button]->mapping;
return NULL;
}
-joystick_axis_value_t joy_hat_prev(uint8_t joynum, uint8_t hat) {
- return joystick_devices[joynum].hat_mapping[hat].prev;
+joystick_axis_value_t joy_hat_prev(uint8_t joynum, uint8_t hat)
+{
+ return joystick_devices[joynum]->hats[hat]->prev;
}
joystick_mapping_t *joy_get_hat_mapping(uint8_t joynum,
@@ -3157,26 +3165,28 @@
uint8_t *prev)
{
joystick_mapping_t *retval = joy_get_hat_mapping_not_setting_value(
- joynum, hat, joystick_devices[joynum].hat_mapping[hat].prev);
+ joynum, hat, joystick_devices[joynum]->hats[hat]->prev);
if (prev)
- *prev = joystick_devices[joynum].hat_mapping[hat].prev;
- joystick_devices[joynum].hat_mapping[hat].prev = value;
+ *prev = joystick_devices[joynum]->hats[hat]->prev;
+ joystick_devices[joynum]->hats[hat]->prev = value;
return retval;
}
joystick_mapping_t *joy_get_hat_mapping_not_setting_value(uint8_t joynum,
uint8_t hat,
- uint8_t value) {
+ uint8_t value)
+{
+ joystick_device_t *joydev = joystick_devices[joynum];
joystick_mapping_t *mapping = NULL;
if (value & JOYSTICK_DIRECTION_UP) {
- mapping = &joystick_devices[joynum].hat_mapping[hat].up;
+ mapping = &joydev->hats[hat]->mapping.up;
} else if (value & JOYSTICK_DIRECTION_DOWN) {
- mapping = &joystick_devices[joynum].hat_mapping[hat].down;
+ mapping = &joydev->hats[hat]->mapping.down;
} else if (value & JOYSTICK_DIRECTION_LEFT) {
- mapping = &joystick_devices[joynum].hat_mapping[hat].left;
+ mapping = &joydev->hats[hat]->mapping.left;
} else if (value & JOYSTICK_DIRECTION_RIGHT) {
- mapping = &joystick_devices[joynum].hat_mapping[hat].right;
+ mapping = &joydev->hats[hat]->mapping.right;
}
return mapping;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <co...@us...> - 2025-03-14 12:04:05
|
Revision: 45530
http://sourceforge.net/p/vice-emu/code/45530
Author: compyx
Date: 2025-03-14 12:03:50 +0000 (Fri, 14 Mar 2025)
Log Message:
-----------
Merge trunk (r45512:HEAD) into branch
Modified Paths:
--------------
branches/compyx/joymap-001/vice/src/arch/gtk3/actions-clipboard.c
branches/compyx/joymap-001/vice/src/arch/sdl/menu_joystick.c
branches/compyx/joymap-001/vice/src/diskconstants.h
branches/compyx/joymap-001/vice/src/diskimage/fsimage-dxx.c
branches/compyx/joymap-001/vice/src/monitor/mon_memory.c
branches/compyx/joymap-001/vice/src/resid/filter8580new.h
branches/compyx/joymap-001/vice/src/vdrive/vdrive.c
Modified: branches/compyx/joymap-001/vice/src/arch/gtk3/actions-clipboard.c
===================================================================
--- branches/compyx/joymap-001/vice/src/arch/gtk3/actions-clipboard.c 2025-03-14 11:49:58 UTC (rev 45529)
+++ branches/compyx/joymap-001/vice/src/arch/gtk3/actions-clipboard.c 2025-03-14 12:03:50 UTC (rev 45530)
@@ -80,6 +80,7 @@
tmp,
(gint)len);
lib_free(tmp);
+ lib_free(text);
}
}
Modified: branches/compyx/joymap-001/vice/src/arch/sdl/menu_joystick.c
===================================================================
--- branches/compyx/joymap-001/vice/src/arch/sdl/menu_joystick.c 2025-03-14 11:49:58 UTC (rev 45529)
+++ branches/compyx/joymap-001/vice/src/arch/sdl/menu_joystick.c 2025-03-14 12:03:50 UTC (rev 45530)
@@ -59,7 +59,9 @@
UI_MENU_DEFINE_RADIO(JoyDevice10)
UI_MENU_DEFINE_RADIO(JoyDevice11)
-static ui_menu_entry_t joystick_device_dyn_menu[JOYPORT_MAX_PORTS][6];
+/* FIXME: proper solution would be to dynamically allocate the array of menu
+ * items per port, for now we stick with max. 16 controllers */
+static ui_menu_entry_t joystick_device_dyn_menu[JOYPORT_MAX_PORTS][5 + 16];
static int joystick_device_dyn_menu_init[JOYPORT_MAX_PORTS] = { 0 };
static void sdl_menu_joystick_device_free(int port)
@@ -135,7 +137,7 @@
#ifdef HAVE_SDL_NUMJOYSTICKS
n = 0;
joystick_ui_reset_device_list();
- while (j < JOYPORT_MAX_PORTS - 1 && (device_name = joystick_ui_get_next_device_name(&id)) != NULL) {
+ while (n < 16 && (device_name = joystick_ui_get_next_device_name(&id)) != NULL) {
entry[j].action = ACTION_NONE;
entry[j].string = lib_strdup(device_name);
entry[j].type = MENU_ENTRY_RESOURCE_RADIO;
Modified: branches/compyx/joymap-001/vice/src/diskconstants.h
===================================================================
--- branches/compyx/joymap-001/vice/src/diskconstants.h 2025-03-14 11:49:58 UTC (rev 45529)
+++ branches/compyx/joymap-001/vice/src/diskconstants.h 2025-03-14 12:03:50 UTC (rev 45530)
@@ -146,8 +146,8 @@
#define HDR_SECTOR_8050 0 /* block w/disk name */
#define BAM_TRACK_8050 38
#define BAM_SECTOR_8050 0
-#define BAM_NAME_8050 6 /* pos. of disk name in header blk */
-#define BAM_ID_8050 24 /* pos. of disk id in header blk */
+#define HDR_NAME_8050 6 /* pos. of disk name in header blk */
+#define HDR_ID_8050 24 /* pos. of disk id in header blk */
#define DIR_TRACK_8050 39
#define DIR_SECTOR_8050 1
@@ -159,8 +159,8 @@
#define HDR_SECTOR_8250 HDR_SECTOR_8050
#define BAM_TRACK_8250 BAM_TRACK_8050
#define BAM_SECTOR_8250 BAM_SECTOR_8050
-#define BAM_NAME_8250 BAM_NAME_8050 /* pos. of disk name in hdr blk */
-#define BAM_ID_8250 BAM_ID_8050 /* pos. of disk id in hdr blk */
+#define HDR_NAME_8250 HDR_NAME_8050 /* pos. of disk name in hdr blk */
+#define HDR_ID_8250 HDR_ID_8050 /* pos. of disk id in hdr blk */
#define DIR_TRACK_8250 DIR_TRACK_8050
#define DIR_SECTOR_8250 DIR_SECTOR_8050
Modified: branches/compyx/joymap-001/vice/src/diskimage/fsimage-dxx.c
===================================================================
--- branches/compyx/joymap-001/vice/src/diskimage/fsimage-dxx.c 2025-03-14 11:49:58 UTC (rev 45529)
+++ branches/compyx/joymap-001/vice/src/diskimage/fsimage-dxx.c 2025-03-14 12:03:50 UTC (rev 45530)
@@ -166,8 +166,8 @@
if (image->type == DISK_IMAGE_TYPE_D80
|| image->type == DISK_IMAGE_TYPE_D82) {
- sectors = disk_image_check_sector(image, BAM_TRACK_8050, BAM_SECTOR_8050);
- bam_id = &buffer[BAM_ID_8050];
+ sectors = disk_image_check_sector(image, HDR_TRACK_8050, HDR_SECTOR_8050);
+ bam_id = &buffer[HDR_ID_8050];
} else {
sectors = disk_image_check_sector(image, BAM_TRACK_1541, BAM_SECTOR_1541);
bam_id = &buffer[BAM_ID_1541];
Modified: branches/compyx/joymap-001/vice/src/monitor/mon_memory.c
===================================================================
--- branches/compyx/joymap-001/vice/src/monitor/mon_memory.c 2025-03-14 11:49:58 UTC (rev 45529)
+++ branches/compyx/joymap-001/vice/src/monitor/mon_memory.c 2025-03-14 12:03:50 UTC (rev 45530)
@@ -282,7 +282,16 @@
int bank;
mem_get_screen_parameter(&base, &rows, &screen_width, &bank);
+ /* HACK: mem_get_screen_parameter() returns actual screen size from the
+ video chip registers - this can be zero rows or zero columns! If
+ width is 0, use last known terminal width instead, to avoid division
+ by 0 further below. */
+ if (screen_width == 0) {
+ screen_width = last_known_xres;
+ }
+
max_width = screen_width;
+
if (max_width > (last_known_xres - (7 + 2))) {
max_width = (last_known_xres - (7 + 2));
/* to make the output easier to read, make sure the number of items
Modified: branches/compyx/joymap-001/vice/src/resid/filter8580new.h
===================================================================
--- branches/compyx/joymap-001/vice/src/resid/filter8580new.h 2025-03-14 11:49:58 UTC (rev 45529)
+++ branches/compyx/joymap-001/vice/src/resid/filter8580new.h 2025-03-14 12:03:50 UTC (rev 45530)
@@ -23,6 +23,7 @@
#include "resid-config.h"
#include <cassert>
+#include <cstdlib>
namespace reSID
{
@@ -648,6 +649,23 @@
static model_filter_t model_filter[2];
friend class SID;
+
+private:
+ class Randomnoise
+ {
+ private:
+ int buffer[1024];
+ mutable int index = 0;
+ public:
+ Randomnoise()
+ {
+ for (int i=0; i<1024; i++)
+ buffer[i] = rand() % (1<<19);
+ }
+ int getNoise() const { index = (index + 1) & 0x3ff; return buffer[index]; }
+ };
+
+ Randomnoise rnd;
};
@@ -667,9 +685,9 @@
{
model_filter_t& f = model_filter[sid_model];
- v1 = (voice1*f.voice_scale_s14 >> 18) + f.voice_DC;
- v2 = (voice2*f.voice_scale_s14 >> 18) + f.voice_DC;
- v3 = (voice3*f.voice_scale_s14 >> 18) + f.voice_DC;
+ v1 = ((voice1*f.voice_scale_s14 + rnd.getNoise()) >> 18) + f.voice_DC;
+ v2 = ((voice2*f.voice_scale_s14 + rnd.getNoise()) >> 18) + f.voice_DC;
+ v3 = ((voice3*f.voice_scale_s14 + rnd.getNoise()) >> 18) + f.voice_DC;
// Sum inputs routed into the filter.
int Vi = 0;
@@ -768,9 +786,9 @@
{
model_filter_t& f = model_filter[sid_model];
- v1 = (voice1*f.voice_scale_s14 >> 18) + f.voice_DC;
- v2 = (voice2*f.voice_scale_s14 >> 18) + f.voice_DC;
- v3 = (voice3*f.voice_scale_s14 >> 18) + f.voice_DC;
+ v1 = ((voice1*f.voice_scale_s14 + rnd.getNoise()) >> 18) + f.voice_DC;
+ v2 = ((voice2*f.voice_scale_s14 + rnd.getNoise()) >> 18) + f.voice_DC;
+ v3 = ((voice3*f.voice_scale_s14 + rnd.getNoise()) >> 18) + f.voice_DC;
// Enable filter on/off.
// This is not really part of SID, but is useful for testing.
Modified: branches/compyx/joymap-001/vice/src/vdrive/vdrive.c
===================================================================
--- branches/compyx/joymap-001/vice/src/vdrive/vdrive.c 2025-03-14 11:49:58 UTC (rev 45529)
+++ branches/compyx/joymap-001/vice/src/vdrive/vdrive.c 2025-03-14 12:03:50 UTC (rev 45530)
@@ -650,8 +650,8 @@
vdrive->Bam_Sector = BAM_SECTOR_8050;
vdrive->Header_Track = HDR_TRACK_8050;
vdrive->Header_Sector = HDR_SECTOR_8050;
- vdrive->bam_name = BAM_NAME_8050;
- vdrive->bam_id = BAM_ID_8050;
+ vdrive->bam_name = HDR_NAME_8050;
+ vdrive->bam_id = HDR_ID_8050;
vdrive->Dir_Track = DIR_TRACK_8050;
vdrive->Dir_Sector = DIR_SECTOR_8050;
break;
@@ -660,8 +660,8 @@
vdrive->Bam_Sector = BAM_SECTOR_8250;
vdrive->Header_Track = HDR_TRACK_8250;
vdrive->Header_Sector = HDR_SECTOR_8250;
- vdrive->bam_name = BAM_NAME_8250;
- vdrive->bam_id = BAM_ID_8250;
+ vdrive->bam_name = HDR_NAME_8250;
+ vdrive->bam_id = HDR_ID_8250;
vdrive->Dir_Track = DIR_TRACK_8250;
vdrive->Dir_Sector = DIR_SECTOR_8250;
break;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <co...@us...> - 2025-03-14 11:50:10
|
Revision: 45529
http://sourceforge.net/p/vice-emu/code/45529
Author: compyx
Date: 2025-03-14 11:49:58 +0000 (Fri, 14 Mar 2025)
Log Message:
-----------
SDL: "Fix" overflow of controller list in joystick menu
See bug #2092.
Modified Paths:
--------------
trunk/vice/src/arch/sdl/menu_joystick.c
Modified: trunk/vice/src/arch/sdl/menu_joystick.c
===================================================================
--- trunk/vice/src/arch/sdl/menu_joystick.c 2025-03-13 14:33:32 UTC (rev 45528)
+++ trunk/vice/src/arch/sdl/menu_joystick.c 2025-03-14 11:49:58 UTC (rev 45529)
@@ -59,7 +59,9 @@
UI_MENU_DEFINE_RADIO(JoyDevice10)
UI_MENU_DEFINE_RADIO(JoyDevice11)
-static ui_menu_entry_t joystick_device_dyn_menu[JOYPORT_MAX_PORTS][6];
+/* FIXME: proper solution would be to dynamically allocate the array of menu
+ * items per port, for now we stick with max. 16 controllers */
+static ui_menu_entry_t joystick_device_dyn_menu[JOYPORT_MAX_PORTS][5 + 16];
static int joystick_device_dyn_menu_init[JOYPORT_MAX_PORTS] = { 0 };
static void sdl_menu_joystick_device_free(int port)
@@ -135,7 +137,7 @@
#ifdef HAVE_SDL_NUMJOYSTICKS
n = 0;
joystick_ui_reset_device_list();
- while (j < JOYPORT_MAX_PORTS - 1 && (device_name = joystick_ui_get_next_device_name(&id)) != NULL) {
+ while (n < 16 && (device_name = joystick_ui_get_next_device_name(&id)) != NULL) {
entry[j].action = ACTION_NONE;
entry[j].string = lib_strdup(device_name);
entry[j].type = MENU_ENTRY_RESOURCE_RADIO;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <co...@us...> - 2025-03-13 14:33:39
|
Revision: 45528
http://sourceforge.net/p/vice-emu/code/45528
Author: compyx
Date: 2025-03-13 14:33:32 +0000 (Thu, 13 Mar 2025)
Log Message:
-----------
Joystick: log joystick registation with proper signular/plural nouns
Avoid things like "1 buttons", right-trim device names and limit names of
idiotic length (>255 chars) so the UI doesn't have to trim names.
Modified Paths:
--------------
branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_linux_evdev.c
branches/compyx/joymap-001/vice/src/joyport/joystick.c
Modified: branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_linux_evdev.c
===================================================================
--- branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_linux_evdev.c 2025-03-13 08:34:04 UTC (rev 45527)
+++ branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_linux_evdev.c 2025-03-13 14:33:32 UTC (rev 45528)
@@ -422,21 +422,21 @@
for (i = 0; i < sd_result; i++) {
joystick_device_t *joydev;
- log_message(joy_evdev_log, "Possible device '%s'", namelist[i]->d_name);
+ //log_message(joy_evdev_log, "Possible device '%s'", namelist[i]->d_name);
joydev = scan_device(namelist[i]->d_name);
if (joydev != NULL) {
if (joydev->num_axes < 2u || joydev->num_buttons < 1u) {
/* reject device */
- log_message(joy_evdev_log,
- "Invalid geometry for %s: axes: %d, buttons: %d",
- joydev->name, joydev->num_axes, joydev->num_buttons);
+ //log_message(joy_evdev_log,
+ // "Invalid geometry for %s: axes: %d, buttons: %d",
+ // joydev->name, joydev->num_axes, joydev->num_buttons);
joystick_device_free(joydev);
} else {
- log_message(joy_evdev_log,
- "Adding device: %s [%04x:%04x] (%d axes, %d buttons)",
- joydev->name,
- (unsigned int)joydev->vendor, (unsigned int)joydev->product,
- joydev->num_axes, joydev->num_buttons);
+ //log_message(joy_evdev_log,
+ // "Adding device: %s [%04x:%04x] (%d axes, %d buttons)",
+ // joydev->name,
+ // (unsigned int)joydev->vendor, (unsigned int)joydev->product,
+ // joydev->num_axes, joydev->num_buttons);
if (!joystick_device_register(joydev)) {
log_message(joy_evdev_log,
Modified: branches/compyx/joymap-001/vice/src/joyport/joystick.c
===================================================================
--- branches/compyx/joymap-001/vice/src/joyport/joystick.c 2025-03-13 08:34:04 UTC (rev 45527)
+++ branches/compyx/joymap-001/vice/src/joyport/joystick.c 2025-03-13 14:33:32 UTC (rev 45528)
@@ -3309,6 +3309,26 @@
}
+/** \brief Right-trim name and limit to 255 chars max
+ *
+ * Right-trim name (at least one device reports a name with trailing spaces on
+ * Linux) and limit length to 255 characters to avoid bizarre behaviour in UIs.
+ *
+ * \param[in] joydev joystick device
+ */
+static void joystick_device_trim_name(joystick_device_t *joydev)
+{
+ char *p = joydev->name + strlen(joydev->name) - 1;
+
+ while (p >= joydev->name && isspace((unsigned int)*p)) {
+ *p-- = '\0';
+ }
+ /* limit name to 255 max to guard against weird broken names */
+ if (p - joydev->name + 1 > 255) {
+ joydev->name[255] = '\0';
+ }
+}
+
/** \brief Apply default minimal mapping to joystick device
*
* Map input for four directions and up to three fire buttons. If the device
@@ -3393,7 +3413,48 @@
return true;
}
+/** \brief Log registration of device
+ *
+ * Log message with proper singular/plural nouns for number of axes, buttons
+ * and hats.
+ *
+ * \param[in] joydev joystick device
+ */
+static void joy_log_registration(const joystick_device_t *joydev)
+{
+ char msg[1024];
+ int ret;
+ ret = snprintf(msg, sizeof msg,
+ "Registered device \"%s\" [%04x:%04x] (",
+ joydev->name, joydev->vendor, joydev->product);
+ if (joydev->num_axes == 1) {
+ strcpy(msg + ret, "1 axis, ");
+ ret += 8;
+ } else {
+ ret += snprintf(msg + ret, sizeof msg - (size_t)ret,
+ "%d axes, ", joydev->num_axes);
+ }
+
+ if (joydev->num_buttons == 1) {
+ strcpy(msg + ret, "1 button, ");
+ ret += 10;
+ } else {
+ ret += snprintf(msg + ret, sizeof msg - (size_t)ret,
+ "%d buttons, ", joydev->num_buttons);
+ }
+
+ if (joydev->num_hats == 1) {
+ strcpy(msg + ret, "1 hat)");
+ } else {
+ snprintf(msg + ret, sizeof msg - (size_t) ret,
+ "%d hats)", joydev->num_hats);
+ }
+
+ log_message(joy_log, "%s", msg);
+}
+
+
/** \brief Register joystick device
*
* Add \a joydev to the list of available joystick devices.
@@ -3419,11 +3480,14 @@
sizeof *joystick_devices * max_joystick_devices);
}
+ joystick_device_trim_name(joydev);
joystick_device_apply_default_mapping(joydev);
joystick_devices[num_joystick_devices] = joydev;
joystick_devices[++num_joystick_devices] = NULL;
+ /* log device registration */
+ joy_log_registration(joydev);
return true;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <co...@us...> - 2025-03-13 08:34:15
|
Revision: 45527
http://sourceforge.net/p/vice-emu/code/45527
Author: compyx
Date: 2025-03-13 08:34:04 +0000 (Thu, 13 Mar 2025)
Log Message:
-----------
Joystick: BSD: clean up ordered inputs code, properly document said code
Modified Paths:
--------------
branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_bsd.c
Modified: branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_bsd.c
===================================================================
--- branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_bsd.c 2025-03-12 20:52:19 UTC (rev 45526)
+++ branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_bsd.c 2025-03-13 08:34:04 UTC (rev 45527)
@@ -92,22 +92,57 @@
int fd;
} joy_priv_t;
+/** \brief Function to free data in a input node list
+ *
+ * Function to call on the \c data member of an #input_node_t if #input_list_free()
+ * is called with \c with_data set to <tt>true</tt>.
+ * This typedef allows us to cast #joystick_axis_free(). #joystick_button_free()
+ * and #joystick_hat_free() to the type expected by #input_list_init(), avoiding
+ * wrapper functions.
+ */
+typedef void (*data_free_t)(void*);
+/** \brief Node in an ordered linked list of inputs
+ */
typedef struct input_node_s {
- struct input_node_s *next;
- void *data;
+ struct input_node_s *next; /**< next node */
+ void *data; /**< data (axis/button/hat object pointer) */
} input_node_t;
+/** \brief Ordered list of inputs
+ */
typedef struct input_list_s {
- input_node_t *head;
- void (*data_free)(void *);
- int (*data_comp)(void *, void *);
+ /** \brief Head node */
+ input_node_t *head;
+
+ /** \brief Function to call to free the data of a node
+ *
+ * This function is called on the \c data member of a node if #input_list_free()
+ * is called with its \c with_data argument set to <tt>true</tt>. This
+ * allows cleaning up the list and its data when an error occurs during
+ * scanning.
+ */
+ void (*data_free)(void *);
+
+ /** \brief Comparison function for ordered insertion
+ *
+ * Return 0 when the codes of both arguments are equal, return < 0 when
+ * \c arg1->code < \c arg2->code, return > 0 when \c arg1->code
+ * > \c arg2->code.
+ */
+ int (*data_comp)(const void *, const void *);
} input_list_t;
+/** \brief Initialize ordered input list
+ *
+ * \param[in] list input list
+ * \param[in] data_free function to free the \c data member of the list nodes
+ * \param[in] data_comp function to compare two \c data members
+ */
static void input_list_init(input_list_t *list,
void (*data_free)(void *),
- int (*data_comp)(void *, void *))
+ int (*data_comp)(const void *, const void *))
{
list->head = NULL;
list->data_free = data_free;
@@ -114,6 +149,13 @@
list->data_comp = data_comp;
}
+/** \brief Free input list
+ *
+ * Free input list node and optionally free each node's \c data member.
+ *
+ * \param[in] list input list
+ * \param[in] with_data also free the \c data member of each node
+ */
static void input_list_free(input_list_t *list, bool with_data)
{
input_node_t *node = list->head;
@@ -128,6 +170,17 @@
list->head = NULL;
}
+/** \brief Insert data into input list in-order
+ *
+ * Insert \a data into \a list, using the \c data_comp function specified in
+ * #input_list_init() to determine its location in the list.
+ *
+ * \param[in] list input list
+ * \param[in] data input object to insert into \a list
+ *
+ * \return <tt>true</tt> on success, <tt>false</tt> if an input with the same
+ * code is already present (which should not happen)
+ */
static bool input_list_insert(input_list_t *list, void *data)
{
input_node_t *node = lib_malloc(sizeof *node);
@@ -182,10 +235,16 @@
/** \brief Log for BSD joystick driver */
static log_t bsd_joy_log;
+/** \brief Temporary ordered list of axes */
static input_list_t axis_list;
+
+/** \brief Temporary ordered list of buttons */
static input_list_t button_list;
+
+/** \brief Temporary ordered list of hats */
static input_list_t hat_list;
+
/** \brief BSD joystick driver declaration */
static joystick_driver_t driver = {
.open = bsd_joy_open,
@@ -500,7 +559,7 @@
axis->maximum = item->logical_maximum;
log_message(bsd_joy_log, "axis %u: %s", axis->code, axis->name);
- joystick_device_add_axis(joydev, axis);
+ input_list_insert(&axis_list, axis);
}
/** \brief Add button to joystick device
@@ -515,10 +574,9 @@
button = joystick_button_new(hid_usage_in_page(item->usage));
button->code = (uint32_t)HID_USAGE(item->usage);
+
log_message(bsd_joy_log, "button %u: %s", button->code, button->name);
-
input_list_insert(&button_list, button);
-// joystick_device_add_button(joydev, button);
}
/** \brief Add hat to joystick device
@@ -533,8 +591,9 @@
hat = joystick_hat_new(hid_usage_in_page(item->usage));
hat->code = (uint32_t)HID_USAGE(item->usage);
+
log_message(bsd_joy_log, "hat %u: %s", hat->code, hat->name);
- joystick_device_add_hat(joydev, hat);
+ input_list_insert(&hat_list, hat);
}
/** \brief Scan device for inputs
@@ -608,9 +667,6 @@
*
* \param[in] node device node to scan
*
- * \todo Order axes, buttons and hats by HID_USAGE() (event code), otherwise
- * our default mappings fail spectacularly =D
- *
* \return new joystick device instance or <tt>NULL</tt> on error
*/
static joystick_device_t *scan_device(const char *node)
@@ -650,11 +706,19 @@
return joydev;
}
-
-static int axis_comp(void *a1, void *a2)
+/** \brief Ordered list comparison callback for axes
+ *
+ * Compare code of axis \a a1 with code of axis \a a2.
+ *
+ * \param[in] a1 joystick axis object
+ * \param[in] a2 joystick axis object
+ *
+ * \return 0 if equal, < 0 if \a a1 < \a a2, > 0 if \a a1 > \a a2
+ */
+static int axis_comp(const void *a1, const void *a2)
{
- joystick_axis_t *axis1 = a1;
- joystick_axis_t *axis2 = a2;
+ const joystick_axis_t *axis1 = a1;
+ const joystick_axis_t *axis2 = a2;
if (axis1->code == axis2->code) {
return 0;
@@ -665,16 +729,20 @@
}
}
-static void axis_free(void *a)
+/** \brief Ordered list comparison callback for buttons
+ *
+ * Compare code of button \a b1 with code of button \a b2.
+ *
+ * \param[in] b1 joystick button object
+ * \param[in] b2 joystick button object
+ *
+ * \return 0 if equal, < 0 if \a b1 < \a b2, > 0 if \a b1 > \a b2
+ */
+static int button_comp(const void *b1, const void *b2)
{
- joystick_axis_free(a);
-}
+ const joystick_button_t *btn1 = b1;
+ const joystick_button_t *btn2 = b2;
-static int button_comp(void *b1, void *b2)
-{
- joystick_button_t *btn1 = b1;
- joystick_button_t *btn2 = b2;
-
if (btn1->code == btn2->code) {
return 0;
} else if (btn1->code < btn2->code) {
@@ -684,14 +752,19 @@
}
}
-static void button_free(void *b)
+/** \brief Ordered list comparison callback for hats
+ *
+ * Compare code of hat \a h1 with code of hat \a h2.
+ *
+ * \param[in] h1 joystick hat object
+ * \param[in] h2 joystick hat object
+ *
+ * \return 0 if equal, < 0 if \a h1 < \a h2, > 0 if \a h1 > \a h2
+ */
+static int hat_comp(const void *h1, const void *h2)
{
- joystick_button_free(b);
-}
-static int hat_comp(void *h1, void *h2)
-{
- joystick_hat_t *hat1 = h1;
- joystick_hat_t *hat2 = h2;
+ const joystick_hat_t *hat1 = h1;
+ const joystick_hat_t *hat2 = h2;
if (hat1->code == hat2->code) {
return 0;
@@ -702,47 +775,44 @@
}
}
-static void hat_free(void *h)
+/* kept for debugging */
+#if 0
+static void add_ordered_buttons(joystick_device_t *joydev)
{
- joystick_hat_free(h);
-}
+ input_node_t *node;
+ int num = 0;
+ for (node = button_list.head; node != NULL; node = node->next) {
+ joystick_button_t *button = node->data;
-static void add_ordered_axes(joystick_device_t *joydev)
-{
- input_node_t *node = axis_list.head;
- while (node != NULL) {
- joystick_device_add_axis(joydev, node->data);
- node = node->next;
+ printf("BUTTON LIST: %d: 0x%04x \"%s\"\n", num++, button->code, button->name);
+ joystick_device_add_button(joydev, node->data);
}
}
+#endif
-static void add_ordered_buttons(joystick_device_t *joydev)
+/** \brief Add inputs ordered by code
+ *
+ * Add axes, buttons and hats ordered by their code (hid usage) to \a joydev.
+ *
+ * \param[in] joydev joystick device
+ */
+static void add_ordered_inputs(joystick_device_t *joydev)
{
- input_node_t *node = button_list.head;
- int num = 0;
- while (node != NULL) {
- joystick_button_t *button = node->data;
+ input_node_t *node;
- printf("BUTTON LIST: %d: 0x%04x \"%s\"\n", num, button->code, button->name);
- joystick_device_add_button(joydev, button);
- num++;
- node = node->next;
+ for (node = axis_list.head; node != NULL; node = node->next) {
+ joystick_device_add_axis(joydev, node->data);
}
-}
-
-static void add_ordered_hats(joystick_device_t *joydev)
-{
- input_node_t *node = hat_list.head;
- while (node != NULL) {
+ for (node = button_list.head; node != NULL; node = node->next) {
+ joystick_device_add_button(joydev, node->data);
+ }
+ for (node = hat_list.head; node != NULL; node = node->next) {
joystick_device_add_hat(joydev, node->data);
- node = node->next;
}
}
-
-
/** \brief Initialize BSD joystick driver and add available devices
*/
void bsd_joystick_init(void)
@@ -784,16 +854,14 @@
log_message(bsd_joy_log, "%s: %s", joydev->node, joydev->name);
/* initialize lists to sort inputs on code */
- input_list_init(&axis_list, axis_free, axis_comp);
- input_list_init(&button_list, button_free, button_comp);
- input_list_init(&hat_list, hat_free, hat_comp);
+ input_list_init(&axis_list, (data_free_t)joystick_axis_free, axis_comp);
+ input_list_init(&button_list, (data_free_t)joystick_button_free, button_comp);
+ input_list_init(&hat_list, (data_free_t)joystick_hat_free, hat_comp);
/* scan axes, buttons and hats */
if (scan_inputs(joydev)) {
/* add inputs to device in-order */
- add_ordered_axes (joydev);
- add_ordered_buttons(joydev);
- add_ordered_hats (joydev);
+ add_ordered_inputs(joydev);
/* OK: try to register */
if (!joystick_device_register(joydev)) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <co...@us...> - 2025-03-12 20:52:31
|
Revision: 45526
http://sourceforge.net/p/vice-emu/code/45526
Author: compyx
Date: 2025-03-12 20:52:19 +0000 (Wed, 12 Mar 2025)
Log Message:
-----------
Joystick: BSD: add axes, buttons and hats in-order
Use naive insertion sort to generate ordered lists of axes, buttons and
hats while scanning a device and add those in-order after scanning has
completed.
TODO: document linked list objects and methods.
Modified Paths:
--------------
branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_bsd.c
Modified: branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_bsd.c
===================================================================
--- branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_bsd.c 2025-03-12 13:31:54 UTC (rev 45525)
+++ branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_bsd.c 2025-03-12 20:52:19 UTC (rev 45526)
@@ -93,6 +93,85 @@
} joy_priv_t;
+typedef struct input_node_s {
+ struct input_node_s *next;
+ void *data;
+} input_node_t;
+
+typedef struct input_list_s {
+ input_node_t *head;
+ void (*data_free)(void *);
+ int (*data_comp)(void *, void *);
+} input_list_t;
+
+
+static void input_list_init(input_list_t *list,
+ void (*data_free)(void *),
+ int (*data_comp)(void *, void *))
+{
+ list->head = NULL;
+ list->data_free = data_free;
+ list->data_comp = data_comp;
+}
+
+static void input_list_free(input_list_t *list, bool with_data)
+{
+ input_node_t *node = list->head;
+ while (node != NULL) {
+ input_node_t *next = node->next;
+ if (with_data) {
+ list->data_free(node->data);
+ }
+ lib_free(node);
+ node = next;
+ }
+ list->head = NULL;
+}
+
+static bool input_list_insert(input_list_t *list, void *data)
+{
+ input_node_t *node = lib_malloc(sizeof *node);
+
+ node->next = NULL;
+ node->data = data;
+
+ if (list->head == NULL) {
+ list->head = node;
+ return true;
+ } else {
+ input_node_t *curr = list->head;
+ input_node_t *prev = NULL;
+
+ while (curr != NULL) {
+ int cmp = list->data_comp(node->data, curr->data);
+
+ if (cmp == 0) {
+ /* error: duplicate code */
+ return false;
+ } else if (cmp < 0) {
+ /* insert before curr */
+ if (prev == NULL) {
+ /* no previous items */
+ node->next = curr;
+ list->head = node;
+ } else {
+ prev->next = node;
+ node->next = curr;
+ }
+ return true;
+ } else {
+ /* keep going */
+ prev = curr;
+ curr = curr->next;
+ }
+ }
+ /* append to tail of list */
+ prev->next = node;
+ return true;
+ }
+}
+
+
/* Forward declarations */
static bool bsd_joy_open (int joyport, joystick_device_t *joydev);
static void bsd_joy_poll (int joyport, joystick_device_t *joydev);
@@ -103,6 +182,10 @@
/** \brief Log for BSD joystick driver */
static log_t bsd_joy_log;
+static input_list_t axis_list;
+static input_list_t button_list;
+static input_list_t hat_list;
+
/** \brief BSD joystick driver declaration */
static joystick_driver_t driver = {
.open = bsd_joy_open,
@@ -155,6 +238,7 @@
}
}
+
static bool bsd_joy_open (int joyport, joystick_device_t *joydev)
{
return true; /* NOP */
@@ -432,7 +516,9 @@
button = joystick_button_new(hid_usage_in_page(item->usage));
button->code = (uint32_t)HID_USAGE(item->usage);
log_message(bsd_joy_log, "button %u: %s", button->code, button->name);
- joystick_device_add_button(joydev, button);
+
+ input_list_insert(&button_list, button);
+// joystick_device_add_button(joydev, button);
}
/** \brief Add hat to joystick device
@@ -565,18 +651,111 @@
}
+static int axis_comp(void *a1, void *a2)
+{
+ joystick_axis_t *axis1 = a1;
+ joystick_axis_t *axis2 = a2;
+
+ if (axis1->code == axis2->code) {
+ return 0;
+ } else if (axis1->code < axis2->code) {
+ return -1;
+ } else {
+ return 1;
+ }
+}
+
+static void axis_free(void *a)
+{
+ joystick_axis_free(a);
+}
+
+static int button_comp(void *b1, void *b2)
+{
+ joystick_button_t *btn1 = b1;
+ joystick_button_t *btn2 = b2;
+
+ if (btn1->code == btn2->code) {
+ return 0;
+ } else if (btn1->code < btn2->code) {
+ return -1;
+ } else {
+ return 1;
+ }
+}
+
+static void button_free(void *b)
+{
+ joystick_button_free(b);
+}
+static int hat_comp(void *h1, void *h2)
+{
+ joystick_hat_t *hat1 = h1;
+ joystick_hat_t *hat2 = h2;
+
+ if (hat1->code == hat2->code) {
+ return 0;
+ } else if (hat1->code < hat2->code) {
+ return -1;
+ } else {
+ return 1;
+ }
+}
+
+static void hat_free(void *h)
+{
+ joystick_hat_free(h);
+}
+
+
+static void add_ordered_axes(joystick_device_t *joydev)
+{
+ input_node_t *node = axis_list.head;
+ while (node != NULL) {
+ joystick_device_add_axis(joydev, node->data);
+ node = node->next;
+ }
+}
+
+static void add_ordered_buttons(joystick_device_t *joydev)
+{
+ input_node_t *node = button_list.head;
+ int num = 0;
+ while (node != NULL) {
+ joystick_button_t *button = node->data;
+
+ printf("BUTTON LIST: %d: 0x%04x \"%s\"\n", num, button->code, button->name);
+ joystick_device_add_button(joydev, button);
+ num++;
+ node = node->next;
+ }
+}
+
+static void add_ordered_hats(joystick_device_t *joydev)
+{
+ input_node_t *node = hat_list.head;
+ while (node != NULL) {
+ joystick_device_add_hat(joydev, node->data);
+ node = node->next;
+ }
+}
+
+
+
+
/** \brief Initialize BSD joystick driver and add available devices
*/
void bsd_joystick_init(void)
{
-struct dirent **namelist = NULL;
+ struct dirent **namelist = NULL;
int nl_count;
-int n;
+ int n;
bsd_joy_log = log_open("BSD Joystick");
log_message(bsd_joy_log, "Registering driver.");
joystick_driver_register(&driver);
+
/* Initialize HID library so we can retrieve strings for page and usage;
* without this button names will be "0x00001" etc, not very informative.
*/
@@ -603,8 +782,19 @@
joydev = scan_device(node);
if (joydev != NULL) {
log_message(bsd_joy_log, "%s: %s", joydev->node, joydev->name);
+
+ /* initialize lists to sort inputs on code */
+ input_list_init(&axis_list, axis_free, axis_comp);
+ input_list_init(&button_list, button_free, button_comp);
+ input_list_init(&hat_list, hat_free, hat_comp);
+
/* scan axes, buttons and hats */
if (scan_inputs(joydev)) {
+ /* add inputs to device in-order */
+ add_ordered_axes (joydev);
+ add_ordered_buttons(joydev);
+ add_ordered_hats (joydev);
+
/* OK: try to register */
if (!joystick_device_register(joydev)) {
/* failure */
@@ -613,6 +803,11 @@
joydev->node, joydev->name);
joystick_device_free(joydev);
}
+
+ /* free lists, but not their data */
+ input_list_free(&axis_list, false);
+ input_list_free(&button_list, false);
+ input_list_free(&hat_list, false);
} else {
log_warning(bsd_joy_log,
"failed to scan inputs for device %s (\"%s\")",
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <co...@us...> - 2025-03-12 13:31:57
|
Revision: 45525
http://sourceforge.net/p/vice-emu/code/45525
Author: compyx
Date: 2025-03-12 13:31:54 +0000 (Wed, 12 Mar 2025)
Log Message:
-----------
Joystick: Fix BSD driver to use new functions
Use the `joystick_[axis|button|hat]()` functions in the NetBSD/FreeBSD
joystick driver.
Modified Paths:
--------------
branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_bsd.c
Modified: branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_bsd.c
===================================================================
--- branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_bsd.c 2025-03-12 08:53:39 UTC (rev 45524)
+++ branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_bsd.c 2025-03-12 13:31:54 UTC (rev 45525)
@@ -166,7 +166,7 @@
int i;
for (i = 0; i < joydev->num_axes; i++) {
- if (joydev->axes[i].code == code) {
+ if (joydev->axes[i]->code == code) {
return i;
}
/* axis codes are *not* stored in-order like with Linux evdev, so we
@@ -180,7 +180,7 @@
int i;
for (i = 0; i < joydev->num_buttons; i++) {
- if (joydev->buttons[i].code == code) {
+ if (joydev->buttons[i]->code == code) {
return i;
}
/* button codes are *not* stored in-order like with Linux evdev, so we
@@ -194,7 +194,7 @@
int i;
for (i = 0; i < joydev->num_hats; i++) {
- if (joydev->hats[i].code == code) {
+ if (joydev->hats[i]->code == code) {
return i;
}
/* hat codes are *not* stored in-order like with Linux evdev, so we
@@ -408,17 +408,15 @@
static void add_joy_axis(joystick_device_t *joydev,
const struct hid_item *item)
{
- joystick_axis_t axis;
+ joystick_axis_t *axis;
- joystick_axis_init(&axis);
- axis.code = (uint16_t)HID_USAGE(item->usage);
- axis.name = lib_strdup(hid_usage_in_page(item->usage));
- axis.minimum = item->logical_minimum;
- axis.maximum = item->logical_maximum;
+ axis = joystick_axis_new(hid_usage_in_page(item->usage));
+ axis->code = (uint32_t)HID_USAGE(item->usage);
+ axis->minimum = item->logical_minimum;
+ axis->maximum = item->logical_maximum;
- log_message(bsd_joy_log, "axis %u: %s", (unsigned int)axis.code, axis.name);
- joystick_device_add_axis(joydev, &axis);
- lib_free(axis.name);
+ log_message(bsd_joy_log, "axis %u: %s", axis->code, axis->name);
+ joystick_device_add_axis(joydev, axis);
}
/** \brief Add button to joystick device
@@ -429,17 +427,12 @@
static void add_joy_button(joystick_device_t *joydev,
const struct hid_item *item)
{
- joystick_button_t button;
+ joystick_button_t *button;
- joystick_button_init(&button);
- button.code = (uint16_t)HID_USAGE(item->usage);
- /* NetBSD usbhid man page lies, function below returns `const char *`,
- * not `char *`, so we need a temporary copy:
- */
- button.name = lib_strdup(hid_usage_in_page(item->usage));
- log_message(bsd_joy_log, "button %u: %s", (unsigned int)button.code, button.name);
- joystick_device_add_button(joydev, &button);
- lib_free(button.name);
+ button = joystick_button_new(hid_usage_in_page(item->usage));
+ button->code = (uint32_t)HID_USAGE(item->usage);
+ log_message(bsd_joy_log, "button %u: %s", button->code, button->name);
+ joystick_device_add_button(joydev, button);
}
/** \brief Add hat to joystick device
@@ -450,14 +443,12 @@
static void add_joy_hat(joystick_device_t *joydev,
const struct hid_item *item)
{
- joystick_hat_t hat;
+ joystick_hat_t *hat;
- joystick_hat_init(&hat);
- hat.code = (uint16_t)HID_USAGE(item->usage);
- hat.name = lib_strdup(hid_usage_in_page(item->usage));
- log_message(bsd_joy_log, "hat %u: %s", (unsigned int)hat.code, hat.name);
- joystick_device_add_hat(joydev, &hat);
- lib_free(hat.name);
+ hat = joystick_hat_new(hid_usage_in_page(item->usage));
+ hat->code = (uint32_t)HID_USAGE(item->usage);
+ log_message(bsd_joy_log, "hat %u: %s", hat->code, hat->name);
+ joystick_device_add_hat(joydev, hat);
}
/** \brief Scan device for inputs
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <co...@us...> - 2025-03-12 08:53:41
|
Revision: 45524
http://sourceforge.net/p/vice-emu/code/45524
Author: compyx
Date: 2025-03-12 08:53:39 +0000 (Wed, 12 Mar 2025)
Log Message:
-----------
Joystick: turn axis, button and hat arrays into arrays of pointers
Reduce code complexity by using arrays of pointers to input objects instead of
arrays of input objects, and reduce number of allocations and deallocations
when adding inputs to joystick devices.
The `joystick_[axis|button|hat]_new()` functions now make a copy of the input's
name (if given) and the `joystick_device_add_[axis|button|hat]()` functions now
take ownership of the objects given.
Modified Paths:
--------------
branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_linux_evdev.c
branches/compyx/joymap-001/vice/src/joyport/joystick.c
branches/compyx/joymap-001/vice/src/joyport/joystick.h
Modified: branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_linux_evdev.c
===================================================================
--- branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_linux_evdev.c 2025-03-11 17:32:47 UTC (rev 45523)
+++ branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_linux_evdev.c 2025-03-12 08:53:39 UTC (rev 45524)
@@ -165,8 +165,8 @@
#endif
index = priv->axis_index[event->code - AXIS_CODE_MIN];
if (index >= 0) {
- int32_t minimum = joydev->axes[index].minimum;
- int32_t maximum = joydev->axes[index].maximum;
+ int32_t minimum = joydev->axes[index]->minimum;
+ int32_t maximum = joydev->axes[index]->maximum;
int32_t range = maximum - minimum + 1;
joystick_axis_value_t direction = JOY_AXIS_MIDDLE;
@@ -298,16 +298,14 @@
for (code = BUTTON_CODE_MIN; code <= BUTTON_CODE_MAX; code++) {
if (libevdev_has_event_code(evdev, EV_KEY, code)) {
joy_priv_t *priv = joydev->priv;
- joystick_button_t button;
+ joystick_button_t *button;
- joystick_button_init(&button);
- button.code = code;
- /* need to copy since event_code_get_name() returns const char* */
- button.name = lib_strdup(libevdev_event_code_get_name(EV_KEY, code));
+ button = joystick_button_new(libevdev_event_code_get_name(EV_KEY, code));
+ button->code = code;
/* store index in buttons array */
priv->button_index[code - BUTTON_CODE_MIN] = joydev->num_buttons;
- joystick_device_add_button(joydev, &button);
- lib_free(button.name);
+ /* joydev takes ownership of button */
+ joystick_device_add_button(joydev, button);
}
}
}
@@ -327,19 +325,18 @@
for (code = AXIS_CODE_MIN; code <= AXIS_CODE_MAX; code++) {
if (libevdev_has_event_code(evdev, EV_ABS, code)) {
const struct input_absinfo *info;
- joystick_axis_t axis;
+ joystick_axis_t *axis;
info = libevdev_get_abs_info(evdev, code);
- joystick_axis_init(&axis);
- axis.code = code;
- axis.name = lib_strdup(libevdev_event_code_get_name(EV_ABS, code));
+ axis = joystick_axis_new(libevdev_event_code_get_name(EV_ABS, code));
+ axis->code = code;
if (info != NULL) {
- axis.minimum = info->minimum;
- axis.maximum = info->maximum;
+ axis->minimum = info->minimum;
+ axis->maximum = info->maximum;
}
priv->axis_index[code - AXIS_CODE_MIN] = joydev->num_axes;
- joystick_device_add_axis(joydev, &axis);
- lib_free(axis.name);
+ /* joydev takes ownership of axis */
+ joystick_device_add_axis(joydev, axis);
}
}
}
Modified: branches/compyx/joymap-001/vice/src/joyport/joystick.c
===================================================================
--- branches/compyx/joymap-001/vice/src/joyport/joystick.c 2025-03-11 17:32:47 UTC (rev 45523)
+++ branches/compyx/joymap-001/vice/src/joyport/joystick.c 2025-03-12 08:53:39 UTC (rev 45524)
@@ -853,7 +853,7 @@
{
if (joynum < num_joystick_devices) {
joystick_device_t *joydev = joystick_devices[joynum];
- joystick_axis_t *axis = &joydev->axes[axis_idx];
+ joystick_axis_t *axis = joydev->axes[axis_idx];
if ((joydev->joyport == 0 || joydev->joyport == 1) && (axis->mapping.pot > 0)) {
joystick_axis_value[joydev->joyport][axis->mapping.pot- 1] = value;
@@ -870,7 +870,9 @@
if (joystick_device_num >= 0 && joystick_device_num < num_joystick_devices) {
for (j = 0; j < joystick_devices[joystick_device_num]->num_axes; j++) {
- if (joystick_devices[joystick_device_num]->axes[j].mapping.pot - 1 == pot) {
+ joystick_device_t *joydev = joystick_devices[joystick_device_num];
+
+ if (joydev->axes[j]->mapping.pot - 1 == pot) {
snprintf(mapping_retval, sizeof mapping_retval, "Ax%d", j);
retval = mapping_retval;
}
@@ -890,12 +892,13 @@
char *index_string = NULL;
if (joystick_device_num >= 0 && joystick_device_num < num_joystick_devices) {
- for (j = 0; j < joystick_devices[joystick_device_num]->num_axes; j++) {
- joystick_mapping_t *positive;
- joystick_mapping_t *negative;
- joystick_axis_t *axis = &joystick_devices[joystick_device_num]->axes[j];
+ joystick_device_t *joydev = joystick_devices[joystick_device_num];
- positive = &axis->mapping.positive;
+ for (j = 0; j < joydev->num_axes; j++) {
+ joystick_axis_t *axis = joydev->axes[j];
+ joystick_mapping_t *positive = &axis->mapping.positive;
+ joystick_mapping_t *negative = &axis->mapping.negative;
+
if (positive->action == JOY_ACTION_JOYSTICK && positive->value.joy_pin == pin) {
valid++;
type_string = "Ax";
@@ -904,7 +907,6 @@
sub_index = 0;
}
- negative = &axis->mapping.negative;
if (negative->action == JOY_ACTION_JOYSTICK && negative->value.joy_pin == pin) {
valid++;
type_string = "Ax";
@@ -914,9 +916,10 @@
}
}
- for (j = 0; j < joystick_devices[joystick_device_num]->num_buttons; j++) {
- joystick_button_t *button = &joystick_devices[joystick_device_num]->buttons[j];
+ for (j = 0; j < joydev->num_buttons; j++) {
+ joystick_button_t *button = joydev->buttons[j];
joystick_mapping_t *mapping = &button->mapping;
+
if (mapping->action == JOY_ACTION_JOYSTICK) {
if (mapping->value.joy_pin == pin) {
valid++;
@@ -928,14 +931,13 @@
}
}
- for (j = 0; j < joystick_devices[joystick_device_num]->num_hats; j++) {
- joystick_mapping_t *up;
- joystick_mapping_t *down;
- joystick_mapping_t *left;
- joystick_mapping_t *right;
- joystick_hat_t *hat = &joystick_devices[joystick_device_num]->hats[j];
+ for (j = 0; j < joydev->num_hats; j++) {
+ joystick_hat_t *hat = joydev->hats[j];
+ joystick_mapping_t *up = &hat->mapping.up;
+ joystick_mapping_t *down = &hat->mapping.down;
+ joystick_mapping_t *left = &hat->mapping.left;
+ joystick_mapping_t *right = &hat->mapping.right;
- up = &hat->mapping.up;
if (up->action == JOY_ACTION_JOYSTICK) {
if (up->value.joy_pin == pin) {
valid++;
@@ -946,7 +948,6 @@
}
}
- down = &hat->mapping.down;
if (down->action == JOY_ACTION_JOYSTICK) {
if (down->value.joy_pin == pin) {
valid++;
@@ -957,7 +958,6 @@
}
}
- left = &hat->mapping.left;
if (left->action == JOY_ACTION_JOYSTICK) {
if (left->value.joy_pin == pin) {
valid++;
@@ -968,7 +968,6 @@
}
}
- right = &hat->mapping.right;
if (right->action == JOY_ACTION_JOYSTICK) {
if (right->value.joy_pin == pin) {
valid++;
@@ -1012,8 +1011,8 @@
joystick_device_t *joydev = joystick_devices[i];
for (j = 0; j < joystick_devices[i]->num_axes; j++) {
- joystick_mapping_t *positive = &joydev->axes[j].mapping.positive;
- joystick_mapping_t *negative = &joydev->axes[j].mapping.negative;
+ joystick_mapping_t *positive = &joydev->axes[j]->mapping.positive;
+ joystick_mapping_t *negative = &joydev->axes[j]->mapping.negative;
if (positive->action == (which ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
valid++;
@@ -1035,7 +1034,7 @@
}
for (j = 0; j < joystick_devices[i]->num_buttons; j++) {
- joystick_mapping_t *mapping = &joydev->buttons[j].mapping;
+ joystick_mapping_t *mapping = &joydev->buttons[j]->mapping;
if (mapping->action == (which ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
valid++;
@@ -1048,10 +1047,10 @@
}
for (j = 0; j < joystick_devices[i]->num_hats; j++) {
- joystick_mapping_t *up = &joydev->hats[j].mapping.up;
- joystick_mapping_t *down = &joydev->hats[j].mapping.down;
- joystick_mapping_t *left = &joydev->hats[j].mapping.left;
- joystick_mapping_t *right = &joydev->hats[j].mapping.right;
+ joystick_mapping_t *up = &joydev->hats[j]->mapping.up;
+ joystick_mapping_t *down = &joydev->hats[j]->mapping.down;
+ joystick_mapping_t *left = &joydev->hats[j]->mapping.left;
+ joystick_mapping_t *right = &joydev->hats[j]->mapping.right;
if (up->action == (which ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
valid++;
@@ -1111,7 +1110,7 @@
void joy_set_pot_mapping(int joystick_device_num, int axis, int pot)
{
- joystick_devices[joystick_device_num]->axes[axis].mapping.pot = pot + 1;
+ joystick_devices[joystick_device_num]->axes[axis]->mapping.pot = pot + 1;
}
void joy_delete_pot_mapping(int joystick_device_num, int pot)
@@ -1122,7 +1121,7 @@
joystick_device_t *joydev = joystick_devices[joystick_device_num];
for (j = 0; j < joydev->num_axes; j++) {
- joystick_axis_t *axis = &joydev->axes[j];
+ joystick_axis_t *axis = joydev->axes[j];
if (axis->mapping.pot - 1 == pot) {
axis->mapping.pot = 0;
}
@@ -1138,8 +1137,8 @@
joystick_device_t *joydev = joystick_devices[joystick_device_num];
for (j = 0; j < joydev->num_axes; j++) {
- joystick_mapping_t *negative = &joydev->axes[j].mapping.negative;
- joystick_mapping_t *positive = &joydev->axes[j].mapping.positive;
+ joystick_mapping_t *negative = &joydev->axes[j]->mapping.negative;
+ joystick_mapping_t *positive = &joydev->axes[j]->mapping.positive;
if (positive->action == JOY_ACTION_JOYSTICK) {
if (positive->value.joy_pin == pin) {
@@ -1157,7 +1156,7 @@
}
for (j = 0; j < joydev->num_buttons; j++) {
- joystick_mapping_t *mapping = &joydev->buttons[j].mapping;
+ joystick_mapping_t *mapping = &joydev->buttons[j]->mapping;
if (mapping->action == JOY_ACTION_JOYSTICK) {
if (mapping->value.joy_pin == pin) {
@@ -1168,10 +1167,10 @@
}
for (j = 0; j < joydev->num_hats; j++) {
- joystick_mapping_t *up = &joydev->hats[j].mapping.up;
- joystick_mapping_t *down = &joydev->hats[j].mapping.down;
- joystick_mapping_t *left = &joydev->hats[j].mapping.left;
- joystick_mapping_t *right = &joydev->hats[j].mapping.right;
+ joystick_mapping_t *up = &joydev->hats[j]->mapping.up;
+ joystick_mapping_t *down = &joydev->hats[j]->mapping.down;
+ joystick_mapping_t *left = &joydev->hats[j]->mapping.left;
+ joystick_mapping_t *right = &joydev->hats[j]->mapping.right;
if (up->action == JOY_ACTION_JOYSTICK) {
if (up->value.joy_pin == pin) {
@@ -1358,7 +1357,7 @@
/* dump axis mappings */
for (inp_idx = 0; inp_idx < joydev->num_axes; inp_idx++) {
- joystick_axis_t *axis = &joydev->axes[inp_idx];
+ joystick_axis_t *axis = joydev->axes[inp_idx];
if (axis->mapping.pot > 0) {
fprintf(fp, "%i %i %i %i %u\n",
@@ -1373,7 +1372,7 @@
/* dump button mappings */
for (inp_idx = 0; inp_idx < joydev->num_buttons; inp_idx++) {
- joystick_button_t *button = &joydev->buttons[inp_idx];
+ joystick_button_t *button = joydev->buttons[inp_idx];
mapping_dump_map(fp, dev_idx, JOY_INPUT_BUTTON, inp_idx, &button->mapping);
}
@@ -1382,7 +1381,7 @@
/* dump hat mappings */
row = 0;
for (inp_idx = 0; inp_idx < joydev->num_hats; inp_idx++) {
- joystick_hat_t *hat = &joydev->hats[inp_idx];
+ joystick_hat_t *hat = joydev->hats[inp_idx];
/* indexes 0-3 are hardcoded to up, down, left and right */
mapping_dump_map(fp, dev_idx, JOY_INPUT_HAT, row + 0, &hat->mapping.up);
@@ -1411,17 +1410,17 @@
joystick_device_t *joydev = joystick_devices[i];
for (k = 0; k < joydev->num_axes; ++k) {
- joydev->axes[k].mapping.positive.action = JOY_ACTION_NONE;
- joydev->axes[k].mapping.negative.action = JOY_ACTION_NONE;
+ joydev->axes[k]->mapping.positive.action = JOY_ACTION_NONE;
+ joydev->axes[k]->mapping.negative.action = JOY_ACTION_NONE;
}
for (k = 0; k < joystick_devices[i]->num_buttons; ++k) {
- joydev->buttons[k].mapping.action = JOY_ACTION_NONE;
+ joydev->buttons[k]->mapping.action = JOY_ACTION_NONE;
}
for (k = 0; k < joystick_devices[i]->num_hats; ++k) {
- joydev->hats[k].mapping.up.action = JOY_ACTION_NONE;
- joydev->hats[k].mapping.down.action = JOY_ACTION_NONE;
- joydev->hats[k].mapping.left.action = JOY_ACTION_NONE;
- joydev->hats[k].mapping.right.action = JOY_ACTION_NONE;
+ joydev->hats[k]->mapping.up.action = JOY_ACTION_NONE;
+ joydev->hats[k]->mapping.down.action = JOY_ACTION_NONE;
+ joydev->hats[k]->mapping.left.action = JOY_ACTION_NONE;
+ joydev->hats[k]->mapping.right.action = JOY_ACTION_NONE;
}
}
}
@@ -1598,7 +1597,7 @@
if (state->action == JOY_ACTION_POT_AXIS) {
/* map to potentiometer */
if (state->input_index < joydev->num_axes) {
- joydev->axes[state->input_index].mapping.pot = state->args.pot;
+ joydev->axes[state->input_index]->mapping.pot = state->args.pot;
} else {
result = false;
}
@@ -1612,7 +1611,7 @@
__func__, index, direction == 0 ? "positive" : "negative");
#endif
if (index < joydev->num_axes) {
- joystick_axis_t *axis = &joydev->axes[index];
+ joystick_axis_t *axis = joydev->axes[index];
joystick_mapping_t *mapping;
/* select directional mapping */
@@ -1648,7 +1647,7 @@
bool result = true;
if (index < joydev->num_buttons) {
- joystick_mapping_t *mapping = &joydev->buttons[index].mapping;
+ joystick_mapping_t *mapping = &joydev->buttons[index]->mapping;
parser_set_mapping(state, mapping);
} else {
parser_log_error(state,
@@ -1672,7 +1671,7 @@
joystick_device_t *joydev = joystick_devices[state->joy_index];
if (index < joydev->num_hats) {
- joystick_hat_t *hat = &joydev->hats[index];
+ joystick_hat_t *hat = joydev->hats[index];
joystick_mapping_t *mapping;
switch (direction) {
@@ -2994,7 +2993,7 @@
void joy_axis_event(uint8_t joynum, uint8_t axis_index, joystick_axis_value_t value)
{
joystick_device_t *joydev = joystick_devices[joynum];
- joystick_axis_t *axis = &joydev->axes[axis_index];
+ joystick_axis_t *axis = joydev->axes[axis_index];
joystick_axis_value_t prev = axis->prev;
int joyport = joydev->joyport;
@@ -3040,13 +3039,13 @@
}
}
#endif
- if (pressed != joydev->buttons[button].prev) {
+ if (pressed != joydev->buttons[button]->prev) {
DBG(("joy_button_event: joynum: %d, button: %d pressed: %d\n",
joynum, button, pressed));
- joy_perform_event(&joydev->buttons[button].mapping,
+ joy_perform_event(&joydev->buttons[button]->mapping,
joydev->joyport,
pressed);
- joydev->buttons[button].prev = pressed;
+ joydev->buttons[button]->prev = pressed;
}
}
@@ -3053,7 +3052,7 @@
void joy_hat_event(uint8_t joynum, uint8_t hat_idx, uint8_t value)
{
joystick_device_t *joydev = joystick_devices[joynum];
- joystick_hat_t *hat = &joydev->hats[hat_idx];
+ joystick_hat_t *hat = joydev->hats[hat_idx];
int joyport = joydev->joyport;
int32_t prev = hat->prev;
@@ -3287,17 +3286,17 @@
lib_free(joydev->node);
for (i = 0; i < joydev->num_axes; i++) {
- lib_free(joydev->axes[i].name);
+ joystick_axis_free(joydev->axes[i]);
}
lib_free(joydev->axes);
for (i = 0; i < joydev->num_buttons; i++) {
- lib_free(joydev->buttons[i].name);
+ joystick_button_free(joydev->buttons[i]);
}
lib_free(joydev->buttons);
for (i = 0; i < joydev->num_hats; i++) {
- lib_free(joydev->hats[i].name);
+ joystick_hat_free(joydev->hats[i]);
}
lib_free(joydev->hats);
@@ -3326,15 +3325,15 @@
{
if (joydev->num_hats > 0) {
/* if the controller as a "hat", use that for joystick directions */
- joystick_hat_t *hat = &joydev->hats[0];
+ joystick_hat_t *hat = joydev->hats[0];
- hat->mapping.up.action = JOY_ACTION_JOYSTICK;
- hat->mapping.up.value.joy_pin = JOYSTICK_DIRECTION_UP;
- hat->mapping.down.action = JOY_ACTION_JOYSTICK;
- hat->mapping.down.value.joy_pin = JOYSTICK_DIRECTION_DOWN;
- hat->mapping.left.action = JOY_ACTION_JOYSTICK;
- hat->mapping.left.value.joy_pin = JOYSTICK_DIRECTION_LEFT;
- hat->mapping.right.action = JOY_ACTION_JOYSTICK;
+ hat->mapping.up.action = JOY_ACTION_JOYSTICK;
+ hat->mapping.up.value.joy_pin = JOYSTICK_DIRECTION_UP;
+ hat->mapping.down.action = JOY_ACTION_JOYSTICK;
+ hat->mapping.down.value.joy_pin = JOYSTICK_DIRECTION_DOWN;
+ hat->mapping.left.action = JOY_ACTION_JOYSTICK;
+ hat->mapping.left.value.joy_pin = JOYSTICK_DIRECTION_LEFT;
+ hat->mapping.right.action = JOY_ACTION_JOYSTICK;
hat->mapping.right.value.joy_pin = JOYSTICK_DIRECTION_RIGHT;
} else if (joydev->num_axes > 1) {
@@ -3341,8 +3340,8 @@
/* If no hat exists, but we have at least two axes, we use those for
* joystick directions. We assume the first axis is horizontal and the
* next one vertical, controlling the same (thumb)stick. */
- joystick_axis_t *x = &joydev->axes[0];
- joystick_axis_t *y = &joydev->axes[1];
+ joystick_axis_t *x = joydev->axes[0];
+ joystick_axis_t *y = joydev->axes[1];
x->mapping.negative.action = JOY_ACTION_JOYSTICK;
x->mapping.negative.value.joy_pin = JOYSTICK_DIRECTION_LEFT;
@@ -3372,13 +3371,13 @@
joystick_button_t *button;
/* primary fire button */
- button = &joydev->buttons[0];
+ button = joydev->buttons[0];
button->mapping.action = JOY_ACTION_JOYSTICK;
button->mapping.value.joy_pin = 16;
if (joydev->num_buttons > 1) {
/* secondary fire button */
- button = &joydev->buttons[1];
+ button = joydev->buttons[1];
button->mapping.action = JOY_ACTION_JOYSTICK;
button->mapping.value.joy_pin = 32;
}
@@ -3385,7 +3384,7 @@
if (joydev->num_buttons > 2) {
/* ternary fire button */
- button = &joydev->buttons[2];
+ button = joydev->buttons[2];
button->mapping.action = JOY_ACTION_JOYSTICK;
button->mapping.value.joy_pin = 64;
}
@@ -3435,7 +3434,7 @@
}
-void joystick_axis_init(joystick_axis_t *axis)
+static void joystick_axis_init(joystick_axis_t *axis)
{
axis->code = 0;
axis->name = NULL;
@@ -3448,8 +3447,7 @@
joystick_mapping_init(&axis->mapping.positive);
}
-
-void joystick_button_init(joystick_button_t *button)
+static void joystick_button_init(joystick_button_t *button)
{
button->code = 0;
button->name = NULL;
@@ -3458,8 +3456,7 @@
joystick_mapping_init(&button->mapping);
}
-
-void joystick_hat_init(joystick_hat_t *hat)
+static void joystick_hat_init(joystick_hat_t *hat)
{
hat->code = 0;
hat->name = NULL;
@@ -3472,34 +3469,75 @@
}
+joystick_axis_t *joystick_axis_new(const char *name)
+{
+ joystick_axis_t *axis = lib_malloc(sizeof *axis);
+ joystick_axis_init(axis);
+ if (name != NULL) {
+ axis->name = lib_strdup(name);
+ }
+ return axis;
+}
-void joystick_device_add_button(joystick_device_t *joydev,
- joystick_button_t *button)
+
+void joystick_axis_free(joystick_axis_t *axis)
{
- joystick_button_t *new_button;
+ if (axis != NULL) {
+ lib_free(axis->name);
+ lib_free(axis);
+ }
+}
- if (joydev->num_buttons == joydev->max_buttons) {
- joydev->max_buttons *= 2;
- joydev->buttons = lib_realloc(joydev->buttons,
- sizeof *joydev->buttons * (size_t)joydev->max_buttons);
+
+joystick_button_t *joystick_button_new(const char *name)
+{
+ joystick_button_t *button = lib_malloc(sizeof *button);
+
+ joystick_button_init(button);
+ if (name != NULL) {
+ button->name = lib_strdup(name);
}
+ return button;
+}
- new_button = &joydev->buttons[joydev->num_buttons];
- joystick_button_init(new_button);
- new_button->code = button->code;
- new_button->name = lib_strdup(button->name);
- new_button->index = joydev->num_buttons;
- joydev->num_buttons++;
+void joystick_button_free(joystick_button_t *button)
+{
+ if (button != NULL) {
+ lib_free(button->name);
+ lib_free(button);
+ }
}
-/** \@brief Add axis data to joystick device
+joystick_hat_t *joystick_hat_new(const char *name)
+{
+ joystick_hat_t *hat = lib_malloc(sizeof *hat);
+
+ joystick_hat_init(hat);
+ if (name != NULL) {
+ hat->name = lib_strdup(name);
+ }
+ return hat;
+}
+
+
+void joystick_hat_free(joystick_hat_t *hat)
+{
+ if (hat != NULL) {
+ lib_free(hat->name);
+ lib_free(hat);
+ }
+}
+
+
+
+/** \@brief Add axis object to joystick device
*
- * Adds \a axis to the \c axes array in \c joydev, making a deep copy of the
- * data in \a axis. Also determines if \a axis is digital or not (minimum == -1,
- * maximum == 1).
+ * Adds \a axis to the \c axes array in \a joydev, with ownership of \a axis
+ * transfered to \a joydev.
+ * Also determines if \a axis is digital or not (minimum == -1, maximum == 1).
*
* \param[in] joydev joystick device
* \param[in] axis axis object
@@ -3507,43 +3545,50 @@
void joystick_device_add_axis(joystick_device_t *joydev,
joystick_axis_t *axis)
{
- joystick_axis_t *new_axis;
-
if (joydev->num_axes == joydev->max_axes) {
joydev->max_axes *= 2;
joydev->axes = lib_realloc(joydev->axes,
sizeof *joydev->axes * (size_t)joydev->max_axes);
}
+ joydev->axes[joydev->num_axes++] = axis;
+}
- new_axis = &joydev->axes[joydev->num_axes];
- joystick_axis_init(new_axis);
- new_axis->code = axis->code;
- new_axis->name = lib_strdup(axis->name);
- new_axis->index = joydev->num_axes;
- new_axis->minimum = axis->minimum;
- new_axis->maximum = axis->maximum;
- new_axis->digital = (bool)((axis->minimum == -1) && (axis->maximum == 1));
- joydev->num_axes++;
+/** \brief Add button object to joystick device
+ *
+ * Adds \a button to the \c buttons array in \a joydev, with ownership of
+ * \a button transfered to \a joydev.
+ *
+ * \param[in] joydev joystick device
+ * \param[in] button button object
+ */
+void joystick_device_add_button(joystick_device_t *joydev,
+ joystick_button_t *button)
+{
+ if (joydev->num_buttons == joydev->max_buttons) {
+ joydev->max_buttons *= 2;
+ joydev->buttons = lib_realloc(joydev->buttons,
+ sizeof *joydev->buttons * (size_t)joydev->max_buttons);
+ }
+ joydev->buttons[joydev->num_buttons++] = button;
}
+/** \brief Add hat object to joystick device
+ *
+ * Adds \a hat to the \c hats array in \a joydev, with ownership of \a hat
+ * transfered to \a joydev.
+ *
+ * \param[in] joydev joystick device
+ * \param[in] hat hat object
+ */
void joystick_device_add_hat(joystick_device_t *joydev,
joystick_hat_t *hat)
{
- joystick_hat_t *new_hat;
-
if (joydev->num_hats == joydev->max_hats) {
joydev->num_hats *= 2;
joydev->hats = lib_realloc(joydev->hats,
sizeof *joydev->hats * (size_t)joydev->max_hats);
}
-
- new_hat = &joydev->hats[joydev->num_hats];
- joystick_hat_init(new_hat);
- new_hat->code = hat->code;
- new_hat->name = lib_strdup(hat->name);
- new_hat->index = joydev->num_hats;
-
- joydev->num_hats++;
+ joydev->hats[joydev->num_hats++] = hat;
}
Modified: branches/compyx/joymap-001/vice/src/joyport/joystick.h
===================================================================
--- branches/compyx/joymap-001/vice/src/joyport/joystick.h 2025-03-11 17:32:47 UTC (rev 45523)
+++ branches/compyx/joymap-001/vice/src/joyport/joystick.h 2025-03-12 08:53:39 UTC (rev 45524)
@@ -240,7 +240,7 @@
*/
typedef struct joystick_device_s {
/** \brief Device name ("<vendor-name> <product-name>") */
- char *name;
+ char *name;
/** \brief Arch-specific device identifier
*
@@ -249,39 +249,39 @@
* For example on Linux this will be a "file" in the <tt>/dev/input/</tt>
* directory.
*/
- char *node;
+ char *node;
/** \brief HID vendor ID */
- uint16_t vendor;
+ uint16_t vendor;
/** \brief HID product ID */
- uint16_t product;
+ uint16_t product;
/** \brief List of axes */
- joystick_axis_t *axes;
+ joystick_axis_t **axes;
/** \brief List of buttons */
- joystick_button_t *buttons;
+ joystick_button_t **buttons;
/** \brief List of hats */
- joystick_hat_t *hats;
+ joystick_hat_t **hats;
/** \brief Number of axes */
- int num_axes;
+ int num_axes;
/** \brief Number of buttons */
- int num_buttons;
+ int num_buttons;
/** \brief Number of hats */
- int num_hats;
+ int num_hats;
/* bookkeeping for resizing arrays when adding elements */
- size_t max_axes; /**< size of \c axes array */
- size_t max_buttons; /**< size of \c buttons array */
- size_t max_hats; /**< size of \c hats array */
+ size_t max_axes; /**< size of \c axes array */
+ size_t max_buttons; /**< size of \c buttons array */
+ size_t max_hats; /**< size of \c hats array */
/** \brief Emulated machine's joystick port associated with host device */
- int joyport;
+ int joyport;
/** \brief Private arch-specific data
*
@@ -293,7 +293,7 @@
* For example: the Linux driver stores a \c joy_priv_t object here that
* contains a file descriptor and a \c struct libevdev instance.
*/
- void *priv;
+ void *priv;
} joystick_device_t;
@@ -409,8 +409,12 @@
joystick_hat_t *hat);
void joystick_mapping_init (joystick_mapping_t *mapping);
-void joystick_axis_init (joystick_axis_t *axis);
-void joystick_button_init (joystick_button_t *button);
-void joystick_hat_init (joystick_hat_t *hat);
+joystick_axis_t *joystick_axis_new (const char *name);
+void joystick_axis_free (joystick_axis_t *axis);
+joystick_button_t *joystick_button_new (const char *name);
+void joystick_button_free (joystick_button_t *button);
+joystick_hat_t *joystick_hat_new (const char *name);
+void joystick_hat_free (joystick_hat_t *hat);
+
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <co...@us...> - 2025-03-11 17:32:55
|
Revision: 45523
http://sourceforge.net/p/vice-emu/code/45523
Author: compyx
Date: 2025-03-11 17:32:47 +0000 (Tue, 11 Mar 2025)
Log Message:
-----------
Joystick: Linux: avoid iteration in input index lookups
Keep maps of event codes to indexes in `joy_priv_t` to avoid having to iterate
over arrays of axes or buttons to determine their index based on the event code
obtained during polling. Adds array of 63 integers [0x100..0x13e] for buttons,
41 integers [0x00..0x28] for axes (per joystick device), removes two functions.
Modified Paths:
--------------
branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_linux_evdev.c
Modified: branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_linux_evdev.c
===================================================================
--- branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_linux_evdev.c 2025-03-11 12:11:53 UTC (rev 45522)
+++ branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_linux_evdev.c 2025-03-11 17:32:47 UTC (rev 45523)
@@ -91,16 +91,8 @@
typedef struct joy_priv_s {
struct libevdev *evdev; /**< evdev instance */
int fd; /**< file descriptor */
-#if 0
- char *name; /**< device name */
- uint16_t vendor; /**< vendor ID */
- uint16_t product; /**< product ID */
- uint16_t version; /**< product version */
- uint32_t num_axes; /**< number of axes */
- uint32_t num_buttons; /**< number of buttons */
- joy_axis_t axes[NUM_AXES_MAX]; /**< list of axes */
- uint16_t buttons[NUM_BUTTONS_MAX]; /**< list of buttons */
-#endif
+ int32_t axis_index[NUM_AXES_MAX]; /**< axis indexes per code [0x00..0x28] */
+ int32_t button_index[NUM_BUTTONS_MAX]; /**< button indexes per code [0x100-0x13e] */
} joy_priv_t;
@@ -108,68 +100,6 @@
static log_t joy_evdev_log;
-#if 0
-/** \brief Initialize joystick axis data
- *
- * \param[in] axis joystick axis data
- */
-static void joy_axis_init(joy_axis_t *axis)
-{
- axis->code = 0;
- axis->minimum = INT16_MIN;
- axis->maximum = INT16_MAX;
-}
-#endif
-
-/** \brief Get index of axis event code
- *
- * \param[in] priv driver-specific joystick data
- * \param[in] code axis event code
- *
- * \return index in axes array or -1 when not found
- */
-static int joy_axis_index(joystick_device_t *joydev, uint32_t code)
-{
- int i;
-
- /* ABS_X (AXIS_CODE_MIN) is 0 and comparing unsigned for < 0 is alway false */
- if (code > AXIS_CODE_MAX) {
- return -1;
- }
- for (i = 0; i < joydev->num_axes; i++) {
- if (joydev->axes[i].code == code) {
- return i;
- } else if (joydev->axes[i].code > code) {
- return -1; /* axis codes are stored in order */
- }
- }
- return -1;
-}
-
-/** \brief Get index of button event code
- *
- * \param[in] priv driver-specific joystick data
- * \param[in] code button event code
- *
- * \return index in buttons array or -1 when not found
- */
-static int joy_button_index(joystick_device_t *joydev, uint32_t code)
-{
- int i;
-
- if (code < BUTTON_CODE_MIN || code > BUTTON_CODE_MAX) {
- return -1;
- }
- for (i = 0; i < joydev->num_buttons; i++) {
- if (joydev->buttons[i].code == code) {
- return i;
- } else if (joydev->buttons[i].code > code) {
- return -1; /* button codes are stored in order */
- }
- }
- return -1;
-}
-
/** \brief Allocate and initialize driver-specific joystick data
*
* \return new data instance, free with \c lib_free()
@@ -181,6 +111,8 @@
priv = lib_malloc(sizeof *priv);
priv->fd = -1;
priv->evdev = NULL;
+ memset(&priv->axis_index, -1, sizeof *priv->axis_index);
+ memset(&priv->button_index, -1, sizeof *priv->button_index);
return priv;
}
@@ -212,15 +144,16 @@
joystick_device_t *joydev,
struct input_event *event)
{
- int index;
+ joy_priv_t *priv = joydev->priv;
+ int index;
if (event->type == EV_KEY) {
-
+#if 0
printf("button %02x (%s): %d\n",
event->code, libevdev_event_code_get_name(EV_KEY, event->code),
event->value);
-
- index = joy_button_index(joydev, event->code);
+#endif
+ index = priv->button_index[event->code - BUTTON_CODE_MIN];
if (index >= 0) {
joy_button_event((uint8_t)joyport, (uint8_t)index, (uint8_t)event->value);
}
@@ -230,7 +163,7 @@
event->code, libevdev_event_code_get_name(EV_ABS, event->code),
event->value);
#endif
- index = joy_axis_index(joydev, event->code);
+ index = priv->axis_index[event->code - AXIS_CODE_MIN];
if (index >= 0) {
int32_t minimum = joydev->axes[index].minimum;
int32_t maximum = joydev->axes[index].maximum;
@@ -360,16 +293,19 @@
static void scan_buttons(joystick_device_t *joydev, struct libevdev *evdev)
{
if (libevdev_has_event_type(evdev, EV_KEY)) {
- unsigned int code;
+ uint32_t code;
for (code = BUTTON_CODE_MIN; code <= BUTTON_CODE_MAX; code++) {
if (libevdev_has_event_code(evdev, EV_KEY, code)) {
- joystick_button_t button;
+ joy_priv_t *priv = joydev->priv;
+ joystick_button_t button;
joystick_button_init(&button);
- button.code = (uint16_t)code;
+ button.code = code;
/* need to copy since event_code_get_name() returns const char* */
button.name = lib_strdup(libevdev_event_code_get_name(EV_KEY, code));
+ /* store index in buttons array */
+ priv->button_index[code - BUTTON_CODE_MIN] = joydev->num_buttons;
joystick_device_add_button(joydev, &button);
lib_free(button.name);
}
@@ -385,7 +321,8 @@
static void scan_axes(joystick_device_t *joydev, struct libevdev *evdev)
{
if (libevdev_has_event_type(evdev, EV_ABS)) {
- unsigned int code;
+ joy_priv_t *priv = joydev->priv;
+ uint32_t code;
for (code = AXIS_CODE_MIN; code <= AXIS_CODE_MAX; code++) {
if (libevdev_has_event_code(evdev, EV_ABS, code)) {
@@ -394,12 +331,13 @@
info = libevdev_get_abs_info(evdev, code);
joystick_axis_init(&axis);
- axis.code = (uint16_t)code;
+ axis.code = code;
axis.name = lib_strdup(libevdev_event_code_get_name(EV_ABS, code));
if (info != NULL) {
axis.minimum = info->minimum;
axis.maximum = info->maximum;
}
+ priv->axis_index[code - AXIS_CODE_MIN] = joydev->num_axes;
joystick_device_add_axis(joydev, &axis);
lib_free(axis.name);
}
@@ -407,55 +345,6 @@
}
}
-#if 0
-/** \brief Scan possible joystick device for capabilities
- *
- * Try to open \a node and process with libevdev to determine its capabilities.
- *
- * Determines supported button event codes and axis event codes, along with
- * axis minimum/maximum values for correct translation into axis direction.
- *
- * \param[in] node node name in \c /dev/input/
- *
- * \return new \c joy_priv_t instance on success, \c NULL on failure
- */
-static joy_priv_t *scan_device(const char *node)
-{
- struct libevdev *evdev;
- joy_priv_t *priv;
- char path[256];
- int fd;
- int rc;
-
- snprintf(path, sizeof path, "/dev/input/%s", node);
-
- fd = open(path, O_RDONLY|O_NONBLOCK);
- if (fd < 0) {
- return NULL;
- }
-
- rc = libevdev_new_from_fd(fd, &evdev);
- if (rc < 0) {
- log_error(LOG_DEFAULT, "failed to initialize libevdev: %s", strerror(rc));
- close(fd);
- return NULL;
- }
-
- priv = joy_priv_new();
- priv->name = lib_strdup(libevdev_get_name(evdev));
- priv->vendor = (uint16_t)libevdev_get_id_vendor(evdev);
- priv->product = (uint16_t)libevdev_get_id_product(evdev);
- priv->version = (uint16_t)libevdev_get_id_version(evdev);
- priv->evdev = evdev;
- priv->fd = fd;
-
- scan_axes(priv, evdev);
- scan_buttons(priv, evdev);
-
- return priv;
-}
-#endif
-
static joystick_device_t *scan_device(const char *node)
{
joystick_device_t *joydev;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <co...@us...> - 2025-03-11 12:11:56
|
Revision: 45522
http://sourceforge.net/p/vice-emu/code/45522
Author: compyx
Date: 2025-03-11 12:11:53 +0000 (Tue, 11 Mar 2025)
Log Message:
-----------
Joystick: add `index` field to axis, button and hat objects
Store object's index in its container in the object, to keep the current
index-based object passing intact while working towards passing objects to
event handlers instead of simple indexes.
Modified Paths:
--------------
branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_linux_evdev.c
branches/compyx/joymap-001/vice/src/joyport/joystick.c
branches/compyx/joymap-001/vice/src/joyport/joystick.h
Modified: branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_linux_evdev.c
===================================================================
--- branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_linux_evdev.c 2025-03-10 20:58:55 UTC (rev 45521)
+++ branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_linux_evdev.c 2025-03-11 12:11:53 UTC (rev 45522)
@@ -77,14 +77,6 @@
#define NUM_BUTTONS_MAX (BUTTON_CODE_MAX - BUTTON_CODE_MIN + 1u)
-/** \brief Joystick axis object
- */
-typedef struct joy_axis_s {
- uint16_t code; /**< event code */
- int32_t minimum; /**< minimum value */
- int32_t maximum; /**< maximum value */
-} joy_axis_t;
-
/** \brief Driver-specific joystick data
*
* Contains data required by the evdev driver that isn't stored in the generic
@@ -136,7 +128,7 @@
*
* \return index in axes array or -1 when not found
*/
-static int joy_axis_index(joystick_device_t *joydev, uint16_t code)
+static int joy_axis_index(joystick_device_t *joydev, uint32_t code)
{
int i;
@@ -161,7 +153,7 @@
*
* \return index in buttons array or -1 when not found
*/
-static int joy_button_index(joystick_device_t *joydev, uint16_t code)
+static int joy_button_index(joystick_device_t *joydev, uint32_t code)
{
int i;
Modified: branches/compyx/joymap-001/vice/src/joyport/joystick.c
===================================================================
--- branches/compyx/joymap-001/vice/src/joyport/joystick.c 2025-03-10 20:58:55 UTC (rev 45521)
+++ branches/compyx/joymap-001/vice/src/joyport/joystick.c 2025-03-11 12:11:53 UTC (rev 45522)
@@ -3440,6 +3440,7 @@
axis->code = 0;
axis->name = NULL;
axis->prev = 0;
+ axis->index = -1;
axis->minimum = INT16_MIN;
axis->maximum = INT16_MAX;
axis->digital = false;
@@ -3450,9 +3451,10 @@
void joystick_button_init(joystick_button_t *button)
{
- button->code = 0;
- button->name = NULL;
- button->prev = 0;
+ button->code = 0;
+ button->name = NULL;
+ button->prev = 0;
+ button->index = -1;
joystick_mapping_init(&button->mapping);
}
@@ -3459,9 +3461,10 @@
void joystick_hat_init(joystick_hat_t *hat)
{
- hat->code = 0;
- hat->name = NULL;
- hat->prev = 0;
+ hat->code = 0;
+ hat->name = NULL;
+ hat->prev = 0;
+ hat->index = -1;
joystick_mapping_init(&hat->mapping.up);
joystick_mapping_init(&hat->mapping.down);
joystick_mapping_init(&hat->mapping.left);
@@ -3484,8 +3487,9 @@
new_button = &joydev->buttons[joydev->num_buttons];
joystick_button_init(new_button);
- new_button->code = button->code;
- new_button->name = lib_strdup(button->name);
+ new_button->code = button->code;
+ new_button->name = lib_strdup(button->name);
+ new_button->index = joydev->num_buttons;
joydev->num_buttons++;
}
@@ -3515,6 +3519,7 @@
joystick_axis_init(new_axis);
new_axis->code = axis->code;
new_axis->name = lib_strdup(axis->name);
+ new_axis->index = joydev->num_axes;
new_axis->minimum = axis->minimum;
new_axis->maximum = axis->maximum;
new_axis->digital = (bool)((axis->minimum == -1) && (axis->maximum == 1));
@@ -3536,8 +3541,9 @@
new_hat = &joydev->hats[joydev->num_hats];
joystick_hat_init(new_hat);
- new_hat->code = hat->code;
- new_hat->name = lib_strdup(hat->name);
+ new_hat->code = hat->code;
+ new_hat->name = lib_strdup(hat->name);
+ new_hat->index = joydev->num_hats;
joydev->num_hats++;
}
Modified: branches/compyx/joymap-001/vice/src/joyport/joystick.h
===================================================================
--- branches/compyx/joymap-001/vice/src/joyport/joystick.h 2025-03-10 20:58:55 UTC (rev 45521)
+++ branches/compyx/joymap-001/vice/src/joyport/joystick.h 2025-03-11 12:11:53 UTC (rev 45522)
@@ -180,9 +180,10 @@
* Information on a host device button input.
*/
typedef struct joystick_button_s {
- uint16_t code; /**< event code */
+ uint32_t code; /**< event code */
char *name; /**< button name */
int32_t prev; /**< previous polled value */
+ int32_t index; /**< index in buttons array */
joystick_mapping_t mapping; /**< button mapping */
/* TODO: add calibration data struct */
} joystick_button_t;
@@ -193,8 +194,9 @@
* Information on a host device axis input.
*/
typedef struct joystick_axis_s {
- uint16_t code; /**< axis event code */
+ uint32_t code; /**< axis event code */
char *name; /**< axis name */
+ int32_t index; /**< index in hats array */
int32_t prev; /**< previous polled value */
/* capabilities (TODO: more data like fuzz, flat) */
int32_t minimum; /**< minimum axis value */
@@ -219,8 +221,9 @@
* Information on a host device hat input.
*/
typedef struct joystick_hat_s {
- uint16_t code; /**< hat event code */
+ uint32_t code; /**< hat event code */
char *name; /**< hat name */
+ int32_t index; /**< index in hats array (for the old API) */
int32_t prev; /**< previous polled value */
struct {
joystick_mapping_t up; /**< mapping for 'up' direction */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <co...@us...> - 2025-03-10 20:59:03
|
Revision: 45521
http://sourceforge.net/p/vice-emu/code/45521
Author: compyx
Date: 2025-03-10 20:58:55 +0000 (Mon, 10 Mar 2025)
Log Message:
-----------
Joystick: BSD: implement rudimentary polling
Polling "works", except apparently hid reports on inputs come in some
undefined order, so our default mappings fail horribly.
Modified Paths:
--------------
branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_bsd.c
Modified: branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_bsd.c
===================================================================
--- branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_bsd.c 2025-03-10 16:38:39 UTC (rev 45520)
+++ branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_bsd.c 2025-03-10 20:58:55 UTC (rev 45521)
@@ -145,7 +145,9 @@
if (p->fd >= 0) {
close(p->fd);
}
- lib_free(p->buffer);
+ if (p->buffer != NULL) {
+ lib_free(p->buffer);
+ }
if (p->rep_desc != NULL) {
hid_dispose_report_desc(p->rep_desc);
}
@@ -158,16 +160,142 @@
return true; /* NOP */
}
-static void bsd_joy_poll (int joyport, joystick_device_t *joydev)
+
+static int joy_axis_index(joystick_device_t *joydev, uint16_t code)
{
- /* NOP */
+ int i;
+
+ for (i = 0; i < joydev->num_axes; i++) {
+ if (joydev->axes[i].code == code) {
+ return i;
+ }
+ /* axis codes are *not* stored in-order like with Linux evdev, so we
+ * must finish the loop */
+ }
+ return -1;
}
+static int joy_button_index(joystick_device_t *joydev, uint16_t code)
+{
+ int i;
+
+ for (i = 0; i < joydev->num_buttons; i++) {
+ if (joydev->buttons[i].code == code) {
+ return i;
+ }
+ /* button codes are *not* stored in-order like with Linux evdev, so we
+ * must finish the loop */
+ }
+ return -1;
+}
+
+static int joy_hat_index(joystick_device_t *joydev, uint16_t code)
+{
+ int i;
+
+ for (i = 0; i < joydev->num_hats; i++) {
+ if (joydev->hats[i].code == code) {
+ return i;
+ }
+ /* hat codes are *not* stored in-order like with Linux evdev, so we
+ * must finish the loop */
+ }
+ return -1;
+}
+
+
+static void bsd_joy_poll(int joyport, joystick_device_t *joydev)
+{
+ joy_priv_t *priv = joydev->priv;
+
+ if (priv != NULL && priv->fd >= 0) {
+ ssize_t rsize;
+
+ while ((rsize = read(priv->fd, priv->buffer, (size_t)priv->rep_size)) == priv->rep_size) {
+ struct hid_data *data;
+ struct hid_item item;
+ int index;
+
+ data = hid_start_parse(priv->rep_desc, 1 << hid_input, priv->rep_id);
+ if (data == NULL) {
+ return;
+ }
+
+ while (hid_get_item(data, &item) > 0) {
+ int value = hid_get_data(priv->buffer, &item);
+ int usage = HID_USAGE(item.usage);
+ unsigned int page = HID_PAGE(item.usage);
+
+ switch (page) {
+ case HUP_GENERIC_DESKTOP:
+ switch (usage) {
+ case HUG_X: /* fall through */
+ case HUG_Y: /* fall through */
+ case HUG_Z: /* fall through */
+ case HUG_RX: /* fall through */
+ case HUG_RY: /* fall through */
+ case HUG_RZ: /* fall through */
+ case HUG_SLIDER:
+ /* axis */
+ index = joy_axis_index(joydev, (uint16_t)usage);
+ if (index >= 0) {
+ //joy_axis_event(joyport, (uint8_t)index, (uint8_t)value);
+ }
+ break;
+
+ case HUG_HAT_SWITCH:
+ /* hat */
+ index = joy_hat_index(joydev, (uint16_t)usage);
+ if (index >= 0) {
+ //joy_hat_event(joyport, (uint8_t)index, (uint8_t)value);
+ }
+ break;
+
+ case HUG_D_PAD_UP: /* fall through */
+ case HUG_D_PAD_DOWN: /* fall through */
+ case HUG_D_PAD_LEFT: /* fall through */
+ case HUG_D_PAD_RIGHT:
+ /* D-Pad is mapped as buttons */
+ index = joy_button_index(joydev, (uint16_t)usage);
+ if (index >= 0) {
+ joy_button_event(joyport, (uint8_t)index, (uint8_t)value);
+ }
+ break;
+ default:
+ break;
+ }
+ break;
+ case HUP_BUTTON:
+ /* button event */
+ index = joy_button_index(joydev, (uint16_t)usage);
+ if (index >= 0) {
+ joy_button_event(joyport, (uint8_t)index, (uint8_t)value);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ hid_end_parse(data);
+ }
+
+ if (rsize != -1 && errno != EAGAIN) {
+ log_warning(bsd_joy_log,
+ "weird report size: %zd: %s",
+ rsize, strerror(errno));
+ }
+ }
+}
+
static void bsd_joy_close(joystick_device_t *joydev)
{
- /* NOP */
+ if (joydev != NULL && joydev->priv != NULL) {
+ joy_priv_free(joydev->priv);
+ joydev->priv = NULL;
+ }
}
+
/** \brief scandir select callback
*
* Check if name matches "uhid?*".
@@ -283,7 +411,7 @@
joystick_axis_t axis;
joystick_axis_init(&axis);
- axis.code = (uint16_t)HID_USAGE(item->usage);
+ axis.code = (uint16_t)HID_USAGE(item->usage);
axis.name = lib_strdup(hid_usage_in_page(item->usage));
axis.minimum = item->logical_minimum;
axis.maximum = item->logical_maximum;
@@ -403,6 +531,9 @@
*
* \param[in] node device node to scan
*
+ * \todo Order axes, buttons and hats by HID_USAGE() (event code), otherwise
+ * our default mappings fail spectacularly =D
+ *
* \return new joystick device instance or <tt>NULL</tt> on error
*/
static joystick_device_t *scan_device(const char *node)
@@ -447,9 +578,9 @@
*/
void bsd_joystick_init(void)
{
- struct dirent **namelist = NULL;
+struct dirent **namelist = NULL;
int nl_count;
- int n;
+int n;
bsd_joy_log = log_open("BSD Joystick");
log_message(bsd_joy_log, "Registering driver.");
@@ -472,6 +603,7 @@
return;
}
+ /* scan uhid device nodes and register valid joystick devices */
for (n = 0; n < nl_count; n++) {
joystick_device_t *joydev;
char *node;
@@ -480,11 +612,22 @@
joydev = scan_device(node);
if (joydev != NULL) {
log_message(bsd_joy_log, "%s: %s", joydev->node, joydev->name);
- if (!scan_inputs(joydev)) {
+ /* scan axes, buttons and hats */
+ if (scan_inputs(joydev)) {
+ /* OK: try to register */
+ if (!joystick_device_register(joydev)) {
+ /* failure */
+ log_warning(bsd_joy_log,
+ "failed to register device %s (\"%s\")",
+ joydev->node, joydev->name);
+ joystick_device_free(joydev);
+ }
+ } else {
+ log_warning(bsd_joy_log,
+ "failed to scan inputs for device %s (\"%s\")",
+ joydev->node, joydev->name);
joystick_device_free(joydev);
}
-
- joystick_device_free(joydev);
}
lib_free(node);
free(namelist[n]);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <co...@us...> - 2025-03-10 16:38:42
|
Revision: 45520
http://sourceforge.net/p/vice-emu/code/45520
Author: compyx
Date: 2025-03-10 16:38:39 +0000 (Mon, 10 Mar 2025)
Log Message:
-----------
Joystick: BSD: implement enumerating axes, buttons and hats
Obtain code, name and limits on axes, buttons and hats and register them.
Also implement the missing `joystick_device_add_hat()` in shared code.
Modified Paths:
--------------
branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_bsd.c
branches/compyx/joymap-001/vice/src/joyport/joystick.c
Modified: branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_bsd.c
===================================================================
--- branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_bsd.c 2025-03-10 14:44:06 UTC (rev 45519)
+++ branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_bsd.c 2025-03-10 16:38:39 UTC (rev 45520)
@@ -99,6 +99,7 @@
static void bsd_joy_close(joystick_device_t *joydev);
static void joy_priv_free(void *priv);
+
/** \brief Log for BSD joystick driver */
static log_t bsd_joy_log;
@@ -111,6 +112,12 @@
};
+/** \brief Allocate new private data object
+ *
+ * Allocate and initialize private data object instance.
+ *
+ * \return new data object
+ */
static joy_priv_t *joy_priv_new(void)
{
joy_priv_t *priv = lib_malloc(sizeof *priv);
@@ -123,6 +130,13 @@
return priv;
}
+/** \brief Free private data instance
+ *
+ * Free private data object and its resources.
+ * Closes file descriptor, cleans up HID report descriptor and free HID buffer.
+ *
+ * \param[in] priv private data object
+ */
static void joy_priv_free(void *priv)
{
joy_priv_t *p = priv;
@@ -139,7 +153,6 @@
}
}
-
static bool bsd_joy_open (int joyport, joystick_device_t *joydev)
{
return true; /* NOP */
@@ -155,7 +168,6 @@
/* NOP */
}
-
/** \brief scandir select callback
*
* Check if name matches "uhid?*".
@@ -191,7 +203,6 @@
return path;
}
-
/** \brief Open device for HID usage
*
* Open \c node and get associated HID data from it for scanning/polling.
@@ -260,7 +271,140 @@
return priv;
}
+/** \brief Add axis to joystick device
+ *
+ * \param[in] joydev joystick device
+ * \param[in] item HID item with axis information
+ *
+ */
+static void add_joy_axis(joystick_device_t *joydev,
+ const struct hid_item *item)
+{
+ joystick_axis_t axis;
+ joystick_axis_init(&axis);
+ axis.code = (uint16_t)HID_USAGE(item->usage);
+ axis.name = lib_strdup(hid_usage_in_page(item->usage));
+ axis.minimum = item->logical_minimum;
+ axis.maximum = item->logical_maximum;
+
+ log_message(bsd_joy_log, "axis %u: %s", (unsigned int)axis.code, axis.name);
+ joystick_device_add_axis(joydev, &axis);
+ lib_free(axis.name);
+}
+
+/** \brief Add button to joystick device
+ *
+ * \param[in] joydev joystick device
+ * \param[in] item HID item with button information
+ */
+static void add_joy_button(joystick_device_t *joydev,
+ const struct hid_item *item)
+{
+ joystick_button_t button;
+
+ joystick_button_init(&button);
+ button.code = (uint16_t)HID_USAGE(item->usage);
+ /* NetBSD usbhid man page lies, function below returns `const char *`,
+ * not `char *`, so we need a temporary copy:
+ */
+ button.name = lib_strdup(hid_usage_in_page(item->usage));
+ log_message(bsd_joy_log, "button %u: %s", (unsigned int)button.code, button.name);
+ joystick_device_add_button(joydev, &button);
+ lib_free(button.name);
+}
+
+/** \brief Add hat to joystick device
+ *
+ * \param[in] joydev joystick device
+ * \param[in] item HID item with hat information
+ */
+static void add_joy_hat(joystick_device_t *joydev,
+ const struct hid_item *item)
+{
+ joystick_hat_t hat;
+
+ joystick_hat_init(&hat);
+ hat.code = (uint16_t)HID_USAGE(item->usage);
+ hat.name = lib_strdup(hid_usage_in_page(item->usage));
+ log_message(bsd_joy_log, "hat %u: %s", (unsigned int)hat.code, hat.name);
+ joystick_device_add_hat(joydev, &hat);
+ lib_free(hat.name);
+}
+
+/** \brief Scan device for inputs
+ *
+ * Scan \a joydev for axes, buttons and hats and register them with \a joydev.
+ *
+ * \param[in] joydev joystick device
+ *
+ * \return \c true on succes
+ */
+static bool scan_inputs(joystick_device_t *joydev)
+{
+ joy_priv_t *priv;
+ struct hid_data *hdata;
+ struct hid_item hitem;
+
+ priv = joydev->priv;
+ hdata = hid_start_parse(priv->rep_desc, 1 << hid_input, priv->rep_id);
+ if (hdata == NULL) {
+ log_error(bsd_joy_log, "hid_start_parse() failed: %s,", strerror(errno));
+ return false;
+ }
+
+ while (hid_get_item(hdata, &hitem) > 0) {
+ unsigned int page = HID_PAGE (hitem.usage);
+ int usage = HID_USAGE(hitem.usage);
+
+ switch (page) {
+ case HUP_GENERIC_DESKTOP:
+ switch (usage) {
+ case HUG_X: /* fall through */
+ case HUG_Y: /* fall through */
+ case HUG_Z: /* fall through */
+ case HUG_RX: /* fall through */
+ case HUG_RY: /* fall through */
+ case HUG_RZ: /* fall through */
+ case HUG_SLIDER:
+ /* got an axis */
+ add_joy_axis(joydev, &hitem);
+ break;
+ case HUG_HAT_SWITCH:
+ /* hat, seems to be D-Pad on Logitech F710 */
+ add_joy_hat(joydev, &hitem);
+ break;
+ case HUG_D_PAD_UP: /* fall through */
+ case HUG_D_PAD_DOWN: /* fall through */
+ case HUG_D_PAD_LEFT: /* fall through */
+ case HUG_D_PAD_RIGHT:
+ /* treat D-Pad as buttons */
+ add_joy_button(joydev, &hitem);
+ break;
+ default:
+ break;
+ }
+ break;
+ case HUP_BUTTON:
+ /* usage appears to be the button number */
+ add_joy_button(joydev, &hitem);
+ break;
+ default:
+ break;
+ }
+ }
+
+ hid_end_parse(hdata);
+ return true;
+}
+
+
+/** \brief Scan joystick device for capabilities
+ *
+ * \param[in] node device node to scan
+ *
+ * \return new joystick device instance or <tt>NULL</tt> on error
+ */
static joystick_device_t *scan_device(const char *node)
{
joystick_device_t *joydev;
@@ -294,14 +438,13 @@
joydev->vendor = devinfo.udi_vendorNo;
joydev->product = devinfo.udi_productNo;
- /* TODO: scan inputs */
-
-
joydev->priv = priv;
return joydev;
}
+/** \brief Initialize BSD joystick driver and add available devices
+ */
void bsd_joystick_init(void)
{
struct dirent **namelist = NULL;
@@ -312,6 +455,11 @@
log_message(bsd_joy_log, "Registering driver.");
joystick_driver_register(&driver);
+ /* Initialize HID library so we can retrieve strings for page and usage;
+ * without this button names will be "0x00001" etc, not very informative.
+ */
+ hid_init(NULL);
+
log_message(bsd_joy_log, "Scanning available devices:");
nl_count = scandir(ROOT_NODE, &namelist, sd_select, NULL);
if (nl_count < 0) {
@@ -328,12 +476,13 @@
joystick_device_t *joydev;
char *node;
- node = full_node_path(namelist[n]->d_name);
-// log_message(bsd_joy_log, "scanning %s", node);
-
+ node = full_node_path(namelist[n]->d_name);
joydev = scan_device(node);
if (joydev != NULL) {
log_message(bsd_joy_log, "%s: %s", joydev->node, joydev->name);
+ if (!scan_inputs(joydev)) {
+ joystick_device_free(joydev);
+ }
joystick_device_free(joydev);
}
Modified: branches/compyx/joymap-001/vice/src/joyport/joystick.c
===================================================================
--- branches/compyx/joymap-001/vice/src/joyport/joystick.c 2025-03-10 14:44:06 UTC (rev 45519)
+++ branches/compyx/joymap-001/vice/src/joyport/joystick.c 2025-03-10 16:38:39 UTC (rev 45520)
@@ -3521,3 +3521,23 @@
joydev->num_axes++;
}
+
+
+void joystick_device_add_hat(joystick_device_t *joydev,
+ joystick_hat_t *hat)
+{
+ joystick_hat_t *new_hat;
+
+ if (joydev->num_hats == joydev->max_hats) {
+ joydev->num_hats *= 2;
+ joydev->hats = lib_realloc(joydev->hats,
+ sizeof *joydev->hats * (size_t)joydev->max_hats);
+ }
+
+ new_hat = &joydev->hats[joydev->num_hats];
+ joystick_hat_init(new_hat);
+ new_hat->code = hat->code;
+ new_hat->name = lib_strdup(hat->name);
+
+ joydev->num_hats++;
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <co...@us...> - 2025-03-10 14:44:18
|
Revision: 45519
http://sourceforge.net/p/vice-emu/code/45519
Author: compyx
Date: 2025-03-10 14:44:06 +0000 (Mon, 10 Mar 2025)
Log Message:
-----------
Joystick: BSD: wrap opening and getting HID report data in separate function
Add `joy_hid_open()` to open() a device and get HID report desc, ID and size and allocate a buffer for parsing reports. To be used in a future `open()` method of the driver as well as device capability scanning.
Modified Paths:
--------------
branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_bsd.c
Modified: branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_bsd.c
===================================================================
--- branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_bsd.c 2025-03-10 10:14:46 UTC (rev 45518)
+++ branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_bsd.c 2025-03-10 14:44:06 UTC (rev 45519)
@@ -87,7 +87,7 @@
typedef struct joy_priv_s {
void *buffer;
report_desc_t rep_desc;
- ssize_t rep_size;
+ int rep_size;
int rep_id;
int fd;
} joy_priv_t;
@@ -192,32 +192,32 @@
}
-static joystick_device_t *scan_device(const char *node)
+/** \brief Open device for HID usage
+ *
+ * Open \c node and get associated HID data from it for scanning/polling.
+ * This function opens the device and allocates a buffer for HID reports, gets
+ * the report ID and size and allocates a \c joy_priv_t instance with all that
+ * data.
+ *
+ * \param[in] node path in <tt>/dev/</tt> to the device
+ *
+ * \return new initialized \c joy_priv_t instance or <tt>NULL</tt> on error
+ */
+static joy_priv_t *joy_hid_open(const char *node)
{
- joystick_device_t *joydev;
- joy_priv_t *priv;
- struct usb_device_info devinfo;
- report_desc_t report;
- int rep_id;
- int rep_size;
- int fd;
- char *name;
+ joy_priv_t *priv;
+ report_desc_t rep_desc;
+ int rep_id;
+ int rep_size;
+ int fd;
-
- fd = open(node, O_RDONLY, O_NONBLOCK);
+ fd = open(node, O_RDONLY|O_NONBLOCK);
if (fd < 0) {
- /* don't log error, BSD allocates 16 nodes in /dev, not all valid*/
- /* log_error(bsd_joy_log, "failed to open %s: %s", node, strerror(errno)); */
+ /* don't log, (Net)BSD allocates a lot of nodes in /dev that aren't
+ * actually valid */
return NULL;
}
- /* get device info for vendor and product */
- if (ioctl(fd, USB_GET_DEVICEINFO, &devinfo) < 0) {
- log_error(bsd_joy_log, "failed to get USB device info: %s", strerror(errno));
- close(fd);
- return NULL;
- }
-
/* get report ID if possible, else asume 0 */
#ifdef USB_GET_REPORT_ID
if (ioctl(fd, USB_GET_REPORT_ID, &rep_id) < 0) {
@@ -229,8 +229,9 @@
rep_id = 0;
#endif
- report = hid_get_report_desc(fd);
- if (report == NULL) {
+ /* get report description */
+ rep_desc = hid_get_report_desc(fd);
+ if (rep_desc == NULL) {
log_error(bsd_joy_log,
"failed to get HID report for %s: %s",
node, strerror(errno));
@@ -238,14 +239,47 @@
return NULL;
}
- rep_size = hid_report_size(report, hid_input, rep_id);
+ /* get report size */
+ rep_size = hid_report_size(rep_desc, hid_input, rep_id);
if (rep_size <= 0) {
log_error(bsd_joy_log, "invalid report size of %d", rep_size);
- hid_dispose_report_desc(report);
+ hid_dispose_report_desc(rep_desc);
close(fd);
return NULL;
}
+ /* success: allocate private data object and store what we need for polling
+ * and further querying */
+ priv = joy_priv_new();
+ priv->buffer = lib_malloc((size_t)rep_size);
+ priv->rep_desc = rep_desc;
+ priv->rep_size = rep_size;
+ priv->rep_id = rep_id;
+ priv->fd = fd;
+
+ return priv;
+}
+
+
+static joystick_device_t *scan_device(const char *node)
+{
+ joystick_device_t *joydev;
+ joy_priv_t *priv;
+ struct usb_device_info devinfo;
+ char *name;
+
+ /* try to open device and get HID report information */
+ priv = joy_hid_open(node);
+ if (priv == NULL) {
+ return NULL;
+ }
+
+ /* get device info for vendor and product */
+ if (ioctl(priv->fd, USB_GET_DEVICEINFO, &devinfo) < 0) {
+ log_error(bsd_joy_log, "failed to get USB device info: %s", strerror(errno));
+ joy_priv_free(priv);
+ return NULL;
+ }
if (*devinfo.udi_vendor == '\0' && *devinfo.udi_product == '\0') {
/* fall back to device node as name */
name = lib_strdup(node);
@@ -262,12 +296,6 @@
/* TODO: scan inputs */
- priv = joy_priv_new();
- priv->buffer = lib_malloc((size_t)rep_size);
- priv->rep_desc = report;
- priv->rep_size = rep_size;
- priv->rep_id = rep_id;
- priv->fd = fd; /* can be removed once we actually use driver->open() */
joydev->priv = priv;
return joydev;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <co...@us...> - 2025-03-10 10:14:59
|
Revision: 45518
http://sourceforge.net/p/vice-emu/code/45518
Author: compyx
Date: 2025-03-10 10:14:46 +0000 (Mon, 10 Mar 2025)
Log Message:
-----------
Joystick: start work on NetBSD/FreeBSD driver
Delete all old code and start from scratch. Scanning '/dev/uhid?*' works with
some basic info gathered like device name, node, vendor and product, along with
HID report data to be used for polling later.
Modified Paths:
--------------
branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_bsd.c
branches/compyx/joymap-001/vice/src/joyport/joystick.c
branches/compyx/joymap-001/vice/src/joyport/joystick.h
Modified: branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_bsd.c
===================================================================
--- branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_bsd.c 2025-03-09 14:29:02 UTC (rev 45517)
+++ branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_bsd.c 2025-03-10 10:14:46 UTC (rev 45518)
@@ -1,8 +1,7 @@
/** \file joystick_bsd.c
- * \brief NetBSD/FreeBSD/DragonFly USB joystick support
+ * \brief NetBSD/FreeBSD USB joystick support
*
- * \author Dieter Baron <di...@ni...>
- * \author Marco van den Heuvel <bla...@ya...>
+ * \author Bas Wassink <b.w...@zi...>
*
* \todo Check if this code also works on OpenBSD.
*/
@@ -30,11 +29,46 @@
#include "vice.h"
-
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <errno.h>
+#include <dirent.h>
#include <fcntl.h>
-#include <stdio.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
#include <unistd.h>
+#include <usbhid.h>
+#ifdef FREEBSD_COMPILE
+/* for hid_* and HUG_* */
+#include <dev/hid/hid.h>
+/* for struct usb_device_info */
+#include <dev/usb/usb_ioctl.h>
+#endif
+
+#ifdef NETBSD_COMPILE
+#include <dev/usb/usb.h>
+#include <dev/usb/usbhid.h>
+#include <dev/hid/hid.h>
+
+/* FreeBSD (9.3) doesn't have the D-Pad defines */
+#ifndef HUG_D_PAD_UP
+#define HUG_D_PAD_UP 0x0090
+#endif
+#ifndef HUG_D_PAD_DOWN
+#define HUG_D_PAD_DOWN 0x0091
+#endif
+#ifndef HUG_D_PAD_RIGHT
+#define HUG_D_PAD_RIGHT 0x0092
+#endif
+#ifndef HUG_D_PAD_LEFT
+#define HUG_D_PAD_LEFT 0x0093
+#endif
+
+#endif /* NETBSD_COMPILE */
+
#include "cmdline.h"
#include "joystick.h"
#include "keyboard.h"
@@ -42,346 +76,242 @@
#include "log.h"
#include "resources.h"
#include "types.h"
+#include "util.h"
+#define ROOT_NODE "/dev"
+#define ROOT_NODE_LEN 4
+#define NODE_PREFIX "uhid"
+#define NODE_PREFIX_LEN 4
-#define ITEM_AXIS 0
-#define ITEM_BUTTON 1
-#define ITEM_HAT 2
-static log_t bsd_joystick_log;
+typedef struct joy_priv_s {
+ void *buffer;
+ report_desc_t rep_desc;
+ ssize_t rep_size;
+ int rep_id;
+ int fd;
+} joy_priv_t;
-#ifdef HAVE_USB_H
-#include <usb.h>
-#endif
-#ifdef DRAGONFLYBSD_COMPILE
-/* sys/param.h contains the __DragonFly_version macro */
-# include <sys/param.h>
-# if __DragonFly_version >= 300200
-/* DragonFly >= 3.2 (USB4BSD stack) */
-# include <bus/u4b/usb.h>
-# include <bus/u4b/usbhid.h>
-# else
-/* DragonFly < 3.2: old USB stack */
-# include <bus/usb/usb.h>
-# include <bus/usb/usbhid.h>
-# endif
-#else
-# ifdef FREEBSD_COMPILE
-# include <sys/ioccom.h>
-# endif
-# include <dev/usb/usb.h>
-# include <dev/usb/usbhid.h>
-#endif
+/* Forward declarations */
+static bool bsd_joy_open (int joyport, joystick_device_t *joydev);
+static void bsd_joy_poll (int joyport, joystick_device_t *joydev);
+static void bsd_joy_close(joystick_device_t *joydev);
+static void joy_priv_free(void *priv);
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
+/** \brief Log for BSD joystick driver */
+static log_t bsd_joy_log;
-#if defined(HAVE_USBHID_H)
-#include <usbhid.h>
-#elif defined(HAVE_LIBUSB_H)
-#include <libusb.h>
-#elif defined(HAVE_LIBUSBHID_H)
-#include <libusbhid.h>
-#endif
+/** \brief BSD joystick driver declaration */
+static joystick_driver_t driver = {
+ .open = bsd_joy_open,
+ .poll = bsd_joy_poll,
+ .close = bsd_joy_close,
+ .priv_free = joy_priv_free
+};
-#define MAX_DEV 16 /* number of uhid devices to try (NetBSD 9.3 has 16
- /dev/uhid* nodes) */
+static joy_priv_t *joy_priv_new(void)
+{
+ joy_priv_t *priv = lib_malloc(sizeof *priv);
-/*
- * This hat map was created from values observed on NetBSD 9.2
- * with an analog joystick "ADDISON TECHNOLOGY" that also has a hat switch.
- * uhidev1 at uhub1 port 6 configuration 1 interface 0
- * uhidev1: vendor 0907 (0x907) product 0523 (0x523), rev 1.00/1.00, addr 40, iclass 3/0
- * uhid0 at uhidev1: input=3, output=0, feature=0
- *
- * Only 0 and the odd values (horizontal and vertical) were observed
- * but let's leave the diagonals in too, just in case.
- *
- * There are apparently hats with 0 for neutral and 1 for up, and some
- * with 8 for neutral and 0 for up. The other values are off by 1.
- * We try to autodetect, by seeing which of 0 or 8 occurs first.
- * We report no direction until one of those is seen.
- */
-#define MAX_HAT_MAP_INDEX 8
-static const uint8_t hat_map[MAX_HAT_MAP_INDEX + 2] = {
- 0, /* 0 */
- JOYSTICK_DIRECTION_UP, /* 1 */
- JOYSTICK_DIRECTION_UP | JOYSTICK_DIRECTION_RIGHT, /* 2 */
- JOYSTICK_DIRECTION_RIGHT, /* 3 */
- JOYSTICK_DIRECTION_RIGHT | JOYSTICK_DIRECTION_DOWN, /* 4 */
- JOYSTICK_DIRECTION_DOWN, /* 5 */
- JOYSTICK_DIRECTION_DOWN | JOYSTICK_DIRECTION_LEFT, /* 6 */
- JOYSTICK_DIRECTION_LEFT, /* 7 */
- JOYSTICK_DIRECTION_LEFT | JOYSTICK_DIRECTION_UP, /* 8 */
- 0, /* 9 */
-};
+ priv->buffer = NULL;
+ priv->rep_desc = NULL;
+ priv->rep_size = 0;
+ priv->fd = -1;
+ priv->rep_id = 0;
+ return priv;
+}
-struct usb_joy_item {
- struct hid_item item;
- struct usb_joy_item *next;
+static void joy_priv_free(void *priv)
+{
+ joy_priv_t *p = priv;
- int type;
- int min_val;
- int max_val;
- int ordinal_number;
-};
+ if (p != NULL) {
+ if (p->fd >= 0) {
+ close(p->fd);
+ }
+ lib_free(p->buffer);
+ if (p->rep_desc != NULL) {
+ hid_dispose_report_desc(p->rep_desc);
+ }
+ lib_free(p);
+ }
+}
-typedef struct bsd_joystick_priv_s {
- struct usb_joy_item *usb_joy_item;
- char *usb_joy_buf;
- int usb_joy_fd;
- int usb_joy_size;
-} bsd_joystick_priv_t;
-static void usb_joy_add_item(struct usb_joy_item **item, struct hid_item *hi, int orval, int type)
+static bool bsd_joy_open (int joyport, joystick_device_t *joydev)
{
- struct usb_joy_item *it;
- int w;
+ return true; /* NOP */
+}
- it = lib_malloc(sizeof *it);
- it->next = *item;
- *item = it;
+static void bsd_joy_poll (int joyport, joystick_device_t *joydev)
+{
+ /* NOP */
+}
- memcpy(&it->item, hi, sizeof(*hi));
- it->type = type;
- it->ordinal_number = orval;
-
- switch (type) {
- case ITEM_AXIS:
- w = (hi->logical_maximum - hi->logical_minimum) / 3;
- it->min_val = hi->logical_minimum + w;
- it->max_val = hi->logical_maximum - w;
- break;
- case ITEM_BUTTON:
- it->min_val = hi->logical_minimum;
- it->max_val = hi->logical_maximum - 1;
- break;
- case ITEM_HAT:
- it->min_val = -1; /* mapping not autodetected yet */
- break;
- }
+static void bsd_joy_close(joystick_device_t *joydev)
+{
+ /* NOP */
}
-static void usb_free_item(struct usb_joy_item **item)
+
+/** \brief scandir select callback
+ *
+ * Check if name matches "uhid?*".
+ *
+ * \param[in] de directory entry
+ *
+ * \return non-0 when matching "uhid?*"
+ */
+static int sd_select(const struct dirent *de)
{
- struct usb_joy_item *it, *it2;
+ const char *name = de->d_name;
- it=*item;
- while (it) {
- it2 = it;
- it = it->next;
- lib_free(it2);
- }
- *item = NULL;
+ return ((strlen(name) >= NODE_PREFIX_LEN + 1u) &&
+ (strncmp(NODE_PREFIX, name, NODE_PREFIX_LEN) == 0));
}
-static void usb_joystick_close(void* priv)
+/** \brief Get full path of UHID device node
+ *
+ * \param[in] node node in /dev/
+ *
+ * \return full path to \a node
+ * \note free with \c lib_free() after use
+ */
+static char *full_node_path(const char *node)
{
- bsd_joystick_priv_t *joypriv = priv;
- close(joypriv->usb_joy_fd);
- usb_free_item(&joypriv->usb_joy_item);
- lib_free(priv);
+ size_t nlen = strlen(node);
+ size_t plen = ROOT_NODE_LEN + 1u + nlen + 1u;
+ char *path = lib_malloc(plen);
+
+ memcpy(path, ROOT_NODE, ROOT_NODE_LEN);
+ path[ROOT_NODE_LEN] = '/';
+ memcpy(path + ROOT_NODE_LEN + 1, node, nlen + 1u);
+ return path;
}
-static void usb_joystick(int jp, void* priv)
+
+static joystick_device_t *scan_device(const char *node)
{
- int val;
- ssize_t ret;
- struct usb_joy_item *it;
- bsd_joystick_priv_t *joypriv = priv;
+ joystick_device_t *joydev;
+ joy_priv_t *priv;
+ struct usb_device_info devinfo;
+ report_desc_t report;
+ int rep_id;
+ int rep_size;
+ int fd;
+ char *name;
- val = 0;
- while ((ret = read(joypriv->usb_joy_fd, joypriv->usb_joy_buf, joypriv->usb_joy_size)) == joypriv->usb_joy_size) {
- val = 1;
+
+ fd = open(node, O_RDONLY, O_NONBLOCK);
+ if (fd < 0) {
+ /* don't log error, BSD allocates 16 nodes in /dev, not all valid*/
+ /* log_error(bsd_joy_log, "failed to open %s: %s", node, strerror(errno)); */
+ return NULL;
}
- if (ret != -1 && errno != EAGAIN) {
- /* XXX */
- log_warning(bsd_joystick_log, "strange read return: %zd/%d", ret, errno);
- return;
+
+ /* get device info for vendor and product */
+ if (ioctl(fd, USB_GET_DEVICEINFO, &devinfo) < 0) {
+ log_error(bsd_joy_log, "failed to get USB device info: %s", strerror(errno));
+ close(fd);
+ return NULL;
}
- if (!val) {
- return;
+
+ /* get report ID if possible, else asume 0 */
+#ifdef USB_GET_REPORT_ID
+ if (ioctl(fd, USB_GET_REPORT_ID, &rep_id) < 0) {
+ log_warning(bsd_joy_log, "USB_GET_REPORT_ID failed.");
+ close(fd);
+ return NULL;
}
+#else
+ rep_id = 0;
+#endif
- for (it = joypriv->usb_joy_item; it; it = it->next) {
- val = hid_get_data(joypriv->usb_joy_buf, &it->item);
- if (it->type == ITEM_HAT) {
- if (val >= 0 && val <= MAX_HAT_MAP_INDEX) {
- /* Autodect if 0 is neutral, or 8 */
- if (it->min_val < 0) {
- if (val == 0) {
- it->min_val = 0;
- } else if (val == 8) {
- it->min_val = 1;
- } else {
- /* Not yet autodetected */
- }
- /* Report neutral position for now */
- joy_hat_event(jp, it->ordinal_number, 0);
- } else {
- val += it->min_val;
- joy_hat_event(jp, it->ordinal_number, hat_map[val]);
- }
- }
- } else {
- if (it->type == ITEM_BUTTON) {
- joy_button_event(jp, it->ordinal_number, val);
- } else if (val <= it->min_val) {
- joy_axis_event(jp, it->ordinal_number, JOY_AXIS_NEGATIVE);
- } else if (val > it->max_val) {
- joy_axis_event(jp, it->ordinal_number, JOY_AXIS_POSITIVE);
- } else {
- joy_axis_event(jp, it->ordinal_number, JOY_AXIS_MIDDLE);
- }
- }
+ report = hid_get_report_desc(fd);
+ if (report == NULL) {
+ log_error(bsd_joy_log,
+ "failed to get HID report for %s: %s",
+ node, strerror(errno));
+ close(fd);
+ return NULL;
}
-}
-static joystick_driver_t bsd_joystick_driver = {
- .poll = usb_joystick,
- .close = usb_joystick_close
-};
+ rep_size = hid_report_size(report, hid_input, rep_id);
+ if (rep_size <= 0) {
+ log_error(bsd_joy_log, "invalid report size of %d", rep_size);
+ hid_dispose_report_desc(report);
+ close(fd);
+ return NULL;
+ }
-void usb_joystick_init(void)
-{
- int j, id = 0, fd;
- report_desc_t report;
- struct hid_item h;
- struct hid_data *d;
- char dev[32];
- char name[20];
- int next_ordinal_to_assign;
- int ordinal_to_assign;
- int found_x;
- int found_y;
- struct usb_joy_item *it;
- char axes = 0, buttons = 0, hats = 0;
- bsd_joystick_priv_t *priv;
- int usb_joy_size;
+ if (*devinfo.udi_vendor == '\0' && *devinfo.udi_product == '\0') {
+ /* fall back to device node as name */
+ name = lib_strdup(node);
+ } else {
+ name = util_concat(devinfo.udi_vendor, " ", devinfo.udi_product, NULL);
+ }
- for (j=0; j<MAX_DEV; j++) {
- axes = 0;
- buttons = 0;
- hats = 0;
- next_ordinal_to_assign = 0;
+ /* now we can allocate the joystick device instance and its data */
+ joydev = joystick_device_new();
+ joydev->node = lib_strdup(node);
+ joydev->name = name;
+ joydev->vendor = devinfo.udi_vendorNo;
+ joydev->product = devinfo.udi_productNo;
- sprintf(dev, "/dev/uhid%d", j);
- fd = open(dev, O_RDONLY | O_NONBLOCK);
- if (fd < 0) {
- continue;
- }
+ /* TODO: scan inputs */
-#if defined(USB_GET_REPORT_ID) && !defined(DRAGONFLYBSD_COMPILE)
- if (ioctl(fd, USB_GET_REPORT_ID, &id) < 0) {
- log_warning(bsd_joystick_log, "Cannot get report id for joystick device `%s'.", dev);
- close(fd);
- }
-#endif
+ priv = joy_priv_new();
+ priv->buffer = lib_malloc((size_t)rep_size);
+ priv->rep_desc = report;
+ priv->rep_size = rep_size;
+ priv->rep_id = rep_id;
+ priv->fd = fd; /* can be removed once we actually use driver->open() */
- if ((report=hid_get_report_desc(fd)) == NULL) {
- log_warning(bsd_joystick_log, "Cannot report description for joystick device `%s'.", dev);
- close(fd);
- continue;
- }
- usb_joy_size = hid_report_size(report, hid_input, id);
+ joydev->priv = priv;
+ return joydev;
+}
- next_ordinal_to_assign = 2;
- found_x = 0;
- found_y = 0;
- priv = NULL;
-#if !defined(HAVE_USBHID_H) && !defined(HAVE_LIBUSB_H) && defined(HAVE_LIBUSBHID)
- for (d = hid_start_parse(report, id);
-#else
- for (d = hid_start_parse(report, 1 << hid_input, id);
-#endif
- hid_get_item(d, &h);) {
- if (h.kind == hid_collection && HID_PAGE(h.usage) == HUP_GENERIC_DESKTOP && (HID_USAGE(h.usage) == HUG_JOYSTICK || HID_USAGE(h.usage) == HUG_GAME_PAD)) {
- if (priv == NULL) {
- priv = lib_malloc(sizeof(bsd_joystick_priv_t));
- priv->usb_joy_size = usb_joy_size;
- priv->usb_joy_item = NULL;
- }
- continue;
- }
- if (!priv) {
- continue;
- }
+void bsd_joystick_init(void)
+{
+ struct dirent **namelist = NULL;
+ int nl_count;
+ int n;
- switch (HID_PAGE(h.usage)) {
- case HUP_GENERIC_DESKTOP:
- switch (HID_USAGE(h.usage)) {
- case HUG_X:
- case HUG_RX:
- if (!found_x) {
- ordinal_to_assign = 0;
- } else {
- ordinal_to_assign = next_ordinal_to_assign;
- }
- usb_joy_add_item(&priv->usb_joy_item, &h, ordinal_to_assign, ITEM_AXIS);
- axes++;
- if (!found_x) {
- found_x = 1;
- } else {
- next_ordinal_to_assign++;
- }
- break;
- case HUG_Y:
- case HUG_RY:
- if (!found_y) {
- ordinal_to_assign = 1;
- } else {
- ordinal_to_assign = next_ordinal_to_assign;
- }
- usb_joy_add_item(&priv->usb_joy_item, &h, ordinal_to_assign, ITEM_AXIS);
- axes++;
- if (!found_y) {
- found_y = 1;
- } else {
- next_ordinal_to_assign++;
- }
- break;
- case HUG_HAT_SWITCH:
- usb_joy_add_item(&priv->usb_joy_item, &h, hats, ITEM_HAT);
- hats++;
- break;
- }
- break;
- case HUP_BUTTON:
- usb_joy_add_item(&priv->usb_joy_item, &h, buttons, ITEM_BUTTON);
- buttons++;
- break;
- }
- }
+ bsd_joy_log = log_open("BSD Joystick");
+ log_message(bsd_joy_log, "Registering driver.");
+ joystick_driver_register(&driver);
- hid_end_parse(d);
- hid_dispose_report_desc(report);
- if (!priv) {
- continue;
- }
- if (!found_x || !found_y) {
- next_ordinal_to_assign = 0;
- for (it = priv->usb_joy_item; it; it = it->next) {
- if (it->type == ITEM_AXIS) {
- it->ordinal_number = next_ordinal_to_assign++;
- }
- }
- }
+ log_message(bsd_joy_log, "Scanning available devices:");
+ nl_count = scandir(ROOT_NODE, &namelist, sd_select, NULL);
+ if (nl_count < 0) {
+ log_warning(bsd_joy_log,
+ "scandir(\"%s/%s?*\") failed, giving up.",
+ ROOT_NODE, NODE_PREFIX);
+ return;
+ } else if (nl_count == 0) {
+ log_message(bsd_joy_log, "no devices found.");
+ return;
+ }
- if ((priv->usb_joy_buf = malloc(priv->usb_joy_size)) == NULL) {
- log_warning(bsd_joystick_log, "Cannot allocate buffer for joystick device `%s'.", dev);
- close(fd);
- usb_free_item(&priv->usb_joy_item);
- lib_free(priv);
- continue;
+ for (n = 0; n < nl_count; n++) {
+ joystick_device_t *joydev;
+ char *node;
+
+ node = full_node_path(namelist[n]->d_name);
+// log_message(bsd_joy_log, "scanning %s", node);
+
+ joydev = scan_device(node);
+ if (joydev != NULL) {
+ log_message(bsd_joy_log, "%s: %s", joydev->node, joydev->name);
+
+ joystick_device_free(joydev);
}
+ lib_free(node);
+ free(namelist[n]);
+ }
- log_message(bsd_joystick_log, "USB joystick found: `%s'.", dev);
- priv->usb_joy_fd = fd;
- snprintf(name, sizeof(name), "Joystick %d", j);
- register_joystick_driver(&bsd_joystick_driver, name, priv, axes, buttons, hats);
- }
+ free(namelist);
}
Modified: branches/compyx/joymap-001/vice/src/joyport/joystick.c
===================================================================
--- branches/compyx/joymap-001/vice/src/joyport/joystick.c 2025-03-09 14:29:02 UTC (rev 45517)
+++ branches/compyx/joymap-001/vice/src/joyport/joystick.c 2025-03-10 10:14:46 UTC (rev 45518)
@@ -2721,7 +2721,7 @@
#elif defined(HAVE_LINUX_EVDEV)
linux_joystick_evdev_init();
#elif defined HAS_USB_JOYSTICK
- usb_joystick_init();
+ bsd_joystick_init();
#elif defined MAC_JOYSTICK
joy_hidlib_init();
#elif defined HAVE_DINPUT
Modified: branches/compyx/joymap-001/vice/src/joyport/joystick.h
===================================================================
--- branches/compyx/joymap-001/vice/src/joyport/joystick.h 2025-03-09 14:29:02 UTC (rev 45517)
+++ branches/compyx/joymap-001/vice/src/joyport/joystick.h 2025-03-10 10:14:46 UTC (rev 45518)
@@ -348,7 +348,7 @@
void linux_joystick_init(void);
void linux_joystick_evdev_init(void);
-void usb_joystick_init(void);
+void bsd_joystick_init(void);
void joy_hidlib_init(void);
void joy_hidlib_exit(void);
int win32_directinput_joystick_init(void);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <co...@us...> - 2025-03-09 14:29:10
|
Revision: 45517
http://sourceforge.net/p/vice-emu/code/45517
Author: compyx
Date: 2025-03-09 14:29:02 +0000 (Sun, 09 Mar 2025)
Log Message:
-----------
Joystick: remove last remnant of old driver reference, update documentation
Remove driver reference in joystick objects, calls go directly through the
single global driver reference.
Properly document the `joystick_driver_t`, `joystick_device_t`, `joystick_axis_t`,
`joystick_button_t` and `joystick_hat_t` structs.
Add some TODO reminders for calibration data and support of non-on/off pots
(to support mapping axes to paddles and pointing/drawing devices).
Modified Paths:
--------------
branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_linux_evdev.c
branches/compyx/joymap-001/vice/src/joyport/joystick.c
branches/compyx/joymap-001/vice/src/joyport/joystick.h
Modified: branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_linux_evdev.c
===================================================================
--- branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_linux_evdev.c 2025-03-09 13:12:37 UTC (rev 45516)
+++ branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_linux_evdev.c 2025-03-09 14:29:02 UTC (rev 45517)
@@ -554,7 +554,6 @@
joydev->name, joydev->num_axes, joydev->num_buttons);
joystick_device_free(joydev);
} else {
- joydev->driver = &driver;
log_message(joy_evdev_log,
"Adding device: %s [%04x:%04x] (%d axes, %d buttons)",
joydev->name,
Modified: branches/compyx/joymap-001/vice/src/joyport/joystick.c
===================================================================
--- branches/compyx/joymap-001/vice/src/joyport/joystick.c 2025-03-09 13:12:37 UTC (rev 45516)
+++ branches/compyx/joymap-001/vice/src/joyport/joystick.c 2025-03-09 14:29:02 UTC (rev 45517)
@@ -3204,7 +3204,7 @@
{
int i;
for (i = 0; i < num_joystick_devices; i++) {
- joystick_devices[i]->driver->poll(i, joystick_devices[i]);
+ joy_driver.poll(i, joystick_devices[i]);
}
}
Modified: branches/compyx/joymap-001/vice/src/joyport/joystick.h
===================================================================
--- branches/compyx/joymap-001/vice/src/joyport/joystick.h 2025-03-09 13:12:37 UTC (rev 45516)
+++ branches/compyx/joymap-001/vice/src/joyport/joystick.h 2025-03-09 14:29:02 UTC (rev 45517)
@@ -1,11 +1,12 @@
-/*
- * joystick.h - Common joystick emulation.
+/** \file joystick.h
+ * \brief Common joystick emulation.
*
- * Written by
- * Andreas Boose <vic...@t-...>
- * Marco van den Heuvel <bla...@ya...>
- *
- * This file is part of VICE, the Versatile Commodore Emulator.
+ * \author Andreas Boose <vic...@t-...>
+ * \author Marco van den Heuvel <bla...@ya...>
+ * \author Bas Wassink <b.w...@zi...>
+ */
+
+/* This file is part of VICE, the Versatile Commodore Emulator.
* See README for copyright notice.
*
* This program is free software; you can redistribute it and/or modify
@@ -105,11 +106,12 @@
*/
#define JOYDEV_NAME_SIZE 0x80
-
+/** \brief Digital axis values
+ */
typedef enum joystick_axis_value_e {
- JOY_AXIS_NEGATIVE = -1,
- JOY_AXIS_MIDDLE = 0,
- JOY_AXIS_POSITIVE = 1
+ JOY_AXIS_NEGATIVE = -1, /**< negative direction (usually up or left) */
+ JOY_AXIS_MIDDLE = 0, /**< middle, centered position */
+ JOY_AXIS_POSITIVE = 1 /**< positive direction (usually down or right) */
} joystick_axis_value_t;
/** \brief Hat direction joystick input index values
@@ -157,6 +159,7 @@
JOY_INPUT_MAX = JOY_INPUT_BALL
} joystick_input_t;
+
/* Input mapping for each direction/button/etc */
typedef struct joystick_mapping_s {
/* Action to perform */
@@ -172,38 +175,23 @@
} joystick_mapping_t;
-typedef struct joystick_axis_mapping_s {
- /* Previous state of input */
- uint8_t prev;
- struct joystick_mapping_s positive_direction;
- struct joystick_mapping_s negative_direction;
- uint8_t pot;
-} joystick_axis_mapping_t;
-
-typedef struct joystick_button_mapping_s {
- /* Previous state of input */
- uint8_t prev;
- struct joystick_mapping_s mapping;
-} joystick_button_mapping_t;
-
-typedef struct joystick_hat_mapping_s {
- /* Previous state of input */
- uint8_t prev;
- struct joystick_mapping_s up;
- struct joystick_mapping_s down;
- struct joystick_mapping_s left;
- struct joystick_mapping_s right;
-} joystick_hat_mapping_t;
-
-
+/** \brief Joystick button object
+ *
+ * Information on a host device button input.
+ */
typedef struct joystick_button_s {
- uint16_t code;
- char *name;
- int32_t prev;
- joystick_mapping_t mapping;
+ uint16_t code; /**< event code */
+ char *name; /**< button name */
+ int32_t prev; /**< previous polled value */
+ joystick_mapping_t mapping; /**< button mapping */
/* TODO: add calibration data struct */
} joystick_button_t;
+
+/** \brief Joystick axis object
+ *
+ * Information on a host device axis input.
+ */
typedef struct joystick_axis_s {
uint16_t code; /**< axis event code */
char *name; /**< axis name */
@@ -214,76 +202,122 @@
bool digital; /**< axis is digital (reports -1, 0, 1) */
struct {
- joystick_mapping_t negative;
- joystick_mapping_t positive;
- unsigned int pot;
- } mapping;
+ joystick_mapping_t negative; /**< negative direction */
+ joystick_mapping_t positive; /**< positive direction */
+ unsigned int pot; /**< pot index (0 or 1) */
+ } mapping; /**< mapping for negative and positive directions, and
+ pot. TODO: support pot values other than on/off so
+ emulated paddles and mice can be mapped to axes. */
+ /* TODO: add calibration data */
+
} joystick_axis_t;
+
+/** \brief Joystick hat object
+ *
+ * Information on a host device hat input.
+ */
typedef struct joystick_hat_s {
- uint16_t code;
- char *name;
- int32_t prev;
+ uint16_t code; /**< hat event code */
+ char *name; /**< hat name */
+ int32_t prev; /**< previous polled value */
struct {
- joystick_mapping_t up;
- joystick_mapping_t down;
- joystick_mapping_t left;
- joystick_mapping_t right;
- } mapping;
+ joystick_mapping_t up; /**< mapping for 'up' direction */
+ joystick_mapping_t down; /**< mapping for 'down' direction */
+ joystick_mapping_t left; /**< mapping for 'left' direction */
+ joystick_mapping_t right; /**< mapping for 'right' direction */
+ } mapping; /**< mappings per direction */
} joystick_hat_t;
-/* device structure */
+/** \brief Joystick device object
+ *
+ * Contains all information on a host joystick device.
+ */
typedef struct joystick_device_s {
- /* to be removed */
- struct joystick_driver_s *driver;
-#if 0
- joystick_axis_mapping_t *axis_mapping;
- joystick_button_mapping_t *button_mapping;
- joystick_hat_mapping_t *hat_mapping;
-#endif
+ /** \brief Device name ("<vendor-name> <product-name>") */
+ char *name;
- char *name;
+ /** \brief Arch-specific device identifier
+ *
+ * Path or UUID use to identify the device for the driver's \c open()
+ * method to (re)open the device for use.
+ * For example on Linux this will be a "file" in the <tt>/dev/input/</tt>
+ * directory.
+ */
char *node;
+
+ /** \brief HID vendor ID */
uint16_t vendor;
+
+ /** \brief HID product ID */
uint16_t product;
- /* these array elements contain names, codes, capabilities and mappings */
+ /** \brief List of axes */
joystick_axis_t *axes;
+
+ /** \brief List of buttons */
joystick_button_t *buttons;
+
+ /** \brief List of hats */
joystick_hat_t *hats;
+ /** \brief Number of axes */
int num_axes;
- int num_hats;
+
+ /** \brief Number of buttons */
int num_buttons;
+ /** \brief Number of hats */
+ int num_hats;
+
/* bookkeeping for resizing arrays when adding elements */
- size_t max_axes;
- size_t max_buttons;
- size_t max_hats;
+ size_t max_axes; /**< size of \c axes array */
+ size_t max_buttons; /**< size of \c buttons array */
+ size_t max_hats; /**< size of \c hats array */
+ /** \brief Emulated machine's joystick port associated with host device */
int joyport;
+
+ /** \brief Private arch-specific data
+ *
+ * An arch-specific driver can store data here that cannot be portably
+ * contained in the core joystick data. This pointer will be passed to the
+ * driver's \c priv_free() method (if that method reference is non-NULL) on
+ * calling \c joystick_device_free().
+ *
+ * For example: the Linux driver stores a \c joy_priv_t object here that
+ * contains a file descriptor and a \c struct libevdev instance.
+ */
void *priv;
} joystick_device_t;
+/** \brief Host joystick driver object
+ *
+ * Methods to be called by the VICE core joystick code to open, poll and close
+ * devices, and to clean up on detaching/shutdown.
+ *
+ * The arch-specific code is required to call \c joystick_driver_register() to
+ * register itself on emulator startup. (TODO: maybe have the core code request
+ * this somehow?).
+ */
typedef struct joystick_driver_s {
- bool (*open)(int, joystick_device_t *);
- void (*poll)(int, joystick_device_t *);
- void (*close)(joystick_device_t *);
+ /** \brief Open host device for specific machine port */
+ bool (*open) (int, joystick_device_t *);
+
+ /** \brief Poll host device for specific machine port */
+ void (*poll) (int, joystick_device_t *);
+
+ /** \brief Close host device */
+ void (*close) (joystick_device_t *);
+
+ /** \brief Optional method to free arch-specific device data */
void (*priv_free)(void *);
} joystick_driver_t;
-void register_joystick_driver(
- struct joystick_driver_s *driver,
- const char *jname,
- void *priv,
- int num_axes,
- int num_buttons,
- int num_hats);
-
int joystick_init(void);
int joystick_resources_init(void);
int joystick_cmdline_options_init(void);
@@ -358,7 +392,7 @@
#endif
-void joystick_driver_register(const joystick_driver_t *driver);
+void joystick_driver_register (const joystick_driver_t *driver);
joystick_device_t *joystick_device_new (void);
void joystick_device_free (joystick_device_t *joydev);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <co...@us...> - 2025-03-09 13:12:43
|
Revision: 45516
http://sourceforge.net/p/vice-emu/code/45516
Author: compyx
Date: 2025-03-09 13:12:37 +0000 (Sun, 09 Mar 2025)
Log Message:
-----------
Joystick: Major rewrite of driver and device handling
Restructure `joystick_device_t`: add `joystick_axis_t`, `joystick_button_t` and
joystick_hat_t` arrays that contain data on indivual inputs, like name, event
code and limits; mappings (`joystick_mapping_t` are now contained within the
axis, button and hat structures. Calibration data will be added to the input
structs at a later time.
Register a single driver instead of having each device have its own driver
reference (which was the same for all drivers on any given OS/UI combination).
Add `open()` method to driver to allow (re)opening a device for input, and make
the `close()` method actually close the device without freeing all resources
associated with it, so reopening can work.
Add `joystick_device_free()` to actually free resources associated with a device:
used on shutdown and to be used on unplugging (if we ever add plug-n-play).
An additional `free_priv()` callback is added to the driver which will be called
to free arch-specific device data -- if required -- called from
`joystick_device_free()`.
Linux/Gtk3 only for now: the SDL, Windows, FreeBSD and NetBSD drivers will be
updated to work with the rewritten code next.
Modified Paths:
--------------
branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_linux_evdev.c
branches/compyx/joymap-001/vice/src/joyport/joystick.c
branches/compyx/joymap-001/vice/src/joyport/joystick.h
Modified: branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_linux_evdev.c
===================================================================
--- branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_linux_evdev.c 2025-03-05 17:05:34 UTC (rev 45515)
+++ branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_linux_evdev.c 2025-03-09 13:12:37 UTC (rev 45516)
@@ -97,16 +97,18 @@
* always reported in the INT16_MIN to INT16_MAX range.
*/
typedef struct joy_priv_s {
+ struct libevdev *evdev; /**< evdev instance */
+ int fd; /**< file descriptor */
+#if 0
char *name; /**< device name */
- struct libevdev *evdev; /**< evdev instance */
uint16_t vendor; /**< vendor ID */
uint16_t product; /**< product ID */
uint16_t version; /**< product version */
- int fd; /**< file descriptor */
uint32_t num_axes; /**< number of axes */
uint32_t num_buttons; /**< number of buttons */
joy_axis_t axes[NUM_AXES_MAX]; /**< list of axes */
uint16_t buttons[NUM_BUTTONS_MAX]; /**< list of buttons */
+#endif
} joy_priv_t;
@@ -114,6 +116,7 @@
static log_t joy_evdev_log;
+#if 0
/** \brief Initialize joystick axis data
*
* \param[in] axis joystick axis data
@@ -124,6 +127,7 @@
axis->minimum = INT16_MIN;
axis->maximum = INT16_MAX;
}
+#endif
/** \brief Get index of axis event code
*
@@ -132,18 +136,18 @@
*
* \return index in axes array or -1 when not found
*/
-static int32_t joy_axis_index(joy_priv_t *priv, uint16_t code)
+static int joy_axis_index(joystick_device_t *joydev, uint16_t code)
{
- uint32_t i;
+ int i;
/* ABS_X (AXIS_CODE_MIN) is 0 and comparing unsigned for < 0 is alway false */
if (code > AXIS_CODE_MAX) {
return -1;
}
- for (i = 0; i < priv->num_axes; i++) {
- if (priv->axes[i].code == code) {
- return (int32_t)i;
- } else if (priv->axes[i].code > code) {
+ for (i = 0; i < joydev->num_axes; i++) {
+ if (joydev->axes[i].code == code) {
+ return i;
+ } else if (joydev->axes[i].code > code) {
return -1; /* axis codes are stored in order */
}
}
@@ -157,17 +161,17 @@
*
* \return index in buttons array or -1 when not found
*/
-static int32_t joy_button_index(joy_priv_t *priv, uint16_t code)
+static int joy_button_index(joystick_device_t *joydev, uint16_t code)
{
- uint32_t i;
+ int i;
if (code < BUTTON_CODE_MIN || code > BUTTON_CODE_MAX) {
return -1;
}
- for (i = 0; i < priv->num_buttons; i++) {
- if (priv->buttons[i] == code) {
- return (int32_t)i;
- } else if (priv->buttons[i] > code) {
+ for (i = 0; i < joydev->num_buttons; i++) {
+ if (joydev->buttons[i].code == code) {
+ return i;
+ } else if (joydev->buttons[i].code > code) {
return -1; /* button codes are stored in order */
}
}
@@ -181,20 +185,10 @@
static joy_priv_t *joy_priv_new(void)
{
joy_priv_t *priv;
- size_t i;
priv = lib_malloc(sizeof *priv);
- priv->name = NULL;
- priv->evdev = NULL;
- priv->fd = -1;
- priv->num_axes = 0;
- priv->num_buttons = 0;
- for (i = 0; i < ARRAY_LEN(priv->buttons); i++) {
- priv->buttons[i] = 0;
- }
- for (i = 0; i < ARRAY_LEN(priv->axes); i++) {
- joy_axis_init(&(priv->axes[i]));
- }
+ priv->fd = -1;
+ priv->evdev = NULL;
return priv;
}
@@ -205,13 +199,14 @@
*
* \param[in] priv driver-specific joystick data
*/
-static void joy_priv_free(joy_priv_t *priv)
+static void joy_priv_free(void *priv)
{
if (priv != NULL) {
- lib_free(priv->name);
- libevdev_free(priv->evdev);
- close(priv->fd);
- lib_free(priv);
+ joy_priv_t *p = priv;
+
+ libevdev_free(p->evdev);
+ close(p->fd);
+ lib_free(p);
}
}
@@ -218,20 +213,22 @@
/** \brief Dispatcher for joystick events
*
* \param[in] joyport joystick port index
- * \param[in] priv driver-specific joystick data
+ * \param[in] joydev joystick device instance
* \param[in] event event data
*/
-static void dispatch_event(int joyport, joy_priv_t *priv, struct input_event *event)
+static void dispatch_event(int joyport,
+ joystick_device_t *joydev,
+ struct input_event *event)
{
- int32_t index;
+ int index;
if (event->type == EV_KEY) {
-#if 0
+
printf("button %02x (%s): %d\n",
event->code, libevdev_event_code_get_name(EV_KEY, event->code),
event->value);
-#endif
- index = joy_button_index(priv, event->code);
+
+ index = joy_button_index(joydev, event->code);
if (index >= 0) {
joy_button_event((uint8_t)joyport, (uint8_t)index, (uint8_t)event->value);
}
@@ -241,10 +238,10 @@
event->code, libevdev_event_code_get_name(EV_ABS, event->code),
event->value);
#endif
- index = joy_axis_index(priv, event->code);
+ index = joy_axis_index(joydev, event->code);
if (index >= 0) {
- int32_t minimum = priv->axes[index].minimum;
- int32_t maximum = priv->axes[index].maximum;
+ int32_t minimum = joydev->axes[index].minimum;
+ int32_t maximum = joydev->axes[index].maximum;
int32_t range = maximum - minimum + 1;
joystick_axis_value_t direction = JOY_AXIS_MIDDLE;
@@ -265,18 +262,51 @@
}
}
+static bool linux_joystick_evdev_open(int joyport, joystick_device_t *joydev)
+{
+ struct libevdev *evdev;
+ joy_priv_t *priv;
+ int fd;
+ int rc;
+
+ if (joydev == NULL || joydev->node == NULL) {
+ return false;
+ }
+
+ fd = open(joydev->node, O_RDONLY|O_NONBLOCK);
+ if (fd < 0) {
+ return false;
+ }
+
+ /* get evdev instance from file descriptor */
+ rc = libevdev_new_from_fd(fd, &evdev);
+ if (rc < 0) {
+ log_error(LOG_DEFAULT, "failed to initialize libevdev: %s", strerror(rc));
+ close(fd);
+ return false;
+ }
+
+ priv = joydev->priv;
+ priv->fd = fd;
+ priv->evdev = evdev;
+
+ return true;
+}
+
/** \brief Poll callback for the joystick system
*
* \param[in] joyport joystick port index
* \param[in] priv driver-specific joystick data
*/
-static void linux_joystick_evdev_poll(int joyport, void *priv)
+static void linux_joystick_evdev_poll(int joyport, joystick_device_t *joydev)
{
struct libevdev *evdev;
+ joy_priv_t *priv;
int rc;
unsigned int flags = LIBEVDEV_READ_FLAG_NORMAL;
- evdev = ((joy_priv_t *)priv)->evdev;
+ priv = joydev->priv;
+ evdev = priv->evdev;
while (libevdev_has_event_pending(evdev)) {
struct input_event event;
@@ -288,7 +318,7 @@
}
} else if (rc == LIBEVDEV_READ_STATUS_SUCCESS) {
if (event.type == EV_ABS || event.type == EV_KEY) {
- dispatch_event(joyport, priv, &event);
+ dispatch_event(joyport, joydev, &event);
}
}
}
@@ -300,9 +330,16 @@
*
* \param[in] priv driver-specific joystick data
*/
-static void linux_joystick_evdev_close(void *priv)
+static void linux_joystick_evdev_close(joystick_device_t *joydev)
{
- joy_priv_free(priv);
+ if (joydev != NULL && joydev->priv != NULL) {
+ joy_priv_t *priv = joydev->priv;
+
+ close(priv->fd);
+ libevdev_free(priv->evdev);
+ priv->fd = -1;
+ priv->evdev = NULL;
+ }
}
/** \brief Filter callback for scandir(3)
@@ -325,10 +362,10 @@
/** \brief Scan device for available buttons
*
- * \param[in] priv joystick private data
+ * \param[in] joydev joystick device instance
* \param[in] evdev libevdev instance
*/
-static void scan_buttons(joy_priv_t *priv, struct libevdev *evdev)
+static void scan_buttons(joystick_device_t *joydev, struct libevdev *evdev)
{
if (libevdev_has_event_type(evdev, EV_KEY)) {
unsigned int code;
@@ -335,7 +372,14 @@
for (code = BUTTON_CODE_MIN; code <= BUTTON_CODE_MAX; code++) {
if (libevdev_has_event_code(evdev, EV_KEY, code)) {
- priv->buttons[priv->num_buttons++] = (uint16_t)code;
+ joystick_button_t button;
+
+ joystick_button_init(&button);
+ button.code = (uint16_t)code;
+ /* need to copy since event_code_get_name() returns const char* */
+ button.name = lib_strdup(libevdev_event_code_get_name(EV_KEY, code));
+ joystick_device_add_button(joydev, &button);
+ lib_free(button.name);
}
}
}
@@ -343,10 +387,10 @@
/** \brief Scan device for available axes
*
- * \param[in] priv joystick private data
+ * \param[in] joydev joystick device instance
* \param[in] evdev libevdev instance
*/
-static void scan_axes(joy_priv_t *priv, struct libevdev *evdev)
+static void scan_axes(joystick_device_t *joydev, struct libevdev *evdev)
{
if (libevdev_has_event_type(evdev, EV_ABS)) {
unsigned int code;
@@ -354,20 +398,24 @@
for (code = AXIS_CODE_MIN; code <= AXIS_CODE_MAX; code++) {
if (libevdev_has_event_code(evdev, EV_ABS, code)) {
const struct input_absinfo *info;
- joy_axis_t *axis;
+ joystick_axis_t axis;
info = libevdev_get_abs_info(evdev, code);
- axis = &(priv->axes[priv->num_axes++]);
- axis->code = (uint16_t)code;
+ joystick_axis_init(&axis);
+ axis.code = (uint16_t)code;
+ axis.name = lib_strdup(libevdev_event_code_get_name(EV_ABS, code));
if (info != NULL) {
- axis->minimum = info->minimum;
- axis->maximum = info->maximum;
+ axis.minimum = info->minimum;
+ axis.maximum = info->maximum;
}
+ joystick_device_add_axis(joydev, &axis);
+ lib_free(axis.name);
}
}
}
}
+#if 0
/** \brief Scan possible joystick device for capabilities
*
* Try to open \a node and process with libevdev to determine its capabilities.
@@ -414,8 +462,50 @@
return priv;
}
+#endif
+static joystick_device_t *scan_device(const char *node)
+{
+ joystick_device_t *joydev;
+ struct libevdev *evdev;
+ joy_priv_t *priv;
+ char path[256];
+ int fd;
+ int rc;
+ snprintf(path, sizeof path, "/dev/input/%s", node);
+ fd = open(path, O_RDONLY|O_NONBLOCK);
+ if (fd < 0) {
+ return NULL;
+ }
+
+ /* get evdev instance from file descriptor */
+ rc = libevdev_new_from_fd(fd, &evdev);
+ if (rc < 0) {
+ log_error(LOG_DEFAULT, "failed to initialize libevdev: %s", strerror(rc));
+ close(fd);
+ return NULL;
+ }
+
+ /* create new joystick device instance and add data */
+ joydev = joystick_device_new();
+ joydev->name = lib_strdup(libevdev_get_name(evdev));
+ joydev->node = lib_strdup(path);
+ joydev->vendor = (uint16_t)libevdev_get_id_vendor(evdev);
+ joydev->product = (uint16_t)libevdev_get_id_product(evdev);
+
+ priv = joy_priv_new();
+ priv->fd = fd; /* TODO: remove once open() is implemented */
+ priv->evdev = evdev; /* TODO: remove once open() is implemented */
+ joydev->priv = priv;
+
+ /* scan for valid inputs */
+ scan_buttons(joydev, evdev);
+ scan_axes(joydev, evdev);
+ return joydev;
+}
+
+
/** \brief Object used to register driver for devices
*
* The address of this object is used in the joystick code, it isn't copied,
@@ -422,8 +512,10 @@
* so we cannot move this into `linux_joystick_init()` to use for registration.
*/
static joystick_driver_t driver = {
+ .open = linux_joystick_evdev_open,
.poll = linux_joystick_evdev_poll,
- .close = linux_joystick_evdev_close
+ .close = linux_joystick_evdev_close,
+ .priv_free = joy_priv_free
};
@@ -441,6 +533,7 @@
joy_evdev_log = log_open("evdev Joystick");
log_message(joy_evdev_log, "Initializing Linux evdev joystick driver.");
+ joystick_driver_register(&driver);
sd_result = scandir("/dev/input", &namelist, sd_filter, alphasort);
if (sd_result < 0) {
@@ -449,32 +542,32 @@
}
for (i = 0; i < sd_result; i++) {
- joy_priv_t *priv;
+ joystick_device_t *joydev;
- //log_message(joy_evdev_log, "Possible device '%s'", namelist[i]->d_name);
- priv = scan_device(namelist[i]->d_name);
- if (priv != NULL) {
- if (priv->num_axes < 2u || priv->num_buttons < 1u) {
+ log_message(joy_evdev_log, "Possible device '%s'", namelist[i]->d_name);
+ joydev = scan_device(namelist[i]->d_name);
+ if (joydev != NULL) {
+ if (joydev->num_axes < 2u || joydev->num_buttons < 1u) {
/* reject device */
log_message(joy_evdev_log,
- "Invalid geometry for %s: axes: %u, buttons: %u",
- priv->name,
- (unsigned int)priv->num_axes,
- (unsigned int)priv->num_buttons);
- joy_priv_free(priv);
+ "Invalid geometry for %s: axes: %d, buttons: %d",
+ joydev->name, joydev->num_axes, joydev->num_buttons);
+ joystick_device_free(joydev);
} else {
-#if 0
+ joydev->driver = &driver;
log_message(joy_evdev_log,
- "Adding device: %s [%04x:%04x] (%u axes, %u buttons)",
- priv->name,
- (unsigned int)priv->vendor, (unsigned int)priv->product,
- (unsigned int)priv->num_axes, (unsigned int)priv->num_buttons);
- joy_priv_free(priv);
-#endif
- register_joystick_driver(&driver, priv->name, priv, priv->num_axes, priv->num_buttons, 0);
+ "Adding device: %s [%04x:%04x] (%d axes, %d buttons)",
+ joydev->name,
+ (unsigned int)joydev->vendor, (unsigned int)joydev->product,
+ joydev->num_axes, joydev->num_buttons);
+
+ if (!joystick_device_register(joydev)) {
+ log_message(joy_evdev_log,
+ "Failed to add device, continuing with next device.");
+ joystick_device_free(joydev);
+ }
}
}
- free(namelist[i]);
}
free(namelist);
}
Modified: branches/compyx/joymap-001/vice/src/joyport/joystick.c
===================================================================
--- branches/compyx/joymap-001/vice/src/joyport/joystick.c 2025-03-05 17:05:34 UTC (rev 45515)
+++ branches/compyx/joymap-001/vice/src/joyport/joystick.c 2025-03-09 13:12:37 UTC (rev 45516)
@@ -35,6 +35,9 @@
#include <stdlib.h>
#include <string.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <assert.h>
#include "archdep.h"
#include "alarm.h"
@@ -172,6 +175,15 @@
static char *joymap_factory = NULL;
+static joystick_driver_t joy_driver = {
+ .open = NULL,
+ .poll = NULL,
+ .close = NULL,
+ .priv_free = NULL
+};
+
+
+
static log_t joy_log = LOG_DEFAULT;
static void joystick_latch_matrix(CLOCK offset)
@@ -801,52 +813,13 @@
return 0;
}
-typedef struct joystick_axis_mapping_s {
- /* Previous state of input */
- uint8_t prev;
- struct joystick_mapping_s positive_direction;
- struct joystick_mapping_s negative_direction;
- uint8_t pot;
-} joystick_axis_mapping_t;
-typedef struct joystick_button_mapping_s {
- /* Previous state of input */
- uint8_t prev;
- struct joystick_mapping_s mapping;
-} joystick_button_mapping_t;
-typedef struct joystick_hat_mapping_s {
- /* Previous state of input */
- uint8_t prev;
- struct joystick_mapping_s up;
- struct joystick_mapping_s down;
- struct joystick_mapping_s left;
- struct joystick_mapping_s right;
-} joystick_hat_mapping_t;
+static size_t num_joystick_devices = 0;
+static size_t max_joystick_devices = 0;
+static joystick_device_t **joystick_devices = NULL;
-static int num_joystick_devices = 0;
-/** \brief Joystick device name length (including 0)
- */
-#define JOYDEV_NAME_SIZE 0x80
-
-/* device structure */
-typedef struct joystick_device_s {
- struct joystick_driver_s *driver;
- char jname[JOYDEV_NAME_SIZE];
- int joyport;
- void *priv;
- joystick_axis_mapping_t *axis_mapping;
- joystick_button_mapping_t *button_mapping;
- joystick_hat_mapping_t *hat_mapping;
- int num_axes;
- int num_hats;
- int num_buttons;
-} joystick_device_t;
-
-
-static struct joystick_device_s *joystick_devices = NULL;
-
static int set_joystick_device(int val, void *param)
{
int port_idx = vice_ptr_to_int(param);
@@ -854,7 +827,7 @@
if (joystick_port_map[port_idx] >= JOYDEV_REALJOYSTICK_MIN) {
int olddev = joystick_port_map[port_idx] - JOYDEV_REALJOYSTICK_MIN;
if (olddev < num_joystick_devices) {
- joystick_devices[olddev].joyport = -1;
+ joystick_devices[olddev]->joyport = -1;
}
}
@@ -863,7 +836,7 @@
if (joystick_port_map[port_idx] >= JOYDEV_REALJOYSTICK_MIN) {
int newdev = joystick_port_map[port_idx] - JOYDEV_REALJOYSTICK_MIN;
if (newdev < num_joystick_devices) {
- joystick_devices[newdev].joyport = port_idx;
+ joystick_devices[newdev]->joyport = port_idx;
int i;
for (i = 0; i < JOYPORT_MAX_PORTS; i++) {
if (i != port_idx && joystick_port_map[port_idx] == joystick_port_map[i]) {
@@ -876,12 +849,15 @@
return 0;
}
-void joystick_set_axis_value(unsigned int joynum, unsigned int axis, uint8_t value)
+void joystick_set_axis_value(unsigned int joynum, unsigned int axis_idx, uint8_t value)
{
- if (joynum < num_joystick_devices
- && (joystick_devices[joynum].joyport == 0 || joystick_devices[joynum].joyport == 1)
- && joystick_devices[joynum].axis_mapping[axis].pot > 0) {
- joystick_axis_value[joystick_devices[joynum].joyport][joystick_devices[joynum].axis_mapping[axis].pot - 1] = value;
+ if (joynum < num_joystick_devices) {
+ joystick_device_t *joydev = joystick_devices[joynum];
+ joystick_axis_t *axis = &joydev->axes[axis_idx];
+
+ if ((joydev->joyport == 0 || joydev->joyport == 1) && (axis->mapping.pot > 0)) {
+ joystick_axis_value[joydev->joyport][axis->mapping.pot- 1] = value;
+ }
}
}
@@ -893,9 +869,9 @@
char *retval = NULL;
if (joystick_device_num >= 0 && joystick_device_num < num_joystick_devices) {
- for (j = 0; j < joystick_devices[joystick_device_num].num_axes; j++) {
- if (joystick_devices[joystick_device_num].axis_mapping[j].pot - 1 == pot) {
- snprintf(mapping_retval, 50, "Ax%d", j);
+ for (j = 0; j < joystick_devices[joystick_device_num]->num_axes; j++) {
+ if (joystick_devices[joystick_device_num]->axes[j].mapping.pot - 1 == pot) {
+ snprintf(mapping_retval, sizeof mapping_retval, "Ax%d", j);
retval = mapping_retval;
}
}
@@ -906,7 +882,6 @@
char *get_joy_pin_mapping_string(int joystick_device_num, int pin)
{
int j;
- joystick_action_t t;
int valid = 0;
int index = 0;
int sub_index = 0;
@@ -915,79 +890,92 @@
char *index_string = NULL;
if (joystick_device_num >= 0 && joystick_device_num < num_joystick_devices) {
- for (j = 0; j < joystick_devices[joystick_device_num].num_axes; j++) {
- t = joystick_devices[joystick_device_num].axis_mapping[j].positive_direction.action;
- if (t == JOY_ACTION_JOYSTICK && joystick_devices[joystick_device_num].axis_mapping[j].positive_direction.value.joy_pin == pin) {
+ for (j = 0; j < joystick_devices[joystick_device_num]->num_axes; j++) {
+ joystick_mapping_t *positive;
+ joystick_mapping_t *negative;
+ joystick_axis_t *axis = &joystick_devices[joystick_device_num]->axes[j];
+
+ positive = &axis->mapping.positive;
+ if (positive->action == JOY_ACTION_JOYSTICK && positive->value.joy_pin == pin) {
valid++;
- type_string = "Ax";
+ type_string = "Ax";
index_string = "I";
- index = j;
- sub_index = 0;
+ index = j;
+ sub_index = 0;
}
- t = joystick_devices[joystick_device_num].axis_mapping[j].negative_direction.action;
- if (t == JOY_ACTION_JOYSTICK && joystick_devices[joystick_device_num].axis_mapping[j].negative_direction.value.joy_pin == pin) {
+
+ negative = &axis->mapping.negative;
+ if (negative->action == JOY_ACTION_JOYSTICK && negative->value.joy_pin == pin) {
valid++;
- type_string = "Ax";
+ type_string = "Ax";
index_string = "I";
- index = j;
- sub_index = 1;
+ index = j;
+ sub_index = 1;
}
}
- for (j = 0; j < joystick_devices[joystick_device_num].num_buttons; j++) {
- t = joystick_devices[joystick_device_num].button_mapping[j].mapping.action;
- if (t == JOY_ACTION_JOYSTICK) {
- if (joystick_devices[joystick_device_num].button_mapping[j].mapping.value.joy_pin == pin) {
+
+ for (j = 0; j < joystick_devices[joystick_device_num]->num_buttons; j++) {
+ joystick_button_t *button = &joystick_devices[joystick_device_num]->buttons[j];
+ joystick_mapping_t *mapping = &button->mapping;
+ if (mapping->action == JOY_ACTION_JOYSTICK) {
+ if (mapping->value.joy_pin == pin) {
valid++;
- type_string = "Bt";
+ type_string = "Bt";
index_string = NULL;
- index = j;
- sub_index = 0;
+ index = j;
+ sub_index = 0;
}
}
}
- for (j = 0; j < joystick_devices[joystick_device_num].num_hats; j++) {
- t = joystick_devices[joystick_device_num].hat_mapping[j].up.action;
- if (t == JOY_ACTION_JOYSTICK) {
- if (joystick_devices[joystick_device_num].hat_mapping[j].up.value.joy_pin == pin) {
+ for (j = 0; j < joystick_devices[joystick_device_num]->num_hats; j++) {
+ joystick_mapping_t *up;
+ joystick_mapping_t *down;
+ joystick_mapping_t *left;
+ joystick_mapping_t *right;
+ joystick_hat_t *hat = &joystick_devices[joystick_device_num]->hats[j];
+
+ up = &hat->mapping.up;
+ if (up->action == JOY_ACTION_JOYSTICK) {
+ if (up->value.joy_pin == pin) {
valid++;
- type_string = "Ht";
+ type_string = "Ht";
index_string = "I";
- index = j;
- sub_index = 0;
+ index = j;
+ sub_index = 0;
}
}
- t = joystick_devices[joystick_device_num].hat_mapping[j].down.action;
- if (t == JOY_ACTION_JOYSTICK) {
- if (joystick_devices[joystick_device_num].hat_mapping[j].down.value.joy_pin == pin) {
+ down = &hat->mapping.down;
+ if (down->action == JOY_ACTION_JOYSTICK) {
+ if (down->value.joy_pin == pin) {
valid++;
- type_string = "Ht";
+ type_string = "Ht";
index_string = "I";
- index = j;
- sub_index = 1;
+ index = j;
+ sub_index = 1;
}
}
- t = joystick_devices[joystick_device_num].hat_mapping[j].left.action;
- if (t == JOY_ACTION_JOYSTICK) {
- if (joystick_devices[joystick_device_num].hat_mapping[j].left.value.joy_pin == pin) {
+ left = &hat->mapping.left;
+ if (left->action == JOY_ACTION_JOYSTICK) {
+ if (left->value.joy_pin == pin) {
valid++;
- type_string = "Ht";
+ type_string = "Ht";
index_string = "I";
- index = j;
- sub_index = 2;
+ index = j;
+ sub_index = 2;
}
}
- t = joystick_devices[joystick_device_num].hat_mapping[j].right.action;
- if (t == JOY_ACTION_JOYSTICK) {
- if (joystick_devices[joystick_device_num].hat_mapping[j].right.value.joy_pin == pin) {
+ right = &hat->mapping.right;
+ if (right->action == JOY_ACTION_JOYSTICK) {
+ if (right->value.joy_pin == pin) {
valid++;
- type_string = "Ht";
+ type_string = "Ht";
index_string = "I";
- index = j;
- sub_index = 3;
+ index = j;
+ sub_index = 3;
}
}
}
@@ -997,9 +985,11 @@
}
if (valid == 1) {
if (index_string != NULL ) {
- snprintf(mapping_retval, 50, "%s%d, %s%d", type_string, index, index_string, sub_index);
+ snprintf(mapping_retval, sizeof mapping_retval,
+ "%s%d, %s%d", type_string, index, index_string, sub_index);
} else {
- snprintf(mapping_retval, 50, "%s%d", type_string, index);
+ snprintf(mapping_retval, sizeof mapping_retval,
+ "%s%d", type_string, index);
}
retval = mapping_retval;
}
@@ -1010,7 +1000,6 @@
char *get_joy_extra_mapping_string(int which)
{
int i, j;
- joystick_action_t t;
int valid = 0;
int joy = 0;
int index = 0;
@@ -1020,77 +1009,84 @@
char *index_string = NULL;
for (i = 0; i < num_joystick_devices; i++) {
- for (j = 0; j < joystick_devices[i].num_axes; j++) {
- t = joystick_devices[i].axis_mapping[j].positive_direction.action;
- if (t == (which ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
+ joystick_device_t *joydev = joystick_devices[i];
+
+ for (j = 0; j < joystick_devices[i]->num_axes; j++) {
+ joystick_mapping_t *positive = &joydev->axes[j].mapping.positive;
+ joystick_mapping_t *negative = &joydev->axes[j].mapping.negative;
+
+ if (positive->action == (which ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
valid++;
- joy = i;
- type_string = "Ax";
+ joy = i;
+ type_string = "Ax";
index_string = "I";
- index = j;
- sub_index = 0;
+ index = j;
+ sub_index = 0;
}
- t = joystick_devices[i].axis_mapping[j].negative_direction.action;
- if (t == (which ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
+
+ if (negative->action == (which ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
valid++;
- joy = i;
- type_string = "Ax";
+ joy = i;
+ type_string = "Ax";
index_string = "I";
- index = j;
- sub_index = 1;
+ index = j;
+ sub_index = 1;
}
}
- for (j = 0; j < joystick_devices[i].num_buttons; j++) {
- t = joystick_devices[i].button_mapping[j].mapping.action;
- if (t == (which ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
+
+ for (j = 0; j < joystick_devices[i]->num_buttons; j++) {
+ joystick_mapping_t *mapping = &joydev->buttons[j].mapping;
+
+ if (mapping->action == (which ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
valid++;
- joy = i;
- type_string = "Bt";
+ joy = i;
+ type_string = "Bt";
index_string = NULL;
- index = j;
- sub_index = 0;
+ index = j;
+ sub_index = 0;
}
}
- for (j = 0; j < joystick_devices[i].num_hats; j++) {
- t = joystick_devices[i].hat_mapping[j].up.action;
- if (t == (which ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
+ for (j = 0; j < joystick_devices[i]->num_hats; j++) {
+ joystick_mapping_t *up = &joydev->hats[j].mapping.up;
+ joystick_mapping_t *down = &joydev->hats[j].mapping.down;
+ joystick_mapping_t *left = &joydev->hats[j].mapping.left;
+ joystick_mapping_t *right = &joydev->hats[j].mapping.right;
+
+ if (up->action == (which ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
valid++;
- joy = i;
- type_string = "Ht";
+ joy = i;
+ type_string = "Ht";
index_string = "I";
- index = j;
- sub_index = 0;
+ index = j;
+ sub_index = 0;
}
- t = joystick_devices[i].hat_mapping[j].down.action;
- if (t == (which ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
+ if (down->action == (which ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
valid++;
- joy = i;
- type_string = "Ht";
+ joy = i;
+ type_string = "Ht";
index_string = "I";
- index = j;
- sub_index = 1;
+ index = j;
+ sub_index = 1;
}
- t = joystick_devices[i].hat_mapping[j].left.action;
- if (t == (which ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
+ if (left->action == (which ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
valid++;
- joy = i;
- type_string = "Ht";
+ joy = i;
+ type_string = "Ht";
index_string = "I";
- index = j;
- sub_index = 2;
+ index = j;
+ sub_index = 2;
}
- t = joystick_devices[i].hat_mapping[j].right.action;
- if (t == (which ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
+ if (right->action == (which ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
valid++;
- joy = i;
- type_string = "Ht";
+ joy = i;
+ type_string = "Ht";
index_string = "I";
- index = j;
- sub_index = 3;
+ index = j;
+ sub_index = 3;
}
}
}
@@ -1099,9 +1095,13 @@
}
if (valid == 1) {
if (index_string != NULL ) {
- snprintf(mapping_retval, 50, "J%d, %s%d, %s%d", joy, type_string, index, index_string, sub_index);
+ snprintf(mapping_retval, sizeof mapping_retval,
+ "J%d, %s%d, %s%d",
+ joy, type_string, index, index_string, sub_index);
} else {
- snprintf(mapping_retval, 50, "J%d, %s%d", joy, type_string, index);
+ snprintf(mapping_retval, sizeof mapping_retval,
+ "J%d, %s%d",
+ joy, type_string, index);
}
retval = mapping_retval;
}
@@ -1111,7 +1111,7 @@
void joy_set_pot_mapping(int joystick_device_num, int axis, int pot)
{
- joystick_devices[joystick_device_num].axis_mapping[axis].pot = pot + 1;
+ joystick_devices[joystick_device_num]->axes[axis].mapping.pot = pot + 1;
}
void joy_delete_pot_mapping(int joystick_device_num, int pot)
@@ -1119,9 +1119,12 @@
int j;
if (joystick_device_num >= 0 && joystick_device_num < num_joystick_devices) {
- for (j = 0; j < joystick_devices[joystick_device_num].num_axes; j++) {
- if (joystick_devices[joystick_device_num].axis_mapping[j].pot - 1 == pot) {
- joystick_devices[joystick_device_num].axis_mapping[j].pot = 0;
+ joystick_device_t *joydev = joystick_devices[joystick_device_num];
+
+ for (j = 0; j < joydev->num_axes; j++) {
+ joystick_axis_t *axis = &joydev->axes[j];
+ if (axis->mapping.pot - 1 == pot) {
+ axis->mapping.pot = 0;
}
}
}
@@ -1130,61 +1133,68 @@
void joy_delete_pin_mapping(int joystick_device_num, int pin)
{
int j;
- joystick_action_t t;
if (joystick_device_num >= 0 && joystick_device_num < num_joystick_devices) {
- for (j = 0; j < joystick_devices[joystick_device_num].num_axes; j++) {
- t = joystick_devices[joystick_device_num].axis_mapping[j].positive_direction.action;
- if (t == JOY_ACTION_JOYSTICK) {
- if (joystick_devices[joystick_device_num].axis_mapping[j].positive_direction.value.joy_pin == pin) {
- joystick_devices[joystick_device_num].axis_mapping[j].positive_direction.action = JOY_ACTION_NONE;
- joystick_devices[joystick_device_num].axis_mapping[j].positive_direction.value.joy_pin = 0;
+ joystick_device_t *joydev = joystick_devices[joystick_device_num];
+
+ for (j = 0; j < joydev->num_axes; j++) {
+ joystick_mapping_t *negative = &joydev->axes[j].mapping.negative;
+ joystick_mapping_t *positive = &joydev->axes[j].mapping.positive;
+
+ if (positive->action == JOY_ACTION_JOYSTICK) {
+ if (positive->value.joy_pin == pin) {
+ positive->action = JOY_ACTION_NONE;
+ positive->value.joy_pin = 0;
}
}
- t = joystick_devices[joystick_device_num].axis_mapping[j].negative_direction.action;
- if (t == JOY_ACTION_JOYSTICK) {
- if (joystick_devices[joystick_device_num].axis_mapping[j].negative_direction.value.joy_pin == pin) {
- joystick_devices[joystick_device_num].axis_mapping[j].negative_direction.action = JOY_ACTION_NONE;
- joystick_devices[joystick_device_num].axis_mapping[j].negative_direction.value.joy_pin = 0;
+
+ if (negative->action == JOY_ACTION_JOYSTICK) {
+ if (negative->value.joy_pin == pin) {
+ negative->action = JOY_ACTION_NONE;
+ negative->value.joy_pin = 0;
}
}
}
- for (j = 0; j < joystick_devices[joystick_device_num].num_buttons; j++) {
- t = joystick_devices[joystick_device_num].button_mapping[j].mapping.action;
- if (t == JOY_ACTION_JOYSTICK) {
- if (joystick_devices[joystick_device_num].button_mapping[j].mapping.value.joy_pin == pin) {
- joystick_devices[joystick_device_num].button_mapping[j].mapping.action = JOY_ACTION_NONE;
- joystick_devices[joystick_device_num].button_mapping[j].mapping.value.joy_pin = 0;
+
+ for (j = 0; j < joydev->num_buttons; j++) {
+ joystick_mapping_t *mapping = &joydev->buttons[j].mapping;
+
+ if (mapping->action == JOY_ACTION_JOYSTICK) {
+ if (mapping->value.joy_pin == pin) {
+ mapping->action = JOY_ACTION_NONE;
+ mapping->value.joy_pin = 0;
}
}
}
- for (j = 0; j < joystick_devices[joystick_device_num].num_hats; j++) {
- t = joystick_devices[joystick_device_num].hat_mapping[j].up.action;
- if (t == JOY_ACTION_JOYSTICK) {
- if (joystick_devices[joystick_device_num].hat_mapping[j].up.value.joy_pin == pin) {
- joystick_devices[joystick_device_num].hat_mapping[j].up.action = JOY_ACTION_NONE;
- joystick_devices[joystick_device_num].hat_mapping[j].up.value.joy_pin = 0;
+
+ for (j = 0; j < joydev->num_hats; j++) {
+ joystick_mapping_t *up = &joydev->hats[j].mapping.up;
+ joystick_mapping_t *down = &joydev->hats[j].mapping.down;
+ joystick_mapping_t *left = &joydev->hats[j].mapping.left;
+ joystick_mapping_t *right = &joydev->hats[j].mapping.right;
+
+ if (up->action == JOY_ACTION_JOYSTICK) {
+ if (up->value.joy_pin == pin) {
+ up->action = JOY_ACTION_NONE;
+ up->value.joy_pin = 0;
}
}
- t = joystick_devices[joystick_device_num].hat_mapping[j].down.action;
- if (t == JOY_ACTION_JOYSTICK) {
- if (joystick_devices[joystick_device_num].hat_mapping[j].down.value.joy_pin == pin) {
- joystick_devices[joystick_device_num].hat_mapping[j].down.action = JOY_ACTION_NONE;
- joystick_devices[joystick_device_num].hat_mapping[j].down.value.joy_pin = 0;
+ if (down->action == JOY_ACTION_JOYSTICK) {
+ if (down->value.joy_pin == pin) {
+ down->action = JOY_ACTION_NONE;
+ down->value.joy_pin = 0;
}
}
- t = joystick_devices[joystick_device_num].hat_mapping[j].left.action;
- if (t == JOY_ACTION_JOYSTICK) {
- if (joystick_devices[joystick_device_num].hat_mapping[j].left.value.joy_pin == pin) {
- joystick_devices[joystick_device_num].hat_mapping[j].left.action = JOY_ACTION_NONE;
- joystick_devices[joystick_device_num].hat_mapping[j].left.value.joy_pin = 0;
+ if (left->action == JOY_ACTION_JOYSTICK) {
+ if (left->value.joy_pin == pin) {
+ left->action = JOY_ACTION_NONE;
+ left->value.joy_pin = 0;
}
}
- t = joystick_devices[joystick_device_num].hat_mapping[j].right.action;
- if (t == JOY_ACTION_JOYSTICK) {
- if (joystick_devices[joystick_device_num].hat_mapping[j].right.value.joy_pin == pin) {
- joystick_devices[joystick_device_num].hat_mapping[j].right.action = JOY_ACTION_NONE;
- joystick_devices[joystick_device_num].hat_mapping[j].right.value.joy_pin = 0;
+ if (right->action == JOY_ACTION_JOYSTICK) {
+ if (right->value.joy_pin == pin) {
+ right->action = JOY_ACTION_NONE;
+ right->value.joy_pin = 0;
}
}
}
@@ -1198,45 +1208,45 @@
joystick_action_t t;
for (i = 0; i < num_joystick_devices; i++) {
- for (j = 0; j < joystick_devices[i].num_axes; j++) {
- t = joystick_devices[i].axis_mapping[j].positive_direction.action;
+ for (j = 0; j < joystick_devices[i]->num_axes; j++) {
+ t = joystick_devices[i]->axis_mapping[j].positive_direction.action;
if (t == (type ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
- joystick_devices[i].axis_mapping[j].positive_direction.action = JOY_ACTION_NONE;
- joystick_devices[i].axis_mapping[j].positive_direction.value.ui_action = ACTION_NONE;
+ joystick_devices[i]->axis_mapping[j].positive_direction.action = JOY_ACTION_NONE;
+ joystick_devices[i]->axis_mapping[j].positive_direction.value.ui_action = ACTION_NONE;
}
- t = joystick_devices[i].axis_mapping[j].negative_direction.action;
+ t = joystick_devices[i]->axis_mapping[j].negative_direction.action;
if (t == (type ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
- joystick_devices[i].axis_mapping[j].negative_direction.action = JOY_ACTION_NONE;
- joystick_devices[i].axis_mapping[j].negative_direction.value.ui_action = ACTION_NONE;
+ joystick_devices[i]->axis_mapping[j].negative_direction.action = JOY_ACTION_NONE;
+ joystick_devices[i]->axis_mapping[j].negative_direction.value.ui_action = ACTION_NONE;
}
}
- for (j = 0; j < joystick_devices[i].num_buttons; j++) {
- t = joystick_devices[i].button_mapping[j].mapping.action;
+ for (j = 0; j < joystick_devices[i]->num_buttons; j++) {
+ t = joystick_devices[i]->button_mapping[j].mapping.action;
if (t == (type ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
- joystick_devices[i].button_mapping[j].mapping.action = JOY_ACTION_NONE;
- joystick_devices[i].button_mapping[j].mapping.value.ui_action = ACTION_NONE;
+ joystick_devices[i]->button_mapping[j].mapping.action = JOY_ACTION_NONE;
+ joystick_devices[i]->button_mapping[j].mapping.value.ui_action = ACTION_NONE;
}
}
- for (j = 0; j < joystick_devices[i].num_hats; j++) {
- t = joystick_devices[i].hat_mapping[j].up.action;
+ for (j = 0; j < joystick_devices[i]->num_hats; j++) {
+ t = joystick_devices[i]->hat_mapping[j].up.action;
if (t == (type ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
- joystick_devices[i].hat_mapping[j].up.action = JOY_ACTION_NONE;
- joystick_devices[i].hat_mapping[j].up.value.ui_action = ACTION_NONE;
+ joystick_devices[i]->hat_mapping[j].up.action = JOY_ACTION_NONE;
+ joystick_devices[i]->hat_mapping[j].up.value.ui_action = ACTION_NONE;
}
- t = joystick_devices[i].hat_mapping[j].down.action;
+ t = joystick_devices[i]->hat_mapping[j].down.action;
if (t == (type ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
- joystick_devices[i].hat_mapping[j].down.action = JOY_ACTION_NONE;
- joystick_devices[i].hat_mapping[j].down.value.ui_action = ACTION_NONE;
+ joystick_devices[i]->hat_mapping[j].down.action = JOY_ACTION_NONE;
+ joystick_devices[i]->hat_mapping[j].down.value.ui_action = ACTION_NONE;
}
t = joystick_devices[i].hat_mapping[j].left.action;
if (t == (type ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
- joystick_devices[i].hat_mapping[j].left.action = JOY_ACTION_NONE;
- joystick_devices[i].hat_mapping[j].left.value.ui_action = ACTION_NONE;
+ joystick_devices[i]->hat_mapping[j].left.action = JOY_ACTION_NONE;
+ joystick_devices[i]->hat_mapping[j].left.value.ui_action = ACTION_NONE;
}
- t = joystick_devices[i].hat_mapping[j].right.action;
+ t = joystick_devices[i]->hat_mapping[j].right.action;
if (t == (type ? JOY_ACTION_MAP : JOY_ACTION_UI_ACTIVATE)) {
- joystick_devices[i].hat_mapping[j].right.action = JOY_ACTION_NONE;
- joystick_devices[i].hat_mapping[j].right.value.ui_action = ACTION_NONE;
+ joystick_devices[i]->hat_mapping[j].right.action = JOY_ACTION_NONE;
+ joystick_devices[i]->hat_mapping[j].right.value.ui_action = ACTION_NONE;
}
}
}
@@ -1321,7 +1331,7 @@
{
FILE *fp;
int dev_idx;
- int map_idx;
+ int inp_idx;
#ifdef SDL_DEBUG
fprintf(stderr, "%s\n", __func__);
@@ -1341,21 +1351,21 @@
fprintf(fp, "!CLEAR\n\n");
for (dev_idx = 0; dev_idx < num_joystick_devices; dev_idx++) {
- joystick_device_t *device = &joystick_devices[dev_idx];
+ joystick_device_t *joydev = joystick_devices[dev_idx];
int row = 0;
- fprintf(fp, "# %s\n", device->jname);
+ fprintf(fp, "# %s\n", joydev->name);
/* dump axis mappings */
- for (map_idx = 0; map_idx < device->num_axes; map_idx++) {
- joystick_axis_mapping_t *axis = &(device->axis_mapping[map_idx]);
+ for (inp_idx = 0; inp_idx < joydev->num_axes; inp_idx++) {
+ joystick_axis_t *axis = &joydev->axes[inp_idx];
- if (axis->pot > 0) {
+ if (axis->mapping.pot > 0) {
fprintf(fp, "%i %i %i %i %u\n",
- dev_idx, JOY_INPUT_AXIS, map_idx, JOY_ACTION_POT_AXIS, axis->pot);
+ dev_idx, JOY_INPUT_AXIS, inp_idx, JOY_ACTION_POT_AXIS, axis->mapping.pot);
} else {
- mapping_dump_map(fp, dev_idx, JOY_INPUT_AXIS, row + 0, &(axis->positive_direction));
- mapping_dump_map(fp, dev_idx, JOY_INPUT_AXIS, row + 1, &(axis->negative_direction));
+ mapping_dump_map(fp, dev_idx, JOY_INPUT_AXIS, row + 0, &axis->mapping.positive);
+ mapping_dump_map(fp, dev_idx, JOY_INPUT_AXIS, row + 1, &axis->mapping.negative);
}
fprintf(fp, "\n");
row += 2;
@@ -1362,23 +1372,23 @@
}
/* dump button mappings */
- for (map_idx = 0; map_idx < device->num_buttons; map_idx++) {
- joystick_button_mapping_t *button = &(device->button_mapping[map_idx]);
+ for (inp_idx = 0; inp_idx < joydev->num_buttons; inp_idx++) {
+ joystick_button_t *button = &joydev->buttons[inp_idx];
- mapping_dump_map(fp, dev_idx, JOY_INPUT_BUTTON, map_idx, &button->mapping);
+ mapping_dump_map(fp, dev_idx, JOY_INPUT_BUTTON, inp_idx, &button->mapping);
}
fprintf(fp, "\n");
/* dump hat mappings */
row = 0;
- for (map_idx = 0; map_idx < device->num_hats; map_idx++) {
- joystick_hat_mapping_t *hat = &(device->hat_mapping[map_idx]);
+ for (inp_idx = 0; inp_idx < joydev->num_hats; inp_idx++) {
+ joystick_hat_t *hat = &joydev->hats[inp_idx];
/* indexes 0-3 are hardcoded to up, down, left and right */
- mapping_dump_map(fp, dev_idx, JOY_INPUT_HAT, row + 0, &(hat->up));
- mapping_dump_map(fp, dev_idx, JOY_INPUT_HAT, row + 1, &(hat->down));
- mapping_dump_map(fp, dev_idx, JOY_INPUT_HAT, row + 2, &(hat->left));
- mapping_dump_map(fp, dev_idx, JOY_INPUT_HAT, row + 3, &(hat->right));
+ mapping_dump_map(fp, dev_idx, JOY_INPUT_HAT, row + 0, &hat->mapping.up);
+ mapping_dump_map(fp, dev_idx, JOY_INPUT_HAT, row + 1, &hat->mapping.down);
+ mapping_dump_map(fp, dev_idx, JOY_INPUT_HAT, row + 2, &hat->mapping.left);
+ mapping_dump_map(fp, dev_idx, JOY_INPUT_HAT, row + 3, &hat->mapping.right);
row += 4;
}
@@ -1398,18 +1408,20 @@
int i, k;
for (i = 0; i < num_joystick_devices; ++i) {
- for (k = 0; k < joystick_devices[i].num_axes; ++k) {
- joystick_devices[i].axis_mapping[k].positive_direction.action = JOY_ACTION_NONE;
- joystick_devices[i].axis_mapping[k].negative_direction.action = JOY_ACTION_NONE;
+ joystick_device_t *joydev = joystick_devices[i];
+
+ for (k = 0; k < joydev->num_axes; ++k) {
+ joydev->axes[k].mapping.positive.action = JOY_ACTION_NONE;
+ joydev->axes[k].mapping.negative.action = JOY_ACTION_NONE;
}
- for (k = 0; k < joystick_devices[i].num_buttons; ++k) {
- joystick_devices[i].button_mapping[k].mapping.action = JOY_ACTION_NONE;
+ for (k = 0; k < joystick_devices[i]->num_buttons; ++k) {
+ joydev->buttons[k].mapping.action = JOY_ACTION_NONE;
}
- for (k = 0; k < joystick_devices[i].num_hats; ++k) {
- joystick_devices[i].hat_mapping[k].up.action = JOY_ACTION_NONE;
- joystick_devices[i].hat_mapping[k].down.action = JOY_ACTION_NONE;
- joystick_devices[i].hat_mapping[k].left.action = JOY_ACTION_NONE;
- joystick_devices[i].hat_mapping[k].right.action = JOY_ACTION_NONE;
+ for (k = 0; k < joystick_devices[i]->num_hats; ++k) {
+ joydev->hats[k].mapping.up.action = JOY_ACTION_NONE;
+ joydev->hats[k].mapping.down.action = JOY_ACTION_NONE;
+ joydev->hats[k].mapping.left.action = JOY_ACTION_NONE;
+ joydev->hats[k].mapping.right.action = JOY_ACTION_NONE;
}
}
}
@@ -1580,13 +1592,13 @@
*/
static bool parser_set_axis(const parser_state_t *state)
{
- joystick_device_t *dev = &(joystick_devices[state->joy_index]);
+ joystick_device_t *joydev = joystick_devices[state->joy_index];
bool result = true;
if (state->action == JOY_ACTION_POT_AXIS) {
/* map to potentiometer */
- if (state->input_index < dev->num_axes) {
- dev->axis_mapping[state->input_index].pot = state->args.pot;
+ if (state->input_index < joydev->num_axes) {
+ joydev->axes[state->input_index].mapping.pot = state->args.pot;
} else {
result = false;
}
@@ -1599,15 +1611,15 @@
printf("%s(): AXIS: index = %d, direction = %s\n",
__func__, index, direction == 0 ? "positive" : "negative");
#endif
- if (index < dev->num_axes) {
- joystick_axis_mapping_t *axis = &(dev->axis_mapping[index]);
- joystick_mapping_t *mapping;
+ if (index < joydev->num_axes) {
+ joystick_axis_t *axis = &joydev->axes[index];
+ joystick_mapping_t *mapping;
/* select directional mapping */
if (direction == 0) {
- mapping = &(axis->positive_direction);
+ mapping = &axis->mapping.positive;
} else {
- mapping = &(axis->negative_direction);
+ mapping = &axis->mapping.negative;
}
parser_set_mapping(state, mapping);
} else {
@@ -1631,18 +1643,17 @@
*/
static bool parser_set_button(const parser_state_t *state)
{
- joystick_device_t *dev = &(joystick_devices[state->joy_index]);
- int button = state->input_index;
+ joystick_device_t *joydev = joystick_devices[state->joy_index];
+ int index = state->input_index;
bool result = true;
- if (button < dev->num_buttons) {
- joystick_mapping_t *mapping = &(dev->button_mapping[button].mapping);
-
+ if (index < joydev->num_buttons) {
+ joystick_mapping_t *mapping = &joydev->buttons[index].mapping;
parser_set_mapping(state, mapping);
} else {
parser_log_error(state,
"invalid button index %d for joystick %d.",
- button, state->joy_index);
+ index, state->joy_index);
result = false;
}
return result;
@@ -1656,26 +1667,26 @@
*/
static bool parser_set_hat(const parser_state_t *state)
{
- int index = state->input_index / 4;
- int direction = state->input_index % 4;
- joystick_device_t *dev = &(joystick_devices[state->joy_index]);
+ int index = state->input_index / 4;
+ int direction = state->input_index % 4;
+ joystick_device_t *joydev = joystick_devices[state->joy_index];
- if (index < dev->num_hats) {
- joystick_hat_mapping_t *hat = &(dev->hat_mapping[index]);
- joystick_mapping_t *mapping;
+ if (index < joydev->num_hats) {
+ joystick_hat_t *hat = &joydev->hats[index];
+ joystick_mapping_t *mapping;
switch (direction) {
case JOY_HAT_UP:
- mapping = &(hat->up);
+ mapping = &hat->mapping.up;
break;
case JOY_HAT_DOWN:
- mapping = &(hat->down);
+ mapping = &hat->mapping.down;
break;
case JOY_HAT_LEFT:
- mapping = &(hat->left);
+ mapping = &hat->mapping.left;
break;
case JOY_HAT_RIGHT:
- mapping = &(hat->right);
+ mapping = &hat->mapping.right;
break;
default:
/* never reached, to satisfy gcc */
@@ -2695,6 +2706,12 @@
joystick_alarm = alarm_new(maincpu_alarm_context, "Joystick",
joystick_latch_handler, NULL);
+ /* preallocate devices array */
+ num_joystick_devices = 0;
+ max_joystick_devices = 16;
+ joystick_devices = lib_malloc(sizeof *joystick_devices * max_joystick_devices);
+ joystick_devices[0] = NULL;
+
#ifdef COMMON_JOYKEYS
kbd_initialize_numpad_joykeys(joykeys[0]);
#endif
@@ -2718,7 +2735,7 @@
for (i = 0; i < JOYPORT_MAX_PORTS; i++) {
if (joystick_port_map[i] >= JOYDEV_REALJOYSTICK_MIN) {
if (joystick_port_map[i] - JOYDEV_REALJOYSTICK_MIN < num_joystick_devices) {
- joystick_devices[joystick_port_map[i] - JOYDEV_REALJOYSTICK_MIN].joyport = i;
+ joystick_devices[joystick_port_map[i] - JOYDEV_REALJOYSTICK_MIN]->joyport = i;
} else {
joystick_port_map[i] = JOYDEV_NONE;
}
@@ -2801,6 +2818,7 @@
*/
static int gtkjoy_pins[JOYPORT_MAX_PORTS][JOYPORT_MAX_PINS];
+#if 0
void register_joystick_driver(
struct joystick_driver_s *driver,
const char *jname,
@@ -2813,10 +2831,10 @@
joystick_devices = lib_realloc(joystick_devices,
sizeof(struct joystick_device_s) * (num_joystick_devices + 1));
- new_joystick_device = &joystick_devices[num_joystick_devices++];
+ new_joystick_device = joystick_devices[num_joystick_devices++];
new_joystick_device->driver = driver;
- strncpy(new_joystick_device->jname, jname, JOYDEV_NAME_SIZE - 1);
- new_joystick_device->jname[JOYDEV_NAME_SIZE - 1] = '\0';
+ strncpy(new_joystick_device->name, jname, JOYDEV_NAME_SIZE - 1);
+ new_joystick_device->name[JOYDEV_NAME_SIZE - 1] = '\0';
new_joystick_device->num_axes = num_axes;
new_joystick_device->num_hats = num_hats;
new_joystick_device->num_buttons = num_buttons;
@@ -2823,7 +2841,7 @@
log_message(joy_log,
"registered controller '%s' with %d %s, %d %s, %d %s",
- new_joystick_device->jname,
+ new_joystick_device->name,
num_axes, num_axes == 1 ? "axis" : "axes",
num_hats, num_hats == 1 ? "hat" : "hats",
num_buttons, num_buttons == 1 ? "button" : "buttons");
@@ -2893,6 +2911,7 @@
new_joystick_device->button_mapping[0].value.action = 2;
#endif
}
+#endif
/* When a host joystick event happens that cause a 'press' of a pin, increment the 'press amount' of that pin */
static void gtkjoy_set_value_press(unsigned int joyport, uint16_t value)
@@ -2972,10 +2991,12 @@
}
-void joy_axis_event(uint8_t joynum, uint8_t axis, joystick_axis_value_t value)
+void joy_axis_event(uint8_t joynum, uint8_t axis_index, joystick_axis_value_t value)
{
- joystick_axis_value_t prev = joystick_devices[joynum].axis_mapping[axis].prev;
- int joyport = joystick_devices[joynum].joyport;
+ joystick_device_t *joydev = joystick_devices[joynum];
+ joystick_axis_t *axis = &joydev->axes[axis_index];
+ joystick_axis_value_t prev = axis->prev;
+ int joyport = joydev->joyport;
if (value == prev) {
return;
@@ -2985,26 +3006,27 @@
/* release directions first if needed */
if (prev == JOY_AXIS_POSITIVE) {
- joy_perform_event(&joystick_devices[joynum].axis_mapping[axis].positive_direction, joyport, 0);
+ joy_perform_event(&axis->mapping.positive, joyport, 0);
}
if (prev == JOY_AXIS_NEGATIVE) {
- joy_perform_event(&joystick_devices[joynum].axis_mapping[axis].negative_direction, joyport, 0);
+ joy_perform_event(&axis->mapping.negative, joyport, 0);
}
/* press new direction if needed */
if (value == JOY_AXIS_POSITIVE) {
- joy_perform_event(&joystick_devices[joynum].axis_mapping[axis].positive_direction, joyport, 1);
+ joy_perform_event(&axis->mapping.positive, joyport, 1);
}
if (value == JOY_AXIS_NEGATIVE) {
- joy_perform_event(&joystick_devices[joynum].axis_mapping[axis].negative_direction, joyport, 1);
+ joy_perform_event(&axis->mapping.negative, joyport, 1);
}
- joystick_devices[joynum].axis_mapping[axis].prev = value;
+ axis->prev = value;
}
void joy_button_event(uint8_t joynum, uint8_t button, uint8_t value)
{
- int pressed = value ? 1 : 0;
+ joystick_device_t *joydev = joystick_devices[joynum];
+ int32_t pressed = value ? 1 : 0;
#if 0
int num_buttons = joystick_devices[joynum].num_buttons;
int joy_pin = joystick_devices[joynum].button_mapping[button].value.joy_pin;
@@ -3018,56 +3040,58 @@
}
}
#endif
- if (pressed != joystick_devices[joynum].button_mapping[button].prev) {
+ if (pressed != joydev->buttons[button].prev) {
DBG(("joy_button_event: joynum: %d, button: %d pressed: %d\n",
joynum, button, pressed));
- joy_perform_event(&(joystick_devices[joynum].button_mapping[button].mapping),
- joystick_devices[joynum].joyport, pressed);
- joystick_devices[joynum].button_mapping[button].prev = pressed;
+ joy_perform_event(&joydev->buttons[button].mapping,
+ joydev->joyport,
+ ...
[truncated message content] |
|
From: <co...@us...> - 2025-03-05 17:05:51
|
Revision: 45515
http://sourceforge.net/p/vice-emu/code/45515
Author: compyx
Date: 2025-03-05 17:05:34 +0000 (Wed, 05 Mar 2025)
Log Message:
-----------
Gtk3: fix memory leak in clipboard handling
Modified Paths:
--------------
trunk/vice/src/arch/gtk3/actions-clipboard.c
Modified: trunk/vice/src/arch/gtk3/actions-clipboard.c
===================================================================
--- trunk/vice/src/arch/gtk3/actions-clipboard.c 2025-03-04 19:45:20 UTC (rev 45514)
+++ trunk/vice/src/arch/gtk3/actions-clipboard.c 2025-03-05 17:05:34 UTC (rev 45515)
@@ -80,6 +80,7 @@
tmp,
(gint)len);
lib_free(tmp);
+ lib_free(text);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gp...@us...> - 2025-03-04 19:45:32
|
Revision: 45514
http://sourceforge.net/p/vice-emu/code/45514
Author: gpz
Date: 2025-03-04 19:45:20 +0000 (Tue, 04 Mar 2025)
Log Message:
-----------
Fix for [bugs:#2116], remove aliasing noise by dithering. patch by Leandro Nini.
Modified Paths:
--------------
trunk/vice/src/resid/filter8580new.h
Modified: trunk/vice/src/resid/filter8580new.h
===================================================================
--- trunk/vice/src/resid/filter8580new.h 2025-03-04 19:07:36 UTC (rev 45513)
+++ trunk/vice/src/resid/filter8580new.h 2025-03-04 19:45:20 UTC (rev 45514)
@@ -23,6 +23,7 @@
#include "resid-config.h"
#include <cassert>
+#include <cstdlib>
namespace reSID
{
@@ -648,6 +649,23 @@
static model_filter_t model_filter[2];
friend class SID;
+
+private:
+ class Randomnoise
+ {
+ private:
+ int buffer[1024];
+ mutable int index = 0;
+ public:
+ Randomnoise()
+ {
+ for (int i=0; i<1024; i++)
+ buffer[i] = rand() % (1<<19);
+ }
+ int getNoise() const { index = (index + 1) & 0x3ff; return buffer[index]; }
+ };
+
+ Randomnoise rnd;
};
@@ -667,9 +685,9 @@
{
model_filter_t& f = model_filter[sid_model];
- v1 = (voice1*f.voice_scale_s14 >> 18) + f.voice_DC;
- v2 = (voice2*f.voice_scale_s14 >> 18) + f.voice_DC;
- v3 = (voice3*f.voice_scale_s14 >> 18) + f.voice_DC;
+ v1 = ((voice1*f.voice_scale_s14 + rnd.getNoise()) >> 18) + f.voice_DC;
+ v2 = ((voice2*f.voice_scale_s14 + rnd.getNoise()) >> 18) + f.voice_DC;
+ v3 = ((voice3*f.voice_scale_s14 + rnd.getNoise()) >> 18) + f.voice_DC;
// Sum inputs routed into the filter.
int Vi = 0;
@@ -768,9 +786,9 @@
{
model_filter_t& f = model_filter[sid_model];
- v1 = (voice1*f.voice_scale_s14 >> 18) + f.voice_DC;
- v2 = (voice2*f.voice_scale_s14 >> 18) + f.voice_DC;
- v3 = (voice3*f.voice_scale_s14 >> 18) + f.voice_DC;
+ v1 = ((voice1*f.voice_scale_s14 + rnd.getNoise()) >> 18) + f.voice_DC;
+ v2 = ((voice2*f.voice_scale_s14 + rnd.getNoise()) >> 18) + f.voice_DC;
+ v3 = ((voice3*f.voice_scale_s14 + rnd.getNoise()) >> 18) + f.voice_DC;
// Enable filter on/off.
// This is not really part of SID, but is useful for testing.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rh...@us...> - 2025-03-04 19:07:39
|
Revision: 45513
http://sourceforge.net/p/vice-emu/code/45513
Author: rhialto
Date: 2025-03-04 19:07:36 +0000 (Tue, 04 Mar 2025)
Log Message:
-----------
fsimage_read_dxx_image() for DISK_IMAGE_TYPE_D80/D82 got its disk ID bytes from the wrong place.
Nobody ever noticed because for 8050/8250 drives, we currently don't emulate the disk at the gcr level but by emulating the job queue commands, so no gcr is involved and this function is not called anyway.
Modified Paths:
--------------
trunk/vice/src/diskconstants.h
trunk/vice/src/diskimage/fsimage-dxx.c
trunk/vice/src/vdrive/vdrive.c
Modified: trunk/vice/src/diskconstants.h
===================================================================
--- trunk/vice/src/diskconstants.h 2025-03-03 00:17:40 UTC (rev 45512)
+++ trunk/vice/src/diskconstants.h 2025-03-04 19:07:36 UTC (rev 45513)
@@ -146,8 +146,8 @@
#define HDR_SECTOR_8050 0 /* block w/disk name */
#define BAM_TRACK_8050 38
#define BAM_SECTOR_8050 0
-#define BAM_NAME_8050 6 /* pos. of disk name in header blk */
-#define BAM_ID_8050 24 /* pos. of disk id in header blk */
+#define HDR_NAME_8050 6 /* pos. of disk name in header blk */
+#define HDR_ID_8050 24 /* pos. of disk id in header blk */
#define DIR_TRACK_8050 39
#define DIR_SECTOR_8050 1
@@ -159,8 +159,8 @@
#define HDR_SECTOR_8250 HDR_SECTOR_8050
#define BAM_TRACK_8250 BAM_TRACK_8050
#define BAM_SECTOR_8250 BAM_SECTOR_8050
-#define BAM_NAME_8250 BAM_NAME_8050 /* pos. of disk name in hdr blk */
-#define BAM_ID_8250 BAM_ID_8050 /* pos. of disk id in hdr blk */
+#define HDR_NAME_8250 HDR_NAME_8050 /* pos. of disk name in hdr blk */
+#define HDR_ID_8250 HDR_ID_8050 /* pos. of disk id in hdr blk */
#define DIR_TRACK_8250 DIR_TRACK_8050
#define DIR_SECTOR_8250 DIR_SECTOR_8050
Modified: trunk/vice/src/diskimage/fsimage-dxx.c
===================================================================
--- trunk/vice/src/diskimage/fsimage-dxx.c 2025-03-03 00:17:40 UTC (rev 45512)
+++ trunk/vice/src/diskimage/fsimage-dxx.c 2025-03-04 19:07:36 UTC (rev 45513)
@@ -166,8 +166,8 @@
if (image->type == DISK_IMAGE_TYPE_D80
|| image->type == DISK_IMAGE_TYPE_D82) {
- sectors = disk_image_check_sector(image, BAM_TRACK_8050, BAM_SECTOR_8050);
- bam_id = &buffer[BAM_ID_8050];
+ sectors = disk_image_check_sector(image, HDR_TRACK_8050, HDR_SECTOR_8050);
+ bam_id = &buffer[HDR_ID_8050];
} else {
sectors = disk_image_check_sector(image, BAM_TRACK_1541, BAM_SECTOR_1541);
bam_id = &buffer[BAM_ID_1541];
Modified: trunk/vice/src/vdrive/vdrive.c
===================================================================
--- trunk/vice/src/vdrive/vdrive.c 2025-03-03 00:17:40 UTC (rev 45512)
+++ trunk/vice/src/vdrive/vdrive.c 2025-03-04 19:07:36 UTC (rev 45513)
@@ -650,8 +650,8 @@
vdrive->Bam_Sector = BAM_SECTOR_8050;
vdrive->Header_Track = HDR_TRACK_8050;
vdrive->Header_Sector = HDR_SECTOR_8050;
- vdrive->bam_name = BAM_NAME_8050;
- vdrive->bam_id = BAM_ID_8050;
+ vdrive->bam_name = HDR_NAME_8050;
+ vdrive->bam_id = HDR_ID_8050;
vdrive->Dir_Track = DIR_TRACK_8050;
vdrive->Dir_Sector = DIR_SECTOR_8050;
break;
@@ -660,8 +660,8 @@
vdrive->Bam_Sector = BAM_SECTOR_8250;
vdrive->Header_Track = HDR_TRACK_8250;
vdrive->Header_Sector = HDR_SECTOR_8250;
- vdrive->bam_name = BAM_NAME_8250;
- vdrive->bam_id = BAM_ID_8250;
+ vdrive->bam_name = HDR_NAME_8250;
+ vdrive->bam_id = HDR_ID_8250;
vdrive->Dir_Track = DIR_TRACK_8250;
vdrive->Dir_Sector = DIR_SECTOR_8250;
break;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gp...@us...> - 2025-03-03 00:17:46
|
Revision: 45512
http://sourceforge.net/p/vice-emu/code/45512
Author: gpz
Date: 2025-03-03 00:17:40 +0000 (Mon, 03 Mar 2025)
Log Message:
-----------
fix division by zero in monitor i command, should fix #2130
Modified Paths:
--------------
trunk/vice/src/monitor/mon_memory.c
Modified: trunk/vice/src/monitor/mon_memory.c
===================================================================
--- trunk/vice/src/monitor/mon_memory.c 2025-03-01 13:54:56 UTC (rev 45511)
+++ trunk/vice/src/monitor/mon_memory.c 2025-03-03 00:17:40 UTC (rev 45512)
@@ -282,7 +282,16 @@
int bank;
mem_get_screen_parameter(&base, &rows, &screen_width, &bank);
+ /* HACK: mem_get_screen_parameter() returns actual screen size from the
+ video chip registers - this can be zero rows or zero columns! If
+ width is 0, use last known terminal width instead, to avoid division
+ by 0 further below. */
+ if (screen_width == 0) {
+ screen_width = last_known_xres;
+ }
+
max_width = screen_width;
+
if (max_width > (last_known_xres - (7 + 2))) {
max_width = (last_known_xres - (7 + 2));
/* to make the output easier to read, make sure the number of items
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <co...@us...> - 2025-03-01 13:55:02
|
Revision: 45511
http://sourceforge.net/p/vice-emu/code/45511
Author: compyx
Date: 2025-03-01 13:54:56 +0000 (Sat, 01 Mar 2025)
Log Message:
-----------
Create branch for joystick device scanning/registering rework
Added Paths:
-----------
branches/compyx/joymap-001/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <co...@us...> - 2025-03-01 08:45:31
|
Revision: 45510
http://sourceforge.net/p/vice-emu/code/45510
Author: compyx
Date: 2025-03-01 08:45:24 +0000 (Sat, 01 Mar 2025)
Log Message:
-----------
Gtk3: Fix non-ASCII codes appearing in the clipboard with "Edit" -> "Copy"
See bug #2087.
Modified Paths:
--------------
trunk/vice/src/arch/gtk3/actions-clipboard.c
Modified: trunk/vice/src/arch/gtk3/actions-clipboard.c
===================================================================
--- trunk/vice/src/arch/gtk3/actions-clipboard.c 2025-02-27 19:28:21 UTC (rev 45509)
+++ trunk/vice/src/arch/gtk3/actions-clipboard.c 2025-03-01 08:45:24 UTC (rev 45510)
@@ -34,6 +34,7 @@
#include <stddef.h>
#include <stdbool.h>
#include <string.h>
+#include <ctype.h>
#include "charset.h"
#include "clipboard.h"
@@ -50,11 +51,35 @@
*/
static void edit_copy_action(ui_action_map_t *self)
{
+#ifdef WINDOWS_COMPILE
+ char *text = clipboard_read_screen_output("\r\n");
+#else
char *text = clipboard_read_screen_output("\n");
+#endif
+ if (text != NULL) {
+ size_t i;
+ size_t len;
+ char *tmp;
- if (text != NULL) {
+ /* Some characters were translated to ASCII by clipboard_read_screen_output(),
+ * but just about anything in the non a-zA-Z range wasn't so we need to
+ * mangle the text further: */
+ len = strlen(text);
+ tmp = lib_malloc(len + 1u);
+ for (i = 0; i < len; i++) {
+ unsigned char c = (unsigned char)text[i];
+ if ((c == '\r' || c == '\n') || (c < 127 && isprint(c))) {
+ tmp[i] = (char)c;
+ } else {
+ tmp[i] = '?';
+ }
+ }
+ tmp[len] = '\0';
+
gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
- text, (gint)strlen(text));
+ tmp,
+ (gint)len);
+ lib_free(tmp);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <co...@us...> - 2025-02-27 19:28:23
|
Revision: 45509
http://sourceforge.net/p/vice-emu/code/45509
Author: compyx
Date: 2025-02-27 19:28:21 +0000 (Thu, 27 Feb 2025)
Log Message:
-----------
Gtk3: Add label "Master volume" in front of volume slider
In the settings node "Audio" -> "Sound driver", add a label next to the volume
slider to avoid confusion for certain citrus people.
Modified Paths:
--------------
trunk/vice/src/arch/gtk3/widgets/settings_sound.c
Modified: trunk/vice/src/arch/gtk3/widgets/settings_sound.c
===================================================================
--- trunk/vice/src/arch/gtk3/widgets/settings_sound.c 2025-02-27 07:42:17 UTC (rev 45508)
+++ trunk/vice/src/arch/gtk3/widgets/settings_sound.c 2025-02-27 19:28:21 UTC (rev 45509)
@@ -105,6 +105,7 @@
GtkWidget *scale;
GtkWidget *enabled_check;
GtkWidget *warp_enabled_check;
+ GtkWidget *label;
/* outer grid: contains the checkbox and an 'inner' grid for the widgets */
outer = gtk_grid_new();
@@ -112,8 +113,16 @@
/* add checkbox for 'sound enabled' */
enabled_check = vice_gtk3_resource_check_button_new("Sound",
"Enable sound emulation");
- gtk_grid_attach(GTK_GRID(outer), enabled_check, 0, 0, 1, 1);
+ gtk_grid_attach(GTK_GRID(outer), enabled_check, 0, 0, 2, 1);
+ warp_enabled_check = vice_gtk3_resource_check_button_new("SoundEmulateOnWarp",
+ "Enable sound emulation in warp mode. (Disabling has a negative impact on compatibility)");
+ gtk_grid_attach(GTK_GRID(outer), warp_enabled_check, 0, 1, 2, 1);
+
+ label = gtk_label_new("Master volume");
+ gtk_widget_set_halign(label, GTK_ALIGN_START);
+ gtk_widget_set_margin_end(label, 8); /* a litte more space to avoid the
+ slider handle touching the text */
scale = vice_gtk3_resource_scale_custom_new_printf("%s",
GTK_ORIENTATION_HORIZONTAL,
0,
@@ -125,18 +134,14 @@
"SoundVolume");
gtk_widget_set_hexpand(scale, TRUE);
gtk_scale_set_value_pos(GTK_SCALE(scale), GTK_POS_RIGHT);
- gtk_grid_attach(GTK_GRID(outer), scale, 1, 0, 1, 1);
-
- warp_enabled_check = vice_gtk3_resource_check_button_new("SoundEmulateOnWarp",
- "Enable sound emulation in warp mode. (Disabling has a negative impact on compatibility)");
- gtk_grid_attach(GTK_GRID(outer), warp_enabled_check, 0, 1, 2, 1);
-
+ gtk_grid_attach(GTK_GRID(outer), label, 0, 2, 1, 1);
+ gtk_grid_attach(GTK_GRID(outer), scale, 1, 2, 1, 1);
/* inner grid: contains widgets and can be enabled/disabled depending on
* the state of the 'sound enabled' checkbox */
inner = create_inner_grid();
gtk_widget_set_margin_top(inner, 16);
- gtk_grid_attach(GTK_GRID(outer), inner, 0, 2, 2, 1);
+ gtk_grid_attach(GTK_GRID(outer), inner, 0, 3, 2, 1);
gtk_widget_show_all(outer);
return outer;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|