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.
This commit is contained in:
Jean-Marc Zucconi 1995-01-28 21:54:37 +00:00
parent 35bff0b976
commit 7c5329fd30
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=5993
3 changed files with 24 additions and 33 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;