VirtualBox

Changeset 26925 in vbox


Ignore:
Timestamp:
Mar 1, 2010 8:22:59 PM (15 years ago)
Author:
vboxsync
Message:

Devices/Input/DevPS2: backed out the absolute reporting code, minus cleanup done to the device code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Input/DevPS2.cpp

    r26690 r26925  
    5757#include "../Builtins.h"
    5858
    59 #define PCKBD_SAVED_STATE_VERSION 4
     59#define PCKBD_SAVED_STATE_VERSION 5
    6060
    6161
     
    167167    MOUSE_PROT_PS2 = 0,
    168168    MOUSE_PROT_IMPS2 = 3,
    169     MOUSE_PROT_IMEX = 4,
    170     MOUSE_PROT_LIFEBOOK = 5
     169    MOUSE_PROT_IMEX = 4
    171170};
    172171
    173 /** Mouse flags */
     172/** @name Mouse flags */
     173/** @{ */
     174/** IMEX horizontal scroll-wheel mode is active */
    174175# define MOUSE_REPORT_HORIZONTAL  0x01
    175 
    176 /** @name Extended mouse button values for Lifebook mode
    177  * @{ */
    178 /** Downwards scrollwheel movement of one step.  Doesn't affect the mouse
    179  * buttons */
    180 # define MOUSE_EXT_VSCROLL_DN   4
    181 /** Upwards scrollwheel movement of one step. */
    182 # define MOUSE_EXT_VSCROLL_UP   5
    183 /** Leftwards scrollwheel movement of one step. */
    184 # define MOUSE_EXT_HSCROLL_BW   6
    185 /** Rightwards scrollwheel movement of one step. */
    186 # define MOUSE_EXT_HSCROLL_FW   7
    187176/** @} */
    188177
     
    225214    uint8_t mouse_sample_rate;
    226215    uint8_t mouse_wrap;
    227     uint8_t mouse_type; /* 0 = PS2, 3 = IMPS/2, 4 = IMEX */
     216    uint8_t mouse_type; /* MOUSE_PROT_PS2, *_IMPS/2, *_IMEX */
    228217    uint8_t mouse_detect_state;
    229218    int32_t mouse_dx; /* current values, needed for 'poll' mode */
     
    232221    int32_t mouse_dw;
    233222    int32_t mouse_flags;
    234     uint32_t mouse_cx; /** @todo r=bird: cx/cy? aren't these absolute coordinates? 'c' usually means 'count of'. mouse_abs_x or just mouse_x would probably be clearer. */
    235     uint32_t mouse_cy;
    236223    uint8_t mouse_buttons;
    237224    uint8_t mouse_buttons_reported;
    238     uint8_t mouse_last_button;
    239225
    240226    /** Pointer to the device instance - RC. */
     
    679665}
    680666
    681 static bool kbd_mouse_test_set_button(KBDState *s, unsigned cIndex)
    682 {
    683     unsigned fButtonMask = 1 << (cIndex - 1);
    684 
    685     AssertReturn(3 <= cIndex && cIndex <= 5, false);
    686     if (   (s->mouse_buttons & fButtonMask)
    687         && !(s->mouse_buttons_reported & fButtonMask))
    688     {
    689         s->mouse_last_button = cIndex;
    690         kbd_mouse_set_reported_buttons(s, fButtonMask, 0x1c);
    691         return true;
    692     }
    693     return false;
    694 }
    695 
    696 static bool kbd_mouse_test_clear_last_button(KBDState *s)
    697 {
    698     unsigned fButtonMask = 1 << (s->mouse_last_button - 1);
    699 
    700     if (   s->mouse_last_button != 0
    701         && !(s->mouse_buttons & fButtonMask))
    702     {
    703         s->mouse_last_button = 0;
    704         kbd_mouse_set_reported_buttons(s, 0, fButtonMask);
    705         return true;
    706     }
    707     return false;
    708 }
    709 
    710667/**
    711668 * Send a single relative packet in 3-byte PS/2 format, optionally with our
     
    723680{
    724681    int aux = fToCmdQueue ? 1 : 2;
    725     int dx1 =   s->mouse_dx < 0 ? RT_MAX(s->mouse_dx, -256)
    726               : s->mouse_dx > 0 ? RT_MIN(s->mouse_dx, 255) : 0;
    727     int dy1 =   s->mouse_dy < 0 ? RT_MAX(s->mouse_dy, -256)
    728               : s->mouse_dy > 0 ? RT_MIN(s->mouse_dy, 255) : 0;
     682    int dx1 = s->mouse_dx < 0 ? RT_MAX(s->mouse_dx, -256)
     683                              : RT_MIN(s->mouse_dx, 255);
     684    int dy1 = s->mouse_dy < 0 ? RT_MAX(s->mouse_dy, -256)
     685                              : RT_MIN(s->mouse_dy, 255);
    729686    unsigned int b;
    730687    unsigned fButtonsPacked;
     
    733690    s->mouse_dy -= dy1;
    734691    kbd_mouse_set_reported_buttons(s, fButtonsLow, 0x03);
    735     /* When we are not in lifebook mode, we just set the third bit
    736      * in the first packet byte if the middle button is pressed,
    737      * as per the PS/2 protocol. */
    738     if (s->mouse_type != MOUSE_PROT_LIFEBOOK)
    739     {
    740         fButtonsPacked = (s->mouse_buttons & 0x04 ? 0x04 : 0);
    741         kbd_mouse_set_reported_buttons(s, s->mouse_buttons, 0x04);
    742     }
    743     else
    744     {
    745         if (kbd_mouse_test_set_button(s, 3))
    746             fButtonsPacked = 1;
    747         else if (kbd_mouse_test_set_button(s, 4))
    748             fButtonsPacked = 2;
    749         else if (kbd_mouse_test_set_button(s, 5))
    750             fButtonsPacked = 3;
    751         /* Release event for buttons in the range 3-5. */
    752         else if (kbd_mouse_test_clear_last_button(s))
    753             fButtonsPacked = 0;
    754         else if (s->mouse_dz < 0)
    755         {
    756             ++s->mouse_dz;
    757             fButtonsPacked = MOUSE_EXT_VSCROLL_DN;
    758         }
    759         else if (s->mouse_dz > 0)
    760         {
    761             --s->mouse_dz;
    762             fButtonsPacked = MOUSE_EXT_VSCROLL_UP;
    763         }
    764         else if (s->mouse_dw < 0)
    765         {
    766             ++s->mouse_dw;
    767             fButtonsPacked = MOUSE_EXT_HSCROLL_BW;
    768         }
    769         else if (s->mouse_dw > 0)
    770         {
    771             --s->mouse_dw;
    772             fButtonsPacked = MOUSE_EXT_HSCROLL_FW;
    773         }
    774         else
    775             fButtonsPacked = s->mouse_last_button;
    776     }
     692    fButtonsPacked = (s->mouse_buttons & 0x04 ? 0x04 : 0);
     693    kbd_mouse_set_reported_buttons(s, s->mouse_buttons, 0x04);
    777694    LogRel3(("%s: dx1=%d, dy1=%d, fButtonsLow=0x%x, fButtonsPacked=0x%x\n",
    778695             __PRETTY_FUNCTION__, dx1, dy1, fButtonsLow, fButtonsPacked));
     
    788705    int aux = fToCmdQueue ? 1 : 2;
    789706
    790     int dz1 =   s->mouse_dz < 0 ? RT_MAX(s->mouse_dz, -127)
    791               : s->mouse_dz > 0 ? RT_MIN(s->mouse_dz, 127) : 0;
     707    int dz1 = s->mouse_dz < 0 ? RT_MAX(s->mouse_dz, -127)
     708                              : RT_MIN(s->mouse_dz, 127);
    792709    s->mouse_dz -= dz1;
    793710    kbd_queue(s, dz1 & 0xff, aux);
     
    800717    if (s->mouse_dw)
    801718    {
    802         int dw1 =   s->mouse_dw < 0 ? RT_MAX(s->mouse_dw, -32)
    803                   : s->mouse_dw > 0 ? RT_MIN(s->mouse_dw, 32) : 0;
     719        int dw1 = s->mouse_dw < 0 ? RT_MAX(s->mouse_dw, -31)
     720                                  : RT_MIN(s->mouse_dw, 32);
    804721        s->mouse_dw -= dw1;
    805722        kbd_queue(s, 0x40 | (dw1 & 0x3f), aux);
     
    807724    else if (s->mouse_flags & MOUSE_REPORT_HORIZONTAL && s->mouse_dz)
    808725    {
    809         int dz1 =   s->mouse_dz < 0 ? RT_MAX(s->mouse_dz, -32)
    810                   : s->mouse_dz > 0 ? RT_MIN(s->mouse_dz, 32) : 0;
     726        int dz1 = s->mouse_dz < 0 ? RT_MAX(s->mouse_dz, -31)
     727                                  : RT_MIN(s->mouse_dz, 32);
    811728        s->mouse_dz -= dz1;
    812729        kbd_queue(s, 0x80 | (dz1 & 0x3f), aux);
     
    814731    else
    815732    {
    816         int dz1 =   s->mouse_dz < 0 ? RT_MAX(s->mouse_dz, -8)
    817                   : s->mouse_dz > 0 ? RT_MIN(s->mouse_dz, 8) : 0;
     733        int dz1 = s->mouse_dz < 0 ? RT_MAX(s->mouse_dz, -7)
     734                                  : RT_MIN(s->mouse_dz, 8);
    818735        s->mouse_dz -= dz1;
    819736        kbd_mouse_set_reported_buttons(s, s->mouse_buttons, 0x18);
     
    829746 *                      event queue)?
    830747 */
    831 static void kbd_mouse_send_rel_packet(KBDState *s, bool fToCmdQueue)
     748static void kbd_mouse_send_packet(KBDState *s, bool fToCmdQueue)
    832749{
    833750    kbd_mouse_send_rel3_packet(s, fToCmdQueue);
     
    838755}
    839756
    840 /**
    841  * Send a single absolute packet in 6-byte lifebook format to the PS/2
    842  * controller.
    843  * @param  s            keyboard state object
    844  * @param  fToCmdQueue  Which queue.
    845  */
    846 static void kbd_mouse_send_abs_packet(KBDState *s, bool fToCmdQueue)
    847 {
    848     int aux = fToCmdQueue ? 1 : 2;
    849     unsigned cx1 = s->mouse_cx * 4095 / 0xffff;
    850     unsigned cy1 = 4095 - (s->mouse_cy * 4095 / 0xffff);
    851     unsigned fButtons = s->mouse_buttons & 0x03;
    852     unsigned int b[6];
    853 
    854     LogRel3(("%s: cx1=%d, cy1=%d, fButtons=0x%x\n", __PRETTY_FUNCTION__,
    855              cx1, cy1, fButtons));
    856     b[0] = fButtons;
    857     Assert((b[0] & 0xf8) == 0);
    858     kbd_queue(s, b[0], aux);
    859     b[1] = ((cy1 << 2) & 0xc0) | (cx1 >> 6);
    860     kbd_queue(s, b[1], aux);
    861     b[2] = ((cx1 << 2) & 0xc0) | (cx1 & 0x3f);
    862     Assert(((b[2] & 0x30) << 2) == (b[2] & 0xc0));
    863     kbd_queue(s, b[2], aux);
    864     b[3] = 0xc0;
    865     kbd_queue(s, b[3], aux);  /* This byte is really wasted in the protocol */
    866     b[4] = ((cx1 << 2) & 0xc0) | (cy1 >> 6);
    867     Assert((b[4] & 0xc0) == (b[2] & 0xc0));
    868     kbd_queue(s, b[4], aux);
    869     b[5] = ((cy1 << 2) & 0xc0) | (cy1 & 0x3f);
    870     Assert(   (((b[5] & 0x30) << 2) == (b[1] & 0xc0))
    871            && ((b[5] & 0xc0) == (b[1] & 0xc0)));
    872     kbd_queue(s, b[5], aux);
    873 }
    874 
    875 static bool kbd_mouse_rel_unreported(KBDState *s)
     757static bool kbd_mouse_unreported(KBDState *s)
    876758{
    877759   return    s->mouse_dx
     
    882764}
    883765
    884 /**
    885  * Send a single packet in (IM)PS/2, IMEX or Lifebook format to the PS/2
    886  * controller.
    887  * @param  s            keyboard state object
    888  * @param  fToCmdQueue  is this the result of a poll on the mouse controller?
    889  */
    890 static void kbd_mouse_send_packet(KBDState *s, bool fToCmdQueue)
    891 {
    892     if (   kbd_mouse_rel_unreported(s)
    893         || (s->mouse_type != MOUSE_PROT_LIFEBOOK))
    894         kbd_mouse_send_rel_packet(s, fToCmdQueue);
    895     else
    896         kbd_mouse_send_abs_packet(s, fToCmdQueue);
    897 }
    898 
    899766#ifdef IN_RING3
    900767static size_t kbd_mouse_event_queue_free(KBDState *s)
     
    920787    s->mouse_dz += dz;
    921788    if (   (   (s->mouse_type == MOUSE_PROT_IMEX)
    922             && s->mouse_flags & MOUSE_REPORT_HORIZONTAL)
    923         || (s->mouse_type == MOUSE_PROT_LIFEBOOK))
     789            && s->mouse_flags & MOUSE_REPORT_HORIZONTAL))
    924790        s->mouse_dw += dw;
    925791    s->mouse_buttons = buttons_state;
     
    927793        /* if not remote, send event. Multiple events are sent if
    928794           too big deltas */
    929         while (   kbd_mouse_rel_unreported(s)
     795        while (   kbd_mouse_unreported(s)
    930796               && kbd_mouse_event_queue_free(s) > 4)
    931             kbd_mouse_send_rel_packet(s, false);
    932 }
    933 
    934 static void pc_kbd_mouse_event_abs(void *opaque, unsigned cx, unsigned cy)
    935 {
    936     LogRel3(("%s: cx=%d, cy=%d\n", __PRETTY_FUNCTION__, cx, cy));
    937     KBDState *s = (KBDState*)opaque;
    938 
    939     if (!(s->mouse_status & MOUSE_STATUS_ENABLED))
    940         return;
    941 
    942     if (s->mouse_type != MOUSE_PROT_LIFEBOOK)
    943         return;
    944 
    945     s->mouse_cx = cx;
    946     s->mouse_cy = cy;
    947 
    948     if (!(s->mouse_status & MOUSE_STATUS_REMOTE) &&
    949         (s->mouse_event_queue.count < (MOUSE_EVENT_QUEUE_SIZE - 4)))
    950         /* if not remote, send event */
    951         kbd_mouse_send_abs_packet(s, false);
     797            kbd_mouse_send_packet(s, false);
    952798}
    953799#endif /* IN_RING3 */
     
    1124970            kbd_queue(s, AUX_ACK, 1);
    1125971        }
    1126         else if (val == 6)  /* Lifebook off magic knock */
    1127         {
    1128 #ifdef IN_RING3
    1129             LogRelFlowFunc(("switching mouse device to basic PS/2 mode\n"));
    1130             s->mouse_type = MOUSE_PROT_PS2;
    1131             s->Mouse.pDrv->pfnAbsModeChange(s->Mouse.pDrv, false);
    1132 #else
    1133             return VINF_IOM_HC_IOPORT_WRITE;
    1134 #endif
    1135             kbd_queue(s, AUX_NACK, 1);
    1136         }
    1137         else if (val == 8)  /* Lifebook on magic knock */
    1138         {
    1139 #ifdef IN_RING3
    1140             LogRelFlowFunc(("switching mouse device to touch screen mode\n"));
    1141             s->mouse_type = MOUSE_PROT_LIFEBOOK;
    1142             s->Mouse.pDrv->pfnAbsModeChange(s->Mouse.pDrv, true);
    1143 #else
    1144             return VINF_IOM_HC_IOPORT_WRITE;
    1145 #endif
    1146             kbd_queue(s, AUX_NACK, 1);
    1147         }
    1148972        else
    1149973            kbd_queue(s, AUX_NACK, 1);
     
    12281052    s->mouse_wrap = 0;
    12291053    s->mouse_type = MOUSE_PROT_PS2;
    1230     if (s->Mouse.pDrv)
    1231         s->Mouse.pDrv->pfnAbsModeChange(s->Mouse.pDrv, false);
    12321054    s->mouse_detect_state = 0;
    12331055    s->mouse_dx = 0;
     
    12361058    s->mouse_dw = 0;
    12371059    s->mouse_flags = 0;
    1238     s->mouse_cx = 0x8000;
    1239     s->mouse_cy = 0x8000;
    12401060    s->mouse_buttons = 0;
    12411061    s->mouse_buttons_reported = 0;
    1242     s->mouse_last_button = 0;
    12431062    q = &s->queue;
    12441063    q->rptr = 0;
     
    12781097    qemu_put_be32s(f, &s->mouse_dw);
    12791098    qemu_put_be32s(f, &s->mouse_flags);
    1280     qemu_put_be32s(f, &s->mouse_cx);
    1281     qemu_put_be32s(f, &s->mouse_cy);
    12821099    qemu_put_8s(f, &s->mouse_buttons);
    12831100    qemu_put_8s(f, &s->mouse_buttons_reported);
    1284     qemu_put_8s(f, &s->mouse_last_button);
    12851101
    12861102    /* XXX: s->scancode_set isn't being saved, but we only really support set 2,
     
    13161132{
    13171133    uint32_t    u32, i;
     1134    uint8_t u8Dummy;
     1135    uint32_t u32Dummy;
    13181136    int         rc;
    13191137    KBDState *s = (KBDState*)opaque;
    13201138
     1139#if 0
     1140    /** @todo enable this and remove the "if (version_id == 4)" code at some
     1141     * later time */
     1142    /* Version 4 was never created by any publicly released version of VBox */
     1143    AssertReturn(version_id != 4, VERR_NOT_SUPPORTED);
     1144#endif
    13211145    if (version_id < 2 || version_id > PCKBD_SAVED_STATE_VERSION)
    13221146        return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
     
    13321156    qemu_get_8s(f, &s->mouse_wrap);
    13331157    qemu_get_8s(f, &s->mouse_type);
    1334     if (s->mouse_type == MOUSE_PROT_LIFEBOOK && s->Mouse.pDrv)
    1335         s->Mouse.pDrv->pfnAbsModeChange(s->Mouse.pDrv, true);
    13361158    qemu_get_8s(f, &s->mouse_detect_state);
    13371159    qemu_get_be32s(f, (uint32_t *)&s->mouse_dx);
     
    13441166    }
    13451167    qemu_get_8s(f, &s->mouse_buttons);
     1168    if (version_id == 4)
     1169    {
     1170        SSMR3GetU32(f, &u32Dummy);
     1171        SSMR3GetU32(f, &u32Dummy);
     1172    }
    13461173    if (version_id > 3)
    1347     {
    1348         SSMR3GetU32(f, &s->mouse_cx);
    1349         SSMR3GetU32(f, &s->mouse_cy);
    13501174        SSMR3GetU8(f, &s->mouse_buttons_reported);
    1351         SSMR3GetU8(f, &s->mouse_last_button);
    1352     }
     1175    if (version_id == 4)
     1176        SSMR3GetU8(f, &u8Dummy);
    13531177    s->queue.count = 0;
    13541178    s->queue.rptr = 0;
     
    16781502static DECLCALLBACK(int) kbdMousePutEventAbs(PPDMIMOUSEPORT pInterface, uint32_t uX, uint32_t uY, int32_t iDeltaZ, int32_t iDeltaW, uint32_t fButtons)
    16791503{
    1680     KBDState *pThis = RT_FROM_MEMBER(pInterface, KBDState, Mouse.IPort);
    1681     int rc = PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
    1682     AssertReleaseRC(rc);
    1683 
    1684     if (uX != pThis->mouse_cx || uY != pThis->mouse_cy)
    1685         pc_kbd_mouse_event_abs(pThis, uX, uY);
    1686     if (iDeltaZ || iDeltaW || fButtons != pThis->mouse_buttons)
    1687         pc_kbd_mouse_event(pThis, 0, 0, iDeltaZ, iDeltaW, fButtons);
    1688 
    1689     PDMCritSectLeave(&pThis->CritSect);
    1690     return VINF_SUCCESS;
     1504    AssertFailedReturn(VERR_NOT_SUPPORTED);
    16911505}
    16921506
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette