.{memory, log, string} := @use("../../../../libraries/stn/src/lib.hb") render := @use("../../../../libraries/render/src/lib.hb") /* expected result: trash notepad app, colours should change with r,g,b,w keys */ psf := @embed("../../../../consolefonts/tamsyn/10x20r.psf") send_byte := fn(byte: u8): u8 { memory.outb(96, byte) return memory.inb(96) } example := fn(): void { screen := render.init(true) font := render.text.font_from_psf2(@bitcast(&psf), false) msg := "ableboard (tm) (patent pending):\n\0" msg_len := string.length(msg) buf := memory.alloc(u8, 4096) @inline(memory.copy, u8, msg, buf, msg_len) cursor := buf + msg_len if font == null { return } _ = send_byte(238) log.info("PS/2 Driver Loaded\0") if send_byte(238) == 238 { log.info("PS/2 Keyboard Echoed\0") } if send_byte(244) == 250 { log.info("Enabled scanning\0") } color := render.white prev_input := 250 loop { input := memory.inb(96) if input != prev_input { prev_input = input char := map_keys(input) if char != 0 { if char == 0xA { *cursor = 32 cursor += 1; *cursor = 92 cursor += 1 } else if char == 0x72 { color = render.red } else if char == 0x67 { color = render.green } else if char == 0x62 { color = render.blue } else if char == 0x77 { color = render.white } else if char == 0xE { cursor -= 1; *cursor = 32 continue }; *cursor = char cursor += 1 } } render.clear(screen, render.black) render.put_rect(screen, .(0, 0), .(screen.width - 1, screen.height - 1), render.white) render.put_text(screen, font, .(0, 0), color, buf) render.sync(screen) } return } map_keys := fn(inp: u8): u8 { if inp == 0x29 { return 0x7E } else if inp == 0x2 { return 0x31 } else if inp == 0x3 { return 0x32 } else if inp == 0x4 { return 0x33 } else if inp == 0x5 { return 0x34 } else if inp == 0x6 { return 0x35 } else if inp == 0x7 { return 0x36 } else if inp == 0x8 { return 0x37 } else if inp == 0x9 { return 0x38 } else if inp == 0xA { return 0x39 } else if inp == 0xB { return 0x30 } else if inp == 0xC { return 0x2D } else if inp == 0xD { return 0x3D } else if inp == 0xE { return 0xE } else if inp == 0x1C { return 0xA } else if inp == 0x10 { return 0x71 } else if inp == 0x11 { return 0x77 } else if inp == 0x12 { return 0x65 } else if inp == 0x13 { return 0x72 } else if inp == 0x14 { return 0x74 } else if inp == 0x15 { return 0x79 } else if inp == 0x16 { return 0x75 } else if inp == 0x17 { return 0x69 } else if inp == 0x18 { return 0x6F } else if inp == 0x19 { return 0x70 } else if inp == 0x1E { return 0x61 } else if inp == 0x1F { return 0x73 } else if inp == 0x20 { return 0x64 } else if inp == 0x21 { return 0x66 } else if inp == 0x22 { return 0x67 } else if inp == 0x23 { return 0x68 } else if inp == 0x24 { return 0x6A } else if inp == 0x25 { return 0x6B } else if inp == 0x26 { return 0x6C } else if inp == 0x2C { return 0x7A } else if inp == 0x2D { return 0x78 } else if inp == 0x2E { return 0x63 } else if inp == 0x2F { return 0x76 } else if inp == 0x30 { return 0x62 } else if inp == 0x31 { return 0x6E } else if inp == 0x32 { return 0x6D } else if inp == 0x2B { return 0x5C } else if inp == 0x39 { return 32 } else { return 0 } }