/* l4_calibrate() calibrates the L4 for the attached device, so that the device's resistance fits into the L4's 8-bit range.  */
static int l4_calibrate(struct gameport *gameport, int *axes, int *max)
/* l4_calibrate() calibrates the L4 for the attached device, so that the device's resistance fits into the L4's 8-bit range.  */
static int l4_calibrate(struct gameport *gameport, int *axes, int *max)
{
	int i, t;
	int cal[4];
	struct l4 *l4 = gameport->port_data;
	if (l4_getcal(l4->port, cal))
		return -1;
	for (i = 0; i < 4; i++) {
		t = (max[i] * cal[i]) / 200;
		t = (t < 1) ? 1 : ((t > 255) ? 255 : t);
		axes[i] = (axes[i] < 0) ? -1 : (axes[i] * cal[i]) / t;
		axes[i] = (axes[i] > 252) ? 252 : axes[i];
		cal[i] = t;
	}
	if (l4_setcal(l4->port, cal))
		return -1;
	return 0;
}