Got keyboard input to work now need with some sort of stdin.

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
monsterhunter445
Posts: 20
Joined: Sun Jan 02, 2011 4:46 pm

Got keyboard input to work now need with some sort of stdin.

Post by monsterhunter445 »

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;
}
Attachments
cli.png
cli.png (7.9 KiB) Viewed 950 times
Yargh
Member
Member
Posts: 56
Joined: Sat Jun 12, 2010 9:04 pm
Location: Somewhere else.

Re: Got keyboard input to work now need with some sort of st

Post by Yargh »

It would probably be a better idea to use interrupts rather than polling for the keyboard. As for the stdin question, you could just implement a function similar to getche() which waits for a keyboard irq, adds the key to the buffer, and if enter is pressed then return it.
Wait... What?
monsterhunter445
Posts: 20
Joined: Sun Jan 02, 2011 4:46 pm

Re: Got keyboard input to work now need with some sort of st

Post by monsterhunter445 »

Thanks for the reply, I will take your advice.
Post Reply