konniskatt wrote:I've made it work, I don't know what I did. But the leds on the keyboard still don't work. My question now is: how can I use the modifier keys? (Control, Shift, Alt, Altgr, Function key...)
No offense intended, however, if you are asking this, you still don't understand how you communicate with a keyboard.
The keyboard has absolutely no idea what a "modifier" key is. i.e.: It hasn't a clue what a "shift" key, "ctrl" key, or any other key is, other than it has a "make" code and a "break" code for each key on that keyboard. Period.
Your PS2 driver should simply "monitor" the PS2 port(s) receiving and sending bytes as needed. Nothing more. When a byte is ready to be received from the PS2 hardware, your driver places it in the next position of a FIFO buffer, probably about 64 bytes in size, but can be smaller, or much larger. The same driver monitors a similar buffer and when it receives a byte, your PS2 driver sends it to the controller at the next available instance. That's it. It does nothing more.
You should then have another driver that monitors that 64-byte FIFO buffer. When a byte is placed in it by the PS2 driver, this driver (say a keyboard driver) checks to see if there is a valid make or break code existing in this buffer. If so, it removes it from the buffer and then does some task specific to the make or break code. If this make code is the make code for the Shift key, you then set a flag that the Shift key is down. Then, every other make code that is found, needs to check with this flag to see if you "received" a capital "A" or a small case "a", for example. When the break code for the shift key is found, clear the flag. Same goes for all other "modifier" keys.
Now, there are a few other things you need to know. These make/break codes can be different values for different keyboards. This is why a lookup table was mentioned in a previous post. Once you figure out which keyboard and its scan code set, you then "call" that particular table.
Also, at times, there can be bogus (or unknown) codes placed in the FIFO buffer. After a certain time (specified by how you decided to do it), simply remove these unknown codes (or even single bytes) from the FIFO buffer or you will eventually fill the buffer.
With this technique, the keyboard can be attached via any interface: PS2, AT, USB, whatever, as long as it simply fills a FIFO buffer. The keyboard buffer (you probably ought to call it something else) will simply monitor the FIFO buffer with absolutely no clue to the interface (PS2, AT, or USB). This way, you can have multiple keyboards attached using multiple interfaces.
Also, when this "keyboard driver" (named something else) see's that a Caps Lock make/break has been received, it should send some kind of message to all keyboards so that each keyboard attached sets the LED for that operation, if it has one.
For example, what if I have a keyboard that does not have the normal numbers on the right, like some older keyboards? This keyboard could use the PS2 interface. Then I run down to my local supply shop and buy a cheap num-pad only keyboard that happens to be USB. You now have two keyboards attached, each using a different interface, yet you need you OS to see only one input device interface.
Does this make sense?
Ben
P.S. This is explained in detail in Volume Four of my book series.
-
http://www.fysnet.net/osdesign_book_series.htm