writing keyboard driver
Posted: Thu Jan 17, 2008 4:53 pm
hi
im trying to write a useful keyboard driver. it works, but only because i ignoed a couple of issues which in a real world situation just cannot be ignored.
i first defined a keyboard structure as follows:
write is a pointer to the next byte in the buffer where a character can be placed
modifier might be something like SHIFT, ALT+SHIFT,etc..I havent yet implemented that
buffer is the actual buffer
next, i implemented a keymap structure as follows:
fnct is a function to be called when the specified scancode is recorded
no_args is the number of dword-arguments passed to the above function
args is then the pointer to the arguments to be passed to the above function, unless no_args = 1, in which case args is the argument itself
my keymap then looks like this:
You can see that for now I am only using the readchar and the enter_pressed functions, which both look like this:
So what I can do is I can type characters and see them echoed on the screen. My characters are also buffered in the keyboard buffer until I press enter, making it potentially possible to get to the stage where I can actually enter commands
But two very important things I dont quite know how to go about:
1) Backspace:
How do you implement this? Suppose I type a key and see the character displayed on the screen. Then I might want to type backspace. It's easy enough to remove that last character from the keyboard buffer, but when removing that character from screen, how can I be sure that the last character just before the cursor is really the last character I typed and not something the os printed out there in the meantime? how would i usually go about this?
2) tabs:
How do you implement them? Again, the problem is with backspacing. How do you remove backspaces? Removing from the buffer is easy, but when removing from the screen, you will have to make sure that the last n bytes before the cursor really belong to your tab.
Can any one give me some directions here?
Thanks
Martin
im trying to write a useful keyboard driver. it works, but only because i ignoed a couple of issues which in a real world situation just cannot be ignored.
i first defined a keyboard structure as follows:
Code: Select all
type keyboard:
record;
write: pointer to byte;
modifier: dword;
buffer: byte[KBD_BUFFER_SIZE];
endrecord;
modifier might be something like SHIFT, ALT+SHIFT,etc..I havent yet implemented that
buffer is the actual buffer
next, i implemented a keymap structure as follows:
Code: Select all
type keymap:
record;
fnct: dword;
no_args: uns32;
args: dword;
endrecord;
no_args is the number of dword-arguments passed to the above function
args is then the pointer to the arguments to be passed to the above function, unless no_args = 1, in which case args is the argument itself
my keymap then looks like this:
Code: Select all
km: keymap[NO_SCANCODES, NO_MODIFIERS]:=
[
keymap:[NULL, 0, NULL], keymap:[NULL, 0, 0],
keymap:[NULL, 0, NULL], keymap:[NULL, 0, 0],
keymap:[NULL, 0, NULL], keymap:[NULL, 0, 0],
keymap:[NULL, 0, NULL], keymap:[NULL, 0, 0],
keymap:[NULL, 0, NULL], keymap:[NULL, 0, 0],
keymap:[NULL, 0, NULL], keymap:[NULL, 0, 0],
keymap:[NULL, 0, NULL], keymap:[NULL, 0, 0],
keymap:[NULL, 0, NULL], keymap:[NULL, 0, 0],
keymap:[NULL, 0, NULL], keymap:[NULL, 0, 0],
keymap:[NULL, 0, NULL], keymap:[NULL, 0, 0],
keymap:[NULL, 0, NULL], keymap:[NULL, 0, 0],
keymap:[NULL, 0, NULL], keymap:[NULL, 0, 0],
keymap:[NULL, 0, NULL], keymap:[NULL, 0, 0],
keymap:[NULL, 0, NULL], keymap:[NULL, 0, 0],
keymap:[NULL, 0, NULL], keymap:[NULL, 0, 0],
keymap:[NULL, 0, NULL], keymap:[NULL, 0, 0],
keymap:[&readchar, 1, (type dword 'q')], keymap:[&readchar, 1, (type dword 'Q')],
keymap:[&readchar, 1, (type dword 'w')], keymap:[&readchar, 1, (type dword 'W')],
keymap:[&readchar, 1, (type dword 'e')], keymap:[&readchar, 1, (type dword 'E')],
keymap:[&readchar, 1, (type dword 'r')], keymap:[&readchar, 1, (type dword 'R')],
keymap:[&readchar, 1, (type dword 't')], keymap:[&readchar, 1, (type dword 'T')],
keymap:[&readchar, 1, (type dword 'z')], keymap:[&readchar, 1, (type dword 'Z')],
keymap:[&readchar, 1, (type dword 'u')], keymap:[&readchar, 1, (type dword 'U')],
keymap:[&readchar, 1, (type dword 'i')], keymap:[&readchar, 1, (type dword 'I')],
keymap:[&readchar, 1, (type dword 'o')], keymap:[&readchar, 1, (type dword 'O')],
keymap:[&readchar, 1, (type dword 'p')], keymap:[&readchar, 1, (type dword 'P')],
keymap:[NULL, 0, NULL], keymap:[NULL, 0, 0],
keymap:[NULL, 0, NULL], keymap:[NULL, 0, 0],
keymap:[&enter_pressed, 0, NULL], keymap:[&enter_pressed, 0, NULL],
keymap:[NULL, 0, NULL], keymap:[NULL, 0, 0],
keymap:[&readchar, 1, (type dword 'a')], keymap:[&readchar, 1, (type dword 'A')],
keymap:[&readchar, 1, (type dword 's')], keymap:[&readchar, 1, (type dword 'S')],
keymap:[&readchar, 1, (type dword 'd')], keymap:[&readchar, 1, (type dword 'D')],
keymap:[&readchar, 1, (type dword 'f')], keymap:[&readchar, 1, (type dword 'F')],
keymap:[&readchar, 1, (type dword 'g')], keymap:[&readchar, 1, (type dword 'G')],
keymap:[&readchar, 1, (type dword 'h')], keymap:[&readchar, 1, (type dword 'H')],
keymap:[&readchar, 1, (type dword 'j')], keymap:[&readchar, 1, (type dword 'J')],
keymap:[&readchar, 1, (type dword 'k')], keymap:[&readchar, 1, (type dword 'K')],
keymap:[&readchar, 1, (type dword 'l')], keymap:[&readchar, 1, (type dword 'L')],
keymap:[NULL, 0, NULL], keymap:[NULL, 0, 0],
keymap:[NULL, 0, NULL], keymap:[NULL, 0, 0],
keymap:[NULL, 0, NULL], keymap:[NULL, 0, 0],
keymap:[NULL, 0, NULL], keymap:[NULL, 0, 0],
keymap:[NULL, 0, NULL], keymap:[NULL, 0, 0],
keymap:[&readchar, 1, (type dword 'y')], keymap:[&readchar, 1, (type dword 'Y')],
keymap:[&readchar, 1, (type dword 'x')], keymap:[&readchar, 1, (type dword 'X')],
keymap:[&readchar, 1, (type dword 'c')], keymap:[&readchar, 1, (type dword 'C')],
keymap:[&readchar, 1, (type dword 'v')], keymap:[&readchar, 1, (type dword 'V')],
keymap:[&readchar, 1, (type dword 'b')], keymap:[&readchar, 1, (type dword 'B')],
keymap:[&readchar, 1, (type dword 'n')], keymap:[&readchar, 1, (type dword 'N')],
keymap:[&readchar, 1, (type dword 'm')], keymap:[&readchar, 1, (type dword 'M')],
keymap:[NULL, 0, NULL], keymap:[NULL, 0, 0],
keymap:[NULL, 0, NULL], keymap:[NULL, 0, 0],
keymap:[NULL, 0, NULL], keymap:[NULL, 0, 0],
keymap:[NULL, 0, NULL], keymap:[NULL, 0, 0],
keymap:[NULL, 0, NULL], keymap:[NULL, 0, 0],
keymap:[NULL, 0, NULL], keymap:[NULL, 0, 0],
keymap:[&readchar, 1, (type dword ' ')], keymap:[&readchar, 1, (type dword ' ')],
];
Code: Select all
procedure readchar(what:dword);
begin readchar;
push(eax);
push(ebx);
pushfd();
if (kbd.write <> NULL) then
mov(kbd.write,eax);
mov(what,ebx);
mov(bl,[eax]);
inc(eax);
if (eax > &kbd.buffer[KBD_BUFFER_SIZE - 1]) then
mov(NULL,eax);
endif;
mov(eax,kbd.write);
putchar(what);
endif;
popfd();
pop(ebx);
pop(eax);
end readchar;
Code: Select all
procedure enter_pressed;
begin enter_pressed;
mov(&kbd.buffer[0],kbd.write);
putchar(LF);
end enter_pressed;
But two very important things I dont quite know how to go about:
1) Backspace:
How do you implement this? Suppose I type a key and see the character displayed on the screen. Then I might want to type backspace. It's easy enough to remove that last character from the keyboard buffer, but when removing that character from screen, how can I be sure that the last character just before the cursor is really the last character I typed and not something the os printed out there in the meantime? how would i usually go about this?
2) tabs:
How do you implement them? Again, the problem is with backspacing. How do you remove backspaces? Removing from the buffer is easy, but when removing from the screen, you will have to make sure that the last n bytes before the cursor really belong to your tab.
Can any one give me some directions here?
Thanks
Martin