[gpu] Add graphics and adapter

This commit is contained in:
2024-02-18 15:11:37 +05:30
parent 91702f3997
commit 7492ba8dd3
5 changed files with 90 additions and 2 deletions

30
src/emu/graphics.rs Normal file
View File

@@ -0,0 +1,30 @@
use crate::misc::emulator_error::DeviceType::GRAPHICS;
use crate::misc::emulator_error::EmulatorError;
use crate::misc::result::EmulatorResult;
pub const DEVICE_FRAMEBUFFER_SIZE: usize = 256 * 256;
pub struct GraphicsProcessor {
framebuffer: Box<[u8; DEVICE_FRAMEBUFFER_SIZE]>,
}
/// Abstracted graphics processor. Refer GraphicsAdapter
impl GraphicsProcessor {
pub fn try_new() -> EmulatorResult<GraphicsProcessor> {
let framebuffer = vec![0; DEVICE_FRAMEBUFFER_SIZE].into_boxed_slice()
.try_into()
.map_err(|_| {
EmulatorError::AllocationFailure(GRAPHICS, "Failed to allocate graphics")
})?;
Ok(GraphicsProcessor {
framebuffer
})
}
pub fn set_framebuffer(&mut self,memory_slice: &[u8]){
self.framebuffer.copy_from_slice(memory_slice);
}
pub fn get_framebuffer(&self) -> &[u8;DEVICE_FRAMEBUFFER_SIZE] {
&self.framebuffer
}
}

View File

@@ -2,4 +2,5 @@ pub mod cpu;
pub mod mmu;
pub mod ram;
pub mod iomem;
pub mod program_counter;
pub mod program_counter;
pub mod graphics;