From 693d861a4e6210c97b2163004697bc372932bc00 Mon Sep 17 00:00:00 2001 From: Able Date: Mon, 5 Dec 2022 07:27:10 -0600 Subject: [PATCH] update --- drivers/graphics/vgable/src/main.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/drivers/graphics/vgable/src/main.rs b/drivers/graphics/vgable/src/main.rs index efd0daf..23268a2 100644 --- a/drivers/graphics/vgable/src/main.rs +++ b/drivers/graphics/vgable/src/main.rs @@ -1,6 +1,8 @@ #![no_std] #![no_main] +use core::ptr; + use able_graphics_library::display::parse_display_string; const VGA_ADDRESS: *mut u8 = 0xB8000 as *mut u8; @@ -10,7 +12,7 @@ fn start() { // TODO: Initialize the VGA hardware and configure it to the desired video mode // (e.g. 640x480, 800x600, etc.). - let result = parse_display_string("680x480x32@60"); + let result = parse_display_string("680x480x16@60"); use able_graphics_library::display::DisplayError::*; match result { Ok(display) => { @@ -90,4 +92,28 @@ impl<'a> VGAState<'a> { self.set_vga_mode(self.mode) // initalize the graphics lib to be usable } + unsafe fn set_register(address: u16, value: u8) -> Result<(), VGAError> { + let address_ptr = address as *mut u8; + let value_ptr = value as u8; + + // TODO: check if this works + ptr::write_volatile(address_ptr, value_ptr); + let read_value = Self::read_register(address); + if read_value != value { + return Err(VGAError::WrittenValueNotReadValue); + } + Ok(()) + } + unsafe fn read_register(address: u16) -> u8 { + let address_ptr = address as *mut u8; + + ptr::read_volatile(address_ptr) + } +} + +pub enum VgaRegister {} + +pub enum VGAError { + /// The value written is not the same as the value read + WrittenValueNotReadValue, }