Page 1 of 1
Using Keyboard in OS
Posted: Sun Nov 04, 2001 4:57 am
by HRR
I have written a kernel in C which can display text. How can I use kayboard in my Kernel ? I also want help about how to port (or duplicate) printf. Please help. I am 15 years old.
Re: Using Keyboard in OS
Posted: Wed Nov 14, 2001 4:25 am
by Ranieri
You can poll port 0x60 and read the character that is currently being pressed or released.
There's plenty of documentation on that floating around, just remember that keyboard scancodes != ASCII.
What you eventually really need to do (considering the wastefulness of busy looping) is build an ISR for interrupt 8 (== IRQ 1).
This handler will get called every time soemthing happens to the keyboard.
Easiest way by far to deal with it is then update an internal memory image of the keyboard to reflect what keys have been pressed/released. THen you can basically treat the keyboard as a memory mapped device in the rest of your OS.
Hope this helps a bit, ranieri
Re: Using Keyboard in OS
Posted: Mon Nov 19, 2001 1:11 am
by hrr
Thanks for your reply. But my kernel is in Protected Mode. How can I use keyboard in protected mode ?
Re: Using Keyboard in OS
Posted: Mon Nov 19, 2001 5:58 pm
by Chris Giese
>I have written a kernel in C which can display text. How can I use kayboard in my Kernel ?
Hook the IRQ 1 keyboard interrupt. IRQ 1 is INT 9 unless
you reprogram the 8259 interrupt controller chips. (You
should reprogram these chips in a pmode OS.)
You _must_ read I/O port 60h after each keyboard interrupt,
or you will not get any more keyboard interrupts.
The value you read from port 60h depends on the key
pressed, key up or down, "scancode set", NumLock state,
phase of the moon, etc. Here are some tables and code:
http://www.execpc.com/~geezer/osd/kbd/index.htm#scan
http://www.execpc.com/~geezer/osd/kbd/kbd.c
>I also want help about how to port (or duplicate) printf.
If you get rid of floating point and locales (e.g. different
languages), then printf() is a lot simpler.
http://www.execpc.com/~geezer/osd/libc/ ... tm#problem
Re: Using Keyboard in OS
Posted: Tue Nov 20, 2001 6:12 am
by hrr
I tried to use the port 0x60. The code was as follows: (It is a part of the main file)
Code: Select all
unsigned char ky,ky1;
ky1=inportb(0x60);
do
{
?ky=inportb(0x60);
}while(ky==ky1);
This code returns the same value of the variable ky whichever key is pressed. Is this code correct ? What modifications should I make so that I can get the scancode of the key pressed ?
Please Help.
Re: Using Keyboard in OS
Posted: Tue Nov 20, 2001 11:00 pm
by hrr
The code now works properly. The problem was with another part of the kernel. :)