MMBasic for Windows - support for Xbox and DualShock 4 controllers


Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 11168
Posted: 05:47pm 23 Dec 2023      

V5.07.03b24


MMBasic.zip


New commands

GAMEPAD ON [interrupt] [,MASK] ' mask specifies which buttons should trigger an interrupt - defaults to all
GAMEPAD OFF
GAMEPAD VIBRATE n' (n=1 to 100)
GAMEPAD STOP 'Stops vibration

NB: the vibrate commands appear to be coded correctly but don't work on my cheap second-hand DualShock4. The code including vibrate isn't tested on a XBox controller which is supposed to be supported but I don't have one.
After the GAMEPAD ON command the first button pressed on the controller activates the system and will report that the controller is connected if all is well. The command can be issued at the command line

NB: The gamepad must be connected to the computer when MMBasic is started

New Function

GAMEPAD(func)

func is the same as the PicoMite and CMM2 i.e. LX, LY, RX, RY for the joysticks and L and R for the analogue buttons. B returns the digital buttons as a bitmap identical to the Wii Classic on the CMM2 and PicoMite. See the example code below
gamepad on myint
Pause 1000
Do
Loop
Sub myint
Static integer l%=0
m%=1
a%=gamepad(b)
t%=l% Xor a%
If t% And m% Then
  If a% And m% Then : Print "R_ON":Else : Print "R_OFF":EndIf
EndIf
Inc m%,m%
If t% And m% Then
  If a% And m% Then : Print "Start_ON":Else : Print "Start_OFF":EndIf
EndIf
Inc m%,m%
If t% And m% Then
  If a% And m% Then : Print "Home_ON":Else : Print "Home_OFF":EndIf
EndIf
Inc m%,m%
If t% And m% Then
  If a% And m% Then : Print "Select_ON":Else : Print "Select_OFF":EndIf
EndIf
Inc m%,m%
If t% And m% Then
  If a% And m% Then : Print "L_ON":Else : Print "L_OFF":EndIf
EndIf
Inc m%,m%
If t% And m% Then
  If a% And m% Then : Print "DOWN_ON":Else : Print "DOWN_OFF":EndIf
EndIf
Inc m%,m%
If t% And m% Then
  If a% And m% Then : Print "RIGHT_ON":Else : Print "RIGHT_OFF":EndIf
EndIf
Inc m%,m%
If t% And m% Then
  If a% And m% Then : Print "UP_ON":Else : Print "UP_OFF":EndIf
EndIf
Inc m%,m%
If t% And m% Then
  If a% And m% Then : Print "LEFT_ON":Else : Print "LEFT_OFF":EndIf
EndIf
Inc m%,m%
If t% And m% Then
  If a% And m% Then : Print "ZR_ON":Else : Print "ZR_OFF":EndIf
EndIf
Inc m%,m%
If t% And m% Then
  If a% And m% Then : Print "X_ON":Else : Print "X_OFF":EndIf
EndIf
Inc m%,m%
If t% And m% Then
  If a% And m% Then : Print "A_ON":Else : Print "A_OFF":EndIf
EndIf
Inc m%,m%
If t% And m% Then
  If a% And m% Then : Print "Y_ON":Else : Print "Y_OFF":EndIf
EndIf
Inc m%,m%
If t% And m% Then
  If a% And m% Then : Print "B_ON":Else : Print "B_OFF":EndIf
EndIf
Inc m%,m%
If t% And m% Then
  If a% And m% Then : Print "ZL_ON":Else : Print "ZL_OFF":EndIf
EndIf
l%=a%
End Sub


Edited 2023-12-24 04:17 by matherp