debugging

This commit is contained in:
Elfein Landers 2022-01-27 00:06:58 -08:00
parent bbed40d46d
commit 9ac6927411
4 changed files with 301 additions and 307 deletions

View file

@ -1,11 +1,9 @@
use crate::vga_e::VGAE;
use ab_glyph::{Font, FontRef, Glyph};
use alloc::{boxed::Box, vec, vec::Vec};
use shadeable::{
evaluate_shader,
pixel_format::{Rgba64},
};
use shadeable::{evaluate_shader, pixel_format::Rgba64};
use spin;
use vga::{writers::GraphicsWriter};
use vga::writers::GraphicsWriter;
#[derive(Debug)]
pub struct ScreenSize {
@ -13,6 +11,10 @@ pub struct ScreenSize {
pub y: usize,
}
const FONT_SCALE: f32 = 1.6;
const GLYPH_HEIGHT: f32 = 18.0;
const GLYPH_WIDTH: f32 = 10.0;
lazy_static::lazy_static! {
pub static ref SCREEN_BUFFER: spin::Mutex<ScreenBuffer> = spin::Mutex::new(ScreenBuffer::new(640, 480));
@ -75,14 +77,7 @@ impl ScreenBuffer {
}
}
}
pub fn draw_unfilled_rect(
&mut self,
x1: usize,
y1: usize,
x2: usize,
y2: usize,
color: Rgba64,
) {
pub fn draw_unfilled_rect(&mut self, x1: usize, y1: usize, x2: usize, y2: usize, color: Rgba64) {
// x1 y1 => x2 y1 => x2 y2 => x1 y2 => x1 y1
self.draw_line(x1, y1, x2, y1, color);
self.draw_line(x2, y1, x2, y2, color);
@ -127,6 +122,73 @@ impl ScreenBuffer {
use shadeable::pixel_format::into_vga_16;
VGAE.lock().clear_screen(into_vga_16(self.clear_color));
}
/// Draw a glyph on the screen at the given position
///
/// # Arguments
/// * `x` - the x position of the glyph
/// * `y` - the y position of the glyph
/// * `glyph` - the glyph to draw
/// * `color` - the color of the glyph
pub fn draw_char(&mut self, mut x: u32, mut y: u32, character: char, color: Rgba64) {
// trace!["Judy Hopps is thicc af"];
// let mode = *VGAE.lock();
// trace!["She got them bouncy bunny buns"];
let basic_multingual_plane = FontRef::try_from_slice(include_bytes!(
"../../../ableos/assets/fonts/unifont-14.0.01.ttf"
))
.unwrap();
let supplementary_multilingual_plane = FontRef::try_from_slice(include_bytes!(
"../../../ableos/assets/fonts/unifont_upper-14.0.01.ttf"
))
.unwrap();
// let mut has_char = false;
// for x in font.codepoint_ids() {
// if x.1 == character {
// has_char = true;
// break;
// }
// }
let in_supp_plane = character as u32 > 0xffff;
let plane = match in_supp_plane {
false => basic_multingual_plane,
true => supplementary_multilingual_plane,
};
match character {
'\n' => {}
_ => {
let q_glyph: Glyph = plane.glyph_id(character).with_scale_and_position(
20.0 * FONT_SCALE,
ab_glyph::point(GLYPH_WIDTH * FONT_SCALE, GLYPH_HEIGHT * FONT_SCALE),
);
// elf: I don't know if GLYPH_HEIGHT is in the right units here. I'm just guessing.
if x as usize > self.size.x {
x = 0;
y += (GLYPH_HEIGHT * FONT_SCALE) as u32;
}
if let Some(q) = plane.outline_glyph(q_glyph) {
q.draw(|gx, gy, c| {
if c > 0.015 {
let corner = q.px_bounds().min;
self.set_pixel(
gx as usize + corner.x as usize + x as usize,
gy as usize + corner.y as usize + y as usize,
color,
);
}
});
}
}
}
}
}
pub trait VgaBuffer {
@ -137,7 +199,7 @@ impl VgaBuffer for ScreenBuffer {
let mode = VGAE.lock();
for y in 0..self.size.y {
for x in 0..self.size.x {
use shadeable::pixel_format::{into_vga_16};
use shadeable::pixel_format::into_vga_16;
// let vga_color = get_color16(self.buff[y * self.size.x + x]);
let vga_color = into_vga_16(self.buff[y * self.size.x + x]);

View file

@ -112,11 +112,12 @@ pub fn tick() {
crate::kernel_state::KERNEL_STATE.lock().update_state();
let mut scheduler = SCHEDULER.lock();
scheduler.bump_exec();
// let mut scheduler = SCHEDULER.lock();
// scheduler.bump_exec();
TICK.store(data, Relaxed)
}
/// called every time a key is pressed to add it to the randomness pool
pub fn key_entropy(key: u8) {}

View file

@ -93,9 +93,11 @@ pub fn screen_writer_test() {
// sock_print_id.write(format!("I look forward to ur ai stuff :^>").into());
// sock_print_id.write(format!("1....2....3....4....5....6....7....8....9").into());
let mut mode = SCREEN_BUFFER.lock();
for current in (*String::from_utf8_lossy(&sock_print_id.peek().unwrap())).chars() {
vga_e::draw_char(0, 0, current, from_vga_16(Color16::Red));
mode.draw_char(0, 0, current, from_vga_16(Color16::Red));
}
mode.copy_to_buffer();
}
pub fn vga_boot_screen() {

View file

@ -20,77 +20,6 @@ lazy_static::lazy_static! {
pub static ref VGAE_BUFF_OFFSET_Y: spin::Mutex<u8> = spin::Mutex::new(0);
}
const FONT_SCALE: f32 = 1.6;
const GLYPH_HEIGHT: f32 = 18.0;
const GLYPH_WIDTH: f32 = 10.0;
/// Draw a glyph on the screen at the given position
///
/// # Arguments
/// * `x` - the x position of the glyph
/// * `y` - the y position of the glyph
/// * `glyph` - the glyph to draw
/// * `color` - the color of the glyph
pub fn draw_char(mut x: u32, mut y: u32, character: char, color: Rgba64) {
// trace!["Judy Hopps is thicc af"];
// let mode = *VGAE.lock();
let mut mode = SCREEN_BUFFER.lock();
// trace!["She got them bouncy bunny buns"];
let basic_multingual_plane = FontRef::try_from_slice(include_bytes!(
"../../ableos/assets/fonts/unifont-14.0.01.ttf"
))
.unwrap();
let supplementary_multilingual_plane = FontRef::try_from_slice(include_bytes!(
"../../ableos/assets/fonts/unifont_upper-14.0.01.ttf"
))
.unwrap();
// let mut has_char = false;
// for x in font.codepoint_ids() {
// if x.1 == character {
// has_char = true;
// break;
// }
// }
let is_in_basic_multilingual_plane = character as u32 <= 0xffff;
let plane = match is_in_basic_multilingual_plane {
true => basic_multingual_plane,
false => supplementary_multilingual_plane,
};
match character {
'\n' => {}
_ => {
let q_glyph: Glyph = plane.glyph_id(character).with_scale_and_position(
20.0 * FONT_SCALE,
ab_glyph::point(GLYPH_WIDTH * FONT_SCALE, GLYPH_HEIGHT * FONT_SCALE),
);
// elf: I don't know if GLYPH_HEIGHT is in the right units here. I'm just guessing.
if x as usize > mode.size.x {
x = 0;
y += (GLYPH_HEIGHT * FONT_SCALE) as u32;
}
if let Some(q) = plane.outline_glyph(q_glyph) {
q.draw(|gx, gy, c| {
if c > 0.015 {
let corner = q.px_bounds().min;
mode.set_pixel(
gx as usize + corner.x as usize + x as usize,
gy as usize + corner.y as usize + y as usize,
color,
);
}
});
}
}
}
}
/// Converts a number to ... i forgor 💀
pub fn num_to_vga16(num: u8) -> Color16 {