From 183136103f4a6f8a07b4a69172c5f7f8fa631eac Mon Sep 17 00:00:00 2001 From: Able Date: Mon, 5 Dec 2022 05:37:36 -0600 Subject: [PATCH] updates --- Cargo.lock | 4 ++ drivers/graphics/vgable/Cargo.toml | 2 + drivers/graphics/vgable/src/main.rs | 54 +++++++++++++++++++ .../able_graphics_library/src/display.rs | 4 +- libraries/able_graphics_library/src/lib.rs | 1 + 5 files changed, 64 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 5560b55..940ab06 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -356,6 +356,10 @@ dependencies = [ [[package]] name = "vgable" version = "0.1.0" +dependencies = [ + "able_graphics_library", + "versioning", +] [[package]] name = "wasi" diff --git a/drivers/graphics/vgable/Cargo.toml b/drivers/graphics/vgable/Cargo.toml index 7441bbe..cf48239 100644 --- a/drivers/graphics/vgable/Cargo.toml +++ b/drivers/graphics/vgable/Cargo.toml @@ -6,3 +6,5 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +versioning = { path = "../../../libraries/versioning" } +able_graphics_library = { path = "../../../libraries/able_graphics_library" } diff --git a/drivers/graphics/vgable/src/main.rs b/drivers/graphics/vgable/src/main.rs index 568a356..943b8e8 100644 --- a/drivers/graphics/vgable/src/main.rs +++ b/drivers/graphics/vgable/src/main.rs @@ -1,8 +1,62 @@ #![no_std] #![no_main] +use able_graphics_library::display::parse_display_string; + #[no_mangle] 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"); + use able_graphics_library::display::DisplayError::*; + match result { + Ok(display) => { + let (width, height, bpp, fps) = display; + let vga_mode = VGAMode::get_vga_mode(width, height, bpp).unwrap_or(VGAMode::Mode0); + } + + Err(err) => match err { + InvalidFormat => panic!("Invalid format"), + InvalidWidth => panic!("Invalid width"), + InvalidHeight => panic!("Invalid height"), + InvalidBPP => panic!("Invalid bpp"), + InvalidFPS => panic!("Invalid fps"), + }, + } +} + +#[derive(Debug)] +enum VGAMode { + Mode0, //: 640x480 pixels, 16 colors + Mode1, //: 640x480 pixels, 256 colors + Mode2, //: 640x480 pixels, 16-bit color + Mode3, //: 800x600 pixels, 16 colors + Mode4, //: 800x600 pixels, 256 colors + Mode5, //: 800x600 pixels, 16-bit color + Mode6, //: 1024x768 pixels, 16 colors + Mode7, //: 1024x768 pixels, 256 colors + Mode8, //: 1024x768 pixels, 16-bit color + Mode9, //: 1280x1024 pixels, 16 colors + Mode10, //: 1280x1024 pixels, 256 colors + Mode11, //1: 1280x1024 pixels, 16-bit color +} +impl VGAMode { + fn get_vga_mode(width: u32, height: u32, bpp: u32) -> Option { + match (width, height, bpp) { + (640, 480, 4) => Some(VGAMode::Mode0), + (640, 480, 8) => Some(VGAMode::Mode1), + (640, 480, 16) => Some(VGAMode::Mode2), + (800, 600, 4) => Some(VGAMode::Mode3), + (800, 600, 8) => Some(VGAMode::Mode4), + (800, 600, 16) => Some(VGAMode::Mode5), + (1024, 768, 4) => Some(VGAMode::Mode6), + (1024, 768, 8) => Some(VGAMode::Mode7), + (1024, 768, 16) => Some(VGAMode::Mode8), + (1280, 1024, 4) => Some(VGAMode::Mode9), + (1280, 1024, 8) => Some(VGAMode::Mode10), + (1280, 1024, 16) => Some(VGAMode::Mode11), + _ => None, + } + } } diff --git a/libraries/able_graphics_library/src/display.rs b/libraries/able_graphics_library/src/display.rs index 1dbd744..6b76362 100644 --- a/libraries/able_graphics_library/src/display.rs +++ b/libraries/able_graphics_library/src/display.rs @@ -1,3 +1,5 @@ +use alloc::vec::Vec; + pub enum DisplayError { InvalidFormat, InvalidWidth, @@ -18,7 +20,7 @@ pub fn parse_display_string(s: &str) -> Result<(u32, u32, u32, u32), DisplayErro let height = parts[1] .parse::() .map_err(|_| DisplayError::InvalidHeight)?; - let bits = parts[2].split('@').collect(); + let bits: Vec<&str> = parts[2].split('@').collect(); if bits.len() != 2 { return Err(DisplayError::InvalidFormat); } diff --git a/libraries/able_graphics_library/src/lib.rs b/libraries/able_graphics_library/src/lib.rs index 77c2b09..154c8f8 100644 --- a/libraries/able_graphics_library/src/lib.rs +++ b/libraries/able_graphics_library/src/lib.rs @@ -6,6 +6,7 @@ extern crate alloc; pub mod buffer; pub mod color; pub mod commands; +pub mod display; pub mod framebuffer; pub mod types; pub mod vertex;