diff options
| author | hachem <im@hachem.wtf> | 2026-09-25 11:31:59 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-09-25 11:31:59 +0200 |
| commit | ed285c9fc665e262ed21c7bf5734acb2b7a532db (patch) | |
| tree | e51434e8069bc7219221cc1136515828d0293aca /kernel/input.rv | |
| parent | d18d1da05a4d065d54787434d6bc46f3354626a5 (diff) | |
feat: load + run native ELF binaries
Diffstat (limited to 'kernel/input.rv')
| -rw-r--r-- | kernel/input.rv | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/kernel/input.rv b/kernel/input.rv new file mode 100644 index 0000000..33cf65d --- /dev/null +++ b/kernel/input.rv @@ -0,0 +1,47 @@ +# keyboard scancode table +# ts is NOT a good way to write a driver LMAO +const KBD = " 1234567890-= qwertyuiop[] asdfghjkl;'` \\zxcvbnm,./ " +# same layout, shifted. index 42 (left shift) / 54 (right shift) stay blank. +const KBD_SHIFT = " !@#$%^&*()_+ QWERTYUIOP{} ASDFGHJKL:\"~ |ZXCVBNM<>? " + +# 8259 PIC +fn pic_remap() do + outb(0x20, 0x11) outb(0xa0, 0x11) + outb(0x21, 0x20) outb(0xa1, 0x28) + outb(0x21, 0x04) outb(0xa1, 0x02) + outb(0x21, 0x01) outb(0xa1, 0x01) + outb(0x21, 0xff) outb(0xa1, 0xff) +end +fn pic_unmask(line) outb(0x21, inb(0x21) band (255 bxor (1 shl line))) + +# she stroke my keys till i handle +# no fr this is just a key stroke handler +global sh = { line = "", shift = :false } +global on_key = fn(code) do + # shift: 0x2a/0x36 press, + # 0xaa/0xb6 release + # index a blank cell and type a stray space. + if code == 0x2a do sh.shift = :true return :nil end + if code == 0x36 do sh.shift = :true return :nil end + if code == 0xaa do sh.shift = :false return :nil end + if code == 0xb6 do sh.shift = :false return :nil end + if code >= 128 return :nil # other key releases + if code == 28 do # Enter + puts("\n") + run(sh.line) + sh.line = "" + return :nil + end + if code == 14 do # Backspace + if sh.line:len() > 0 do + sh.line = sh.line:sub(0, sh.line:len() - 1) + puts("\x08 \x08") + end + return :nil + end + if code < 2 return :nil + if code >= KBD:len() return :nil + const ch = if sh.shift KBD_SHIFT[code] else KBD[code] + sh.line = sh.line ~ ch + puts(ch) +end |
