1 | Konfiguration ***
|
2 | '*******************************************************************************
|
3 | 'AVR
|
4 | $regfile = "M32def.dat"
|
5 | $crystal = 16000000
|
6 | $hwstack = 100
|
7 | $swstack = 100
|
8 | $framesize = 100
|
9 | $baud = 19200
|
10 |
|
11 |
|
12 | '**************************************************************************
|
13 | '*** Ein-Ausgängedefinieren ***
|
14 | '**************************************************************************
|
15 | Config Portd.6 = Output
|
16 | Pad_att_line Alias Portd.6
|
17 |
|
18 | '**************************************************************************
|
19 | '*** Variablen ***
|
20 | '**************************************************************************
|
21 | Dim Cmdstart As Byte
|
22 | Cmdstart = &H01
|
23 | Dim Cmdstatus As Byte
|
24 | Cmdstatus = &H42
|
25 |
|
26 | 'PSX Type ID
|
27 | Const Cnstid_digital = &H41
|
28 | Const Cnstid_negocn = &H23
|
29 | Const Cnstid_analogred = &H73
|
30 | Const Cnstid_analoggreen = &H53
|
31 |
|
32 | 'These are for local storage of last read packet from PSX PAD
|
33 | Dim Pspad_present As Byte
|
34 | Dim Pspad_mode As Byte
|
35 | Dim Pspad_byte1 As Byte
|
36 | Dim Pspad_byte2 As Byte
|
37 |
|
38 | 'PSX PAD Joysticks
|
39 | 'Horizontal
|
40 | Dim Pspad_rjoy_h_pos As Byte '0 = Left , 255 = Right
|
41 | Dim Pspad_ljoy_h_pos As Byte '0 = Left , 255 = Right
|
42 |
|
43 | 'Vertikal
|
44 | Dim Pspad_rjoy_v_pos As Byte '0 = Up , 255 = Down
|
45 | Dim Pspad_ljoy_v_pos As Byte '0 = Up , 255 = Down
|
46 |
|
47 |
|
48 | '**************************************************************************
|
49 | '*** Alias Namen für PSX-PAD Tasten ***
|
50 | '**************************************************************************
|
51 | Pspad_key_select Alias Pspad_byte1.0
|
52 | Pspad_key_joyr Alias Pspad_byte1 .1
|
53 | Pspad_key_joyl Alias Pspad_byte1.2
|
54 | Pspad_key_start Alias Pspad_byte1.3
|
55 | Pspad_key_up Alias Pspad_byte1.4
|
56 | Pspad_key_right Alias Pspad_byte1.5
|
57 | Pspad_key_down Alias Pspad_byte1.6
|
58 | Pspad_key_left Alias Pspad_byte1.7
|
59 |
|
60 | Pspad_key_l2 Alias Pspad_byte2.0
|
61 | Pspad_key_r2 Alias Pspad_byte2.1
|
62 | Pspad_key_l1 Alias Pspad_byte2.2
|
63 | Pspad_key_r1 Alias Pspad_byte2.3
|
64 | Pspad_key_triangle Alias Pspad_byte2.4
|
65 | Pspad_key_circle Alias Pspad_byte2.5
|
66 | Pspad_key_x Alias Pspad_byte2.6
|
67 | Pspad_key_square Alias Pspad_byte2.7
|
68 |
|
69 | '**************************************************************************
|
70 | '*** Subroutine Declaration ***
|
71 | '**************************************************************************
|
72 | Declare Sub Query_pspad
|
73 |
|
74 | '**************************************************************************
|
75 | '*** SPI-Mode in Hardware konfigurieren ***
|
76 | '**************************************************************************
|
77 | Config Spi = Hard , Interrupt = Off , Data Order = Lsb , Master = Yes , _
|
78 | Polarity = High , Phase = 1 , Clockrate = 128
|
79 | Spiinit
|
80 |
|
81 | '**************************************************************************
|
82 | '*** HAUPTPROGRAMM ***
|
83 | '**************************************************************************
|
84 |
|
85 | Do
|
86 | 'Buttons are active low
|
87 | 'Update langsam zum testen im Terminal
|
88 | Waitms 1000
|
89 | 'Get current Button states from PSX-Controller
|
90 | Gosub Query_pspad
|
91 | 'Now do something base on the results
|
92 | If Pspad_present = 1 Then '0 = not present , 1 = present
|
93 |
|
94 | Print "Select:" ; Pspad_key_select
|
95 | Print "JoyR:" ; Pspad_key_joyr
|
96 | Print "JoyL:" ; Pspad_key_joyl
|
97 | Print "Start:" ; Pspad_key_start
|
98 | Print "Up:" ; Pspad_key_up
|
99 | Print "Right:" ; Pspad_key_right
|
100 | Print "Down:" ; Pspad_key_down
|
101 | Print "Left:" ; Pspad_key_left
|
102 | Print "L2:" ; Pspad_key_l2
|
103 | Print "R2:" ; Pspad_key_r2
|
104 | Print "L1:" ; Pspad_key_l1
|
105 | Print "R1:" ; Pspad_key_r1
|
106 | Print "Triangle:" ; Pspad_key_triangle
|
107 | Print "Circle:" ; Pspad_key_circle
|
108 | Print "X Key:" ; Pspad_key_x
|
109 | Print "Square:" ; Pspad_key_square
|
110 | Print "Right Joystick H Position:" ; Pspad_rjoy_h_pos
|
111 | Print "Right Joystick V Position:" ; Pspad_rjoy_v_pos
|
112 | Print "Left Joystick H Position:" ; Pspad_ljoy_h_pos
|
113 | Print "Left Joystick V Position:" ; Pspad_ljoy_v_pos
|
114 |
|
115 | Else
|
116 | Print " No Response From PSX-PAD"
|
117 | End If
|
118 |
|
119 | Loop
|
120 |
|
121 | '**************************************************************************
|
122 |
|
123 | Sub Query_pspad
|
124 | Reset Pad_att_line 'Get PSX-PAD Attention
|
125 | Spiout Cmdstart , 1 'Send Start
|
126 | Pspad_mode = Spimove(cmdstatus) 'Send Request, Receive ID Byte
|
127 |
|
128 | Spiin Pspad_present , 1 'Is PAD Responding
|
129 | 'Now see if the Controller is going to send something
|
130 |
|
131 |
|
132 | If Pspad_present = 90 Then '90 = Data on its way
|
133 | Pspad_present = 1 'Set the global bit
|
134 | Spiin Pspad_byte1 , 1 'Byte 1 and 2 are always used
|
135 | Spiin Pspad_byte2 , 1
|
136 | Spiin Pspad_rjoy_h_pos , 1 'Byte 3-6 are for Analog Modes
|
137 | Spiin Pspad_rjoy_v_pos , 1
|
138 | Spiin Pspad_ljoy_h_pos , 1
|
139 | Spiin Pspad_ljoy_v_pos , 1
|
140 | Set Pad_att_line
|
141 |
|
142 | Else
|
143 |
|
144 | Pspad_present = 0 'Set the global state set Pad_Att_Line 'Release Attention Line to the PS2 PAD
|
145 |
|
146 | End If
|
147 |
|
148 | End Sub
|
149 |
|
150 |
|
151 | '*******************************************************************************
|