- added a basic pong game

- added a better timer system for event updates
This commit is contained in:
FantasyPvP
2024-03-22 23:52:45 +00:00
parent d5d9e031d5
commit c4067fabc8
7 changed files with 136 additions and 40 deletions
+4 -1
View File
@@ -137,7 +137,10 @@ impl Frame {
}
pub fn write(&mut self, position: Position, char: ColouredChar) -> Result<(), RenderError> {
if position.x >= self.dimensions.x || position.y >= self.dimensions.y {
return Err(RenderError::OutOfBounds(true, true));
return Err(RenderError::OutOfBounds(
position.x >= self.dimensions.x,
position.y >= self.dimensions.y,
));
}
self.frame[position.y][position.x] = char;
Ok(())
+6 -6
View File
@@ -52,12 +52,12 @@ pub enum Screen {
/// DEPRECATED - STOP USING THIS SOON
impl Screen {
/// mode can be set for the kernel using this method
pub fn set_mode(&self) -> Result<(), RenderError> {
Ok(match self {
Screen::Terminal => RENDERER.lock().terminal_mode(),
Screen::Application => RENDERER.lock().application_mode(),
})
}
// pub fn set_mode(&self) -> Result<(), RenderError> {
// Ok(match self {
// Screen::Terminal => RENDERER.lock().terminal_mode(),
// Screen::Application => RENDERER.lock().application_mode(),
// })
// }
/// returns the current display mode
pub fn get_mode() -> Screen {
+38
View File
@@ -1,6 +1,9 @@
use cmos_rtc::Time;
use crate::println;
use super::super::kernel::interrupts::GLOBALTIMER;
use x86_64::instructions::interrupts;
use crate::system::kernel::interrupts::InterruptIndex;
pub fn wait(seconds: f64) {
let mut start = 0;
interrupts::without_interrupts(||{
@@ -22,4 +25,39 @@ pub fn timer() {
interrupts::without_interrupts(||{
println!("{}", GLOBALTIMER.lock().val);
});
}
pub struct Timer {
duration: f64,
end: f64
}
impl Timer {
pub(crate) fn new(seconds: f64) -> Self {
let mut start = 0;
interrupts::without_interrupts(||{
start = GLOBALTIMER.lock().val;
});
Timer {
duration: seconds,
end: start as f64 + seconds * 16.0
}
}
pub(crate) fn is_done(&self) -> bool {
let mut done = false;
interrupts::without_interrupts(||{
done = GLOBALTIMER.lock().val as f64 > self.end;
});
done
}
pub(crate) fn reset(&mut self) {
let mut start = 0;
interrupts::without_interrupts(||{
start = GLOBALTIMER.lock().val;
});
self.end = start as f64 + self.duration * 16.0
}
}