Page 1 of 1

YAHOO!! Keyboard driver is working! lol

Posted: Mon Sep 23, 2002 9:36 pm
by gtsphere
;D ;D ;D
hey! well, i finally got it working and i wish to thank dronkit and if any moderators read this, give him props or something lol, but yes, it works now.

my problem:
every keyboard driver i had crashed my computer (reboots) but now, after testing and talking and testing, it works great now, at least its a loop which tells me when a key is pressed and released... yahoo! heh, its in differnt colors too! oh yes ;)

solution for people who need help:
everyone keyboard thing tried to enable the interrupts, sti, but i tried it, removed it, changed some of the worlds features, and now it works:

static void KeyboardInterruptHandler()
{
int scanCode; /* Storage for scan code */
register int i; /* Register is desirable */

//enable(); /* Enable CPU interrupts immediately */
/* Substitute 'asm sti;' for enable() if this does not compile */

scanCode = inp(0x60); /* Read the key board scan code */

/* Acknowledge the reading of the scan code to the keyboard controller */
i = inp(0x61); /* Get keyboard control register */
outp(0x61, i | 0x80); /* Toggle acknowledge bit high */
outp(0x61, i); /* Toggle acknowledge bit low */

/* Acknowledge the interrupt to the programmable interrupt controller */
outp(0x20, 0x20); /* Signal non specific end of interrupt */

/* Set the appropriate flags in the state tables */
if (scanCode & 0x80)
   {
keyIsPressed[scanCode & 0x7F] = 0;
      prints("pressed!", WHITE, 4 );
   }
else
   {
keyIsPressed[scanCode] = keyWasPressed[scanCode] = 1;
      prints("RELEASED!", BLUE, 4 );

   }
}

--with these functions for the outp inp:
#define outp(value,port) \
__asm__ ("outb %%al,%%dx"::"a" (value),"d" (port))


#define inp(port) ({ \
unsigned char _v; \
__asm__ volatile ("inb %%dx,%%al":"=a" (_v):"d" (port)); \
_v; \
})


I hope this helps someone else out there! Thank you all on this board, you rock! :D ;D ;D ;D and special thanks to dronkit!
peace, Alan

Re:YAHOO!! Keyboard driver is working! lol

Posted: Mon Sep 23, 2002 9:48 pm
by gtsphere
also now, i believe (and i just tested and its a yes) that we can do if else or a switch upon the scancodes, but now, i found a list of scancodes and its a bit dfiferent than my keyboard, IE;

f6 = 40
f5 = 3f but when i do
if(scanCode & 40)


it displays the conditionaly when i hit F5 not F6... hrm?
Alan

Re:YAHOO!! Keyboard driver is working! lol

Posted: Tue Sep 24, 2002 6:47 am
by dronkit
good for you man, that's the spirit. I'm glad i could be of help. I already got my reward (i'm two-starred now ;))
c ya

Re:YAHOO!! Keyboard driver is working! lol

Posted: Tue Sep 24, 2002 7:33 am
by Pype.Clicker
hmm .. why exactly do you need to re-enable interrupts before the handler is done ? if i remember 8259a architecture, interrupts will remain masked until out 20,20, right ?

Re:YAHOO!! Keyboard driver is working! lol

Posted: Tue Sep 24, 2002 7:43 am
by gtsphere
thats the thing you, you don't! ;D some of the code i've been trying always says "enable" well i didn't and it works heh

go figure!

peace

Re:YAHOO!! Keyboard driver is working! lol

Posted: Tue Sep 24, 2002 1:36 pm
by Tim
Why do you fiddle the bits in port 0x61? Merely reading from port 0x60 acknowledges a scan code; as far as I can tell, port 0x61 isn't used on the AT and above.

Re:YAHOO!! Keyboard driver is working! lol

Posted: Wed Sep 25, 2002 5:25 am
by gtsphere
could you explain a little more?

Re:YAHOO!! Keyboard driver is working! lol

Posted: Wed Oct 09, 2002 2:50 am
by Whatever5k
Why do you fiddle the bits in port 0x61
I've also seen this in Minix - AST seems to use that too...
He sais it's for telling the keyboard controller that we have received the key code...

Re:YAHOO!! Keyboard driver is working! lol

Posted: Mon Oct 14, 2002 9:50 am
by Tim
HelpPC claims that port 0x61 on the 286 and above provides an emulation of some old PC behaviour. Therefore there's no need to use it unless you're targetting the 8086.