[Teton] Move console/shell to rust. WIP
This commit is contained in:
parent
76f8795a46
commit
18e512cf1f
17 changed files with 409 additions and 5 deletions
38
rust/sys/teton/src/framebuffer.rs
Normal file
38
rust/sys/teton/src/framebuffer.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
use mammoth::{mem::MemoryRegion, zion::ZError};
|
||||
use yellowstone::FramebufferInfo;
|
||||
|
||||
pub struct Framebuffer {
|
||||
fb_info: FramebufferInfo,
|
||||
memory_region: MemoryRegion,
|
||||
}
|
||||
|
||||
impl Framebuffer {
|
||||
pub fn from_info(fb_info: FramebufferInfo) -> Result<Self, ZError> {
|
||||
let size = fb_info.height * fb_info.pitch;
|
||||
let memory_region = MemoryRegion::direct_physical(fb_info.address_phys, size)?;
|
||||
Ok(Self {
|
||||
fb_info,
|
||||
memory_region,
|
||||
})
|
||||
}
|
||||
|
||||
fn draw_pixel(&self, row: u32, col: u32, pixel: u32) {
|
||||
let index = row * (self.fb_info.pitch as u32 / 4) + col;
|
||||
self.memory_region.mut_slice()[index as usize] = pixel;
|
||||
}
|
||||
|
||||
pub fn draw_glyph(&self, glyph: &[u8], row: u32, col: u32) {
|
||||
let gl_width = 8;
|
||||
let gl_height = 16;
|
||||
|
||||
for r in 0..gl_height {
|
||||
for c in 0..gl_width {
|
||||
if ((glyph[r] >> c) % 2) == 1 {
|
||||
self.draw_pixel(row + (r as u32), col + (gl_width - c - 1), 0xFFFFFFFF);
|
||||
} else {
|
||||
self.draw_pixel(row + (r as u32), col + (gl_width - c - 1), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue