0,0 → 1,203 |
|
/* |
* Project: S.Ha.R.K. |
* |
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it> |
* |
* Authors : Mauro Marinoni <mauro.marinoni@unipv.it> |
* (see authors.txt for full list of hartik's authors) |
* |
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
* |
* http://www.sssup.it |
* http://retis.sssup.it |
* http://shark.sssup.it |
*/ |
|
/* |
* Copyright (C) 2000 Paolo Gai |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
* (at your option) any later version. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* |
*/ |
|
#include "kernel/kern.h" |
#include "joy.h" |
|
void get_joystick_buttons(JOY_BUTTONS *jb) |
{ |
int j; |
|
outp(JPORT, 0); |
j = inp(JPORT); |
jb->b1 = !(j & 0x10); |
jb->b2 = !(j & 0x20); |
jb->b3 = !(j & 0x40); |
jb->b4 = !(j & 0x80); |
} |
|
int get_joystick_AB(JOY_STATE *jsa, JOY_STATE *jsb) |
{ |
int i, j; |
int mask = 15; |
|
SYS_FLAGS f; |
|
outp(JPORT, 0); |
f = kern_fsave(); |
for (i=1; mask && i<CMAX; i++) { |
j = inp(JPORT) ^ mask; |
if (j & 1) { jsa->x = i; mask ^= 1; } |
if (j & 2) { jsa->y = i; mask ^= 2; } |
if (j & 4) { jsb->x = i; mask ^= 4; } |
if (j & 8) { jsb->y = i; mask ^= 8; } |
} |
kern_frestore(f); |
j = inp(JPORT); |
jsa->b1 = !(j & 0x10); |
jsa->b2 = !(j & 0x20); |
jsb->b1 = !(j & 0x40); |
jsb->b2 = !(j & 0x80); |
|
return i==CMAX ? -1 : 0; |
} |
|
int get_joystick_A(JOY_STATE *js) |
{ |
int i, j; |
int mask = 3; |
|
SYS_FLAGS f; |
|
outp(JPORT, 0); |
f = kern_fsave(); |
for (i=1; mask && i<CMAX; i++) { |
j = inp(JPORT) ^ mask; |
if (j & 1) { js->x = i; mask ^= 1; } |
if (j & 2) { js->y = i; mask ^= 2; } |
} |
kern_frestore(f); |
j = inp(JPORT); |
js->b1 = !(j & 0x10); |
js->b2 = !(j & 0x20); |
|
return i==CMAX ? -1 : 0; |
} |
|
int get_joystick_B(JOY_STATE *js) |
{ |
int i, j; |
int mask = 12; |
|
SYS_FLAGS f; |
|
outp(JPORT, 0); |
f = kern_fsave(); |
for (i=1; mask && i<CMAX; i++) { |
j = inp(JPORT) ^ mask; |
if (j & 4) { js->x = i; mask ^= 4; } |
if (j & 8) { js->y = i; mask ^= 8; } |
} |
kern_frestore(f); |
j = inp(JPORT); |
js->b1 = !(j & 0x40); |
js->b2 = !(j & 0x80); |
|
return i==CMAX ? -1 : 0; |
} |
|
int get_joystick_bound_A(JOY_BOUND *jb) |
{ |
int i, j; |
int mask = 3; |
int xmin = CMAX, ymin = CMAX; |
int xmax = 0, ymax = 0; |
int btn = 0; |
|
SYS_FLAGS f; |
|
while (!btn) { |
mask = 3; |
outp(JPORT, 0); |
f = kern_fsave(); |
for (i=1; mask && i<CMAX; i++) { |
j = inp(JPORT) ^ mask; |
if (j & 1) { |
if (i < xmin) xmin = i; |
if (i > xmax) xmax = i; |
mask ^= 1; |
} |
if (j & 2) { |
if (i < ymin) ymin = i; |
if (i > ymax) ymax = i; |
mask ^= 2; |
} |
} |
kern_frestore(f); |
if (i==CMAX) return -1; |
j = inp(JPORT); |
btn += !(j & 0x10); |
btn += !(j & 0x20); |
} |
|
jb->x_min = xmin; |
jb->y_min = ymin; |
jb->x_max = xmax; |
jb->y_max = ymax; |
|
return 0; |
} |
|
int get_joystick_bound_B(JOY_BOUND *jb) |
{ |
int i, j; |
int mask; |
int xmin = CMAX, ymin = CMAX; |
int xmax = 0, ymax = 0; |
int btn = 0; |
|
SYS_FLAGS f; |
|
while (!btn) { |
mask = 12; |
outp(JPORT, 0); |
f = kern_fsave(); |
for (i=1; mask && i<CMAX; i++) { |
j = inp(JPORT) ^ mask; |
if (j & 4) { |
if (i < xmin) xmin = i; |
if (i > xmax) xmax = i; |
mask ^= 4; |
} |
if (j & 8) { |
if (i < ymin) ymin = i; |
if (i > ymax) ymax = i; |
mask ^= 8; |
} |
} |
kern_frestore(f); |
if (i==CMAX) return -1; |
j = inp(JPORT); |
btn += !(j & 0x40); |
btn += !(j & 0x80); |
} |
|
jb->x_min = xmin; |
jb->y_min = ymin; |
jb->x_max = xmax; |
jb->y_max = ymax; |
|
return 0; |
} |