diff --git a/src/emulator.rs b/src/emulator.rs index 9c9c21a..6248357 100644 --- a/src/emulator.rs +++ b/src/emulator.rs @@ -405,14 +405,28 @@ where self.memory[memory_index] = self.registers[i as usize]; } } - ProcessorInstruction::GetKeyBlocking(_vx) => { - //todo!("must implement") + ProcessorInstruction::GetKeyBlocking(vx) => { + if let Some(key) = self.last_key_pressed { + self.registers[vx as usize] = key; + } else { + self.program_counter -= 2; + } } - ProcessorInstruction::SkipIfKeyIsPressed(_vx) => { - //todo!("must implement") + ProcessorInstruction::SkipIfKeyIsPressed(vx) => { + if let Some(key) = self.last_key_pressed { + if self.registers[vx as usize] == key { + self.program_counter += 2; + } + } } - ProcessorInstruction::SkipIfKeyIsNotPressed(_vx) => { - //todo!("must implement") + ProcessorInstruction::SkipIfKeyIsNotPressed(vx) => { + if let Some(key) = self.last_key_pressed { + if self.registers[vx as usize] != key { + self.program_counter += 2; + } + } else { + self.program_counter += 2; + } } _ => { warn!("Unknown instruction: {:04x}, skipping.", instruction); diff --git a/src/input.rs b/src/input.rs index 682e74c..ec039e8 100644 --- a/src/input.rs +++ b/src/input.rs @@ -41,7 +41,7 @@ impl InputModule for CrossTermInput { if !self.initialized { panic!("CrossTermInput needs to be constructed using ::new") } - if let Ok(true) = poll(Duration::from_millis(2)) { + if let Ok(true) = poll(Duration::from_millis(1)) { // It's guaranteed that read() won't block if `poll` returns `Ok(true)` let read_result = read(); @@ -50,7 +50,7 @@ impl InputModule for CrossTermInput { Event::Key(key_event) => match key_event.code { KeyCode::Esc => { return Some(0xFF); - }, + } KeyCode::Char(character) => { let lowercase_character = character.to_lowercase(); for char in lowercase_character {