Category : Files from Magazines
Archive   : CGAZV5N1.ZIP
Filename : JOY.C

 
Output of file : JOY.C contained in archive : CGAZV5N1.ZIP
/************ Listing 1 ******** JOY.C ***********
* High-level joystick routines
* Author Victor Volkman
* (c) 1990 C Gazette. May be used freely if
* authorship and publication are acknowledged.
***************************************************/

#include
#include
#include
#include
#include

#ifndef MAKEFD
#include "joy.fd"
#endif

#include "timer.h" /* 8254 Programmable Interval Timer */
#include "game.h" /* Game adapter */

extern int gettimer(void); /* From JOYTIME.ASM */
extern int waitjoy(int mask);


void get_joy(joy_p,mask)
short *joy_p;
int mask;
{
unsigned int t1, t2;
int time_left;
*joy_p = 0;

intsoff();
t1 = gettimer();
time_left = waitjoy(mask);
t2 = gettimer();
intson();

if (time_left)
*joy_p = (t1 - t2) >> 4;
}


int joy_stick_present()
{
union REGS r;
int86(0x11, &r, &r);
printf("ax = %04x\n",r.x.ax & 0x1000);
return r.x.ax & 0x1000 ? 1 : 0;
}


int _bios_joystick( joya_x, joya_y, joyb_x, joyb_y, fire)
short *joya_x;
short *joya_y;
short *joyb_x;
short *joyb_y;
short *fire;
{
union REGS r;
short error; /* TRUE if no game adapter is installed */

r.h.ah = READ_JOYSTICK;
r.x.dx = BIOS_JOY_SWITCH;
int86(BIOS_IO_EXT, &r, &r);
*fire = r.h.al;

r.h.ah = READ_JOYSTICK;
r.x.dx = BIOS_JOY_POT;
int86(BIOS_IO_EXT, &r, &r);
*joya_x = r.x.ax; /* Joystick "A" */
*joya_y = r.x.bx;
*joyb_x = r.x.cx; /* Joystick "B" */
*joyb_y = r.x.dx;

error = r.x.cflag; /* CY set for error */
return error;
}

int c_joystick(joya_x, joya_y, joyb_x, joyb_y, fire)
short *joya_x;
short *joya_y;
short *joyb_x;
short *joyb_y;
short *fire;
{
short error; /* TRUE if no game adapter is installed */

get_joy(joya_x,GAME_A_POT_X);
get_joy(joya_y,GAME_A_POT_Y);
get_joy(joyb_x,GAME_B_POT_X);
get_joy(joyb_y,GAME_B_POT_Y);
*fire = inp(JOY_PORT) & 0xF0;
error = (*joya_x == 0 && *joya_y == 0 &&
*joyb_x == 0 && *joyb_y == 0);
return error;
}

  3 Responses to “Category : Files from Magazines
Archive   : CGAZV5N1.ZIP
Filename : JOY.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/