2022-01-27 01:37:12 -06:00
|
|
|
use alloc::{
|
2022-01-27 01:47:24 -06:00
|
|
|
format,
|
|
|
|
string::{String, ToString},
|
|
|
|
vec,
|
2022-01-27 01:37:12 -06:00
|
|
|
};
|
|
|
|
use picorand::PicoRandGenerate;
|
|
|
|
use rkyv::{ser::serializers::AllocSerializer, Deserialize};
|
|
|
|
use shadeable::pixel_format::from_vga_16;
|
2022-01-27 01:47:24 -06:00
|
|
|
use vga::colors::Color16;
|
2022-01-27 01:37:12 -06:00
|
|
|
use y_compositor_protocol::Version;
|
|
|
|
|
|
|
|
use crate::{
|
2022-01-27 01:47:24 -06:00
|
|
|
kmain::{BOOT_CONF, TICK},
|
|
|
|
network::socket::{SimpleSock, Socket, SocketReturns},
|
|
|
|
num_to_vga16, vga_e, VgaBuffer, SCREEN_BUFFER,
|
2022-01-27 01:37:12 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
pub fn run_tests() {
|
2022-01-27 01:47:24 -06:00
|
|
|
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_shader_tests {
|
|
|
|
shader_tests();
|
|
|
|
}
|
2022-01-27 01:37:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn socket_test() {
|
2022-01-27 01:47:24 -06:00
|
|
|
let mut xyz = SimpleSock::new();
|
2022-01-27 01:37:12 -06:00
|
|
|
|
2022-01-27 01:47:24 -06:00
|
|
|
xyz.peek();
|
2022-01-27 01:37:12 -06:00
|
|
|
|
2022-01-27 01:47:24 -06:00
|
|
|
xyz.write(vec![0, 1, 2, 3]);
|
2022-01-27 01:37:12 -06:00
|
|
|
|
2022-01-27 01:47:24 -06:00
|
|
|
let x = "simple 🧦".to_string().into_bytes();
|
|
|
|
xyz.write(x);
|
2022-01-27 01:37:12 -06:00
|
|
|
|
2022-01-27 01:47:24 -06:00
|
|
|
info!("{:?}", &xyz.read(4).unwrap());
|
2022-01-27 01:37:12 -06:00
|
|
|
|
2022-01-27 01:47:24 -06:00
|
|
|
match &xyz.peek() {
|
|
|
|
SocketReturns::ReadOk(strr) => {
|
|
|
|
let out = String::from_utf8_lossy(strr);
|
2022-01-27 01:37:12 -06:00
|
|
|
|
2022-01-27 01:47:24 -06:00
|
|
|
info!("{}", out);
|
|
|
|
}
|
|
|
|
SocketReturns::ReadIndexOutOfBounds => todo!(),
|
|
|
|
SocketReturns::WriteOk => todo!(),
|
|
|
|
}
|
2022-01-27 01:37:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn socket_test_rng() {
|
2022-01-27 01:47:24 -06:00
|
|
|
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()
|
|
|
|
);
|
2022-01-27 01:37:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn socket_startup_rng() {
|
2022-01-27 01:47:24 -06:00
|
|
|
use picorand::{WyRand, RNG};
|
|
|
|
let mut random_socket = SimpleSock::new();
|
2022-01-27 01:37:12 -06:00
|
|
|
|
2022-01-27 01:47:24 -06:00
|
|
|
random_socket.register_protocol("RNGProvider".to_string());
|
|
|
|
let bruh = TICK.load(core::sync::atomic::Ordering::Relaxed);
|
2022-01-27 01:37:12 -06:00
|
|
|
|
2022-01-27 01:47:24 -06:00
|
|
|
let mut rng = RNG::<WyRand, u8>::new(bruh);
|
2022-01-27 01:37:12 -06:00
|
|
|
|
2022-01-27 01:47:24 -06:00
|
|
|
for _ in 0..512 {
|
|
|
|
let x = rng.generate();
|
|
|
|
random_socket.write(vec![x]);
|
|
|
|
}
|
2022-01-27 01:37:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn screen_writer_test() {
|
2022-01-27 01:47:24 -06:00
|
|
|
let mut sock_print_id = SimpleSock::new();
|
2022-01-27 01:37:12 -06:00
|
|
|
|
2022-01-27 01:47:24 -06:00
|
|
|
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());
|
2022-01-27 01:37:12 -06:00
|
|
|
|
2022-01-27 01:47:24 -06:00
|
|
|
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());
|
2022-01-27 01:37:12 -06:00
|
|
|
|
2022-01-27 01:47:24 -06:00
|
|
|
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));
|
|
|
|
}
|
2022-01-27 01:37:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn vga_boot_screen() {
|
2022-01-27 01:47:24 -06:00
|
|
|
let mut abcde = SCREEN_BUFFER.lock();
|
2022-01-27 01:37:12 -06:00
|
|
|
|
2022-01-27 01:47:24 -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;
|
2022-01-27 01:37:12 -06:00
|
|
|
|
2022-01-27 01:47:24 -06:00
|
|
|
abcde.set_pixel(x, y, from_vga_16(num_to_vga16(segment as u8)));
|
|
|
|
}
|
|
|
|
}
|
2022-01-27 01:37:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn graphics_pipe_test() {
|
2022-01-27 01:47:24 -06:00
|
|
|
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();
|
|
|
|
|
|
|
|
// 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::<Version>(&the_bytes);
|
|
|
|
let deserialized: Version = archived.deserialize(&mut rkyv::Infallible).unwrap();
|
|
|
|
trace!("{:?}", deserialized);
|
|
|
|
}
|
2022-01-27 01:37:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn graphics_pipe_startup() {
|
2022-01-27 01:47:24 -06:00
|
|
|
let mut graphics_pipe = SimpleSock::new();
|
2022-01-27 01:37:12 -06:00
|
|
|
|
2022-01-27 01:47:24 -06:00
|
|
|
graphics_pipe.register_protocol("YCompositor".to_string());
|
2022-01-27 01:37:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn graphics_api_demo() {
|
2022-01-27 01:47:24 -06:00
|
|
|
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();
|
2022-01-27 01:37:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn shader_tests() {
|
2022-01-27 01:47:24 -06:00
|
|
|
let mut graphics = SCREEN_BUFFER.lock();
|
2022-01-27 01:37:12 -06:00
|
|
|
|
2022-01-27 01:47:24 -06:00
|
|
|
graphics.clear();
|
|
|
|
graphics.force_redraw();
|
|
|
|
graphics.draw_filled_rect(25, 25, 50, 50, 0xff000000);
|
|
|
|
graphics.set_pixel(50, 50, 0xffffff00);
|
|
|
|
graphics.shade();
|
2022-01-27 01:37:12 -06:00
|
|
|
|
2022-01-27 01:47:24 -06:00
|
|
|
graphics.copy_to_buffer();
|
2022-01-27 01:37:12 -06:00
|
|
|
|
2022-01-27 01:47:24 -06:00
|
|
|
// drop(graphics)
|
2022-01-27 01:37:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn ser_de_test() {
|
2022-01-27 01:47:24 -06:00
|
|
|
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 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::<Version>(&the_bytes);
|
|
|
|
let deserialized: Version = archived.deserialize(&mut rkyv::Infallible).unwrap();
|
|
|
|
trace!("{:?}", deserialized);
|
|
|
|
}
|
2022-01-27 01:37:12 -06:00
|
|
|
}
|