cpu.rs: Separate lastkey from flags
This commit is contained in:
parent
05fee3fb75
commit
7d5718f384
@ -55,6 +55,8 @@ pub struct CPU {
|
|||||||
sound: f64,
|
sound: f64,
|
||||||
// I/O
|
// I/O
|
||||||
keys: [bool; 16],
|
keys: [bool; 16],
|
||||||
|
/// Set to the last key that's been *released* after a keypause
|
||||||
|
pub lastkey: Option<usize>,
|
||||||
// Execution data
|
// Execution data
|
||||||
cycle: usize,
|
cycle: usize,
|
||||||
breakpoints: Vec<Adr>,
|
breakpoints: Vec<Adr>,
|
||||||
@ -163,7 +165,7 @@ impl CPU {
|
|||||||
if *keyref {
|
if *keyref {
|
||||||
*keyref = false;
|
*keyref = false;
|
||||||
if self.flags.keypause {
|
if self.flags.keypause {
|
||||||
self.flags.lastkey = Some(key);
|
self.lastkey = Some(key);
|
||||||
self.flags.keypause = false;
|
self.flags.keypause = false;
|
||||||
}
|
}
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
@ -306,7 +308,6 @@ impl CPU {
|
|||||||
keypause: false,
|
keypause: false,
|
||||||
draw_wait: false,
|
draw_wait: false,
|
||||||
draw_mode: false,
|
draw_mode: false,
|
||||||
lastkey: None,
|
|
||||||
..self.flags
|
..self.flags
|
||||||
};
|
};
|
||||||
// clear the stack
|
// clear the stack
|
||||||
@ -320,6 +321,7 @@ impl CPU {
|
|||||||
self.sound = 0.0;
|
self.sound = 0.0;
|
||||||
// I/O
|
// I/O
|
||||||
self.keys = [false; 16];
|
self.keys = [false; 16];
|
||||||
|
self.lastkey = None;
|
||||||
// Execution data
|
// Execution data
|
||||||
self.cycle = 0;
|
self.cycle = 0;
|
||||||
}
|
}
|
||||||
@ -610,6 +612,7 @@ impl Default for CPU {
|
|||||||
sound: 0.0,
|
sound: 0.0,
|
||||||
cycle: 0,
|
cycle: 0,
|
||||||
keys: [false; 16],
|
keys: [false; 16],
|
||||||
|
lastkey: None,
|
||||||
flags: Flags {
|
flags: Flags {
|
||||||
debug: true,
|
debug: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -528,9 +528,9 @@ impl CPU {
|
|||||||
/// |`Fx0A`| Wait for key, then vX = K
|
/// |`Fx0A`| Wait for key, then vX = K
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub(super) fn wait_for_key(&mut self, x: Reg) {
|
pub(super) fn wait_for_key(&mut self, x: Reg) {
|
||||||
if let Some(key) = self.flags.lastkey {
|
if let Some(key) = self.lastkey {
|
||||||
self.v[x] = key as u8;
|
self.v[x] = key as u8;
|
||||||
self.flags.lastkey = None;
|
self.lastkey = None;
|
||||||
} else {
|
} else {
|
||||||
self.pc = self.pc.wrapping_sub(2);
|
self.pc = self.pc.wrapping_sub(2);
|
||||||
self.flags.keypause = true;
|
self.flags.keypause = true;
|
||||||
|
@ -19,8 +19,6 @@ pub struct Flags {
|
|||||||
pub draw_wait: bool,
|
pub draw_wait: bool,
|
||||||
/// Set when the emulator is in high-res mode
|
/// Set when the emulator is in high-res mode
|
||||||
pub draw_mode: bool,
|
pub draw_mode: bool,
|
||||||
/// Set to the last key that's been *released* after a keypause
|
|
||||||
pub lastkey: Option<usize>,
|
|
||||||
/// Represents the current emulator [Mode]
|
/// Represents the current emulator [Mode]
|
||||||
pub mode: Mode,
|
pub mode: Mode,
|
||||||
/// Represents the set of emulator [Quirks] to enable, independent of the [Mode]
|
/// Represents the set of emulator [Quirks] to enable, independent of the [Mode]
|
||||||
|
@ -861,7 +861,7 @@ mod io {
|
|||||||
assert!(cpu.release(key).expect("Key should be released"));
|
assert!(cpu.release(key).expect("Key should be released"));
|
||||||
assert!(!cpu.release(key).expect("Key shouldn't be released again"));
|
assert!(!cpu.release(key).expect("Key shouldn't be released again"));
|
||||||
assert!(!cpu.flags.keypause);
|
assert!(!cpu.flags.keypause);
|
||||||
assert_eq!(Some(key), cpu.flags.lastkey);
|
assert_eq!(Some(key), cpu.lastkey);
|
||||||
cpu.wait_for_key(x);
|
cpu.wait_for_key(x);
|
||||||
assert_eq!(key as u8, cpu.v[x]);
|
assert_eq!(key as u8, cpu.v[x]);
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,6 @@ mod cpu {
|
|||||||
pause: false,
|
pause: false,
|
||||||
keypause: false,
|
keypause: false,
|
||||||
draw_wait: false,
|
draw_wait: false,
|
||||||
lastkey: None,
|
|
||||||
monotonic: None,
|
monotonic: None,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user