keyboard input not working

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
piranha

keyboard input not working

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

Re:keyboard input not working!!!!!

Post 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 :)
piranha

Re:keyboard input not working!!!!!

Post by piranha »

Thanks, but when I compile, the output says 'undefined reference to 'hlt()'
what is that?
GLneo

Re:keyboard input not working!!!!!

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

Re:keyboard input not working!!!!!

Post by piranha »

thanks, that works.
Post Reply