/* ______ ___ ___ * /\ _ \ /\_ \ /\_ \ * \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___ * \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\ * \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \ * \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/ * \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/ * /\____/ * \_/__/ * * Joystick driver for the Gravis GamePad Pro. * * By Marius Fodor, using information provided by Benji York. * * See readme.txt for copyright information. */ #include "allegro.h" #include "allegro/internal/aintern.h" #include "allegro/platform/aintdos.h" #ifndef ALLEGRO_DOS #error something is wrong with the makefile #endif /* driver functions */ static int gpro_init(void); static void gpro_exit(void); static int gpro_poll(void); JOYSTICK_DRIVER joystick_gpro = { JOY_TYPE_GAMEPAD_PRO, empty_string, empty_string, "GamePad Pro", gpro_init, gpro_exit, gpro_poll, NULL, NULL, NULL, NULL }; /* int read_gpp: * Reads the GamePad Pro pointed to by pad_num (0 or 1) and returns its * status. Returns 1 if the GPP returned corrupt data, or if no GPP was * detected. * * This code was converted from asm into C by Shawn Hargreaves, who didn't * really understand the original, so any errors are very probable :-) */ static int read_gpp(int pad_num) { int samples[50]; int clock_mask, data_mask, data, old_data; int num_samples, timeout1, timeout2, sample_pos, c; if (pad_num == 0) { clock_mask = 0x10; data_mask = 0x20; } else { clock_mask = 0x40; data_mask = 0x80; } num_samples = 0; timeout1 = 0; DISABLE(); old_data = inportb(0x201); data = 0; while (num_samples<50) { for (timeout2=0; timeout2<255; timeout2++) { data = inportb(0x201); if (data != old_data) break; } if (timeout2 == 255) { ENABLE(); return 1; } if ((old_data & clock_mask) && (!(data & clock_mask))) { samples[num_samples] = (data & data_mask) ? 1 : 0; num_samples++; } old_data = data; if (timeout1++ == 200) break; } ENABLE(); c = 0; for (sample_pos=1; sample_pos