use crate::computers::beneater::BenEater;
use crate::traits::backplane::Backplane;

impl Backplane for BenEater {
    fn data_bus(&self) -> u8 {
        self.data_bus
    }

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

    fn read_mode(&self) -> bool {
        self.read_mode
    }

    fn set_read_mode(&mut self, new_mode: bool) {
        self.read_mode = new_mode
    }

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

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

    fn tick(&mut self) {
        println!("Tick the system.");

        self.tick_ram(self.address_bus, self.data_bus, true, true, true);
        self.tick_rom(self.address_bus, true, true);
        self.tick_via(self.address_bus, self.data_bus, true, true, self.read_mode, true, true);
    }

    fn tick_ram(&mut self, address: u16, data: u8, cs: bool, oe: bool, we: bool) -> u8 {
        println!("Ticking RAM");
        0x00
    }

    fn tick_rom(&mut self, address: u16, cs: bool, oe: bool) -> u8 {
        println!("Ticking ROM");
        0x00
    }

    fn tick_via(&mut self, address: u16, data: u8, cs0: bool, cs1: bool, rw: bool, rs0: bool, rs1: bool) -> (u8, bool, bool) {
        println!("Ticking VIA 6522");
        let (new_address, new_data) = self.via.tick(self.address_bus, self.data_bus, false, self.read_mode);
        (new_data, false, false)
    }
}