KEYBOARD DRIVER/C QUESTION

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.
slacker

KEYBOARD DRIVER/C QUESTION

Post 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.
Tim

Re:KEYBOARD DRIVER/C QUESTION

Post 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.
slacker

Re:KEYBOARD DRIVER/C QUESTION

Post 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?
Tim

Re:KEYBOARD DRIVER/C QUESTION

Post 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.
kemu

Re:KEYBOARD DRIVER/C QUESTION

Post 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 ?
slacker

Re:KEYBOARD DRIVER/C QUESTION

Post by slacker »

Tim, anyone,
I also need a site that has info about scan codes, etc
DarylD

Re:KEYBOARD DRIVER/C QUESTION

Post by DarylD »

Google is your friend.
slacker

Re:KEYBOARD DRIVER/C QUESTION

Post by slacker »

once the break code is read from 0x60, does reading from 0x60 give you 0x00 ?
slacker

Re:KEYBOARD DRIVER/C QUESTION

Post 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!
slacker

Re:KEYBOARD DRIVER/C QUESTION

Post by slacker »

what is the value from port 0x60 when no keys are being pressed?
Therx

Re:KEYBOARD DRIVER/C QUESTION

Post by Therx »

Simple! 0x00
Tim

Re:KEYBOARD DRIVER/C QUESTION

Post 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);
LOneWoolF

Re:KEYBOARD DRIVER/C QUESTION

Post 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;
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:KEYBOARD DRIVER/C QUESTION

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