From 7e0f021a9aec35fd8e6725e87e3313b101d26f5e Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 27 Jan 2008 11:37:44 +0100 Subject: Initial import (2.0.2-6) --- reference/C/CONTRIB/SNIP/joystick.c | 74 +++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100755 reference/C/CONTRIB/SNIP/joystick.c (limited to 'reference/C/CONTRIB/SNIP/joystick.c') diff --git a/reference/C/CONTRIB/SNIP/joystick.c b/reference/C/CONTRIB/SNIP/joystick.c new file mode 100755 index 0000000..4eca117 --- /dev/null +++ b/reference/C/CONTRIB/SNIP/joystick.c @@ -0,0 +1,74 @@ +/* +** JOYSTICK.H +** +** Joystick support functions +** +** Public domain demo by Bob Stout +*/ + +typedef enum {ERROR = -1, FALSE, TRUE} LOGICAL; + +#define BOOL(x) (!(!(x))) +#define SUCCESS 0 + +struct joystick { + LOGICAL switch_0; + LOGICAL switch_1; + LOGICAL switch_2; + LOGICAL switch_3; + + int pos_Ax; + int pos_Ay; + int pos_Bx; + int pos_By; +}; + +LOGICAL read_joystick(void); + +/* +** JOYSTICK.C +** +** Joystick support functions +** +** Public domain demo by Bob Stout +*/ + +#include +#include "joystick.h" + +struct joystick JoyStick; + +/* +** read_joystick() +** +** returns SUCCESS or ERROR +** +** fills in global JoyStick structure +*/ + +LOGICAL 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 = BOOL(regs.h.al & 0x10); + JoyStick.switch_1 = BOOL(regs.h.al & 0x20); + JoyStick.switch_2 = BOOL(regs.h.al & 0x40); + JoyStick.switch_3 = BOOL(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; +} -- cgit v1.2.3-54-g00ecf