Limit visibilities
This commit is contained in:
@@ -5,7 +5,7 @@ use super::Display;
|
||||
static FONT: &[u8] = include_bytes!("../../../res/unifont.font");
|
||||
|
||||
pub struct DebugDisplay {
|
||||
pub(crate) display: Display,
|
||||
pub(super) display: Display,
|
||||
x: usize,
|
||||
y: usize,
|
||||
w: usize,
|
||||
@@ -13,7 +13,7 @@ pub struct DebugDisplay {
|
||||
}
|
||||
|
||||
impl DebugDisplay {
|
||||
pub fn new(display: Display) -> DebugDisplay {
|
||||
pub(super) fn new(display: Display) -> DebugDisplay {
|
||||
let w = display.width / 8;
|
||||
let h = display.height / 16;
|
||||
DebugDisplay {
|
||||
@@ -25,7 +25,7 @@ impl DebugDisplay {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write_char(&mut self, c: char) {
|
||||
fn write_char(&mut self, c: char) {
|
||||
if self.x >= self.w || c == '\n' {
|
||||
self.x = 0;
|
||||
self.y += 1;
|
||||
@@ -63,7 +63,7 @@ impl DebugDisplay {
|
||||
}
|
||||
|
||||
/// Draw a character
|
||||
pub fn char(&mut self, x: usize, y: usize, character: char, color: u32) {
|
||||
fn char(&mut self, x: usize, y: usize, character: char, color: u32) {
|
||||
if x + 8 <= self.display.width && y + 16 <= self.display.height {
|
||||
let mut dst = unsafe {
|
||||
self.display
|
||||
@@ -90,7 +90,7 @@ impl DebugDisplay {
|
||||
}
|
||||
|
||||
/// Scroll the screen
|
||||
pub fn scroll(&mut self, lines: usize) {
|
||||
fn scroll(&mut self, lines: usize) {
|
||||
let offset = cmp::min(self.display.height, lines) * self.display.stride;
|
||||
let size = (self.display.stride * self.display.height) - offset;
|
||||
unsafe {
|
||||
|
||||
@@ -2,16 +2,21 @@ use alloc::boxed::Box;
|
||||
use core::{ptr, slice};
|
||||
|
||||
/// A display
|
||||
pub struct Display {
|
||||
pub width: usize,
|
||||
pub height: usize,
|
||||
pub stride: usize,
|
||||
pub onscreen: &'static mut [u32],
|
||||
pub offscreen: Option<Box<[u32]>>,
|
||||
pub(super) struct Display {
|
||||
pub(super) width: usize,
|
||||
pub(super) height: usize,
|
||||
pub(super) stride: usize,
|
||||
onscreen: &'static mut [u32],
|
||||
offscreen: Option<Box<[u32]>>,
|
||||
}
|
||||
|
||||
impl Display {
|
||||
pub fn new(width: usize, height: usize, stride: usize, onscreen_ptr: *mut u32) -> Display {
|
||||
pub(super) fn new(
|
||||
width: usize,
|
||||
height: usize,
|
||||
stride: usize,
|
||||
onscreen_ptr: *mut u32,
|
||||
) -> Display {
|
||||
let size = stride * height;
|
||||
let onscreen = unsafe {
|
||||
ptr::write_bytes(onscreen_ptr, 0, size);
|
||||
@@ -26,7 +31,11 @@ impl Display {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn data_mut(&mut self) -> &mut [u32] {
|
||||
pub(super) fn heap_init(&mut self) {
|
||||
self.offscreen = Some(self.onscreen.to_vec().into_boxed_slice());
|
||||
}
|
||||
|
||||
pub(super) fn data_mut(&mut self) -> &mut [u32] {
|
||||
match &mut self.offscreen {
|
||||
Some(offscreen) => offscreen,
|
||||
None => self.onscreen,
|
||||
@@ -34,7 +43,7 @@ impl Display {
|
||||
}
|
||||
|
||||
/// Sync from offscreen to onscreen, unsafe because it trusts provided x, y, w, h
|
||||
pub unsafe fn sync(&mut self, x: usize, y: usize, w: usize, mut h: usize) {
|
||||
pub(super) unsafe fn sync(&mut self, x: usize, y: usize, w: usize, mut h: usize) {
|
||||
if let Some(offscreen) = &self.offscreen {
|
||||
let mut offset = y * self.stride + x;
|
||||
while h > 0 {
|
||||
|
||||
@@ -68,8 +68,7 @@ pub fn init(env: &[u8]) {
|
||||
|
||||
pub fn init_heap() {
|
||||
if let Some(debug_display) = &mut *DEBUG_DISPLAY.lock() {
|
||||
debug_display.display.offscreen =
|
||||
Some(debug_display.display.onscreen.to_vec().into_boxed_slice());
|
||||
debug_display.display.heap_init();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user