Deleted Added
full compact
sysmouse.c (93593) sysmouse.c (111815)
1/*-
2 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer as
10 * the first lines of this file unmodified.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer as
10 * the first lines of this file unmodified.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/dev/syscons/sysmouse.c 93593 2002-04-01 21:31:13Z jhb $
26 * $FreeBSD: head/sys/dev/syscons/sysmouse.c 111815 2003-03-03 12:15:54Z phk $
27 */
28
29#include "opt_syscons.h"
30
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/conf.h>
34#include <sys/tty.h>
35#include <sys/kernel.h>
36#include <sys/consio.h>
37#include <sys/mouse.h>
38
39#include <dev/syscons/syscons.h>
40
41#ifndef SC_NO_SYSMOUSE
42
43#define CDEV_MAJOR 12 /* major number, shared with syscons */
44#define SC_MOUSE 128 /* minor number */
45
46static d_open_t smopen;
47static d_close_t smclose;
48static d_ioctl_t smioctl;
49
50static struct cdevsw sm_cdevsw = {
27 */
28
29#include "opt_syscons.h"
30
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/conf.h>
34#include <sys/tty.h>
35#include <sys/kernel.h>
36#include <sys/consio.h>
37#include <sys/mouse.h>
38
39#include <dev/syscons/syscons.h>
40
41#ifndef SC_NO_SYSMOUSE
42
43#define CDEV_MAJOR 12 /* major number, shared with syscons */
44#define SC_MOUSE 128 /* minor number */
45
46static d_open_t smopen;
47static d_close_t smclose;
48static d_ioctl_t smioctl;
49
50static struct cdevsw sm_cdevsw = {
51 /* open */ smopen,
52 /* close */ smclose,
53 /* read */ ttyread,
54 /* write */ nowrite,
55 /* ioctl */ smioctl,
56 /* poll */ ttypoll,
57 /* mmap */ nommap,
58 /* strategy */ nostrategy,
59 /* name */ "sysmouse",
60 /* maj */ CDEV_MAJOR,
61 /* dump */ nodump,
62 /* psize */ nopsize,
63 /* flags */ D_TTY,
51 .d_open = smopen,
52 .d_close = smclose,
53 .d_read = ttyread,
54 .d_ioctl = smioctl,
55 .d_poll = ttypoll,
56 .d_name = "sysmouse",
57 .d_maj = CDEV_MAJOR,
58 .d_flags = D_TTY,
64};
65
66/* local variables */
67static struct tty *sysmouse_tty;
68static int mouse_level; /* sysmouse protocol level */
69static mousestatus_t mouse_status;
70
71static void smstart(struct tty *tp);
72static int smparam(struct tty *tp, struct termios *t);
73
74static int
75smopen(dev_t dev, int flag, int mode, struct thread *td)
76{
77 struct tty *tp;
78
79 DPRINTF(5, ("smopen: dev:%d,%d, vty:%d\n",
80 major(dev), minor(dev), SC_VTY(dev)));
81
82#if 0
83 if (SC_VTY(dev) != SC_MOUSE)
84 return ENXIO;
85#endif
86
87 tp = dev->si_tty = ttymalloc(dev->si_tty);
88 if (!(tp->t_state & TS_ISOPEN)) {
89 sysmouse_tty = tp;
90 tp->t_oproc = smstart;
91 tp->t_param = smparam;
92 tp->t_stop = nottystop;
93 tp->t_dev = dev;
94 ttychars(tp);
95 tp->t_iflag = TTYDEF_IFLAG;
96 tp->t_oflag = TTYDEF_OFLAG;
97 tp->t_cflag = TTYDEF_CFLAG;
98 tp->t_lflag = TTYDEF_LFLAG;
99 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
100 smparam(tp, &tp->t_termios);
101 (*linesw[tp->t_line].l_modem)(tp, 1);
102 } else if (tp->t_state & TS_XCLUDE && suser(td)) {
103 return EBUSY;
104 }
105
106 return (*linesw[tp->t_line].l_open)(dev, tp);
107}
108
109static int
110smclose(dev_t dev, int flag, int mode, struct thread *td)
111{
112 struct tty *tp;
113 int s;
114
115 tp = dev->si_tty;
116 s = spltty();
117 mouse_level = 0;
118 (*linesw[tp->t_line].l_close)(tp, flag);
119 ttyclose(tp);
120 splx(s);
121
122 return 0;
123}
124
125static void
126smstart(struct tty *tp)
127{
128 struct clist *rbp;
129 u_char buf[PCBURST];
130 int s;
131
132 s = spltty();
133 if (!(tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))) {
134 tp->t_state |= TS_BUSY;
135 rbp = &tp->t_outq;
136 while (rbp->c_cc)
137 q_to_b(rbp, buf, PCBURST);
138 tp->t_state &= ~TS_BUSY;
139 ttwwakeup(tp);
140 }
141 splx(s);
142}
143
144static int
145smparam(struct tty *tp, struct termios *t)
146{
147 tp->t_ispeed = t->c_ispeed;
148 tp->t_ospeed = t->c_ospeed;
149 tp->t_cflag = t->c_cflag;
150 return 0;
151}
152
153static int
154smioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td)
155{
156 struct tty *tp;
157 mousehw_t *hw;
158 mousemode_t *mode;
159 int error;
160 int s;
161
162 tp = dev->si_tty;
163 switch (cmd) {
164
165 case MOUSE_GETHWINFO: /* get device information */
166 hw = (mousehw_t *)data;
167 hw->buttons = 10; /* XXX unknown */
168 hw->iftype = MOUSE_IF_SYSMOUSE;
169 hw->type = MOUSE_MOUSE;
170 hw->model = MOUSE_MODEL_GENERIC;
171 hw->hwid = 0;
172 return 0;
173
174 case MOUSE_GETMODE: /* get protocol/mode */
175 mode = (mousemode_t *)data;
176 mode->level = mouse_level;
177 switch (mode->level) {
178 case 0: /* emulate MouseSystems protocol */
179 mode->protocol = MOUSE_PROTO_MSC;
180 mode->rate = -1; /* unknown */
181 mode->resolution = -1; /* unknown */
182 mode->accelfactor = 0; /* disabled */
183 mode->packetsize = MOUSE_MSC_PACKETSIZE;
184 mode->syncmask[0] = MOUSE_MSC_SYNCMASK;
185 mode->syncmask[1] = MOUSE_MSC_SYNC;
186 break;
187
188 case 1: /* sysmouse protocol */
189 mode->protocol = MOUSE_PROTO_SYSMOUSE;
190 mode->rate = -1;
191 mode->resolution = -1;
192 mode->accelfactor = 0;
193 mode->packetsize = MOUSE_SYS_PACKETSIZE;
194 mode->syncmask[0] = MOUSE_SYS_SYNCMASK;
195 mode->syncmask[1] = MOUSE_SYS_SYNC;
196 break;
197 }
198 return 0;
199
200 case MOUSE_SETMODE: /* set protocol/mode */
201 mode = (mousemode_t *)data;
202 if (mode->level == -1)
203 ; /* don't change the current setting */
204 else if ((mode->level < 0) || (mode->level > 1))
205 return EINVAL;
206 else
207 mouse_level = mode->level;
208 return 0;
209
210 case MOUSE_GETLEVEL: /* get operation level */
211 *(int *)data = mouse_level;
212 return 0;
213
214 case MOUSE_SETLEVEL: /* set operation level */
215 if ((*(int *)data < 0) || (*(int *)data > 1))
216 return EINVAL;
217 mouse_level = *(int *)data;
218 return 0;
219
220 case MOUSE_GETSTATUS: /* get accumulated mouse events */
221 s = spltty();
222 *(mousestatus_t *)data = mouse_status;
223 mouse_status.flags = 0;
224 mouse_status.obutton = mouse_status.button;
225 mouse_status.dx = 0;
226 mouse_status.dy = 0;
227 mouse_status.dz = 0;
228 splx(s);
229 return 0;
230
231#if notyet
232 case MOUSE_GETVARS: /* get internal mouse variables */
233 case MOUSE_SETVARS: /* set internal mouse variables */
234 return ENODEV;
235#endif
236
237 case MOUSE_READSTATE: /* read status from the device */
238 case MOUSE_READDATA: /* read data from the device */
239 return ENODEV;
240 }
241
242 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, td);
243 if (error != ENOIOCTL)
244 return error;
245 error = ttioctl(tp, cmd, data, flag);
246 if (error != ENOIOCTL)
247 return error;
248 return ENOTTY;
249}
250
251static void
252sm_attach_mouse(void *unused)
253{
254 dev_t dev;
255
256 dev = make_dev(&sm_cdevsw, SC_MOUSE, UID_ROOT, GID_WHEEL, 0600,
257 "sysmouse");
258 /* sysmouse doesn't have scr_stat */
259}
260
261SYSINIT(sysmouse, SI_SUB_DRIVERS, SI_ORDER_MIDDLE + CDEV_MAJOR,
262 sm_attach_mouse, NULL)
263
264int
265sysmouse_event(mouse_info_t *info)
266{
267 /* MOUSE_BUTTON?DOWN -> MOUSE_MSC_BUTTON?UP */
268 static int butmap[8] = {
269 MOUSE_MSC_BUTTON1UP | MOUSE_MSC_BUTTON2UP | MOUSE_MSC_BUTTON3UP,
270 MOUSE_MSC_BUTTON2UP | MOUSE_MSC_BUTTON3UP,
271 MOUSE_MSC_BUTTON1UP | MOUSE_MSC_BUTTON3UP,
272 MOUSE_MSC_BUTTON3UP,
273 MOUSE_MSC_BUTTON1UP | MOUSE_MSC_BUTTON2UP,
274 MOUSE_MSC_BUTTON2UP,
275 MOUSE_MSC_BUTTON1UP,
276 0,
277 };
278 u_char buf[8];
279 int x, y, z;
280 int i;
281
282 switch (info->operation) {
283 case MOUSE_ACTION:
284 mouse_status.button = info->u.data.buttons;
285 /* FALL THROUGH */
286 case MOUSE_MOTION_EVENT:
287 x = info->u.data.x;
288 y = info->u.data.y;
289 z = info->u.data.z;
290 break;
291 case MOUSE_BUTTON_EVENT:
292 x = y = z = 0;
293 if (info->u.event.value > 0)
294 mouse_status.button |= info->u.event.id;
295 else
296 mouse_status.button &= ~info->u.event.id;
297 break;
298 default:
299 return 0;
300 }
301
302 mouse_status.dx += x;
303 mouse_status.dy += y;
304 mouse_status.dz += z;
305 mouse_status.flags |= ((x || y || z) ? MOUSE_POSCHANGED : 0)
306 | (mouse_status.obutton ^ mouse_status.button);
307 if (mouse_status.flags == 0)
308 return 0;
309
310 if ((sysmouse_tty == NULL) || !(sysmouse_tty->t_state & TS_ISOPEN))
311 return mouse_status.flags;
312
313 /* the first five bytes are compatible with MouseSystems' */
314 buf[0] = MOUSE_MSC_SYNC
315 | butmap[mouse_status.button & MOUSE_STDBUTTONS];
316 x = imax(imin(x, 255), -256);
317 buf[1] = x >> 1;
318 buf[3] = x - buf[1];
319 y = -imax(imin(y, 255), -256);
320 buf[2] = y >> 1;
321 buf[4] = y - buf[2];
322 for (i = 0; i < MOUSE_MSC_PACKETSIZE; ++i)
323 (*linesw[sysmouse_tty->t_line].l_rint)(buf[i], sysmouse_tty);
324 if (mouse_level >= 1) {
325 /* extended part */
326 z = imax(imin(z, 127), -128);
327 buf[5] = (z >> 1) & 0x7f;
328 buf[6] = (z - (z >> 1)) & 0x7f;
329 /* buttons 4-10 */
330 buf[7] = (~mouse_status.button >> 3) & 0x7f;
331 for (i = MOUSE_MSC_PACKETSIZE; i < MOUSE_SYS_PACKETSIZE; ++i)
332 (*linesw[sysmouse_tty->t_line].l_rint)(buf[i],
333 sysmouse_tty);
334 }
335
336 return mouse_status.flags;
337}
338
339#endif /* !SC_NO_SYSMOUSE */
59};
60
61/* local variables */
62static struct tty *sysmouse_tty;
63static int mouse_level; /* sysmouse protocol level */
64static mousestatus_t mouse_status;
65
66static void smstart(struct tty *tp);
67static int smparam(struct tty *tp, struct termios *t);
68
69static int
70smopen(dev_t dev, int flag, int mode, struct thread *td)
71{
72 struct tty *tp;
73
74 DPRINTF(5, ("smopen: dev:%d,%d, vty:%d\n",
75 major(dev), minor(dev), SC_VTY(dev)));
76
77#if 0
78 if (SC_VTY(dev) != SC_MOUSE)
79 return ENXIO;
80#endif
81
82 tp = dev->si_tty = ttymalloc(dev->si_tty);
83 if (!(tp->t_state & TS_ISOPEN)) {
84 sysmouse_tty = tp;
85 tp->t_oproc = smstart;
86 tp->t_param = smparam;
87 tp->t_stop = nottystop;
88 tp->t_dev = dev;
89 ttychars(tp);
90 tp->t_iflag = TTYDEF_IFLAG;
91 tp->t_oflag = TTYDEF_OFLAG;
92 tp->t_cflag = TTYDEF_CFLAG;
93 tp->t_lflag = TTYDEF_LFLAG;
94 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
95 smparam(tp, &tp->t_termios);
96 (*linesw[tp->t_line].l_modem)(tp, 1);
97 } else if (tp->t_state & TS_XCLUDE && suser(td)) {
98 return EBUSY;
99 }
100
101 return (*linesw[tp->t_line].l_open)(dev, tp);
102}
103
104static int
105smclose(dev_t dev, int flag, int mode, struct thread *td)
106{
107 struct tty *tp;
108 int s;
109
110 tp = dev->si_tty;
111 s = spltty();
112 mouse_level = 0;
113 (*linesw[tp->t_line].l_close)(tp, flag);
114 ttyclose(tp);
115 splx(s);
116
117 return 0;
118}
119
120static void
121smstart(struct tty *tp)
122{
123 struct clist *rbp;
124 u_char buf[PCBURST];
125 int s;
126
127 s = spltty();
128 if (!(tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))) {
129 tp->t_state |= TS_BUSY;
130 rbp = &tp->t_outq;
131 while (rbp->c_cc)
132 q_to_b(rbp, buf, PCBURST);
133 tp->t_state &= ~TS_BUSY;
134 ttwwakeup(tp);
135 }
136 splx(s);
137}
138
139static int
140smparam(struct tty *tp, struct termios *t)
141{
142 tp->t_ispeed = t->c_ispeed;
143 tp->t_ospeed = t->c_ospeed;
144 tp->t_cflag = t->c_cflag;
145 return 0;
146}
147
148static int
149smioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td)
150{
151 struct tty *tp;
152 mousehw_t *hw;
153 mousemode_t *mode;
154 int error;
155 int s;
156
157 tp = dev->si_tty;
158 switch (cmd) {
159
160 case MOUSE_GETHWINFO: /* get device information */
161 hw = (mousehw_t *)data;
162 hw->buttons = 10; /* XXX unknown */
163 hw->iftype = MOUSE_IF_SYSMOUSE;
164 hw->type = MOUSE_MOUSE;
165 hw->model = MOUSE_MODEL_GENERIC;
166 hw->hwid = 0;
167 return 0;
168
169 case MOUSE_GETMODE: /* get protocol/mode */
170 mode = (mousemode_t *)data;
171 mode->level = mouse_level;
172 switch (mode->level) {
173 case 0: /* emulate MouseSystems protocol */
174 mode->protocol = MOUSE_PROTO_MSC;
175 mode->rate = -1; /* unknown */
176 mode->resolution = -1; /* unknown */
177 mode->accelfactor = 0; /* disabled */
178 mode->packetsize = MOUSE_MSC_PACKETSIZE;
179 mode->syncmask[0] = MOUSE_MSC_SYNCMASK;
180 mode->syncmask[1] = MOUSE_MSC_SYNC;
181 break;
182
183 case 1: /* sysmouse protocol */
184 mode->protocol = MOUSE_PROTO_SYSMOUSE;
185 mode->rate = -1;
186 mode->resolution = -1;
187 mode->accelfactor = 0;
188 mode->packetsize = MOUSE_SYS_PACKETSIZE;
189 mode->syncmask[0] = MOUSE_SYS_SYNCMASK;
190 mode->syncmask[1] = MOUSE_SYS_SYNC;
191 break;
192 }
193 return 0;
194
195 case MOUSE_SETMODE: /* set protocol/mode */
196 mode = (mousemode_t *)data;
197 if (mode->level == -1)
198 ; /* don't change the current setting */
199 else if ((mode->level < 0) || (mode->level > 1))
200 return EINVAL;
201 else
202 mouse_level = mode->level;
203 return 0;
204
205 case MOUSE_GETLEVEL: /* get operation level */
206 *(int *)data = mouse_level;
207 return 0;
208
209 case MOUSE_SETLEVEL: /* set operation level */
210 if ((*(int *)data < 0) || (*(int *)data > 1))
211 return EINVAL;
212 mouse_level = *(int *)data;
213 return 0;
214
215 case MOUSE_GETSTATUS: /* get accumulated mouse events */
216 s = spltty();
217 *(mousestatus_t *)data = mouse_status;
218 mouse_status.flags = 0;
219 mouse_status.obutton = mouse_status.button;
220 mouse_status.dx = 0;
221 mouse_status.dy = 0;
222 mouse_status.dz = 0;
223 splx(s);
224 return 0;
225
226#if notyet
227 case MOUSE_GETVARS: /* get internal mouse variables */
228 case MOUSE_SETVARS: /* set internal mouse variables */
229 return ENODEV;
230#endif
231
232 case MOUSE_READSTATE: /* read status from the device */
233 case MOUSE_READDATA: /* read data from the device */
234 return ENODEV;
235 }
236
237 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, td);
238 if (error != ENOIOCTL)
239 return error;
240 error = ttioctl(tp, cmd, data, flag);
241 if (error != ENOIOCTL)
242 return error;
243 return ENOTTY;
244}
245
246static void
247sm_attach_mouse(void *unused)
248{
249 dev_t dev;
250
251 dev = make_dev(&sm_cdevsw, SC_MOUSE, UID_ROOT, GID_WHEEL, 0600,
252 "sysmouse");
253 /* sysmouse doesn't have scr_stat */
254}
255
256SYSINIT(sysmouse, SI_SUB_DRIVERS, SI_ORDER_MIDDLE + CDEV_MAJOR,
257 sm_attach_mouse, NULL)
258
259int
260sysmouse_event(mouse_info_t *info)
261{
262 /* MOUSE_BUTTON?DOWN -> MOUSE_MSC_BUTTON?UP */
263 static int butmap[8] = {
264 MOUSE_MSC_BUTTON1UP | MOUSE_MSC_BUTTON2UP | MOUSE_MSC_BUTTON3UP,
265 MOUSE_MSC_BUTTON2UP | MOUSE_MSC_BUTTON3UP,
266 MOUSE_MSC_BUTTON1UP | MOUSE_MSC_BUTTON3UP,
267 MOUSE_MSC_BUTTON3UP,
268 MOUSE_MSC_BUTTON1UP | MOUSE_MSC_BUTTON2UP,
269 MOUSE_MSC_BUTTON2UP,
270 MOUSE_MSC_BUTTON1UP,
271 0,
272 };
273 u_char buf[8];
274 int x, y, z;
275 int i;
276
277 switch (info->operation) {
278 case MOUSE_ACTION:
279 mouse_status.button = info->u.data.buttons;
280 /* FALL THROUGH */
281 case MOUSE_MOTION_EVENT:
282 x = info->u.data.x;
283 y = info->u.data.y;
284 z = info->u.data.z;
285 break;
286 case MOUSE_BUTTON_EVENT:
287 x = y = z = 0;
288 if (info->u.event.value > 0)
289 mouse_status.button |= info->u.event.id;
290 else
291 mouse_status.button &= ~info->u.event.id;
292 break;
293 default:
294 return 0;
295 }
296
297 mouse_status.dx += x;
298 mouse_status.dy += y;
299 mouse_status.dz += z;
300 mouse_status.flags |= ((x || y || z) ? MOUSE_POSCHANGED : 0)
301 | (mouse_status.obutton ^ mouse_status.button);
302 if (mouse_status.flags == 0)
303 return 0;
304
305 if ((sysmouse_tty == NULL) || !(sysmouse_tty->t_state & TS_ISOPEN))
306 return mouse_status.flags;
307
308 /* the first five bytes are compatible with MouseSystems' */
309 buf[0] = MOUSE_MSC_SYNC
310 | butmap[mouse_status.button & MOUSE_STDBUTTONS];
311 x = imax(imin(x, 255), -256);
312 buf[1] = x >> 1;
313 buf[3] = x - buf[1];
314 y = -imax(imin(y, 255), -256);
315 buf[2] = y >> 1;
316 buf[4] = y - buf[2];
317 for (i = 0; i < MOUSE_MSC_PACKETSIZE; ++i)
318 (*linesw[sysmouse_tty->t_line].l_rint)(buf[i], sysmouse_tty);
319 if (mouse_level >= 1) {
320 /* extended part */
321 z = imax(imin(z, 127), -128);
322 buf[5] = (z >> 1) & 0x7f;
323 buf[6] = (z - (z >> 1)) & 0x7f;
324 /* buttons 4-10 */
325 buf[7] = (~mouse_status.button >> 3) & 0x7f;
326 for (i = MOUSE_MSC_PACKETSIZE; i < MOUSE_SYS_PACKETSIZE; ++i)
327 (*linesw[sysmouse_tty->t_line].l_rint)(buf[i],
328 sysmouse_tty);
329 }
330
331 return mouse_status.flags;
332}
333
334#endif /* !SC_NO_SYSMOUSE */