Skip to content

Commit

Permalink
added numerous commands to the shell, added a way to clear the vga an…
Browse files Browse the repository at this point in the history
…d it's save buffer
  • Loading branch information
Namonay committed Jul 22, 2024
1 parent d433e1c commit 8190910
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
32 changes: 23 additions & 9 deletions sources/drivers/vga/vga.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const kernel = @import("kernel");


const SCREEN_SIZE = 2000;

const SCROLL_BUFFER_SIZE = SCREEN_SIZE * 3;
pub const Color = enum(u8)
{
BLACK = 0,
Expand Down Expand Up @@ -36,7 +40,7 @@ const Screen = struct
curr_fg : Color = Color.WHITE,
color: u8 = computeColor(Color.WHITE, Color.BLACK),
pointer: u16 = 0,
buffer : [8000]u16 = [_]u16{getVal(' ', computeColor(Color.WHITE, Color.BLACK))} ** 8000,
buffer : [SCROLL_BUFFER_SIZE]u16 = [_]u16{getVal(' ', computeColor(Color.WHITE, Color.BLACK))} ** SCROLL_BUFFER_SIZE,
};

const VGA = struct
Expand Down Expand Up @@ -76,7 +80,7 @@ pub fn changeScreen(target_screen: u8) void
{
if(target_screen == vga.current_screen or target_screen < 0 or target_screen >= 8)
return;
for(vga.width..2000) |i|
for(vga.width..SCREEN_SIZE) |i|
vga.screens_array[vga.current_screen].buffer[vga.screens_array[vga.current_screen].pointer * vga.width + i] = vga.buffer[i];

vga.screens_array[vga.current_screen].x = vga.x;
Expand All @@ -85,7 +89,7 @@ pub fn changeScreen(target_screen: u8) void
vga.screens_array[vga.current_screen].curr_bg = vga.curr_bg;
vga.screens_array[vga.current_screen].curr_fg = vga.curr_fg;

for(vga.width..2000) |i|
for(vga.width..SCREEN_SIZE) |i|
vga.buffer[i] = vga.screens_array[target_screen].buffer[vga.screens_array[target_screen].pointer * vga.width + i];

vga.x = vga.screens_array[target_screen].x;
Expand Down Expand Up @@ -141,7 +145,7 @@ pub fn init(title : []const u8, title_color : u8, navbar_color : u8, triggered_c
vga.nav_triggered_color = triggered_color;
vga.color = computeColor(vga.curr_fg, vga.curr_bg);
vga.y = 1;
for(80..1999) |i|
for(80..SCREEN_SIZE - 1) |i|
vga.buffer[i] = getVal(' ', computeColor(Color.WHITE, Color.BLACK));
updateCursor();
updateNavbar();
Expand Down Expand Up @@ -261,13 +265,23 @@ pub fn setColor(fg: Color, bg: Color) void
vga.curr_bg = bg;
}

pub fn scroll_buffer_clear(color: Color) void
{
for(0..SCROLL_BUFFER_SIZE) |i|
vga.screens_array[vga.current_screen].buffer[i] = getVal(' ', computeColor(Color.WHITE, color));
for (80..SCREEN_SIZE) |i|
vga.buffer[i] = getVal(' ', computeColor(Color.WHITE, color));
vga.y = 1;
vga.x = 0;
updateCursor();
}

pub fn clear(color: Color) void
{
for(0..vga.height) |i|
{
for(0..vga.width) |j|
vga.buffer[i * vga.width + j] = getVal(' ', computeColor(Color.WHITE, color));
}
for(0..SCROLL_BUFFER_SIZE) |i|
vga.screens_array[vga.current_screen].buffer[i] = getVal(' ', computeColor(Color.WHITE, color));
for (0..SCREEN_SIZE) |i|
vga.buffer[i] = getVal(' ', computeColor(Color.WHITE, color));
vga.y = 0;
vga.x = 0;
updateCursor();
Expand Down
2 changes: 1 addition & 1 deletion sources/kernel/panic.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub fn kpanic(message: []const u8) noreturn
{
@setCold(true);
vga.setColor(vga.Color.WHITE, vga.Color.RED);
vga.clear(vga.Color.RED);
vga.scroll_buffer_clear(vga.Color.RED);
vga.putString(logs.getLogBuffer());
stk.stackTrace(8);
vga.putString("\nkernel panic : ");
Expand Down
16 changes: 16 additions & 0 deletions sources/kernel/shell/dumb_shell.zig
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,22 @@ pub const DumbShell = struct
libk.io.kputs(logs.getLogBuffer());
libk.io.kputs("================ Journal ================\n");
}
else if (libk.str.streqlnt(&self.buffer, "help"))
{
libk.io.kputs("================ Help ================\n");
libk.io.kputs("shutdown/exit -> shutdown RatiOS\n");
libk.io.kputs("reboot -> reboot RatiOS\n");
libk.io.kputs("journal -> prints the kernel logs\n");
libk.io.kputs("stack -> prints the stack trace\n");
libk.io.kputs("panic -> trigger a kernel panic\n");
libk.io.kputs("stfu -> shutdown the keyboard\n");
libk.io.kputs("clear -> clears the shell\n");
libk.io.kputs("================ Help ================\n");
}
else if (libk.str.streqlnt(&self.buffer, "clear"))
{
drivers.vga.scroll_buffer_clear(drivers.vga.Color.BLACK);
}
else
libk.io.kprintf("command not found: {}\n", .{ &self.buffer });
}
Expand Down

0 comments on commit 8190910

Please sign in to comment.