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