2021-11-16 00:09:27 -06:00
|
|
|
#![allow(clippy::empty_loop)]
|
2021-11-28 14:50:14 -06:00
|
|
|
|
2022-01-18 06:15:51 -06:00
|
|
|
// use std::println;
|
|
|
|
|
|
|
|
use alloc::format;
|
|
|
|
|
2022-01-18 08:30:09 -06:00
|
|
|
use shadeable::pixel_format::{from_vga_16, into_vga_16, new_rgba64};
|
2022-01-16 14:55:58 -06:00
|
|
|
use vga::{colors::Color16, writers::GraphicsWriter};
|
2022-01-16 09:23:19 -06:00
|
|
|
|
2022-01-16 14:55:58 -06:00
|
|
|
use crate::{
|
2022-01-18 06:15:51 -06:00
|
|
|
graphics::VgaBuffer,
|
|
|
|
relib::network::socket::{SimpleSock, SocketReturns},
|
2022-01-18 08:30:09 -06:00
|
|
|
vga_e::{self, num_to_vga16, VGAE},
|
2022-01-16 14:55:58 -06:00
|
|
|
};
|
2022-01-16 09:23:19 -06:00
|
|
|
|
2022-01-16 19:42:11 -06:00
|
|
|
use log::*;
|
|
|
|
|
2021-12-24 03:30:27 -06:00
|
|
|
use {
|
|
|
|
crate::{
|
|
|
|
arch::{drivers::graphics::GraphicsBuffer, init, sloop},
|
|
|
|
driver_traits::graphics::Graphics,
|
2022-01-16 09:23:19 -06:00
|
|
|
experiments::{
|
|
|
|
info::master,
|
|
|
|
systeminfo::{KERNEL_VERSION, RELEASE_TYPE},
|
|
|
|
},
|
2022-01-18 06:15:51 -06:00
|
|
|
|
|
|
|
graphics::ScreenBuffer,
|
2022-01-16 14:55:58 -06:00
|
|
|
// log::LOG_STATE,
|
2021-12-24 03:30:27 -06:00
|
|
|
relib::math::rand::RAND_HANDLE,
|
2022-01-16 19:42:11 -06:00
|
|
|
relib::network::socket::Socket,
|
2021-12-24 03:30:27 -06:00
|
|
|
scheduler::{test_fn, Thread, ThreadList},
|
2022-01-16 09:23:19 -06:00
|
|
|
},
|
|
|
|
alloc::{
|
|
|
|
string::{String, ToString},
|
|
|
|
vec,
|
2021-12-24 03:30:27 -06:00
|
|
|
},
|
|
|
|
lazy_static::lazy_static,
|
2021-11-16 00:09:27 -06:00
|
|
|
};
|
2022-01-13 08:54:33 -06:00
|
|
|
|
2021-11-16 00:09:27 -06:00
|
|
|
#[no_mangle]
|
|
|
|
#[allow(unconditional_recursion)]
|
|
|
|
pub extern "C" fn stack_overflow() -> u8 {
|
|
|
|
stack_overflow();
|
2021-11-23 05:54:57 -06:00
|
|
|
// meme number
|
2022-01-07 10:31:47 -06:00
|
|
|
69 // NOTE: Any specific reason for this number aside from memes?
|
2021-11-16 00:09:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
lazy_static! {
|
2022-01-07 10:31:47 -06:00
|
|
|
pub static ref KEY_BUFFER: spin::Mutex<String> = spin::Mutex::new("".to_string());
|
2021-12-24 03:30:27 -06:00
|
|
|
pub static ref THREAD_LIST: spin::Mutex<ThreadList> = spin::Mutex::new(vec![]);
|
|
|
|
pub static ref TICK: spin::Mutex<u64> = spin::Mutex::new(0);
|
2021-11-16 00:09:27 -06:00
|
|
|
}
|
2021-11-23 06:01:42 -06:00
|
|
|
|
2021-11-16 00:09:27 -06:00
|
|
|
#[no_mangle]
|
2021-11-23 06:01:42 -06:00
|
|
|
pub fn kernel_main() -> ! {
|
2021-11-16 00:09:27 -06:00
|
|
|
init::init();
|
2022-01-07 10:31:47 -06:00
|
|
|
|
2022-01-18 06:15:51 -06:00
|
|
|
log::set_max_level(LevelFilter::Trace);
|
|
|
|
// crate::wasm::evaluate();
|
2022-01-16 19:42:11 -06:00
|
|
|
|
2022-01-18 08:30:09 -06:00
|
|
|
let mut abcde = ScreenBuffer::new(640, 480);
|
2022-01-18 06:15:51 -06:00
|
|
|
// abcde.clear();
|
|
|
|
// abcde.copy_to_buffer();
|
2022-01-18 08:30:09 -06:00
|
|
|
|
2022-01-18 06:15:51 -06:00
|
|
|
VGAE.lock().clear_screen(Color16::Black);
|
2021-12-24 13:00:20 -06:00
|
|
|
|
2022-01-18 06:15:51 -06:00
|
|
|
trace!("length of screen buffer {}", abcde.buff.len());
|
|
|
|
trace!("Screen size {:?}", abcde.size);
|
2021-12-24 03:30:27 -06:00
|
|
|
|
2022-01-18 08:30:09 -06:00
|
|
|
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)));
|
2022-01-13 08:54:33 -06:00
|
|
|
}
|
2022-01-02 04:04:36 -06:00
|
|
|
}
|
2022-01-18 08:30:09 -06:00
|
|
|
|
|
|
|
// abcde.copy_to_buffer();
|
2022-01-16 14:55:58 -06:00
|
|
|
|
2022-01-16 09:23:19 -06:00
|
|
|
{
|
|
|
|
let mut xyz = SimpleSock::new();
|
|
|
|
|
2022-01-16 14:55:58 -06:00
|
|
|
xyz.peek();
|
2022-01-16 09:23:19 -06:00
|
|
|
|
2022-01-16 14:55:58 -06:00
|
|
|
xyz.write(vec![0, 1, 2, 3]);
|
2022-01-16 09:23:19 -06:00
|
|
|
|
2022-01-16 14:55:58 -06:00
|
|
|
let x = "simple 🧦".to_string().into_bytes();
|
|
|
|
xyz.write(x);
|
|
|
|
|
|
|
|
info!("{:?}", &xyz.read(4).unwrap());
|
2022-01-16 09:23:19 -06:00
|
|
|
|
2022-01-16 14:55:58 -06:00
|
|
|
match &xyz.peek() {
|
|
|
|
SocketReturns::ReadOk(strr) => {
|
|
|
|
let out = String::from_utf8_lossy(strr);
|
|
|
|
|
|
|
|
info!("{}", out);
|
|
|
|
}
|
|
|
|
SocketReturns::ReadIndexOutOfBounds => todo!(),
|
|
|
|
SocketReturns::WriteOk => todo!(),
|
|
|
|
}
|
2022-01-16 09:23:19 -06:00
|
|
|
}
|
|
|
|
|
2022-01-18 06:15:51 -06:00
|
|
|
let mut sock_print_id = SimpleSock::new();
|
2022-01-07 10:31:47 -06:00
|
|
|
|
2022-01-18 06:15:51 -06:00
|
|
|
{
|
2022-01-18 08:30:09 -06:00
|
|
|
sock_print_id.write(format!("a原b画cフdァeイfル 集").into());
|
|
|
|
// sock_print_id.write(format!("simple sockets are based").into());
|
2022-01-18 06:15:51 -06:00
|
|
|
// sock_print_id.write(format!("1....2....3....4....5....6....7....8....9").into());
|
|
|
|
}
|
|
|
|
// crate::relib::image::mono_bitmap::bruh();
|
2022-01-16 19:42:11 -06:00
|
|
|
|
2022-01-18 08:30:09 -06:00
|
|
|
if true {
|
|
|
|
let mut prev = None;
|
|
|
|
for current in (*String::from_utf8_lossy(&sock_print_id.peek().unwrap())).chars() {
|
|
|
|
vga_e::draw_char(prev, current, 0);
|
|
|
|
|
|
|
|
prev = Some(current);
|
2022-01-16 19:42:11 -06:00
|
|
|
}
|
2022-01-16 14:55:58 -06:00
|
|
|
}
|
2022-01-18 06:15:51 -06:00
|
|
|
|
|
|
|
if false {
|
|
|
|
draw_filled_circle(400, 350, 99, Color16::Black);
|
|
|
|
// let _ = shadeable::evaluate_shader(1);
|
2022-01-16 19:42:11 -06:00
|
|
|
}
|
|
|
|
|
2022-01-18 06:15:51 -06:00
|
|
|
// abcde.clear();
|
|
|
|
// abcde.copy_to_buffer();
|
2022-01-16 19:42:11 -06:00
|
|
|
|
2021-11-16 00:09:27 -06:00
|
|
|
// stack_overflow();
|
2022-01-13 08:54:33 -06:00
|
|
|
|
2021-11-23 05:54:57 -06:00
|
|
|
sloop()
|
2021-11-16 00:09:27 -06:00
|
|
|
}
|
2021-11-23 08:49:41 -06:00
|
|
|
|
2021-11-16 00:09:27 -06:00
|
|
|
/// 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);
|
2022-01-13 08:54:33 -06:00
|
|
|
|
|
|
|
// println!("{}", *data);
|
|
|
|
crate::kernel_state::KERNEL_STATE.lock().update_state();
|
2021-11-16 00:09:27 -06:00
|
|
|
}
|
2021-11-23 08:49:41 -06:00
|
|
|
|
2021-11-16 00:09:27 -06:00
|
|
|
pub fn key_entropy(key: u8) {
|
|
|
|
RAND_HANDLE.lock().seed_entropy_keyboard(key);
|
|
|
|
}
|
2022-01-18 06:15:51 -06:00
|
|
|
|
|
|
|
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()
|
|
|
|
);
|
|
|
|
}
|