diff --git a/rust_experiments/src/lib.rs b/rust_experiments/src/lib.rs index f4e94b2..61c3ada 100644 --- a/rust_experiments/src/lib.rs +++ b/rust_experiments/src/lib.rs @@ -1,5 +1,5 @@ -#![feature(no_std, lang_items, const_fn, asm)] +#![feature(no_std, lang_items, const_fn, asm, core_str_ext)] #![no_std] #[cfg(test)] @@ -9,6 +9,8 @@ extern crate std; extern crate rlibc; extern crate multiboot2; +use core::fmt::Write; + /* externs */ #[no_mangle] pub extern fn rust_setup_PIC() { @@ -182,7 +184,9 @@ pub extern fn rust_main(multiboot_info_header: usize) { clear(); checkerboard(Color::Red); - let boot_info = unsafe { multiboot2::load(multiboot_info_header) }; + //let boot_info = unsafe { multiboot2::load(multiboot_info_header) }; + + printstr::write_to_screen(6, "hello you person: {}"); loop { @@ -231,6 +235,39 @@ mod util { } } +mod printstr { + use vga_buffer::{Color, ColorCode, write_to_coord}; + + const std_code: ColorCode = ColorCode::new(Color::LightBlue, Color::Black); + + pub fn write_to_screen(line_num: u8, s: &str) { + + let mut x_position: usize = 0; + let mut y_position: usize = line_num as usize; + + for ch in s.bytes() { + + if x_position > ::vga_buffer::BUFFER_WIDTH { + x_position = 0; + y_position += 1; + } + + if y_position > ::vga_buffer::BUFFER_HEIGHT { + return; + } + + match ch { + b'\n' => { y_position += 1; x_position = 0; }, + byte => { + write_to_coord(x_position, y_position, byte, std_code); + x_position += 1; + } + } + } + } + +} + mod vga_buffer { #[repr(u8)] #[derive(Clone, Copy)]