fix KBSR/KBDR mem-map registers
dummy me did not realize the ready bit was bit 15
This commit is contained in:
parent
6cda9912f5
commit
666152229a
@ -312,6 +312,6 @@ fn trap_puts(vm: &mut VM) {
|
||||
}
|
||||
|
||||
fn trap_getc(vm: &mut VM) {
|
||||
while vm.mem.get_mem(0xFE00) & 1 == 0 {}
|
||||
while vm.mem.get_mem(0xFE00) & (1 << 15) == 0 {}
|
||||
vm.registers.r0 = vm.mem.get_mem(0xFE02) & 0xFF;
|
||||
}
|
||||
|
@ -30,7 +30,13 @@ impl Memory<'_> {
|
||||
pub fn get_mem(&mut self, addr: u16) -> u16 {
|
||||
if addr >= 0xFE00 {
|
||||
return match addr {
|
||||
0xFE00 => self.io.check_key() as u16,
|
||||
0xFE00 => {
|
||||
if self.io.check_key() {
|
||||
1 << 15
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
0xFE02 => {
|
||||
let key = match self.io.get_key() {
|
||||
Some(key) => key as u16,
|
||||
|
@ -29,6 +29,7 @@ pub trait KeyboardIO {
|
||||
|
||||
pub struct TerminalIO {
|
||||
stdin_channel: Receiver<u8>,
|
||||
char: Option<u8>,
|
||||
}
|
||||
|
||||
impl TerminalIO {
|
||||
@ -36,6 +37,7 @@ impl TerminalIO {
|
||||
setup_termios();
|
||||
TerminalIO {
|
||||
stdin_channel: Self::spawn_stdin_channel(),
|
||||
char: None,
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,17 +61,14 @@ impl Drop for TerminalIO {
|
||||
|
||||
impl KeyboardIO for TerminalIO {
|
||||
fn get_key(&mut self) -> Option<u8> {
|
||||
match self.stdin_channel.try_recv() {
|
||||
Ok(key) => Some(key),
|
||||
Err(mpsc::TryRecvError::Empty) => None,
|
||||
Err(mpsc::TryRecvError::Disconnected) => panic!("terminal keyboard stream broke"),
|
||||
}
|
||||
self.char
|
||||
}
|
||||
|
||||
fn check_key(&mut self) -> bool {
|
||||
match self.stdin_channel.try_iter().peekable().peek() {
|
||||
Some(data) => true,
|
||||
None => false,
|
||||
match self.stdin_channel.try_recv() {
|
||||
Ok(key) => { self.char = Some(key); true },
|
||||
Err(mpsc::TryRecvError::Empty) => false,
|
||||
Err(mpsc::TryRecvError::Disconnected) => panic!("terminal keyboard stream broke"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user