implement input handling instructions
This commit is contained in:
parent
3beddd9acd
commit
0112138b78
2 changed files with 22 additions and 8 deletions
|
@ -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::SkipIfKeyIsNotPressed(_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) => {
|
||||
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);
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue