home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C++ Games Programming
/
CPPGAMES.ISO
/
thx
/
source
/
theatrix
/
jssrvr.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1995-05-03
|
2KB
|
108 lines
#include <iostream.h>
#include <fastgraf.h>
#include <dos.h>
#include <stdlib.h>
#include "standard.h"
#include "jsfold.h"
#include "jssrvr.h"
JoystickServer::JoystickServer()
{
dz = 0;
xadj = yadj = 0;
cx = cy = 0;
lx = ty = 0;
rx = by = 0;
joystick_supported = 0;
}
int JoystickServer::setting(int *x, int *y)
{
_AH = 0x84;
_DX = 1;
geninterrupt(0x15);
int ax = _AX;
int bx = _BX;
*x = ax;
*y = bx;
_AH = 0x84;
_DX = 0;
geninterrupt(0x15);
int sw = _AL;
return (sw & 0x30) ^ 0x30;
}
void JoystickServer::calibrate(char *pos, int *x, int *y)
{
int sw;
// --- wait for no buttons down
do
sw = setting(x, y);
while (sw);
// --- wait for button down
cout << "\nMove joystick to "
<< pos
<< " and press a button\n";
do
sw = setting(x, y);
while (sw == 0);
cout << pos << ": " << *x << '/' << *y << '\n';
}
void JoystickServer::startup()
{
if (!joystick_supported)
return;
int x, y;
setting(&x, &y);
if (x == 0 || y == 0)
{
cout << "\nJoystick not sensed";
joystick_supported = 0;
return;
}
// ---- get the dead zone factor
int i = 200;
int mnx = 10000, mxx = 0;
int mny = 10000, mxy = 0;
while (--i) {
setting(&x, &y);
x = abs(x);
y = abs(y);
mxx = max(mxx, x);
mnx = min(mnx, x);
mxy = max(mxy, y);
mny = min(mny, y);
}
xadj = (mxx - mnx + 1);
yadj = (mxy - mny + 1);
cx = mnx + xadj;
cy = mny + yadj;
calibrate("upper left", &lx, &ty);
calibrate("lower right", &rx, &by);
}
void JoystickServer::check(Folder& fld)
{
if (!joystick_supported)
return;
int x,y;
int sw = setting(&x, &y);
// --- normalize the coordinates
x = x - cx;
y = cy - y;
if (x >= -xadj && x <= xadj)
x = 0;
if (y >= -yadj && y <= yadj)
y = 0;
if ((sw & 0x30) || x || y)
fld.dispatch(x, y, sw);
}