KEYBOARD DRIVER/C QUESTION
KEYBOARD DRIVER/C QUESTION
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.
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
More like:
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.
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;
scan_code is the code of the key, regardless of whether it was pressed or released.
Re:KEYBOARD DRIVER/C QUESTION
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?
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
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
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 ?
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
Tim, anyone,
I also need a site that has info about scan codes, etc
I also need a site that has info about scan codes, etc
Re:KEYBOARD DRIVER/C QUESTION
once the break code is read from 0x60, does reading from 0x60 give you 0x00 ?
Re:KEYBOARD DRIVER/C QUESTION
~0x80 will invert the bits!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.
Re:KEYBOARD DRIVER/C QUESTION
what is the value from port 0x60 when no keys are being pressed?
Re:KEYBOARD DRIVER/C QUESTION
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:
For example:
Code: Select all
while ((in(0x64) & 1) == 0)
;
scan = in(0x60);
Re:KEYBOARD DRIVER/C QUESTION
aren't the in and portin function std c functions?
i get undefined references...
can i do sth like this?
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;
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:KEYBOARD DRIVER/C QUESTION
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
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