From 7e704ff982dd3c408e1dc1fedb37396f7b9e94e3 Mon Sep 17 00:00:00 2001 From: Atreya Bain Date: Mon, 19 Feb 2024 22:38:29 +0530 Subject: [PATCH] [kbd] Add keyboard.rs --- src/emu/keyboard.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/emu/keyboard.rs diff --git a/src/emu/keyboard.rs b/src/emu/keyboard.rs new file mode 100644 index 0000000..da9a44a --- /dev/null +++ b/src/emu/keyboard.rs @@ -0,0 +1,44 @@ +use crate::emu::memory::{Memory, RamMemory}; +use crate::misc::result::EmulatorResult; + + +pub struct Keyboard<'a>{ + dirty: bool, + bitflags: u16, + ram: &'a RamMemory +} + +impl<'a> Keyboard<'a>{ + pub fn new(ram:&'a RamMemory)->Keyboard<'a>{ + Keyboard { + dirty: true, + bitflags:0, + ram + } + } + + pub fn clear_keyboard(&mut self){ + log::debug!("Keyboard clear"); + self.bitflags = 0; + self.dirty = true; + } + + pub fn key_down(&mut self,x:u8){ + self.bitflags |= 1<EmulatorResult<()>{ + if self.dirty { + log::debug!("Flushing keyboard {}",self.bitflags); + self.ram.try_set_u16(0, self.bitflags)?; + self.dirty = false; + } + Ok(()) + } +} \ No newline at end of file