Only support 32bpp
This commit is contained in:
parent
ed2fdb74a1
commit
041dd736f1
|
@ -1,4 +1,5 @@
|
|||
use super::pci::{find_pci_device, PciDevice, PciHeader};
|
||||
use crate::writers::GraphicsWriter;
|
||||
use x86_64::{instructions::port::Port, PhysAddr, VirtAddr};
|
||||
|
||||
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_GETCAPS: u16 = 0x02;
|
||||
const VBE_DISPI_LFB_ENABLED: u16 = 0x40;
|
||||
const VBE_DISPI_BPP_32: u16 = 0x20;
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
#[repr(u8)]
|
||||
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 {
|
||||
pub struct Resolution {
|
||||
width: u16,
|
||||
height: u16,
|
||||
bpp: BitsPerPixel,
|
||||
}
|
||||
|
||||
impl Mode {
|
||||
pub const fn new(width: u16, height: u16, bpp: BitsPerPixel) -> Mode {
|
||||
Mode { width, height, bpp }
|
||||
impl Resolution {
|
||||
pub fn new(width: u16, height: u16) -> Resolution {
|
||||
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 height = self.get_height();
|
||||
let bpp = self.get_bpp();
|
||||
Mode { width, height, bpp }
|
||||
Resolution { width, height }
|
||||
}
|
||||
|
||||
pub fn set_mode(&mut self, mode: Mode) {
|
||||
pub fn set_resolution(&mut self, resolution: Resolution) {
|
||||
self.disable_display();
|
||||
self.set_width(mode.width);
|
||||
self.set_height(mode.height);
|
||||
self.set_bpp(mode.bpp);
|
||||
self.set_width(resolution.width);
|
||||
self.set_height(resolution.height);
|
||||
self.set_bpp();
|
||||
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) {
|
||||
unsafe {
|
||||
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 {
|
||||
self.index_port.write(VBE_DISPI_INDEX_BPP);
|
||||
self.data_port.write(bpp as u16);
|
||||
self.data_port.write(VBE_DISPI_BPP_32);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
pub mod bochs;
|
||||
mod pci;
|
||||
|
||||
pub use bochs::{BitsPerPixel, BochsDevice, Mode};
|
||||
pub use bochs::{BochsDevice, Resolution};
|
||||
|
|
Loading…
Reference in a new issue