I am trying to make an os in c and assembly in 32-bits protected mode. I am trying to create a scanf() type function which gets the keyboard input until the enter button is pressed. I have a basic keyboard IRQ handler setup which prints anything typed and i want to implement a scanf() function but i have problems to return the value from the keyboard Handler to the main kernel.
Heres the code for the keyboard handler.
unsigned int shift_key = 0;
unsigned int caps_key = 0;
int counter = 0;
char *sbuf;
int scan = 1;
void keyboard_handler(registers_t regs)
{
// monitor_write("handler called");
unsigned char scancode;
scancode = get_scancode();
if(scancode == 0x2A )
{
shift_key = 1;//Shift key is pressed
//monitor_write("Shift + ");
}
else if(scancode == 0xAA)
{
shift_key= 0;//Shift Key is not pressed
// monitor_write("Unshift");
}
else if(scancode == 0x3A && caps_key == 1)
{
caps_key = 0;//Caps key is pressed
// monitor_write("Shift + ");
}
else if(scancode == 0x3A && caps_key == 0)
{
caps_key = 1;//Caps key is pressed
// monitor_write("Shift + ");
}
//Left arrow
else if(scancode == 0x4B)
{
move_cursor_LR(1,0);
}
//right Arrow
else if(scancode == 0x4D)
{
move_cursor_LR(0,1);
}
else
{
if (shift_key == 1 && caps_key == 0)
{
// int shiftaltctrl = 1;//Put anything to see what special keys were pressed
monitor_put(Kkbdus[scancode]);
if (scan == 1 && Kkbdus[scancode] != '\n')
{
sbuf[counter] = Kkbdus[scancode];
counter++ ;
}
}
if (caps_key == 1 && shift_key == 0)
{
// int shiftaltctrl = 1;//Put anything to see what special keys were pressed
monitor_put(Kkbdus[scancode]);
if (scan == 1 && Kkbdus[scancode] != '\n')
{
sbuf[counter] = Kkbdus[scancode] ;
counter++ ;
}
}
if(shift_key == 0 && caps_key == 0)
{
monitor_put(kbdus[scancode]); //Prints the character which was pressed
if (scan == 1 && kbdus[scancode] != '\n')
{
sbuf[counter] = kbdus[scancode];
counter++ ;
}
}
if( caps_key == 1 && shift_key == 1)
{
monitor_put(kbdus[scancode]);
if (scan == 1 && kbdus[scancode] != '\n')
{
sbuf[counter] = kbdus[scancode];
counter++ ;
}
}
if(scan == 1 && kbdus[scancode] == '\n')
{
scan = 0;
sbuf[0] = '\0';
}
if(kbdus[scancode] == '\t')
{
monitor_write(sbuf);
}
}
}
I am using the scan variable as a bool to put the chars in an array when the irq is called. but i cant get a way to return it to the main file from which i call it.