| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: ms.c,v 1.34 2014/07/25 08:10:35 dholland Exp $ */ | | 1 | /* $NetBSD: ms.c,v 1.35 2021/02/07 16:13:56 tsutsui Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1992, 1993 | | 4 | * Copyright (c) 1992, 1993 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * This software was developed by the Computer Systems Engineering group | | 7 | * This software was developed by the Computer Systems Engineering group |
8 | * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and | | 8 | * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and |
9 | * contributed to Berkeley. | | 9 | * contributed to Berkeley. |
10 | * | | 10 | * |
11 | * All advertising materials mentioning features or use of this software | | 11 | * All advertising materials mentioning features or use of this software |
12 | * must display the following acknowledgement: | | 12 | * must display the following acknowledgement: |
13 | * This product includes software developed by the University of | | 13 | * This product includes software developed by the University of |
14 | * California, Lawrence Berkeley Laboratory. | | 14 | * California, Lawrence Berkeley Laboratory. |
| @@ -35,27 +35,27 @@ | | | @@ -35,27 +35,27 @@ |
35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
37 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 37 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
38 | * SUCH DAMAGE. | | 38 | * SUCH DAMAGE. |
39 | * | | 39 | * |
40 | * @(#)ms.c 8.1 (Berkeley) 6/11/93 | | 40 | * @(#)ms.c 8.1 (Berkeley) 6/11/93 |
41 | */ | | 41 | */ |
42 | | | 42 | |
43 | /* | | 43 | /* |
44 | * X68k mouse driver. | | 44 | * X68k mouse driver. |
45 | */ | | 45 | */ |
46 | | | 46 | |
47 | #include <sys/cdefs.h> | | 47 | #include <sys/cdefs.h> |
48 | __KERNEL_RCSID(0, "$NetBSD: ms.c,v 1.34 2014/07/25 08:10:35 dholland Exp $"); | | 48 | __KERNEL_RCSID(0, "$NetBSD: ms.c,v 1.35 2021/02/07 16:13:56 tsutsui Exp $"); |
49 | | | 49 | |
50 | #include <sys/param.h> | | 50 | #include <sys/param.h> |
51 | #include <sys/conf.h> | | 51 | #include <sys/conf.h> |
52 | #include <sys/ioctl.h> | | 52 | #include <sys/ioctl.h> |
53 | #include <sys/kernel.h> | | 53 | #include <sys/kernel.h> |
54 | #include <sys/proc.h> | | 54 | #include <sys/proc.h> |
55 | #include <sys/syslog.h> | | 55 | #include <sys/syslog.h> |
56 | #include <sys/systm.h> | | 56 | #include <sys/systm.h> |
57 | #include <sys/tty.h> | | 57 | #include <sys/tty.h> |
58 | #include <sys/device.h> | | 58 | #include <sys/device.h> |
59 | #include <sys/signalvar.h> | | 59 | #include <sys/signalvar.h> |
60 | #include <sys/mutex.h> | | 60 | #include <sys/mutex.h> |
61 | | | 61 | |
| @@ -346,28 +346,28 @@ mskqfilter(dev_t dev, struct knote *kn) | | | @@ -346,28 +346,28 @@ mskqfilter(dev_t dev, struct knote *kn) |
346 | | | 346 | |
347 | /**************************************************************** | | 347 | /**************************************************************** |
348 | * Middle layer (translator) | | 348 | * Middle layer (translator) |
349 | ****************************************************************/ | | 349 | ****************************************************************/ |
350 | | | 350 | |
351 | /* | | 351 | /* |
352 | * Called by our ms_softint() routine on input. | | 352 | * Called by our ms_softint() routine on input. |
353 | */ | | 353 | */ |
354 | static void | | 354 | static void |
355 | ms_input(struct ms_softc *ms, int c) | | 355 | ms_input(struct ms_softc *ms, int c) |
356 | { | | 356 | { |
357 | struct firm_event *fe; | | 357 | struct firm_event *fe; |
358 | int mb, ub, d, get, put, any; | | 358 | int mb, ub, d, get, put, any; |
359 | static const char to_one[] = { 1, 2, 3 }; | | 359 | static const char to_one[] = { 1, 2, 2 }; |
360 | static const int to_id[] = { MS_LEFT, MS_RIGHT, MS_MIDDLE }; | | 360 | static const int to_id[] = { MS_LEFT, MS_RIGHT }; |
361 | | | 361 | |
362 | /* | | 362 | /* |
363 | * Discard input if not ready. Drop sync on parity or framing | | 363 | * Discard input if not ready. Drop sync on parity or framing |
364 | * error; gain sync on button byte. | | 364 | * error; gain sync on button byte. |
365 | */ | | 365 | */ |
366 | if (ms->ms_ready == 0) | | 366 | if (ms->ms_ready == 0) |
367 | return; | | 367 | return; |
368 | | | 368 | |
369 | ms->ms_nodata = 0; | | 369 | ms->ms_nodata = 0; |
370 | /* | | 370 | /* |
371 | * Run the decode loop, adding to the current information. | | 371 | * Run the decode loop, adding to the current information. |
372 | * We add, rather than replace, deltas, so that if the event queue | | 372 | * We add, rather than replace, deltas, so that if the event queue |
373 | * fills, we accumulate data for when it opens up again. | | 373 | * fills, we accumulate data for when it opens up again. |
| @@ -392,27 +392,27 @@ ms_input(struct ms_softc *ms, int c) | | | @@ -392,27 +392,27 @@ ms_input(struct ms_softc *ms, int c) |
392 | case 2: | | 392 | case 2: |
393 | /* delta-y */ | | 393 | /* delta-y */ |
394 | ms->ms_byteno = -1; | | 394 | ms->ms_byteno = -1; |
395 | ms->ms_dy += (char)c; | | 395 | ms->ms_dy += (char)c; |
396 | break; | | 396 | break; |
397 | | | 397 | |
398 | default: | | 398 | default: |
399 | panic("ms_input"); | | 399 | panic("ms_input"); |
400 | /* NOTREACHED */ | | 400 | /* NOTREACHED */ |
401 | } | | 401 | } |
402 | | | 402 | |
403 | /* | | 403 | /* |
404 | * We have at least one event (mouse button, delta-X, or | | 404 | * We have at least one event (mouse button, delta-X, or |
405 | * delta-Y; possibly all three, and possibly three separate | | 405 | * delta-Y; possibly all three, and possibly two separate |
406 | * button events). Deliver these events until we are out | | 406 | * button events). Deliver these events until we are out |
407 | * of changes or out of room. As events get delivered, | | 407 | * of changes or out of room. As events get delivered, |
408 | * mark them `unchanged'. | | 408 | * mark them `unchanged'. |
409 | */ | | 409 | */ |
410 | any = 0; | | 410 | any = 0; |
411 | get = ms->ms_events.ev_get; | | 411 | get = ms->ms_events.ev_get; |
412 | put = ms->ms_events.ev_put; | | 412 | put = ms->ms_events.ev_put; |
413 | fe = &ms->ms_events.ev_q[put]; | | 413 | fe = &ms->ms_events.ev_q[put]; |
414 | | | 414 | |
415 | /* NEXT prepares to put the next event, backing off if necessary */ | | 415 | /* NEXT prepares to put the next event, backing off if necessary */ |
416 | #define NEXT \ | | 416 | #define NEXT \ |
417 | if ((++put) % EV_QSIZE == get) { \ | | 417 | if ((++put) % EV_QSIZE == get) { \ |
418 | put--; \ | | 418 | put--; \ |
| @@ -420,32 +420,32 @@ ms_input(struct ms_softc *ms, int c) | | | @@ -420,32 +420,32 @@ ms_input(struct ms_softc *ms, int c) |
420 | } | | 420 | } |
421 | /* ADVANCE completes the `put' of the event */ | | 421 | /* ADVANCE completes the `put' of the event */ |
422 | #define ADVANCE \ | | 422 | #define ADVANCE \ |
423 | fe++; \ | | 423 | fe++; \ |
424 | if (put >= EV_QSIZE) { \ | | 424 | if (put >= EV_QSIZE) { \ |
425 | put = 0; \ | | 425 | put = 0; \ |
426 | fe = &ms->ms_events.ev_q[0]; \ | | 426 | fe = &ms->ms_events.ev_q[0]; \ |
427 | } \ | | 427 | } \ |
428 | | | 428 | |
429 | mb = ms->ms_mb; | | 429 | mb = ms->ms_mb; |
430 | ub = ms->ms_ub; | | 430 | ub = ms->ms_ub; |
431 | while ((d = mb ^ ub) != 0) { | | 431 | while ((d = mb ^ ub) != 0) { |
432 | /* | | 432 | /* |
433 | * Mouse button change. Convert up to three changes | | 433 | * Mouse button change. Convert up to two changes |
434 | * to the `first' change, and drop it into the event queue. | | 434 | * to the `first' change, and drop it into the event queue. |
435 | */ | | 435 | */ |
436 | NEXT; | | 436 | NEXT; |
437 | d = to_one[d - 1]; /* from 1..7 to {1,2,4} */ | | 437 | d = to_one[d - 1]; /* from 1..3 to {1,2} */ |
438 | fe->id = to_id[d - 1]; /* from {1,2,4} to ID */ | | 438 | fe->id = to_id[d - 1]; /* from {1,2} to ID */ |
439 | fe->value = mb & d ? VKEY_DOWN : VKEY_UP; | | 439 | fe->value = mb & d ? VKEY_DOWN : VKEY_UP; |
440 | firm_gettime(fe); | | 440 | firm_gettime(fe); |
441 | ADVANCE; | | 441 | ADVANCE; |
442 | ub ^= d; | | 442 | ub ^= d; |
443 | any++; | | 443 | any++; |
444 | } | | 444 | } |
445 | if (ms->ms_dx) { | | 445 | if (ms->ms_dx) { |
446 | NEXT; | | 446 | NEXT; |
447 | fe->id = LOC_X_DELTA; | | 447 | fe->id = LOC_X_DELTA; |
448 | fe->value = ms->ms_dx; | | 448 | fe->value = ms->ms_dx; |
449 | firm_gettime(fe); | | 449 | firm_gettime(fe); |
450 | ADVANCE; | | 450 | ADVANCE; |
451 | ms->ms_dx = 0; | | 451 | ms->ms_dx = 0; |