OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Apr 25, 2024 10:07 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 58 posts ]  Go to page Previous  1, 2, 3, 4  Next
Author Message
 Post subject: Re:Keyboard
PostPosted: Tue Aug 03, 2004 3:26 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 2:31 am
Posts: 5964
Location: In a galaxy, far, far away
that strongly depend on what you want your keyboard code to do. You should at least read the scancode on port 0x60 and acknowledge the IRQ.

Most OSes then use the scancode either to update the keydriver's internal status (e.g. is SHIFT up or down ?) or use the current status and the received scancode to generate a character that will be enqueued in some buffer for later use.

that 'translation' process depends much on how you'd like your character to be encoded (UTF, ASCII ...) and of your keyboard's map (which letter is on which key)

_________________
Image May the source be with you.


Top
 Profile  
 
 Post subject: Re:Keyboard
PostPosted: Sat Aug 07, 2004 12:49 am 
Do you use inb to read from port 0x60?


Top
  
 
 Post subject: Re:Keyboard
PostPosted: Sat Aug 07, 2004 4:50 am 
Quote:
Do you use inb to read from port 0x60?

Yes..
Example:
Code:
c=inb(0x60);

C contains the value...


Top
  
 
 Post subject: Re:Keyboard
PostPosted: Mon Aug 09, 2004 12:03 am 
I did that in and printed the result in an infinent loop and it displays weird characters when you press different keys. How do you translate this into normal characters??


Top
  
 
 Post subject: Re:Keyboard
PostPosted: Mon Aug 09, 2004 2:20 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 2:31 am
Posts: 5964
Location: In a galaxy, far, far away
you need to build a translation table (which is dependent of your country settings: you can't use the same table with a us-qwerty keyboard and for a fr-azerty keyboard ...)

http://www.nondot.org/sabre/os/files/HCI/keyboard.txt (at OSRC) has a list of scancodes->key for us-qwerty keyboards.

Using this list, you can easily build

Code:
char lowercase[]="##1234567890-*##qwertyuiop[]" ...
char uppercase[]="##????????????##QWERTYUIOP{}" ...


Probably you'll prefer to have that table for your own keyboard, though :)

_________________
Image May the source be with you.


Top
 Profile  
 
 Post subject: Re:Keyboard
PostPosted: Wed Aug 25, 2004 4:58 am 
OK, I have a table and now I can type characters, but when I press a key, it prints about 20 of that character. How can I fix this??


Top
  
 
 Post subject: Re:Keyboard
PostPosted: Wed Aug 25, 2004 7:04 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 2:31 am
Posts: 5964
Location: In a galaxy, far, far away
normally, the keyboard is allowed to repeat the "make code" according to the system's typematic preference (usually something like "wait 1.5 seconds then repeat the character every .25 second")

now, if you get 20 characters at once, probably you're not listenning to interrupts nor do you check the 8042 status to tell whether a new character has arrived or not.

using something like
Code:
for (;;) {
   char c=inb(60);
   if (!(c&80)) // don't print break codes
      print(scancode[c]);
   }
}

you're code will show the last receive make code until a break code (e.g. key released) is issued ... probably not what you want.

_________________
Image May the source be with you.


Top
 Profile  
 
 Post subject: Re:Keyboard
PostPosted: Wed Aug 25, 2004 5:54 pm 
I used something like this:
Code:
char oldkey;
char key; 
for (;;) {
  oldkey=key;
  key=inb(60);
  if(!(oldkey==key)){
    print(key);
  }
}


Top
  
 
 Post subject: Re:Keyboard
PostPosted: Wed Aug 25, 2004 6:31 pm 
What you probably want to do is have interrupts. Specifically, in protected mode this involves setting an IDT (interrupt descriptor table, see intel manuals or osdever.net or something), setting the relevant interrupts to point to a handler written in assembler, which then calls your c-code when the interrupt occurs.

The assembler part should save all the general purpose registers, setup whatever your C-code needs from it's environment (probably at least a stack) and call the C-code, then restore the general purpose registers when the C-code returns, and IRET so that the code that was running starts executing again. Finally, at some point before executing IRET, you want to tell PIC that you have handled the interrupt (and the slave-PIC too, if the IRQ was from the 8-15 range).

If you really want to avoid this, you can ask keyboard whether there are new characters, but I don't remember how to do this since the interrupt-method is what (almost) everyone needs to use sooner or later anyway.


Top
  
 
 Post subject: Re:Keyboard
PostPosted: Thu Aug 26, 2004 1:51 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 2:31 am
Posts: 5964
Location: In a galaxy, far, far away
jka913 wrote:
I used something like this:


This is a bit better since you can type things. But still it will make the system barely useable for text (or even command line) editting since you cannot wipe a whole line using a single long 'backspace' keystroke.

Honestly, you should investigate for interrupts support. Now if you're not willing to, you should poll the status register of the 8042 (e.g. inb(0x64), bit 1 should be set if you have new data)

Please note that i'm not sure at that bit to check since my beloved OSRC is down atm.

_________________
Image May the source be with you.


Top
 Profile  
 
 Post subject: Re:Keyboard
PostPosted: Thu Aug 26, 2004 6:00 am 
It almost works!!!
the only problem is that when some keys are pressed, two characters appear. For example, when the space bar s pressed, it prints a space and then a capital letter P. How can I limit the variable to one character?

[glow=red,2,300]Stephen[/glow] :)


Top
  
 
 Post subject: Re:Keyboard
PostPosted: Thu Aug 26, 2004 8:34 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 2:31 am
Posts: 5964
Location: In a galaxy, far, far away
hmm, that may be due to some escape-codes issued by some "special keys". If you still have an old keyboard picture somewhere, there were 'normal' keys and 'grey' keys (that are not part of the initial scancode set) like F9-F12. Those keys are usually prefixed with a '0xE0' scancode. I'm unsure if this is the reason why your spacebar displays a 'P', but it might be a hint.

_________________
Image May the source be with you.


Top
 Profile  
 
 Post subject: Re:Keyboard
PostPosted: Thu Aug 26, 2004 8:37 am 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 11:33 pm
Posts: 3882
Location: Eindhoven
I think it might be due to not detecting bad transfers by some bits set in the register, so a break can be viewed as a break for some other key instead.


Top
 Profile  
 
 Post subject: Re:Keyboard
PostPosted: Sat Aug 28, 2004 6:10 am 
These extra characters only occur when a key is released, so when you press and hold a key, they do not appear until you let go. Are these break-codes?

Do you need to use interupts to repeat characters? How do you do that????

[glow=green,2,300]Stephen[/glow] :)


Top
  
 
 Post subject: Re:Keyboard
PostPosted: Sat Aug 28, 2004 9:31 am 
Quote:
These extra characters only occur when a key is released, so when you press and hold a key, they do not appear until you let go. Are these break-codes?
The reason your getting two characters of the same letter is because your printing out the make and break codes.

What you want to do is use the makecode to print out the character being pressed and use the breakcode for controlling the repeat of the keys.

Quote:
Do you need to use interupts to repeat characters? How do you do that????
No. but you need to send an EOI (End of Interupt) to the PIC in your ASM handler so that your can continue to read from port 0x60.

Hope this helps.


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 58 posts ]  Go to page Previous  1, 2, 3, 4  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: deblokc, DotBot [Bot], RayanMargham, SemrushBot [Bot] and 234 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group