[gpu] Add graphics and adapter
This commit is contained in:
30
src/emu/graphics.rs
Normal file
30
src/emu/graphics.rs
Normal 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
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
Reference in New Issue
Block a user