From 7c5329fd30734520374f743044a31d656dd747d0 Mon Sep 17 00:00:00 2001 From: Jean-Marc Zucconi Date: Sat, 28 Jan 1995 21:54:37 +0000 Subject: [PATCH] Do not recompute TIMER0's maximum count, since it is in timer0_max_count. Use a simpler formula to convert usecs to ticks. Output is in microseconds instead of ticks, so that values do not depend on the timer frequency. --- sys/dev/joy/joy.c | 19 ++++++++----------- sys/i386/isa/joy.c | 19 ++++++++----------- sys/isa/joy.c | 19 ++++++++----------- 3 files changed, 24 insertions(+), 33 deletions(-) diff --git a/sys/dev/joy/joy.c b/sys/dev/joy/joy.c index df3f780bd5fe..83ff11a1a86d 100644 --- a/sys/dev/joy/joy.c +++ b/sys/dev/joy/joy.c @@ -49,14 +49,11 @@ * wait until the corresponding bit returns to 0. */ -/* #defines below taken from clock.c */ -#ifndef TIMER_FREQ -#define TIMER_FREQ 1193182 -#endif -#define usec2ticks(u) (u) * (TIMER_FREQ / 1000000) \ - + (u) * ((TIMER_FREQ % 1000000) / 1000) / 1000 \ - + (u) * (TIMER_FREQ % 1000) / 1000000 +/* 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 @@ -72,7 +69,7 @@ static struct { } joy[NJOY]; -extern int hz; +extern int timer0_max_count; int joyprobe (struct isa_device *), joyattach (struct isa_device *); @@ -145,7 +142,7 @@ joyread (dev_t dev, struct uio *uio, int flag) state >>= 2; t1 = get_tick (); if (t1 > t0) - t1 -= TIMER_FREQ/hz; + t1 -= timer0_max_count; if (!x && !(state & 0x01)) x = t1; if (!y && !(state & 0x02)) @@ -154,8 +151,8 @@ joyread (dev_t dev, struct uio *uio, int flag) break; } enable_intr (); - c[0] = x ? joy[unit].x_off[joypart(dev)] + (t0-x) : 0x80000000; - c[1] = y ? joy[unit].y_off[joypart(dev)] + (t0-y) : 0x80000000; + c[0] = x ? joy[unit].x_off[joypart(dev)] + ticks2usec(t0-x) : 0x80000000; + c[1] = y ? joy[unit].y_off[joypart(dev)] + ticks2usec(t0-y) : 0x80000000; state >>= 4; c[2] = ~state & 1; c[3] = ~(state >> 1) & 1; diff --git a/sys/i386/isa/joy.c b/sys/i386/isa/joy.c index df3f780bd5fe..83ff11a1a86d 100644 --- a/sys/i386/isa/joy.c +++ b/sys/i386/isa/joy.c @@ -49,14 +49,11 @@ * wait until the corresponding bit returns to 0. */ -/* #defines below taken from clock.c */ -#ifndef TIMER_FREQ -#define TIMER_FREQ 1193182 -#endif -#define usec2ticks(u) (u) * (TIMER_FREQ / 1000000) \ - + (u) * ((TIMER_FREQ % 1000000) / 1000) / 1000 \ - + (u) * (TIMER_FREQ % 1000) / 1000000 +/* 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 @@ -72,7 +69,7 @@ static struct { } joy[NJOY]; -extern int hz; +extern int timer0_max_count; int joyprobe (struct isa_device *), joyattach (struct isa_device *); @@ -145,7 +142,7 @@ joyread (dev_t dev, struct uio *uio, int flag) state >>= 2; t1 = get_tick (); if (t1 > t0) - t1 -= TIMER_FREQ/hz; + t1 -= timer0_max_count; if (!x && !(state & 0x01)) x = t1; if (!y && !(state & 0x02)) @@ -154,8 +151,8 @@ joyread (dev_t dev, struct uio *uio, int flag) break; } enable_intr (); - c[0] = x ? joy[unit].x_off[joypart(dev)] + (t0-x) : 0x80000000; - c[1] = y ? joy[unit].y_off[joypart(dev)] + (t0-y) : 0x80000000; + c[0] = x ? joy[unit].x_off[joypart(dev)] + ticks2usec(t0-x) : 0x80000000; + c[1] = y ? joy[unit].y_off[joypart(dev)] + ticks2usec(t0-y) : 0x80000000; state >>= 4; c[2] = ~state & 1; c[3] = ~(state >> 1) & 1; diff --git a/sys/isa/joy.c b/sys/isa/joy.c index df3f780bd5fe..83ff11a1a86d 100644 --- a/sys/isa/joy.c +++ b/sys/isa/joy.c @@ -49,14 +49,11 @@ * wait until the corresponding bit returns to 0. */ -/* #defines below taken from clock.c */ -#ifndef TIMER_FREQ -#define TIMER_FREQ 1193182 -#endif -#define usec2ticks(u) (u) * (TIMER_FREQ / 1000000) \ - + (u) * ((TIMER_FREQ % 1000000) / 1000) / 1000 \ - + (u) * (TIMER_FREQ % 1000) / 1000000 +/* 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 @@ -72,7 +69,7 @@ static struct { } joy[NJOY]; -extern int hz; +extern int timer0_max_count; int joyprobe (struct isa_device *), joyattach (struct isa_device *); @@ -145,7 +142,7 @@ joyread (dev_t dev, struct uio *uio, int flag) state >>= 2; t1 = get_tick (); if (t1 > t0) - t1 -= TIMER_FREQ/hz; + t1 -= timer0_max_count; if (!x && !(state & 0x01)) x = t1; if (!y && !(state & 0x02)) @@ -154,8 +151,8 @@ joyread (dev_t dev, struct uio *uio, int flag) break; } enable_intr (); - c[0] = x ? joy[unit].x_off[joypart(dev)] + (t0-x) : 0x80000000; - c[1] = y ? joy[unit].y_off[joypart(dev)] + (t0-y) : 0x80000000; + c[0] = x ? joy[unit].x_off[joypart(dev)] + ticks2usec(t0-x) : 0x80000000; + c[1] = y ? joy[unit].y_off[joypart(dev)] + ticks2usec(t0-y) : 0x80000000; state >>= 4; c[2] = ~state & 1; c[3] = ~(state >> 1) & 1;