From 15825f7828d0aaba7a059a8d5d989e7cdeb39a7a Mon Sep 17 00:00:00 2001 From: Ryan Kennedy Date: Sun, 22 Mar 2020 20:03:06 -0500 Subject: [PATCH] Moved general read/write out of vga --- src/vga.rs | 63 ------------------------------ src/writers/graphics_640x480x16.rs | 2 +- src/writers/mod.rs | 34 +++++++++------- src/writers/text_40x25.rs | 2 +- src/writers/text_40x50.rs | 2 +- src/writers/text_80x25.rs | 2 +- 6 files changed, 24 insertions(+), 81 deletions(-) diff --git a/src/vga.rs b/src/vga.rs index 81ecdc2..c7a361b 100644 --- a/src/vga.rs +++ b/src/vga.rs @@ -156,74 +156,11 @@ impl Vga { 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. pub fn get_emulation_mode(&mut self) -> EmulationMode { 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`. pub fn load_font(&mut self, vga_font: &VgaFont) { // Save registers diff --git a/src/writers/graphics_640x480x16.rs b/src/writers/graphics_640x480x16.rs index 7a186ef..dcace91 100644 --- a/src/writers/graphics_640x480x16.rs +++ b/src/writers/graphics_640x480x16.rs @@ -82,7 +82,7 @@ impl Graphics640x480x16 { // Some bios mess up the palette when switching modes, // 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 diff --git a/src/writers/mod.rs b/src/writers/mod.rs index 02719c2..1154faa 100644 --- a/src/writers/mod.rs +++ b/src/writers/mod.rs @@ -84,9 +84,10 @@ pub trait TextWriter { fn disable_cursor(&self) { let (mut vga, _frame_buffer) = self.get_frame_buffer(); let emulation_mode = vga.get_emulation_mode(); - let cursor_start = - vga.read_crtc_controller(emulation_mode, CrtcControllerIndex::TextCursorStart); - vga.write_crtc_controller( + let cursor_start = vga + .crtc_controller_registers + .read(emulation_mode, CrtcControllerIndex::TextCursorStart); + vga.crtc_controller_registers.write( emulation_mode, CrtcControllerIndex::TextCursorStart, cursor_start | 0x20, @@ -97,9 +98,10 @@ pub trait TextWriter { fn enable_cursor(&self) { let (mut vga, _frame_buffer) = self.get_frame_buffer(); let emulation_mode = vga.get_emulation_mode(); - let cursor_start = - vga.read_crtc_controller(emulation_mode, CrtcControllerIndex::TextCursorStart); - vga.write_crtc_controller( + let cursor_start = vga + .crtc_controller_registers + .read(emulation_mode, CrtcControllerIndex::TextCursorStart); + vga.crtc_controller_registers.write( emulation_mode, CrtcControllerIndex::TextCursorStart, cursor_start & 0xDF, @@ -122,16 +124,20 @@ pub trait TextWriter { fn set_cursor(&self, scan_line_start: u8, scan_line_end: u8) { let (mut vga, _frame_buffer) = self.get_frame_buffer(); let emulation_mode = vga.get_emulation_mode(); - let cursor_start = - vga.read_crtc_controller(emulation_mode, CrtcControllerIndex::TextCursorStart) & 0xC0; - let cursor_end = - vga.read_crtc_controller(emulation_mode, CrtcControllerIndex::TextCursorEnd) & 0xE0; - vga.write_crtc_controller( + let cursor_start = vga + .crtc_controller_registers + .read(emulation_mode, CrtcControllerIndex::TextCursorStart) + & 0xC0; + let cursor_end = vga + .crtc_controller_registers + .read(emulation_mode, CrtcControllerIndex::TextCursorEnd) + & 0xE0; + vga.crtc_controller_registers.write( emulation_mode, CrtcControllerIndex::TextCursorStart, cursor_start | scan_line_start, ); - vga.write_crtc_controller( + vga.crtc_controller_registers.write( emulation_mode, CrtcControllerIndex::TextCursorEnd, cursor_end | scan_line_end, @@ -146,12 +152,12 @@ pub trait TextWriter { let emulation_mode = vga.get_emulation_mode(); let cursor_start = offset & 0xFF; let cursor_end = (offset >> 8) & 0xFF; - vga.write_crtc_controller( + vga.crtc_controller_registers.write( emulation_mode, CrtcControllerIndex::TextCursorLocationLow, cursor_start as u8, ); - vga.write_crtc_controller( + vga.crtc_controller_registers.write( emulation_mode, CrtcControllerIndex::TextCursorLocationHigh, cursor_end as u8, diff --git a/src/writers/text_40x25.rs b/src/writers/text_40x25.rs index 5eb92f2..29f9cd8 100644 --- a/src/writers/text_40x25.rs +++ b/src/writers/text_40x25.rs @@ -45,7 +45,7 @@ impl TextWriter for Text40x25 { // Some bios mess up the palette when switching modes, // so explicitly set it. - vga.load_palette(&DEFAULT_PALETTE); + vga.color_palette_registers.load_palette(&DEFAULT_PALETTE); vga.load_font(&TEXT_8X16_FONT); } } diff --git a/src/writers/text_40x50.rs b/src/writers/text_40x50.rs index ac604f4..e7a45c5 100644 --- a/src/writers/text_40x50.rs +++ b/src/writers/text_40x50.rs @@ -45,7 +45,7 @@ impl TextWriter for Text40x50 { // Some bios mess up the palette when switching modes, // so explicitly set it. - vga.load_palette(&DEFAULT_PALETTE); + vga.color_palette_registers.load_palette(&DEFAULT_PALETTE); vga.load_font(&TEXT_8X8_FONT); } } diff --git a/src/writers/text_80x25.rs b/src/writers/text_80x25.rs index aadb975..9929755 100644 --- a/src/writers/text_80x25.rs +++ b/src/writers/text_80x25.rs @@ -44,7 +44,7 @@ impl TextWriter for Text80x25 { // Some bios mess up the palette when switching modes, // so explicitly set it. - vga.load_palette(&DEFAULT_PALETTE); + vga.color_palette_registers.load_palette(&DEFAULT_PALETTE); vga.load_font(&TEXT_8X16_FONT); } }