1 /* $NetBSD: ms.c,v 1.1 2001/01/25 14:33:29 tsutsui Exp $ */ 2 3 /*- 4 * Copyright (c) 2001 Izumi Tsutsui. All rights reserved. 5 * Copyright (c) 2000 Tsubai Masanari. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. The name of the author may not be used to endorse or promote products 16 * derived from this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 #include <sys/param.h> 31 #include <sys/device.h> 32 #include <sys/systm.h> 33 34 #include <dev/wscons/wsconsio.h> 35 #include <dev/wscons/wsmousevar.h> 36 37 #include <machine/cpu.h> 38 #include <machine/bus.h> 39 40 #include <news68k/dev/msvar.h> 41 42 void 43 ms_intr(sc) 44 struct ms_softc *sc; 45 { 46 bus_space_tag_t bt = sc->sc_bt; 47 bus_space_handle_t bh = sc->sc_bh; 48 bus_size_t offset = sc->sc_offset; 49 int code, index, byte0, byte1, byte2; 50 int button, dx, dy; 51 52 if (sc->sc_wsmousedev == NULL) 53 return; 54 55 code = bus_space_read_1(bt, bh, offset); 56 index = sc->sc_ndata; 57 58 if (code & MS_S_MARK) { 59 sc->sc_buf[MS_S_BYTE] = code; 60 sc->sc_ndata = MS_X_BYTE; 61 return; 62 } 63 64 if (index == MS_X_BYTE) { 65 sc->sc_buf[MS_X_BYTE] = code; 66 sc->sc_ndata = MS_Y_BYTE; 67 return; 68 } 69 70 if (index == MS_Y_BYTE) { 71 sc->sc_buf[MS_Y_BYTE] = code; 72 sc->sc_ndata = 0; 73 74 byte0 = sc->sc_buf[MS_S_BYTE]; 75 byte1 = sc->sc_buf[MS_X_BYTE]; 76 byte2 = sc->sc_buf[MS_Y_BYTE]; 77 78 button = 0; 79 if (byte0 & MS_S_SW1) 80 button |= 0x01; 81 if (byte0 & MS_S_SW3) 82 button |= 0x02; 83 if (byte0 & MS_S_SW2) 84 button |= 0x04; 85 86 dx = byte1 & MS_X_DATA; 87 if (byte0 & MS_S_XSIGN) 88 dx = -dx; 89 dy = byte2 & MS_Y_DATA; 90 if (byte0 & MS_S_YSIGN) 91 dy = -dy; 92 93 wsmouse_input(sc->sc_wsmousedev, button, dx, -dy, 0, 94 WSMOUSE_INPUT_DELTA); 95 } 96 } 97