voodoo programming on PS/2 mouse and keyboard
Posted: Tue Sep 22, 2020 5:06 pm
At the very beginning I point that my code is working after I swapped mouse initialization with keyboard initialization, and I have no idea why it did not work in first place, I read wiki and couple of related topic and found no answer, but I suspect that might be a problem with mouse and keyboard initialization. Second question is: why mouse is sending second data packet as first?
Currently mouse starts first, then keyboard.
My code:
Currently mouse starts first, then keyboard.
My code:
Code: Select all
void InitMouse()
{
MouseStruct.mouse_data[0] = 0;
MouseStruct.mouse_data[1] = 0;
MouseStruct.mouse_data[2] = 0;
MouseStruct.mouse_X = 0;
MouseStruct.mouse_Y = 0;
MouseStruct.mouse_data_itterator = 1;
WaitFor0x60_0x64Write();
MS_CP = 0xA8;
writePort(PORT_MODE_8, HEX_PORT_NUMBER_KBMS_CP, (void*)&MS_CP);
WaitFor0x60_0x64Write();
MS_CP = 0x20;
writePort(PORT_MODE_8, HEX_PORT_NUMBER_KBMS_CP, (void*)&MS_CP);
WaitFor0x60Read();
readPort(PORT_MODE_8, HEX_PORT_NUMBER_KBMS_DP, (void*)&MouseStruct.status);
MouseStruct.status |=2;
WaitFor0x60_0x64Write();
MS_CP = 0x60;
writePort(PORT_MODE_8, HEX_PORT_NUMBER_KBMS_CP, (void*)&MS_CP);
WaitFor0x60_0x64Write();
writePort(PORT_MODE_8, HEX_PORT_NUMBER_KBMS_DP, (void*)&MouseStruct.status);
WaitFor0x60_0x64Write();
MS_CP = 0xD4;
writePort(PORT_MODE_8, HEX_PORT_NUMBER_KBMS_CP, (void*)&MS_CP);
WaitFor0x60_0x64Write();
MS_DP = 0xF6;
writePort(PORT_MODE_8, HEX_PORT_NUMBER_KBMS_DP, (void*)&MS_DP);
WaitFor0x60_0x64Write();
MS_CP = 0xD4;
writePort(PORT_MODE_8, HEX_PORT_NUMBER_KBMS_CP, (void*)&MS_CP);
WaitFor0x60_0x64Write();
MS_DP = 0xF4;
writePort(PORT_MODE_8, HEX_PORT_NUMBER_KBMS_DP, (void*)&MS_DP);
WaitFor0x60Read();
printf("Mouse ready\n");
}
Code: Select all
void InitKeyboard()
{
readPort(PORT_MODE_8_SLOW, HEX_PORT_NUMBER_KBMS_CP, (void*)&KeyboardStruct.status);
WaitFor0x60_0x64Write();
KB_CP = 0xAE;
writePort(PORT_MODE_8_SLOW, HEX_PORT_NUMBER_KBMS_CP, (void*)&KB_CP);
WaitFor0x60_0x64Write();
KB_CP = 0x20;
writePort(PORT_MODE_8_SLOW, HEX_PORT_NUMBER_KBMS_CP, (void*)&KB_CP);
WaitFor0x60Read();
readPort(PORT_MODE_8_SLOW, HEX_PORT_NUMBER_KBMS_DP, (void*)&KeyboardStruct.status);
KeyboardStruct.status = (KeyboardStruct.status | 1) & ~0x10;
WaitFor0x60_0x64Write();
KB_CP = 0x60;
writePort(PORT_MODE_8_SLOW, HEX_PORT_NUMBER_KBMS_CP, (void*)&KB_CP);
WaitFor0x60_0x64Write();
writePort(PORT_MODE_8_SLOW, HEX_PORT_NUMBER_KBMS_DP, (void*)&KeyboardStruct.status);
WaitFor0x60_0x64Write();
KB_DP = 0xF4;
writePort(PORT_MODE_8_SLOW, HEX_PORT_NUMBER_KBMS_DP, (void*)&KB_DP);
printf("Keyboard ready.\n");
}