hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/boot/keyboard.zig
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-09-25 21:21:09 +0200
committerhachem <im@hachem.wtf>2026-09-25 21:21:09 +0200
commit09982d80c45805715984cc1cae96c37e4fc148c3 (patch)
treef711d6e7f4d4cb2d4dcb555d6a139aae343d7334 /boot/keyboard.zig
parentfd3f51eecaecc12806a573c38263df1de43ee8c2 (diff)
feat: scheduler + cleanup
Diffstat (limited to 'boot/keyboard.zig')
-rw-r--r--boot/keyboard.zig44
1 files changed, 22 insertions, 22 deletions
diff --git a/boot/keyboard.zig b/boot/keyboard.zig
index 8e3a58f..a4352d7 100644
--- a/boot/keyboard.zig
+++ b/boot/keyboard.zig
@@ -1,13 +1,13 @@
-// top half of the PS/2 keyboard driver.
-// the IRQ1 handler calls onIrq and reads the raw scancode out
-// of the controller and drops it in a ring buffer. thats ALLLLLL it does
+// top half of the ps/2 keyboard driver
+// the irq1 handler calls onirq and reads the raw scancode out
+// of the controller and drops it in a ring buffer. thats allllll it does
// no decoding, no allocation, nothing that could (should) fault or reenter
// the only reason this exists is because the interrupt handler is not a safe
-// spot to execute revo code and shit can break easily and i am NOT going to debug
-// it so its just better to do it like this.
+// spot to execute revo code and shit can break easily and i am not going to debug
+// it so its just better to do it like this
//
-// since there is just one producer (ISR) and one consumer (the event loop)
-// i dont need to make a lock, the ISR just moves the tail and the loop just
+// since there is just one producer (isr) and one consumer (the event loop)
+// i dont need to make a lock, the isr just moves the tail and the loop just
// moves the head
const port = @import("port.zig");
@@ -17,26 +17,26 @@ const SIZE: usize = 256; // u8 indices wrap mod 256 for free
var buf: [SIZE]u8 = undefined;
var head: u8 = 0; // next slot the loop will read
-var tail: u8 = 0; // next slot the ISR will write
+var tail: u8 = 0; // next slot the isr will write
-// called from the IRQ1 handler. read the scancode (which also ACKs the
-// controller so it'll send the next one) and enqueue it, dropping it on the
-// floor if the buffer is somehow full.
+// called from the irq1 handler. read the scancode (which also acks the
+// controller so itll send the next one) and enqueue it, dropping it on the
+// floor if the buffer is somehow full
pub fn onIrq() void {
const code = port.inb(DATA_PORT);
- const t: *volatile u8 = &tail;
- const h: *volatile u8 = &head;
- if (t.* +% 1 == h.*) return; // full, drop
- buf[t.*] = code;
- t.* +%= 1;
+ const tail_ptr: *volatile u8 = &tail;
+ const head_ptr: *volatile u8 = &head;
+ if (tail_ptr.* +% 1 == head_ptr.*) return; // full, drop
+ buf[tail_ptr.*] = code;
+ tail_ptr.* +%= 1;
}
-// called from the event loop. next queued scancode, or null if empty.
+// called from the event loop. next queued scancode, or null if empty
pub fn pop() ?u8 {
- const t: *volatile u8 = &tail;
- const h: *volatile u8 = &head;
- if (h.* == t.*) return null;
- const code = buf[h.*];
- h.* +%= 1;
+ const tail_ptr: *volatile u8 = &tail;
+ const head_ptr: *volatile u8 = &head;
+ if (head_ptr.* == tail_ptr.*) return null;
+ const code = buf[head_ptr.*];
+ head_ptr.* +%= 1;
return code;
}