diff --git a/Changelog.md b/Changelog.md index 7b170a9..e8b149f 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,7 +2,7 @@ ## Breaking -- `ScreenCharacter::new` now takes a `TextModeColor` instead of 2 `Color16Bit`. +- `ScreenCharacter::new` now takes a `TextModeColor` instead of 2 `Color16`. ## Other - Added `ScreenCharacter::get_character`. diff --git a/README.md b/README.md index 354b15d..4ad8ec0 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,11 @@ this crate to work properly. ## Usage ```rust -use vga::colors::{Color16Bit, TextModeColor}; +use vga::colors::{Color16, TextModeColor}; use vga::writers::{ScreenCharacter, TextWriter, Text80x25}; let text_mode = Text80x25::new(); -let color = TextModeColor::new(Color16Bit::Yellow, Color16Bit::Black); +let color = TextModeColor::new(Color16::Yellow, Color16::Black); let screen_character = ScreenCharacter::new(b'T', color); text_mode.set_mode(); diff --git a/src/colors.rs b/src/colors.rs index 8bc44de..11ad75c 100644 --- a/src/colors.rs +++ b/src/colors.rs @@ -6,7 +6,7 @@ pub const PALETTE_SIZE: usize = 768; /// Represents a 16 bit color used for vga display. #[derive(Debug, Clone, Copy)] #[repr(u8)] -pub enum Color16Bit { +pub enum Color16 { /// Represents the color `Black (0x0)`. Black = 0x0, /// Represents the color `Blue (0x1)`. @@ -41,8 +41,8 @@ pub enum Color16Bit { White = 0xF, } -impl From for u8 { - fn from(value: Color16Bit) -> u8 { +impl From for u8 { + fn from(value: Color16) -> u8 { value as u8 } } @@ -55,17 +55,17 @@ pub struct TextModeColor(u8); impl TextModeColor { /// Returns a new `TextModeColor` given the specified `foreground` /// and `background` color. - pub const fn new(foreground: Color16Bit, background: Color16Bit) -> TextModeColor { + pub const fn new(foreground: Color16, background: Color16) -> TextModeColor { TextModeColor((background as u8) << 4 | (foreground as u8)) } /// Sets the background color given the specified `background`; - pub fn set_background(&mut self, background: Color16Bit) { + pub fn set_background(&mut self, background: Color16) { self.0 = (background as u8) << 4 | (self.0 & 0x0F); } /// Sets the foreground color given the specified `foreground`. - pub fn set_foreground(&mut self, foreground: Color16Bit) { + pub fn set_foreground(&mut self, foreground: Color16) { self.0 = foreground as u8; } } @@ -128,15 +128,15 @@ mod test { #[test] fn test_set_foreground() { - let mut color = TextModeColor::new(Color16Bit::Yellow, Color16Bit::Black); - color.set_foreground(Color16Bit::Red); - assert_eq!(color.0 & 0x0F, Color16Bit::Red as u8); + let mut color = TextModeColor::new(Color16::Yellow, Color16::Black); + color.set_foreground(Color16::Red); + assert_eq!(color.0 & 0x0F, Color16::Red as u8); } #[test] fn test_set_background() { - let mut color = TextModeColor::new(Color16Bit::Yellow, Color16Bit::Black); - color.set_background(Color16Bit::DarkGrey); - assert_eq!(color.0 >> 4, Color16Bit::DarkGrey as u8); + let mut color = TextModeColor::new(Color16::Yellow, Color16::Black); + color.set_background(Color16::DarkGrey); + assert_eq!(color.0 >> 4, Color16::DarkGrey as u8); } } diff --git a/src/registers/graphics_controller.rs b/src/registers/graphics_controller.rs index c4afa41..eaa698a 100644 --- a/src/registers/graphics_controller.rs +++ b/src/registers/graphics_controller.rs @@ -1,4 +1,4 @@ -use super::{Color16Bit, GRX_DATA_ADDRESS, GRX_INDEX_ADDRESS}; +use super::{Color16, GRX_DATA_ADDRESS, GRX_INDEX_ADDRESS}; use core::convert::TryFrom; use x86_64::instructions::port::Port; @@ -169,7 +169,7 @@ impl GraphicsControllerRegisters { /// Sets the value to use for `GraphicsControllerIndex::SetReset`, /// as spcified by `color`. - pub fn write_set_reset(&mut self, color: Color16Bit) { + pub fn write_set_reset(&mut self, color: Color16) { let original_value = self.read(GraphicsControllerIndex::SetReset) & 0xF0; self.write( GraphicsControllerIndex::SetReset, diff --git a/src/registers/mod.rs b/src/registers/mod.rs index c53850e..d3223d4 100644 --- a/src/registers/mod.rs +++ b/src/registers/mod.rs @@ -7,7 +7,7 @@ mod general; mod graphics_controller; mod sequencer; -use crate::colors::{Color16Bit, PALETTE_SIZE}; +use crate::colors::{Color16, PALETTE_SIZE}; pub use attribute_controller::{AttributeControllerIndex, AttributeControllerRegisters}; pub use color_palette::ColorPaletteRegisters; diff --git a/src/writers/graphics_640x480x16.rs b/src/writers/graphics_640x480x16.rs index e8537f2..48583de 100644 --- a/src/writers/graphics_640x480x16.rs +++ b/src/writers/graphics_640x480x16.rs @@ -1,6 +1,6 @@ use super::GraphicsWriter; use crate::{ - colors::{Color16Bit, DEFAULT_PALETTE}, + colors::{Color16, DEFAULT_PALETTE}, drawing::{Bresenham, Point}, registers::{PlaneMask, WriteMode}, vga::{Vga, VideoMode, VGA}, @@ -20,19 +20,19 @@ const WIDTH_IN_BYTES: usize = WIDTH / 8; /// Basic usage: /// /// ```no_run -/// use vga::colors::Color16Bit; +/// use vga::colors::Color16; /// use vga::writers::{GraphicsWriter, Graphics640x480x16}; /// /// let graphics_mode = Graphics640x480x16::new(); /// /// graphics_mode.set_mode(); -/// graphics_mode.clear_screen(Color16Bit::Black); +/// graphics_mode.clear_screen(Color16::Black); /// ``` #[derive(Default)] pub struct Graphics640x480x16; -impl GraphicsWriter for Graphics640x480x16 { - fn clear_screen(&self, color: Color16Bit) { +impl GraphicsWriter for Graphics640x480x16 { + fn clear_screen(&self, color: Color16) { self.set_write_mode_2(); let (_vga, frame_buffer) = self.get_frame_buffer(); for offset in 0..ALL_PLANES_SCREEN_SIZE { @@ -42,14 +42,14 @@ impl GraphicsWriter for Graphics640x480x16 { } } - fn draw_line(&self, start: Point, end: Point, color: Color16Bit) { + fn draw_line(&self, start: Point, end: Point, color: Color16) { self.set_write_mode_0(color); for (x, y) in Bresenham::new(start, end) { self._set_pixel(x as usize, y as usize, color); } } - fn draw_character(&self, x: usize, y: usize, character: char, color: Color16Bit) { + fn draw_character(&self, x: usize, y: usize, character: char, color: Color16) { self.set_write_mode_2(); let character = match font8x8::BASIC_FONTS.get(character) { Some(character) => character, @@ -67,7 +67,7 @@ impl GraphicsWriter for Graphics640x480x16 { } } - fn set_pixel(&self, x: usize, y: usize, color: Color16Bit) { + fn set_pixel(&self, x: usize, y: usize, color: Color16) { self.set_write_mode_2(); self._set_pixel(x, y, color); } @@ -91,7 +91,7 @@ impl Graphics640x480x16 { /// Sets the vga to 'WriteMode::Mode0`. This also sets `GraphicsControllerIndex::SetReset` /// to the specified `color`, `GraphicsControllerIndex::EnableSetReset` to `0xFF` and /// `SequencerIndex::PlaneMask` to `PlaneMask::ALL_PLANES`. - pub fn set_write_mode_0(&self, color: Color16Bit) { + pub fn set_write_mode_0(&self, color: Color16) { let (mut vga, _frame_buffer) = self.get_frame_buffer(); vga.graphics_controller_registers.write_set_reset(color); vga.graphics_controller_registers @@ -121,7 +121,7 @@ impl Graphics640x480x16 { } #[inline] - fn _set_pixel(&self, x: usize, y: usize, color: Color16Bit) { + fn _set_pixel(&self, x: usize, y: usize, color: Color16) { let (mut vga, frame_buffer) = self.get_frame_buffer(); let offset = x / 8 + y * WIDTH_IN_BYTES; let pixel_mask = 0x80 >> (x & 0x07); diff --git a/src/writers/mod.rs b/src/writers/mod.rs index 2965ec3..b2e0b6a 100644 --- a/src/writers/mod.rs +++ b/src/writers/mod.rs @@ -5,7 +5,7 @@ mod text_40x50; mod text_80x25; use super::{ - colors::{Color16Bit, TextModeColor}, + colors::{Color16, TextModeColor}, drawing::Point, registers::CrtcControllerIndex, vga::{Vga, VGA}, @@ -44,7 +44,7 @@ impl ScreenCharacter { static BLANK_CHARACTER: ScreenCharacter = ScreenCharacter { character: b' ', - color: TextModeColor::new(Color16Bit::Yellow, Color16Bit::Black), + color: TextModeColor::new(Color16::Yellow, Color16::Black), }; /// A helper trait used to interact with various vga screens. @@ -73,8 +73,8 @@ pub trait TextWriter: Screen { } /// Clears the screen by setting all cells to `b' '` with - /// a background color of `Color16Bit::Black` and a foreground - /// color of `Color16Bit::Yellow`. + /// a background color of `Color16::Black` and a foreground + /// color of `Color16::Yellow`. fn clear_screen(&self) { let (_vga, frame_buffer) = self.get_frame_buffer(); let screen_size = self.get_width() * self.get_height(); diff --git a/src/writers/text_40x25.rs b/src/writers/text_40x25.rs index 545a10a..452d2d8 100644 --- a/src/writers/text_40x25.rs +++ b/src/writers/text_40x25.rs @@ -15,11 +15,11 @@ const HEIGHT: usize = 25; /// Basic usage: /// /// ```no_run -/// use vga::colors::{Color16Bit, TextModeColor}; +/// use vga::colors::{Color16, TextModeColor}; /// use vga::writers::{ScreenCharacter, TextWriter, Text40x25}; /// /// let text_mode = Text40x25::new(); -/// let color = TextModeColor::new(Color16Bit::Yellow, Color16Bit::Black); +/// let color = TextModeColor::new(Color16::Yellow, Color16::Black); /// let screen_character = ScreenCharacter::new(b'T', color); /// /// text_mode.set_mode(); diff --git a/src/writers/text_40x50.rs b/src/writers/text_40x50.rs index 02766b9..62b057b 100644 --- a/src/writers/text_40x50.rs +++ b/src/writers/text_40x50.rs @@ -15,11 +15,11 @@ const HEIGHT: usize = 50; /// Basic usage: /// /// ```no_run -/// use vga::colors::{Color16Bit, TextModeColor}; +/// use vga::colors::{Color16, TextModeColor}; /// use vga::writers::{ScreenCharacter, TextWriter, Text40x50}; /// /// let text_mode = Text40x50::new(); -/// let color = TextModeColor::new(Color16Bit::Yellow, Color16Bit::Black); +/// let color = TextModeColor::new(Color16::Yellow, Color16::Black); /// let screen_character = ScreenCharacter::new(b'T', color); /// /// text_mode.set_mode(); diff --git a/src/writers/text_80x25.rs b/src/writers/text_80x25.rs index ed0d473..72a4354 100644 --- a/src/writers/text_80x25.rs +++ b/src/writers/text_80x25.rs @@ -15,11 +15,11 @@ const HEIGHT: usize = 25; /// Basic usage: /// /// ```no_run -/// use vga::colors::{Color16Bit, TextModeColor}; +/// use vga::colors::{Color16, TextModeColor}; /// use vga::writers::{ScreenCharacter, TextWriter, Text80x25}; /// /// let text_mode = Text80x25::new(); -/// let color = TextModeColor::new(Color16Bit::Yellow, Color16Bit::Black); +/// let color = TextModeColor::new(Color16::Yellow, Color16::Black); /// let screen_character = ScreenCharacter::new(b'T', color); /// /// text_mode.set_mode(); diff --git a/testing/tests/vga.rs b/testing/tests/vga.rs index 3c772c4..52a7d6f 100644 --- a/testing/tests/vga.rs +++ b/testing/tests/vga.rs @@ -83,8 +83,8 @@ fn load_palette() { let mut palette = [0u8; PALETTE_SIZE]; let mut vga = VGA.lock(); - vga.load_palette(&DEFAULT_PALETTE); - vga.read_palette(&mut palette); + vga.color_palette_registers.load_palette(&DEFAULT_PALETTE); + vga.color_palette_registers.read_palette(&mut palette); for i in 0..PALETTE_SIZE { assert_eq!(palette[i], DEFAULT_PALETTE[i]); @@ -95,23 +95,30 @@ fn load_palette() { fn check_registers(vga: &mut Vga, configuration: &VgaConfiguration) { let emulation_mode = vga.get_emulation_mode(); - assert_eq!(vga.read_msr(), configuration.miscellaneous_output); + assert_eq!( + vga.general_registers.read_msr(), + configuration.miscellaneous_output + ); for (index, value) in configuration.sequencer_registers { - assert_eq!(vga.read_sequencer(*index), *value); + assert_eq!(vga.sequencer_registers.read(*index), *value); } for (index, value) in configuration.crtc_controller_registers { - assert_eq!(vga.read_crtc_controller(emulation_mode, *index), *value); + assert_eq!( + vga.crtc_controller_registers.read(emulation_mode, *index), + *value + ); } for (index, value) in configuration.graphics_controller_registers { - assert_eq!(vga.read_graphics_controller(*index), *value); + assert_eq!(vga.graphics_controller_registers.read(*index), *value); } for (index, value) in configuration.attribute_controller_registers { assert_eq!( - vga.read_attribute_controller(emulation_mode, *index), + vga.attribute_controller_registers + .read(emulation_mode, *index), *value ); }