Get rid of the arch dependencies for tome measurement - use microtime().
Works as well as before on my i386 (for want of a real joystick with a 50k resistor between pins 1 and 3).
This commit is contained in:
parent
8e491dbabd
commit
989eec1d34
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: joy.c,v 1.6 2003/06/29 22:30:12 fvdl Exp $ */
|
||||
/* $NetBSD: joy.c,v 1.7 2004/07/08 21:57:31 drochner Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1995 Jean-Marc Zucconi
|
||||
|
@ -32,7 +32,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: joy.c,v 1.6 2003/06/29 22:30:12 fvdl Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: joy.c,v 1.7 2004/07/08 21:57:31 drochner Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
@ -41,16 +41,9 @@ __KERNEL_RCSID(0, "$NetBSD: joy.c,v 1.6 2003/06/29 22:30:12 fvdl Exp $");
|
|||
#include <sys/errno.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/event.h>
|
||||
|
||||
#include <machine/bus.h>
|
||||
|
||||
#include <machine/cpu.h>
|
||||
#include <machine/pio.h>
|
||||
#include <machine/joystick.h>
|
||||
|
||||
#include <dev/isa/isavar.h>
|
||||
#include <dev/isa/isareg.h>
|
||||
|
||||
#include <sys/joystick.h>
|
||||
#include <dev/ic/joyvar.h>
|
||||
|
||||
/*
|
||||
|
@ -63,13 +56,6 @@ __KERNEL_RCSID(0, "$NetBSD: joy.c,v 1.6 2003/06/29 22:30:12 fvdl Exp $");
|
|||
* at port and wait until the corresponding bit returns to 0.
|
||||
*/
|
||||
|
||||
/*
|
||||
* The formulae below only work if u is ``not too large''. See also
|
||||
* the discussion in microtime.s
|
||||
*/
|
||||
#define USEC2TICKS(u) (((u) * 19549) >> 14)
|
||||
#define TICKS2USEC(u) (((u) * 3433) >> 12)
|
||||
|
||||
|
||||
#define JOYPART(d) (minor(d) & 1)
|
||||
#define JOYUNIT(d) minor(d) >> 1 & 3
|
||||
|
@ -101,8 +87,6 @@ joyattach(sc)
|
|||
printf("%s: joystick %sconnected\n", sc->sc_dev.dv_xname,
|
||||
(bus_space_read_1(sc->sc_iot, sc->sc_ioh, 0) & 0x0f) == 0x0f ?
|
||||
"not " : "");
|
||||
|
||||
sc->sc_timer_freq = joy_timer_freq();
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -154,32 +138,34 @@ joyread(dev, uio, flag)
|
|||
bus_space_tag_t iot = sc->sc_iot;
|
||||
bus_space_handle_t ioh = sc->sc_ioh;
|
||||
struct joystick c;
|
||||
int i, t0, t1, s;
|
||||
int i, s;
|
||||
struct timeval start, now, diff;
|
||||
int state = 0, x = 0, y = 0;
|
||||
|
||||
s = splhigh(); /* XXX */
|
||||
bus_space_write_1(iot, ioh, 0, 0xff);
|
||||
t0 = joy_get_tick();
|
||||
t1 = t0;
|
||||
i = USEC2TICKS(sc->timeout[JOYPART(dev)]);
|
||||
while (t0 - t1 < i) {
|
||||
microtime(&start);
|
||||
now = start; /* structure assignment */
|
||||
i = sc->timeout[JOYPART(dev)];
|
||||
for (;;) {
|
||||
timersub(&now, &start, &diff);
|
||||
if (diff.tv_sec > 0 || diff.tv_usec > i)
|
||||
break;
|
||||
state = bus_space_read_1(iot, ioh, 0);
|
||||
if (JOYPART(dev) == 1)
|
||||
state >>= 2;
|
||||
t1 = joy_get_tick();
|
||||
if (t1 > t0)
|
||||
t1 -= sc->sc_timer_freq / hz;
|
||||
if (!x && !(state & 0x01))
|
||||
x = t1;
|
||||
x = diff.tv_usec;
|
||||
if (!y && !(state & 0x02))
|
||||
y = t1;
|
||||
y = diff.tv_usec;
|
||||
if (x && y)
|
||||
break;
|
||||
microtime(&now);
|
||||
}
|
||||
splx(s); /* XXX */
|
||||
|
||||
c.x = x ? sc->x_off[JOYPART(dev)] + TICKS2USEC(t0 - x) : 0x80000000;
|
||||
c.y = y ? sc->y_off[JOYPART(dev)] + TICKS2USEC(t0 - y) : 0x80000000;
|
||||
c.x = x ? sc->x_off[JOYPART(dev)] + x : 0x80000000;
|
||||
c.y = y ? sc->y_off[JOYPART(dev)] + y : 0x80000000;
|
||||
state >>= 4;
|
||||
c.b1 = ~state & 1;
|
||||
c.b2 = ~(state >> 1) & 1;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: joyvar.h,v 1.1 2002/02/02 18:37:44 jdolecek Exp $ */
|
||||
/* $NetBSD: joyvar.h,v 1.2 2004/07/08 21:57:31 drochner Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1995 Jean-Marc Zucconi
|
||||
|
@ -44,13 +44,8 @@ struct joy_softc {
|
|||
bus_space_handle_t sc_ioh;
|
||||
int x_off[2], y_off[2];
|
||||
int timeout[2];
|
||||
int sc_timer_freq;
|
||||
};
|
||||
|
||||
void joyattach __P((struct joy_softc *));
|
||||
int joy_get_tick __P((void));
|
||||
int joy_timer_freq __P((void));
|
||||
|
||||
|
||||
|
||||
#endif /* ! _JOYVAR_H_ */
|
||||
|
|
Loading…
Reference in New Issue