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.
|