Keyboard translation error
Posted: Mon Feb 19, 2018 5:20 pm
Hi guys. I got one for you.
I jump at the chance to test my code on any machine that someone dares to let me. (Suckers!!). Anyway, I have a chance to use a later model (10 year old) laptop and my keyboard code wasn't working. After some digging, I found out I was receiving Scan Set 1 while expecting Scan Set 2. I went digging some more and I actually think that this keyboard controller (8042?) may be bad and not disabling translation.
To get right down to the bare controller, I ran a test.
Resulting in:
I sent the reset and disable twice, just to be sure. Got ACK back each time.
I sent the Self Test and received 0x55 as expected.
I read the Command Byte to see if translation is enabled--read back 0x65--meaning that it is enabled.
I wrote the byte back, now with bit 6 clear.
Then I read it back to see if the bit actually cleared, and it did--read back 0x25.
Then I write the scan code set I wish to use (2) to the keyboard--Got ACK for both written bytes.
I then read the Command Byte again, just to check--Still 0x25. Translation off.
I then read the current Scan Code Set to see what it reports--Again, got both ACKs and the expected '2'.
I then enabled the keyboard.
Sounds correct, yes? However, I typed "ben" and got the following:
0x30, 0xB0
0x12, 0x92
0x31, 0xB1
Clearly still using Scan Set 1.
I don't know if the keyboard is sending Scan Set 1 and the controller is not converting, or visa-versa, the keyboard is sending Set 2 and the controller *is* translating. Either way, it is in error.
This machine boots to Win Vista just fine, keyboard works. The BIOS uses the correct (either set) settings, since I can type within my loader code, receiving the expected BIOS scan code.
Therefore, the BIOS and Win Vista either assume Set 1, have a way to test for the current set, or my code is just flat out wrong.
Anyway, if anyone has an idea, please let me know.
Edit 0:
Another comment: I set the keyboard to scan set 3, the keyboard ACK okay (0xFA) yet, I still received scan set 1. I set the scan set to 4 and got the expected error code (0xFC). Keyboard is probably working just fine. It is probably the controller translating all code to scan set 1. period. I will do some more digging.
Thanks,
Ben
-- http://www.fysnet.net/blog
I jump at the chance to test my code on any machine that someone dares to let me. (Suckers!!). Anyway, I have a chance to use a later model (10 year old) laptop and my keyboard code wasn't working. After some digging, I found out I was receiving Scan Set 1 while expecting Scan Set 2. I went digging some more and I actually think that this keyboard controller (8042?) may be bad and not disabling translation.
To get right down to the bare controller, I ran a test.
Code: Select all
#define KEYBRD_CMND_60 0x60 // Commands go to the keyboard
#define KEYBRD_CMND_64 0x64 // Commands go to the keyboard controller
// reset and disable.
keyboard_write(KEYBRD_CMND_60, KEY_CMD_RESDIS);
printf("0000: %02X\n", keyboard_read()); // KEYBOARD_ACK
keyboard_write(KEYBRD_CMND_60, KEY_CMD_RESDIS);
printf("1111: %02X\n", keyboard_read()); // KEYBOARD_ACK
keyboard_write(KEYBRD_CMND_64, KEY_CMD_SELFTEST);
printf("2222: %02X\n", keyboard_read()); // 0x55
keyboard_write(KEYBRD_CMND_64, KEY_CMD_READ);
printf("aaaa: %02X\n", byte = keyboard_read()); // 0x65
keyboard_write(KEYBRD_CMND_64, KEY_CMD_WRITE);
keyboard_write(KEYBRD_CMND_60, (byte & ~(1<<6))); // clear translation bit
keyboard_write(KEYBRD_CMND_64, KEY_CMD_READ);
printf("bbbb: %02X\n", keyboard_read()); // 0x25
keyboard_write(KEYBRD_CMND_60, KEY_GETSET_SCAN_CODE);
printf("cccc: %02X\n", keyboard_read()); // KEYBOARD_ACK
keyboard_write(KEYBRD_CMND_60, 2);
printf("dddd: %02X\n", keyboard_read()); // KEYBOARD_ACK
keyboard_write(KEYBRD_CMND_64, KEY_CMD_READ);
printf("eeee: %02X\n", keyboard_read()); // 0x25
keyboard_write(KEYBRD_CMND_60, KEY_GETSET_SCAN_CODE);
printf("ffff: %02X\n", keyboard_read()); // KEYBOARD_ACK
keyboard_write(KEYBRD_CMND_60, 0);
printf("gggg: %02X\n", keyboard_read()); // KEYBOARD_ACK
printf("hhhh: %02X\n", keyboard_read()); // 2
keyboard_write(KEYBRD_CMND_60, KEY_CMD_ENABLE);
printf("iiii: %02X\n", keyboard_read()); // KEYBOARD_ACK
Code: Select all
0000: FA
1111: FA
2222: 55
aaaa: 65
bbbb: 25
cccc: FA
dddd: FA
eeee: 25
ffff: FA
gggg: FA
hhhh: 02
iiii: FA
I sent the Self Test and received 0x55 as expected.
I read the Command Byte to see if translation is enabled--read back 0x65--meaning that it is enabled.
I wrote the byte back, now with bit 6 clear.
Then I read it back to see if the bit actually cleared, and it did--read back 0x25.
Then I write the scan code set I wish to use (2) to the keyboard--Got ACK for both written bytes.
I then read the Command Byte again, just to check--Still 0x25. Translation off.
I then read the current Scan Code Set to see what it reports--Again, got both ACKs and the expected '2'.
I then enabled the keyboard.
Sounds correct, yes? However, I typed "ben" and got the following:
0x30, 0xB0
0x12, 0x92
0x31, 0xB1
Clearly still using Scan Set 1.
I don't know if the keyboard is sending Scan Set 1 and the controller is not converting, or visa-versa, the keyboard is sending Set 2 and the controller *is* translating. Either way, it is in error.
This machine boots to Win Vista just fine, keyboard works. The BIOS uses the correct (either set) settings, since I can type within my loader code, receiving the expected BIOS scan code.
Therefore, the BIOS and Win Vista either assume Set 1, have a way to test for the current set, or my code is just flat out wrong.
Anyway, if anyone has an idea, please let me know.
Edit 0:
Another comment: I set the keyboard to scan set 3, the keyboard ACK okay (0xFA) yet, I still received scan set 1. I set the scan set to 4 and got the expected error code (0xFC). Keyboard is probably working just fine. It is probably the controller translating all code to scan set 1. period. I will do some more digging.
Thanks,
Ben
-- http://www.fysnet.net/blog