robhagemans / pcbasic

PC-BASIC - A free, cross-platform emulator for the GW-BASIC family of interpreters
http://www.pc-basic.org
Other
396 stars 48 forks source link

STRIG function - buttons mapped to wrong joystick #158

Closed JDoucette closed 2 years ago

JDoucette commented 2 years ago

Bug report

Problem STRIG(x) returns the wrong buttons.

With Xbox 360 controller plugged into Windows 10 machine, and I run this program:

10 SCREEN 0:WIDTH 80
20 FOR I=0 TO 3:XY(I)=STICK(I):NEXT I
30 FOR I=0 TO 7:B(I)=STRIG(I):NEXT I
40 PRINT "Joy1:";XY(0);XY(1);B(0);B(1);B(4);B(5);"Joy2:";XY(2);XY(3);B(2);B(3);B(6);B(7)
50 GOTO 20

I see this option when pressing A and B buttons on joystick 1:

Joy1: 130  136 -1 -1  0  0 Joy2: 0  0  0 -1  0  0                               
Joy1: 130  136  0 -1  0  0 Joy2: 0  0  0 -1  0  0                               
Joy1: 130  136  0 -1  0  0 Joy2: 0  0  0 -1  0  0                               
Joy1: 130  136  0 -1  0  0 Joy2: 0  0  0  0  0  0                               
Joy1: 130  136  0 -1  0  0 Joy2: 0  0  0  0  0  0           

This corresponds to STRIG(x) for x = 0,1,2,3. But the documentation: https://robhagemans.github.io/pcbasic/doc/1.2/#STRIG-function Says that x = 0,1,4,5 are joystick 1. 2,3,6,7 are joystick 2.

Is the documentation wrong? Or is PC BASIC emulation wrong? Perhaps PC-BASIC could allow remapping of controller buttons, in case this is not clear, or in case Xbox controller does not follow standard button mappings for Windows (I seem to doubt that; it is probably standard).

Steps See program above. Run it. Press A and B on joystick one, and watch the output. Better yet: plug in joystick two, and see if that works as well (I have not tried).

Program See above.

Crash log None.

Notes

PC-BASIC version: 1.2.14 Operating system version: Windows 10

JDoucette commented 2 years ago

If you use the indexes in order, then the first 0,1,2,3 applies to Joystick 1, and 4,5,6,7 applies to Joystick 2.

40 SCREEN 0:WIDTH 80
50 X1=STICK(0):Y1=STICK(1)
60 X2=STICK(2):Y2=STICK(3)
70 J1ACHANGE=STRIG(0):J1ACURRENT=STRIG(1)
80 J1BCHANGE=STRIG(2):J1BCURRENT=STRIG(3)
90 J2ACHANGE=STRIG(4):J2ACURRENT=STRIG(5)
100 J2BCHANGE=STRIG(6):J2BCURRENT=STRIG(7)
110 PRINT USING "JOY1 X ### Y ### A ## ## B ## ## JOY2 X ### Y ### A ## ## B ## ##";X1;Y1;J1ACHANGE;J1ACURRENT;J1BCHANGE;J1BCURRENT;X2;Y2;J2ACHANGE;J2ACURRENT;J2BCHANGE;J2BCURRENT
120 GOTO 50
robhagemans commented 2 years ago

Fixed by commit 7ca38a81, thanks for reporting!