xref: /openbsd/sys/arch/i386/isa/joyreg.h (revision f19f38fc)
1 /*	$OpenBSD: joyreg.h,v 1.5 2007/11/29 10:53:54 deraadt Exp $	*/
2 /*	$NetBSD: joy.c,v 1.3 1996/05/05 19:46:15 christos Exp $	*/
3 
4 /*-
5  * Copyright (c) 1995 Jean-Marc Zucconi
6  * All rights reserved.
7  *
8  * Ported to NetBSD by Matthieu Herrb <matthieu@laas.fr>
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer
15  *    in this position and unchanged.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. The name of the author may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  */
34 
35 /*
36  * The game port can manage 4 buttons and 4 variable resistors (usually 2
37  * joysticks, each with 2 buttons and 2 pots.) via the port at address 0x201.
38  * Getting the state of the buttons is done by reading the game port;
39  * buttons 1-4 correspond to bits 4-7 and resistors 1-4 (X1, Y1, X2, Y2)
40  * to bits 0-3.  If button 1 (resp 2, 3, 4) is pressed, the bit 4 (resp 5,
41  * 6, 7) is set to 0 to get the value of a resistor, write the value 0xff
42  * at port and wait until the corresponding bit returns to 0.
43  */
44 
45 /*
46  * The formulae below only work if u is ``not too large''.
47  */
48 #define USEC2TICKS(u) 	(((u) * 19549) >> 14)
49 #define TICKS2USEC(u) 	(((u) * 3433) >> 12)
50 
51 
52 #define JOYPART(d) (minor(d) & 1)
53 #define JOYUNIT(d) minor(d) >> 1 & 3
54 
55 #ifndef JOY_TIMEOUT
56 #define JOY_TIMEOUT   2000	/* 2 milliseconds */
57 #endif
58 
59 #define JOY_NPORTS    1
60 
61 struct joy_softc {
62 	struct	device sc_dev;
63 	int	port;
64 	int	x_off[2], y_off[2];
65 	int	timeout[2];
66 };
67 
68 int		joyopen(dev_t, int, int, struct proc *);
69 int		joyclose(dev_t, int, int, struct proc *);
70