Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/atari/dev Misc KNF and cleanup for readability.



details:   https://anonhg.NetBSD.org/src/rev/264f22f51cf0
branches:  trunk
changeset: 368155:264f22f51cf0
user:      tsutsui <tsutsui%NetBSD.org@localhost>
date:      Sun Jun 26 06:02:28 2022 +0000

description:
Misc KNF and cleanup for readability.

diffstat:

 sys/arch/atari/dev/ms.c    |  156 +++++++++++++++++++++++---------------------
 sys/arch/atari/dev/msvar.h |   12 +-
 2 files changed, 88 insertions(+), 80 deletions(-)

diffs (truncated from 423 to 300 lines):

diff -r 383802084314 -r 264f22f51cf0 sys/arch/atari/dev/ms.c
--- a/sys/arch/atari/dev/ms.c   Sun Jun 26 05:55:30 2022 +0000
+++ b/sys/arch/atari/dev/ms.c   Sun Jun 26 06:02:28 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ms.c,v 1.26 2014/07/25 08:10:32 dholland Exp $ */
+/*     $NetBSD: ms.c,v 1.27 2022/06/26 06:02:28 tsutsui Exp $  */
 
 /*
  * Copyright (c) 1995 Leo Weppelman.
@@ -52,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ms.c,v 1.26 2014/07/25 08:10:32 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ms.c,v 1.27 2022/06/26 06:02:28 tsutsui Exp $");
 
 #include <sys/param.h>
 #include <sys/conf.h>
@@ -79,9 +79,9 @@
 #define NMOUSE 1
 #endif
 
-typedef void   (*FPV)(void *);
+typedef void (*FPV)(void *);
 
-static struct ms_softc ms_softc[NMOUSE];
+static struct ms_softc ms_softc[NMOUSE];
 
 dev_type_open(msopen);
 dev_type_close(msclose);
@@ -105,45 +105,47 @@
        .d_flag = 0
 };
 
-static void    ms_3b_delay(struct ms_softc *);
+static void ms_3b_delay(struct ms_softc *);
 
 int
 mouseattach(int cnt)
 {
+
        printf("1 mouse configured\n");
        ms_softc[0].ms_emul3b = 1;
        callout_init(&ms_softc[0].ms_delay_ch, 0);
-       return(NMOUSE);
+
+       return NMOUSE;
 }
 
 static void
 ms_3b_delay(struct ms_softc *ms)
 {
-       REL_MOUSE       rel_ms;
+       REL_MOUSE rel_ms;
 
        rel_ms.id = TIMEOUT_ID;
        rel_ms.dx = rel_ms.dy = 0;
        mouse_soft(&rel_ms, sizeof(rel_ms), KBD_TIMEO_PKG);
 }
-/* 
+/*
  * Note that we are called from the keyboard software interrupt!
  */
 void
 mouse_soft(REL_MOUSE *rel_ms, int size, int type)
 {
-       struct ms_softc         *ms = &ms_softc[0];
-       struct firm_event       *fe, *fe2;
-       REL_MOUSE               fake_mouse;
-       int                     get, put;
-       int                     sps;
-       u_char                  mbut, bmask;
-       int                     flush_buttons;
+       struct ms_softc *ms = &ms_softc[0];
+       struct firm_event *fe, *fe2;
+       REL_MOUSE fake_mouse;
+       int get, put;
+       int s;
+       uint8_t mbut, bmask;
+       int flush_buttons;
 
        if (ms->ms_events.ev_io == NULL)
                return;
 
        switch (type) {
-           case KBD_JOY1_PKG:
+       case KBD_JOY1_PKG:
                /*
                 * Ignore if in emulation mode
                 */
@@ -158,11 +160,12 @@
                 * Flush all button changes.
                 */
                flush_buttons = 1;
-               fake_mouse.id = (rel_ms->dx & 1 ? 4 : 0) | (ms->ms_buttons & 3);
+               fake_mouse.id = ((rel_ms->dx & 0x01) != 0 ? 0x04 : 0x00) |
+                   (ms->ms_buttons & 0x03);
                fake_mouse.dx = fake_mouse.dy = 0;
                rel_ms = &fake_mouse;
                break;
-           case KBD_TIMEO_PKG:
+       case KBD_TIMEO_PKG:
                /*
                 * Timeout package. No button changes and no movement.
                 * Flush all button changes.
@@ -172,31 +175,31 @@
                fake_mouse.dx = fake_mouse.dy = 0;
                rel_ms = &fake_mouse;
                break;
-           case KBD_RMS_PKG:
+       case KBD_RMS_PKG:
                /*
                 * Normal mouse package. Always copy the middle button
                 * status. The emulation code decides if button changes
                 * must be flushed.
                 */
-               rel_ms->id = (ms->ms_buttons & 4) | (rel_ms->id & 3);
-               flush_buttons = (ms->ms_emul3b) ? 0 : 1;
+               rel_ms->id = (ms->ms_buttons & 0x04) | (rel_ms->id & 0x03);
+               flush_buttons = ms->ms_emul3b ? 0 : 1;
                break;
-           default:
+       default:
                return;
        }
 
-       sps = splev();
+       s = splev();
        get = ms->ms_events.ev_get;
        put = ms->ms_events.ev_put;
        fe  = &ms->ms_events.ev_q[put];
 
-       if ((type != KBD_TIMEO_PKG) && ms->ms_emul3b && ms->ms_bq_idx)
+       if ((type != KBD_TIMEO_PKG) && ms->ms_emul3b && ms->ms_bq_idx != 0)
                callout_stop(&ms->ms_delay_ch);
 
        /*
         * Button states are encoded in the lower 3 bits of 'id'
         */
-       if (!(mbut = (rel_ms->id ^ ms->ms_buttons)) && (put != get)) {
+       if ((mbut = (rel_ms->id ^ ms->ms_buttons)) == 0 && (put != get)) {
                /*
                 * Compact dx/dy messages. Always generate an event when
                 * a button is pressed or the event queue is empty.
@@ -213,7 +216,7 @@
         * Output location events _before_ button events ie. make sure
         * the button is pressed at the correct location.
         */
-       if (rel_ms->dx) {
+       if (rel_ms->dx != 0) {
                if ((++put) % EV_QSIZE == get) {
                        put--;
                        goto out;
@@ -224,10 +227,11 @@
                if (put >= EV_QSIZE) {
                        put = 0;
                        fe  = &ms->ms_events.ev_q[0];
+               } else {
+                       fe++;
                }
-               else fe++;
        }
-       if (rel_ms->dy) {
+       if (rel_ms->dy != 0) {
                if ((++put) % EV_QSIZE == get) {
                        put--;
                        goto out;
@@ -238,20 +242,23 @@
                if (put >= EV_QSIZE) {
                        put = 0;
                        fe  = &ms->ms_events.ev_q[0];
+               } else {
+                       fe++;
                }
-               else fe++;
        }
-       if (mbut && (type != KBD_TIMEO_PKG)) {
-               for (bmask = 1; bmask < 0x08; bmask <<= 1) {
-                       if (!(mbut & bmask))
+       if (mbut != 0 && (type != KBD_TIMEO_PKG)) {
+               for (bmask = 0x01; bmask < 0x08; bmask <<= 1) {
+                       if ((mbut & bmask) == 0)
                                continue;
                        fe2 = &ms->ms_bq[ms->ms_bq_idx++];
-                       if (bmask == 1)
+                       if (bmask == 0x01)
                                fe2->id = MS_RIGHT;
-                       else if (bmask == 2)
+                       else if (bmask == 0x02)
                                fe2->id = MS_LEFT;
-                       else fe2->id = MS_MIDDLE;
-                       fe2->value = rel_ms->id & bmask ? VKEY_DOWN : VKEY_UP;
+                       else
+                               fe2->id = MS_MIDDLE;
+                       fe2->value =
+                           (rel_ms->id & bmask) != 0 ?  VKEY_DOWN : VKEY_UP;
                        firm_gettime(fe2);
                }
        }
@@ -259,19 +266,19 @@
        /*
         * Handle 3rd button emulation.
         */
-       if (ms->ms_emul3b && ms->ms_bq_idx && (type != KBD_TIMEO_PKG)) {
+       if (ms->ms_emul3b && ms->ms_bq_idx != 0 && (type != KBD_TIMEO_PKG)) {
                /*
                 * If the middle button is pressed, any change to
                 * one of the other buttons releases all.
                 */
-               if ((ms->ms_buttons & 4) && (mbut & 3)) {
+               if ((ms->ms_buttons & 0x04) != 0 && (mbut & 0x03) != 0) {
                        ms->ms_bq[0].id = MS_MIDDLE;
                        ms->ms_bq_idx   = 1;
                        rel_ms->id      = 0;
                        flush_buttons   = 1;
                        goto out;
                }
-               if (ms->ms_bq_idx == 2) {
+               if (ms->ms_bq_idx == 2) {
                        if (ms->ms_bq[0].value == ms->ms_bq[1].value) {
                                /* Must be 2 button presses! */
                                ms->ms_bq[0].id = MS_MIDDLE;
@@ -286,9 +293,9 @@
                }
                flush_buttons   = 1;
        }
-out:
+ out:
        if (flush_buttons) {
-               int     i;
+               int i;
 
                for (i = 0; i < ms->ms_bq_idx; i++) {
                        if ((++put) % EV_QSIZE == get) {
@@ -300,32 +307,33 @@
                        if (put >= EV_QSIZE) {
                                put = 0;
                                fe  = &ms->ms_events.ev_q[0];
+                       } else {
+                               fe++;
                        }
-                       else fe++;
                }
                ms->ms_bq_idx = 0;
        }
        ms->ms_events.ev_put = put;
        ms->ms_buttons       = rel_ms->id;
-       splx(sps);
+       splx(s);
        EV_WAKEUP(&ms->ms_events);
 }
 
 int
 msopen(dev_t dev, int flags, int mode, struct lwp *l)
 {
-       u_char          report_ms_joy[] = { 0x14, 0x08 };
-       struct ms_softc *ms;
-       int             unit;
+       uint8_t report_ms_joy[] = { 0x14, 0x08 };
+       struct ms_softc *ms;
+       int unit;
 
        unit = minor(dev);
        ms   = &ms_softc[unit];
 
        if (unit >= NMOUSE)
-               return(EXDEV);
+               return EXDEV;
 
        if (ms->ms_events.ev_io)
-               return(EBUSY);
+               return EBUSY;
 
        ms->ms_events.ev_io = l->l_proc;
        ms->ms_dx = ms->ms_dy = 0;
@@ -338,17 +346,17 @@
         * Enable mouse reporting.
         */
        kbd_write(report_ms_joy, sizeof(report_ms_joy));
-       return(0);
+       return 0;
 }
 
 int
 msclose(dev_t dev, int flags, int mode, struct lwp *l)
 {
-       u_char          disable_ms_joy[] = { 0x12, 0x1a };
-       int             unit;
-       struct ms_softc *ms;
+       uint8_t disable_ms_joy[] = { 0x12, 0x1a };
+       int unit;
+       struct ms_softc *ms;
 
-       unit = minor (dev);
+       unit = minor(dev);
        ms   = &ms_softc[unit];
 
        /*
@@ -357,7 +365,7 @@
        kbd_write(disable_ms_joy, sizeof(disable_ms_joy));



Home | Main Index | Thread Index | Old Index