/* Poll gameport; return true if all bits set in 'onbits' are on and all bits set in 'offbits' are off.  */
static int poll_until(u8 onbits, u8 offbits, int u_sec, struct gameport *gp, u8 *data)
/* Poll gameport; return true if all bits set in 'onbits' are on and all bits set in 'offbits' are off.  */
static int poll_until(u8 onbits, u8 offbits, int u_sec, struct gameport *gp, u8 *data)
{
	int i, nloops;
	nloops = gameport_time(gp, u_sec);
	for (i = 0; i < nloops; i++) {
		*data = gameport_read(gp);
		if ((*data & onbits) == onbits &&
		    (~(*data) & offbits) == offbits)
			return 1;
	}
	dbg("gameport timed out after %d microseconds.\n", u_sec);
	return 0;
}