Page 1 of 1

keyboard input not working

Posted: Fri Sep 01, 2006 7:43 pm
by piranha
Hi,

I have my kernel so it can get input one char at a time, but when I use my homemade gets function, the screen displays weird colors and text. can you help?

here is the code:
char getch()
{
char ch = '\0';
do
{
ch = kbdus[inportb(0x60)];
}while (ch == '\0');
putch(ch);
if(ch == '\r')
{
return '\r';
}
else if (ch == '\n')
{
return '\r';
}
else
{
return ch;
}
}

char gets(char *inp)
{
char c[128];
int cc = 0;
do
{
c[cc] = getch();
cc++;
}while( c[cc - 1] != '\n');
inp = c;
return c[0];
}
Thanks!!

Re:keyboard input not working!!!!!

Posted: Fri Sep 01, 2006 8:19 pm
by GLneo
first i dont see the need for these lines:

Code: Select all

if(ch == '\r')
   {
      return '\r';
   }
next, as far as i know port 0x60 does not reset to '\0', so what will happen is if you push a key your handler will get that key over and over... so try this:

Code: Select all

volatile int int01_flag = 0;
while(int01_flag == 0)
hlt();
   ch = kbdus[inportb(0x60)];
int01_flag = 0;
insted of

Code: Select all

do
   {
   ch = kbdus[inportb(0x60)];
   }while (ch == '\0');
o and at an interupt run this:

Code: Select all

void int01_handler()
{
    int01_flag = 0;
}
put it all together and you get this:

Code: Select all

volatile int int01_flag = 0;
char ch = '\0';

char getch()
{
     
     while(int01_flag == 0)
         hlt();
     ch = kbdus[ inportb(0x60) ];
     int01_flag = 0;
     putch( ch );
     else if ( ch == '\n' )
         return '\r';
     else
         return ch;
}

char gets(char *inp)
{
   char c[128];
   int cc = 0;
   do
   {
      c[cc] = getch();
      cc++;
   }while( c[cc - 1] != '\n');
   inp = c;
   return c;
}

void int01_handler()
{
    int01_flag = 1;
}
hope that helps :)

Re:keyboard input not working!!!!!

Posted: Fri Sep 01, 2006 8:41 pm
by piranha
Thanks, but when I compile, the output says 'undefined reference to 'hlt()'
what is that?

Re:keyboard input not working!!!!!

Posted: Fri Sep 01, 2006 9:03 pm
by GLneo
the function hlt() halts the cpu (so it can cool down when not needed):

Code: Select all

inline void hlt()
{
    asm volatile("hlt");
}
o and do you have int01_handler() hooked to your INT service handler?

Re:keyboard input not working!!!!!

Posted: Fri Sep 01, 2006 11:47 pm
by piranha
thanks, that works.