aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/commands/command.c17
-rw-r--r--src/commands/command.h6
-rw-r--r--src/graphics/vga.c17
3 files changed, 33 insertions, 7 deletions
diff --git a/src/commands/command.c b/src/commands/command.c
new file mode 100644
index 0000000..ee53c90
--- /dev/null
+++ b/src/commands/command.c
@@ -0,0 +1,17 @@
+#include "../graphics/graphics.h"
+#include "../lib/lib.h"
+
+int32_t starts_with(const char *a, const char *b) {
+ if (strcmp(a, b, strlen(b)) == 0)
+ return 1
+ return 0
+}
+
+void exec_command(char *command) {
+ if (starts_with(command, "ls"))
+ terminal_write_string("// listing files");
+ else if (starts_with(command, "help"))
+ terminal_write_string("I can't help you write now");
+ else if (starts_with(command, "ping"))
+ terminal_write_string("pong!")
+}
diff --git a/src/commands/command.h b/src/commands/command.h
new file mode 100644
index 0000000..2a43416
--- /dev/null
+++ b/src/commands/command.h
@@ -0,0 +1,6 @@
+#ifndef MELVIX_COMMAND_H
+#define MELVIX_COMMAND_H
+
+void exec_command(char *command);
+
+#endif
diff --git a/src/graphics/vga.c b/src/graphics/vga.c
index cf04027..603a579 100644
--- a/src/graphics/vga.c
+++ b/src/graphics/vga.c
@@ -1,6 +1,7 @@
#include <stddef.h>
#include <stdint.h>
#include "../io/io.h"
+#include "../lib/lib.h"
// Hardware text mode color constants
enum vga_color {
@@ -30,13 +31,6 @@ static inline uint16_t vga_entry(unsigned char uc, uint8_t color) {
return (uint16_t) uc | (uint16_t) color << 8;
}
-size_t strlen(const char *str) {
- size_t len = 0;
- while (str[len])
- len++;
- return len;
-}
-
static const size_t VGA_WIDTH = 80;
static const size_t VGA_HEIGHT = 25;
@@ -99,6 +93,14 @@ void terminal_put_entry_at(char c, uint8_t color, size_t x, size_t y) {
terminal_buffer[index] = vga_entry(c, color);
}
+char* terminal_get_line() {
+ char* line = "";
+ for (size_t x = 0; x < terminal_column; i++) {
+ line += terminal_buffer[terminal_row * VGA_WIDTH + x];
+ // TODO: Fix returning line..
+ return line;
+}
+
void terminal_put_char(char c) {
if (c == 0x08) {
if (terminal_column != 0) terminal_column--;
@@ -107,6 +109,7 @@ void terminal_put_char(char c) {
} else if (c == '\r') {
terminal_column = 0;
} else if (c == '\n') {
+ exec_command(line);
terminal_column = 0;
terminal_row++;
terminal_scroll();