This commit is contained in:
Able 2022-12-05 05:37:36 -06:00
parent 469325b52a
commit 183136103f
5 changed files with 64 additions and 1 deletions

4
Cargo.lock generated
View file

@ -356,6 +356,10 @@ dependencies = [
[[package]]
name = "vgable"
version = "0.1.0"
dependencies = [
"able_graphics_library",
"versioning",
]
[[package]]
name = "wasi"

View file

@ -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" }

View file

@ -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<VGAMode> {
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,
}
}
}

View file

@ -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::<u32>()
.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);
}

View file

@ -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;