2020-12-23 09:43:49 +00:00
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
|
|
pub struct Bus {
|
|
|
|
boot: [u8; 256],
|
|
|
|
}
|
2020-12-23 09:25:16 +00:00
|
|
|
|
2020-12-23 09:43:49 +00:00
|
|
|
impl Default for Bus {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
boot: include_bytes!("../bin/DMG_ROM.bin").to_owned(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-29 23:38:27 +00:00
|
|
|
|
|
|
|
impl Bus {
|
2020-09-04 05:41:19 +00:00
|
|
|
pub fn read_byte(&self, addr: u16) -> u8 {
|
2020-12-23 09:25:16 +00:00
|
|
|
match addr {
|
|
|
|
0x0000..=0x00FF => {
|
|
|
|
// Restart and Interrupt Vectors
|
2020-12-23 09:43:49 +00:00
|
|
|
self.boot[addr as usize]
|
2020-12-23 09:25:16 +00:00
|
|
|
}
|
2020-12-23 09:43:49 +00:00
|
|
|
_ => unimplemented!("Can't read byte from {:#06x}", addr),
|
2020-12-23 09:25:16 +00:00
|
|
|
}
|
2020-08-29 23:38:27 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 09:43:49 +00:00
|
|
|
pub fn write_byte(&mut self, addr: u16, byte: u8) {
|
|
|
|
match addr {
|
|
|
|
0x000..=0x0FF => {
|
|
|
|
// Restart and Itterupt Vectors
|
|
|
|
self.boot[addr as usize] = byte;
|
|
|
|
}
|
|
|
|
_ => unimplemented!("Can't write {:#04x} to {:#06x}", byte, addr),
|
|
|
|
}
|
2020-08-29 23:38:27 +00:00
|
|
|
}
|
|
|
|
|
2020-09-04 05:41:19 +00:00
|
|
|
pub fn read_word(&self, addr: u16) -> u16 {
|
2020-12-23 09:25:16 +00:00
|
|
|
match addr {
|
|
|
|
0x0000..=0x00FF => {
|
|
|
|
// Restart and Interrupt Vectors
|
2020-12-23 09:43:49 +00:00
|
|
|
(self.boot[(addr + 1) as usize] as u16) << 8 | self.boot[addr as usize] as u16
|
2020-12-23 09:25:16 +00:00
|
|
|
}
|
2020-12-23 09:43:49 +00:00
|
|
|
_ => unimplemented!("Can't read word from {:#06x}", addr),
|
2020-12-23 09:25:16 +00:00
|
|
|
}
|
2020-08-29 23:38:27 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 09:43:49 +00:00
|
|
|
pub fn write_word(&mut self, addr: u16, word: u16) {
|
|
|
|
unimplemented!("Can't write {:#06x} to {:#06x}", word, addr)
|
2020-08-29 23:38:27 +00:00
|
|
|
}
|
2020-09-04 05:41:19 +00:00
|
|
|
}
|