Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.
Permalink
Browse files
re-do vga package
  • Loading branch information
steveklabnik committed Jun 7, 2018
1 parent fbf4513 commit a970d359e5f23c995d084b9e0774395af51853a5
Show file tree
Hide file tree
Showing 3 changed files with 209 additions and 145 deletions.
@@ -0,0 +1,64 @@
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct Character {
character: u8,
attribute: u8,
}

#[derive(Copy, Clone, PartialEq, Debug)]
pub enum Color {
Black = 0x0,
Blue = 0x1,
Green = 0x2,
Cyan = 0x3,
Red = 0x4,
Magenta = 0x5,
Brown = 0x6,
Gray = 0x7,
DarkGray = 0x8,
BrightBlue = 0x9,
BrightGreen = 0xA,
BrightCyan = 0xB,
BrightRed = 0xC,
BrightMagenta = 0xD,
Yellow = 0xE,
White = 0xF,
}

impl Character {
pub fn new(character: u8, foreground: Color, background: Color) -> Character {
let attribute = ((background as u8) << 4) + (foreground as u8);

Character {
character,
attribute,
}
}

pub fn as_bytes(&self) -> (u8, u8) {
(self.character, self.attribute)
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn creation() {
let character = Character::new(b'a', Color::Blue, Color::BrightMagenta);

assert_eq!(character.character, b'a');
assert_eq!(character.attribute, 0xD1);

let character = Character::new(b'b', Color::Yellow, Color::Red);

assert_eq!(character.character, b'b');
assert_eq!(character.attribute, 0x4E);

let character = Character::new(b'c', Color::DarkGray, Color::White);

assert_eq!(character.character, b'c');
assert_eq!(character.attribute, 0xF8);
}

}

This file was deleted.

0 comments on commit a970d35

Please sign in to comment.