From bbed40d46d24aba500eb3f8dd951ba259475729f Mon Sep 17 00:00:00 2001 From: Elfein Landers Date: Wed, 26 Jan 2022 23:47:24 -0800 Subject: [PATCH 1/2] judy hopps --- ableos/src/tests.rs | 239 ++++++++++++++++++++++---------------------- ableos/src/vga_e.rs | 2 + 2 files changed, 122 insertions(+), 119 deletions(-) diff --git a/ableos/src/tests.rs b/ableos/src/tests.rs index 090e39ca7..c26d0b1a8 100644 --- a/ableos/src/tests.rs +++ b/ableos/src/tests.rs @@ -1,186 +1,187 @@ use alloc::{ - format, - string::{String, ToString}, - vec, + format, + string::{String, ToString}, + vec, }; use picorand::PicoRandGenerate; use rkyv::{ser::serializers::AllocSerializer, Deserialize}; use shadeable::pixel_format::from_vga_16; +use vga::colors::Color16; use y_compositor_protocol::Version; use crate::{ - kmain::{BOOT_CONF, TICK}, - network::socket::{SimpleSock, Socket, SocketReturns}, - num_to_vga16, vga_e, VgaBuffer, SCREEN_BUFFER, + kmain::{BOOT_CONF, TICK}, + network::socket::{SimpleSock, Socket, SocketReturns}, + num_to_vga16, vga_e, VgaBuffer, SCREEN_BUFFER, }; pub fn run_tests() { - if BOOT_CONF.run_tests { - // quick and dirty testing framework - screen_writer_test(); - socket_test(); - graphics_pipe_test(); - socket_startup_rng(); - socket_test_rng(); - } + if BOOT_CONF.run_tests { + // quick and dirty testing framework + screen_writer_test(); + socket_test(); + graphics_pipe_test(); + socket_startup_rng(); + socket_test_rng(); + } - if BOOT_CONF.run_demos { - graphics_api_demo(); - } + if BOOT_CONF.run_demos { + graphics_api_demo(); + } - if BOOT_CONF.run_shader_tests { - shader_tests(); - } + if BOOT_CONF.run_shader_tests { + shader_tests(); + } } pub fn socket_test() { - let mut xyz = SimpleSock::new(); + let mut xyz = SimpleSock::new(); - xyz.peek(); + xyz.peek(); - xyz.write(vec![0, 1, 2, 3]); + xyz.write(vec![0, 1, 2, 3]); - let x = "simple 🧦".to_string().into_bytes(); - xyz.write(x); + let x = "simple 🧦".to_string().into_bytes(); + xyz.write(x); - info!("{:?}", &xyz.read(4).unwrap()); + info!("{:?}", &xyz.read(4).unwrap()); - match &xyz.peek() { - SocketReturns::ReadOk(strr) => { - let out = String::from_utf8_lossy(strr); + match &xyz.peek() { + SocketReturns::ReadOk(strr) => { + let out = String::from_utf8_lossy(strr); - info!("{}", out); - } - SocketReturns::ReadIndexOutOfBounds => todo!(), - SocketReturns::WriteOk => todo!(), - } + info!("{}", out); + } + SocketReturns::ReadIndexOutOfBounds => todo!(), + SocketReturns::WriteOk => todo!(), + } } pub fn socket_test_rng() { - let mut test_sock = SimpleSock::grab_socket("RNGProvider".to_string()).unwrap(); - info!( - "Recieving {} from protocol {}", - test_sock.read(1).unwrap()[0], - test_sock.protocol().unwrap() - ); + let mut test_sock = SimpleSock::grab_socket("RNGProvider".to_string()).unwrap(); + info!( + "Recieving {} from protocol {}", + test_sock.read(1).unwrap()[0], + test_sock.protocol().unwrap() + ); } pub fn socket_startup_rng() { - use picorand::{WyRand, RNG}; - let mut random_socket = SimpleSock::new(); + use picorand::{WyRand, RNG}; + let mut random_socket = SimpleSock::new(); - random_socket.register_protocol("RNGProvider".to_string()); - let bruh = TICK.load(core::sync::atomic::Ordering::Relaxed); + random_socket.register_protocol("RNGProvider".to_string()); + let bruh = TICK.load(core::sync::atomic::Ordering::Relaxed); - let mut rng = RNG::::new(bruh); + let mut rng = RNG::::new(bruh); - for _ in 0..512 { - let x = rng.generate(); - random_socket.write(vec![x]); - } + for _ in 0..512 { + let x = rng.generate(); + random_socket.write(vec![x]); + } } pub fn screen_writer_test() { - let mut sock_print_id = SimpleSock::new(); + let mut sock_print_id = SimpleSock::new(); - sock_print_id.register_protocol("Screen Printer".to_string()); - // sock_print_id.write(format!("a原 b画 cフ dァ eイ fル 集").into()); - // sock_print_id.write(format!("⋮").into()); + sock_print_id.register_protocol("Screen Printer".to_string()); + // sock_print_id.write(format!("a原 b画 cフ dァ eイ fル 集").into()); + // sock_print_id.write(format!("⋮").into()); - sock_print_id.write(format!("λ³ Half Life 3 booting up ㎣").into()); - // sock_print_id.write(format!("Happy birthday 🎉").into()); - // 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()); + sock_print_id.write(format!("λ³ Half Life 3 booting up ㎣").into()); + // sock_print_id.write(format!("Happy birthday 🎉").into()); + // 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()); - for current in (*String::from_utf8_lossy(&sock_print_id.peek().unwrap())).chars() { - vga_e::draw_char(0, 0, current, 0); - } + 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)); + } } pub fn vga_boot_screen() { - let mut abcde = SCREEN_BUFFER.lock(); + let mut abcde = SCREEN_BUFFER.lock(); - for y in 0..480 { - for x in 0..640 { - let segment_x = x * 4 / 640; - let segment_y = y * 4 / 480; - let segment = segment_x + segment_y * 4; + for y in 0..480 { + for x in 0..640 { + let segment_x = x * 4 / 640; + let segment_y = y * 4 / 480; + let segment = segment_x + segment_y * 4; - abcde.set_pixel(x, y, from_vga_16(num_to_vga16(segment as u8))); - } - } + abcde.set_pixel(x, y, from_vga_16(num_to_vga16(segment as u8))); + } + } } pub fn graphics_pipe_test() { - let mut graphics_pipe = SimpleSock::grab_socket("YCompositor".to_string()).unwrap(); + let mut graphics_pipe = SimpleSock::grab_socket("YCompositor".to_string()).unwrap(); - let version = Version { - major: 13, - minor: 123, - patch: 0, - }; - use rkyv::ser::Serializer; - let mut serializer = AllocSerializer::<0>::default(); - serializer.serialize_value(&version).unwrap(); - // let bytes = serializer.into_serializer().into_inner(); + let version = Version { + major: 13, + minor: 123, + patch: 0, + }; + use rkyv::ser::Serializer; + let mut serializer = AllocSerializer::<0>::default(); + serializer.serialize_value(&version).unwrap(); + // let bytes = serializer.into_serializer().into_inner(); - // info!("{:?}", bytes); - let bytes = serializer.into_serializer().into_inner(); - graphics_pipe.write(bytes.into_vec()); - unsafe { - let the_bytes = graphics_pipe.read(3).unwrap(); - let archived = rkyv::archived_root::(&the_bytes); - let deserialized: Version = archived.deserialize(&mut rkyv::Infallible).unwrap(); - trace!("{:?}", deserialized); - } + // info!("{:?}", bytes); + let bytes = serializer.into_serializer().into_inner(); + graphics_pipe.write(bytes.into_vec()); + unsafe { + let the_bytes = graphics_pipe.read(3).unwrap(); + let archived = rkyv::archived_root::(&the_bytes); + let deserialized: Version = archived.deserialize(&mut rkyv::Infallible).unwrap(); + trace!("{:?}", deserialized); + } } pub fn graphics_pipe_startup() { - let mut graphics_pipe = SimpleSock::new(); + let mut graphics_pipe = SimpleSock::new(); - graphics_pipe.register_protocol("YCompositor".to_string()); + graphics_pipe.register_protocol("YCompositor".to_string()); } pub fn graphics_api_demo() { - let mut abcde = SCREEN_BUFFER.lock(); - abcde.force_redraw(); + let mut abcde = SCREEN_BUFFER.lock(); + abcde.force_redraw(); - abcde.draw_filled_circle(100, 100, 300, 0x0000ff00); - abcde.draw_unfilled_rect(100, 100, 400, 200, 0xff000000); - abcde.draw_filled_rect(300, 300, 400, 400, 0xff000000); - abcde.draw_line(100, 100, 400, 200, 0xff000000); - abcde.copy_to_buffer(); + abcde.draw_filled_circle(100, 100, 300, 0x0000ff00); + abcde.draw_unfilled_rect(100, 100, 400, 200, 0xff000000); + abcde.draw_filled_rect(300, 300, 400, 400, 0xff000000); + abcde.draw_line(100, 100, 400, 200, 0xff000000); + abcde.copy_to_buffer(); } pub fn shader_tests() { - let mut graphics = SCREEN_BUFFER.lock(); + let mut graphics = SCREEN_BUFFER.lock(); - graphics.clear(); - graphics.force_redraw(); - graphics.draw_filled_rect(25, 25, 50, 50, 0xff000000); - graphics.set_pixel(50, 50, 0xffffff00); - graphics.shade(); + graphics.clear(); + graphics.force_redraw(); + graphics.draw_filled_rect(25, 25, 50, 50, 0xff000000); + graphics.set_pixel(50, 50, 0xffffff00); + graphics.shade(); - graphics.copy_to_buffer(); + graphics.copy_to_buffer(); - // drop(graphics) + // drop(graphics) } pub fn ser_de_test() { - let mut proc_1 = SimpleSock::new(); - proc_1.register_protocol("ProcessSpawner".to_string()); + let mut proc_1 = SimpleSock::new(); + proc_1.register_protocol("ProcessSpawner".to_string()); - let version = 0; - use rkyv::ser::Serializer; - let mut serializer = AllocSerializer::<0>::default(); - serializer.serialize_value(&version).unwrap(); + let version = 0; + use rkyv::ser::Serializer; + let mut serializer = AllocSerializer::<0>::default(); + serializer.serialize_value(&version).unwrap(); - let bytes = serializer.into_serializer().into_inner(); - proc_1.write(bytes.into_vec()); - unsafe { - let the_bytes = proc_1.read(3).unwrap(); - let archived = rkyv::archived_root::(&the_bytes); - let deserialized: Version = archived.deserialize(&mut rkyv::Infallible).unwrap(); - trace!("{:?}", deserialized); - } + let bytes = serializer.into_serializer().into_inner(); + proc_1.write(bytes.into_vec()); + unsafe { + let the_bytes = proc_1.read(3).unwrap(); + let archived = rkyv::archived_root::(&the_bytes); + let deserialized: Version = archived.deserialize(&mut rkyv::Infallible).unwrap(); + trace!("{:?}", deserialized); + } } diff --git a/ableos/src/vga_e.rs b/ableos/src/vga_e.rs index 2c6a1ff31..9aa76fa0c 100644 --- a/ableos/src/vga_e.rs +++ b/ableos/src/vga_e.rs @@ -32,8 +32,10 @@ const GLYPH_WIDTH: f32 = 10.0; /// * `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" From 9ac6927411bc1c278204488353feedb25d5cd45b Mon Sep 17 00:00:00 2001 From: Elfein Landers Date: Thu, 27 Jan 2022 00:06:58 -0800 Subject: [PATCH 2/2] debugging --- ableos/src/graphics/mod.rs | 360 ++++++++++++++++++++++--------------- ableos/src/kmain.rs | 173 +++++++++--------- ableos/src/tests.rs | 4 +- ableos/src/vga_e.rs | 71 -------- 4 files changed, 301 insertions(+), 307 deletions(-) diff --git a/ableos/src/graphics/mod.rs b/ableos/src/graphics/mod.rs index d625edd56..38e193c09 100644 --- a/ableos/src/graphics/mod.rs +++ b/ableos/src/graphics/mod.rs @@ -1,195 +1,257 @@ 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 { - pub x: usize, - pub y: usize, + pub x: usize, + 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 = spin::Mutex::new(ScreenBuffer::new(640, 480)); } impl ScreenSize { - pub fn new(x: usize, y: usize) -> Self { - Self { x, y } - } + pub fn new(x: usize, y: usize) -> Self { + Self { x, y } + } } pub enum GraphicsReturn { - Ok, - ImproperScreenSize, + Ok, + ImproperScreenSize, } pub struct ScreenBuffer { - pub size: ScreenSize, - pub clear_color: Rgba64, - pub buff: Box<[Rgba64]>, // Vec, + pub size: ScreenSize, + pub clear_color: Rgba64, + pub buff: Box<[Rgba64]>, // Vec, } impl ScreenBuffer { - // Add optional size later - pub fn new(x: usize, y: usize) -> Self { - Self { - size: ScreenSize::new(x, y), - clear_color: 0, - buff: vec![0u64; x * y].into_boxed_slice(), - } - } - pub fn draw_filled_circle(&mut self, cx: i32, cy: i32, radius: usize, color: Rgba64) { - let r = radius as i32 * 2; - for y in 0..640 { - for x in 0..480 { - let dx = cx - x as i32 * 2 - 1; - let dy = cy - y as i32 * 2 - 1; + // Add optional size later + pub fn new(x: usize, y: usize) -> Self { + Self { + size: ScreenSize::new(x, y), + clear_color: 0, + buff: vec![0u64; x * y].into_boxed_slice(), + } + } + pub fn draw_filled_circle(&mut self, cx: i32, cy: i32, radius: usize, color: Rgba64) { + let r = radius as i32 * 2; + for y in 0..640 { + for x in 0..480 { + let dx = cx - x as i32 * 2 - 1; + let dy = cy - y as i32 * 2 - 1; - if dx * dx + dy * dy <= r * r { - self.set_pixel(x, y, color); - }; + if dx * dx + dy * dy <= r * r { + self.set_pixel(x, y, color); + }; + } + } + } + + #[inline] + pub fn set_pixel(&mut self, x: usize, y: usize, color: Rgba64) { + self.buff[y * self.size.x + x] = color; + } + + pub fn clear(&mut self) { + self.buff = vec![0u64; self.buff.len()].into_boxed_slice(); + } + + pub fn blit(&mut self, _width: usize, _height: usize) {} + pub fn draw_filled_rect(&mut self, x1: usize, y1: usize, x2: usize, y2: usize, color: Rgba64) { + for y in y1..y2 { + for x in x1..x2 { + self.set_pixel(x, y, color); + } + } + } + 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); + self.draw_line(x2, y2, x1, y2, color); + self.draw_line(x1, y2, x1, y1, color); + } + + #[inline] + pub fn draw_line(&mut self, x1: usize, y1: usize, x2: usize, y2: usize, color: Rgba64) { + let x = crate::graphics::get_coordinates( + x1.try_into().unwrap(), + y1.try_into().unwrap(), + x2.try_into().unwrap(), + y2.try_into().unwrap(), + ); + + for coord in x { + self.set_pixel(coord.0, coord.1, color); + } + } + + pub fn shade(&mut self) { + for y in 0..100 { + for x in 0..100 { + let rgba_ret = evaluate_shader(x, y, self.buff[y * self.size.x + x]); + match rgba_ret { + Ok(pixel) => { + // info!("{:?}", pixel); + self.set_pixel(x, y, pixel); + } + + Err(err) => error!("{}", err), } - } - } + } + } - #[inline] - pub fn set_pixel(&mut self, x: usize, y: usize, color: Rgba64) { - self.buff[y * self.size.x + x] = color; - } + info!("Shaders done"); + } - pub fn clear(&mut self) { - self.buff = vec![0u64; self.buff.len()].into_boxed_slice(); - } + // TODO force clear + pub fn force_redraw(&mut self) { + use shadeable::pixel_format::into_vga_16; + VGAE.lock().clear_screen(into_vga_16(self.clear_color)); + } - pub fn blit(&mut self, _width: usize, _height: usize) {} - pub fn draw_filled_rect(&mut self, x1: usize, y1: usize, x2: usize, y2: usize, color: Rgba64) { - for y in y1..y2 { - for x in x1..x2 { - self.set_pixel(x, y, 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; } - } - } - 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); - self.draw_line(x2, y2, x1, y2, color); - self.draw_line(x1, y2, x1, y1, color); - } - #[inline] - pub fn draw_line(&mut self, x1: usize, y1: usize, x2: usize, y2: usize, color: Rgba64) { - let x = crate::graphics::get_coordinates( - x1.try_into().unwrap(), - y1.try_into().unwrap(), - x2.try_into().unwrap(), - y2.try_into().unwrap(), - ); - - for coord in x { - self.set_pixel(coord.0, coord.1, color); - } - } - - pub fn shade(&mut self) { - for y in 0..100 { - for x in 0..100 { - let rgba_ret = evaluate_shader(x, y, self.buff[y * self.size.x + x]); - match rgba_ret { - Ok(pixel) => { - // info!("{:?}", pixel); - self.set_pixel(x, y, pixel); - } - - Err(err) => error!("{}", err), - } + 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, + ); + } + }); } - } - - info!("Shaders done"); - } - - // TODO force clear - pub fn force_redraw(&mut self) { - use shadeable::pixel_format::into_vga_16; - VGAE.lock().clear_screen(into_vga_16(self.clear_color)); - } + } + } + } } pub trait VgaBuffer { - fn copy_to_buffer(&self) -> GraphicsReturn; + fn copy_to_buffer(&self) -> GraphicsReturn; } impl VgaBuffer for ScreenBuffer { - fn copy_to_buffer(&self) -> GraphicsReturn { - 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}; - // let vga_color = get_color16(self.buff[y * self.size.x + x]); + fn copy_to_buffer(&self) -> GraphicsReturn { + 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; + // 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]); + let vga_color = into_vga_16(self.buff[y * self.size.x + x]); - if into_vga_16(self.clear_color) != vga_color { - mode.set_pixel(x, y, vga_color); - } + if into_vga_16(self.clear_color) != vga_color { + mode.set_pixel(x, y, vga_color); } - } + } + } - GraphicsReturn::Ok - } + GraphicsReturn::Ok + } } pub fn get_coordinates(x1: i32, y1: i32, x2: i32, y2: i32) -> Vec<(usize, usize)> { - let mut coordinates: Vec<(usize, usize)> = vec![]; - let dx: i32 = i32::abs(x2 - x1); - let dy: i32 = i32::abs(y2 - y1); - let sx: i32 = { - if x1 < x2 { - 1 - } else { - -1 - } - }; - let sy: i32 = { - if y1 < y2 { - 1 - } else { - -1 - } - }; - let mut error: i32 = (if dx > dy { dx } else { -dy }) / 2; - let mut current_x: i32 = x1; - let mut current_y: i32 = y1; - loop { - coordinates.push((current_x as usize, current_y as usize)); - // info!("0 {:?}", (current_x, current_y)); + let mut coordinates: Vec<(usize, usize)> = vec![]; + let dx: i32 = i32::abs(x2 - x1); + let dy: i32 = i32::abs(y2 - y1); + let sx: i32 = { + if x1 < x2 { + 1 + } else { + -1 + } + }; + let sy: i32 = { + if y1 < y2 { + 1 + } else { + -1 + } + }; + let mut error: i32 = (if dx > dy { dx } else { -dy }) / 2; + let mut current_x: i32 = x1; + let mut current_y: i32 = y1; + loop { + coordinates.push((current_x as usize, current_y as usize)); + // info!("0 {:?}", (current_x, current_y)); - if current_x == x2 && current_y == y2 { - break; - } + if current_x == x2 && current_y == y2 { + break; + } - let error2: i32 = error; + let error2: i32 = error; - if error2 > -dx { - error -= dy; - current_x += sx; - } - if error2 < dy { - error += dx; - current_y += sy; - } - } - coordinates + if error2 > -dx { + error -= dy; + current_x += sx; + } + if error2 < dy { + error += dx; + current_y += sy; + } + } + coordinates } diff --git a/ableos/src/kmain.rs b/ableos/src/kmain.rs index dc6f35194..78d77772b 100644 --- a/ableos/src/kmain.rs +++ b/ableos/src/kmain.rs @@ -3,135 +3,136 @@ use alloc::{format, vec::Vec}; use crate::{ - boot_conf::BootConfig, - capabilities::FileAccess, - file::{File, PathRep}, - scheduler::SCHEDULER, - ALIAS_TABLE, + boot_conf::BootConfig, + capabilities::FileAccess, + file::{File, PathRep}, + scheduler::SCHEDULER, + ALIAS_TABLE, }; // use crate::scheduler; use { - crate::{ - arch::{init, sloop}, - boot_conf, - experiments::{ - info::master, - systeminfo::{KERNEL_VERSION, RELEASE_TYPE}, - }, - graphics::{VgaBuffer, SCREEN_BUFFER}, - relib::network::socket::Socket, - relib::network::socket::{SimpleSock, SocketReturns}, - vga_e::{self, num_to_vga16}, - }, - alloc::{ - string::{String, ToString}, - vec, - }, - core::sync::atomic::{AtomicU64, Ordering::*}, - lazy_static::lazy_static, - log::*, - picorand::PicoRandGenerate, - rkyv::{ser::serializers::AllocSerializer, Deserialize}, - shadeable::pixel_format::from_vga_16, - y_compositor_protocol::Version, + crate::{ + arch::{init, sloop}, + boot_conf, + experiments::{ + info::master, + systeminfo::{KERNEL_VERSION, RELEASE_TYPE}, + }, + graphics::{VgaBuffer, SCREEN_BUFFER}, + relib::network::socket::Socket, + relib::network::socket::{SimpleSock, SocketReturns}, + vga_e::{self, num_to_vga16}, + }, + alloc::{ + string::{String, ToString}, + vec, + }, + core::sync::atomic::{AtomicU64, Ordering::*}, + lazy_static::lazy_static, + log::*, + picorand::PicoRandGenerate, + rkyv::{ser::serializers::AllocSerializer, Deserialize}, + shadeable::pixel_format::from_vga_16, + y_compositor_protocol::Version, }; #[no_mangle] #[allow(unconditional_recursion)] pub extern "C" fn stack_overflow() -> u8 { - stack_overflow(); - // meme number - 69 // NOTE: Any specific reason for this number aside from memes? + stack_overflow(); + // meme number + 69 // NOTE: Any specific reason for this number aside from memes? } lazy_static! { - pub static ref KEY_BUFFER: spin::Mutex = spin::Mutex::new("".to_string()); - pub static ref TICK: AtomicU64 = AtomicU64::new(0); - pub static ref BOOT_CONF: BootConfig = boot_conf::BootConfig::new(); + pub static ref KEY_BUFFER: spin::Mutex = spin::Mutex::new("".to_string()); + pub static ref TICK: AtomicU64 = AtomicU64::new(0); + pub static ref BOOT_CONF: BootConfig = boot_conf::BootConfig::new(); } /// The main entry point of the kernel #[no_mangle] pub fn kernel_main() -> ! { - init::init(); - log::set_max_level(BOOT_CONF.log_level()); + init::init(); + log::set_max_level(BOOT_CONF.log_level()); - use crate::scheduler::Priority; - let mut scheduler = SCHEDULER.lock(); + use crate::scheduler::Priority; + let mut scheduler = SCHEDULER.lock(); - use Priority::*; + use Priority::*; - let mut process_1 = scheduler.new_process(High); - process_1.capabilities.files = FileAccess::Some(vec![PathRep { - location: FileLocations::Home, - file_name: "test".to_string(), - }]); - scheduler.add_process(process_1); - for ref_process in &scheduler.list { - trace!("{:?}", ref_process); - } - drop(scheduler); + let mut process_1 = scheduler.new_process(High); + process_1.capabilities.files = FileAccess::Some(vec![PathRep { + location: FileLocations::Home, + file_name: "test".to_string(), + }]); + scheduler.add_process(process_1); + for ref_process in &scheduler.list { + trace!("{:?}", ref_process); + } + drop(scheduler); - use crate::proto_filetable::contain::FILE_TABLE; - use crate::proto_filetable::file::FileLocations; + use crate::proto_filetable::contain::FILE_TABLE; + use crate::proto_filetable::file::FileLocations; - let mut file_table = FILE_TABLE.lock(); - let mut new_file = File::new(FileLocations::Bin, "test".to_string(), "txt".to_string()); + let mut file_table = FILE_TABLE.lock(); + let mut new_file = File::new(FileLocations::Bin, "test".to_string(), "txt".to_string()); - new_file.write_bytes(b"Hello, world!"); - file_table.add_file("test", new_file); + new_file.write_bytes(b"Hello, world!"); + file_table.add_file("test", new_file); - let file = file_table.get_file("test"); + let file = file_table.get_file("test"); - match file { - Some(file) => { - let file_bytes = &file.data_pointer; - let file_string = String::from_utf8(file_bytes.to_vec()).unwrap(); - info!("{}", file_string); - } - None => { - info!("File not found"); - } - } + match file { + Some(file) => { + let file_bytes = &file.data_pointer; + let file_string = String::from_utf8(file_bytes.to_vec()).unwrap(); + info!("{}", file_string); + } + None => { + info!("File not found"); + } + } - crate::tests::screen_writer_test(); + crate::tests::screen_writer_test(); - use crate::wasm::WasmProgram; - let ret = WasmProgram::new_from_bytes(&[0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00]); - trace!("Binary Valid: {:?}", ret.validate_header()); + use crate::wasm::WasmProgram; + let ret = WasmProgram::new_from_bytes(&[0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00]); + trace!("Binary Valid: {:?}", ret.validate_header()); - sloop() + sloop() } /// called by arch specific timers to tick up all kernel related functions pub fn tick() { - let mut data = TICK.load(Relaxed); - data += 1; + let mut data = TICK.load(Relaxed); + data += 1; - crate::kernel_state::KERNEL_STATE.lock().update_state(); + 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) + TICK.store(data, Relaxed) } + /// called every time a key is pressed to add it to the randomness pool pub fn key_entropy(key: u8) {} pub fn cpu_socket_startup() { - let mut cpu_info_socket = SimpleSock::new(); - cpu_info_socket.register_protocol("CPU_INFO".to_string()); + let mut cpu_info_socket = SimpleSock::new(); + cpu_info_socket.register_protocol("CPU_INFO".to_string()); - let x = master().unwrap(); - let _xyz = x.brand_string().unwrap(); + let x = master().unwrap(); + let _xyz = x.brand_string().unwrap(); } pub fn log_version_data() { - info!("{} v{}", RELEASE_TYPE, KERNEL_VERSION); - info!( - "Brand String: {:?}", - master().unwrap().brand_string().unwrap() - ); + info!("{} v{}", RELEASE_TYPE, KERNEL_VERSION); + info!( + "Brand String: {:?}", + master().unwrap().brand_string().unwrap() + ); } diff --git a/ableos/src/tests.rs b/ableos/src/tests.rs index c26d0b1a8..80b7ec75c 100644 --- a/ableos/src/tests.rs +++ b/ableos/src/tests.rs @@ -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() { diff --git a/ableos/src/vga_e.rs b/ableos/src/vga_e.rs index 9aa76fa0c..fb21b8ac4 100644 --- a/ableos/src/vga_e.rs +++ b/ableos/src/vga_e.rs @@ -20,77 +20,6 @@ lazy_static::lazy_static! { pub static ref VGAE_BUFF_OFFSET_Y: spin::Mutex = 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 {