use core::computers::ram_rom::RamRomComputer;
use core::traits::backplane::Backplane;
use std::fs;

fn main() {
    println!("Taxation is Theft");

    // let opts = CliOptions::parse();
    let path = "/home/tmerritt/Projects/mos6502/resources/test/periph/at28c256/checksum.bin";
    let bytes = match  fs::read(path) {
        Ok(bytes) => {
            println!("Read {} bytes.", bytes.len());
            bytes
        },
        Err(e) => {
            eprintln!("FAIL to read rom.");
            panic!("No rom no run.");
            vec![]
        }
    };


    let mut computer = RamRomComputer::new();

    // Read byte from ROM   0x4000
    println!("-- ");
    computer.set_read_mode(true);
    computer.set_address_bus(0x4020);
    computer.tick();
    println!("-- ");
    // Data Bus contains value from ROM

    let read_from_rom = computer.data_bus();
    // Write byte to RAM    0x0000
    computer.set_read_mode(false);
    computer.set_address_bus(0x0001);
    computer.tick();
    println!("-- ");
    // Read byte from RAM
    computer.set_read_mode(true);
    computer.set_address_bus(0x0001);
    computer.tick();
    println!("-- ");
    let read_from_ram = computer.data_bus();

    assert_eq!(read_from_rom, read_from_ram);
    println!("Test passed.  We read the same from ROM as we did from RAM - {} == {}", read_from_rom, read_from_ram);
}
