greatly simplified Writer by removing T generic, 0xb8000 is now hardcoded in flush()
This commit is contained in:
parent
67dbf5d9b3
commit
c1cb1e5620
3 changed files with 34 additions and 21 deletions
|
|
@ -5,24 +5,16 @@ use vga;
|
|||
|
||||
pub struct Context {
|
||||
pub current_term: u8,
|
||||
pub vga1: vga::Writer<&'static mut [u8]>,
|
||||
pub vga2: vga::Writer<&'static mut [u8]>,
|
||||
pub vga1: vga::Writer,
|
||||
pub vga2: vga::Writer,
|
||||
}
|
||||
|
||||
impl Context {
|
||||
pub fn new() -> Context {
|
||||
let slice1 = unsafe {
|
||||
core::slice::from_raw_parts_mut(0xb8000 as *mut u8, 4000)
|
||||
};
|
||||
|
||||
let slice2 = unsafe {
|
||||
core::slice::from_raw_parts_mut(0xb8000 as *mut u8, 4000)
|
||||
};
|
||||
|
||||
Context {
|
||||
current_term: 0,
|
||||
vga1: vga::Writer::new(slice1),
|
||||
vga2: vga::Writer::new(slice2),
|
||||
vga1: vga::Writer::new(),
|
||||
vga2: vga::Writer::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -33,7 +25,7 @@ impl Context {
|
|||
};
|
||||
}
|
||||
|
||||
pub fn current_term(&mut self) -> &mut vga::Writer<&'static mut [u8]>{
|
||||
pub fn current_term(&mut self) -> &mut vga::Writer{
|
||||
if self.current_term == 0 {
|
||||
&mut self.vga1
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ use context;
|
|||
|
||||
pub static SCANCODE_TO_ASCII: [u8; 59] = *b"??1234567890-=??qwertyuiop[]\n?asdfghjkl;'`?\\zxcvbnm,./?*? ?";
|
||||
|
||||
|
||||
pub fn kbd_callback(context: &mut context::Context) {
|
||||
// let terminal_two: vga::terminal::Terminal = vga::Screen::new();
|
||||
let control = unsafe { cpuio::inb(0x64) };
|
||||
|
|
|
|||
|
|
@ -16,20 +16,41 @@ struct ScreenChar {
|
|||
color_code: ColorCode,
|
||||
}
|
||||
|
||||
// macro_rules! print {
|
||||
// ($($arg:tt)*) => ({
|
||||
// $crate::vga_buffer::print(format_args!($($arg)*));
|
||||
// });
|
||||
// }
|
||||
|
||||
// macro_rules! println {
|
||||
// ($fmt:expr) => (print!(concat!($fmt, "\n")));
|
||||
// ($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*));
|
||||
// }
|
||||
|
||||
// pub fn print(args: fmt::Arguments) {
|
||||
// use core::fmt::Write;
|
||||
// context.current_screen().write_fmt(args).unwrap();
|
||||
// }
|
||||
|
||||
|
||||
extern crate core;
|
||||
|
||||
// pub const unsafe fn vga_slice() -> &'static [u8] {
|
||||
// unsafe { core::slice::from_raw_parts_mut(0xb8000 as *mut u8, 4000) }
|
||||
// }
|
||||
|
||||
const BUFFER_ROWS: usize = 25;
|
||||
const BUFFER_COLS: usize = 80 * 2;
|
||||
|
||||
pub struct Writer<T: AsMut<[u8]>> {
|
||||
pub struct Writer {
|
||||
pub position: usize,
|
||||
color_code: ColorCode,
|
||||
slice: T,
|
||||
buffer: [u8; BUFFER_ROWS * BUFFER_COLS],
|
||||
}
|
||||
|
||||
impl<T: AsMut<[u8]>> Writer<T> {
|
||||
pub fn new(slice: T) -> Writer<T> {
|
||||
impl Writer {
|
||||
pub fn new() -> Writer {
|
||||
Writer {
|
||||
slice,
|
||||
position: 0,
|
||||
color_code: ColorCode::new(Color::White, Color::Black),
|
||||
buffer: [0; BUFFER_ROWS * BUFFER_COLS],
|
||||
|
|
@ -70,7 +91,8 @@ impl<T: AsMut<[u8]>> Writer<T> {
|
|||
}
|
||||
|
||||
pub fn flush(&mut self) {
|
||||
self.slice.as_mut().clone_from_slice(&self.buffer);
|
||||
let slice = unsafe { core::slice::from_raw_parts_mut(0xb8000 as *mut u8, 4000) };
|
||||
slice.as_mut().clone_from_slice(&self.buffer);
|
||||
}
|
||||
|
||||
fn scroll(&mut self) {
|
||||
|
|
@ -92,7 +114,7 @@ impl<T: AsMut<[u8]>> Writer<T> {
|
|||
}
|
||||
|
||||
use core::fmt;
|
||||
impl<T: AsMut<[u8]>> fmt::Write for Writer<T> {
|
||||
impl fmt::Write for Writer {
|
||||
fn write_str(&mut self, s: &str) -> ::core::fmt::Result {
|
||||
for byte in s.bytes() {
|
||||
self.write_byte(byte)
|
||||
|
|
|
|||
Loading…
Reference in a new issue