From 0c0a53f1be37214b30ccad1717e31ee9f3d96dc6 Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 10 Jul 2019 23:39:12 -0700 Subject: [PATCH] Better vga buffer --- src/main.rs | 4 +++- src/vga_buffer.rs | 13 +++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 11b1a71..7e63916 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,9 @@ fn panic(_info: &PanicInfo) -> !{ #[no_mangle] pub extern "C" fn _start() -> ! { - vga_buffer::yolo(); + use core::fmt::Write; + vga_buffer::WRITER.lock().write_str("Gamarjoba, munde").unwrap(); + write!(vga_buffer::WRITER.lock(), ", hella {} bro", 2).unwrap(); loop {} } diff --git a/src/vga_buffer.rs b/src/vga_buffer.rs index a6d052e..0524e93 100644 --- a/src/vga_buffer.rs +++ b/src/vga_buffer.rs @@ -1,6 +1,7 @@ use volatile::Volatile; use core::fmt; -use core::fmt::Write; +use spin::Mutex; +use lazy_static::lazy_static; #[allow(dead_code)] #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -95,11 +96,11 @@ impl fmt::Write for Writer { } } -pub fn yolo() { - let mut writer = Writer { + +lazy_static! { + pub static ref WRITER: Mutex = Mutex::new(Writer { column_position: 0, color_code: ColorCode::new(Color::Yellow, Color::Black), buffer: unsafe { &mut *(0xb8000 as *mut Buffer) }, - }; - - write!(writer, "Gamarjoba munde {}", 34); + }); } +