
pub trait BusDevice {
    fn min_offset(&self) -> u16;
    fn max_offset(&self) -> u16;
    fn address_bus(&self) -> u16;
    fn data_bus(&self) -> u8;

    fn set_address_bus(&mut self, new_value: u16);
    fn set_data_bus(&mut self, new_value: u8);
    fn talking_to_me(&self, address: u16) -> bool {
        address >= self.min_offset() && address < self.max_offset()
    }

    /// internal_address
    ///
    /// Converts from a system-wide address to a device specific address
    ///
    /// ex: 0x3000 to a ROM chip with min_offset = 0x2000
    ///     -> internal_address = 0x1000  <-- read this offset from data array
    ///     -> external_address = 0x3000
    fn internal_address(&self, address: u16) -> u16 {
        // println!("MINOFFSET ${:04x}", self.min_offset());
        let mo = self.max_offset();
        let result= if address > mo {
            address - self.max_offset()
        } else {
            address
        };
        // println!("RESULT = {:04x}", result - self.min_offset());

        result - self.min_offset()
    }
}
