Font rendering semi-done

master
Able 2022-01-16 14:55:58 -06:00
parent 60a034f509
commit 89b720eaee
Signed by untrusted user: able
GPG Key ID: D164AF5F5700BE51
20 changed files with 133 additions and 59 deletions

View File

@ -34,8 +34,6 @@ vga = "*"
pretty-hex = "0.2.1"
[dependencies.ab_glyph]
default-features = false
features = ["libm"]

Binary file not shown.

Binary file not shown.

View File

@ -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()

View File

@ -27,6 +27,7 @@ pub mod arch;
#[macro_use]
pub mod print;
#[macro_use]
pub mod log;

View File

@ -3,36 +3,97 @@ use alloc::vec::Vec;
pub type Stream = Vec<u8>;
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<SimpleSock>;
lazy_static::lazy_static! {
pub static ref SOCKETS: spin::Mutex<SocketState> = spin::Mutex::new(vec![]);
}
pub trait Socket {
fn new() {}
fn read(&mut self) -> Vec<u8>;
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<u8>,
}
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<u8> {
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) {}
}

View File

@ -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<Graphics640x480x16> = {
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,
);
}
});
}
}