chore: improve code quality

Removed a lot of magic constants. Gave them descriptive variable names
This commit is contained in:
2021-03-20 20:22:31 -05:00
parent 0f4dec8a38
commit cd0eac9d37
8 changed files with 74 additions and 58 deletions

View File

@@ -1,22 +1,25 @@
const HIGH_RAM_SIZE: usize = 127;
const HIGH_RAM_START_ADDRESS: usize = 0xFF80;
#[derive(Debug, Clone)]
pub struct HighRam {
buf: Box<[u8; 127]>,
buf: Box<[u8; HIGH_RAM_SIZE]>,
}
impl Default for HighRam {
fn default() -> Self {
Self {
buf: Box::new([0u8; 127]),
buf: Box::new([0u8; HIGH_RAM_SIZE]),
}
}
}
impl HighRam {
pub fn write_byte(&mut self, addr: u16, byte: u8) {
self.buf[addr as usize - 0xFF80] = byte;
self.buf[addr as usize - HIGH_RAM_START_ADDRESS] = byte;
}
pub fn read_byte(&self, addr: u16) -> u8 {
self.buf[addr as usize - 0xFF80]
self.buf[addr as usize - HIGH_RAM_START_ADDRESS]
}
}