From 49fd8926a5d03c58d3587bddbf997bdc88dbfd85 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Thu, 24 Sep 2015 14:12:49 +0200 Subject: [PATCH] Add a VGA buffer module skeleton It contains basic types for colors, screen characters, and the buffer itself. --- src/lib.rs | 3 +++ src/vga_buffer.rs | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/vga_buffer.rs diff --git a/src/lib.rs b/src/lib.rs index bbf11c0a..29afba64 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,10 +13,13 @@ // limitations under the License. #![feature(no_std, lang_items)] +#![feature(const_fn)] #![no_std] extern crate rlibc; +mod vga_buffer; + #[no_mangle] pub extern fn rust_main() { // ATTENTION: we have a very small stack and no guard page diff --git a/src/vga_buffer.rs b/src/vga_buffer.rs new file mode 100644 index 00000000..efc42ed7 --- /dev/null +++ b/src/vga_buffer.rs @@ -0,0 +1,39 @@ +const BUFFER_HEIGHT: usize = 25; +const BUFFER_WIDTH: usize = 80; + +#[repr(u8)] +pub enum Color { + Black = 0, + Blue = 1, + Green = 2, + Cyan = 3, + Red = 4, + Magenta = 5, + Brown = 6, + LightGray = 7, + DarkGray = 8, + LightBlue = 9, + LightGreen = 10, + LightCyan = 11, + LightRed = 12, + Pink = 13, + Yellow = 14, + White = 15, +} + +struct ColorCode(u8); + +impl ColorCode { + const fn new(foreground: Color, background: Color) -> ColorCode { + ColorCode((background as u8) << 4 | (foreground as u8)) + } +} + +struct ScreenChar { + ascii_character: u8, + color_code: ColorCode, +} + +struct Buffer { + chars: [[ScreenChar; BUFFER_WIDTH]; BUFFER_HEIGHT], +}