Commit 0cbc3eac authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Add wnohang, make PS/2 driver write input to display scheme, which then passes it to the shell

parent b9a25544
......@@ -5,9 +5,12 @@ use std::thread;
use keymap;
pub fn keyboard() {
pub fn keyboard() {
let mut file = File::open("irq:1").expect("ps2d: failed to open irq:1");
let mut input = File::open("display:input").expect("ps2d: failed to open display:input");
let mut lshift = false;
let mut rshift = false;
loop {
let mut irqs = [0; 8];
if file.read(&mut irqs).expect("ps2d: failed to read irq:1") >= mem::size_of::<usize>() {
......@@ -16,17 +19,25 @@ pub fn keyboard() {
asm!("in al, dx" : "={al}"(data) : "{dx}"(0x60) : : "intel", "volatile");
}
file.write(&irqs).expect("ps2d: failed to write irq:1");
let (scancode, pressed) = if data >= 0x80 {
(data - 0x80, false)
} else {
(data, true)
};
if pressed {
print!("{}", keymap::get_char(scancode));
if scancode == 0x2A {
lshift = pressed;
} else if scancode == 0x36 {
rshift = pressed;
} else if pressed {
let c = keymap::get_char(scancode, lshift || rshift);
if c != '\0' {
print!("{}", c);
input.write(&[c as u8]).expect("ps2d: failed to write input");
}
}
file.write(&irqs).expect("ps2d: failed to write irq:1");
} else {
thread::yield_now();
}
......
static ENGLISH: [[char; 3]; 58] = [
['\0', '\0', '\0'],
['\x1B', '\x1B', '\x1B'],
['1', '!', '1'],
['2', '@', '2'],
['3', '#', '3'],
['4', '$', '4'],
['5', '%', '5'],
['6', '^', '6'],
['7', '&', '7'],
['8', '*', '8'],
['9', '(', '9'],
['0', ')', '0'],
['-', '_', '-'],
['=', '+', '='],
['\0', '\0', '\0'],
['\t', '\t', '\t'],
['q', 'Q', 'q'],
['w', 'W', 'w'],
['e', 'E', 'e'],
['r', 'R', 'r'],
['t', 'T', 't'],
['y', 'Y', 'y'],
['u', 'U', 'u'],
['i', 'I', 'i'],
['o', 'O', 'o'],
['p', 'P', 'p'],
['[', '{', '['],
[']', '}', ']'],
['\n', '\n', '\n'],
['\0', '\0', '\0'],
['a', 'A', 'a'],
['s', 'S', 's'],
['d', 'D', 'd'],
['f', 'F', 'f'],
['g', 'G', 'g'],
['h', 'H', 'h'],
['j', 'J', 'j'],
['k', 'K', 'k'],
['l', 'L', 'l'],
[';', ':', ';'],
['\'', '"', '\''],
['`', '~', '`'],
['\0', '\0', '\0'],
['\\', '|', '\\'],
['z', 'Z', 'z'],
['x', 'X', 'x'],
['c', 'C', 'c'],
['v', 'V', 'v'],
['b', 'B', 'b'],
['n', 'N', 'n'],
['m', 'M', 'm'],
[',', '<', ','],
['.', '>', '.'],
['/', '?', '/'],
['\0', '\0', '\0'],
['\0', '\0', '\0'],
['\0', '\0', '\0'],
[' ', ' ', ' ']
static ENGLISH: [[char; 2]; 58] = [
['\0', '\0'],
['\x1B', '\x1B'],
['1', '!'],
['2', '@'],
['3', '#'],
['4', '$'],
['5', '%'],
['6', '^'],
['7', '&'],
['8', '*'],
['9', '('],
['0', ')'],
['-', '_'],
['=', '+'],
['\x7F', '\x7F'],
['\t', '\t'],
['q', 'Q'],
['w', 'W'],
['e', 'E'],
['r', 'R'],
['t', 'T'],
['y', 'Y'],
['u', 'U'],
['i', 'I'],
['o', 'O'],
['p', 'P'],
['[', '{'],
[']', '}'],
['\n', '\n'],
['\0', '\0'],
['a', 'A'],
['s', 'S'],
['d', 'D'],
['f', 'F'],
['g', 'G'],
['h', 'H'],
['j', 'J'],
['k', 'K'],
['l', 'L'],
[';', ':'],
['\'', '"'],
['`', '~'],
['\0', '\0'],
['\\', '|'],
['z', 'Z'],
['x', 'X'],
['c', 'C'],
['v', 'V'],
['b', 'B'],
['n', 'N'],
['m', 'M'],
[',', '<'],
['.', '>'],
['/', '?'],
['\0', '\0'],
['\0', '\0'],
['\0', '\0'],
[' ', ' ']
];
pub fn get_char(scancode: u8) -> char {
pub fn get_char(scancode: u8, shift: bool) -> char {
if let Some(c) = ENGLISH.get(scancode as usize) {
c[0]
if shift {
c[1]
} else {
c[0]
}
} else {
'\0'
}
......
......@@ -8,6 +8,7 @@ extern crate ransid;
extern crate syscall;
use std::cell::RefCell;
use std::collections::VecDeque;
use std::fs::File;
use std::io::{Read, Write};
use std::{slice, thread};
......@@ -24,32 +25,55 @@ pub mod primitive;
struct DisplayScheme {
console: RefCell<Console>,
display: RefCell<Display>
display: RefCell<Display>,
input: RefCell<VecDeque<u8>>
}
impl Scheme for DisplayScheme {
fn open(&self, _path: &[u8], _flags: usize) -> Result<usize> {
Ok(0)
fn open(&self, path: &[u8], _flags: usize) -> Result<usize> {
if path == b"input" {
Ok(1)
} else {
Ok(0)
}
}
fn dup(&self, _id: usize) -> Result<usize> {
Ok(0)
fn dup(&self, id: usize) -> Result<usize> {
Ok(id)
}
fn fsync(&self, _id: usize) -> Result<usize> {
Ok(0)
}
fn write(&self, _id: usize, buf: &[u8]) -> Result<usize> {
let mut display = self.display.borrow_mut();
self.console.borrow_mut().write(buf, |event| {
match event {
Event::Char { x, y, c, color, .. } => display.char(x * 8, y * 16, c, color.data),
Event::Rect { x, y, w, h, color } => display.rect(x * 8, y * 16, w * 8, h * 16, color.data),
Event::Scroll { rows, color } => display.scroll(rows * 16, color.data)
fn read(&self, _id: usize, buf: &mut [u8]) -> Result<usize> {
let mut i = 0;
let mut input = self.input.borrow_mut();
while i < buf.len() && ! input.is_empty() {
buf[i] = input.pop_front().unwrap();
i += 1;
}
Ok(i)
}
fn write(&self, id: usize, buf: &[u8]) -> Result<usize> {
if id == 1 {
let mut input = self.input.borrow_mut();
for &b in buf.iter() {
input.push_back(b);
}
});
Ok(buf.len())
Ok(buf.len())
} else {
let mut display = self.display.borrow_mut();
self.console.borrow_mut().write(buf, |event| {
match event {
Event::Char { x, y, c, color, .. } => display.char(x * 8, y * 16, c, color.data),
Event::Rect { x, y, w, h, color } => display.rect(x * 8, y * 16, w * 8, h * 16, color.data),
Event::Scroll { rows, color } => display.scroll(rows * 16, color.data)
}
});
Ok(buf.len())
}
}
fn close(&self, _id: usize) -> Result<usize> {
......@@ -89,15 +113,27 @@ fn main() {
display: RefCell::new(Display::new(width, height,
unsafe { slice::from_raw_parts_mut(onscreen as *mut u32, size) },
unsafe { slice::from_raw_parts_mut(offscreen as *mut u32, size) }
))
)),
input: RefCell::new(VecDeque::new())
};
let mut blocked = VecDeque::new();
loop {
let mut packet = Packet::default();
socket.read(&mut packet).expect("vesad: failed to read display scheme");
//println!("vesad: {:?}", packet);
scheme.handle(&mut packet);
socket.write(&packet).expect("vesad: failed to write display scheme");
if packet.a == syscall::number::SYS_READ && packet.d > 0 && scheme.input.borrow().is_empty() {
blocked.push_back(packet);
} else {
scheme.handle(&mut packet);
socket.write(&packet).expect("vesad: failed to write display scheme");
}
while ! scheme.input.borrow().is_empty() {
if let Some(mut packet) = blocked.pop_front() {
scheme.handle(&mut packet);
socket.write(&packet).expect("vesad: failed to write display scheme");
}
}
}
});
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment