VirtualBox

Changeset 54240 in vbox


Ignore:
Timestamp:
Feb 17, 2015 3:37:46 PM (10 years ago)
Author:
vboxsync
Message:

PS2M: Final round of fixes before enabling.

Location:
trunk/src/VBox/Devices/Input
Files:
3 edited

Legend:

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

    r53055 r54240  
    11881188    {
    11891189        int32_t     i32Dummy;
     1190        uint8_t     u8State;
     1191        uint8_t     u8Rate;
     1192        uint8_t     u8Proto;
     1193
    11901194        SSMR3GetU32(pSSM, &u32Dummy);
     1195        SSMR3GetU8(pSSM, &u8State);
    11911196        SSMR3GetU8(pSSM, &u8Dummy);
     1197        SSMR3GetU8(pSSM, &u8Rate);
    11921198        SSMR3GetU8(pSSM, &u8Dummy);
    1193         SSMR3GetU8(pSSM, &u8Dummy);
    1194         SSMR3GetU8(pSSM, &u8Dummy);
    1195         SSMR3GetU8(pSSM, &u8Dummy);
     1199        SSMR3GetU8(pSSM, &u8Proto);
    11961200        SSMR3GetU8(pSSM, &u8Dummy);
    11971201        SSMR3GetS32(pSSM, &i32Dummy);
     
    12131217        if (version_id == 4)
    12141218            SSMR3GetU8(pSSM, &u8Dummy);
     1219
     1220        PS2MFixupState(&s->Aux, u8State, u8Rate, u8Proto);
    12151221    }
    12161222#endif
  • trunk/src/VBox/Devices/Input/PS2Dev.h

    r49469 r54240  
    6868void PS2MSaveState(PPS2M pThis, PSSMHANDLE pSSM);
    6969int  PS2MLoadState(PPS2M pThis, PSSMHANDLE pSSM, uint32_t uVersion);
     70void PS2MFixupState(PPS2M pThis, uint8_t u8State, uint8_t u8Rate, uint8_t u8Proto);
    7071
    7172PS2M *KBDGetPS2MFromDevIns(PPDMDEVINS pDevIns);
  • trunk/src/VBox/Devices/Input/PS2M.cpp

    r53322 r54240  
     1/* $Id$ */
    12/** @file
    23 * PS2M - PS/2 auxiliary device (mouse) emulation.
     
    125126#define ACMD_SET_SAMP_RATE  0xF3    /* Set sampling rate. */
    126127#define ACMD_ENABLE         0xF4    /* Enable (streaming mode). */
    127 #define ACMD_DFLT_DISABLE   0xF5    /* Disable and set defaults. */
     128#define ACMD_DISABLE        0xF5    /* Disable (streaming mode). */
    128129#define ACMD_SET_DEFAULT    0xF6    /* Set defaults. */
    129130#define ACMD_INVALID_4      0xF7
     
    239240    /** Accumulated button presses. */
    240241    uint32_t            fAccumB;
     242    /** Instantaneous button data. */
     243    uint32_t            fCurrB;
    241244    /** Throttling delay in milliseconds. */
    242245    unsigned            uThrottleDelay;
    243 #if HC_ARCH_BITS == 32
    244     uint32_t            Alignment0;
    245 #endif
    246246
    247247    /** The device critical section protecting everything - R3 Ptr */
     
    466466    /* Event queue, eccumulators, and button status bits are cleared. */
    467467    ps2kClearQueue((GeneriQ *)&pThis->evtQ);
    468     pThis->iAccumX = pThis->iAccumY = pThis->iAccumZ = pThis->fAccumB = 0;
     468    pThis->iAccumX = pThis->iAccumY = pThis->iAccumZ = pThis->fAccumB = pThis->fCurrB = 0;
    469469}
    470470
     
    506506}
    507507
     508/* Three-button event mask. */
     509#define PS2M_STD_BTN_MASK   (RT_BIT(0) | RT_BIT(1) | RT_BIT(2))
     510
     511/* Report accumulated movement and button presses, then clear the accumulators. */
     512static void ps2mReportAccumulatedEvents(PPS2M pThis, GeneriQ *pQueue, bool fAccumBtns)
     513{
     514    uint32_t    fBtnState = fAccumBtns ? pThis->fAccumB : pThis->fCurrB;
     515    uint8_t     val;
     516    int         dX, dY, dZ;
     517
     518    /* Clamp the accumulated delta values to the allowed range. */
     519    dX = RT_MIN(RT_MAX(pThis->iAccumX, -256), 255);
     520    dY = RT_MIN(RT_MAX(pThis->iAccumY, -256), 255);
     521    dZ = RT_MIN(RT_MAX(pThis->iAccumZ, -8), 7);
     522
     523    /* Start with the sync bit and buttons 1-3. */
     524    val = RT_BIT(3) | (fBtnState & PS2M_STD_BTN_MASK);
     525    /* Set the X/Y sign bits. */
     526    if (dX < 0)
     527        val |= RT_BIT(4);
     528    if (dY < 0)
     529        val |= RT_BIT(5);
     530
     531    /* Send the standard 3-byte packet (always the same). */
     532    ps2kInsertQueue(pQueue, val);
     533    ps2kInsertQueue(pQueue, dX);
     534    ps2kInsertQueue(pQueue, dY);
     535
     536    /* Add fourth byte if extended protocol is in use. */
     537    if (pThis->enmProtocol > PS2M_PROTO_PS2STD)
     538    {
     539        if (pThis->enmProtocol == PS2M_PROTO_IMPS2)
     540            ps2kInsertQueue(pQueue, dZ);
     541        else
     542        {
     543            Assert(pThis->enmProtocol == PS2M_PROTO_IMEX);
     544            /* Z value uses 4 bits; buttons 4/5 in bits 4 and 5. */
     545            val  = dZ & 0x0f;
     546            val |= (fBtnState << 1) & (RT_BIT(4) | RT_BIT(5));
     547            ps2kInsertQueue(pQueue, dZ);
     548        }
     549    }
     550
     551    /* Clear the movement accumulators. */
     552    pThis->iAccumX = pThis->iAccumY = pThis->iAccumZ = 0;
     553    /* Clear accumulated button state only when it's being used. */
     554    if (fAccumBtns)
     555        pThis->fAccumB = 0;
     556}
     557
     558
    508559/**
    509560 * Receive and process a byte sent by the keyboard controller.
     
    572623            pThis->u8CurrCmd = 0;
    573624            break;
     625        case ACMD_READ_REMOTE:
     626            ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
     627            ps2mReportAccumulatedEvents(pThis, (GeneriQ *)&pThis->cmdQ, false);
     628            pThis->u8CurrCmd = 0;
     629            break;
    574630        case ACMD_RESET_WRAP:
    575631            pThis->enmMode = AUX_MODE_STD;
     
    605661            pThis->u8CurrCmd = 0;
    606662            break;
    607         case ACMD_DFLT_DISABLE:
    608             ps2mSetDefaults(pThis);
     663        case ACMD_DISABLE:
     664            pThis->u8State &= ~AUX_STATE_ENABLED;
    609665            ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
    610666            pThis->u8CurrCmd = 0;
     
    716772#ifdef IN_RING3
    717773
    718 /* Three-button event mask. */
    719 #define PS2M_STD_BTN_MASK   (RT_BIT(0) | RT_BIT(1) | RT_BIT(2))
    720 
    721 /* Report accumulated movement and button presses, then clear the accumulators. */
    722 static void ps2mReportAccumulatedEvents(PPS2M pThis)
    723 {
    724     uint8_t     val;
    725     int8_t      dX, dY, dZ;
    726 
    727     /* Clamp the accumulated delta values to the allowed range. */
    728     dX = RT_MIN(RT_MAX(pThis->iAccumX, -256), 255);
    729     dY = RT_MIN(RT_MAX(pThis->iAccumY, -256), 255);
    730     dZ = RT_MIN(RT_MAX(pThis->iAccumZ, -8), 7);
    731 
    732     /* Start with the sync bit and buttons 1-3. */
    733     val = RT_BIT(3) | (pThis->fAccumB & PS2M_STD_BTN_MASK);
    734     /* Set the X/Y sign bits. */
    735     if (dX < 0)
    736         val |= RT_BIT(4);
    737     if (dY < 0)
    738         val |= RT_BIT(5);
    739 
    740     /* Send the standard 3-byte packet (always the same). */
    741     ps2kInsertQueue((GeneriQ *)&pThis->evtQ, val);
    742     ps2kInsertQueue((GeneriQ *)&pThis->evtQ, dX);
    743     ps2kInsertQueue((GeneriQ *)&pThis->evtQ, dY);
    744 
    745     /* Add fourth byte if extended protocol is in use. */
    746     if (pThis->enmProtocol > PS2M_PROTO_PS2STD)
    747     {
    748         if (pThis->enmProtocol == PS2M_PROTO_IMPS2)
    749             ps2kInsertQueue((GeneriQ *)&pThis->evtQ, dZ);
    750         else
    751         {
    752             Assert(pThis->enmProtocol == PS2M_PROTO_IMEX);
    753             /* Z value uses 4 bits; buttons 4/5 in bits 4 and 5. */
    754             val  = dZ & 0x0f;
    755             val |= (pThis->fAccumB << 1) & (RT_BIT(4) | RT_BIT(5));
    756             ps2kInsertQueue((GeneriQ *)&pThis->evtQ, dZ);
    757         }
    758     }
    759 
    760     /* Clear the accumulators. */
    761     pThis->iAccumX = pThis->iAccumY = pThis->iAccumZ = pThis->fAccumB = 0;
    762 
    763     /* Poke the KBC to update its state. */
    764     KBCUpdateInterrupts(pThis->pParent);
    765 }
    766 
    767774/* Event rate throttling timer to emulate the auxiliary device sampling rate.
    768775 */
     
    786793#endif
    787794    {
    788         ps2mReportAccumulatedEvents(pThis);
     795        /* Report accumulated data, poke the KBC, and start the timer. */
     796        ps2mReportAccumulatedEvents(pThis, (GeneriQ *)&pThis->evtQ, true);
     797        KBCUpdateInterrupts(pThis->pParent);
    789798        TMTimerSetMillies(pThis->CTX_SUFF(pThrottleTimer), pThis->uThrottleDelay);
    790799    }
     
    880889    pThis->iAccumY += dy;
    881890    pThis->iAccumZ += dz;
    882     pThis->fAccumB |= fButtons & PS2M_STD_BTN_MASK; //@todo: accumulate based on current protocol?
     891    pThis->fAccumB |= fButtons;     //@todo: accumulate based on current protocol?
     892    pThis->fCurrB   = fButtons;
    883893
    884894#if 1
     
    886896    if (!pThis->fThrottleActive)
    887897    {
    888         ps2mReportAccumulatedEvents(pThis);
     898        ps2mReportAccumulatedEvents(pThis, (GeneriQ *)&pThis->evtQ, true);
     899        KBCUpdateInterrupts(pThis->pParent);
    889900        pThis->fThrottleActive = true;
    890901        TMTimerSetMillies(pThis->CTX_SUFF(pThrottleTimer), pThis->uThrottleDelay);
     
    10651076    ps2mSetRate(pThis, pThis->u8SampleRate);
    10661077
    1067     //@todo: Is this the right place/logic?
    10681078    ps2mSetDriverState(pThis, !!(pThis->u8State & AUX_STATE_ENABLED));
    10691079
    10701080    return rc;
     1081}
     1082
     1083void PS2MFixupState(PPS2M pThis, uint8_t u8State, uint8_t u8Rate, uint8_t u8Proto)
     1084{
     1085    LogFlowFunc(("Fixing up old PS2M state version\n"));
     1086
     1087    /* Load the basic auxiliary device state. */
     1088    pThis->u8State      = u8State;
     1089    pThis->u8SampleRate = u8Rate;
     1090    pThis->enmProtocol  = (PS2M_PROTO)u8Proto;
     1091
     1092    /* Recalculate the throttling delay. */
     1093    ps2mSetRate(pThis, pThis->u8SampleRate);
     1094
     1095    ps2mSetDriverState(pThis, !!(pThis->u8State & AUX_STATE_ENABLED));
    10711096}
    10721097
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