http://www.ctv.es/pckits/tpjoystick.html
#include <tscope.h>
#include <tscope/internal.h>
int main()
{
ts_scrsize(SIZE1);
ts_defkey(KEY_SPACE);
ts_textmode(0);
if (ioperm(GAMEPORT, 1, 1))
ts_fatal("error opening gameport");
ts_printf_centre(0, YMAX - 20, "testgport.c");
ts_printf(-XMAX + 20, -YMAX + 170,
"If a button is ON when pressed, use a G1-G4 definition");
ts_printf(-XMAX + 20, -YMAX + 160,
"If a button is OFF when pressed, use a IG1-IG4 definition");
ts_printf(-XMAX + 20, -YMAX + 120,
"If no box is connected, the values are undefined");
ts_printf(-XMAX + 20, -YMAX + 80, "Read the source of this program");
ts_printf(-XMAX + 20, -YMAX + 70, "for more information about");
ts_printf(-XMAX + 20, -YMAX + 60, "the gameport.");
ts_printf(-XMAX + 20, -YMAX + 20, "Press space to exit.");
int resp, boxbin, boxhex;
do {
resp = ts_respstatus();
boxbin = 0;
boxhex = inb(GAMEPORT);
if ((boxhex & 16) >> 4)
ts_fgcolor(RED);
else
ts_fgcolor(WHITE);
ts_printf_centre(0, 40, "G1 (pin 02 / bit 4)");
if ((boxhex & 32) >> 5)
ts_fgcolor(RED);
else
ts_fgcolor(WHITE);
ts_printf_centre(0, 30, "G2 (pin 07 / bit 5)");
if ((boxhex & 64) >> 6)
ts_fgcolor(RED);
else
ts_fgcolor(WHITE);
ts_printf_centre(0, 20, "G3 (pin 10 / bit 6)");
if ((boxhex & 128) >> 7)
ts_fgcolor(RED);
else
ts_fgcolor(WHITE);
ts_printf_centre(0, 10, "G4 (pin 14 / bit 6)");
} while (resp != 1);
ioperm(GAMEPORT, 1, 0);
return 0;
}
END_OF_MAIN();