Mods and docs

This commit is contained in:
Ryan Kennedy 2020-03-15 18:49:04 -05:00
parent c8392a53aa
commit 9838cc7e70
7 changed files with 106 additions and 30 deletions

View file

@ -1,4 +1,4 @@
//! Common color structures used in vga. //! Common color structures used in vga programming.
/// Represents the size of the vga palette in bytes. /// Represents the size of the vga palette in bytes.
pub const PALETTE_SIZE: usize = 768; pub const PALETTE_SIZE: usize = 768;

View file

@ -1,3 +1,5 @@
//! Common video configurations used in vga programming.
use super::registers::{ use super::registers::{
AttributeControllerIndex, CrtcControllerIndex, GraphicsControllerIndex, SequencerIndex, AttributeControllerIndex, CrtcControllerIndex, GraphicsControllerIndex, SequencerIndex,
}; };
@ -49,7 +51,7 @@ pub const MODE_40X25_CONFIGURATION: VgaConfiguration = VgaConfiguration {
(CrtcControllerIndex::VerticalSyncEnd, 0x8E), (CrtcControllerIndex::VerticalSyncEnd, 0x8E),
(CrtcControllerIndex::VerticalDisplayEnableEnd, 0x8F), (CrtcControllerIndex::VerticalDisplayEnableEnd, 0x8F),
(CrtcControllerIndex::Offset, 0x14), (CrtcControllerIndex::Offset, 0x14),
(CrtcControllerIndex::UnderlineLocationRegister, 0x1F), (CrtcControllerIndex::UnderlineLocation, 0x1F),
(CrtcControllerIndex::VerticalBlankingStart, 0x96), (CrtcControllerIndex::VerticalBlankingStart, 0x96),
(CrtcControllerIndex::VerticalBlankingEnd, 0xB9), (CrtcControllerIndex::VerticalBlankingEnd, 0xB9),
(CrtcControllerIndex::ModeControl, 0xA3), (CrtcControllerIndex::ModeControl, 0xA3),
@ -123,7 +125,7 @@ pub const MODE_40X50_CONFIGURATION: VgaConfiguration = VgaConfiguration {
(CrtcControllerIndex::VerticalSyncEnd, 0x8E), (CrtcControllerIndex::VerticalSyncEnd, 0x8E),
(CrtcControllerIndex::VerticalDisplayEnableEnd, 0x8F), (CrtcControllerIndex::VerticalDisplayEnableEnd, 0x8F),
(CrtcControllerIndex::Offset, 0x14), (CrtcControllerIndex::Offset, 0x14),
(CrtcControllerIndex::UnderlineLocationRegister, 0x1F), (CrtcControllerIndex::UnderlineLocation, 0x1F),
(CrtcControllerIndex::VerticalBlankingStart, 0x96), (CrtcControllerIndex::VerticalBlankingStart, 0x96),
(CrtcControllerIndex::VerticalBlankingEnd, 0xB9), (CrtcControllerIndex::VerticalBlankingEnd, 0xB9),
(CrtcControllerIndex::ModeControl, 0xA3), (CrtcControllerIndex::ModeControl, 0xA3),
@ -197,7 +199,7 @@ pub const MODE_80X25_CONFIGURATION: VgaConfiguration = VgaConfiguration {
(CrtcControllerIndex::VerticalSyncEnd, 0x0E), (CrtcControllerIndex::VerticalSyncEnd, 0x0E),
(CrtcControllerIndex::VerticalDisplayEnableEnd, 0x8F), (CrtcControllerIndex::VerticalDisplayEnableEnd, 0x8F),
(CrtcControllerIndex::Offset, 0x28), (CrtcControllerIndex::Offset, 0x28),
(CrtcControllerIndex::UnderlineLocationRegister, 0x1F), (CrtcControllerIndex::UnderlineLocation, 0x1F),
(CrtcControllerIndex::VerticalBlankingStart, 0x96), (CrtcControllerIndex::VerticalBlankingStart, 0x96),
(CrtcControllerIndex::VerticalBlankingEnd, 0xB9), (CrtcControllerIndex::VerticalBlankingEnd, 0xB9),
(CrtcControllerIndex::ModeControl, 0xA3), (CrtcControllerIndex::ModeControl, 0xA3),
@ -272,7 +274,7 @@ pub const MODE_640X480X16_CONFIGURATION: VgaConfiguration = VgaConfiguration {
(CrtcControllerIndex::VerticalSyncEnd, 0x0C), (CrtcControllerIndex::VerticalSyncEnd, 0x0C),
(CrtcControllerIndex::VerticalDisplayEnableEnd, 0xDF), (CrtcControllerIndex::VerticalDisplayEnableEnd, 0xDF),
(CrtcControllerIndex::Offset, 0x28), (CrtcControllerIndex::Offset, 0x28),
(CrtcControllerIndex::UnderlineLocationRegister, 0x00), (CrtcControllerIndex::UnderlineLocation, 0x00),
(CrtcControllerIndex::VerticalBlankingStart, 0xE7), (CrtcControllerIndex::VerticalBlankingStart, 0xE7),
(CrtcControllerIndex::VerticalBlankingEnd, 0x04), (CrtcControllerIndex::VerticalBlankingEnd, 0x04),
(CrtcControllerIndex::ModeControl, 0xE3), (CrtcControllerIndex::ModeControl, 0xE3),

View file

@ -1,7 +1,12 @@
//! Common font structures used in vga programming.
/// Represents a font to be used for text mode. /// Represents a font to be used for text mode.
pub struct VgaFont { pub struct VgaFont {
/// Represents the number of characters contained in the font.
pub characters: u16, pub characters: u16,
/// Represents the height of the characters in bytes.
pub character_height: u16, pub character_height: u16,
/// Represents the font data to be loaded in.
pub font_data: &'static [u8], pub font_data: &'static [u8],
} }

View file

@ -7,17 +7,9 @@
#![no_std] #![no_std]
#![warn(missing_docs)] #![warn(missing_docs)]
mod colors; pub mod colors;
mod configurations; pub mod configurations;
mod fonts; pub mod fonts;
mod registers; pub mod registers;
mod vga; pub mod vga;
mod writers; pub mod writers;
pub use self::colors::{Color16Bit, TextModeColor, DEFAULT_PALETTE, PALETTE_SIZE};
pub use self::configurations::{
VgaConfiguration, MODE_40X25_CONFIGURATION, MODE_40X50_CONFIGURATION,
MODE_640X480X16_CONFIGURATION, MODE_80X25_CONFIGURATION,
};
pub use self::vga::{Vga, VideoMode, VGA};
pub use self::writers::{Graphics640x480x16, Text40x25, Text40x50, Text80x25};

View file

@ -1,3 +1,5 @@
//! Common registers used in vga programming.
use crate::colors::PALETTE_SIZE; use crate::colors::PALETTE_SIZE;
use x86_64::instructions::port::{Port, PortReadOnly, PortWriteOnly}; use x86_64::instructions::port::{Port, PortReadOnly, PortWriteOnly};
@ -28,10 +30,13 @@ const COLOR_PALETTE_DATA_ADDRESS: u16 = 0x3C9;
const COLOR_PALETTE_INDEX_READ_ADDRESS: u16 = 0x3C7; const COLOR_PALETTE_INDEX_READ_ADDRESS: u16 = 0x3C7;
const COLOR_PALETTE_INDEX_WRITE_ADDRESSS: u16 = 0x3C8; const COLOR_PALETTE_INDEX_WRITE_ADDRESSS: u16 = 0x3C8;
/// Represents a vga emulation mode.
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
#[repr(u8)] #[repr(u8)]
pub enum EmulationMode { pub enum EmulationMode {
/// Represents a monochrome emulation mode.
Mda = 0x0, Mda = 0x0,
/// Respresents a color emulation mode.
Cga = 0x1, Cga = 0x1,
} }
@ -45,14 +50,21 @@ impl From<u8> for EmulationMode {
} }
} }
/// Represents an index for the seqeuncer registers.
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
#[repr(u8)] #[repr(u8)]
pub enum SequencerIndex { pub enum SequencerIndex {
/// Represents the `Sequencer Reset` register index.
SequencerReset = 0x0, SequencerReset = 0x0,
/// Represents the `Clocking Mode` register index.
ClockingMode = 0x1, ClockingMode = 0x1,
/// Represents the Plane/Map mask register index.
PlaneMask = 0x2, PlaneMask = 0x2,
/// Represents the `Character Font` register index.
CharacterFont = 0x3, CharacterFont = 0x3,
/// Represents the `Memory Mode` register index.
MemoryMode = 0x4, MemoryMode = 0x4,
/// Represents the `Horizontal Character Counter Reset` register index.
CounterReset = 0x7, CounterReset = 0x7,
} }
@ -62,20 +74,33 @@ impl From<SequencerIndex> for u8 {
} }
} }
/// Represents an index for the graphics controller registers.
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
#[repr(u8)] #[repr(u8)]
pub enum GraphicsControllerIndex { pub enum GraphicsControllerIndex {
/// Represents the `Set/Reset` register index.
SetReset = 0x0, SetReset = 0x0,
/// Represents the `Enable Set/Reset` register index.
EnableSetReset = 0x1, EnableSetReset = 0x1,
/// Represents the `Color Compare` register index.
ColorCompare = 0x2, ColorCompare = 0x2,
/// Represents the `Data Rotate` register index.
DataRotate = 0x3, DataRotate = 0x3,
/// Represents the `Read Plane Select` register index.
ReadPlaneSelect = 0x4, ReadPlaneSelect = 0x4,
/// Represents the `Graphics Mode` register index.
GraphicsMode = 0x5, GraphicsMode = 0x5,
/// Represents the `Miscellaneous` register index.
Miscellaneous = 0x6, Miscellaneous = 0x6,
/// Represents the `Color Don't Care` register index.
ColorDontCare = 0x7, ColorDontCare = 0x7,
/// Represents the `Bit Mask` register index.
BitMask = 0x8, BitMask = 0x8,
/// Represents the `Address Mapping` register index.
AddressMapping = 0x10, AddressMapping = 0x10,
/// Represents the `Page Selector` register index.
PageSelector = 0x11, PageSelector = 0x11,
/// Represents the `Software Flags` register index.
SoftwareFlags = 0x18, SoftwareFlags = 0x18,
} }
@ -85,29 +110,51 @@ impl From<GraphicsControllerIndex> for u8 {
} }
} }
/// Represents an index for the attribute controller registers.
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
#[repr(u8)] #[repr(u8)]
pub enum AttributeControllerIndex { pub enum AttributeControllerIndex {
/// Represents the `Palette 0` register index.
PaletteRegister0 = 0x00, PaletteRegister0 = 0x00,
/// Represents the `Palette 1` register index.
PaletteRegister1 = 0x01, PaletteRegister1 = 0x01,
/// Represents the `Palette 2` register index.
PaletteRegister2 = 0x02, PaletteRegister2 = 0x02,
/// Represents the `Palette 3` register index.
PaletteRegister3 = 0x03, PaletteRegister3 = 0x03,
/// Represents the `Palette 4` register index.
PaletteRegister4 = 0x04, PaletteRegister4 = 0x04,
/// Represents the `Palette 5` register index.
PaletteRegister5 = 0x05, PaletteRegister5 = 0x05,
/// Represents the `Palette 6` register index.
PaletteRegister6 = 0x06, PaletteRegister6 = 0x06,
/// Represents the `Palette 7` register index.
PaletteRegister7 = 0x07, PaletteRegister7 = 0x07,
/// Represents the `Palette 8` register index.
PaletteRegister8 = 0x08, PaletteRegister8 = 0x08,
/// Represents the `Palette 9` register index.
PaletteRegister9 = 0x09, PaletteRegister9 = 0x09,
/// Represents the `Palette A` register index.
PaletteRegisterA = 0x0A, PaletteRegisterA = 0x0A,
/// Represents the `Palette B` register index.
PaletteRegisterB = 0x0B, PaletteRegisterB = 0x0B,
/// Represents the `Palette C` register index.
PaletteRegisterC = 0x0C, PaletteRegisterC = 0x0C,
/// Represents the `Palette D` register index.
PaletteRegisterD = 0x0D, PaletteRegisterD = 0x0D,
/// Represents the `Palette E` register index.
PaletteRegisterE = 0x0E, PaletteRegisterE = 0x0E,
/// Represents the `Palette F` register index.
PaletteRegisterF = 0x0F, PaletteRegisterF = 0x0F,
/// Represents the `Mode Control` register index.
ModeControl = 0x10, ModeControl = 0x10,
/// Represents the `Overscan Color` register index.
OverscanColor = 0x11, OverscanColor = 0x11,
/// Represents the `Memory Plane Enable` register index.
MemoryPlaneEnable = 0x12, MemoryPlaneEnable = 0x12,
/// Represents the `Horizontal Pixel Panning` register index.
HorizontalPixelPanning = 0x13, HorizontalPixelPanning = 0x13,
/// Represents the `Color Select` register index.
ColorSelect = 0x14, ColorSelect = 0x14,
} }
@ -117,35 +164,63 @@ impl From<AttributeControllerIndex> for u8 {
} }
} }
/// Represents an index for the crtc controller registers.
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
#[repr(u8)] #[repr(u8)]
pub enum CrtcControllerIndex { pub enum CrtcControllerIndex {
/// Represents the `Horizontal Total` register index.
HorizontalTotal = 0x00, HorizontalTotal = 0x00,
/// Represents the `Horizontal Display Enable End` register index.
HorizontalDisplayEnableEnd = 0x01, HorizontalDisplayEnableEnd = 0x01,
/// Represents the `Horizontal Blanking Start` register index.
HorizontalBlankingStart = 0x02, HorizontalBlankingStart = 0x02,
/// Represents the `Horizontal Blanking End` register index.
HorizontalBlankingEnd = 0x03, HorizontalBlankingEnd = 0x03,
/// Represents the `Horizontal Sync Start` register index.
HorizontalSyncStart = 0x04, HorizontalSyncStart = 0x04,
/// Represents the `Horizontal Sync End` register index.
HorizontalSyncEnd = 0x05, HorizontalSyncEnd = 0x05,
/// Represents the `Vertical Total` register index.
VeritcalTotal = 0x06, VeritcalTotal = 0x06,
/// Represents the `Overflow` register index.
Overflow = 0x07, Overflow = 0x07,
/// Represents the `Preset Row Scan` register index.
PresetRowScan = 0x08, PresetRowScan = 0x08,
/// Represents the `Maximum Scan Line` register index.
MaximumScanLine = 0x09, MaximumScanLine = 0x09,
/// Represents the `Text Cursor Start` register index.
TextCursorStart = 0x0A, TextCursorStart = 0x0A,
/// Represents the `Text Cursor End` register index.
TextCursorEnd = 0x0B, TextCursorEnd = 0x0B,
/// Represents the `Start Address High` register index.
StartAddressHigh = 0x0C, StartAddressHigh = 0x0C,
/// Represents the `Start Address Low` register index.
StartAddressLow = 0x0D, StartAddressLow = 0x0D,
/// Represents the `Text Cursor Location High` register index.
TextCursorLocationHigh = 0x0E, TextCursorLocationHigh = 0x0E,
/// Represents the `Text Cursor Location Low` register index.
TextCursorLocationLow = 0x0F, TextCursorLocationLow = 0x0F,
/// Represents the `Vertical Sync Start` register index.
VerticalSyncStart = 0x10, VerticalSyncStart = 0x10,
/// Represents the `Vertical Sync End` register index.
VerticalSyncEnd = 0x11, VerticalSyncEnd = 0x11,
/// Represents the `Vertical Display Enable End` register index
VerticalDisplayEnableEnd = 0x12, VerticalDisplayEnableEnd = 0x12,
/// Represents the `Offset` register index.
Offset = 0x13, Offset = 0x13,
UnderlineLocationRegister = 0x14, /// Represents the `Underline Location` register index.
UnderlineLocation = 0x14,
/// Represents the `Vertical Blanking Start` register index.
VerticalBlankingStart = 0x15, VerticalBlankingStart = 0x15,
/// Represents the `Vertical Blanking End` register index.
VerticalBlankingEnd = 0x16, VerticalBlankingEnd = 0x16,
/// Represents the `Mode Control` register index.
ModeControl = 0x17, ModeControl = 0x17,
/// Represents the `Line Compare` register index.
LineCompare = 0x18, LineCompare = 0x18,
/// Represents the `Memory Read Latch Data` register index.
MemoryReadLatchData = 0x22, MemoryReadLatchData = 0x22,
/// Represents the `Toggle State Of Attribute Controller` register index.
ToggleStateOfAttributeController = 0x24, ToggleStateOfAttributeController = 0x24,
} }
@ -156,7 +231,7 @@ impl From<CrtcControllerIndex> for u8 {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct GeneralRegisters { pub(crate) struct GeneralRegisters {
st00_read: PortReadOnly<u8>, st00_read: PortReadOnly<u8>,
st01_read_cga: PortReadOnly<u8>, st01_read_cga: PortReadOnly<u8>,
st01_read_mda: PortReadOnly<u8>, st01_read_mda: PortReadOnly<u8>,
@ -193,7 +268,7 @@ impl GeneralRegisters {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct SequencerRegisters { pub(crate) struct SequencerRegisters {
srx_index: Port<u8>, srx_index: Port<u8>,
srx_data: Port<u8>, srx_data: Port<u8>,
} }
@ -226,7 +301,7 @@ impl SequencerRegisters {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct GraphicsControllerRegisters { pub(crate) struct GraphicsControllerRegisters {
grx_index: Port<u8>, grx_index: Port<u8>,
grx_data: Port<u8>, grx_data: Port<u8>,
} }
@ -259,7 +334,7 @@ impl GraphicsControllerRegisters {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct AttributeControllerRegisters { pub(crate) struct AttributeControllerRegisters {
arx_index: Port<u8>, arx_index: Port<u8>,
arx_data: Port<u8>, arx_data: Port<u8>,
st01_read_cga: Port<u8>, st01_read_cga: Port<u8>,
@ -345,7 +420,7 @@ impl AttributeControllerRegisters {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct CrtcControllerRegisters { pub(crate) struct CrtcControllerRegisters {
crx_index_cga: Port<u8>, crx_index_cga: Port<u8>,
crx_index_mda: Port<u8>, crx_index_mda: Port<u8>,
crx_data_cga: Port<u8>, crx_data_cga: Port<u8>,
@ -396,7 +471,7 @@ impl CrtcControllerRegisters {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct ColorPaletteRegisters { pub(crate) struct ColorPaletteRegisters {
data_port: Port<u8>, data_port: Port<u8>,
index_read_port: Port<u8>, index_read_port: Port<u8>,
index_write_port: Port<u8>, index_write_port: Port<u8>,

View file

@ -1,3 +1,4 @@
//! Writers for common vga modes.
mod graphics_640x480x16; mod graphics_640x480x16;
mod text_40x25; mod text_40x25;
mod text_40x50; mod text_40x50;

View file

@ -6,11 +6,12 @@
use core::panic::PanicInfo; use core::panic::PanicInfo;
use testing::{gdt, interrupts, serial_print, serial_println}; use testing::{gdt, interrupts, serial_print, serial_println};
use vga::{ use vga::colors::{DEFAULT_PALETTE, PALETTE_SIZE};
Vga, VgaConfiguration, VideoMode, DEFAULT_PALETTE, MODE_40X25_CONFIGURATION, use vga::configurations::{
MODE_40X50_CONFIGURATION, MODE_640X480X16_CONFIGURATION, MODE_80X25_CONFIGURATION, VgaConfiguration, MODE_40X25_CONFIGURATION, MODE_40X50_CONFIGURATION,
PALETTE_SIZE, VGA, MODE_640X480X16_CONFIGURATION, MODE_80X25_CONFIGURATION,
}; };
use vga::vga::{Vga, VideoMode, VGA};
#[no_mangle] // don't mangle the name of this function #[no_mangle] // don't mangle the name of this function
pub extern "C" fn _start() -> ! { pub extern "C" fn _start() -> ! {