ableos/ableos/src/kmain.rs

178 lines
4.3 KiB
Rust

#![allow(clippy::empty_loop)]
// use std::println;
use alloc::format;
use shadeable::pixel_format::{into_vga_16, new_rgba64};
use vga::{colors::Color16, writers::GraphicsWriter};
use crate::{
graphics::VgaBuffer,
relib::network::socket::{SimpleSock, SocketReturns},
vga_e::{self, VGAE},
};
use log::*;
use {
crate::{
arch::{drivers::graphics::GraphicsBuffer, init, sloop},
driver_traits::graphics::Graphics,
experiments::{
info::master,
systeminfo::{KERNEL_VERSION, RELEASE_TYPE},
},
graphics::ScreenBuffer,
// log::LOG_STATE,
relib::math::rand::RAND_HANDLE,
relib::network::socket::Socket,
scheduler::{test_fn, Thread, ThreadList},
},
alloc::{
string::{String, ToString},
vec,
},
lazy_static::lazy_static,
};
#[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?
}
lazy_static! {
pub static ref KEY_BUFFER: spin::Mutex<String> = spin::Mutex::new("".to_string());
pub static ref THREAD_LIST: spin::Mutex<ThreadList> = spin::Mutex::new(vec![]);
pub static ref TICK: spin::Mutex<u64> = spin::Mutex::new(0);
}
#[no_mangle]
pub fn kernel_main() -> ! {
init::init();
log::set_max_level(LevelFilter::Trace);
// crate::wasm::evaluate();
let mut abcde = ScreenBuffer::new(480, 640);
// abcde.clear();
// abcde.copy_to_buffer();
VGAE.lock().clear_screen(Color16::Black);
trace!("length of screen buffer {}", abcde.buff.len());
trace!("Screen size {:?}", abcde.size);
abcde.set_pixel(10, 10, new_rgba64(255, 0, 0, 255));
for y in 30..60 {
for x in 1..=639 {
abcde.set_pixel(x, y, new_rgba64(255, 255, 8, 255));
}
}
// info!("{:?}", abcde.buff);
abcde.copy_to_buffer();
{
let mut xyz = SimpleSock::new();
xyz.peek();
xyz.write(vec![0, 1, 2, 3]);
let x = "simple 🧦".to_string().into_bytes();
xyz.write(x);
info!("{:?}", &xyz.read(4).unwrap());
match &xyz.peek() {
SocketReturns::ReadOk(strr) => {
let out = String::from_utf8_lossy(strr);
info!("{}", out);
}
SocketReturns::ReadIndexOutOfBounds => todo!(),
SocketReturns::WriteOk => todo!(),
}
}
let mut sock_print_id = SimpleSock::new();
{
// sock_print_id.write(format!("原 画 フ ァ イ ル 集").into());
sock_print_id.write(format!("simple sockets are based").into());
sock_print_id.write(format!("🤯 🍆 💦").into());
// sock_print_id.write(format!("1....2....3....4....5....6....7....8....9").into());
}
// crate::relib::image::mono_bitmap::bruh();
if false {
for x in (*String::from_utf8_lossy(&sock_print_id.peek().unwrap()))
.chars()
.enumerate()
{
vga_e::draw_char(x.1, x.0);
}
}
if false {
draw_filled_circle(400, 350, 99, Color16::Black);
// let _ = shadeable::evaluate_shader(1);
}
// abcde.clear();
// abcde.copy_to_buffer();
// stack_overflow();
sloop()
}
/// called by arch specific timers to tick up all kernel related functions
pub fn tick() {
let mut data = TICK.lock();
*data += 1;
RAND_HANDLE.lock().seed_entropy_timer(*data);
// println!("{}", *data);
crate::kernel_state::KERNEL_STATE.lock().update_state();
}
pub fn key_entropy(key: u8) {
RAND_HANDLE.lock().seed_entropy_keyboard(key);
}
pub fn test_threads() {
let mut a_thread = Thread::new();
a_thread.new_task(test_fn);
a_thread.new_task(test_fn);
THREAD_LIST.lock().push(a_thread);
}
fn draw_filled_circle(cx: i32, cy: i32, radius: usize, color: Color16) {
let vga = VGAE.lock();
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 {
vga.set_pixel(x, y, color);
};
}
}
}
pub fn log_version_data() {
info!("{} v{}", RELEASE_TYPE, KERNEL_VERSION);
info!(
"Brand String: {:?}",
master().unwrap().brand_string().unwrap()
);
}