/* JOYPOTS.C -- Samples joystick pots and retreives their values.
* by Gary Neal, Jr. -- garyneal@geocities.com
*/
#include /* Console specific I/O */
int main(void)
{
unsigned int joyState; /* Bit status of Port 201h */
unsigned short joyPotVal[4], limit; /* Loop counters & counting limit */
clrscr(); /* Clear the screen */
gotoxy(10, 9); /* Set screen position */
cputs("Joystick potentiometer values:");
/* Initialize loop counters */
joyPotVal[0] = joyPotVal[1] = joyPotVal[2] = joyPotVal[3] = limit = 0;
outp(0x201, 0); /* Discharge capacitors */
do {
joyState = inp(0x201); /* Get capacitor status bits */
/* Increase pot value count until cap fully charges */
joyPotVal[0] += ((joyState & 0x01) != 0);
joyPotVal[1] += ((joyState & 0x02) != 0);
joyPotVal[2] += ((joyState & 0x04) != 0);
joyPotVal[3] += ((joyState & 0x08) != 0);
/* Increase loop limit count */
limit += 1;
/* Continue until all caps are fully charged or limit is reached */
} while ((joyState & 0x0F) && limit);
/* Write joystick pot values on screen */
gotoxy(15, 11);
cprintf("Joystick A's X-axis = %u", joyPotVal[0]);
gotoxy(15, 12);
cprintf("Joystick A's Y-axis = %u", joyPotVal[1]);
gotoxy(15, 13);
cprintf("Joystick B's X-axis = %u", joyPotVal[2]);
gotoxy(15, 14);
cprintf("Joystick B's Y-axis = %u", joyPotVal[3]);
return 0;
}
               (
geocities.com/siliconvalley/park/7113/GameLib)                   (
geocities.com/siliconvalley/park/7113)                   (
geocities.com/siliconvalley/park)                   (
geocities.com/siliconvalley)