From 0ed21fb943b3942cad54b01e13482031dd6e79a4 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Wed, 12 Apr 2017 19:24:25 +0200 Subject: [PATCH] Use volatile writes for printing to screen --- Cargo.toml | 1 + src/lib.rs | 1 + src/vga_buffer.rs | 7 ++++--- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index eec662f..455d244 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,4 @@ crate-type = ["staticlib"] [dependencies] rlibc = "1.0" +volatile = "0.1.0" diff --git a/src/lib.rs b/src/lib.rs index 4ed2979..2fa06b5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,7 @@ #![no_std] extern crate rlibc; +extern crate volatile; mod vga_buffer; diff --git a/src/vga_buffer.rs b/src/vga_buffer.rs index fe07af9..1a76527 100644 --- a/src/vga_buffer.rs +++ b/src/vga_buffer.rs @@ -1,4 +1,5 @@ use core::ptr::Unique; +use volatile::Volatile; #[allow(dead_code)] #[derive(Debug, Clone, Copy)] @@ -42,7 +43,7 @@ const BUFFER_HEIGHT: usize = 25; const BUFFER_WIDTH: usize = 80; struct Buffer { - chars: [[ScreenChar; BUFFER_WIDTH]; BUFFER_HEIGHT], + chars: [[Volatile; BUFFER_WIDTH]; BUFFER_HEIGHT], } pub struct Writer { @@ -64,10 +65,10 @@ impl Writer { let col = self.column_position; let color_code = self.color_code; - self.buffer().chars[row][col] = ScreenChar { + self.buffer().chars[row][col].write(ScreenChar { ascii_character: byte, color_code: color_code, - }; + }); self.column_position += 1; } }