use core::fmt::Write;
use crate::device::cga::{Attribute, Rect, Window};
use crate::interrupts::guard::GUARD;
use crate::threading::APPS;
use crate::MAX_CPUS;
pub extern "C" fn init_action() -> ! {
{
let _g = GUARD.enter();
println!("Hello from the Init App!");
}
{
let g = GUARD.enter();
let active = g.scheduler.active().unwrap();
let t = g.scheduler.thread(active).unwrap();
println!("self: {t:?}");
}
{
let mut g = GUARD.enter();
g.scheduler.exit();
}
}
pub extern "C" fn app_action() -> ! {
let tid = {
let g = GUARD.enter();
g.scheduler.active().unwrap()
};
let row = (tid - MAX_CPUS) as u8;
let style = Attribute::with(((row + 3) & 0b1111).into(), (row & 0b111).into());
let mut screen = Window::new(Rect::new(0, row, 40, 1)).with_style(style);
{
let _g = GUARD.enter();
screen.clear();
}
let mut i = 0_u16;
loop {
{
let _g = GUARD.enter();
screen.set_cursor((0, row));
write!(screen, "i: {i}").unwrap();
}
i = i.wrapping_add(1);
if row >= 1 {
let g = &mut *GUARD.enter();
g.bell_ringer.sleep(&mut g.scheduler, 50 << row);
}
let border = APPS.div_ceil(2);
if i == 100 && row as usize >= border {
let mut g = GUARD.enter();
g.scheduler.kill(MAX_CPUS + row as usize - border);
}
}
}
pub extern "C" fn keyboard_action() -> ! {
loop {
{
let g = &mut *GUARD.enter();
print!("{}", g.keyboard.pop(&mut g.scheduler));
}
}
}