I am trying to make a getch() function for my os. I know I posted a thread like this some time ago, but I've rewritten my kernel since then and the method wasnt very flexible. Anyway, this is my code:
Code: Select all
//Includes somewhere here
//KBDUS defined here
u32int getch_progress=0;
char new_key;
/* Handles the keyboard interrupt */
void keyboard_handler(registers_t *r)
{
unsigned char scancode;
//Read from port 0x60 for getting input
scancode = inportb(0x60);
//Check if key has been released or pressed
if (scancode & 0x80)
{
//unused for now
}
else
{
//Here, we set getch_process to 1
getch_progress=1;
new_key=kbdus[scancode]);
}
}
/* Installs the keyboard handler into IRQ1 */
void init_keyboard()
{
register_interrupt_handler(IRQ1, keyboard_handler);
}
char getch()
{
getch_progress=0;
if(getch_progress==0)
while(getch_progress==0);
kprintf("getch_progress=%u;\n",ex);
getch_progress = 0;
return new_key;
}
The trouble is, that getch_progress is never equal to 1, and therefore, never exits the loop. The kprintf() in the getch() function is never printed. How come then, that I have set getch_progress to 1 in the keyboard irq handler? I think I know why, that all variables are reset to their original value after the keyboard handler is executed, but does anyone know of a solution to this?
New problem, see below.
Thanks,
t6q4