vga/src/configurations.rs

318 lines
16 KiB
Rust
Raw Normal View History

2020-03-15 18:49:04 -05:00
//! Common video configurations used in vga programming.
2020-03-12 12:34:13 -05:00
use super::registers::{
2020-03-12 12:10:18 -05:00
AttributeControllerIndex, CrtcControllerIndex, GraphicsControllerIndex, SequencerIndex,
};
/// Represents a set of vga registers for a given mode.
#[derive(Debug)]
pub struct VgaConfiguration {
2020-03-14 22:55:48 -05:00
/// Represents the configuration value for the miscellaneous output register.
2020-03-12 12:10:18 -05:00
pub miscellaneous_output: u8,
2020-03-14 22:55:48 -05:00
/// Represents the configuration values for the sequencer registers.
2020-03-12 12:10:18 -05:00
pub sequencer_registers: &'static [(SequencerIndex, u8)],
2020-03-14 22:55:48 -05:00
/// Represents the configuration values for the crtc controller registers.
2020-03-12 12:10:18 -05:00
pub crtc_controller_registers: &'static [(CrtcControllerIndex, u8)],
2020-03-14 22:55:48 -05:00
/// Represents the configuration values for the graphics controller registers.
2020-03-12 12:10:18 -05:00
pub graphics_controller_registers: &'static [(GraphicsControllerIndex, u8)],
2020-03-14 22:55:48 -05:00
/// Represents the configuration values for the attribute controller registers.
2020-03-12 12:10:18 -05:00
pub attribute_controller_registers: &'static [(AttributeControllerIndex, u8)],
}
/// Register values for Vga mode 40x25 Text.
pub const MODE_40X25_CONFIGURATION: VgaConfiguration = VgaConfiguration {
// Configuration values acquired from https://www.singlix.com/trdos/archive/vga/Graphics%20in%20pmode.pdf
miscellaneous_output: 0x67,
sequencer_registers: &[
(SequencerIndex::SequencerReset, 0x03),
(SequencerIndex::ClockingMode, 0x08),
(SequencerIndex::PlaneMask, 0x03),
(SequencerIndex::CharacterFont, 0x00),
(SequencerIndex::MemoryMode, 0x02),
],
crtc_controller_registers: &[
(CrtcControllerIndex::HorizontalTotal, 0x2D),
(CrtcControllerIndex::HorizontalDisplayEnableEnd, 0x27),
(CrtcControllerIndex::HorizontalBlankingStart, 0x28),
(CrtcControllerIndex::HorizontalBlankingEnd, 0x90),
(CrtcControllerIndex::HorizontalSyncStart, 0x2B),
(CrtcControllerIndex::HorizontalSyncEnd, 0xA0),
(CrtcControllerIndex::VeritcalTotal, 0xBF),
(CrtcControllerIndex::Overflow, 0x1F),
(CrtcControllerIndex::PresetRowScan, 0x00),
(CrtcControllerIndex::MaximumScanLine, 0x4F),
2020-03-16 19:00:11 -05:00
(CrtcControllerIndex::TextCursorStart, 0x0D),
(CrtcControllerIndex::TextCursorEnd, 0x0E),
2020-03-12 12:10:18 -05:00
(CrtcControllerIndex::StartAddressHigh, 0x00),
(CrtcControllerIndex::StartAddressLow, 0x00),
(CrtcControllerIndex::TextCursorLocationHigh, 0x00),
(CrtcControllerIndex::TextCursorLocationLow, 0xA0),
(CrtcControllerIndex::VerticalSyncStart, 0x9C),
(CrtcControllerIndex::VerticalSyncEnd, 0x8E),
(CrtcControllerIndex::VerticalDisplayEnableEnd, 0x8F),
(CrtcControllerIndex::Offset, 0x14),
2020-03-15 18:49:04 -05:00
(CrtcControllerIndex::UnderlineLocation, 0x1F),
2020-03-12 12:10:18 -05:00
(CrtcControllerIndex::VerticalBlankingStart, 0x96),
(CrtcControllerIndex::VerticalBlankingEnd, 0xB9),
(CrtcControllerIndex::ModeControl, 0xA3),
(CrtcControllerIndex::LineCompare, 0xFF),
],
graphics_controller_registers: &[
(GraphicsControllerIndex::SetReset, 0x00),
(GraphicsControllerIndex::EnableSetReset, 0x00),
(GraphicsControllerIndex::ColorCompare, 0x00),
(GraphicsControllerIndex::DataRotate, 0x00),
(GraphicsControllerIndex::ReadPlaneSelect, 0x00),
(GraphicsControllerIndex::GraphicsMode, 0x10),
(GraphicsControllerIndex::Miscellaneous, 0x0E),
(GraphicsControllerIndex::ColorDontCare, 0x00),
(GraphicsControllerIndex::BitMask, 0xFF),
],
attribute_controller_registers: &[
(AttributeControllerIndex::PaletteRegister0, 0x00),
(AttributeControllerIndex::PaletteRegister1, 0x01),
(AttributeControllerIndex::PaletteRegister2, 0x02),
(AttributeControllerIndex::PaletteRegister3, 0x03),
(AttributeControllerIndex::PaletteRegister4, 0x04),
(AttributeControllerIndex::PaletteRegister5, 0x05),
(AttributeControllerIndex::PaletteRegister6, 0x14),
(AttributeControllerIndex::PaletteRegister7, 0x07),
(AttributeControllerIndex::PaletteRegister8, 0x38),
(AttributeControllerIndex::PaletteRegister9, 0x39),
(AttributeControllerIndex::PaletteRegisterA, 0x3A),
(AttributeControllerIndex::PaletteRegisterB, 0x3B),
(AttributeControllerIndex::PaletteRegisterC, 0x3C),
(AttributeControllerIndex::PaletteRegisterD, 0x3D),
(AttributeControllerIndex::PaletteRegisterE, 0x3E),
(AttributeControllerIndex::PaletteRegisterF, 0x3F),
(AttributeControllerIndex::ModeControl, 0x0C),
(AttributeControllerIndex::OverscanColor, 0x00),
(AttributeControllerIndex::MemoryPlaneEnable, 0x0F),
(AttributeControllerIndex::HorizontalPixelPanning, 0x08),
(AttributeControllerIndex::ColorSelect, 0x00),
],
};
/// Register values for Vga mode 40x50 Text.
pub const MODE_40X50_CONFIGURATION: VgaConfiguration = VgaConfiguration {
// Configuration values acquired from https://www.singlix.com/trdos/archive/vga/Graphics%20in%20pmode.pdf
miscellaneous_output: 0x67,
sequencer_registers: &[
(SequencerIndex::SequencerReset, 0x03),
(SequencerIndex::ClockingMode, 0x08),
(SequencerIndex::PlaneMask, 0x03),
(SequencerIndex::CharacterFont, 0x00),
(SequencerIndex::MemoryMode, 0x02),
],
crtc_controller_registers: &[
(CrtcControllerIndex::HorizontalTotal, 0x2D),
(CrtcControllerIndex::HorizontalDisplayEnableEnd, 0x27),
(CrtcControllerIndex::HorizontalBlankingStart, 0x28),
(CrtcControllerIndex::HorizontalBlankingEnd, 0x90),
(CrtcControllerIndex::HorizontalSyncStart, 0x2B),
(CrtcControllerIndex::HorizontalSyncEnd, 0xA0),
(CrtcControllerIndex::VeritcalTotal, 0xBF),
(CrtcControllerIndex::Overflow, 0x1F),
(CrtcControllerIndex::PresetRowScan, 0x00),
(CrtcControllerIndex::MaximumScanLine, 0x47),
2020-03-16 19:00:11 -05:00
(CrtcControllerIndex::TextCursorStart, 0x06),
(CrtcControllerIndex::TextCursorEnd, 0x07),
2020-03-12 12:10:18 -05:00
(CrtcControllerIndex::StartAddressHigh, 0x00),
(CrtcControllerIndex::StartAddressLow, 0x00),
(CrtcControllerIndex::TextCursorLocationHigh, 0x04),
(CrtcControllerIndex::TextCursorLocationLow, 0x60),
(CrtcControllerIndex::VerticalSyncStart, 0x9C),
(CrtcControllerIndex::VerticalSyncEnd, 0x8E),
(CrtcControllerIndex::VerticalDisplayEnableEnd, 0x8F),
(CrtcControllerIndex::Offset, 0x14),
2020-03-15 18:49:04 -05:00
(CrtcControllerIndex::UnderlineLocation, 0x1F),
2020-03-12 12:10:18 -05:00
(CrtcControllerIndex::VerticalBlankingStart, 0x96),
(CrtcControllerIndex::VerticalBlankingEnd, 0xB9),
(CrtcControllerIndex::ModeControl, 0xA3),
(CrtcControllerIndex::LineCompare, 0xFF),
],
graphics_controller_registers: &[
(GraphicsControllerIndex::SetReset, 0x00),
(GraphicsControllerIndex::EnableSetReset, 0x00),
(GraphicsControllerIndex::ColorCompare, 0x00),
(GraphicsControllerIndex::DataRotate, 0x00),
(GraphicsControllerIndex::ReadPlaneSelect, 0x00),
(GraphicsControllerIndex::GraphicsMode, 0x10),
(GraphicsControllerIndex::Miscellaneous, 0x0E),
(GraphicsControllerIndex::ColorDontCare, 0x00),
(GraphicsControllerIndex::BitMask, 0xFF),
],
attribute_controller_registers: &[
(AttributeControllerIndex::PaletteRegister0, 0x00),
(AttributeControllerIndex::PaletteRegister1, 0x01),
(AttributeControllerIndex::PaletteRegister2, 0x02),
(AttributeControllerIndex::PaletteRegister3, 0x03),
(AttributeControllerIndex::PaletteRegister4, 0x04),
(AttributeControllerIndex::PaletteRegister5, 0x05),
(AttributeControllerIndex::PaletteRegister6, 0x14),
(AttributeControllerIndex::PaletteRegister7, 0x07),
(AttributeControllerIndex::PaletteRegister8, 0x38),
(AttributeControllerIndex::PaletteRegister9, 0x39),
(AttributeControllerIndex::PaletteRegisterA, 0x3A),
(AttributeControllerIndex::PaletteRegisterB, 0x3B),
(AttributeControllerIndex::PaletteRegisterC, 0x3C),
(AttributeControllerIndex::PaletteRegisterD, 0x3D),
(AttributeControllerIndex::PaletteRegisterE, 0x3E),
(AttributeControllerIndex::PaletteRegisterF, 0x3F),
(AttributeControllerIndex::ModeControl, 0x0C),
(AttributeControllerIndex::OverscanColor, 0x00),
(AttributeControllerIndex::MemoryPlaneEnable, 0x0F),
(AttributeControllerIndex::HorizontalPixelPanning, 0x08),
(AttributeControllerIndex::ColorSelect, 0x00),
],
};
/// Register values for Vga mode 80x25 Text.
pub const MODE_80X25_CONFIGURATION: VgaConfiguration = VgaConfiguration {
// Configuration values acquired from https://www.singlix.com/trdos/archive/vga/Graphics%20in%20pmode.pdf
miscellaneous_output: 0x67,
sequencer_registers: &[
(SequencerIndex::SequencerReset, 0x03),
(SequencerIndex::ClockingMode, 0x00),
(SequencerIndex::PlaneMask, 0x03),
(SequencerIndex::CharacterFont, 0x00),
(SequencerIndex::MemoryMode, 0x02),
],
crtc_controller_registers: &[
(CrtcControllerIndex::HorizontalTotal, 0x5F),
(CrtcControllerIndex::HorizontalDisplayEnableEnd, 0x4F),
(CrtcControllerIndex::HorizontalBlankingStart, 0x50),
(CrtcControllerIndex::HorizontalBlankingEnd, 0x82),
(CrtcControllerIndex::HorizontalSyncStart, 0x55),
(CrtcControllerIndex::HorizontalSyncEnd, 0x81),
(CrtcControllerIndex::VeritcalTotal, 0xBF),
(CrtcControllerIndex::Overflow, 0x1F),
(CrtcControllerIndex::PresetRowScan, 0x00),
(CrtcControllerIndex::MaximumScanLine, 0x4F),
(CrtcControllerIndex::TextCursorStart, 0x0D),
(CrtcControllerIndex::TextCursorEnd, 0x0E),
(CrtcControllerIndex::StartAddressHigh, 0x00),
(CrtcControllerIndex::StartAddressLow, 0x00),
(CrtcControllerIndex::TextCursorLocationHigh, 0x00),
(CrtcControllerIndex::TextCursorLocationLow, 0x50),
(CrtcControllerIndex::VerticalSyncStart, 0x9C),
(CrtcControllerIndex::VerticalSyncEnd, 0x0E),
(CrtcControllerIndex::VerticalDisplayEnableEnd, 0x8F),
(CrtcControllerIndex::Offset, 0x28),
2020-03-15 18:49:04 -05:00
(CrtcControllerIndex::UnderlineLocation, 0x1F),
2020-03-12 12:10:18 -05:00
(CrtcControllerIndex::VerticalBlankingStart, 0x96),
(CrtcControllerIndex::VerticalBlankingEnd, 0xB9),
(CrtcControllerIndex::ModeControl, 0xA3),
(CrtcControllerIndex::LineCompare, 0xFF),
],
graphics_controller_registers: &[
(GraphicsControllerIndex::SetReset, 0x00),
(GraphicsControllerIndex::EnableSetReset, 0x00),
(GraphicsControllerIndex::ColorCompare, 0x00),
(GraphicsControllerIndex::DataRotate, 0x00),
(GraphicsControllerIndex::ReadPlaneSelect, 0x00),
(GraphicsControllerIndex::GraphicsMode, 0x10),
(GraphicsControllerIndex::Miscellaneous, 0x0E),
(GraphicsControllerIndex::ColorDontCare, 0x00),
(GraphicsControllerIndex::BitMask, 0xFF),
],
attribute_controller_registers: &[
(AttributeControllerIndex::PaletteRegister0, 0x00),
(AttributeControllerIndex::PaletteRegister1, 0x01),
(AttributeControllerIndex::PaletteRegister2, 0x02),
(AttributeControllerIndex::PaletteRegister3, 0x03),
(AttributeControllerIndex::PaletteRegister4, 0x04),
(AttributeControllerIndex::PaletteRegister5, 0x05),
(AttributeControllerIndex::PaletteRegister6, 0x14),
(AttributeControllerIndex::PaletteRegister7, 0x07),
(AttributeControllerIndex::PaletteRegister8, 0x38),
(AttributeControllerIndex::PaletteRegister9, 0x39),
(AttributeControllerIndex::PaletteRegisterA, 0x3A),
(AttributeControllerIndex::PaletteRegisterB, 0x3B),
(AttributeControllerIndex::PaletteRegisterC, 0x3C),
(AttributeControllerIndex::PaletteRegisterD, 0x3D),
(AttributeControllerIndex::PaletteRegisterE, 0x3E),
(AttributeControllerIndex::PaletteRegisterF, 0x3F),
(AttributeControllerIndex::ModeControl, 0x0C),
(AttributeControllerIndex::OverscanColor, 0x00),
(AttributeControllerIndex::MemoryPlaneEnable, 0x0F),
(AttributeControllerIndex::HorizontalPixelPanning, 0x08),
(AttributeControllerIndex::ColorSelect, 0x00),
],
};
/// Register values for Vga mode 640x480x16 Graphics.
pub const MODE_640X480X16_CONFIGURATION: VgaConfiguration = VgaConfiguration {
// Configuration values acquired from https://www.singlix.com/trdos/archive/vga/Graphics%20in%20pmode.pdf
// and https://forum.osdev.org/viewtopic.php?f=1&t=20137&hilit=640x480x16
miscellaneous_output: 0xE3,
sequencer_registers: &[
(SequencerIndex::SequencerReset, 0x03),
(SequencerIndex::ClockingMode, 0x01),
(SequencerIndex::PlaneMask, 0x08),
(SequencerIndex::CharacterFont, 0x00),
(SequencerIndex::MemoryMode, 0x06),
],
crtc_controller_registers: &[
(CrtcControllerIndex::HorizontalTotal, 0x5F),
(CrtcControllerIndex::HorizontalDisplayEnableEnd, 0x4F),
(CrtcControllerIndex::HorizontalBlankingStart, 0x50),
(CrtcControllerIndex::HorizontalBlankingEnd, 0x82),
(CrtcControllerIndex::HorizontalSyncStart, 0x54),
(CrtcControllerIndex::HorizontalSyncEnd, 0x80),
(CrtcControllerIndex::VeritcalTotal, 0x0B),
(CrtcControllerIndex::Overflow, 0x3E),
(CrtcControllerIndex::PresetRowScan, 0x00),
(CrtcControllerIndex::MaximumScanLine, 0x40),
(CrtcControllerIndex::TextCursorStart, 0x00),
(CrtcControllerIndex::TextCursorEnd, 0x00),
(CrtcControllerIndex::StartAddressHigh, 0x00),
(CrtcControllerIndex::StartAddressLow, 0x00),
(CrtcControllerIndex::TextCursorLocationHigh, 0x00),
(CrtcControllerIndex::TextCursorLocationLow, 0x00),
(CrtcControllerIndex::VerticalSyncStart, 0xEA),
(CrtcControllerIndex::VerticalSyncEnd, 0x0C),
(CrtcControllerIndex::VerticalDisplayEnableEnd, 0xDF),
(CrtcControllerIndex::Offset, 0x28),
2020-03-15 18:49:04 -05:00
(CrtcControllerIndex::UnderlineLocation, 0x00),
2020-03-12 12:10:18 -05:00
(CrtcControllerIndex::VerticalBlankingStart, 0xE7),
(CrtcControllerIndex::VerticalBlankingEnd, 0x04),
(CrtcControllerIndex::ModeControl, 0xE3),
(CrtcControllerIndex::LineCompare, 0xFF),
],
graphics_controller_registers: &[
(GraphicsControllerIndex::SetReset, 0x00),
(GraphicsControllerIndex::EnableSetReset, 0x00),
(GraphicsControllerIndex::ColorCompare, 0x00),
(GraphicsControllerIndex::DataRotate, 0x00),
(GraphicsControllerIndex::ReadPlaneSelect, 0x03),
(GraphicsControllerIndex::GraphicsMode, 0x00),
(GraphicsControllerIndex::Miscellaneous, 0x05),
(GraphicsControllerIndex::ColorDontCare, 0x0F),
(GraphicsControllerIndex::BitMask, 0xFF),
],
attribute_controller_registers: &[
(AttributeControllerIndex::PaletteRegister0, 0x00),
(AttributeControllerIndex::PaletteRegister1, 0x01),
(AttributeControllerIndex::PaletteRegister2, 0x02),
(AttributeControllerIndex::PaletteRegister3, 0x03),
(AttributeControllerIndex::PaletteRegister4, 0x04),
(AttributeControllerIndex::PaletteRegister5, 0x05),
(AttributeControllerIndex::PaletteRegister6, 0x14),
(AttributeControllerIndex::PaletteRegister7, 0x07),
(AttributeControllerIndex::PaletteRegister8, 0x38),
(AttributeControllerIndex::PaletteRegister9, 0x39),
(AttributeControllerIndex::PaletteRegisterA, 0x3A),
(AttributeControllerIndex::PaletteRegisterB, 0x3B),
(AttributeControllerIndex::PaletteRegisterC, 0x3C),
(AttributeControllerIndex::PaletteRegisterD, 0x3D),
(AttributeControllerIndex::PaletteRegisterE, 0x3E),
(AttributeControllerIndex::PaletteRegisterF, 0x3F),
(AttributeControllerIndex::ModeControl, 0x01),
(AttributeControllerIndex::OverscanColor, 0x00),
(AttributeControllerIndex::MemoryPlaneEnable, 0x0F),
(AttributeControllerIndex::HorizontalPixelPanning, 0x00),
(AttributeControllerIndex::ColorSelect, 0x00),
],
};