Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
361 | giacomo | 1 | |
2 | /* |
||
3 | * Project: S.Ha.R.K. |
||
4 | * |
||
5 | * Coordinators: Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * |
||
7 | * Authors : Mauro Marinoni <mauro.marinoni@unipv.it> |
||
8 | * (see authors.txt for full list of hartik's authors) |
||
9 | * |
||
10 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
11 | * |
||
12 | * http://www.sssup.it |
||
13 | * http://retis.sssup.it |
||
14 | * http://shark.sssup.it |
||
15 | */ |
||
16 | |||
17 | /* |
||
18 | * Copyright (C) 2000 Paolo Gai |
||
19 | * |
||
20 | * This program is free software; you can redistribute it and/or modify |
||
21 | * it under the terms of the GNU General Public License as published by |
||
22 | * the Free Software Foundation; either version 2 of the License, or |
||
23 | * (at your option) any later version. |
||
24 | * |
||
25 | * This program is distributed in the hope that it will be useful, |
||
26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
28 | * GNU General Public License for more details. |
||
29 | * |
||
30 | * You should have received a copy of the GNU General Public License |
||
31 | * along with this program; if not, write to the Free Software |
||
32 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
33 | * |
||
34 | */ |
||
35 | |||
36 | #include "kernel/kern.h" |
||
37 | #include "joy.h" |
||
38 | |||
39 | void get_joystick_buttons(JOY_BUTTONS *jb) |
||
40 | { |
||
41 | int j; |
||
42 | |||
43 | outp(JPORT, 0); |
||
44 | j = inp(JPORT); |
||
45 | jb->b1 = !(j & 0x10); |
||
46 | jb->b2 = !(j & 0x20); |
||
47 | jb->b3 = !(j & 0x40); |
||
48 | jb->b4 = !(j & 0x80); |
||
49 | } |
||
50 | |||
51 | int get_joystick_AB(JOY_STATE *jsa, JOY_STATE *jsb) |
||
52 | { |
||
53 | int i, j; |
||
54 | int mask = 15; |
||
55 | |||
56 | SYS_FLAGS f; |
||
57 | |||
58 | outp(JPORT, 0); |
||
59 | f = kern_fsave(); |
||
60 | for (i=1; mask && i<CMAX; i++) { |
||
61 | j = inp(JPORT) ^ mask; |
||
62 | if (j & 1) { jsa->x = i; mask ^= 1; } |
||
63 | if (j & 2) { jsa->y = i; mask ^= 2; } |
||
64 | if (j & 4) { jsb->x = i; mask ^= 4; } |
||
65 | if (j & 8) { jsb->y = i; mask ^= 8; } |
||
66 | } |
||
67 | kern_frestore(f); |
||
68 | j = inp(JPORT); |
||
69 | jsa->b1 = !(j & 0x10); |
||
70 | jsa->b2 = !(j & 0x20); |
||
71 | jsb->b1 = !(j & 0x40); |
||
72 | jsb->b2 = !(j & 0x80); |
||
73 | |||
74 | return i==CMAX ? -1 : 0; |
||
75 | } |
||
76 | |||
77 | int get_joystick_A(JOY_STATE *js) |
||
78 | { |
||
79 | int i, j; |
||
80 | int mask = 3; |
||
81 | |||
82 | SYS_FLAGS f; |
||
83 | |||
84 | outp(JPORT, 0); |
||
85 | f = kern_fsave(); |
||
86 | for (i=1; mask && i<CMAX; i++) { |
||
87 | j = inp(JPORT) ^ mask; |
||
88 | if (j & 1) { js->x = i; mask ^= 1; } |
||
89 | if (j & 2) { js->y = i; mask ^= 2; } |
||
90 | } |
||
91 | kern_frestore(f); |
||
92 | j = inp(JPORT); |
||
93 | js->b1 = !(j & 0x10); |
||
94 | js->b2 = !(j & 0x20); |
||
95 | |||
96 | return i==CMAX ? -1 : 0; |
||
97 | } |
||
98 | |||
99 | int get_joystick_B(JOY_STATE *js) |
||
100 | { |
||
101 | int i, j; |
||
102 | int mask = 12; |
||
103 | |||
104 | SYS_FLAGS f; |
||
105 | |||
106 | outp(JPORT, 0); |
||
107 | f = kern_fsave(); |
||
108 | for (i=1; mask && i<CMAX; i++) { |
||
109 | j = inp(JPORT) ^ mask; |
||
110 | if (j & 4) { js->x = i; mask ^= 4; } |
||
111 | if (j & 8) { js->y = i; mask ^= 8; } |
||
112 | } |
||
113 | kern_frestore(f); |
||
114 | j = inp(JPORT); |
||
115 | js->b1 = !(j & 0x40); |
||
116 | js->b2 = !(j & 0x80); |
||
117 | |||
118 | return i==CMAX ? -1 : 0; |
||
119 | } |
||
120 | |||
121 | int get_joystick_bound_A(JOY_BOUND *jb) |
||
122 | { |
||
123 | int i, j; |
||
124 | int mask = 3; |
||
125 | int xmin = CMAX, ymin = CMAX; |
||
126 | int xmax = 0, ymax = 0; |
||
127 | int btn = 0; |
||
128 | |||
129 | SYS_FLAGS f; |
||
130 | |||
131 | while (!btn) { |
||
132 | mask = 3; |
||
133 | outp(JPORT, 0); |
||
134 | f = kern_fsave(); |
||
135 | for (i=1; mask && i<CMAX; i++) { |
||
136 | j = inp(JPORT) ^ mask; |
||
137 | if (j & 1) { |
||
138 | if (i < xmin) xmin = i; |
||
139 | if (i > xmax) xmax = i; |
||
140 | mask ^= 1; |
||
141 | } |
||
142 | if (j & 2) { |
||
143 | if (i < ymin) ymin = i; |
||
144 | if (i > ymax) ymax = i; |
||
145 | mask ^= 2; |
||
146 | } |
||
147 | } |
||
148 | kern_frestore(f); |
||
149 | if (i==CMAX) return -1; |
||
150 | j = inp(JPORT); |
||
151 | btn += !(j & 0x10); |
||
152 | btn += !(j & 0x20); |
||
153 | } |
||
154 | |||
155 | jb->x_min = xmin; |
||
156 | jb->y_min = ymin; |
||
157 | jb->x_max = xmax; |
||
158 | jb->y_max = ymax; |
||
159 | |||
160 | return 0; |
||
161 | } |
||
162 | |||
163 | int get_joystick_bound_B(JOY_BOUND *jb) |
||
164 | { |
||
165 | int i, j; |
||
166 | int mask; |
||
167 | int xmin = CMAX, ymin = CMAX; |
||
168 | int xmax = 0, ymax = 0; |
||
169 | int btn = 0; |
||
170 | |||
171 | SYS_FLAGS f; |
||
172 | |||
173 | while (!btn) { |
||
174 | mask = 12; |
||
175 | outp(JPORT, 0); |
||
176 | f = kern_fsave(); |
||
177 | for (i=1; mask && i<CMAX; i++) { |
||
178 | j = inp(JPORT) ^ mask; |
||
179 | if (j & 4) { |
||
180 | if (i < xmin) xmin = i; |
||
181 | if (i > xmax) xmax = i; |
||
182 | mask ^= 4; |
||
183 | } |
||
184 | if (j & 8) { |
||
185 | if (i < ymin) ymin = i; |
||
186 | if (i > ymax) ymax = i; |
||
187 | mask ^= 8; |
||
188 | } |
||
189 | } |
||
190 | kern_frestore(f); |
||
191 | if (i==CMAX) return -1; |
||
192 | j = inp(JPORT); |
||
193 | btn += !(j & 0x40); |
||
194 | btn += !(j & 0x80); |
||
195 | } |
||
196 | |||
197 | jb->x_min = xmin; |
||
198 | jb->y_min = ymin; |
||
199 | jb->x_max = xmax; |
||
200 | jb->y_max = ymax; |
||
201 | |||
202 | return 0; |
||
203 | } |