USBJoystick 0.22 - prototype

USB Joystick driver for RISC OS 5
Post Reply
richw
Posts: 159
Joined: Sat Sep 14, 2013 9:05 pm

USBJoystick 0.22 - prototype

Post by richw »

Here is a prototype build. The main changes are:

More buttons

The Acorn Joystick_Read SWI can provide more buttons.

API for listing devices and axes

The Acorn Joystick_Read SWI has additional reason codes. These allow you to:
  • Discover the connected joysticks
  • Query the axes availability/configuration for a joystick
  • Query the axes values
'Documentation' can be found by reading the source code (joyswis.c) and/or studying the utils.acorntest2 BASIC program.

Not sure what I think about the SWI approach. It's not something I have previously studied or designed! I'm happy to receive feedback, and expect the new reason codes to change. Probably wise at this point to NOT release any applications using them!
Attachments
usbjoystick022.zip
(217.61 KiB) Downloaded 397 times
JonAbbott
Posts: 2957
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: USBJoystick 0.22 - prototype

Post by JonAbbott »

richw wrote: Fri Aug 18, 2023 4:53 pm Not sure what I think about the SWI approach. It's not something I have previously studied or designed! I'm happy to receive feedback, and expect the new reason codes to change. Probably wise at this point to NOT release any applications using them!
Great, this adds things I could use for games. Using SWI reason codes seem fine to me.

I noted the games that need two thumb-sticks in this post, I can update the Joystick mapping in ADFFS to support additional Axis and try this.

Looking though acorntest2 and joyswi it's not immediately obvious to me how I would go about reading the Left and Right thumb-sticks on an XB360 controller? Documentation on the reason codes and data structures would be really useful ;)

I think I need to call Joystick_Read with R0=&40 + <joystick no> and it returns a pointer to the Joystick Axis data via R2, but what is the structure?

Assuming its something like:

Code: Select all

+0 Left-thumb Left/Right
+4 Left-thumb Up/Down
+8 Right-thumb Left/Right
+12 Right-thumb Up/Down
+16 Left trigger
+20 Right trigger
Would they not potentially reorder depending on the Joystick make/model? How can I be certain I'm reading the left or right thumb-stick?
richw
Posts: 159
Joined: Sat Sep 14, 2013 9:05 pm

Re: USBJoystick 0.22 - prototype

Post by richw »

Yes, the ordering may change. The axes info will show you everything... the typeid, the name, min, mid, max and current value. So I suspect an 'advanced' game would show all of the axes and ask the user to pick which ones they wanted. That's what I've seen on PC games, when I last played them - about 20 years ago. ;)

I am away from the code at the moment, but I can't remember if I put the typeid into the structure. It's in the h/usbjoystick file... look at the structs with 'joy read' in their names. Sorry, I'll respond with something more useful, or maybe even edit the code, when I'm in front of the Pi. I wish I'd got simplegit figured out and uploaded it somewhere for easy browsing! Next time...
User avatar
IanJeffray
Posts: 162
Joined: Mon Jan 18, 2021 1:51 pm

Re: USBJoystick 0.22 - prototype

Post by IanJeffray »

JonAbbott wrote: Sat Aug 19, 2023 4:56 pm Would they not potentially reorder depending on the Joystick make/model? How can I be certain I'm reading the left or right thumb-stick?
NAFAIK.

You may find my "Dual joypad driver and test software" useful : http://ian.jeffray.co.uk/riscos/joypad/ - ignore the driver part, but the simple test software is validated with multiple implementations of modules that provide dual joystick support, including obviously my own.
JonAbbott
Posts: 2957
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: USBJoystick 0.22 - prototype

Post by JonAbbott »

richw wrote: Sat Aug 19, 2023 5:51 pm I can't remember if I put the typeid into the structure. It's in the h/usbjoystick file... look at the structs with 'joy read' in their names.
I'm assuming R2 points to a sequence of axisdata_struct, of which there's:

Code: Select all

uint32_t type; //todo: make a type/enum for this?
Which I presume is the Usage ID from the USB Device Descriptor? (ref. 5.5 Usages / p17 of Device Class Definition for Human Interface Devices (HID) and Table 4 / p26 of USB HID Usage Tables)

Looking though the USB spec. again, I don't think it differentiates between thumb-sticks as there's only provision for the data usage being X/Y/Z/Rx/Ry/Rz, so I think I can probably assume the first Rx/Ry Axis is always the primary thumb-stick. So...provided I can determine the type as Rx, Ry or Rz from the returned structure I think I'm good.
richw
Posts: 159
Joined: Sat Sep 14, 2013 9:05 pm

Re: USBJoystick 0.22 - prototype

Post by richw »

Almost. R2 points to a cut-down version of that struct (which is used internally). These are the 'public' structs...
struct joystick_read_dev_info_struct {
  uint8_t              joystick_id;
  char                 *device_path;
  char                 *manufacturer;
  char                 *product;
  char                 *serial;
  uint8_t              number_axes;
  uint8_t              number_buttons;
};

struct joystick_read_axes_info_struct {
  uint32_t             type;
  char                 *name;
  int32_t              min;
  int32_t              mid;
  int32_t              max;
  int32_t              val;
};

The 'values' code just returns a bunch of int32s.

The 'type' is one of:
#define AXIS_HATX     1
#define AXIS_HATY     2
#define AXIS_DPADX    3
#define AXIS_DPADY    4
#define AXIS_X        5
#define AXIS_Y        6
#define AXIS_Z        7
#define AXIS_RX       8
#define AXIS_RY       9
#define AXIS_RZ       10
#define AXIS_SLIDER   11

which I think I just made up. I cannot remember, to be honest. This list may grow over time, but I don't plan to change it. As USBJoystick discovers the device, it enumerates the axes and uses these to indicate which is which.

For the 'classic' Acorn/SerialPort/RTFM interface, I have an 'auto map' function which looks for DPADXY, then HATXY, then XY to work out which axes to use.

With the newer code, you just get them all and decide yourself which ones you want to use.

You could well be right about getting the primary thumb stick. Not a bad plan. But I bet there are devices which do things differently! There are workarounds in USBJoystick for the XBOX360 controller! (which I only out in as I have such a controller, and I think it's commonly copied)
Post Reply