Changeset 54240 in vbox
- Timestamp:
- Feb 17, 2015 3:37:46 PM (10 years ago)
- Location:
- trunk/src/VBox/Devices/Input
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Input/DevPS2.cpp
r53055 r54240 1188 1188 { 1189 1189 int32_t i32Dummy; 1190 uint8_t u8State; 1191 uint8_t u8Rate; 1192 uint8_t u8Proto; 1193 1190 1194 SSMR3GetU32(pSSM, &u32Dummy); 1195 SSMR3GetU8(pSSM, &u8State); 1191 1196 SSMR3GetU8(pSSM, &u8Dummy); 1197 SSMR3GetU8(pSSM, &u8Rate); 1192 1198 SSMR3GetU8(pSSM, &u8Dummy); 1193 SSMR3GetU8(pSSM, &u8Dummy); 1194 SSMR3GetU8(pSSM, &u8Dummy); 1195 SSMR3GetU8(pSSM, &u8Dummy); 1199 SSMR3GetU8(pSSM, &u8Proto); 1196 1200 SSMR3GetU8(pSSM, &u8Dummy); 1197 1201 SSMR3GetS32(pSSM, &i32Dummy); … … 1213 1217 if (version_id == 4) 1214 1218 SSMR3GetU8(pSSM, &u8Dummy); 1219 1220 PS2MFixupState(&s->Aux, u8State, u8Rate, u8Proto); 1215 1221 } 1216 1222 #endif -
trunk/src/VBox/Devices/Input/PS2Dev.h
r49469 r54240 68 68 void PS2MSaveState(PPS2M pThis, PSSMHANDLE pSSM); 69 69 int PS2MLoadState(PPS2M pThis, PSSMHANDLE pSSM, uint32_t uVersion); 70 void PS2MFixupState(PPS2M pThis, uint8_t u8State, uint8_t u8Rate, uint8_t u8Proto); 70 71 71 72 PS2M *KBDGetPS2MFromDevIns(PPDMDEVINS pDevIns); -
trunk/src/VBox/Devices/Input/PS2M.cpp
r53322 r54240 1 /* $Id$ */ 1 2 /** @file 2 3 * PS2M - PS/2 auxiliary device (mouse) emulation. … … 125 126 #define ACMD_SET_SAMP_RATE 0xF3 /* Set sampling rate. */ 126 127 #define ACMD_ENABLE 0xF4 /* Enable (streaming mode). */ 127 #define ACMD_D FLT_DISABLE 0xF5 /* Disable and set defaults. */128 #define ACMD_DISABLE 0xF5 /* Disable (streaming mode). */ 128 129 #define ACMD_SET_DEFAULT 0xF6 /* Set defaults. */ 129 130 #define ACMD_INVALID_4 0xF7 … … 239 240 /** Accumulated button presses. */ 240 241 uint32_t fAccumB; 242 /** Instantaneous button data. */ 243 uint32_t fCurrB; 241 244 /** Throttling delay in milliseconds. */ 242 245 unsigned uThrottleDelay; 243 #if HC_ARCH_BITS == 32244 uint32_t Alignment0;245 #endif246 246 247 247 /** The device critical section protecting everything - R3 Ptr */ … … 466 466 /* Event queue, eccumulators, and button status bits are cleared. */ 467 467 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; 469 469 } 470 470 … … 506 506 } 507 507 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. */ 512 static 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 508 559 /** 509 560 * Receive and process a byte sent by the keyboard controller. … … 572 623 pThis->u8CurrCmd = 0; 573 624 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; 574 630 case ACMD_RESET_WRAP: 575 631 pThis->enmMode = AUX_MODE_STD; … … 605 661 pThis->u8CurrCmd = 0; 606 662 break; 607 case ACMD_D FLT_DISABLE:608 p s2mSetDefaults(pThis);663 case ACMD_DISABLE: 664 pThis->u8State &= ~AUX_STATE_ENABLED; 609 665 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK); 610 666 pThis->u8CurrCmd = 0; … … 716 772 #ifdef IN_RING3 717 773 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 else751 {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 767 774 /* Event rate throttling timer to emulate the auxiliary device sampling rate. 768 775 */ … … 786 793 #endif 787 794 { 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); 789 798 TMTimerSetMillies(pThis->CTX_SUFF(pThrottleTimer), pThis->uThrottleDelay); 790 799 } … … 880 889 pThis->iAccumY += dy; 881 890 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; 883 893 884 894 #if 1 … … 886 896 if (!pThis->fThrottleActive) 887 897 { 888 ps2mReportAccumulatedEvents(pThis); 898 ps2mReportAccumulatedEvents(pThis, (GeneriQ *)&pThis->evtQ, true); 899 KBCUpdateInterrupts(pThis->pParent); 889 900 pThis->fThrottleActive = true; 890 901 TMTimerSetMillies(pThis->CTX_SUFF(pThrottleTimer), pThis->uThrottleDelay); … … 1065 1076 ps2mSetRate(pThis, pThis->u8SampleRate); 1066 1077 1067 //@todo: Is this the right place/logic?1068 1078 ps2mSetDriverState(pThis, !!(pThis->u8State & AUX_STATE_ENABLED)); 1069 1079 1070 1080 return rc; 1081 } 1082 1083 void 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)); 1071 1096 } 1072 1097
Note:
See TracChangeset
for help on using the changeset viewer.