Mods and docs

pull/2/head
Ryan Kennedy 2020-03-15 18:49:04 -05:00
parent fc585e1879
commit 3d3e82d31f
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.
pub const PALETTE_SIZE: usize = 768;

View File

@ -1,3 +1,5 @@
//! Common video configurations used in vga programming.
use super::registers::{
AttributeControllerIndex, CrtcControllerIndex, GraphicsControllerIndex, SequencerIndex,
};
@ -49,7 +51,7 @@ pub const MODE_40X25_CONFIGURATION: VgaConfiguration = VgaConfiguration {
(CrtcControllerIndex::VerticalSyncEnd, 0x8E),
(CrtcControllerIndex::VerticalDisplayEnableEnd, 0x8F),
(CrtcControllerIndex::Offset, 0x14),
(CrtcControllerIndex::UnderlineLocationRegister, 0x1F),
(CrtcControllerIndex::UnderlineLocation, 0x1F),
(CrtcControllerIndex::VerticalBlankingStart, 0x96),
(CrtcControllerIndex::VerticalBlankingEnd, 0xB9),
(CrtcControllerIndex::ModeControl, 0xA3),
@ -123,7 +125,7 @@ pub const MODE_40X50_CONFIGURATION: VgaConfiguration = VgaConfiguration {
(CrtcControllerIndex::VerticalSyncEnd, 0x8E),
(CrtcControllerIndex::VerticalDisplayEnableEnd, 0x8F),
(CrtcControllerIndex::Offset, 0x14),
(CrtcControllerIndex::UnderlineLocationRegister, 0x1F),
(CrtcControllerIndex::UnderlineLocation, 0x1F),
(CrtcControllerIndex::VerticalBlankingStart, 0x96),
(CrtcControllerIndex::VerticalBlankingEnd, 0xB9),
(CrtcControllerIndex::ModeControl, 0xA3),
@ -197,7 +199,7 @@ pub const MODE_80X25_CONFIGURATION: VgaConfiguration = VgaConfiguration {
(CrtcControllerIndex::VerticalSyncEnd, 0x0E),
(CrtcControllerIndex::VerticalDisplayEnableEnd, 0x8F),
(CrtcControllerIndex::Offset, 0x28),
(CrtcControllerIndex::UnderlineLocationRegister, 0x1F),
(CrtcControllerIndex::UnderlineLocation, 0x1F),
(CrtcControllerIndex::VerticalBlankingStart, 0x96),
(CrtcControllerIndex::VerticalBlankingEnd, 0xB9),
(CrtcControllerIndex::ModeControl, 0xA3),
@ -272,7 +274,7 @@ pub const MODE_640X480X16_CONFIGURATION: VgaConfiguration = VgaConfiguration {
(CrtcControllerIndex::VerticalSyncEnd, 0x0C),
(CrtcControllerIndex::VerticalDisplayEnableEnd, 0xDF),
(CrtcControllerIndex::Offset, 0x28),
(CrtcControllerIndex::UnderlineLocationRegister, 0x00),
(CrtcControllerIndex::UnderlineLocation, 0x00),
(CrtcControllerIndex::VerticalBlankingStart, 0xE7),
(CrtcControllerIndex::VerticalBlankingEnd, 0x04),
(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.
pub struct VgaFont {
/// Represents the number of characters contained in the font.
pub characters: u16,
/// Represents the height of the characters in bytes.
pub character_height: u16,
/// Represents the font data to be loaded in.
pub font_data: &'static [u8],
}

View File

@ -7,17 +7,9 @@
#![no_std]
#![warn(missing_docs)]
mod colors;
mod configurations;
mod fonts;
mod registers;
mod vga;
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};
pub mod colors;
pub mod configurations;
pub mod fonts;
pub mod registers;
pub mod vga;
pub mod writers;

View File

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

View File

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

View File

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