Page 1 of 2
KEYBOARD DRIVER/C QUESTION
Posted: Wed Mar 05, 2003 4:15 pm
by slacker
according to one article i read....there are two codes that can be read from port 0x60. the "make code" is the actual scan code and the "break code" is the code when they key is released. i think the break code can be calculated by "and ing" the make code with 0x80. is this true. also can this be done like this in C:
unsigned make, break;
make=portin(0x60);
break = make & 0x80;
will this work? is this how its done?
thanks for your help people.
Re:KEYBOARD DRIVER/C QUESTION
Posted: Wed Mar 05, 2003 6:07 pm
by Tim
More like:
Code: Select all
raw_data_from_keyboard = portin(0x60);
key_is_down = (raw_data_from_keyboard & 0x80) == 0;
scan_code = raw_data_from_keyboard & ~0x80;
key_is_down is true if the key was just pressed, or false if it was just released.
scan_code is the code of the key, regardless of whether it was pressed or released.
Re:KEYBOARD DRIVER/C QUESTION
Posted: Wed Mar 05, 2003 6:36 pm
by slacker
i thought the scan code was what was read from port 0x60?
key_is_down = (raw_data_from_keyboard & 0x80) == 0;
does this line mean all input from port 0x60 when the key is done is equal to 0?
Re:KEYBOARD DRIVER/C QUESTION
Posted: Wed Mar 05, 2003 6:46 pm
by Tim
The value at port 0x60 consists of 7 bits of scan code and 1 make/break bit. (value & 0x80) tells you whether the top bit is set; convert 0x80 to binary and look at the value. (value & ~0x80) gives you all bits except the top bit; again, work out ~0x80 and convert it to binary. This is basic Boolean algebra.
Re:KEYBOARD DRIVER/C QUESTION
Posted: Wed Mar 05, 2003 7:57 pm
by kemu
what article did you read ?
I want to write keyboard driver cause I'm using an azerty keyboard but I don't know where to start any good articles example code ?
Re:KEYBOARD DRIVER/C QUESTION
Posted: Wed Mar 05, 2003 8:21 pm
by slacker
Tim, anyone,
I also need a site that has info about scan codes, etc
Re:KEYBOARD DRIVER/C QUESTION
Posted: Thu Mar 06, 2003 2:55 am
by DarylD
Google is your friend.
Re:KEYBOARD DRIVER/C QUESTION
Posted: Thu Mar 06, 2003 2:16 pm
by slacker
once the break code is read from 0x60, does reading from 0x60 give you 0x00 ?
Re:KEYBOARD DRIVER/C QUESTION
Posted: Thu Mar 06, 2003 2:34 pm
by Therx
Re:KEYBOARD DRIVER/C QUESTION
Posted: Fri Mar 07, 2003 3:05 pm
by slacker
Tim Robinson wrote:
The value at port 0x60 consists of 7 bits of scan code and 1 make/break bit. (value & 0x80) tells you whether the top bit is set; convert 0x80 to binary and look at the value. (value & ~0x80) gives you all bits except the top bit; again, work out ~0x80 and convert it to binary. This is basic Boolean algebra.
~0x80 will invert the bits!
Re:KEYBOARD DRIVER/C QUESTION
Posted: Fri Mar 07, 2003 3:14 pm
by slacker
what is the value from port 0x60 when no keys are being pressed?
Re:KEYBOARD DRIVER/C QUESTION
Posted: Fri Mar 07, 2003 4:00 pm
by Therx
Simple! 0x00
Re:KEYBOARD DRIVER/C QUESTION
Posted: Sat Mar 08, 2003 5:44 am
by Tim
You can't really rely on this. It's better to only read from port 0x60 when the LSB of port 0x64 is set.
For example:
Code: Select all
while ((in(0x64) & 1) == 0)
;
scan = in(0x60);
Re:KEYBOARD DRIVER/C QUESTION
Posted: Sun Mar 09, 2003 4:11 am
by LOneWoolF
aren't the in and portin function std c functions?
i get undefined references...
can i do sth like this?
Code: Select all
register unsigned int iax __asm__("ax");
unsigned int i_ax;
__asm__("push ax");
unsigned raw_data, key_down, scan_code;
__asm__(
"in ax, 0x60"
);
i_ax = iax;
while((i_ax & 1)==0);
//scan = in(0x60);
__asm__(
"in ax, 0x64"
);
i_ax = iax;
raw_data = i_ax;
key_down = raw_data & 0x80 == 0;
scan_code = raw_data & ~0x80;
__asm__("pop ax");
return scan_code;
return 0;
Re:KEYBOARD DRIVER/C QUESTION
Posted: Sun Mar 09, 2003 5:23 am
by Pype.Clicker
you should really avoid pushes & pops in inline assembly unless you put them in the very same asm statement.
your code seems pretty weird (2 return statements, no function definition ...).
Moreover, there is no reason saving AX on the stack as it is the register used to return values. The compiler will assume it holds the return value anyway