Add wnohang, make PS/2 driver write input to display scheme, which then passes it to the shell
This commit is contained in:
parent
046236c10f
commit
76b0c7eeea
9 changed files with 151 additions and 96 deletions
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue