Only support 32bpp

This commit is contained in:
Ryan Kennedy 2020-04-12 20:03:56 -05:00
parent ed2fdb74a1
commit 041dd736f1
2 changed files with 15 additions and 47 deletions

View file

@ -1,4 +1,5 @@
use super::pci::{find_pci_device, PciDevice, PciHeader}; use super::pci::{find_pci_device, PciDevice, PciHeader};
use crate::writers::GraphicsWriter;
use x86_64::{instructions::port::Port, PhysAddr, VirtAddr}; use x86_64::{instructions::port::Port, PhysAddr, VirtAddr};
const BOCHS_ID: u32 = 0x1111_1234; const BOCHS_ID: u32 = 0x1111_1234;
@ -14,42 +15,17 @@ const VBE_DISPI_DISABLED: u16 = 0x00;
const VBE_DISPI_ENABLED: u16 = 0x01; const VBE_DISPI_ENABLED: u16 = 0x01;
const VBE_DISPI_GETCAPS: u16 = 0x02; const VBE_DISPI_GETCAPS: u16 = 0x02;
const VBE_DISPI_LFB_ENABLED: u16 = 0x40; const VBE_DISPI_LFB_ENABLED: u16 = 0x40;
const VBE_DISPI_BPP_32: u16 = 0x20;
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
#[repr(u8)] pub struct Resolution {
pub enum BitsPerPixel {
Bpp4 = 0x04,
Bpp8 = 0x08,
Bpp15 = 0x0F,
Bpp16 = 0x10,
Bpp24 = 0x18,
Bpp32 = 0x20,
}
impl From<u16> for BitsPerPixel {
fn from(value: u16) -> BitsPerPixel {
match value {
0x04 => BitsPerPixel::Bpp4,
0x08 => BitsPerPixel::Bpp8,
0x0F => BitsPerPixel::Bpp15,
0x10 => BitsPerPixel::Bpp16,
0x18 => BitsPerPixel::Bpp24,
0x20 => BitsPerPixel::Bpp32,
_ => panic!("invalid bits per pixel value: {}", value),
}
}
}
#[derive(Debug, Copy, Clone)]
pub struct Mode {
width: u16, width: u16,
height: u16, height: u16,
bpp: BitsPerPixel,
} }
impl Mode { impl Resolution {
pub const fn new(width: u16, height: u16, bpp: BitsPerPixel) -> Mode { pub fn new(width: u16, height: u16) -> Resolution {
Mode { width, height, bpp } Resolution { width, height }
} }
} }
@ -145,18 +121,17 @@ impl BochsDevice {
} }
} }
pub fn get_mode(&mut self) -> Mode { pub fn get_resolution(&mut self) -> Resolution {
let width = self.get_width(); let width = self.get_width();
let height = self.get_height(); let height = self.get_height();
let bpp = self.get_bpp(); Resolution { width, height }
Mode { width, height, bpp }
} }
pub fn set_mode(&mut self, mode: Mode) { pub fn set_resolution(&mut self, resolution: Resolution) {
self.disable_display(); self.disable_display();
self.set_width(mode.width); self.set_width(resolution.width);
self.set_height(mode.height); self.set_height(resolution.height);
self.set_bpp(mode.bpp); self.set_bpp();
self.enable_display(); self.enable_display();
} }
@ -174,13 +149,6 @@ impl BochsDevice {
} }
} }
pub fn get_bpp(&mut self) -> BitsPerPixel {
unsafe {
self.index_port.write(VBE_DISPI_INDEX_BPP);
BitsPerPixel::from(self.data_port.read())
}
}
fn set_width(&mut self, width: u16) { fn set_width(&mut self, width: u16) {
unsafe { unsafe {
self.index_port.write(VBE_DISPI_INDEX_XRES); self.index_port.write(VBE_DISPI_INDEX_XRES);
@ -195,10 +163,10 @@ impl BochsDevice {
} }
} }
fn set_bpp(&mut self, bpp: BitsPerPixel) { fn set_bpp(&mut self) {
unsafe { unsafe {
self.index_port.write(VBE_DISPI_INDEX_BPP); self.index_port.write(VBE_DISPI_INDEX_BPP);
self.data_port.write(bpp as u16); self.data_port.write(VBE_DISPI_BPP_32);
} }
} }
} }

View file

@ -1,4 +1,4 @@
pub mod bochs; pub mod bochs;
mod pci; mod pci;
pub use bochs::{BitsPerPixel, BochsDevice, Mode}; pub use bochs::{BochsDevice, Resolution};