diff --git a/headers/commands.h b/headers/commands.h new file mode 100644 index 0000000..0045948 --- /dev/null +++ b/headers/commands.h @@ -0,0 +1,12 @@ +#pragma once + +void halt_cmd(char *arg); +void color_cmd(char *arg); +void date_cmd(char *arg); +void poweroff_cmd(char *arg); +void stack_cmd(char *arg); +void help_cmd(char *arg); +void reboot_cmd(char* arg); +void heap_cmd(char *arg); +void clear_cmd(char *arg); +void merdella_cmd(char *arg); \ No newline at end of file diff --git a/headers/shell.h b/headers/shell.h index 3b7318d..d029e27 100644 --- a/headers/shell.h +++ b/headers/shell.h @@ -1,51 +1,5 @@ #pragma once -#include "debug.h" -#include "power.h" - #define PROMPT "> " -[[__maybe_unused__]] static const char *POOP = - " / ____/ / _ \\\n" - " _/ ___/_ / / \\___ \\_\n" - " / _/'-, `---._ / / \\_ \\\n" - " / ______/(0} `, , ` , ) / / \\_ \\\n" - " / V ; ` , ` ( / / ,'~~~~~~`, \\\n" - " | `.____,- ' (, ` , ) / / :`,-'\"\"`. \"; " - "|\n" - " | `-------._); , ` `, / / \\;: )``: |\n" - " / / ) ) ; ` ,, : / / `` : '; " - "\\\n" - "/ / ( (`;: ; ` ;:\\ / / ;;;, " - "\\\n" - "| / (: )``;:;;)`'`'`--./ / ____ _,-';;` " - "|\n" - "| | :` )`;)`)`' : / / ~~~~~ ~~~`--',.;;;| " - "|\n" - "| | `--;~~~~~ ` / /, \" \" \"` \",, \\ ;`` | " - " |\n" - "| | ( ; , / / ; `; ; | " - "|\n" - "| | (; ; ; ` / / ,` ` : | " - "><\n" - "| | (; / / / ` ; ; : |\n" - "| \\ ;(_; ; : / /` ; ; ,,,\"\"\";} `; / " - "><\n" - "\\ \\ : `; `; ` / /,;,'''' );;`); ; / >< " - " ><\n" - " \\ | ;' :; ;/ / (;` :( ; , ; | " - "><\n" - " | | |, `;; ,/ / `)`; `(; ` `; | " - "(`\\\n" - " | \\ ; ;; ``: / `).:` \\;, `. / _> " - ")_\n" - " \\ \\_ ,-' ;`;;:;` / ;;'`;; `) )/ ,-' " - ",-. `;\n" - " \\ \\_ ~~~,-`;`;,\" / ~~~~~ ,-' ; " - "`\"\"/ /\"\"\n" - " \\_ \\___\"\"\"/\"\" / `\"\"/\"\" " - "\n"; - -void shell_init(void); -void date(void); -void merdella(void); +void shell_init(); \ No newline at end of file diff --git a/src/shell/commands/clear_cmd.c b/src/shell/commands/clear_cmd.c new file mode 100644 index 0000000..61a37f3 --- /dev/null +++ b/src/shell/commands/clear_cmd.c @@ -0,0 +1,7 @@ +#include "terminal.h" + +void clear_cmd(char *arg) +{ + (void)arg; + terminal_clear(); +} \ No newline at end of file diff --git a/src/shell/date.c b/src/shell/commands/date_cmd.c similarity index 95% rename from src/shell/date.c rename to src/shell/commands/date_cmd.c index 5d9bcb7..28c64e7 100644 --- a/src/shell/date.c +++ b/src/shell/commands/date_cmd.c @@ -1,7 +1,7 @@ #include "kprintf.h" #include "rtc.h" -void date(void) +void date_cmd(char *arg) { static const char *months[12] = {"January", "February", "March", "April", "May", "June", @@ -10,6 +10,7 @@ void date(void) static const char *week_days[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; + (void)arg; struct rtc_date date = get_date(); kprintf(0, "%s. %d %s. %d %d:%d:%d\n", week_days[date.index_of_the_day], diff --git a/src/shell/commands/halt_cmd.c b/src/shell/commands/halt_cmd.c new file mode 100644 index 0000000..125ba1c --- /dev/null +++ b/src/shell/commands/halt_cmd.c @@ -0,0 +1,7 @@ +#include "power.h" + +void halt_cmd(char *arg) +{ + (void)arg; + halt(); +} \ No newline at end of file diff --git a/src/shell/commands/heap_cmd.c b/src/shell/commands/heap_cmd.c new file mode 100644 index 0000000..586ef3f --- /dev/null +++ b/src/shell/commands/heap_cmd.c @@ -0,0 +1,7 @@ +#include "alloc.h" + +void heap_cmd(char *arg) +{ + (void)arg; + show_alloc_mem(); +} \ No newline at end of file diff --git a/src/shell/commands/merdella_cmd.c b/src/shell/commands/merdella_cmd.c new file mode 100644 index 0000000..e9660bc --- /dev/null +++ b/src/shell/commands/merdella_cmd.c @@ -0,0 +1,49 @@ +#include "kprintf.h" +#include "shell.h" + +[[__maybe_unused__]] static const char *POOP = + " / ____/ / _ \\\n" + " _/ ___/_ / / \\___ \\_\n" + " / _/'-, `---._ / / \\_ \\\n" + " / ______/(0} `, , ` , ) / / \\_ \\\n" + " / V ; ` , ` ( / / ,'~~~~~~`, \\\n" + " | `.____,- ' (, ` , ) / / :`,-'\"\"`. \"; " + "|\n" + " | `-------._); , ` `, / / \\;: )``: |\n" + " / / ) ) ; ` ,, : / / `` : '; " + "\\\n" + "/ / ( (`;: ; ` ;:\\ / / ;;;, " + "\\\n" + "| / (: )``;:;;)`'`'`--./ / ____ _,-';;` " + "|\n" + "| | :` )`;)`)`' : / / ~~~~~ ~~~`--',.;;;| " + "|\n" + "| | `--;~~~~~ ` / /, \" \" \"` \",, \\ ;`` | " + " |\n" + "| | ( ; , / / ; `; ; | " + "|\n" + "| | (; ; ; ` / / ,` ` : | " + "><\n" + "| | (; / / / ` ; ; : |\n" + "| \\ ;(_; ; : / /` ; ; ,,,\"\"\";} `; / " + "><\n" + "\\ \\ : `; `; ` / /,;,'''' );;`); ; / >< " + " ><\n" + " \\ | ;' :; ;/ / (;` :( ; , ; | " + "><\n" + " | | |, `;; ,/ / `)`; `(; ` `; | " + "(`\\\n" + " | \\ ; ;; ``: / `).:` \\;, `. / _> " + ")_\n" + " \\ \\_ ,-' ;`;;:;` / ;;'`;; `) )/ ,-' " + ",-. `;\n" + " \\ \\_ ~~~,-`;`;,\" / ~~~~~ ,-' ; " + "`\"\"/ /\"\"\n" + " \\_ \\___\"\"\"/\"\" / `\"\"/\"\" " + "\n"; + +void merdella_cmd(char *arg) +{ + (void)arg; + kprintf(POOP); +} diff --git a/src/shell/commands/poweroff_cmd.c b/src/shell/commands/poweroff_cmd.c new file mode 100644 index 0000000..cb3d78b --- /dev/null +++ b/src/shell/commands/poweroff_cmd.c @@ -0,0 +1,7 @@ +#include "power.h" + +void poweroff_cmd(char *arg) +{ + (void)arg; + halt(); +} \ No newline at end of file diff --git a/src/shell/commands/reboot.c b/src/shell/commands/reboot.c new file mode 100644 index 0000000..95a8799 --- /dev/null +++ b/src/shell/commands/reboot.c @@ -0,0 +1,7 @@ +#include "power.h" + +void reboot_cmd(char *arg) +{ + (void)arg; + reboot(); +} \ No newline at end of file diff --git a/src/shell/commands/stack_cmd.c b/src/shell/commands/stack_cmd.c new file mode 100644 index 0000000..d85d52d --- /dev/null +++ b/src/shell/commands/stack_cmd.c @@ -0,0 +1,7 @@ +#include "debug.h" + +void stack_cmd(char arg) +{ + (void)arg; + print_stack(); +} \ No newline at end of file diff --git a/src/shell/exec.c b/src/shell/exec.c index 3551764..7f1ec9e 100644 --- a/src/shell/exec.c +++ b/src/shell/exec.c @@ -1,39 +1,41 @@ #include "alloc.h" +#include "commands.h" #include "kprintf.h" #include "shell.h" #include "string.h" #include "terminal.h" -#define NB_CMDS (sizeof(commands) / sizeof(commands[0])) -#define BORDER "===========================================================" -#define HEADER "Welcome to bozOShell - Available Commands" - -extern struct screen *screen; +#define BORDER "===========================================================" +#define HEADER "Welcome to bozOShell - Available Commands" struct shell_command { char name[16]; char description[256]; - void (*fn)(void); + void (*fn)(char *arg); }; -static void help(void); - -static const struct shell_command commands[] = { - {"help", "Print this help menu", help}, - {"reboot", "Reboot the system", reboot}, - {"poweroff", "Shut down the system", halt}, - {"halt", "Stop all CPU functions", halt}, - {"stack", "Print the stack trace", print_stack}, - {"heap", "Print the heaps", show_alloc_mem}, - {"clear", "Clear the current terminal", terminal_clear}, - {"date", "Display the current time and date (UTC+0)", date}, - {"merdella", "Surprise", merdella}, +const struct shell_command commands[] = { + {"help", "Print this help menu", help_cmd}, + {"reboot", "Reboot the system", reboot_cmd}, + {"poweroff", "Shut down the system", poweroff_cmd}, + {"halt", "Stop all CPU functions", halt_cmd}, + {"stack", "Print the stack trace", stack_cmd}, + {"heap", "Print the heaps", heap_cmd}, + {"clear", "Clear the current terminal", clear_cmd}, + {"date", "Display the current time and date", date_cmd}, + {"merdella", "Surprise", merdella_cmd}, + // {"color", "Change the screen color", color}, }; -static void help(void) +#define NB_CMDS (sizeof(commands) / sizeof(commands[0])) + +extern struct screen *screen; + +void help_cmd(char *arg) { const size_t padding = 15; + (void)arg; kprintf("%s\n", BORDER); kprintf(" %s\n", HEADER); kprintf("%s\n", BORDER); @@ -103,7 +105,7 @@ static void read_line(void) screen->line[i] = '\0'; } -void shell_init(void) +void shell_init() { while (1) { kprintf(PROMPT); @@ -111,7 +113,8 @@ void shell_init(void) bool invalid = true; for (unsigned i = 0; i < NB_CMDS; i++) { if (!strcmp(commands[i].name, screen->line)) { - commands[i].fn(); + commands[i].fn(screen->line + + strlen(commands[i].name) + 1); invalid = false; break; } diff --git a/src/shell/misc_cmds.c b/src/shell/misc_cmds.c deleted file mode 100644 index 3f1307c..0000000 --- a/src/shell/misc_cmds.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "kprintf.h" -#include "shell.h" - -void merdella(void) -{ - kprintf(POOP); -} diff --git a/src/terminal/put.c b/src/terminal/put.c index ef70fd0..7dd90cb 100644 --- a/src/terminal/put.c +++ b/src/terminal/put.c @@ -33,8 +33,9 @@ void terminal_initialize(void) for (int i = 0; i < TERM_COUNT; i++) { screens[i].row = 0; screens[i].column = 0; - screens[i].color = + screens[i].default_color = vga_entry_color(VGA_COLOR_WHITE, VGA_COLOR_BLACK); + screens[i].color = screens[i].default_color; memcpy(screens[i].buffer, TERM_BUF, sizeof(screen->buffer)); } } @@ -59,6 +60,11 @@ void terminal_set_fg_color(uint8_t fg_color) screen->color = (screen->color & 0xF0) | fg_color; } +void terminal_set_color(uint8_t color) +{ + screen->color = color; +} + void terminal_putentryat(char c, uint8_t color, size_t x, size_t y) { const size_t index = y * VGA_WIDTH + x; @@ -172,5 +178,8 @@ void set_color_level(int level) VGA_COLOR_LIGHT_YELLOW, VGA_COLOR_LIGHT_YELLOW, VGA_COLOR_LIGHT_BLUE, VGA_COLOR_GREEN, VGA_COLOR_LIGHT_GREY}; + + if (level == 0) + terminal_set_color(screen->default_color); terminal_set_fg_color(color_translation[level]); }