Skip to content

Commit

Permalink
adding a dumb shell
Browse files Browse the repository at this point in the history
  • Loading branch information
Kbz-8 committed Jul 21, 2024
1 parent 6a04a77 commit 8fa0366
Show file tree
Hide file tree
Showing 13 changed files with 479 additions and 210 deletions.
149 changes: 71 additions & 78 deletions sources/drivers/keyboard/keyboard.zig
Original file line number Diff line number Diff line change
@@ -1,50 +1,52 @@
const kernel = @import("kernel");
const vga = @import("../vga/vga.zig");
const libk = @import("libk");

const vga = @import("../vga/vga.zig");

var caps_on: bool = false;
var caps_lock: bool = false;
var num_lock: bool = false;

pub var keyboard_toggle : bool = true;
var keyboard_toggle : bool = true;

const UNKNOWN: u32 = 0xFFFFFFFF;
const ESC: u32 = 0xFFFFFFFF - 1;
const CTRL: u32 = 0xFFFFFFFF - 2;
const LSHFT: u32 = 0xFFFFFFFF - 3;
const RSHFT: u32 = 0xFFFFFFFF - 4;
const ALT: u32 = 0xFFFFFFFF - 5;
const F1: u32 = 0xFFFFFFFF - 6;
const F2: u32 = 0xFFFFFFFF - 7;
const F3: u32 = 0xFFFFFFFF - 8;
const F4: u32 = 0xFFFFFFFF - 9;
const F5: u32 = 0xFFFFFFFF - 10;
const F6: u32 = 0xFFFFFFFF - 11;
const F7: u32 = 0xFFFFFFFF - 12;
const F8: u32 = 0xFFFFFFFF - 13;
const F9: u32 = 0xFFFFFFFF - 14;
const F10: u32 = 0xFFFFFFFF - 15;
const F11: u32 = 0xFFFFFFFF - 16;
const F12: u32 = 0xFFFFFFFF - 17;
const SCRLCK: u32 = 0xFFFFFFFF - 18;
const HOME: u32 = 0xFFFFFFFF - 19;
const UP: u32 = 0xFFFFFFFF - 20;
const LEFT: u32 = 0xFFFFFFFF - 21;
const RIGHT: u32 = 0xFFFFFFFF - 22;
const DOWN: u32 = 0xFFFFFFFF - 23;
const PGUP: u32 = 0xFFFFFFFF - 24;
const PGDOWN: u32 = 0xFFFFFFFF - 25;
const END: u32 = 0xFFFFFFFF - 26;
const INS: u32 = 0xFFFFFFFF - 27;
const DEL: u32 = 0xFFFFFFFF - 28;
const CAPS: u32 = 0xFFFFFFFF - 29;
const NONE: u32 = 0xFFFFFFFF - 30;
const ALTGR: u32 = 0xFFFFFFFF - 31;
const NUMLCK: u32 = 0xFFFFFFFF - 32;
pub const UNKNOWN = 0xFFFFFFFF;
pub const ESC = 0xFFFFFFFF - 1;
pub const CTRL = 0xFFFFFFFF - 2;
pub const LSHFT = 0xFFFFFFFF - 3;
pub const RSHFT = 0xFFFFFFFF - 4;
pub const ALT = 0xFFFFFFFF - 5;
pub const F1 = 0xFFFFFFFF - 6;
pub const F2 = 0xFFFFFFFF - 7;
pub const F3 = 0xFFFFFFFF - 8;
pub const F4 = 0xFFFFFFFF - 9;
pub const F5 = 0xFFFFFFFF - 10;
pub const F6 = 0xFFFFFFFF - 11;
pub const F7 = 0xFFFFFFFF - 12;
pub const F8 = 0xFFFFFFFF - 13;
pub const F9 = 0xFFFFFFFF - 14;
pub const F10 = 0xFFFFFFFF - 15;
pub const F11 = 0xFFFFFFFF - 16;
pub const F12 = 0xFFFFFFFF - 17;
pub const SCRLCK = 0xFFFFFFFF - 18;
pub const HOME = 0xFFFFFFFF - 19;
pub const UP = 0xFFFFFFFF - 20;
pub const LEFT = 0xFFFFFFFF - 21;
pub const RIGHT = 0xFFFFFFFF - 22;
pub const DOWN = 0xFFFFFFFF - 23;
pub const PGUP = 0xFFFFFFFF - 24;
pub const PGDOWN = 0xFFFFFFFF - 25;
pub const END = 0xFFFFFFFF - 26;
pub const INS = 0xFFFFFFFF - 27;
pub const DEL = 0xFFFFFFFF - 28;
pub const CAPS = 0xFFFFFFFF - 29;
pub const NONE = 0xFFFFFFFF - 30;
pub const ALTGR = 0xFFFFFFFF - 31;
pub const NUMLCK = 0xFFFFFFFF - 32;
pub const BACKSPACE = 0x08;

const lowercase = [128]u32 {
UNKNOWN,ESC,'1','2','3','4','5','6','7','8',
'9','0','-','=',0x08,'\t','q','w','e','r',
'9','0','-','=',BACKSPACE,'\t','q','w','e','r',
't','y','u','i','o','p','[',']','\n',CTRL,
'a','s','d','f','g','h','j','k','l',';',
'\'','`',LSHFT,'\\','z','x','c','v','b','n','m',',',
Expand All @@ -56,7 +58,7 @@ const lowercase = [128]u32 {
};

const uppercase = [128]u32 {
UNKNOWN,ESC,'!','@','#','$','%','^','&','*','(',')','_','+',0x08,'\t','Q','W','E','R',
UNKNOWN,ESC,'!','@','#','$','%','^','&','*','(',')','_','+',BACKSPACE,'\t','Q','W','E','R',
'T','Y','U','I','O','P','{','}','\n',CTRL,'A','S','D','F','G','H','J','K','L',':','"','~',LSHFT,'|','Z','X','C',
'V','B','N','M','<','>','?',RSHFT,'*',ALT,' ',CAPS,F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,NUMLCK,SCRLCK,HOME,UP,PGUP,'-',
LEFT,UNKNOWN,RIGHT,'+',END,DOWN,PGDOWN,INS,DEL,UNKNOWN,UNKNOWN,UNKNOWN,F11,F12,UNKNOWN,UNKNOWN,UNKNOWN,UNKNOWN,
Expand All @@ -65,74 +67,65 @@ const uppercase = [128]u32 {
UNKNOWN,UNKNOWN,UNKNOWN,UNKNOWN,UNKNOWN,UNKNOWN,UNKNOWN
};

var keybuffer: [256]u8 = .{0} ** 256;
var current_key_pressed: u32 = 0;

pub fn getCurrentKeyPressed() u32
{
const ret = current_key_pressed;
current_key_pressed = 0; // reset key to avoid stupidly fast key repeat
return ret;
}

pub fn disableKeyboard() void
{
keyboard_toggle = false;
}

pub fn keyboardHandler(regs: *kernel.arch.idt.IDTRegister) void
{
_ = regs;
const scan_code = kernel.arch.ports.in(u8, 0x60) & 0x7F;
const press = kernel.arch.ports.in(u8, 0x60) & 0x80;

switch(scan_code)
switch(scan_code)
{
1, 29, 56, 59...69,72, 73, 75, 77, 80, 81, 87, 88 => // control keys
59...66, 69 => // control keys
{
if (scan_code == 69)
if(scan_code == 69)
{
if (!caps_lock and press == 0)
if(!caps_lock and press == 0)
caps_lock = true
else if (caps_lock and press == 0)
else if(caps_lock and press == 0)
caps_lock = false;
return;
}
if (press != 0)
return;
if (scan_code == 72 or scan_code == 75 or scan_code == 77 or scan_code == 80)
vga.moveCursor(scan_code);
if (scan_code == 73)
vga.reverseScroll();
if (scan_code == 81)
vga.scroll();
if (scan_code >= 59 and scan_code <= 66)
if(press != 0)
current_key_pressed = 0
else if(scan_code >= 59 and scan_code <= 66)
vga.changeScreen(scan_code - 59);
return;
},
else => {}
}
if (keyboard_toggle == false)
return;
else => {}
}

if(keyboard_toggle == false)
return;

switch(scan_code)
{
14 =>
{
if (press != 0)
return;
vga.backspace();
return;
},
42 =>
42, 54 =>
{
caps_on = press == 0;
return;
},
58 =>
{
if (!caps_lock and press == 0)
caps_lock = true
else if (caps_lock and press == 0)
caps_lock = false;
return;
},
else =>
{
if (press != 0)
return;
if (caps_on or caps_lock)
vga.putChar(@truncate(uppercase[scan_code]))
if(press != 0)
current_key_pressed = 0
else if(caps_on or caps_lock)
current_key_pressed = uppercase[scan_code]
else
vga.putChar(@truncate(lowercase[scan_code]));
current_key_pressed = lowercase[scan_code];
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions sources/drivers/power/power.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ pub fn init() void
@setCold(true);
kernel.logs.klogln("[Power Driver] loading...");
kernel.logs.beginSection();
if(!acpi.init())
//if(!acpi.init())
if(true)
{
kernel.logs.endSection();
kernel.logs.klogln("[Power Driver] couldn't load");
Expand All @@ -20,8 +21,9 @@ pub fn init() void

pub fn shutdown() void
{
//kernel.arch.ports.out(u16, 0x604, 0x2000);
acpi.powerOff();
// qemu shutdown; TODO : fix ACPI
kernel.arch.ports.out(u16, 0x604, 0x2000);
//acpi.powerOff();
}

pub fn reboot() void
Expand Down
Loading

0 comments on commit 8fa0366

Please sign in to comment.