Add printstr functionality

This commit is contained in:
greg
2015-11-27 16:35:05 -08:00
parent 02ffdd55bd
commit ad61d53c8f

View File

@@ -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)]