Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Reduce the massive code duplication regarding joy(4). Sp...



details:   https://anonhg.NetBSD.org/src/rev/3695f9ad9f79
branches:  trunk
changeset: 521651:3695f9ad9f79
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Sat Feb 02 18:37:38 2002 +0000

description:
Reduce the massive code duplication regarding joy(4). Split it into
MI and MD parts, and make ISA/ISAPNP/PCI joy(4) attachments MI.

diffstat:

 sys/arch/arc/conf/files.arc             |    6 +-
 sys/arch/arc/isa/joy.c                  |  255 --------------------------------
 sys/arch/arc/isa/joy_timer.c            |   65 ++++++++
 sys/arch/arm32/conf/files.arm32         |   11 +-
 sys/arch/arm32/isa/joy.c                |  235 -----------------------------
 sys/arch/arm32/isa/joy_isa.c            |  107 -------------
 sys/arch/arm32/isa/joy_isapnp.c         |  108 -------------
 sys/arch/arm32/isa/joy_timer.c          |   75 +++++++++
 sys/arch/arm32/isa/joyvar.h             |   56 -------
 sys/arch/bebox/conf/files.bebox         |    8 +-
 sys/arch/bebox/isa/joy.c                |  234 -----------------------------
 sys/arch/bebox/isa/joy_isa.c            |  107 -------------
 sys/arch/bebox/isa/joy_timer.c          |   76 +++++++++
 sys/arch/bebox/isa/joyvar.h             |   56 -------
 sys/arch/cats/conf/files.cats           |   11 +-
 sys/arch/dnard/conf/files.dnard         |    7 +-
 sys/arch/i386/conf/files.i386           |   15 +-
 sys/arch/i386/isa/joy.c                 |  238 -----------------------------
 sys/arch/i386/isa/joy_isa.c             |  119 --------------
 sys/arch/i386/isa/joy_isapnp.c          |  111 -------------
 sys/arch/i386/isa/joy_timer.c           |   79 +++++++++
 sys/arch/i386/isa/joyvar.h              |   56 -------
 sys/arch/i386/pci/joy_pci.c             |  138 -----------------
 sys/arch/netwinder/conf/files.netwinder |   11 +-
 sys/arch/prep/conf/files.prep           |    8 +-
 sys/arch/prep/isa/joy.c                 |  234 -----------------------------
 sys/arch/prep/isa/joy_isa.c             |  116 --------------
 sys/arch/prep/isa/joy_timer.c           |   75 +++++++++
 sys/arch/prep/isa/joyvar.h              |   56 -------
 sys/conf/files                          |    6 +-
 sys/dev/ic/joy.c                        |  221 +++++++++++++++++++++++++++
 sys/dev/ic/joyvar.h                     |   56 +++++++
 sys/dev/isa/files.isa                   |    6 +-
 sys/dev/isa/joy_isa.c                   |  119 ++++++++++++++
 sys/dev/isapnp/files.isapnp             |    6 +-
 sys/dev/isapnp/joy_isapnp.c             |  111 +++++++++++++
 sys/dev/pci/files.pci                   |    6 +-
 sys/dev/pci/joy_pci.c                   |  139 +++++++++++++++++
 38 files changed, 1056 insertions(+), 2287 deletions(-)

diffs (truncated from 3620 to 300 lines):

diff -r 40935affe11d -r 3695f9ad9f79 sys/arch/arc/conf/files.arc
--- a/sys/arch/arc/conf/files.arc       Sat Feb 02 18:10:28 2002 +0000
+++ b/sys/arch/arc/conf/files.arc       Sat Feb 02 18:37:38 2002 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.arc,v 1.35 2001/11/28 10:21:11 lukem Exp $
+#      $NetBSD: files.arc,v 1.36 2002/02/02 18:37:42 jdolecek Exp $
 #      $OpenBSD: files.arc,v 1.21 1999/09/11 10:20:20 niklas Exp $
 #
 # maxpartitions must be first item in files.${ARCH}
@@ -251,9 +251,7 @@
 file   arch/arc/jazz/com_jazzio.c      com & com_jazzio
 
 # Game adapter (joystick)
-device joy
-attach joy at isa
-file   arch/arc/isa/joy.c              joy needs-flag
+file   arch/arc/isa/joy_timer.c        joy
 
 # National Semiconductor DS8390/WD83C690-based boards
 # (WD/SMC 80x3 family, SMC Ultra [8216], 3Com 3C503, NE[12]000, and clones)
diff -r 40935affe11d -r 3695f9ad9f79 sys/arch/arc/isa/joy.c
--- a/sys/arch/arc/isa/joy.c    Sat Feb 02 18:10:28 2002 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,255 +0,0 @@
-/*     $NetBSD: joy.c,v 1.5 2001/06/13 15:03:53 soda Exp $     */
-/*     NetBSD: joy.c,v 1.3 1996/05/05 19:46:15 christos Exp    */
-
-/*-
- * Copyright (c) 1995 Jean-Marc Zucconi
- * All rights reserved.
- *
- * Ported to NetBSD by Matthieu Herrb <matthieu%laas.fr@localhost>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer
- *    in this position and unchanged.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/device.h>
-#include <sys/errno.h>
-
-#include <machine/cpu.h>
-#include <machine/pio.h>
-#include <machine/joystick.h>
-
-#include <dev/isa/isavar.h>
-#include <dev/isa/isareg.h>
-#include <dev/ic/i8253reg.h>
-
-/*
- * 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;
- * buttons 1-4 correspond to bits 4-7 and resistors 1-4 (X1, Y1, X2, Y2)
- * to bits 0-3.  If button 1 (resp 2, 3, 4) is pressed, the bit 4 (resp 5,
- * 6, 7) is set to 0 to get the value of a resistor, write the value 0xff
- * at port and wait until the corresponding bit returns to 0.
- */
-
-/*
- * 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)
-#define JOYUNIT(d) minor(d) >> 1 & 3
-
-#ifndef JOY_TIMEOUT
-#define JOY_TIMEOUT   2000     /* 2 milliseconds */
-#endif
-
-#define JOY_NPORTS    1
-
-struct joy_softc {
-       struct  device sc_dev;
-       int     port;
-       int     x_off[2], y_off[2];
-       int     timeout[2];
-};
-
-int            joyprobe __P((struct device *, struct cfdata *, void *));
-int            joyread __P((dev_t dev, struct uio *uio, int flag));
-int            joyioctl __P((dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p));
-void           joyattach __P((struct device *, struct device *, void *));
-int            joyopen __P((dev_t, int, int, struct proc *));
-int            joyclose __P((dev_t, int, int, struct proc *));
-static int     get_tick __P((void));
-
-struct cfattach joy_ca = {
-       sizeof(struct joy_softc), joyprobe, joyattach
-};
-
-extern struct cfdriver joy_cd;
-
-int
-joyprobe(parent, match, aux)
-       struct device *parent;
-       struct cfdata *match;
-       void *aux;
-{
-       struct isa_attach_args *ia = aux;
-#ifdef WANT_JOYSTICK_CONNECTED
-       int iobase = ia->ia_iobase;
-
-       isa_outb(iobase, 0xff);
-       DELAY(10000);           /* 10 ms delay */
-       return (isa_inb(iobase) & 0x0f) != 0x0f;
-#else
-       ia->ia_iosize = JOY_NPORTS;
-       ia->ia_msize = 0;
-       return 1;
-#endif
-}
-
-void
-joyattach(parent, self, aux)
-       struct device *parent, *self;
-       void *aux;
-{
-       struct joy_softc *sc = (void *) self;
-       struct isa_attach_args *ia = aux;
-       int iobase = ia->ia_iobase;
-
-       sc->port = iobase;
-       sc->timeout[0] = sc->timeout[1] = 0;
-       isa_outb(iobase, 0xff);
-       DELAY(10000);           /* 10 ms delay */
-       printf(": joystick%sconnected\n",
-           (isa_inb(iobase) & 0x0f) == 0x0f ? " not " : " ");
-}
-
-int
-joyopen(dev, flag, mode, p)
-       dev_t dev;
-       int flag, mode;
-       struct proc *p;
-{
-       int unit = JOYUNIT(dev);
-       int i = JOYPART(dev);
-       struct joy_softc *sc;
-
-       if (unit >= joy_cd.cd_ndevs)
-               return (ENXIO);
-
-       sc = joy_cd.cd_devs[unit];
-
-       if (sc->timeout[i])
-               return EBUSY;
-
-       sc->x_off[i] = sc->y_off[i] = 0;
-       sc->timeout[i] = JOY_TIMEOUT;
-       return 0;
-}
-
-int
-joyclose(dev, flag, mode, p)
-       dev_t dev;
-       int flag, mode;
-       struct proc *p;
-{
-       int unit = JOYUNIT(dev);
-       int i = JOYPART(dev);
-       struct joy_softc *sc = joy_cd.cd_devs[unit];
-
-       sc->timeout[i] = 0;
-       return 0;
-}
-
-int
-joyread(dev_t dev, struct uio *uio, int flag)
-{
-       int unit = JOYUNIT(dev);
-       struct joy_softc *sc = joy_cd.cd_devs[unit];
-       struct joystick c;
-       int port = sc->port;
-       int i, t0, t1;
-       int state = 0, x = 0, y = 0;
-
-       /* disable_intr(); */ /* XXX BAD */
-       isa_outb(port, 0xff);
-       t0 = get_tick();
-       t1 = t0;
-       i = USEC2TICKS(sc->timeout[JOYPART(dev)]);
-       while (t0 - t1 < i) {
-               state = isa_inb(port);
-               if (JOYPART(dev) == 1)
-                       state >>= 2;
-               t1 = get_tick();
-               if (t1 > t0)
-                       t1 -= TIMER_FREQ / hz;
-               if (!x && !(state & 0x01))
-                       x = t1;
-               if (!y && !(state & 0x02))
-                       y = t1;
-               if (x && y)
-                       break;
-       }
-       /* enable_intr(); */ /* XXX BAD */
-       c.x = x ? sc->x_off[JOYPART(dev)] + TICKS2USEC(t0 - x) : 0x80000000;
-       c.y = y ? sc->y_off[JOYPART(dev)] + TICKS2USEC(t0 - y) : 0x80000000;
-       state >>= 4;
-       c.b1 = ~state & 1;
-       c.b2 = ~(state >> 1) & 1;
-       return uiomove((caddr_t) & c, sizeof(struct joystick), uio);
-}
-
-int
-joyioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
-{
-       int unit = JOYUNIT(dev);
-       struct joy_softc *sc = joy_cd.cd_devs[unit];
-       int i = JOYPART(dev);
-       int x;
-
-       switch (cmd) {
-       case JOY_SETTIMEOUT:
-               x = *(int *) data;
-               if (x < 1 || x > 10000) /* 10ms maximum! */
-                       return EINVAL;
-               sc->timeout[i] = x;
-               break;
-       case JOY_GETTIMEOUT:
-               *(int *) data = sc->timeout[i];
-               break;
-       case JOY_SET_X_OFFSET:
-               sc->x_off[i] = *(int *) data;
-               break;
-       case JOY_SET_Y_OFFSET:
-               sc->y_off[i] = *(int *) data;
-               break;
-       case JOY_GET_X_OFFSET:
-               *(int *) data = sc->x_off[i];
-               break;
-       case JOY_GET_Y_OFFSET:
-               *(int *) data = sc->y_off[i];
-               break;
-       default:
-               return ENXIO;
-       }
-       return 0;
-}
-
-static int
-get_tick()
-{
-       int low, high;
-
-       isa_outb(TIMER_MODE, TIMER_SEL0);
-       low = isa_inb(TIMER_CNTR0);
-       high = isa_inb(TIMER_CNTR0);
-
-       return (high << 8) | low;
-}
diff -r 40935affe11d -r 3695f9ad9f79 sys/arch/arc/isa/joy_timer.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arc/isa/joy_timer.c      Sat Feb 02 18:37:38 2002 +0000
@@ -0,0 +1,65 @@
+/*     $NetBSD: joy_timer.c,v 1.1 2002/02/02 18:37:38 jdolecek Exp $   */
+
+/*-
+ * Copyright (c) 1995 Jean-Marc Zucconi
+ * All rights reserved.
+ *
+ * Ported to NetBSD by Matthieu Herrb <matthieu%laas.fr@localhost>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer
+ *    in this position and unchanged.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.



Home | Main Index | Thread Index | Old Index