ms.c revision 1.5 1 /* $NetBSD: ms.c,v 1.5 2006/11/12 19:00:43 plunky 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/cdefs.h>
31 __KERNEL_RCSID(0, "$NetBSD: ms.c,v 1.5 2006/11/12 19:00:43 plunky Exp $");
32
33 #include <sys/param.h>
34 #include <sys/device.h>
35 #include <sys/systm.h>
36
37 #include <dev/wscons/wsconsio.h>
38 #include <dev/wscons/wsmousevar.h>
39
40 #include <machine/cpu.h>
41 #include <machine/bus.h>
42
43 #include <news68k/dev/msvar.h>
44
45 void
46 ms_intr(struct ms_softc *sc)
47 {
48 bus_space_tag_t bt = sc->sc_bt;
49 bus_space_handle_t bh = sc->sc_bh;
50 bus_size_t offset = sc->sc_offset;
51 int code, index, byte0, byte1, byte2;
52 int button, dx, dy;
53
54 if (sc->sc_wsmousedev == NULL)
55 return;
56
57 code = bus_space_read_1(bt, bh, offset);
58 index = sc->sc_ndata;
59
60 if (code & MS_S_MARK) {
61 sc->sc_buf[MS_S_BYTE] = code;
62 sc->sc_ndata = MS_X_BYTE;
63 return;
64 }
65
66 if (index == MS_X_BYTE) {
67 sc->sc_buf[MS_X_BYTE] = code;
68 sc->sc_ndata = MS_Y_BYTE;
69 return;
70 }
71
72 if (index == MS_Y_BYTE) {
73 sc->sc_buf[MS_Y_BYTE] = code;
74 sc->sc_ndata = 0;
75
76 byte0 = sc->sc_buf[MS_S_BYTE];
77 byte1 = sc->sc_buf[MS_X_BYTE];
78 byte2 = sc->sc_buf[MS_Y_BYTE];
79
80 button = 0;
81 if (byte0 & MS_S_SW1)
82 button |= 0x01;
83 if (byte0 & MS_S_SW3)
84 button |= 0x02;
85 if (byte0 & MS_S_SW2)
86 button |= 0x04;
87
88 dx = byte1 & MS_X_DATA;
89 if (byte0 & MS_S_XSIGN)
90 dx = -dx;
91 dy = byte2 & MS_Y_DATA;
92 if (byte0 & MS_S_YSIGN)
93 dy = -dy;
94
95 wsmouse_input(sc->sc_wsmousedev,
96 button,
97 dx, -dy, 0, 0,
98 WSMOUSE_INPUT_DELTA);
99 }
100 }
101