#![allow(unused_imports)]
#[allow(unused)]
macro_rules! debug {
($($arg:tt)*) => ({
$crate::device::Output::Debug.write(format_args!($($arg)*));
});
}
#[allow(unused)]
macro_rules! print {
($($arg:tt)*) => ({
$crate::device::Output::Print.write(format_args!($($arg)*));
});
}
#[allow(unused)]
macro_rules! println {
($($arg:tt)*) => ({
$crate::device::Output::Println.write(format_args!($($arg)*));
});
}
#[allow(unused)]
macro_rules! serial {
(force: $($arg:tt)*) => ({
$crate::device::Output::Serial {
force: true,
file: core::file!(),
line: core::line!(),
}.write(format_args!($($arg)*))
});
($($arg:tt)*) => ({
$crate::device::Output::Serial {
force: false,
file: core::file!(),
line: core::line!(),
}.write(format_args!($($arg)*));
});
}
use core::fmt::{self, Write};
use core::ptr::addr_of_mut;
mod serial;
pub use serial::Serial;
pub mod cga;
use cga::{Attribute, Color, Rect, Window};
#[cfg(feature = "graphics")]
pub mod vga;
mod keyboard;
pub use keyboard::{KeyBuffer, PS2Controller};
use crate::arch::{cpu, int};
use crate::interrupts::guard::GUARD;
use crate::util::Spin;
pub static mut KEYBOARD: PS2Controller = PS2Controller::new();
pub static mut KOUT: Window = Window::new(Rect::new(0, 10, 40, 15))
.with_hw_cursor()
.with_style(Attribute::with(Color::Black, Color::Brown));
pub static mut DBG: Window =
Window::new(Rect::new(40, 0, 40, 25)).with_style(Attribute::with(Color::Red, Color::Blue));
pub static mut SERIAL: Serial = Serial::new(serial::COM1);
#[allow(unused)]
pub enum Output {
Debug,
Print,
Println,
Serial {
force: bool,
file: &'static str,
line: u32,
},
}
impl Output {
pub fn write(self, args: fmt::Arguments) {
let _ = int::suppress(|| match self {
Self::Debug => writeln!(unsafe { &mut *addr_of_mut!(DBG) }, "{args}"),
Self::Print => write!(unsafe { &mut *addr_of_mut!(KOUT) }, "{args}"),
Self::Println => writeln!(unsafe { &mut *addr_of_mut!(KOUT) }, "{args}"),
Self::Serial {
force: _,
file,
line,
} => {
let c = cpu::id();
let t = 0; unsafe { writeln!(SERIAL, "\x1b[0;90m[{c}:{t} {file}:{line}]\x1b[0m {args}") }
}
});
}
}