Add printstr functionality
This commit is contained in:
@@ -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]
|
#![no_std]
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@@ -9,6 +9,8 @@ extern crate std;
|
|||||||
extern crate rlibc;
|
extern crate rlibc;
|
||||||
extern crate multiboot2;
|
extern crate multiboot2;
|
||||||
|
|
||||||
|
use core::fmt::Write;
|
||||||
|
|
||||||
/* externs */
|
/* externs */
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern fn rust_setup_PIC() {
|
pub extern fn rust_setup_PIC() {
|
||||||
@@ -182,7 +184,9 @@ pub extern fn rust_main(multiboot_info_header: usize) {
|
|||||||
clear();
|
clear();
|
||||||
checkerboard(Color::Red);
|
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 {
|
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 {
|
mod vga_buffer {
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
|
|||||||
Reference in New Issue
Block a user