Got keyboard input to work now need with some sort of stdin.
Posted: Mon Jan 24, 2011 8:55 pm
Hi everybody, I have finally implemented some sort of simple keyboard driver. Now I am having trouble with implementing some sort of stdin to retrieve what the person has entered kind of like when the user types in the terminal a command, and presses the return key. Here is the screenshot of my first OS in progress below and the source.
Code: Select all
#include "/home/danny/Desktop/io.h" // Includes the io / string handler header
#include "/home/danny/Desktop/kbd_driver.h" // Includes the keyboard driver header
#include "/home/danny/Desktop/drawing.h" // Includes the drawing header file
unsigned char* mem = (unsigned char*)0xb8000;
int index = 0;
unsigned char kbdus[128] =
{
0, 27, '1', '2', '3', '4', '5', '6', '7', '8', /* 9 */
'9', '0', '-', '=', '\b', /* Backspace */
'\t', /* Tab */
'q', 'w', 'e', 'r', /* 19 */
't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', /* Enter key */
0, /* 29 - Control */
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', /* 39 */
'\'', '`', 0, /* Left shift */
'\\', 'z', 'x', 'c', 'v', 'b', 'n', /* 49 */
'm', ',', '.', '/', 0, /* Right shift */
'*',
0, /* Alt */
' ', /* Space bar */
0, /* Caps lock */
0, /* 59 - F1 key ... > */
0, 0, 0, 0, 0, 0, 0, 0,
0, /* < ... F10 */
0, /* 69 - Num lock*/
0, /* Scroll Lock */
0, /* Home key */
0, /* Up Arrow */
0, /* Page Up */
'-',
0, /* Left Arrow */
0,
0, /* Right Arrow */
'+',
0, /* 79 - End key*/
0, /* Down Arrow */
0, /* Page Down */
0, /* Insert Key */
0, /* Delete Key */
0, 0, 0,
0, /* F11 Key */
0, /* F12 Key */
0, /* All other keys are undefined */
};
void kmain(void* mbd , unsigned int magic)
{
move_csr();
clear_screen();
beg:
if (magic != 0x2BADB002)
{
printstring("Error: Invalid Magic Number", 04, 0);
return;
}
else
{
char msg[1000];
unsigned char scancode = inportb(0x60);
while(kbdus[scancode] != '`')
{
printstring("MonsterOS >", 0X0A, 0);
int temp = inportb(0x61);
outportb(0x60,temp | 0x80); /* Disable */
outportb(0x60,temp & 0x7F); /* Re-enable */
scancode = inportb(0x60);
outportb(0x20, 0x20);
putch(kbdus[scancode]);
if (stringcmp(mem, "MonsterOS >cls") == 1)
{
clear_screen();
}
if (kbdus[scancode] == '`')
{
clear_screen();
}
}
goto beg;
}
return;
}