use crate::constants::constants_system::SIZE_32KB;
use crate::periph::hm62256::Hm62256;
use crate::traits::bus_device::BusDevice;
use crate::traits::ram_chip::RamChip;

impl BusDevice for Hm62256 {
    fn min_offset(&self) -> u16 {
        self.offset
    }

    fn max_offset(&self) -> u16 {
        self.max_offset
    }

    fn address_bus(&self) -> u16 {
      self.address_bus
    }

    fn data_bus(&self) -> u8 {
        self.data_bus
    }

    fn set_address_bus(&mut self, new_value: u16) {
        self.address_bus = new_value
    }

    fn set_data_bus(&mut self, new_value: u8) {
        self.data_bus = new_value
    }

}

impl RamChip for Hm62256 {
    fn write(&mut self, offset: &u16, value: &u8) {
        let effective = *offset as i32 % SIZE_32KB as i32;
        println!("Writing at E[{effective:04x}] / O[{offset:04x}]");
        self.data[effective as usize] = *value;
    }
}

