Add a VGA buffer module skeleton

It contains basic types for colors, screen characters, and the buffer itself.
This commit is contained in:
Philipp Oppermann
2015-09-24 14:12:49 +02:00
parent 3e7fd1b433
commit 49fd8926a5
2 changed files with 42 additions and 0 deletions

View File

@@ -13,10 +13,13 @@
// limitations under the License. // limitations under the License.
#![feature(no_std, lang_items)] #![feature(no_std, lang_items)]
#![feature(const_fn)]
#![no_std] #![no_std]
extern crate rlibc; extern crate rlibc;
mod vga_buffer;
#[no_mangle] #[no_mangle]
pub extern fn rust_main() { pub extern fn rust_main() {
// ATTENTION: we have a very small stack and no guard page // ATTENTION: we have a very small stack and no guard page

39
src/vga_buffer.rs Normal file
View File

@@ -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],
}