Skip to content

Commit

Permalink
added vga buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
youhaveme9 committed Feb 26, 2024
1 parent 1543981 commit 208fbd9
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ build-std-features = ["compiler-builtins-mem"]
build-std = ["core", "compiler_builtins"]

[build]
target = "x86_64-rust_os.json"
target = "x86_64-rust_os.json"

[target.'cfg(target_os = "none")']
runner = "bootimage runner"
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#![no_std] // don't link the Rust standard library
#![no_main] // disable all Rust-level entry points
#![allow(unused_imports)]
// #![feature(custom_test_frameworks)]
// #![feature(custom_test_frameworks)]

mod vga_buffer;

use core::panic::PanicInfo;

Expand Down
45 changes: 45 additions & 0 deletions src/vga_buffer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#[allow(dead_code)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[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,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(transparent)]
struct ColorCode(u8);

impl ColorCode {
fn new(foreground: Color, background: Color) -> ColorCode {
ColorCode((background as u8) << 4 | (foreground as u8))
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(C)]
struct ScreenChar {
ascii_character: u8,
color_code: ColorCode,
}
const BUFFER_HEIGHT: usize = 25;
const BUFFER_WIDTH: usize = 80;

#[repr(transparent)]
struct Buffer {
chars: [[ScreenChar; BUFFER_WIDTH]; BUFFER_HEIGHT],
}

0 comments on commit 208fbd9

Please sign in to comment.