idk
This commit is contained in:
FantasyPvP
2023-10-02 23:26:54 +01:00
parent bf9c9be88d
commit 410278b6e3
9 changed files with 165 additions and 6 deletions
+32
View File
@@ -70,6 +70,29 @@ impl KeyboardHandler {
}
}
pub fn try_keystroke(&mut self) -> Option<char> {
if let Some(scancode) = self.scancodes.try_next() {
if let Ok(Some(key_event)) = self.keyboard.add_byte(scancode) {
if let Some(key) = self.keyboard.process_keyevent(key_event) {
match key {
DecodedKey::Unicode(character) => {
if character == b'\x08' as char { // checks if the character is a backspace
interrupts::without_interrupts(|| {
RENDERER.lock().backspace(); // runs the backspace function of the vga buffer to remove the last character
});
return None;
} else {
return Some(character);
}
},
DecodedKey::RawKey(key) => { print!("{:?}", key) },
}
}
}
};
None
}
pub async fn get_string(&mut self) -> String {
let mut val = String::new();
@@ -116,6 +139,15 @@ impl ScanCodeStream {
.expect("ScanCodeStream::new has already been called once");
ScanCodeStream { _private: () }
}
pub fn try_next(&mut self) -> Option<u8> {
let queue = SCANCODE_QUEUE.try_get().expect("not initialised");
if let Ok(c) = queue.pop() {
return Some(c);
} else {
return None;
}
}
}
impl Stream for ScanCodeStream {
+5
View File
@@ -22,6 +22,11 @@ impl Stdin {
let chr = KEYBOARD.lock().get_keystroke().await;
chr
}
pub fn try_keystroke() -> Option<char> {
let chr = KEYBOARD.lock().try_keystroke();
chr
}
}
pub struct Screen {}
+1
View File
@@ -4,6 +4,7 @@ pub mod application;
pub mod tasks;
pub mod os;
pub mod frame;
pub mod time;
// this is where the standard library for the operating system will be defined
+28
View File
@@ -0,0 +1,28 @@
use core::time::Duration;
use embedded_time::{Clock, Timer};
use cmos_rtc::{ReadRTC, Time};
use crate::println;
use super::super::kernel::interrupts::GLOBALTIMER;
use x86_64::instructions::interrupts;
pub fn wait(seconds: i64) {
let mut start = 0;
interrupts::without_interrupts(||{
start = GLOBALTIMER.lock().val;
});
loop {
let mut new = 0;
interrupts::without_interrupts(||{
new = GLOBALTIMER.lock().val;
});
if new + seconds > start {
return
}
};
}
pub fn timer() {
interrupts::without_interrupts(||{
println!("{}", GLOBALTIMER.lock().val);
});
}