USBJoystick 0.12

USB Joystick driver for RISC OS 5
Post Reply
Vanfanel
Posts: 576
Joined: Mon Sep 16, 2013 12:01 am

Re: USB Joystick driver

Post by Vanfanel »

Version 0.05 cures the "joystick stuck in perpetual lower-left position" problem!! Great!! None of the games that had the issue are having that issue anymore. I take you don't need the data you asked for, Jon? Since the bug is gone now.

These games however still have issues (will add more to the list as I find them):
-Xenon 2 (ADFFS): only fire button works, no directions
-Magic Pokets(ADFFS): crashes *only when the USBJoystick module is loaded*.
-Spheres of Chaos(ADFFS): crashes to a black screen *only when the USBJoystick module is loaded*.

Other games work or just ignore the joystick input.
-Chuck Rock (ADFFS) ignores the joystick
-Burn'out (ADFFS) seems to support Accorn and RTFM joysticks but none of them work
-Wolfenstein3D(ADFFS) was affected by the down-left bug, but ignores the joystick.

With other games I can't be sure if they support joystick at all.

@richw: Could it be possible to have a parameter to *usbjoystick_map so that UP is mapped to another joystick button? Pressing UP to jump isn't something I am fond from the Amiga days. And it sounds like an easy thing to add as an option, to be used with some games.
JonAbbott
Posts: 2938
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: USB Joystick driver

Post by JonAbbott »

Vanfanel wrote: Sun Apr 01, 2018 11:49 pm -Magic Pokets(ADFFS): crashes *only when the USBJoystick module is loaded*.
-Spheres of Chaos(ADFFS): crashes to a black screen *only when the USBJoystick module is loaded*.
It's possible these have bugs in their IRQ handlers, I'll need to check the code. In the dark ages, its unlikely IRQ's would be occurring when games are running, so these bugs didn't show up. Now that we have USB trigging IRQ's, any game that doesn't preserve R14 immediately on entry to its IRQ routine is likely to crash if it doesn't immediately disable IRQ.

Acorn documentation does explicitly state R14 should not be used in IRQ mode, but very few game developers heeded that advice with many either failing to store R14 on entry or calling subroutines via BL.
Vanfanel wrote: Sun Apr 01, 2018 11:49 pm -Chuck Rock (ADFFS) ignores the joystick
There's a few Krysalis titles which use a proprietary Joystick Module (JoyMod). They first run JSTest which issues SWI &EFFC0 - if it fails, they disable the Joystick. I've not tested it, but try replacing the "Run <Chuck$Dir>.JSTest" line in the !Run (or Obey.zip/F1008101) with:

Code: Select all

RMLoad <Chuck$Dir>.JoyMod
Set JSflag 1 
I did 32bit JoyMod (it's in !ADFFS.extras), but have a feeling its possibly proprietary to each game - the one I converted mentions PipeMania within it. If we can figure out what the SWI's it provides does, it may be possible to extend USBJoystick to mirror the JoyMod functionality.
Vanfanel wrote: Sun Apr 01, 2018 11:49 pm -Burn'out (ADFFS) seems to support Acorn and RTFM joysticks but none of them work
-Wolfenstein3D(ADFFS) was affected by the down-left bug, but ignores the joystick.
Wolfenstein 3D was working for me a few days ago, I'll test with 0.05. I've yet to try Burn'Out.

I'll have to create a separate post detailing games that support Joystick.
JonAbbott
Posts: 2938
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: USB Joystick driver

Post by JonAbbott »

richw wrote: Sun Apr 01, 2018 8:54 pm I've just released 0.05 which I'm hoping will sort out the scaling in the Acorn (and Jon's RTFM) method.
The values returned by Joystick_Read are the wrong way round for me. All the way down is returning 0 (should be -127), centred is returning 127 (should be 0) and all the way up is returning -2 (should be 127). The Joystick axis read -512/-512 at top/left and 511/511 at bottom right.
richw wrote: Sun Apr 01, 2018 8:54 pm Chris: When Jon mentioned his XBOX controllers, I did a bit of research. Looks like these (and certain PlayStation controllers) are USB devices, but do not follow the standard HID model. They have some sort of bespoke configuration, meaning they need a special driver. It looks like various people have produced fake HID report descriptors which can be used to understand their data format.
I don't know about the PlayStation controllers, but XB controllers aren't HID so couldn't even be made to work with a manually injected a HID descriptor. They would need a driver as they only return data on the endpoint once they're received a packet.

That said, I expect there are plenty of HID devices which would work via injecting a HID descriptor. I've yet to look at the steering wheel I have, but suspect an HID descriptor might get it working. At some point, I'll plug it in and see if it sends data and if so, what format that data is in, I can then build a USB descriptor using the USB Descriptor Tool.

Probably the best way to do it is provide a command where you specify the manufacture/device ID's and a USB Descriptor filename. If the device is seen, load the USB Descriptor before parsing it.
JonAbbott
Posts: 2938
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: USB Joystick driver

Post by JonAbbott »

JoyMod was originally provided to allow Joysticks on the Parallel port. Here's the source for the first version provided with Manchester United:

Code: Select all

REM>JoymodSrc
MODE 0
PRINT "Click on !!MUFC!! to start the game"
PRINT
PRINT "For Acorn computer experts only:"
PRINT "This is the source code for the joystick module on the disk (inside !!MUFC!!)"
PRINT "It works with two 1 of 8 input selectors connected to the parallel printer port"
PRINT "{Cost of parts about £8 ish}."
PRINT "Experienced users can change this to suit any hardware they may have."
PRINT "The bit patterns for each joystick are active set. {%000FUDLR}"
PRINT "We cannot supply the hardware,and cannot accept any responsiblity for any use"
PRINT "of the joystick module it's use or advise modifications."
PRINT "You will have to enable the joystick module on the define keys screen of the"
PRINT "Manchester United Management Section."
PRINT "We intend to {and hope others will} support this module and SWI number &CFFC0"
PRINT "in the future. Note that this SWI number is a USER number and was NOT allocated"
PRINT "by Acorn."
PRINT "This program also supports the Voltmace analogue mouse joystick.Enable as for   Joystick module."
PRINT
JOYSWI=&CFFC0
sp=13             :REM Stack pointer
link=14           :REM Link register

DIM CODE 10000    :REM Where to stick the code
FOR PASS=0 TO 2 STEP 2
P%=CODE
[OPT PASS
.CODESTART
EQUD 0
EQUD INITIALISE-CODE
EQUD FINALISE-CODE
EQUD 0
EQUD MTITLE-CODE
EQUD HELPSTRING-CODE
EQUD 0         ;HELPTABLE
EQUD JOYSWI
EQUD SWI_ENTRY-CODE
EQUD SWI_DECODE_TABLE-CODE
EQUD 0




.INITIALISE
.FINALISE
MOV pc,link

.MTITLE EQUS "Joystick"
equb 0

.HELPSTRING
EQUS "Bogeysticks"
EQUB 9
EQUS "1.00 (5 Apr 1990)"
ALIGN


.SWI_ENTRY
CMP R11,#(JUMPEND-JUMPTB)/4
ADDCC PC,PC,R11,LSL #2
B UNKNOWN
.JUMPTB
BAL readstick0
BAL readstick1
.JUMPEND
.UNKNOWN
ADR R0,XERRORM
ORRS PC,R14,#1<<28
.XERRORM
EQUD &1E6
EQUS "No Such SWI (Joymodule)":equb 0
ALIGN



.SWI_DECODE_TABLE
 EQUS "Joy":EQUB 0
 EQUS "Read0":EQUB 0
 EQUS "Read1":EQUB 0
 ALIGN


.delay
   mov   pc,link
.readstick0              ;Read the joystick
   stmfd (sp)!,{link}
  ; swi   "OS_EnterOS"
   mov   r0,#0
   mov   r1,#31
   ldr   r2,pout        ;Printer data out
   mov   r3,#&3200000   ;Base of I/O page

   mov   r4,#&c1        ;Fire
   strb  r4,[r2]
   bl    delay
   ldrb  r4,[r3,#16]
   and   r4,r4,#1
   orr   r0,r0,r4,lsl #4

   mov   r4,#&c0        ;Up
   strb  r4,[r2]
   bl    delay
   ldrb  r4,[r3,#16]
   and   r4,r4,#1
   orr   r0,r0,r4,lsl #3

   mov   r4,#&c4        ;Down
   strb  r4,[r2]
   bl    delay
   ldrb  r4,[r3,#16]
   and   r4,r4,#1
   orr   r0,r0,r4,lsl #2

   mov   r4,#&c2        ;Left
   strb  r4,[r2]
   bl    delay
   ldrb  r4,[r3,#16]
   and   r4,r4,#1
   orr   r0,r0,r4,lsl #1

   mov   r4,#&c6        ;Right
   strb  r4,[r2]
   bl    delay
   ldrb  r4,[r3,#16]
   and   r4,r4,#1
   orr   r0,r0,r4

   orr   r1,r15,#3
   ;teqp  r1,#3
   ldmfd (sp)!,{pc}


.readstick1              ;Read the joystick
   stmfd (sp)!,{link}
   ;swi   "OS_EnterOS"
   mov   r1,#31
   ldr   r2,pout        ;Printer data out
   mov   r3,#&3200000   ;Base of I/O page

   mov   r4,#&c1        ;Fire
   strb  r4,[r2]
   bl    delay
   ldrb  r4,[r3]
   and   r4,r4,#64
   eor   r1,r1,r4,lsr #2

   mov   r4,#&c0        ;Up
   strb  r4,[r2]
   bl    delay
   ldrb  r4,[r3]
   and   r4,r4,#64
   eor   r1,r1,r4,lsr #3

   mov   r4,#&c4        ;Down
   strb  r4,[r2]
   bl    delay
   ldrb  r4,[r3]
   and   r4,r4,#64
   eor   r1,r1,r4,lsr #4

   mov   r4,#&c2        ;Left
   strb  r4,[r2]
   bl    delay
   ldrb  r4,[r3]
   and   r4,r4,#64
   eor   r1,r1,r4,lsr #5

   mov   r4,#&c6        ;Right
   strb  r4,[r2]
   bl    delay
   ldrb  r4,[r3]
   and   r4,r4,#64
   eor   r1,r1,r4,lsr #6

   mov   r0,r1


   orr   r1,r15,#3
   ;teqp  r1,#3
   ldmfd (sp)!,{pc}
.pin     dcd   &3200010
.pout    dcd   &3250010
.CODEEND
]
NEXT PASS
PRINT "Module ASSEMBLED"
PRINT
A$= "If you want to  save the new module type in:"+CHR$(13)+CHR$(10)+"*SAVE JoyMod "+STR$~CODE+"+"+STR$~(CODEEND-CODE)+CHR$(13)+CHR$(10)+"*SetType JoyMod Module"
PRINT A$
PRINT
PRINT "Please do not save the module on your original game disk!!!!"
PRINT
PRINT "RISC OS users can click on the new module from the desktop before clicking on"
PRINT "!!MUFC!! and this version of the module will be used instead if the one on the"
PRINT "disk."
It was later extended to provide RTFM and Serial Port support and Joystick->Keyboard translation with the following * Commands being added:
  • CustomTrap - use a key-table at a specified address
  • KeySet - sets Joystick mapping to a pre-defined keyset
  • KeyTrap - sets Joystick mapping for a specified game (ArcSocr, Balrena, BugHunt, Caverns, Crisis, DropShp, Etype, Hostage, HoverBd, Ibix, IDictor, Inertia, JetPack, Orion, PacMan, PipMan, Quazer, RedShft, Repton, Taliman, Teramex, Thunder, Battle, WhiteM, XRun, Zarch)
  • StopTrap - Disables the Joystick mapping
JoyMod SWI block: CFFC0
0 - Joy_Read0 (returns RTFM Joystick 0 value R0 = %FUDLR)
1 - Joy_Read1 (returns RTFM Joystick 1 value R0 = %FUDLR)
2 - Joy_Test (Checks for RTFM and returns R0=255 - Nothing in Econet port, R0=128 - Econet present, R0=0 - RTFM present)
3 - Joy_ReadPipe (Input R1=?, R2=table pointer. If R1<&11 or >=&1B returns R1=[R2, R1]. For R1=&11..1A returns R1=0 or 1 depending on an internal table read)

I've been through all the Krisalis games I have and determined the following rely on JoyMod for their Joystick support:
  • Champions: Jahangir Khan World Championship Squash
  • Chuck Rock
  • Chuck Rock [BUZZ version]
  • GODS (also has direct support for Serial Port)
  • GODS [RPC version] (also has direct support for Serial Port)
  • Jahangir Khan World Championship Squash
  • Jahangir Khan World Championship Squash [BUZZ version]
  • James Pond
  • James Pond [BUZZ version]
  • James Pond [SA version]
  • Krisalis Collection, The: Revelation! [BUZZ version]
  • Krisalis Collection, The: Terramex
  • Lotus Turbo Challenge 2 (also has direct support for Serial Port)
  • Mad Professor Mariarti
  • Mad Professor Mariarti [BUZZ version]
  • Manchester United
  • Manchester United [BUZZ version]
  • Manchester United Europe
  • Manchester United Europe [BUZZ version]
  • Nebulus
  • Pac-mania [Learning Curve version]
  • Pipe Mania [RPC version]
  • Revelation! [BUZZ version]
  • S.W.I.V.
  • S.W.I.V. [BUZZ version]
From comparing JoyMod 4.27 with the Joystick Module that comes with RTFM, it appears JoyMod is a later version of the RTFM Joystick Module, using the same SWI block and SWI's etc. It doesn't appear to provide Serial Port support so the games must be doing that themselves.

The original JoyMod attached above just supports Joysticks on the Parallel Port and was later dropped in favour of the RTFM version.
Vanfanel
Posts: 576
Joined: Mon Sep 16, 2013 12:01 am

Re: USB Joystick driver

Post by Vanfanel »

@Jon: I have tried what you said in Chuck Rock's !Run, and it made no difference, the joystick is still ignored.
JonAbbott
Posts: 2938
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: USB Joystick driver

Post by JonAbbott »

Vanfanel wrote: Mon Apr 02, 2018 3:35 pm @Jon: I have tried what you said in Chuck Rock's !Run, and it made no difference, the joystick is still ignored.
See what the following shows from an F12 command prompt:

Code: Select all

GOS
GOARM3JIT 0
BASIC
MODE 0
*RMLOAD JoyMod      (from the Chuck Rock directory)
SYS "Joy_Test" TO A%:IF A%=0 PRINT "RTFM Found"
REPEAT:SYS "Joy_Read0" TO A%:PRINTTAB(0,0) ~A%:UNTIL 0
If that doesn't show any Joystick movement, press ESC and see what the following shows:

Code: Select all

REPEAT:PRINTTAB(0,0) ~?&33A0004:UNTIL 0
To return to the desktop:

Code: Select all

QUIT
GOARM3JIT
QUIT
I've just tested on my Pi3 and Chuck Rock is working with a Joystick for me.
Vanfanel
Posts: 576
Joined: Mon Sep 16, 2013 12:01 am

Re: USB Joystick driver

Post by Vanfanel »

@Jon: I can't test these scripts because I have no "~" on the spanish keyboard. I know it sounds stupid :(
I have however tried to put the first one on a text file, make it of the "obey" filetype, put it on the !Chuck directory, and run it as supervisor after manually doing the "GOARM3JIT 0". But once it enters BASIC, it won't go on executing the rest of the commands (the change to BASIC of course stops the script execution). Its there a way I can load the last fragment from BASIC and run it?

What I mean is that I must manually do:

Code: Select all

GOS
GOARM3JIT 0
BASIC
MODE 0
Once in BASIC, all I have to run is this:

Code: Select all

*RMLOAD JoyMod
SYS "Joy_Test" TO A%:IF A%=0 PRINT "RTFM Found"
REPEAT:SYS "Joy_Read0" TO A%:PRINTTAB(0,0) ~A%:UNTIL 0
Is there a way to load a text file from BASIC as a BASIC sequence? I guess there must be, on the speccy and MSX I did it a lot of times.
I tried LOAD "test1". where test1 is a text file of the basic type, but I get "bad program" error.
I also tried LOADTEXT "test1" after adding line numbers to the BASIC file like this:

Code: Select all

10 *RMLOAD JoyMod
20 SYS "Joy_Test" TO A%:IF A%=0 PRINT "RTFM Found"
30 REPEAT:SYS "Joy_Read0" TO A%:PRINTTAB(0,0) ~A%:UNTIL 0
But I get "Unknown of missing variable"
JonAbbott
Posts: 2938
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: USB Joystick driver

Post by JonAbbott »

Just miss off the ~ - it's not important
Vanfanel wrote: Mon Apr 02, 2018 5:05 pmIs there a way to load a text file from BASIC as a BASIC sequence?
*EXEC
Vanfanel
Posts: 576
Joined: Mon Sep 16, 2013 12:01 am

Re: USB Joystick driver

Post by Vanfanel »

JonAbbott wrote: Mon Apr 02, 2018 5:27 pm Just miss off the ~ - it's not important
Vanfanel wrote: Mon Apr 02, 2018 5:05 pmIs there a way to load a text file from BASIC as a BASIC sequence?
*EXEC
Ok! Got the script to work!

After the line

Code: Select all

SYS "Joy_Test" TO A%:IF A%=0 PRINT "RTFM Found"
I get

Code: Select all

RTFM Found
So the joystick is found as an RTFM joy, I guess.

Next I do

Code: Select all

REPEAT:SYS "Joy_Read0" TO A%:PRINTTAB(0,0) A%:UNTIL 0
And I get these numbers:

-When I don't press anything: 0
-Press RIGHT: 1
-Press LEFT: 2
-Press DOWN: 4
-Press UP: 8
-Press the button I set up for UsbJoystick: 16
I get some numbers for diagonals, too.
JonAbbott
Posts: 2938
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: USB Joystick driver

Post by JonAbbott »

RTFM is working correctly, so Chuck Rock should be working provided the JoyMod Module is loaded.
Post Reply