/
joystick.c
47 lines (40 loc) · 1.07 KB
/
joystick.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
** JOYSTICK.C
**
** Joystick support functions
**
** Public domain demo by Bob Stout
*/
#include <dos.h>
#include "snpdosys.h"
struct joystick JoyStick;
/*
** read_joystick()
**
** returns Success_ or Error_
**
** fills in global JoyStick structure
*/
Boolean_T read_joystick(void)
{
union REGS regs;
regs.h.ah = 0x84; /* Read the switches */
regs.x.dx = 0;
int86(0x15, ®s, ®s);
if (regs.x.cflag)
return Error_;
JoyStick.switch_0 = TOBOOL(regs.h.al & 0x10);
JoyStick.switch_1 = TOBOOL(regs.h.al & 0x20);
JoyStick.switch_2 = TOBOOL(regs.h.al & 0x40);
JoyStick.switch_3 = TOBOOL(regs.h.al & 0x80);
regs.h.ah = 0x84; /* Read positions */
regs.x.dx = 1;
int86(0x15, ®s, ®s);
if (regs.x.cflag)
return Error_;
JoyStick.pos_Ax = regs.x.ax;
JoyStick.pos_Ay = regs.x.bx;
JoyStick.pos_Bx = regs.x.cx;
JoyStick.pos_By = regs.x.dx;
return Success_;
}