Skip to content

Commit

Permalink
fixed out of screen issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Namonay committed Jul 22, 2024
1 parent 8190910 commit 8924c19
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
14 changes: 10 additions & 4 deletions sources/drivers/vga/vga.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const kernel = @import("kernel");

const SCREEN_SIZE = 2000;

const SCROLL_BUFFER_SIZE = SCREEN_SIZE * 3;
const SCROLL_BUFFER_SIZE = SCREEN_SIZE * 4;

pub const Color = enum(u8)
{
BLACK = 0,
Expand Down Expand Up @@ -43,7 +44,7 @@ const Screen = struct
buffer : [SCROLL_BUFFER_SIZE]u16 = [_]u16{getVal(' ', computeColor(Color.WHITE, Color.BLACK))} ** SCROLL_BUFFER_SIZE,
};

const VGA = struct
pub const VGA = struct
{
height: usize = 25,
width: usize = 80,
Expand All @@ -60,7 +61,7 @@ const VGA = struct
current_screen: u8,
};

var vga = VGA
pub var vga = VGA
{
.x = 0,
.y = 1,
Expand Down Expand Up @@ -152,6 +153,10 @@ pub fn init(title : []const u8, title_color : u8, navbar_color : u8, triggered_c
kernel.logs.klogln("[VGA Driver] loaded");
}

pub fn canScroll() bool
{
return (vga.screens_array[vga.current_screen].pointer < 59);
}
pub fn reverseScroll() void
{
var x : usize = vga.height - 2;
Expand All @@ -175,7 +180,7 @@ pub fn reverseScroll() void

pub fn scroll() void
{
if(vga.screens_array[vga.current_screen].pointer == 75)
if(vga.screens_array[vga.current_screen].pointer == 59)
return;
for(0..vga.width) |y|
vga.screens_array[vga.current_screen].buffer[vga.screens_array[vga.current_screen].pointer * vga.width + y] = vga.buffer[vga.width + y];
Expand Down Expand Up @@ -271,6 +276,7 @@ pub fn scroll_buffer_clear(color: Color) void
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.screens_array[vga.current_screen].pointer = 0;
vga.y = 1;
vga.x = 0;
updateCursor();
Expand Down
15 changes: 9 additions & 6 deletions sources/kernel/shell/dumb_shell.zig
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub const DumbShell = struct
if(key == drivers.kb.PGUP)
drivers.vga.reverseScroll()
else if(key == drivers.kb.PGDOWN)
drivers.vga.scroll();
_ = drivers.vga.scroll();
if(key == drivers.kb.LEFT)
drivers.vga.moveCursor(.Left)
else if(key == drivers.kb.RIGHT)
Expand Down Expand Up @@ -70,7 +70,10 @@ pub const DumbShell = struct
}
else if(key == '\n')
{
libk.io.kputchar('\n');
if (!drivers.vga.canScroll())
drivers.vga.scroll_buffer_clear(drivers.vga.Color.BLACK)
else
libk.io.kputchar('\n');
return;
}
else if(key < 256) // to accept only printable keys
Expand Down Expand Up @@ -147,11 +150,11 @@ pub const DumbShell = struct
libk.io.kputs("================ Help ================\n");
}
else if (libk.str.streqlnt(&self.buffer, "clear"))
{
drivers.vga.scroll_buffer_clear(drivers.vga.Color.BLACK);
}
drivers.vga.scroll_buffer_clear(drivers.vga.Color.BLACK)
else if (libk.str.streqlnt(&self.buffer, "maldavid"))
libk.io.kputs("t'es mauvais\n")
else
libk.io.kprintf("command not found: {}\n", .{ &self.buffer });
libk.io.kprintf("command not found: {}, type help for help\n", .{ &self.buffer });
}
}
};

0 comments on commit 8924c19

Please sign in to comment.