Getting B3D to work with XInput?

Blitz3D Forums/Blitz3D Beginners Area/Getting B3D to work with XInput?

It was somewhat, didn't notice there was even a thunderstorm going on until the power cut, and my room kept flickering every second, was a bit of a quiet storm as I couldn't hear the dang bolts even when I could see them from the window.

Anyways, mem-leak problem fixed (not going to mess with that kernel at this time), just trying to fix that analogue issue where it keeps returning random values at the most part, making it pretty much useless so far for an app. I doubled-checked the peek values, and it all appears fine.

Also, I believe the joystick peek offsets were a byte off, as when I set the peek offset up one for the joysticks, the values returned are consistent with the actual movement applied to the analogue sticks, exactly as I want them, except for the fact that that the 65535 value is split, where left-to-center range is 32768 to 65535, and from center-to-right is 0 to 32767......was curious if this also has to do with the signed/unsigned problem?

Current source files :

xinput.bb
Function xJoyPacket(port) ; Returns PacketNumber, usage is to see if controller has been used since last time.
	state = CreateBank(16)
	XInputGetState(port, state)
   	packetnumber = PeekInt(state, 0)
	FreeBank state
	
	Return packetnumber
End Function	


Function xJoyX#(port) ; Left Thumbstick X-Axis
	state = CreateBank(16)
	XInputGetState(port, state)
	sThumbLX# = PeekShort(state,8) 
	FreeBank state

	;sThumbLX= sThumbLX - 32767.5
	;sThumbLX = sThumbLX / 32767.5	

	Return sThumbLX
End Function

Function xJoyY#(port) ; Left Thumbstick Y-Axis
	state = CreateBank(16)
	XInputGetState(port, state)
	sThumbLY = PeekShort(state, 10) 	
	FreeBank state
	
;	sThumbLY = sThumbLY - 32767.5
	;sThumbLY = sThumbLY / 32767.5	
	
	Return sThumbLY
End Function

Function xJoyZ(port) ; Emulates DirectX behaviour
	state = CreateBank(16)
	XInputGetState(port, state)	
	bLeftTrigger = PeekByte(state, 6)
	bRightTrigger = PeekByte(state, 7)
	FreeBank state	

	Return (bLeftTrigger-bRightTrigger)	
End Function

Function xJoyZL(port) ; Left Trigger
	state = CreateBank(16)
	XInputGetState(port, state)
	bLeftTrigger = PeekByte(state,6)	
	FreeBank state
	
	Return bLeftTrigger
End Function

Function xJoyZR(port) ; Right Trigger
	state = CreateBank(16)
	XInputGetState(port, state)
	bRightTrigger = PeekByte(state, 7)
	FreeBank state
	
	Return bRightTrigger
End Function

Function xJoyU#(port) ; Right Thumbstick X-Axis
	state = CreateBank(16)
	XInputGetState(port, state)
	sThumbRX# = PeekShort(state, 12)
	FreeBank state
	
	;sThumbRX = sThumbRX - 32767.5
	;sThumbRX = sThumbRX / 32767.5

	Return sThumbRX
End Function


Function xJoyV#(port) ; Right Thumbstick Y-Axis
	state = CreateBank(16)
	XInputGetState(port, state)
	sThumbRY# = PeekShort(state, 14)	
	FreeBank state

	;sThumbRY = sThumbRY - 32767.5
	;sThumbRY = sThumbRY / 32767.5
	
	Return sThumbRY
End Function



Function xJoyType(index, value)
	
	cap = CreateBank(32)
	XInputGetCapabilities(index, 0, cap)
	
	If value = 0
		xType = PeekByte (cap, 0)
		Return xType
	ElseIf value = 1	
	xSubType = PeekByte (cap, 1)
		Return xSubType
	ElseIf value = 2
		xFlag = PeekShort (cap, 2)
		Return xFlag
	EndIf 

	FreeBank cap
End Function


Function xGetJoy(port)
	
	state = CreateBank(14)
   
	XInputGetState(port, state)
	button = PeekShort(state, 4)	
	
;	p = 1
;	For i = 1 To 16
;		If (button And p) = p Then 
;		Return p
;		End If 
;		p = p * 2
;	Next

	FreeBank state
	Return button
	
End Function



Function xJoyRumble(port, side, strength) ; Port: Controller Number , Side : 0 = Both, 1 = Left, 2 = Right, Strength:  0-65535

	Local rumble = CreateBank(4)

	If side = 0
		PokeShort rumble, 0, strength
		PokeShort rumble, 2, strength
	ElseIf side = 1
		PokeShort rumble, 0, strength
	ElseIf side = 2
		PokeShort rumble, 2, strength
	End If 
	
	XInputSetState(port, rumble)
	FreeBank rumble

End Function

xinputtest.bb
Include "xinput.bb"

Const XINPUT_GAMEPAD_DPAD_UP  = 1
Const XINPUT_GAMEPAD_DPAD_DOWN  =  2
Const XINPUT_GAMEPAD_DPAD_LEFT  = 4
Const XINPUT_GAMEPAD_DPAD_RIGHT =  8
Const XINPUT_GAMEPAD_START = 16
Const XINPUT_GAMEPAD_BACK = 32
Const XINPUT_GAMEPAD_LEFT_THUMB   =   64
Const XINPUT_GAMEPAD_RIGHT_THUMB   =   128
Const XINPUT_GAMEPAD_LEFT_SHOULDER = 256
Const XINPUT_GAMEPAD_RIGHT_SHOULDER  = 512
Const XINPUT_GAMEPAD_A = 4096
Const XINPUT_GAMEPAD_B =  8192	
Const XINPUT_GAMEPAD_X = 16384
Const XINPUT_GAMEPAD_Y =  32768

Graphics 800, 600, 0, 2
SetBuffer BackBuffer()
While Not KeyHit(1)

	Cls

		j = 150
		
		For i = 0 To 3
			Text 0,0+(i*j), "Controller: " + i
			Text 24,14+(i*j), "Packet Number: "+xJoyPacket(i)	
			Text 24,28+(i*j), "Buttons: "+xGetJoy(i)
			Text 24,42+(i*j), "Left Trigger: "+xJoyZL(i)
			Text 24,56+(i*j), "Right Trigger: "+xJoyZR(i)
			Text 24,70+(i*j), "Left Thumbstick X: "+ xJoyX#(i)
			Text 24,84+(i*j),"Left Thumbstick Y: "+ xJoyY(i)
			Text 24,98+(i*j), "Right Thumbstick X: "+xJoyU(i)
			Text 24,112+(i*j), "Right Thumbstick Y: "+xJoyV(i)
			Text 24,126+(i*j), "Direct-X Style Z Axis: " +xJoyZ(i)
			
			Text 275,42+(i*j), "Controller Type: "+xJoyType(i,0)
			Text 275,56+(i*j), "Controller SubType: "+xJoyType(i,1)
			Text 275,70+(i*j), "Controller Flags:"+xJoyType(i,2)

		
			Text 550,14+(i*j), "Press 'A' to test rumble"
			If xGetJoy(i) = 4096 
				xJoyRumble(i, 0, 30000)			
			Else
				xJoyRumble(i, 0, 0)	
			EndIf	
			
			
		Next
	Flip

Wend
End


.decls
.lib "xinput9_1_0.dll"
XInputGetState( index, state* )
XInputSetState( index, vibe* )
XInputGetCapabilities( index, flags, capabilities* )
XInputEnable( enable% )


Should grab me my brother's second controller and see if everything reads well for it.

Btw, the app seems to be running pretty darn slow when I have it checking for everything from all controllers, and I assume it's something of my fault, as I doubt checking for the status of four controllers would do this normally if implemented correctly, as there are games designed around multi-controller usage.
(albeit rare as they are on PCs these days)

I'm guessing it'd be the constant creation and deletion of banks eh? If that's the case, would there be any problems if I made a global fair-sized bank in the library and just had all the functions reference it instead and for-loop it clear after?