Moved general read/write out of vga

This commit is contained in:
Ryan Kennedy 2020-03-22 20:03:06 -05:00
parent b5906f42d5
commit 15825f7828
6 changed files with 24 additions and 81 deletions

View file

@ -156,74 +156,11 @@ impl Vga {
self.most_recent_video_mode self.most_recent_video_mode
} }
/// Returns the current value of the miscellaneous output register.
pub fn read_msr(&mut self) -> u8 {
self.general_registers.read_msr()
}
/// Returns the current value of the sequencer register, as determined by `index`.
pub fn read_sequencer(&mut self, index: SequencerIndex) -> u8 {
self.sequencer_registers.read(index)
}
/// Returns the current value of the graphics controller register, as determined by `index`.
pub fn read_graphics_controller(&mut self, index: GraphicsControllerIndex) -> u8 {
self.graphics_controller_registers.read(index)
}
/// Returns the current value of the attribute controller register, as determined by `emulation_mode`
/// and `index`.
pub fn read_attribute_controller(
&mut self,
emulation_mode: EmulationMode,
index: AttributeControllerIndex,
) -> u8 {
self.attribute_controller_registers
.read(emulation_mode, index)
}
/// Returns the current value of the crtc controller, as determined by `emulation_mode`
/// and `index`.
pub fn read_crtc_controller(
&mut self,
emulation_mode: EmulationMode,
index: CrtcControllerIndex,
) -> u8 {
self.crtc_controller_registers.read(emulation_mode, index)
}
/// Writes `value` to the crtc controller, as determined by `index`.
pub fn write_crtc_controller(
&mut self,
emulation_mode: EmulationMode,
index: CrtcControllerIndex,
value: u8,
) {
self.crtc_controller_registers
.write(emulation_mode, index, value);
}
/// Returns the current `EmulationMode` as determined by the miscellaneous output register. /// Returns the current `EmulationMode` as determined by the miscellaneous output register.
pub fn get_emulation_mode(&mut self) -> EmulationMode { pub fn get_emulation_mode(&mut self) -> EmulationMode {
EmulationMode::from(self.general_registers.read_msr() & 0x1) EmulationMode::from(self.general_registers.read_msr() & 0x1)
} }
/// Loads a new palette into the vga, as specified by `palette`.
///
/// Each palette must be `PALETTE_SIZE` bytes long, with every 3
/// bytes representing one color `(R, G, B)`.
pub fn load_palette(&mut self, palette: &[u8; PALETTE_SIZE]) {
self.color_palette_registers.load_palette(palette);
}
/// Reads the current vga palette into `palette`.
///
/// Each palette must be `PALETTE_SIZE` bytes long, with every 3
/// bytes representing one color `(R, G, B)`.
pub fn read_palette(&mut self, palette: &mut [u8; PALETTE_SIZE]) {
self.color_palette_registers.read_palette(palette);
}
/// Loads a vga text mode font as specified by `vga_font`. /// Loads a vga text mode font as specified by `vga_font`.
pub fn load_font(&mut self, vga_font: &VgaFont) { pub fn load_font(&mut self, vga_font: &VgaFont) {
// Save registers // Save registers

View file

@ -82,7 +82,7 @@ impl Graphics640x480x16 {
// Some bios mess up the palette when switching modes, // Some bios mess up the palette when switching modes,
// so explicitly set it. // so explicitly set it.
vga.load_palette(&DEFAULT_PALETTE); vga.color_palette_registers.load_palette(&DEFAULT_PALETTE);
} }
/// Returns the start of the `FrameBuffer` as `*mut u8` as /// Returns the start of the `FrameBuffer` as `*mut u8` as

View file

@ -84,9 +84,10 @@ pub trait TextWriter {
fn disable_cursor(&self) { fn disable_cursor(&self) {
let (mut vga, _frame_buffer) = self.get_frame_buffer(); let (mut vga, _frame_buffer) = self.get_frame_buffer();
let emulation_mode = vga.get_emulation_mode(); let emulation_mode = vga.get_emulation_mode();
let cursor_start = let cursor_start = vga
vga.read_crtc_controller(emulation_mode, CrtcControllerIndex::TextCursorStart); .crtc_controller_registers
vga.write_crtc_controller( .read(emulation_mode, CrtcControllerIndex::TextCursorStart);
vga.crtc_controller_registers.write(
emulation_mode, emulation_mode,
CrtcControllerIndex::TextCursorStart, CrtcControllerIndex::TextCursorStart,
cursor_start | 0x20, cursor_start | 0x20,
@ -97,9 +98,10 @@ pub trait TextWriter {
fn enable_cursor(&self) { fn enable_cursor(&self) {
let (mut vga, _frame_buffer) = self.get_frame_buffer(); let (mut vga, _frame_buffer) = self.get_frame_buffer();
let emulation_mode = vga.get_emulation_mode(); let emulation_mode = vga.get_emulation_mode();
let cursor_start = let cursor_start = vga
vga.read_crtc_controller(emulation_mode, CrtcControllerIndex::TextCursorStart); .crtc_controller_registers
vga.write_crtc_controller( .read(emulation_mode, CrtcControllerIndex::TextCursorStart);
vga.crtc_controller_registers.write(
emulation_mode, emulation_mode,
CrtcControllerIndex::TextCursorStart, CrtcControllerIndex::TextCursorStart,
cursor_start & 0xDF, cursor_start & 0xDF,
@ -122,16 +124,20 @@ pub trait TextWriter {
fn set_cursor(&self, scan_line_start: u8, scan_line_end: u8) { fn set_cursor(&self, scan_line_start: u8, scan_line_end: u8) {
let (mut vga, _frame_buffer) = self.get_frame_buffer(); let (mut vga, _frame_buffer) = self.get_frame_buffer();
let emulation_mode = vga.get_emulation_mode(); let emulation_mode = vga.get_emulation_mode();
let cursor_start = let cursor_start = vga
vga.read_crtc_controller(emulation_mode, CrtcControllerIndex::TextCursorStart) & 0xC0; .crtc_controller_registers
let cursor_end = .read(emulation_mode, CrtcControllerIndex::TextCursorStart)
vga.read_crtc_controller(emulation_mode, CrtcControllerIndex::TextCursorEnd) & 0xE0; & 0xC0;
vga.write_crtc_controller( let cursor_end = vga
.crtc_controller_registers
.read(emulation_mode, CrtcControllerIndex::TextCursorEnd)
& 0xE0;
vga.crtc_controller_registers.write(
emulation_mode, emulation_mode,
CrtcControllerIndex::TextCursorStart, CrtcControllerIndex::TextCursorStart,
cursor_start | scan_line_start, cursor_start | scan_line_start,
); );
vga.write_crtc_controller( vga.crtc_controller_registers.write(
emulation_mode, emulation_mode,
CrtcControllerIndex::TextCursorEnd, CrtcControllerIndex::TextCursorEnd,
cursor_end | scan_line_end, cursor_end | scan_line_end,
@ -146,12 +152,12 @@ pub trait TextWriter {
let emulation_mode = vga.get_emulation_mode(); let emulation_mode = vga.get_emulation_mode();
let cursor_start = offset & 0xFF; let cursor_start = offset & 0xFF;
let cursor_end = (offset >> 8) & 0xFF; let cursor_end = (offset >> 8) & 0xFF;
vga.write_crtc_controller( vga.crtc_controller_registers.write(
emulation_mode, emulation_mode,
CrtcControllerIndex::TextCursorLocationLow, CrtcControllerIndex::TextCursorLocationLow,
cursor_start as u8, cursor_start as u8,
); );
vga.write_crtc_controller( vga.crtc_controller_registers.write(
emulation_mode, emulation_mode,
CrtcControllerIndex::TextCursorLocationHigh, CrtcControllerIndex::TextCursorLocationHigh,
cursor_end as u8, cursor_end as u8,

View file

@ -45,7 +45,7 @@ impl TextWriter for Text40x25 {
// Some bios mess up the palette when switching modes, // Some bios mess up the palette when switching modes,
// so explicitly set it. // so explicitly set it.
vga.load_palette(&DEFAULT_PALETTE); vga.color_palette_registers.load_palette(&DEFAULT_PALETTE);
vga.load_font(&TEXT_8X16_FONT); vga.load_font(&TEXT_8X16_FONT);
} }
} }

View file

@ -45,7 +45,7 @@ impl TextWriter for Text40x50 {
// Some bios mess up the palette when switching modes, // Some bios mess up the palette when switching modes,
// so explicitly set it. // so explicitly set it.
vga.load_palette(&DEFAULT_PALETTE); vga.color_palette_registers.load_palette(&DEFAULT_PALETTE);
vga.load_font(&TEXT_8X8_FONT); vga.load_font(&TEXT_8X8_FONT);
} }
} }

View file

@ -44,7 +44,7 @@ impl TextWriter for Text80x25 {
// Some bios mess up the palette when switching modes, // Some bios mess up the palette when switching modes,
// so explicitly set it. // so explicitly set it.
vga.load_palette(&DEFAULT_PALETTE); vga.color_palette_registers.load_palette(&DEFAULT_PALETTE);
vga.load_font(&TEXT_8X16_FONT); vga.load_font(&TEXT_8X16_FONT);
} }
} }