Keyboard Handler Problem
-
Matze2002
Keyboard Handler Problem
Hi,
i write a smal OS, and now i try to write a keyboard Handler in PM Mode. The os boots a C File. Here is my function to get keys from user:
char keyb_get_key( void )
{
int this_key = 0x00;
char string[] = {""};
do
{
this_key = inportb(0x60);
if (this_key == 1)
{
write("ESC");
this_key = 0x00;
}
}
while(this_key != 28);
write("ENTER");
}
If a user press ESC on the keyboard the handler write ESC on the Screen. But how can i clear the keyboard buffer.
Matze
i write a smal OS, and now i try to write a keyboard Handler in PM Mode. The os boots a C File. Here is my function to get keys from user:
char keyb_get_key( void )
{
int this_key = 0x00;
char string[] = {""};
do
{
this_key = inportb(0x60);
if (this_key == 1)
{
write("ESC");
this_key = 0x00;
}
}
while(this_key != 28);
write("ENTER");
}
If a user press ESC on the keyboard the handler write ESC on the Screen. But how can i clear the keyboard buffer.
Matze
-
drizzt
Re:Keyboard Handler Problem
There's a good example of a keyboard driver in protected mode in crazybuddha's site.
http://www.crazybuddha.com/keyboard.php
http://www.crazybuddha.com/keyboard.php
-
Tim
Re:Keyboard Handler Problem
Matze2002: You don't have a keyboard buffer. You're just reading in scan codes and discarding them.
BTW: a better way to wait for and read a key is like this:
An even better way is to handle the keyboard interrupt (IRQ 1) and read key presses there; that way, you don't have to constantly check the keyboard (which is what crazybuddha has done).
BTW: a better way to wait for and read a key is like this:
Code: Select all
uint8_t scan;
while (true)
{
/* Wait for a key to be available */
while ((in(0x64) & 1) == 0)
;
scan = in(0x60);
/* Discard key up events */
if (scan & 0x80)
continue;
if (scan > 0 && scan < _countof(keys))
/* Return the character code for this scan code */
return keys[scan].normal;
}-
AlanO
Re:Keyboard Handler Problem
which header files allow you to use either one of those examples? i am using GCC and DJGPP
-
AlanO
Re:Keyboard Handler Problem
also, how do you compile the
char keyb_get_key( void );
example?? it says:
:kernel_c.c: undefined reference to `_inportb'
:kernel_c.c: undefined reference to `_write'
:kernel_c.c: undefined reference to `_write'
):kernel_c.c: undefined reference to `_inportb'
):kernel_c.c: undefined reference to `_write'
):kernel_c.c: undefined reference to `_write'
any ideas???
char keyb_get_key( void );
example?? it says:
:kernel_c.c: undefined reference to `_inportb'
:kernel_c.c: undefined reference to `_write'
:kernel_c.c: undefined reference to `_write'
):kernel_c.c: undefined reference to `_inportb'
):kernel_c.c: undefined reference to `_write'
):kernel_c.c: undefined reference to `_write'
any ideas???
-
Tim
Re:Keyboard Handler Problem
Since you're writing your own OS, you need to implement all these functions.
For the above:
For the above:
- inportb: reads an 8-bit value from an I/O port using the in instruction
- write: writes a string to the screen
-
AlanO
Re:Keyboard Handler Problem
okay i got an write to the screen function, but i don't understand the other one, any examples?
-
Schol-R-LEA
Re:Keyboard Handler Problem
The inportb() function is little more than a wrapper around the assembly language instruction,
IN AL, portnumber
which is used to read data from I/O ports.
"OSDEV Guide#3: I/O Access using Inline Assembly" gives a good explanation of how it can be implemented using gcc.
IN AL, portnumber
which is used to read data from I/O ports.
"OSDEV Guide#3: I/O Access using Inline Assembly" gives a good explanation of how it can be implemented using gcc.
-
AlanO
Re:Keyboard Handler Problem
okay that did help a bit, but i decided to rewrite it completly. Is there any good examples of a working C (or using ASM file linked to C) keyboard handlers? Just something to allow user to type, save into variable, allow os to compare variable?
Thanks in advanced
Thanks in advanced