diff --git a/src/lib.rs b/src/lib.rs index 3dc67e0..2f8fca8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,16 +8,15 @@ extern crate rlibc; extern crate volatile; extern crate spin; +#[macro_use] mod vga_buffer; #[no_mangle] pub extern fn rust_main() { // ATTENTION: we have a very small stack and no guard page - use core::fmt::Write; - - vga_buffer::WRITER.lock().write_str("Hello again"); - write!(vga_buffer::WRITER.lock(), ", some numbers: {} {}", 42, 1.337); + vga_buffer::clear_screen(); + println!("Hello World{}", "!"); loop{} } diff --git a/src/vga_buffer.rs b/src/vga_buffer.rs index ca9187d..0b95624 100644 --- a/src/vga_buffer.rs +++ b/src/vga_buffer.rs @@ -123,3 +123,22 @@ impl fmt::Write for Writer { Ok(()) } } + +macro_rules! print { + ($($arg:tt)*) => ({ + use core::fmt::Write; + let mut writer = $crate::vga_buffer::WRITER.lock(); + writer.write_fmt(format_args!($($arg)*)).unwrap(); + }); +} + +macro_rules! println { + ($fmt:expr) => (print!(concat!($fmt, "\n"))); + ($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*)); +} + +pub fn clear_screen() { + for _ in 0..BUFFER_HEIGHT { + println!(""); + } +}