aboutsummaryrefslogtreecommitdiff
path: root/src/io/mod.rs
diff options
context:
space:
mode:
authorTianhao Wang <shrik3@mailbox.org>2024-04-18 22:00:12 +0200
committerTianhao Wang <shrik3@mailbox.org>2024-06-11 15:16:35 +0200
commit2578105f6e365b43ee6dbb4770555ccf3089c2b9 (patch)
tree2c0cc8acbf457485f22ce86d787b92f0e581616d /src/io/mod.rs
parent708189ee9d856f01ef364e23c1b0cf81dd8d5dc4 (diff)
move io.rs into submodule
Diffstat (limited to 'src/io/mod.rs')
-rw-r--r--src/io/mod.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/io/mod.rs b/src/io/mod.rs
new file mode 100644
index 0000000..27be847
--- /dev/null
+++ b/src/io/mod.rs
@@ -0,0 +1,44 @@
+use crate::machine::cgascr::CGAScreen;
+use crate::machine::keyctrl::KeyboardController;
+use core::fmt;
+use lazy_static::lazy_static;
+use spin::Mutex;
+// TODO I want my own locking primitive for practice, instead of stock spin lock
+lazy_static! {
+ pub static ref CGASCREEN_GLOBAL: Mutex<CGAScreen> = Mutex::new(CGAScreen::new());
+ pub static ref KBCTL_GLOBAL: Mutex<KeyboardController> = Mutex::new(KeyboardController::new());
+}
+
+#[macro_export]
+macro_rules! print {
+ ($($arg:tt)*) => ($crate::io::_print(format_args!($($arg)*)));
+}
+pub(crate) use print;
+
+#[macro_export]
+macro_rules! println {
+ () => ($crate::print!("\n"));
+ ($($arg:tt)*) => (print!("{}\n", format_args!($($arg)*)));
+}
+pub(crate) use println;
+
+pub fn _print(args: fmt::Arguments) {
+ use core::fmt::Write;
+ CGASCREEN_GLOBAL.lock().write_fmt(args).unwrap();
+}
+
+pub fn clear_screen() {
+ CGASCREEN_GLOBAL.lock().clear();
+}
+
+pub fn set_attr(attr: u8) {
+ CGASCREEN_GLOBAL.lock().setattr(attr);
+}
+
+pub fn print_welcome() {
+ println!("--RuStuBs--");
+ println!(" _._ _,-'\"\"`-._ ~Meow");
+ println!(" (,-.`._,'( |\\`-/|");
+ println!(" `-.-' \\ )-`( , o o)");
+ println!(" `- \\`_`\"'-");
+}