Page 1 of 1
Terminal Functions
Posted: Wed Jan 23, 2008 10:12 am
by techn9kotine
Hello all. Following Bkerndev. I made a new source callled terminal.c, it contains the function cls(), and a reboot() function that jumps to asm and reboots the computer. But, I'm not sure how to get the input from the user like.. >reboot, or >cls, using the keybaord function provided. It uses the function "scancode" and directly prints the charactor. How do I get input from that? Thanks in advance.
-Techn9kotine
Posted: Wed Jan 23, 2008 10:20 am
by AJ
Hi,
You need to have some kind of 'command buffer' where you store the input so far. When you receive a '\n' character, you need to compare that command to your command list and run the appropriate function. I tend to do this by having a linked list of command structs, which have a function pointer (points to a function returning an integer and accepting argc and argv parameters).
In order to get this working well, you will need to expand bran's kernel development tutorial with a good memory manager, a strncmp function and some way of nicely separating out the console code (some kind of module interface) as chances are you will eventually want to have this console running as a separate executable.
Cheers,
Adam
Posted: Wed Jan 23, 2008 10:28 am
by techn9kotine
Thanks for the reply. As for the memory manager, im currently implementing that. As for the kernel loading modules, i know how to do that, but i wanted something in the module before i coded to load like that, which is why for now, it's just a source in the kernel. But i'm not sure i understand how to set up a charactor buffer. Would it be something like an array of, say 15, and the scancode would be sent to that, and then the typing/function would start from that, and then it'd be erased? Something like that? or im i totally off.?
Posted: Wed Jan 23, 2008 1:13 pm
by AJ
That sounds about right. You may, of course, want a larger buffer (particularly if some commands accept arguments) but my advice would be to store the ASCII codes rather than the scancodes. When you have a full kernel with window manager and so on, you may want to send both scancode and key code to an application's stdin.
If you are using strncmp and are overwriting your existing buffer, you don't even need to erase the buffer after each command - just wait for enter to be pressed and then strncmp up to the current buffer index.
To give some kind of pseudocode:
Code: Select all
void consoleloop()
{
char mybuffer[0xFF];
int index = 0;
showprompt();
while(1)
{
mybuffer[index] = asciilookup[getscancode()];
if(mybuffer[index] == '\n')
{
mybuffer[index] = 0;
interpret(mybuffer);
index = 0;
showprompt();
}
else
index++;
}
}
Of course, you need some kind of flow control in there for when there is no scancode waiting (or an IRQ based system) and other eventualities, but you get the idea!
Cheers,
Adam