Here is the code:
Code: Select all
void kb_test()
{
char hex[] = "0123456789ABCDEF";
byte temp=0;
puts("\nTHIS WILL TEST FEW COMMANDS OF THE PS/2 KEYBOARD.\n");
puts("\nResetting the keyboard... ");
//while ((inportb(0x64)&2)!=0);
outportb(0x60, 0xFF);
while ((inportb(0x64)&4)==0);
temp = inportb(0x60);
putc_font('[', 0x07, 0x02);
putc_font(hex[temp/16], 0x07, 0x02);
putc_font(hex[temp%16], 0x07, 0x02);
putc_font(']', 0x07, 0x02);
puts("\nEcho... ");
while ((inportb(0x64)&2)!=0);
outportb(0x60, 0xEE);
if (inportb(0x60) == 0xEE) puts_font("[OK] ", 0x07, 0x02);
puts("\nSet LEDs - SCROLL on... ");
while ((inportb(0x64)&2)!=0);
outportb(0x60, 0xED);
while ((inportb(0x64)&2)!=0);
outportb(0x60, 1);
if (inportb(0x60) == 0xFA) puts_font("[ACK] ", 0x07, 0x02);
puts("\nGet current scancode set... ");
while ((inportb(0x64)&2)!=0);
outportb(0x60, 0xF0);
while ((inportb(0x64)&2)!=0);
outportb(0x60, 0);
temp = inportb(0x60);
putc_font('[', 0x07, 0x02);
putc_font(hex[temp/16], 0x07, 0x02);
putc_font(hex[temp%16], 0x07, 0x02);
putc_font(']', 0x07, 0x02);
puts("\nTurning on 2 leds (don't know which ones :P)... ");
while ((inportb(0x64)&2)!=0);
outportb(0x60, 0xED);
while ((inportb(0x64)&2)!=0);
outportb(0x60, (byte)1|2);
if (inportb(0x60) == 0xFA) puts_font("[ACK] ", 0x07, 0x02);
}
I also had trouble with the instruction
while ((inportb(0x64)&2)!=0);
that was commented before starting the BAT test. It was running an infinite loop.
And by the way, the testbed is a COMPAQ, Pentium 2, 400 MHz, 128MB RAM.
The keyboard is a bit buggy, it had some... accidents ... like hot tea all over it. It also gives an error on the POST screen, but I skip that by pressing F1, and it works fine.