Page 1 of 1

keyboard driver

Posted: Wed Aug 15, 2007 11:05 am
by sancho1980
hi
i have a question to ask: i have a minimal boot program implementing functions like putchar, putnumber, putstring and so on
i also have a function scrollscreen, so i can output stuff on the screen and everything
now, what im trying to do is implement keyboard functionality..how should i go about? i know i have to convert the scancodes into ascii characters, what i dont really know how to handle is whitespaces
take for example the del key...should i check for this key directly when the scancode is received and erase directly from there the last character immediately before the cursor or should i convert the scan code to an ascii code, pass it on to putchar and have putchar handle the erasure?
this would make sense because, after all, there is a DEL character defined in the ascii table, but on the other hand, ordinary output functions in c dont handle these keys directly either, not that i know of...i guess im just a bit confused and it probably sounds confused...all i want is write a command prompt, so my little kernel starts interacting with the user... :oops:

Posted: Wed Aug 15, 2007 3:45 pm
by Gizmo
You should craft a function that gets a scan code as input and returns ascii.
There are scan code tables available on sites such as wikipedia.org to help you along.
There are ascii codes for white spaces (space is 32, /r/n is 10 13).
When you receive a 13 ascii code you should use a function that scrolls the screen and empties the last line.

You need to program the pic (there are easy tutorials on how this works) and map irq2 (at keyboard) to an interrupt handler number and write the handler to read scan codes.

Your isr (interrupt service routine) for irq2 will take the scan code, use your conversion function, take the ascii code and either put it on screen or handle it accordingly (ie enter key translates into newline (13) and causes the kernel to read the line, take action, and prepare for the next command).

If you want to support really long commands you should make an offscreen keyboard buffer and update the screen with the last 80 charactors so it appears to scroll right when input exceeds line length.

Posted: Wed Aug 15, 2007 4:53 pm
by jerryleecooper
You should make a specific function like manage_delchar(). If you add too much complexity to your putchar function, when you will want for example, put on screen an entire binary file, which will surely contain del characters, things will not be right. For example, in my OS, I have a function that get the scancode, it check to see if it's \b, and if it's the case, calls cmdsol(&console, CON_DELPREV); Any other characters are put in a string and showns on screen eventualy. So if I want to print a DEL character, I just make imprint(&console, "\b");

Posted: Wed Aug 15, 2007 8:48 pm
by t0xic
An easy way to solve this is in your putchar() function:

Code: Select all

if ( cons->cur_y != 0 );	// Not first line
		{
			cons->cur_x--;
			cons->cur_x--;
			where = vga_addr + (cons->cur_y * 160 + cons->cur_x);
			*where = '\0' | att;
		}
So just move your 'x' position back 2 and write and null character in it's place
Hope this helps
--Michael