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) {
|
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;
|
vm.registers.r0 = vm.mem.get_mem(0xFE02) & 0xFF;
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,13 @@ impl Memory<'_> {
|
|||||||
pub fn get_mem(&mut self, addr: u16) -> u16 {
|
pub fn get_mem(&mut self, addr: u16) -> u16 {
|
||||||
if addr >= 0xFE00 {
|
if addr >= 0xFE00 {
|
||||||
return match addr {
|
return match addr {
|
||||||
0xFE00 => self.io.check_key() as u16,
|
0xFE00 => {
|
||||||
|
if self.io.check_key() {
|
||||||
|
1 << 15
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
}
|
||||||
0xFE02 => {
|
0xFE02 => {
|
||||||
let key = match self.io.get_key() {
|
let key = match self.io.get_key() {
|
||||||
Some(key) => key as u16,
|
Some(key) => key as u16,
|
||||||
|
@ -29,6 +29,7 @@ pub trait KeyboardIO {
|
|||||||
|
|
||||||
pub struct TerminalIO {
|
pub struct TerminalIO {
|
||||||
stdin_channel: Receiver<u8>,
|
stdin_channel: Receiver<u8>,
|
||||||
|
char: Option<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TerminalIO {
|
impl TerminalIO {
|
||||||
@ -36,6 +37,7 @@ impl TerminalIO {
|
|||||||
setup_termios();
|
setup_termios();
|
||||||
TerminalIO {
|
TerminalIO {
|
||||||
stdin_channel: Self::spawn_stdin_channel(),
|
stdin_channel: Self::spawn_stdin_channel(),
|
||||||
|
char: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,17 +61,14 @@ impl Drop for TerminalIO {
|
|||||||
|
|
||||||
impl KeyboardIO for TerminalIO {
|
impl KeyboardIO for TerminalIO {
|
||||||
fn get_key(&mut self) -> Option<u8> {
|
fn get_key(&mut self) -> Option<u8> {
|
||||||
match self.stdin_channel.try_recv() {
|
self.char
|
||||||
Ok(key) => Some(key),
|
|
||||||
Err(mpsc::TryRecvError::Empty) => None,
|
|
||||||
Err(mpsc::TryRecvError::Disconnected) => panic!("terminal keyboard stream broke"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_key(&mut self) -> bool {
|
fn check_key(&mut self) -> bool {
|
||||||
match self.stdin_channel.try_iter().peekable().peek() {
|
match self.stdin_channel.try_recv() {
|
||||||
Some(data) => true,
|
Ok(key) => { self.char = Some(key); true },
|
||||||
None => false,
|
Err(mpsc::TryRecvError::Empty) => false,
|
||||||
|
Err(mpsc::TryRecvError::Disconnected) => panic!("terminal keyboard stream broke"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user