Bringing it back
This commit is contained in:
parent
103fba0eac
commit
fb578e73e1
|
@ -40,24 +40,25 @@ pub struct BochsDevice {
|
||||||
pci_device: PciDevice,
|
pci_device: PciDevice,
|
||||||
physical_address: PhysAddr,
|
physical_address: PhysAddr,
|
||||||
virtual_address: VirtAddr,
|
virtual_address: VirtAddr,
|
||||||
current_resolution: Resolution,
|
resolution: Resolution,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BochsDevice {
|
impl BochsDevice {
|
||||||
pub fn new() -> BochsDevice {
|
pub fn new(width: usize, height: usize) -> BochsDevice {
|
||||||
let pci_device = find_pci_device(BOCHS_ID).expect("no bochs device found");
|
let pci_device = find_pci_device(BOCHS_ID).expect("no bochs device found");
|
||||||
let index_port = Port::new(BOCHS_INDEX_PORT_ADDRESS);
|
let index_port = Port::new(BOCHS_INDEX_PORT_ADDRESS);
|
||||||
let data_port = Port::new(BOCHS_DATA_PORT_ADDRESS);
|
let data_port = Port::new(BOCHS_DATA_PORT_ADDRESS);
|
||||||
let base_address = pci_device.base_addresses[0] & 0xFFFF_FFF0;
|
let base_address = pci_device.base_addresses[0] & 0xFFFF_FFF0;
|
||||||
let physical_address = PhysAddr::new(base_address as u64);
|
let physical_address = PhysAddr::new(base_address as u64);
|
||||||
let virtual_address = VirtAddr::new(base_address as u64);
|
let virtual_address = VirtAddr::new(base_address as u64);
|
||||||
|
let resolution = Resolution::new(width, height);
|
||||||
BochsDevice {
|
BochsDevice {
|
||||||
pci_device,
|
pci_device,
|
||||||
index_port,
|
index_port,
|
||||||
data_port,
|
data_port,
|
||||||
physical_address,
|
physical_address,
|
||||||
virtual_address,
|
virtual_address,
|
||||||
current_resolution: Resolution::default(),
|
resolution,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,12 +150,7 @@ impl BochsDevice {
|
||||||
|
|
||||||
/// Sets the `BochsDevice` to the given `resolution`.
|
/// Sets the `BochsDevice` to the given `resolution`.
|
||||||
pub fn set_resolution(&mut self, resolution: Resolution) {
|
pub fn set_resolution(&mut self, resolution: Resolution) {
|
||||||
self.disable_display();
|
self.resolution = resolution;
|
||||||
self.set_width(resolution.width);
|
|
||||||
self.set_height(resolution.height);
|
|
||||||
self.set_bpp();
|
|
||||||
self.enable_display();
|
|
||||||
self.current_resolution = resolution;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_width(&mut self) -> usize {
|
fn get_width(&mut self) -> usize {
|
||||||
|
@ -195,7 +191,7 @@ impl BochsDevice {
|
||||||
|
|
||||||
impl GraphicsWriter<u32> for BochsDevice {
|
impl GraphicsWriter<u32> for BochsDevice {
|
||||||
fn clear_screen(&self, color: u32) {
|
fn clear_screen(&self, color: u32) {
|
||||||
let screen_size = self.current_resolution.width * self.current_resolution.height;
|
let screen_size = self.resolution.width * self.resolution.height;
|
||||||
let frame_buffer = self.virtual_address.as_mut_ptr::<u32>();
|
let frame_buffer = self.virtual_address.as_mut_ptr::<u32>();
|
||||||
for offset in 0..screen_size {
|
for offset in 0..screen_size {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -225,7 +221,7 @@ impl GraphicsWriter<u32> for BochsDevice {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn set_pixel(&self, x: usize, y: usize, color: u32) {
|
fn set_pixel(&self, x: usize, y: usize, color: u32) {
|
||||||
let offset = (y * self.current_resolution.width) + x;
|
let offset = (y * self.resolution.width) + x;
|
||||||
unsafe {
|
unsafe {
|
||||||
self.virtual_address
|
self.virtual_address
|
||||||
.as_mut_ptr::<u32>()
|
.as_mut_ptr::<u32>()
|
||||||
|
@ -236,4 +232,11 @@ impl GraphicsWriter<u32> for BochsDevice {
|
||||||
fn get_frame_buffer(&self) -> *mut u32 {
|
fn get_frame_buffer(&self) -> *mut u32 {
|
||||||
self.virtual_address.as_mut_ptr()
|
self.virtual_address.as_mut_ptr()
|
||||||
}
|
}
|
||||||
|
fn set_mode(&mut self) {
|
||||||
|
self.disable_display();
|
||||||
|
self.set_width(self.resolution.width);
|
||||||
|
self.set_height(self.resolution.height);
|
||||||
|
self.set_bpp();
|
||||||
|
self.enable_display();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,16 +77,7 @@ impl GraphicsWriter<u8> for Graphics320x200x256 {
|
||||||
fn get_frame_buffer(&self) -> *mut u8 {
|
fn get_frame_buffer(&self) -> *mut u8 {
|
||||||
u32::from(VGA.lock().get_frame_buffer()) as *mut u8
|
u32::from(VGA.lock().get_frame_buffer()) as *mut u8
|
||||||
}
|
}
|
||||||
}
|
fn set_mode(&mut self) {
|
||||||
|
|
||||||
impl Graphics320x200x256 {
|
|
||||||
/// Creates a new `Graphics320x200x256`.
|
|
||||||
pub const fn new() -> Graphics320x200x256 {
|
|
||||||
Graphics320x200x256
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the graphics device to a `VideoMode`.
|
|
||||||
pub fn set_mode(&self) {
|
|
||||||
let mut vga = VGA.lock();
|
let mut vga = VGA.lock();
|
||||||
vga.set_video_mode(VideoMode::Mode320x200x256);
|
vga.set_video_mode(VideoMode::Mode320x200x256);
|
||||||
|
|
||||||
|
@ -95,3 +86,10 @@ impl Graphics320x200x256 {
|
||||||
vga.color_palette_registers.load_palette(&DEFAULT_PALETTE);
|
vga.color_palette_registers.load_palette(&DEFAULT_PALETTE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Graphics320x200x256 {
|
||||||
|
/// Creates a new `Graphics320x200x256`.
|
||||||
|
pub const fn new() -> Graphics320x200x256 {
|
||||||
|
Graphics320x200x256
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -87,16 +87,7 @@ impl GraphicsWriter<u8> for Graphics320x240x256 {
|
||||||
fn get_frame_buffer(&self) -> *mut u8 {
|
fn get_frame_buffer(&self) -> *mut u8 {
|
||||||
u32::from(VGA.lock().get_frame_buffer()) as *mut u8
|
u32::from(VGA.lock().get_frame_buffer()) as *mut u8
|
||||||
}
|
}
|
||||||
}
|
fn set_mode(&mut self) {
|
||||||
|
|
||||||
impl Graphics320x240x256 {
|
|
||||||
/// Creates a new `Graphics320x240x256`.
|
|
||||||
pub const fn new() -> Graphics320x240x256 {
|
|
||||||
Graphics320x240x256
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the graphics device to a `VideoMode`.
|
|
||||||
pub fn set_mode(&self) {
|
|
||||||
let mut vga = VGA.lock();
|
let mut vga = VGA.lock();
|
||||||
vga.set_video_mode(VideoMode::Mode320x240x256);
|
vga.set_video_mode(VideoMode::Mode320x240x256);
|
||||||
|
|
||||||
|
@ -105,3 +96,10 @@ impl Graphics320x240x256 {
|
||||||
vga.color_palette_registers.load_palette(&DEFAULT_PALETTE);
|
vga.color_palette_registers.load_palette(&DEFAULT_PALETTE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Graphics320x240x256 {
|
||||||
|
/// Creates a new `Graphics320x240x256`.
|
||||||
|
pub const fn new() -> Graphics320x240x256 {
|
||||||
|
Graphics320x240x256
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -89,16 +89,7 @@ impl GraphicsWriter<Color16> for Graphics640x480x16 {
|
||||||
fn get_frame_buffer(&self) -> *mut Color16 {
|
fn get_frame_buffer(&self) -> *mut Color16 {
|
||||||
u32::from(VGA.lock().get_frame_buffer()) as *mut Color16
|
u32::from(VGA.lock().get_frame_buffer()) as *mut Color16
|
||||||
}
|
}
|
||||||
}
|
fn set_mode(&mut self) {
|
||||||
|
|
||||||
impl Graphics640x480x16 {
|
|
||||||
/// Creates a new `Graphics640x480x16`.
|
|
||||||
pub const fn new() -> Graphics640x480x16 {
|
|
||||||
Graphics640x480x16
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the graphics device to a `VideoMode`.
|
|
||||||
pub fn set_mode(&self) {
|
|
||||||
let mut vga = VGA.lock();
|
let mut vga = VGA.lock();
|
||||||
vga.set_video_mode(VideoMode::Mode640x480x16);
|
vga.set_video_mode(VideoMode::Mode640x480x16);
|
||||||
|
|
||||||
|
@ -106,6 +97,13 @@ impl Graphics640x480x16 {
|
||||||
// so explicitly set it.
|
// so explicitly set it.
|
||||||
vga.color_palette_registers.load_palette(&DEFAULT_PALETTE);
|
vga.color_palette_registers.load_palette(&DEFAULT_PALETTE);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Graphics640x480x16 {
|
||||||
|
/// Creates a new `Graphics640x480x16`.
|
||||||
|
pub const fn new() -> Graphics640x480x16 {
|
||||||
|
Graphics640x480x16
|
||||||
|
}
|
||||||
|
|
||||||
fn set_write_mode_0(self, color: Color16) {
|
fn set_write_mode_0(self, color: Color16) {
|
||||||
let mut vga = VGA.lock();
|
let mut vga = VGA.lock();
|
||||||
|
|
|
@ -199,4 +199,6 @@ pub trait GraphicsWriter<Color> {
|
||||||
fn set_pixel(&self, x: usize, y: usize, color: Color);
|
fn set_pixel(&self, x: usize, y: usize, color: Color);
|
||||||
/// Returns the frame buffer for this vga mode.
|
/// Returns the frame buffer for this vga mode.
|
||||||
fn get_frame_buffer(&self) -> *mut Color;
|
fn get_frame_buffer(&self) -> *mut Color;
|
||||||
|
/// Sets the graphics device to a `VideoMode`.
|
||||||
|
fn set_mode(&mut self);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue