USBJoystick 0.12

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

Re: USB Joystick driver

Post by richw »

I agree that it looks to be down to reportid. I have not had much chance to play (hopefully later), and the reportid is exactly one byte, so would explain your offset.

I am nervous about hacking the netbsd code, since that should be solid. I think it is my calling function, which isn't coping with collections (multiple reportid values).

The broken scaling is entirely my fault for changing the way it worked late on, and it is hard for me to test, as I don't have an analogue device. I shall try to fix.

Thanks for the pointers.
JonAbbott
Posts: 2938
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: USB Joystick driver

Post by JonAbbott »

There appears to be a problem with the Serial Port emulation. If it's enabled Jahangir Khan World Championship Squash crashes after the loader screen.

From the crash it looks like register corruption is occurring as IRQ R14 is randomly changing to a value in the range of &110..&113

EDIT: I've traced it to the calls to sub functions in swi_joystick_status. Looking at the compiled code, ukswiv_hook immediately changing into SVC, and does some funky stuff, such as:

Code: Select all

MOV R10, R13, LSR #20
MOV R10, R10, LSL #20
LDMIA R10, {R4, R5}
That's potentially going to cause a problem if the stack isn't aligned the way it's expecting. It's always possible its my copy of DDE24 that's causing these issues, as they look like compilerisms.
JonAbbott
Posts: 2938
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: USB Joystick driver

Post by JonAbbott »

richw wrote: Fri Mar 30, 2018 2:22 pm The broken scaling is entirely my fault for changing the way it worked late on, and it is hard for me to test, as I don't have an analogue device. I shall try to fix.
Now that I have the MS FF2 Joystick working, I can easily confirm its scaling correctly once you’ve made the changes.
richw
Posts: 159
Joined: Sat Sep 14, 2013 9:05 pm

Re: USB Joystick driver

Post by richw »

I've only had a little time to play, but the reportid does look to be the key. I have been trying different values, and even had my psx pad spring into life. That actually has analogue sticks on it too, so it should be another good test. My other device was pure digital (hat).

I have started crafting a function to query the available reportid value and use it appropriately, including offsetting the data reads. The NetBSD documents indicate that such a function exists, but the source code does not!

Hopefully I shall be able to carry on over the easter weekend.
JonAbbott
Posts: 2938
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: USB Joystick driver

Post by JonAbbott »

I'm going to do some more digging into the crash under ADFFS, I'm not sure at this point how to test if it is the stack alignment assumption DDE is making that's causing the problem. I'm not sure why it clears the bottom 20 bits and then loads R4, R5 from it...that sounds like it should cause an instant crash to me as the stack goes down, not up.

EDIT: It appears I've raised this issue previously, here's Jeffrey's response (see this thread):
All C modules assume that the SVC stack (and IRQ stack?) have their base on a 1MB boundary. It’s due to the nasty way in which they need to set up the C relocation offsets at the base of the stack. I don’t like it, but I don’t think it’s something that we can change without breaking compatibility with all existing C modules.
So that's going to be a problem, as a game is potentially going to set the stack(s) to any address in memory. A possible solution is to create a DA that's aligned to a 1MB boundary and switch to it in the UKSWIV pre-veneer, I'll code it up and see if it does resolve the issue.

EDIT2: It's not the stack alignment causing the crash. I've also tried turning IRQ off around the UKSWIV call, to rule out re-entrancy. Which leaves stack/register/flag corruption to investigate.

EDIT3: I've ruled out SVC register corruption and SVC flags are being preserved. From looking at the Jahangir Khan code, the issue is IRQ R14 is getting corrupt...which is more than likely a bug in JK's source, as it should preserve IRQ R14 before switching into SVC and issuing VTJoystick_Status. I wonder how many other games are affected?

EDIT4: Seems I was just unlucky in that the first game I tested crashed. I've tested as many other games that support the Serial Port interface as I could find and they all worked. Attached is an update boot script for Jahangir Khan to prevent the crash, replace the copy in Obey.zip (see later post for updated obey.zip)
JonAbbott
Posts: 2938
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: USB Joystick driver

Post by JonAbbott »

Whilst looking through the Jahangir Khan code, I've spotted it's calling an additional VTJoystick SWI:

81541 - VTJoystick_Define (R0=table pointer, R1=size of table)

The table contains the following:

Code: Select all

0000C001 00100012 0000C001 00100011 0000C001 00100014 0000C001 00100018
0000C001 00000012 0000C001 00000011 0000C001 00000014 0000C001 00000018 
0000C001 00000020 0000C401 00100110 0000C401 00100410 0000C401 00100810 
0000C401 00000210 0000C401 00000110 0000C401 00000410 0000C401 00000810 
0000C401 00002000
I can't find any documentation on the VTJoystick SWI's, so am not sure what its doing.
JonAbbott
Posts: 2938
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: USB Joystick driver

Post by JonAbbott »

I've had a look at the XB360 and XBOne controllers, neither are HID compliant. I can't even get any data out of them without first sending magic packets to them.

Attached are the updated ADFFS Modules that implement the RTFM interface. (see later post for updated Modules)
richw
Posts: 159
Joined: Sat Sep 14, 2013 9:05 pm

Re: USB Joystick driver

Post by richw »

Thanks. I shall mull over the SWI issue.

I have just posted 0.04 which I hope is better regarding HID parsing (reportid) and hotplug. I wanted to test the scaling, but my analogue stick is intermittent. I think I need a powered USB hub for my Pi.
JonAbbott
Posts: 2938
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: USB Joystick driver

Post by JonAbbott »

richw wrote: Sat Mar 31, 2018 7:30 pm I have just posted 0.04 which I hope is better regarding HID parsing (reportid) and hotplug. I wanted to test the scaling, but my analogue stick is intermittent. I think I need a powered USB hub for my Pi.
Sweet, it now detects my Joystick okay. Hot plugging also detects the Joystick, but reports "Joystick not open" when you try to map it, "Data steam open:" reports "No (is something else using it?)". If the Joystick is plugged in before you load the Module, it works okay.

The scaling is now correct, except when the X/Y are at minimum (-512) the value returned is &80 - it needs capping at &7F.

Other than those minor issues, its looking good. Incidentally, the Module version number/date need updating, its still 0.03.
richw
Posts: 159
Joined: Sat Sep 14, 2013 9:05 pm

Re: USB Joystick driver

Post by richw »

Bah. I wonder if I have managed to upload the wrong version! I shall see if I can have a quick look...
Post Reply