use log::debug;
use crate::periph::at28c256::At28C256;
use crate::traits::bus_device::BusDevice;
use crate::traits::memory_chip::MemoryChip;

impl MemoryChip for At28C256 {
    /// read
    ///
    /// Reads a byte from memory.
    /// Returns a 0x00 if there is no data at that location but is still in ROM address range
    fn read(&self, offset: &u16) -> u8 {
        let effective = self.internal_address(*offset);
        debug!("STARTING READ FROM At28C256 ${:04x} | ${:04x} / ${effective:04x} | ${:04x}", self.offset, offset, self.max_offset);
        if effective >= self.data.len() as u16 { 0x00 } else { self.data[effective as usize] }
    }
}