| 77 | impl MemoryAccess for Keyboard { |
| 78 | fn read_byte(&mut self, addr: u64) -> Result<u8, VmError> { |
| 79 | let a = addr as usize; |
| 80 | if a >= KBD_TOTAL_BYTES { |
| 81 | return Err(VmError::BusError(addr)); |
| 82 | } |
| 83 | // A byte read returns the matching byte of the register word. Reading the |
| 84 | // DATA byte still pops, so guests should use a word read. |
| 85 | let reg = a & !0x3; |
| 86 | let shift = (a & 0x3) * 8; |
| 87 | Ok((self.read_reg(reg) >> shift) as u8) |
| 88 | } |
| 89 | |
| 90 | fn read_word(&mut self, addr: u64) -> Result<u32, VmError> { |
| 91 | let a = addr as usize; |
| 92 | if a + 4 > KBD_TOTAL_BYTES { |