Skip to content

Commit

Permalink
Implement backspace
Browse files Browse the repository at this point in the history
  • Loading branch information
mrgian committed Apr 6, 2023
1 parent eef4092 commit 6789f10
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
32 changes: 22 additions & 10 deletions kernel/src/keyboard.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::pic::PICS;
use crate::print::PRINTER;
use core::arch::asm;

pub const KEYBOARD_INT: u8 = 33;
Expand Down Expand Up @@ -30,14 +31,25 @@ pub extern "C" fn keyboard_handler() {
PICS.end_interrupt(KEYBOARD_INT);

unsafe {
if scancode == 0x2a {
KEYBOARD.lshift = true;
return;
}

if scancode == 0xaa {
KEYBOARD.lshift = false;
return;
match scancode {
//press left shift
0x2a => {
KEYBOARD.lshift = true;
return;
},

//release left shift
0xaa => {
KEYBOARD.lshift = false;
return;
},

//backspace
0x0e => {
PRINTER.backspace();
return;
},
_ => {},
}
}

Expand Down Expand Up @@ -65,12 +77,12 @@ fn scancode_to_char(scancode: u8) -> char {

let mut key;

if index < 36 {
if index < chars.len() {
key = chars[index];

unsafe {
if KEYBOARD.lshift {
key -= 0x20;
key -= 0x20; //make char uppercase
}
}
} else {
Expand Down
8 changes: 8 additions & 0 deletions kernel/src/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ impl Printer {
self.set_cursor_position();
}

pub fn backspace(&mut self) {
self.x -= 1;
self.printc('\0', 12, 0);
self.x -= 1;

self.set_cursor_position();
}

//get cursor position directly talking to vga hardware
pub fn get_cursor_position(&self) -> (u16, u16) {
let mut index: u16 = 0;
Expand Down

0 comments on commit 6789f10

Please sign in to comment.