YAHOO!! Keyboard driver is working! lol

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.
Post Reply
gtsphere

YAHOO!! Keyboard driver is working! lol

Post 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
gtsphere

Re:YAHOO!! Keyboard driver is working! lol

Post 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
dronkit

Re:YAHOO!! Keyboard driver is working! lol

Post 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
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:YAHOO!! Keyboard driver is working! lol

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

Re:YAHOO!! Keyboard driver is working! lol

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

Re:YAHOO!! Keyboard driver is working! lol

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

Re:YAHOO!! Keyboard driver is working! lol

Post by gtsphere »

could you explain a little more?
Whatever5k

Re:YAHOO!! Keyboard driver is working! lol

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

Re:YAHOO!! Keyboard driver is working! lol

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