From 6aa3f673317518f745d5a8a345dbd87034c192b2 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Wed, 12 Apr 2017 19:21:54 +0200 Subject: [PATCH] Add a print_something function to print an `H` in the lower left --- src/lib.rs | 12 +----------- src/vga_buffer.rs | 10 ++++++++++ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 87889a4..4ed2979 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,17 +11,7 @@ mod vga_buffer; pub extern fn rust_main() { // ATTENTION: we have a very small stack and no guard page - let hello = b"Hello World!"; - let color_byte = 0x1f; // white foreground, blue background - - let mut hello_colored = [color_byte; 24]; - for (i, char_byte) in hello.into_iter().enumerate() { - hello_colored[i*2] = *char_byte; - } - - // write `Hello World!` to the center of the VGA text buffer - let buffer_ptr = (0xb8000 + 1988) as *mut _; - unsafe { *buffer_ptr = hello_colored }; + vga_buffer::print_something(); loop{} } diff --git a/src/vga_buffer.rs b/src/vga_buffer.rs index 8b807fb..fe07af9 100644 --- a/src/vga_buffer.rs +++ b/src/vga_buffer.rs @@ -79,3 +79,13 @@ impl Writer { fn new_line(&mut self) {/* TODO */} } + +pub fn print_something() { + let mut writer = Writer { + column_position: 0, + color_code: ColorCode::new(Color::LightGreen, Color::Black), + buffer: unsafe { Unique::new(0xb8000 as *mut _) }, + }; + + writer.write_byte(b'H'); +}