diff options
| author | leo <leo@NetBSD.org> | 1995-06-25 19:05:23 +0000 |
|---|---|---|
| committer | leo <leo@NetBSD.org> | 1995-06-25 19:05:23 +0000 |
| commit | 4abd54fe697bb6e3e2cf17fd0045de2be69daf13 (patch) | |
| tree | e454819162755a390da5e6897298f856ee07109c /sys | |
| parent | a7347091154b2197da8db8a2b50a36622006de12 (diff) | |
Mouse driver added.
Diffstat (limited to 'sys')
| -rw-r--r-- | sys/arch/atari/atari/conf.c | 6 | ||||
| -rw-r--r-- | sys/arch/atari/conf/ATARITT | 4 | ||||
| -rw-r--r-- | sys/arch/atari/conf/GENERIC | 3 | ||||
| -rw-r--r-- | sys/arch/atari/conf/files.atari | 5 | ||||
| -rw-r--r-- | sys/arch/atari/dev/event.c | 6 | ||||
| -rw-r--r-- | sys/arch/atari/dev/kbd.c | 50 | ||||
| -rw-r--r-- | sys/arch/atari/dev/ms.c | 323 |
7 files changed, 366 insertions, 31 deletions
diff --git a/sys/arch/atari/atari/conf.c b/sys/arch/atari/atari/conf.c index 49383e9c569..0fd6b852b59 100644 --- a/sys/arch/atari/atari/conf.c +++ b/sys/arch/atari/atari/conf.c @@ -1,4 +1,4 @@ -/* $NetBSD: conf.c,v 1.6 1995/04/22 22:05:17 leo Exp $ */ +/* $NetBSD: conf.c,v 1.7 1995/06/25 19:06:46 leo Exp $ */ /* * Copyright (c) 1991 The Regents of the University of California. @@ -138,6 +138,8 @@ cdev_decl(ite); cdev_decl(view); #include "kbd.h" cdev_decl(kbd); +#include "mouse.h" +cdev_decl(ms); #define fdopen Fdopen /* conflicts with fdopen() in kern_descrip.c */ cdev_decl(fd); #undef fdopen @@ -169,7 +171,7 @@ struct cdevsw cdevsw[] = cdev_tty_init(NITE,ite), /* 12: console terminal emulator */ cdev_view_init(NVIEW,view), /* 13: /dev/view00 /dev/view01, ... */ cdev_mouse_init(NKBD,kbd), /* 14: /dev/kbd */ - cdev_notdef(), /* 15: /dev/mouse0 /dev/mouse1 */ + cdev_mouse_init(NMOUSE,ms), /* 15: /dev/mouse0 /dev/mouse1 */ #define fdopen Fdopen /* conflicts with fdopen() in kern_descrip.c */ cdev_disk_init(NFD,fd), /* 16: floppy disk */ #undef fdopen diff --git a/sys/arch/atari/conf/ATARITT b/sys/arch/atari/conf/ATARITT index 3830fe46551..85420d7149d 100644 --- a/sys/arch/atari/conf/ATARITT +++ b/sys/arch/atari/conf/ATARITT @@ -1,5 +1,5 @@ # -# $NetBSD: ATARITT,v 1.2 1995/05/28 19:56:14 leo Exp $ +# $NetBSD: ATARITT,v 1.3 1995/06/25 19:07:04 leo Exp $ # # ATARI-TT # @@ -73,13 +73,13 @@ options KTRACE # Add kernel tracing system call options DIAGNOSTIC # Add additional error checking code options "NKMEMCLUSTERS=256" # Size of kernel malloc area options GENERIC # Mini-root boot support -#options KFONT_8x8 # Use 8x8 font instead of 8x16 # # Build one kernel that can boot from any disk. # config netbsd swap on generic +pseudo-device mouse 1 # mouse pseudo-device view 2 # View (graphics mapping) pseudo-device sl # Slip pseudo-device ppp # ppp diff --git a/sys/arch/atari/conf/GENERIC b/sys/arch/atari/conf/GENERIC index f82e7ae6a97..2d4f18c96ef 100644 --- a/sys/arch/atari/conf/GENERIC +++ b/sys/arch/atari/conf/GENERIC @@ -1,5 +1,5 @@ # -# $NetBSD: GENERIC,v 1.3 1995/06/09 19:49:27 leo Exp $ +# $NetBSD: GENERIC,v 1.4 1995/06/25 19:07:06 leo Exp $ # # Maximal ATARI-TT # @@ -89,6 +89,7 @@ options GENERIC # Mini-root boot support # config netbsd swap on generic +pseudo-device mouse 1 # mouse pseudo-device view 2 # View (graphics mapping) pseudo-device sl # Slip pseudo-device ppp # ppp diff --git a/sys/arch/atari/conf/files.atari b/sys/arch/atari/conf/files.atari index d95be31848e..5fedc5467b5 100644 --- a/sys/arch/atari/conf/files.atari +++ b/sys/arch/atari/conf/files.atari @@ -1,5 +1,5 @@ # -# $NetBSD: files.atari,v 1.8 1995/06/09 19:50:42 leo Exp $ +# $NetBSD: files.atari,v 1.9 1995/06/25 19:07:07 leo Exp $ # maxpartitions 16 @@ -55,6 +55,9 @@ file arch/atari/dev/font_8x16.c ite pseudo-device view file arch/atari/dev/view.c view grf needs-count +pseudo-device mouse +file arch/atari/dev/ms.c mouse needs-count + define scsi {} # ncr 5380 controller diff --git a/sys/arch/atari/dev/event.c b/sys/arch/atari/dev/event.c index df1126652cd..c4ae6c8b89f 100644 --- a/sys/arch/atari/dev/event.c +++ b/sys/arch/atari/dev/event.c @@ -1,4 +1,4 @@ -/* $NetBSD: event.c,v 1.1.1.1 1995/03/26 07:12:12 leo Exp $ */ +/* $NetBSD: event.c,v 1.2 1995/06/25 19:05:23 leo Exp $ */ /* * Copyright (c) 1992, 1993 @@ -57,8 +57,8 @@ #include <sys/systm.h> #include <sys/vnode.h> -#include <amiga/dev/vuid_event.h> -#include <amiga/dev/event_var.h> +#include <atari/dev/vuid_event.h> +#include <atari/dev/event_var.h> /* * Initialize a firm_event queue. diff --git a/sys/arch/atari/dev/kbd.c b/sys/arch/atari/dev/kbd.c index 0611fb8531f..2934fa12ae5 100644 --- a/sys/arch/atari/dev/kbd.c +++ b/sys/arch/atari/dev/kbd.c @@ -1,4 +1,4 @@ -/* $NetBSD: kbd.c,v 1.3 1995/06/09 20:00:14 leo Exp $ */ +/* $NetBSD: kbd.c,v 1.4 1995/06/25 19:05:26 leo Exp $ */ /* * Copyright (c) 1995 Leo Weppelman @@ -81,11 +81,12 @@ struct kbd_softc { static struct kbd_softc kbd_softc; +void kbd_write __P((u_char *, int)); + static void kbdsoft __P((void)); static void kbdattach __P((struct device *, struct device *, void *)); static int kbdmatch __P((struct device *, struct cfdata *, void *)); -static int kbd_wite_poll __P((u_char *, int)); -static void kbd_write __P((u_char *, int)); +static int kbd_write_poll __P((u_char *, int)); static void kbd_pkg_start __P((struct kbd_softc *, u_char)); struct cfdriver kbdcd = { @@ -112,7 +113,8 @@ struct device *pdp, *dp; void *auxp; { int timeout; - u_char rst[] = { 0x80, 0x01 }; + u_char kbd_rst[] = { 0x80, 0x01 }; + u_char kbd_icmd[] = { 0x12, 0x15 }; /* * Disable keyboard interrupts from MFP @@ -136,7 +138,7 @@ void *auxp; /* * Now send the reset string, and read+ignore it's response */ - if (!kbd_wite_poll(rst, 2)) + if (!kbd_write_poll(kbd_rst, 2)) printf("kbd: error cannot reset keyboard\n"); for (timeout = 1000; timeout > 0; timeout--) { if (KBD->ac_cs & (A_IRQ|A_RXRDY)) { @@ -145,6 +147,10 @@ void *auxp; } delay(100); } + /* + * Send init command: disable mice & joysticks + */ + kbd_write_poll(kbd_icmd, sizeof(kbd_icmd)); printf("\n"); } @@ -158,7 +164,6 @@ void kbdenable() { int s, code; - u_char kbd_icmd[] = { 0x12, 0x15 }; s = spltty(); @@ -178,11 +183,6 @@ kbdenable() kbd_softc.k_events.ev_io = 0; kbd_softc.k_pkg_size = 0; splx(s); - - /* - * Send init command: disable mice & joysticks - */ - kbd_write(kbd_icmd, sizeof(kbd_icmd)); } int kbdopen(dev_t dev, int flags, int mode, struct proc *p) @@ -355,10 +355,9 @@ kbdsoft() k->k_pkg_size = 0; /* * Package is complete, we can now - * send it to (the not yet present) - * mouse driver... + * send it to the mouse driver... */ - /* mouse_soft(k->k_package,k->k_pkg_size);*/ + mouse_soft(k->k_package, k->k_pkg_size); } continue; } @@ -427,11 +426,16 @@ int kbdgetcn() { u_char code; - int s = spltty(); + int s = spltty(); + int ints_active; - MFP->mf_imrb &= ~IB_AINT; + ints_active = 0; + if (MFP->mf_imrb & IB_AINT) { + ints_active = 1; + MFP->mf_imrb &= ~IB_AINT; + } for (;;) { - while (!(KBD->ac_cs & (A_IRQ|A_RXRDY))) + while (!((KBD->ac_cs & (A_IRQ|A_RXRDY)) == (A_IRQ|A_RXRDY))) ; /* Wait for key */ if (KBD->ac_cs & (A_OE|A_PE)) { code = KBD->ac_da; /* Silently ignore errors */ @@ -440,10 +444,12 @@ kbdgetcn() break; } - MFP->mf_iprb &= ~IB_AINT; - MFP->mf_imrb |= IB_AINT; - code = KBD->ac_da; + if (ints_active) { + MFP->mf_iprb &= ~IB_AINT; + MFP->mf_imrb |= IB_AINT; + } + splx (s); return code; } @@ -452,7 +458,7 @@ kbdgetcn() * Write a command to the keyboard in 'polled' mode. */ static int -kbd_wite_poll(cmd, len) +kbd_write_poll(cmd, len) u_char *cmd; int len; { @@ -471,7 +477,7 @@ int len; /* * Write a command to the keyboard. Return when command is send. */ -static void +void kbd_write(cmd, len) u_char *cmd; int len; diff --git a/sys/arch/atari/dev/ms.c b/sys/arch/atari/dev/ms.c new file mode 100644 index 00000000000..f967cd3c060 --- /dev/null +++ b/sys/arch/atari/dev/ms.c @@ -0,0 +1,323 @@ +/* $NetBSD: ms.c,v 1.1 1995/06/25 19:05:27 leo Exp $ + +/* + * Copyright (c) 1995 Leo Weppelman. + * All rights reserved. + * + * based on: + * + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Lawrence Berkeley Laboratory. + * + * 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. + * 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. + * + * @(#)ms.c 8.1 (Berkeley) 6/11/93 + * + * Header: ms.c,v 1.5 92/11/26 01:28:47 torek Exp (LBL) + */ + +/* + * Mouse driver. + */ + +#include <sys/param.h> +#include <sys/conf.h> +#include <sys/ioctl.h> +#include <sys/kernel.h> +#include <sys/proc.h> +#include <sys/systm.h> +#include <sys/tty.h> + +#include <atari/dev/event_var.h> +#include <atari/dev/vuid_event.h> + +#include "mouse.h" +#if NMOUSE > 0 + +/* there's really no more physical ports on an atari. */ +#if NMOUSE > 1 +#undef NMOUSE +#define NMOUSE 1 +#endif + +int +mouseattach(cnt) + int cnt; +{ + printf("1 mouse configured\n"); + return(NMOUSE); +} + +/* + * Mouse specific packages produced by the keyboard. Currently, we only + * define the REL_MOUSE package, as this is the only one used. + */ +typedef struct { + u_char id; + char dx; + char dy; +} REL_MOUSE; + +#define IS_REL_MOUSE(id) (((u_int)(id) & 0xF8) == 0xF8) + +static struct ms_softc { + u_char ms_buttons; /* button states */ + struct evvar ms_events; /* event queue state */ + int ms_dx; /* accumulated dx */ + int ms_dy; /* accumulated dy */ +} ms_softc[NMOUSE]; + +/* + * Note that we are called from the keyboard software interrupt! + */ +void +mouse_soft(rel_ms, size) +REL_MOUSE *rel_ms; +int size; +{ + struct ms_softc *ms = &ms_softc[0]; + struct firm_event *fe; + int get, put; + int sps; + u_char mbut, bmask; + + if (!IS_REL_MOUSE(rel_ms->id)) + return; /* Probably some other message */ + if (ms->ms_events.ev_io == NULL) + return; + + sps = splev(); + get = ms->ms_events.ev_get; + put = ms->ms_events.ev_put; + fe = &ms->ms_events.ev_q[put]; + + /* + * Button states are encoded in the lower 2 bits of 'id' + */ + if (!(mbut = ((rel_ms->id & 3) ^ ms->ms_buttons)) && (put != get)) { + /* + * Compact dx/dy messages. Always generate an event when + * a button is pressed or the event queue is empty. + */ + ms->ms_dx += rel_ms->dx; + ms->ms_dy += rel_ms->dy; + goto out; + } + rel_ms->dx += ms->ms_dx; + rel_ms->dy += ms->ms_dy; + ms->ms_dx = ms->ms_dy = 0; + + /* + * Output location events _before_ button events ie. make sure + * the button is pressed at the correct location. + */ + if (rel_ms->dx) { + if ((++put) % EV_QSIZE == get) { + put--; + goto out; + } + fe->id = LOC_X_DELTA; + fe->value = rel_ms->dx; + fe->time = time; + if (put >= EV_QSIZE) { + put = 0; + fe = &ms->ms_events.ev_q[0]; + } + else fe++; + } + if (rel_ms->dy) { + if ((++put) % EV_QSIZE == get) { + put--; + goto out; + } + fe->id = LOC_Y_DELTA; + fe->value = rel_ms->dy; + fe->time = time; + if (put >= EV_QSIZE) { + put = 0; + fe = &ms->ms_events.ev_q[0]; + } + else fe++; + } + if (mbut) { + for (bmask = 1; bmask < 0x04; bmask <<= 1) { + if (!(mbut & bmask)) + continue; + if ((++put) % EV_QSIZE == get) { + put--; + goto out; + } + fe->id = bmask & 1 ? MS_RIGHT : MS_LEFT; + fe->value = rel_ms->id & bmask ? VKEY_DOWN : VKEY_UP; + fe->time = time; + if (put >= EV_QSIZE) { + put = 0; + fe = &ms->ms_events.ev_q[0]; + } + else fe++; + } + } +out: + ms->ms_events.ev_put = put; + ms->ms_buttons = rel_ms->id & 3; + splx(sps); + EV_WAKEUP(&ms->ms_events); +} + +int +msopen(dev, flags, mode, p) +dev_t dev; +int flags, mode; +struct proc *p; +{ + u_char report_ms[] = { 0x08 }; + struct ms_softc *ms; + int unit; + + unit = minor(dev); + ms = &ms_softc[unit]; + + if (unit >= NMOUSE) + return(EXDEV); + + if (ms->ms_events.ev_io) + return(EBUSY); + + ms->ms_events.ev_io = p; + ms->ms_dx = ms->ms_dy = 0; + ev_init(&ms->ms_events); /* may cause sleep */ + + /* + * Enable mouse reporting. + */ + kbd_write(report_ms, sizeof(report_ms)); + return(0); +} + +int +msclose(dev, flags, mode, p) +dev_t dev; +int flags, mode; +struct proc *p; +{ + u_char disable_ms[] = { 0x12 }; + int unit; + struct ms_softc *ms; + + unit = minor (dev); + ms = &ms_softc[unit]; + + /* + * Turn off mouse interrogation. + */ + kbd_write(disable_ms, sizeof(disable_ms)); + ev_fini(&ms->ms_events); + ms->ms_events.ev_io = NULL; + return(0); +} + +int +msread(dev, uio, flags) +dev_t dev; +struct uio *uio; +int flags; +{ + struct ms_softc *ms; + + ms = &ms_softc[minor(dev)]; + return(ev_read(&ms->ms_events, uio, flags)); +} + +int +msioctl(dev, cmd, data, flag, p) +dev_t dev; +u_long cmd; +register caddr_t data; +int flag; +struct proc *p; +{ + struct ms_softc *ms; + int unit; + + unit = minor(dev); + ms = &ms_softc[unit]; + + switch (cmd) { + case FIONBIO: /* we will remove this someday (soon???) */ + return(0); + case FIOASYNC: + ms->ms_events.ev_async = *(int *)data != 0; + return(0); + case TIOCSPGRP: + if (*(int *)data != ms->ms_events.ev_io->p_pgid) + return(EPERM); + return(0); + case VUIDGFORMAT: /* we only do firm_events */ + *(int *)data = VUID_FIRM_EVENT; + return(0); + case VUIDSFORMAT: + if (*(int *)data != VUID_FIRM_EVENT) + return(EINVAL); + return(0); + } + return(ENOTTY); +} + +int +msselect(dev, rw, p) +dev_t dev; +int rw; +struct proc *p; +{ + struct ms_softc *ms; + + ms = &ms_softc[minor(dev)]; + return(ev_select(&ms->ms_events, rw, p)); +} + +#else /* NMOUSE > 0 */ +/* + * Provide the hook to the keyboard driver. + */ +void +mouse_soft(pkg, size) +void *pkg; +int size; +{ +} +#endif /* NMOUSE > 0 */ |
