keyboard driver

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.
Post Reply
sancho1980
Member
Member
Posts: 199
Joined: Fri Jul 13, 2007 6:37 am
Location: Stuttgart/Germany
Contact:

keyboard driver

Post 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:
Gizmo
Member
Member
Posts: 41
Joined: Fri Aug 03, 2007 3:41 am

Post 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.
User avatar
jerryleecooper
Member
Member
Posts: 233
Joined: Mon Aug 06, 2007 6:32 pm
Location: Canada

Post 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");
User avatar
t0xic
Member
Member
Posts: 216
Joined: Sat May 05, 2007 3:16 pm
Location: VA
Contact:

Post 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
Post Reply