Page 2 of 4
Re:Keyboard
Posted: Tue Aug 03, 2004 3:26 am
by Pype.Clicker
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)
Re:Keyboard
Posted: Sat Aug 07, 2004 12:49 am
by srg_13
Do you use inb to read from port 0x60?
Re:Keyboard
Posted: Sat Aug 07, 2004 4:50 am
by DennisCGc
Do you use inb to read from port 0x60?
Yes..
Example:
C contains the value...
Re:Keyboard
Posted: Mon Aug 09, 2004 12:03 am
by srg_13
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??
Re:Keyboard
Posted: Mon Aug 09, 2004 2:20 am
by Pype.Clicker
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: Select all
char lowercase[]="##1234567890-*##qwertyuiop[]" ...
char uppercase[]="##????????????##QWERTYUIOP{}" ...
Probably you'll prefer to have that table for your own keyboard, though
Re:Keyboard
Posted: Wed Aug 25, 2004 4:58 am
by srg_13
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??
Re:Keyboard
Posted: Wed Aug 25, 2004 7:04 am
by Pype.Clicker
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: Select all
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.
Re:Keyboard
Posted: Wed Aug 25, 2004 5:54 pm
by jka913
I used something like this:
Code: Select all
char oldkey;
char key;
for (;;) {
oldkey=key;
key=inb(60);
if(!(oldkey==key)){
print(key);
}
}
Re:Keyboard
Posted: Wed Aug 25, 2004 6:31 pm
by mystran
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.
Re:Keyboard
Posted: Thu Aug 26, 2004 1:51 am
by Pype.Clicker
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.
Re:Keyboard
Posted: Thu Aug 26, 2004 6:00 am
by srg_13
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]
Re:Keyboard
Posted: Thu Aug 26, 2004 8:34 am
by Pype.Clicker
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.
Re:Keyboard
Posted: Thu Aug 26, 2004 8:37 am
by Candy
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.
Re:Keyboard
Posted: Sat Aug 28, 2004 6:10 am
by srg_13
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]
Re:Keyboard
Posted: Sat Aug 28, 2004 9:31 am
by beyondsociety
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.
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.