Added very basic interactive shell.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "../include/system.h"
|
||||
#include "../include/shell.h"
|
||||
//http://www.osdever.net/bkerndev/Docs/keyboard.htm
|
||||
/* KBDUS means US Keyboard Layout. This is a scancode table
|
||||
* used to layout a standard US keyboard. I have left some
|
||||
@@ -51,10 +52,15 @@ bool shift = false;
|
||||
void keyboard_handler(struct regs *r)
|
||||
{
|
||||
unsigned char scancode;
|
||||
|
||||
/* Read from the keyboard's data buffer */
|
||||
scancode = inportb(0x60);
|
||||
|
||||
if(scancode == 0x1C)
|
||||
{
|
||||
execmd();
|
||||
return;
|
||||
}
|
||||
|
||||
/* If the top bit of the byte we read from the keyboard is
|
||||
* set, that means that a key has just been released */
|
||||
if (scancode & 0x80)
|
||||
@@ -89,7 +95,8 @@ void keyboard_handler(struct regs *r)
|
||||
{
|
||||
letter = letter - 32;
|
||||
}
|
||||
putch(letter);
|
||||
//putch(letter);
|
||||
key_pressed(letter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+20
@@ -2,6 +2,7 @@
|
||||
#include "../include/gdt.h"
|
||||
#include "../include/idt.h"
|
||||
#include "../include/scrn.h"
|
||||
#include "../include/shell.h"
|
||||
|
||||
unsigned char *memcpy(unsigned char *dest, const unsigned char *src, int count)
|
||||
{
|
||||
@@ -44,6 +45,24 @@ int strlen(const char *str)
|
||||
return retval;
|
||||
}
|
||||
|
||||
bool strcmp(char* str1, char* str2)
|
||||
{
|
||||
int len1 = strlen(str1);
|
||||
int len2 = strlen(str2);
|
||||
|
||||
if(len1 != len2)
|
||||
{
|
||||
puts("Lengths different!\n");
|
||||
return false;
|
||||
}
|
||||
for(int i = len1; i >= 0; i--)
|
||||
{
|
||||
if(str1[i] != str2[i]) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* We will use this later on for reading from the I/O ports to get data
|
||||
* from devices such as the keyboard. We are using what is called
|
||||
* 'inline assembly' in these routines to actually do the work */
|
||||
@@ -87,6 +106,7 @@ void main()
|
||||
kb_install();
|
||||
puts("Keyboard installed.\n");
|
||||
puts("SDOS version 0.0.0.1 initialized.\n");
|
||||
run_shell();
|
||||
//puts(&__BUILD_DATE);
|
||||
//puts(&__BUILD_NUMBER);
|
||||
//puts("Divide by zero check:\n");
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
#include "../include/shell.h"
|
||||
#include "../include/scrn.h"
|
||||
#include "../include/system.h"
|
||||
|
||||
unsigned char* commandbuffer;
|
||||
|
||||
void run_shell()
|
||||
{
|
||||
puts("Starting interactive shell...\n");
|
||||
commandbuffer[0] = '\0';
|
||||
puts("#>");
|
||||
for(;;);
|
||||
}
|
||||
|
||||
void key_pressed(unsigned char* character)
|
||||
{
|
||||
int len = strlen(commandbuffer);
|
||||
commandbuffer[len] = character;
|
||||
commandbuffer[len + 1] = '\0';
|
||||
putch(character);
|
||||
}
|
||||
|
||||
void execmd()
|
||||
{
|
||||
if(strcmp(commandbuffer, "version"))
|
||||
{
|
||||
puts("\nInteractive Shell Version 0.0.0.1\n");
|
||||
}
|
||||
else if(strcmp(commandbuffer,"cls"))
|
||||
{
|
||||
cls();
|
||||
}
|
||||
else
|
||||
{
|
||||
puts("\nUnknown command\n");
|
||||
}
|
||||
puts("#>");
|
||||
commandbuffer[0] = '\0';
|
||||
}
|
||||
Reference in New Issue
Block a user