joy.c (5897) | joy.c (5993) |
---|---|
1/*- 2 * Copyright (c) 1995 Jean-Marc Zucconi 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 35 unchanged lines hidden (view full) --- 44 * Getting the state of the buttons is done by reading the game port: 45 * buttons 1-4 correspond to bits 4-7 and resistors 1-4 (X1, Y1, X2, Y2) 46 * to bits 0-3. 47 * if button 1 (resp 2, 3, 4) is pressed, the bit 4 (resp 5, 6, 7) is set to 0 48 * to get the value of a resistor, write the value 0xff at port and 49 * wait until the corresponding bit returns to 0. 50 */ 51 | 1/*- 2 * Copyright (c) 1995 Jean-Marc Zucconi 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 35 unchanged lines hidden (view full) --- 44 * Getting the state of the buttons is done by reading the game port: 45 * buttons 1-4 correspond to bits 4-7 and resistors 1-4 (X1, Y1, X2, Y2) 46 * to bits 0-3. 47 * if button 1 (resp 2, 3, 4) is pressed, the bit 4 (resp 5, 6, 7) is set to 0 48 * to get the value of a resistor, write the value 0xff at port and 49 * wait until the corresponding bit returns to 0. 50 */ 51 |
52/* #defines below taken from clock.c */ 53#ifndef TIMER_FREQ 54#define TIMER_FREQ 1193182 55#endif 56#define usec2ticks(u) (u) * (TIMER_FREQ / 1000000) \ 57 + (u) * ((TIMER_FREQ % 1000000) / 1000) / 1000 \ 58 + (u) * (TIMER_FREQ % 1000) / 1000000 | |
59 | 52 |
53/* the formulae below only work if u is ``not too large''. See also 54 * the discussion in microtime.s */ 55#define usec2ticks(u) ((u) * 19549)>>14 56#define ticks2usec(u) ((u) * 3433)>>12 |
|
60 61 62#define joypart(d) minor(d)&1 63#define UNIT(d) minor(d)>>1&3 64#ifndef JOY_TIMEOUT 65#define JOY_TIMEOUT 2000 /* 2 milliseconds */ 66#endif 67 68static struct { 69 int port; 70 int x_off[2], y_off[2]; 71 int timeout[2]; 72} joy[NJOY]; 73 74 | 57 58 59#define joypart(d) minor(d)&1 60#define UNIT(d) minor(d)>>1&3 61#ifndef JOY_TIMEOUT 62#define JOY_TIMEOUT 2000 /* 2 milliseconds */ 63#endif 64 65static struct { 66 int port; 67 int x_off[2], y_off[2]; 68 int timeout[2]; 69} joy[NJOY]; 70 71 |
75extern int hz; | 72extern int timer0_max_count; |
76 77int joyprobe (struct isa_device *), joyattach (struct isa_device *); 78 79struct isa_driver joydriver = {joyprobe, joyattach, "joy"}; 80 81static int get_tick (); 82 83 --- 56 unchanged lines hidden (view full) --- 140 t1 = t0; 141 i = usec2ticks(joy[unit].timeout[joypart(dev)]); 142 while (t0-t1 < i) { 143 state = inb (port); 144 if (joypart(dev) == 1) 145 state >>= 2; 146 t1 = get_tick (); 147 if (t1 > t0) | 73 74int joyprobe (struct isa_device *), joyattach (struct isa_device *); 75 76struct isa_driver joydriver = {joyprobe, joyattach, "joy"}; 77 78static int get_tick (); 79 80 --- 56 unchanged lines hidden (view full) --- 137 t1 = t0; 138 i = usec2ticks(joy[unit].timeout[joypart(dev)]); 139 while (t0-t1 < i) { 140 state = inb (port); 141 if (joypart(dev) == 1) 142 state >>= 2; 143 t1 = get_tick (); 144 if (t1 > t0) |
148 t1 -= TIMER_FREQ/hz; | 145 t1 -= timer0_max_count; |
149 if (!x && !(state & 0x01)) 150 x = t1; 151 if (!y && !(state & 0x02)) 152 y = t1; 153 if (x && y) 154 break; 155 } 156 enable_intr (); | 146 if (!x && !(state & 0x01)) 147 x = t1; 148 if (!y && !(state & 0x02)) 149 y = t1; 150 if (x && y) 151 break; 152 } 153 enable_intr (); |
157 c[0] = x ? joy[unit].x_off[joypart(dev)] + (t0-x) : 0x80000000; 158 c[1] = y ? joy[unit].y_off[joypart(dev)] + (t0-y) : 0x80000000; | 154 c[0] = x ? joy[unit].x_off[joypart(dev)] + ticks2usec(t0-x) : 0x80000000; 155 c[1] = y ? joy[unit].y_off[joypart(dev)] + ticks2usec(t0-y) : 0x80000000; |
159 state >>= 4; 160 c[2] = ~state & 1; 161 c[3] = ~(state >> 1) & 1; 162 return uiomove (c, 4*sizeof(int), uio); 163} 164int joyioctl (dev_t dev, int cmd, caddr_t data, int flag, struct proc *p) 165{ 166 int unit = UNIT (dev); --- 43 unchanged lines hidden --- | 156 state >>= 4; 157 c[2] = ~state & 1; 158 c[3] = ~(state >> 1) & 1; 159 return uiomove (c, 4*sizeof(int), uio); 160} 161int joyioctl (dev_t dev, int cmd, caddr_t data, int flag, struct proc *p) 162{ 163 int unit = UNIT (dev); --- 43 unchanged lines hidden --- |