2021-04-09 01:32:32 +00:00
|
|
|
const HIGH_RAM_SIZE: usize = 0x7F;
|
2021-03-21 01:22:31 +00:00
|
|
|
const HIGH_RAM_START_ADDRESS: usize = 0xFF80;
|
|
|
|
|
2021-01-18 03:13:59 +00:00
|
|
|
#[derive(Debug, Clone)]
|
2021-06-07 00:14:28 +00:00
|
|
|
pub(crate) struct HighRam {
|
2021-03-21 01:22:31 +00:00
|
|
|
buf: Box<[u8; HIGH_RAM_SIZE]>,
|
2021-01-18 03:13:59 +00:00
|
|
|
}
|
|
|
|
|
2021-03-16 06:05:13 +00:00
|
|
|
impl Default for HighRam {
|
2021-01-18 03:13:59 +00:00
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
2021-03-21 01:22:31 +00:00
|
|
|
buf: Box::new([0u8; HIGH_RAM_SIZE]),
|
2021-01-18 03:13:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-16 06:05:13 +00:00
|
|
|
impl HighRam {
|
2021-06-07 00:14:28 +00:00
|
|
|
pub(crate) fn write_byte(&mut self, addr: u16, byte: u8) {
|
2021-03-21 01:22:31 +00:00
|
|
|
self.buf[addr as usize - HIGH_RAM_START_ADDRESS] = byte;
|
2021-01-18 03:13:59 +00:00
|
|
|
}
|
|
|
|
|
2021-06-07 00:14:28 +00:00
|
|
|
pub(crate) fn read_byte(&self, addr: u16) -> u8 {
|
2021-03-21 01:22:31 +00:00
|
|
|
self.buf[addr as usize - HIGH_RAM_START_ADDRESS]
|
2021-01-18 03:13:59 +00:00
|
|
|
}
|
|
|
|
}
|