CONTEXT is instanciated at compile time now

This commit is contained in:
Jack Halford 2018-02-12 16:11:47 +01:00
parent c1cb1e5620
commit 2503fdb96d
4 changed files with 20 additions and 26 deletions

View file

@ -2,6 +2,11 @@ extern crate core;
use vga;
pub static mut CONTEXT: Context = Context {
current_term: 0,
vga1: vga::Writer::new(),
vga2: vga::Writer::new(),
};
pub struct Context {
pub current_term: u8,
@ -10,14 +15,6 @@ pub struct Context {
}
impl Context {
pub fn new() -> Context {
Context {
current_term: 0,
vga1: vga::Writer::new(),
vga2: vga::Writer::new(),
}
}
pub fn switch_term(&mut self) {
self.current_term = {
if self.current_term == 0 { 1 }

View file

@ -1,29 +1,28 @@
extern crate core;
use cpuio;
use context;
use context::CONTEXT;
// use vga::color::{Color, ColorCode};
pub static SCANCODE_TO_ASCII: [u8; 59] = *b"??1234567890-=??qwertyuiop[]\n?asdfghjkl;'`?\\zxcvbnm,./?*? ?";
pub fn kbd_callback(context: &mut context::Context) {
pub fn kbd_callback() {
// let terminal_two: vga::terminal::Terminal = vga::Screen::new();
let control = unsafe { cpuio::inb(0x64) };
if (control & 1) == 1 {
let scancode = unsafe { cpuio::inb(0x60) };
//TODO implement logic to translate scancode->ascii
unsafe {
match self::SCANCODE_TO_ASCII.get(scancode as usize) {
Some(&b'1') => {
context.switch_term();
context.current_term().flush();
CONTEXT.switch_term();
CONTEXT.current_term().flush();
}
Some(ascii) => {
let mut terminal = context.current_term();
terminal.keypress(*ascii);
CONTEXT.current_term().keypress(*ascii);
},
None =>{},
// None => println!("nokey ctrl {:x}", control),
}
// current_screen.flush();
}
}
}

View file

@ -41,10 +41,8 @@ pub extern fn kmain() -> ! {
// WRITER.lock().color_code = ColorCode::new(Color::White, Color::Black);
// println!(">> Kernel startup...");
let mut context = context::Context::new();
loop {
keyboard::kbd_callback(&mut context);
keyboard::kbd_callback();
}
}

View file

@ -49,7 +49,7 @@ pub struct Writer {
}
impl Writer {
pub fn new() -> Writer {
pub const fn new() -> Writer {
Writer {
position: 0,
color_code: ColorCode::new(Color::White, Color::Black),