Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
I downloaded Bran's tutorial and was modifying it like crazy until it wasn't Bran's tutorial anymore Now I'm working on implementing the shift keys. The keys get detected as being pressed and a debug message prints, but nothing happens when they get released. (The caps lock that just won't turn off...) Here's the relevant part of my KB code:
bool SHIFT_PRESSED = 0;
// ...
unsigned char scancode;
/* Read from the keyboard's data buffer */
scancode = inportb(0x60);
/* If the top bit of the byte we read from the keyboard is
* set, that means that a key has just been released */
if (scancode & 0x80)
{
/* You can use this one to see if the user released the
* shift, alt, or control keys... */
if (scancode == 42 || scancode == 54) //42 and 54 are left/right shift scancodes
{
SHIFT_PRESSED = 0;
puts("debug: Shift released"); //this never gets printed
}
}
if (scancode == 42 || scancode == 54)
{
//then it was shift
SHIFT_PRESSED = 1;
puts("debug: Shift pressed"); //this gets printed
}
else
//normal keypress code - removed from this post for shortness
void keyboard_handler(struct regs *r)
{
unsigned char scancode;
/* Read from the keyboard's data buffer */
scancode = inportb(0x60);
/* If the top bit of the byte we read from the keyboard is
* set, that means that a key has just been released */
if (scancode == (42|0x80) || scancode == (54|0x80))
{
SHIFT_PRESSED = 0;
}
else if (scancode == 42 || scancode == 54)
{
//then it was shift
SHIFT_PRESSED = 1;
}
else
{
/* Here, a key was just pressed. Please note that if you
* hold a key down, you will get repeated key press
* interrupts. */
/* Just to show you how this works, we simply translate
* the keyboard scancode into an ASCII value, and then
* display it to the screen. You can get creative and
* use some flags to see if a shift is pressed and use a
* different layout, or you can add another 128 entries
* to the above layout to correspond to 'shift' being
* held. If shift is held using the larger lookup table,
* you would add 128 to the scancode when you look for it */
if (SHIFT_PRESSED)
{
putch(kbdus_shift[scancode]);
}
else
{
putch(kbdus[scancode]);
}
}
}