From 1c606561a130fa8fdb24bbc50f7f061bfbbe6b3d Mon Sep 17 00:00:00 2001 From: wescande Date: Tue, 10 Apr 2018 21:43:40 +0200 Subject: [PATCH] keyboard input is now in irq compliant mode --- kernel-rs/mk/grub.mk | 1 + kernel-rs/src/keyboard.rs | 60 ++++++++++++++++++++++----------------- 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/kernel-rs/mk/grub.mk b/kernel-rs/mk/grub.mk index 28d9c17c..1444d67a 100644 --- a/kernel-rs/mk/grub.mk +++ b/kernel-rs/mk/grub.mk @@ -7,3 +7,4 @@ $(grub-iso): $(kernel) $(grub-cfg) Makefile @cp $(grub-cfg) $(isodir)/boot/grub @cp $(kernel) $(isodir)/boot/$(OS) @grub-mkrescue -o $@ $(isodir) 2>/dev/null + @printf "\r\033[38;5;117m✓ GRUB ==> $(grub-iso)\033[0m\033[K\n" diff --git a/kernel-rs/src/keyboard.rs b/kernel-rs/src/keyboard.rs index d7c4a16a..fddb2992 100644 --- a/kernel-rs/src/keyboard.rs +++ b/kernel-rs/src/keyboard.rs @@ -76,33 +76,41 @@ fn check_key_state(key: u8) -> (bool, usize) { } } -pub fn kbd_callback() { - static mut SHIFT: bool = false; - static mut CTRL: bool = false; - static mut ALT: bool = false; - let control = cpuio::inb(0x64); - if (control & 1) == 1 { - let scancode = cpuio::inb(0x60); - let (is_release, scancode) = check_key_state(scancode); - unsafe { - //TODO remove unsafe - match self::KEYMAP_US.get(scancode as usize) { - Some(b"\0\0") => match scancode { - 0x2A | 0x36 => SHIFT = !is_release, - 0x38 => ALT = !is_release, - 0x1D => CTRL = !is_release, - 0x0E if !is_release => { - vga::VGA.backspace(); - } - _ => {} - }, - Some(ascii) if !is_release => { - let sym = if SHIFT { ascii[1] } else { ascii[0] }; - vga::VGA.keypress(sym); - } - Some(_) => {} - None => {} +fn get_scancode() -> u8 { + let mut scancode = 0; + loop { + if cpuio::inb(0x60) != scancode { + scancode = cpuio::inb(0x60); + if scancode > 0 { + return scancode; } } } } + +pub fn kbd_callback() { + static mut SHIFT: bool = false; + static mut CTRL: bool = false; + static mut ALT: bool = false; + let scancode = get_scancode(); + let (is_release, scancode) = check_key_state(scancode); + unsafe { + //TODO remove unsafe + match self::KEYMAP_US.get(scancode as usize) { + Some(b"\0\0") => match scancode { + 0x2A | 0x36 => SHIFT = !is_release, + 0x38 => ALT = !is_release, + 0x1D => CTRL = !is_release, + 0x0E if !is_release => { + vga::VGA.backspace(); + } + _ => {} + }, + Some(ascii) if !is_release => { + let sym = if SHIFT { ascii[1] } else { ascii[0] }; + vga::VGA.keypress(sym); + } + _ => {} + } + } +}