diff --git a/src/system/kernel/render.rs b/src/system/kernel/render.rs index 51eeb6f..49cc7b8 100644 --- a/src/system/kernel/render.rs +++ b/src/system/kernel/render.rs @@ -184,7 +184,7 @@ impl Renderer { self.internal_render(); } - pub fn with_colour(&mut self, cols: ColorCode) { + pub fn set_colour(&mut self, cols: ColorCode) { self.temp_colour = Some(cols); } pub fn reset_colour(&mut self) { @@ -334,7 +334,7 @@ pub fn write(args: fmt::Arguments, cols: (Color, Color)) { interrupts::without_interrupts(|| { let mut writer = RENDERER.lock(); - writer.with_colour(colour_code); + writer.set_colour(colour_code); writer.write_fmt(args).unwrap(); writer.reset_colour(); }) diff --git a/src/system/kernel/tasks/keyboard.rs b/src/system/kernel/tasks/keyboard.rs index 69ae9c2..6e93945 100644 --- a/src/system/kernel/tasks/keyboard.rs +++ b/src/system/kernel/tasks/keyboard.rs @@ -143,9 +143,9 @@ impl ScanCodeStream { pub fn try_next(&mut self) -> Option { let queue = SCANCODE_QUEUE.try_get().expect("not initialised"); if let Ok(c) = queue.pop() { - return Some(c); + Some(c) } else { - return None; + None } } } diff --git a/src/system/std/io.rs b/src/system/std/io.rs index 4f5a335..774b76f 100644 --- a/src/system/std/io.rs +++ b/src/system/std/io.rs @@ -4,6 +4,7 @@ use crate::{ }; use alloc::string::String; +use alloc::vec::Vec; pub use crate::{print, println, serial_print, serial_println}; pub use crate::kernel::render::Color; diff --git a/src/system/std/time.rs b/src/system/std/time.rs index 4d7274d..86a9aad 100644 --- a/src/system/std/time.rs +++ b/src/system/std/time.rs @@ -4,7 +4,7 @@ use cmos_rtc::{ReadRTC, Time}; use crate::println; use super::super::kernel::interrupts::GLOBALTIMER; use x86_64::instructions::interrupts; -pub fn wait(seconds: i64) { +pub fn wait(seconds: f64) { let mut start = 0; interrupts::without_interrupts(||{ start = GLOBALTIMER.lock().val; @@ -15,7 +15,7 @@ pub fn wait(seconds: i64) { interrupts::without_interrupts(||{ new = GLOBALTIMER.lock().val; }); - if new + seconds > start { + if new as f64 > start as f64 + seconds * 16.0 { return } }; diff --git a/src/user/bin/shell.rs b/src/user/bin/shell.rs index bfd303e..21e2bfd 100644 --- a/src/user/bin/shell.rs +++ b/src/user/bin/shell.rs @@ -6,12 +6,8 @@ use x86_64::instructions::interrupts; use alloc::{boxed::Box, string::{String, ToString}, vec, vec::Vec}; use vga::writers::{GraphicsWriter, PrimitiveDrawing}; -use crate::{ - print, println, - std::application::{Application, Error}, - user::bin::*, -}; -use crate::std::io::{Color, write, Screen}; +use crate::{print, println, std, std::application::{Application, Error}, user::bin::*}; +use crate::std::io::{Color, write, Screen, Stdin}; use crate::std::random::Random; use crate::user::bin::gigachad_detector::GigachadDetector; use crate::user::bin::grapher::Grapher; @@ -123,6 +119,19 @@ async fn exec() -> Result<(), Error> { gigachad_detector.run(args).await?; } + "wait" => { + use std::time::wait; + + for _ in 0..20 { + wait(0.5); + let key = Stdin::try_keystroke(); + println!("waited {}", match key { + Some(c) => c, + None => '_', + }); + } + } + // direct OS functions (not applications) "echo" => { println!( diff --git a/src/user/bin/snake.rs b/src/user/bin/snake.rs index b23683f..6bc5451 100644 --- a/src/user/bin/snake.rs +++ b/src/user/bin/snake.rs @@ -50,13 +50,13 @@ impl Application for Game { 'gameloop: loop { - time::wait(20); + time::wait(0.2); - // if let Some(c) = Stdin::try_keystroke() { - // self.mv = c; - // } + if let Some(c) = Stdin::try_keystroke() { + self.mv = c; + } - self.mv = Stdin::keystroke().await; + //self.mv = Stdin::keystroke().await; match self.mv { 'w' => self.head.y -= 1,