diff --git a/ableos/Cargo.toml b/ableos/Cargo.toml index b1f2ff56c..3b5635030 100644 --- a/ableos/Cargo.toml +++ b/ableos/Cargo.toml @@ -34,8 +34,6 @@ vga = "*" pretty-hex = "0.2.1" - - [dependencies.ab_glyph] default-features = false features = ["libm"] diff --git a/ableos/assets/fonts/MesloLGS NF Regular.ttf b/ableos/assets/fonts/MesloLGS NF Regular.ttf new file mode 100644 index 000000000..b829758ea Binary files /dev/null and b/ableos/assets/fonts/MesloLGS NF Regular.ttf differ diff --git a/ableos/assets/fonts/LICENSE.txt b/ableos/assets/fonts/Roboto/LICENSE.txt similarity index 100% rename from ableos/assets/fonts/LICENSE.txt rename to ableos/assets/fonts/Roboto/LICENSE.txt diff --git a/ableos/assets/fonts/Roboto-Black.ttf b/ableos/assets/fonts/Roboto/Roboto-Black.ttf similarity index 100% rename from ableos/assets/fonts/Roboto-Black.ttf rename to ableos/assets/fonts/Roboto/Roboto-Black.ttf diff --git a/ableos/assets/fonts/Roboto-BlackItalic.ttf b/ableos/assets/fonts/Roboto/Roboto-BlackItalic.ttf similarity index 100% rename from ableos/assets/fonts/Roboto-BlackItalic.ttf rename to ableos/assets/fonts/Roboto/Roboto-BlackItalic.ttf diff --git a/ableos/assets/fonts/Roboto-Bold.ttf b/ableos/assets/fonts/Roboto/Roboto-Bold.ttf similarity index 100% rename from ableos/assets/fonts/Roboto-Bold.ttf rename to ableos/assets/fonts/Roboto/Roboto-Bold.ttf diff --git a/ableos/assets/fonts/Roboto-BoldItalic.ttf b/ableos/assets/fonts/Roboto/Roboto-BoldItalic.ttf similarity index 100% rename from ableos/assets/fonts/Roboto-BoldItalic.ttf rename to ableos/assets/fonts/Roboto/Roboto-BoldItalic.ttf diff --git a/ableos/assets/fonts/Roboto-Italic.ttf b/ableos/assets/fonts/Roboto/Roboto-Italic.ttf similarity index 100% rename from ableos/assets/fonts/Roboto-Italic.ttf rename to ableos/assets/fonts/Roboto/Roboto-Italic.ttf diff --git a/ableos/assets/fonts/Roboto-Light.ttf b/ableos/assets/fonts/Roboto/Roboto-Light.ttf similarity index 100% rename from ableos/assets/fonts/Roboto-Light.ttf rename to ableos/assets/fonts/Roboto/Roboto-Light.ttf diff --git a/ableos/assets/fonts/Roboto-LightItalic.ttf b/ableos/assets/fonts/Roboto/Roboto-LightItalic.ttf similarity index 100% rename from ableos/assets/fonts/Roboto-LightItalic.ttf rename to ableos/assets/fonts/Roboto/Roboto-LightItalic.ttf diff --git a/ableos/assets/fonts/Roboto-Medium.ttf b/ableos/assets/fonts/Roboto/Roboto-Medium.ttf similarity index 100% rename from ableos/assets/fonts/Roboto-Medium.ttf rename to ableos/assets/fonts/Roboto/Roboto-Medium.ttf diff --git a/ableos/assets/fonts/Roboto-MediumItalic.ttf b/ableos/assets/fonts/Roboto/Roboto-MediumItalic.ttf similarity index 100% rename from ableos/assets/fonts/Roboto-MediumItalic.ttf rename to ableos/assets/fonts/Roboto/Roboto-MediumItalic.ttf diff --git a/ableos/assets/fonts/Roboto-Regular.ttf b/ableos/assets/fonts/Roboto/Roboto-Regular.ttf similarity index 100% rename from ableos/assets/fonts/Roboto-Regular.ttf rename to ableos/assets/fonts/Roboto/Roboto-Regular.ttf diff --git a/ableos/assets/fonts/Roboto-Thin.ttf b/ableos/assets/fonts/Roboto/Roboto-Thin.ttf similarity index 100% rename from ableos/assets/fonts/Roboto-Thin.ttf rename to ableos/assets/fonts/Roboto/Roboto-Thin.ttf diff --git a/ableos/assets/fonts/Roboto-ThinItalic.ttf b/ableos/assets/fonts/Roboto/Roboto-ThinItalic.ttf similarity index 100% rename from ableos/assets/fonts/Roboto-ThinItalic.ttf rename to ableos/assets/fonts/Roboto/Roboto-ThinItalic.ttf diff --git a/ableos/assets/fonts/Untitled1.ttf b/ableos/assets/fonts/Untitled1.ttf new file mode 100644 index 000000000..8c97b1f7b Binary files /dev/null and b/ableos/assets/fonts/Untitled1.ttf differ diff --git a/ableos/src/kmain.rs b/ableos/src/kmain.rs index aa4afe09a..0661952d2 100644 --- a/ableos/src/kmain.rs +++ b/ableos/src/kmain.rs @@ -1,8 +1,11 @@ #![allow(clippy::empty_loop)] -use alloc::format; +use vga::{colors::Color16, writers::GraphicsWriter}; -use crate::relib::network::socket::Socket; +use crate::{ + relib::network::socket::SocketReturns, + vga_e::{self, VGAE}, +}; use { crate::{ @@ -12,10 +15,10 @@ use { info::master, systeminfo::{KERNEL_VERSION, RELEASE_TYPE}, }, - log::LOG_STATE, + // log::LOG_STATE, relib::math::rand::RAND_HANDLE, + relib::network::socket::{Socket, SOCKETS}, scheduler::{test_fn, Thread, ThreadList}, - vga_e, }, alloc::{ string::{String, ToString}, @@ -40,12 +43,6 @@ lazy_static! { #[no_mangle] pub fn kernel_main() -> ! { - if false { - LOG_STATE.lock().info = false; - LOG_STATE.lock().trace = false; - LOG_STATE.lock().debug = false; - } - init::init(); { @@ -59,7 +56,6 @@ pub fn kernel_main() -> ! { } crate::wasm::evaluate(); - { info!("{} v{}", RELEASE_TYPE, KERNEL_VERSION); info!( @@ -71,35 +67,42 @@ pub fn kernel_main() -> ! { println!("$RED$hi$RESET$"); } } + { use crate::relib::network::socket::SimpleSock; - use crate::utils::type_of; + let mut xyz = SimpleSock::new(); - xyz.write(vec![0, 0, 1, 0]); - xyz.close(); - println!("type of socket: {:?}", type_of(&xyz)); - println!("contents: {:?}", &xyz.read()); + xyz.peek(); - println!("length: {:?}", xyz.read().len()); - drop(xyz); + xyz.write(vec![0, 1, 2, 3]); + + let x = "simple 🧦".to_string().into_bytes(); + xyz.write(x); + + info!("{:?}", &xyz.read(4).unwrap()); + + println!("{:?}", &xyz.peek().unwrap()); + + match &xyz.peek() { + SocketReturns::ReadOk(strr) => { + let out = String::from_utf8_lossy(strr); + + info!("{}", out); + } + SocketReturns::ReadIndexOutOfBounds => todo!(), + SocketReturns::WriteOk => todo!(), + } } - { - use pretty_hex::*; + println!("$GREEN$able$RESET$@$LIGHTBLUE$stAble$ $RED$->$RESET$"); - let v = vec![222, 173, 190, 239, 202, 254, 32, 24]; - assert_eq!(simple_hex(&v), format!("{}", v.hex_dump())); + VGAE.lock().clear_screen(Color16::Black); - println!("{}", v.hex_dump()); + for x in "μkernel".chars().enumerate() { + vga_e::draw_char(x.1, x.0); } - - // - - info!("新着情報"); - - print!("$GREEN$able$RESET$@$LIGHTBLUE$stAble$ $RED$->$RESET$"); - vga_e::draw_q(); + // vga_e::test_it_fucko(); // stack_overflow(); sloop() diff --git a/ableos/src/lib.rs b/ableos/src/lib.rs index d52e3194e..c93ab6d56 100644 --- a/ableos/src/lib.rs +++ b/ableos/src/lib.rs @@ -27,6 +27,7 @@ pub mod arch; #[macro_use] pub mod print; + #[macro_use] pub mod log; diff --git a/ableos/src/relib/network/socket.rs b/ableos/src/relib/network/socket.rs index dd61b47ba..0b471a7a4 100644 --- a/ableos/src/relib/network/socket.rs +++ b/ableos/src/relib/network/socket.rs @@ -3,36 +3,97 @@ use alloc::vec::Vec; pub type Stream = Vec; +pub struct SocketID { + pub id: usize, +} +impl Socket for SocketID { + fn peek(&mut self) -> SocketReturns { + SOCKETS.lock()[self.id].peek() + } + + fn read(&mut self, length: usize) -> SocketReturns { + SOCKETS.lock()[self.id].read(length) + } + + fn write(&mut self, stream: Stream) -> SocketReturns { + SOCKETS.lock()[self.id].write(stream) + } +} + +pub type SocketState = Vec; + +lazy_static::lazy_static! { + pub static ref SOCKETS: spin::Mutex = spin::Mutex::new(vec![]); +} + pub trait Socket { - fn new() {} - fn read(&mut self) -> Vec; - fn write(&mut self, stream: Stream); + fn peek(&mut self) -> SocketReturns; + + /// Reads from the socket and removes read bytes from the socket + fn read(&mut self, length: usize) -> SocketReturns; + + fn write(&mut self, stream: Stream) -> SocketReturns; fn close(&mut self) {} } +#[derive(Debug)] +pub enum SocketReturns { + ReadOk(Stream), + ReadIndexOutOfBounds, + WriteOk, +} + +impl SocketReturns { + pub fn unwrap(self) -> Stream { + match self { + SocketReturns::ReadOk(stream) => stream, + SocketReturns::ReadIndexOutOfBounds => panic!("Read Index Out Of Bounds"), + SocketReturns::WriteOk => vec![1], + } + } +} pub struct SimpleSock { stream: Vec, } impl SimpleSock { - pub fn new() -> Self { - Self { stream: vec![] } + pub fn new() -> SocketID { + let sock = SimpleSock { stream: vec![] }; + let mut sock_lock = SOCKETS.lock(); + sock_lock.push(sock); + + SocketID { + id: sock_lock.len() - 1, + } } } impl Socket for SimpleSock { - fn new() {} - fn read(&mut self) -> Vec { + fn peek(&mut self) -> SocketReturns { let mut return_vec = vec![]; + for x in &self.stream { return_vec.push(x.clone()); } - return_vec + SocketReturns::ReadOk(return_vec) } - fn write(&mut self, stream: Stream) { + fn read(&mut self, length: usize) -> SocketReturns { + let mut return_vec = vec![]; + if length > self.stream.len() { + SocketReturns::ReadIndexOutOfBounds + } else { + for _ in 0..length { + return_vec.push(self.stream[0]); + self.stream.remove(0); + } + SocketReturns::ReadOk(return_vec) + } + } + fn write(&mut self, stream: Stream) -> SocketReturns { for byte in stream { self.stream.push(byte); } + SocketReturns::WriteOk } fn close(&mut self) {} } diff --git a/ableos/src/vga_e.rs b/ableos/src/vga_e.rs index e0df08fe7..30de4d5ce 100644 --- a/ableos/src/vga_e.rs +++ b/ableos/src/vga_e.rs @@ -1,3 +1,4 @@ +use ab_glyph::{Font, FontRef, Glyph}; use alloc::string::String; use vga::{ @@ -5,6 +6,18 @@ use vga::{ writers::{Graphics640x480x16, GraphicsWriter}, }; +lazy_static::lazy_static! { + + pub static ref VGAE: spin::Mutex = { + let xyz = Graphics640x480x16::new(); + xyz.set_mode(); + spin::Mutex::new(xyz) + }; +} + +pub const FONT: &[u8; 1279380] = + include_bytes!("../../ableos/assets/fonts/MesloLGS NF Regular.ttf"); + pub fn test_it_fucko() { let mode = Graphics640x480x16::new(); mode.set_mode(); @@ -31,10 +44,6 @@ pub fn test_it_fucko() { for (offset, character) in "ableOS".chars().enumerate() { mode.draw_character(270 + offset * 8, 72, character, Color16::White) } - - for (offset, character) in "S".chars().enumerate() { - mode.draw_character(270 + offset * 8, 50, character, Color16::White) - } } pub trait GraphicsAPI { @@ -44,29 +53,31 @@ pub trait GraphicsAPI { pub struct Buffer { label: String, resolution: (u64, u64), - // pointer } -pub fn draw_q() { - let mode = Graphics640x480x16::new(); - mode.set_mode(); - mode.clear_screen(Color16::Black); - use ab_glyph::{point, Font, FontRef, Glyph}; +// #[deprecated(note = "Deprecated because you should use the damn graphics api")] +pub fn draw_char(character: char, offset: usize) { + let mode = *VGAE.lock(); - let font = - FontRef::try_from_slice(include_bytes!("../../ableos/assets/fonts/Roboto-Black.ttf")) - .unwrap(); + let font = FontRef::try_from_slice(FONT).unwrap(); // Get a glyph for 'q' with a scale & position. - let q_glyph: Glyph = font - .glyph_id('q') - .with_scale_and_position(24.0, point(100.0, 0.0)); + let q_glyph: Glyph = font.glyph_id(character).with_scale(100.0); // Draw it. if let Some(q) = font.outline_glyph(q_glyph) { - q.draw(|x, y, _c| { - mode.set_pixel(x as usize, y as usize, Color16::LightBlue); + q.draw(|x, y, c| { + // info!("{}", c); + + if c > 0.2 { + mode.set_pixel( + x as usize + (offset * 50), + // + y as usize, + Color16::LightBlue, + ); + } }); } }