'===============================================================================
' Project: PlayStationII Wireless (or wired) controller reader
' Version: v1.0
' Created: 2010-03-27
' By: Glen Aidukas (C)Bahbots.com
' Credits: Original help from Eddy Wright on the PS2 protocol
'
' Description:
'
' PS2 Shockwave controller wiring and PSI data reading
' _____________________________
' | |
' | |1 2 3||4 5 6||7 8 9| | <-- Male connector of controller
' \___________________________/
'
' Pin Color Function Notes
' 1 GREEN MISO Data In
' 2 WHITE MOSI Command out
' 3 VIBRATE +9V
' 4 BLACK GND
' 5 RED VCC 3.3V-5V
' 6 BLUE SS Select
' 7 YELLOW SCK Clock
' 8 N/C N/C
' 9 ACK N/C
'
' This code was tested and working with a wireless PlayStationII controller
'===============================================================================
$regfile = "m32Def.dat"
$crystal = 8000000
$hwstack = 32
$swstack = 16
$framesize = 48
$baud = 38400
'=====[ Dimension and initialize variables ]====================================
Dim Ps2_cmd(2) As Byte ' init cmd sent to PS2 controller
Dim Ps2_data(7) As Byte ' hold returned data from PS2 controller
Dim I As Byte ' General purpose variables
Ps2_miso Alias Pinb.0 : Ddrb.0 = 0 ' data in
Ps2_mosi Alias Portb.1 : Ddrb.1 = 1 ' data out
Ps2_ss Alias Portb.2 : Ddrb.2 = 1 ' Select
Ps2_sck Alias Portb.3 : Ddrb.3 = 1 ' Clock
Ps2_miso = 1 ' turn on internal pull up resister
Ps2_cmd(1) = &H01 ' Start Command
Ps2_cmd(2) = &H42 ' Request Data
'-------------------------------------------------------------------------------
Print "{027}[2J" ; ' ansi clear screen...
print "Starting..."
Cls
Do
Gosub Ps2_read ' read the PS controller data
print "{027}[3;1H"; ' move to page top (ansi)
print "Byte1 : " ; Ps2_data(1) ; " "
''print ""
print "Select: " ; Ps2_data(2).0 ; " Start : " ; Ps2_data(2).3
print "ThumbL: " ; Ps2_data(2).1 ; " ThumbR: " ; Ps2_data(2).2
''print ""
print "CNT-Up: " ; Ps2_data(2).4 ; " CNT-R : " ; Ps2_data(2).5
print "CNT-Dn: " ; Ps2_data(2).6 ; " CNT-L : " ; Ps2_data(2).7
'print ""
print "L1 : " ; Ps2_data(3).2 ; " R1 : " ; Ps2_data(3).3
print "L2 : " ; Ps2_data(3).0 ; " R2 : " ; Ps2_data(3).1
''print ""
print "Triang: " ; Ps2_data(3).4 ; " Cross : " ; Ps2_data(3).6
print "Circle: " ; Ps2_data(3).5 ; " Square: " ; Ps2_data(3).7
''print ""
print "Joy RX: " ; Ps2_data(4) ; " "
print "Joy RY: " ; Ps2_data(5) ; " "
print "Joy LX: " ; Ps2_data(6) ; " "
print "Joy LY: " ; Ps2_data(7) ; " "
'waitms 100
Loop
'-------------------------------------------------------------------------------
'=====[ Read the PS2 controller data ]==========================================
Ps2_read:
Ps2_ss = 0 ' assert select line
Shiftout Ps2_mosi , Ps2_sck , Ps2_cmd(1) , 2 , 8 , 20 ' send start command
Shiftout Ps2_mosi , Ps2_sck , Ps2_cmd(2) , 2 , 8 , 20 ' send request data cmd
For I = 1 To 7
Shiftin Ps2_miso , Ps2_sck , Ps2_data(i) , 2 , 8 , 20 ' read in data
Next I
Ps2_ss = 1 ' release select line
Return
'-------------------------------------------------------------------------------
|