From owner-newconfig-jp@jp.freebsd.org  Mon Jan 11 03:22:38 1999
Received: (from daemon@localhost)
	by jaz.jp.freebsd.org (8.9.1+3.1W/8.7.3) id DAA23703;
	Mon, 11 Jan 1999 03:22:38 +0900 (JST)
	(envelope-from owner-newconfig-jp@jp.FreeBSD.org)
Received: from localhost.rr.iij4u.or.jp (h142.p048.iij4u.or.jp [210.130.48.142])
	by jaz.jp.freebsd.org (8.9.1+3.1W/8.7.3) with ESMTP id DAA23695
	for <newconfig-jp@jp.FreeBSD.ORG>; Mon, 11 Jan 1999 03:22:35 +0900 (JST)
	(envelope-from bishop@rr.iij4u.or.jp)
Received: from localhost (localhost [127.0.0.1])
	by localhost.rr.iij4u.or.jp (8.9.1/8.9.1) with ESMTP id DAA00344
	for <newconfig-jp@jp.FreeBSD.ORG>; Mon, 11 Jan 1999 03:27:32 +0900 (JST)
	(envelope-from bishop@rr.iij4u.or.jp)
To: newconfig-jp@jp.FreeBSD.ORG
From: MAEKAWA Masahide <bishop@rr.iij4u.or.jp>
X-Mailer: Mew version 1.93 on Emacs 19.34 / Mule 2.3 (SUETSUMUHANA)
Mime-Version: 1.0
Content-Type: Text/Plain; charset=iso-2022-jp
Content-Transfer-Encoding: 7bit
Message-Id: <19990111032732Z.bishop@rr.iij4u.or.jp>
Date: Mon, 11 Jan 1999 03:27:32 +0900
X-Dispatcher: imput version 980905(IM100)
Lines: 245
Reply-To: newconfig-jp@jp.freebsd.org
Precedence: list
X-Distribute: distribute version 2.1 (Alpha) patchlevel 24e+981115
X-Sequence: newconfig-jp 872
Subject: [newconfig-jp 872] joy.c
Errors-To: owner-newconfig-jp@jp.freebsd.org
Sender: owner-newconfig-jp@jp.freebsd.org
X-Originator: bishop@rr.iij4u.or.jp

$BA0@n!w?@8MBg3X$G$9(B.

joy.c $B$r=q$-49$($^$7$?(B. ($B$3$s$J$3$H$7$F$k2K$O$J$$$N$G$"$j$s$9$,(B.)
$B%+!<%M%k$N5/F0$O3NG'$O$7$^$7$?$,(B, joystick $B$J$s$F;}$C$F$J$$$N$G(B,
$BF0$/$+$I$&$+$O$o$+$j$^$;$s(B. LKM (KLD?) $B$O$$$B$C$F$*$j$^$;$s(B.
# $B9b66$5$s$N(B sys.diff $B$K$O$J$s$N1F6A$b$J$$$G$9(B.

--- $B?@8MBg3XM}3XIt?t3X2J(B  $B$^$($+$o$^$5$R$G(B   9643024s@kobe-u.ac.jp
                                             gehenna@jp.FreeBSD.org ---

Index: sys/i386/isa/joy.c
===================================================================
RCS file: /home/cvs/newconfig/sys/i386/isa/joy.c,v
retrieving revision 1.3
diff -u -r1.3 joy.c
--- joy.c	1999/01/06 16:10:04	1.3
+++ joy.c	1999/01/10 17:54:28
@@ -51,6 +51,10 @@
 #include <i386/isa/isa_device.h>
 #include <i386/isa/timerreg.h>
 
+#ifdef NEW_CONFIG
+#include "ioconf.h"
+#endif
+
 /* The game port can manage 4 buttons and 4 variable resistors (usually 2
  * joysticks, each with 2 buttons and 2 pots.) via the port at address 0x201.
  * Getting the state of the buttons is done by reading the game port:
@@ -74,6 +78,7 @@
 #define JOY_TIMEOUT   2000 /* 2 milliseconds */
 #endif
 
+#ifndef NEW_CONFIG
 static struct {
     int port;
     int x_off[2], y_off[2];
@@ -82,20 +87,32 @@
     void	*devfs_token;
 #endif
 } joy[NJOY];
+#endif
 
 
+#ifdef NEW_CONFIG
+static int joy_match	__P((struct device *, struct cfdata *, void *));
+static void joy_attach	__P((struct device *, struct device *, void *));
+#else
 static int joyprobe (struct isa_device *);
 static int joyattach (struct isa_device *);
 
 struct isa_driver joydriver = {joyprobe, joyattach, "joy"};
+#endif
 
 #ifdef NEW_CONFIG
 struct joy_softc {
         struct  device joy_dev;
+	int	port;
+	int	x_off[2], y_off[2];
+	int	timeout[2];
+#ifdef DEVFS
+	void	*devfs_token;
+#endif
 };
 
 struct cfattach joy_ca = {
-        sizeof(struct joy_softc), 0, &joydriver, isa_dev_match, NULL,NULL,NULL,
+        sizeof(struct joy_softc), 1, NULL, joy_match, joy_attach,NULL,NULL,
 };
 #endif
 
@@ -113,6 +130,32 @@
 static int get_tick __P((void));
 
 
+#ifdef NEW_CONFIG
+static int
+joy_match(struct device *parent, struct cfdata *match, void *aux)
+{
+	struct isa_attach_args *ia = (struct isa_attach_args *) aux;
+	outb(ia->ia_iobase, 0xff);
+	DELAY (10000); /*  10 ms delay */
+	return ((inb(ia->ia_iobase) & 0x0f) != 0x0f);
+}
+
+static void
+joy_attach(struct device *parent, struct device *self, void *aux)
+{
+	struct joy_softc *joy_sc = (struct joy_softc *) self;
+	struct isa_attach_args *ia = (struct isa_attach_args *) aux;
+
+	joy_sc->port = ia->ia_iobase;
+	joy_sc->timeout[0] = joy_sc->timeout[1] = 0;
+	printf(": joystick\n");
+#ifdef DEVFS
+	joy_sc->devfs_token =
+		devfs_add_devswf(&joy_cdevsw, 0, DV_CHR, 0, 0,
+		                 0600, "joy%d", unit);
+#endif
+}
+#else /* NEW_CONFIG */
 static int
 joyprobe (struct isa_device *dev)
 {
@@ -140,6 +183,7 @@
 #endif
     return 1;
 }
+#endif /* NEW_CONFIG */
 
 static	int
 joyopen (dev_t dev, int flags, int fmt, struct proc *p)
@@ -147,11 +191,25 @@
     int unit = UNIT (dev);
     int i = joypart (dev);
 
+#ifdef NEW_CONFIG
+    struct joy_softc *joy_sc;
+
+    if ((unit >= joy_cd.cd_ndevs) || (joy_cd.cd_devs[unit] == NULL))
+	return (ENXIO);
+    joy_sc = (struct joy_softc *) joy_cd.cd_devs[unit];
+
+    if (joy_sc->timeout[i])
+	return (EBUSY);
+    joy_sc->x_off[i] = joy_sc->y_off[i] = 0;
+    joy_sc->timeout[i] = JOY_TIMEOUT;
+    return (0);
+#else /* NEW_CONFIG */
     if (joy[unit].timeout[i])
 	return EBUSY;
     joy[unit].x_off[i] = joy[unit].y_off[i] = 0;
     joy[unit].timeout[i] = JOY_TIMEOUT;
     return 0;
+#endif /* NEW_CONFIG */
 }
 static	int
 joyclose (dev_t dev, int flags, int fmt, struct proc *p)
@@ -159,7 +217,12 @@
     int unit = UNIT (dev);
     int i = joypart (dev);
 
+#ifdef NEW_CONFIG
+    struct joy_softc *joy_sc = (struct joy_softc *) joy_cd.cd_devs[unit];
+    joy_sc->timeout[i] = 0;
+#else
     joy[unit].timeout[i] = 0;
+#endif
     return 0;
 }
 
@@ -167,7 +230,12 @@
 joyread (dev_t dev, struct uio *uio, int flag)
 {
     int unit = UNIT(dev);
+#ifdef NEW_CONFIG
+    struct joy_softc *joy_sc = (struct joy_softc *) joy_cd.cd_devs[unit];
+    int port = joy_sc->port;
+#else
     int port = joy[unit].port;
+#endif
     int i, t0, t1;
     int state = 0, x = 0, y = 0;
     struct joystick c;
@@ -176,7 +244,11 @@
     outb (port, 0xff);
     t0 = get_tick ();
     t1 = t0;
+#ifdef NEW_CONFIG
+    i = usec2ticks(joy_sc->timeout[joypart(dev)]);
+#else
     i = usec2ticks(joy[unit].timeout[joypart(dev)]);
+#endif
     while (t0-t1 < i) {
 	state = inb (port);
 	if (joypart(dev) == 1)
@@ -192,8 +264,13 @@
 	    break;
     }
     enable_intr ();
+#ifdef NEW_CONFIG
+    c.x = x ? joy_sc->x_off[joypart(dev)] + ticks2usec(t0-x) : 0x80000000;
+    c.y = y ? joy_sc->y_off[joypart(dev)] + ticks2usec(t0-y) : 0x80000000;
+#else
     c.x = x ? joy[unit].x_off[joypart(dev)] + ticks2usec(t0-x) : 0x80000000;
     c.y = y ? joy[unit].y_off[joypart(dev)] + ticks2usec(t0-y) : 0x80000000;
+#endif
     state >>= 4;
     c.b1 = ~state & 1;
     c.b2 = ~(state >> 1) & 1;
@@ -206,28 +283,55 @@
     int unit = UNIT (dev);
     int i = joypart (dev);
     int x;
+#ifdef NEW_CONFIG
+    struct joy_softc *joy_sc = (struct joy_softc *) joy_cd.cd_devs[unit];
+#endif
 
     switch (cmd) {
     case JOY_SETTIMEOUT:
 	x = *(int *) data;
 	if (x < 1 || x > 10000) /* 10ms maximum! */
 	    return EINVAL;
+#ifdef NEW_CONFIG
+	joy_sc->timeout[i] = x;
+#else
 	joy[unit].timeout[i] = x;
+#endif
 	break;
     case JOY_GETTIMEOUT:
+#ifdef NEW_CONFIG
+	*(int *) data = joy_sc->timeout[i];
+#else
 	*(int *) data = joy[unit].timeout[i];
+#endif
 	break;
     case JOY_SET_X_OFFSET:
+#ifdef NEW_CONFIG
+	joy_sc->x_off[i] = *(int *) data;
+#else
 	joy[unit].x_off[i] = *(int *) data;
+#endif
 	break;
     case JOY_SET_Y_OFFSET:
+#ifdef NEW_CONFIG
+	joy_sc->y_off[i] = *(int *) data;
+#else
 	joy[unit].y_off[i] = *(int *) data;
+#endif
 	break;
     case JOY_GET_X_OFFSET:
+#ifdef NEW_CONFIG
+	*(int *) data = joy_sc->x_off[i];
+#else
 	*(int *) data = joy[unit].x_off[i];
+#endif
 	break;
     case JOY_GET_Y_OFFSET:
+#ifdef NEW_CONFIG
+	*(int *) data = joy_sc->y_off[i];
+#else
 	*(int *) data = joy[unit].y_off[i];
+#endif
 	break;
     default:
 	return ENXIO;
