use core::periph::mos6522::Mos6522;
use core::constants::constants_via6522::*;

#[test]
fn registers() {
    let mut x = Mos6522::new(0x0000);
    x.tick(VIA6522_DDRA as u16, 0b0000_0000, false, true);
    assert_eq!(x.dda, 0b0000_0000);
    x.tick(VIA6522_DDRA as u16, 0b1111_1111, false, true);
    assert_eq!(x.dda, 0b1111_1111);

    x.tick(VIA6522_DDRB as u16, 0b0000_0000, false, true);
    assert_eq!(x.ddb, 0b0000_0000);
    x.tick(VIA6522_DDRB as u16, 0b1111_1111, false, true);
    assert_eq!(x.ddb, 0b1111_1111);

    x.tick(VIA6522_ORA as u16, 0b0000_0000, false, true);
    assert_eq!(x.ora, 0b0000_0000);
    x.tick(VIA6522_ORA as u16, 0b1111_1111,  false, true);
    assert_eq!(x.ora, 0b1111_1111);

    x.tick(VIA6522_ORB as u16, 0b0000_0000, false, true);
    assert_eq!(x.orb, 0b0000_0000);
    x.tick(VIA6522_ORB as u16, 0b1111_1111, false, true);
    assert_eq!(x.orb, 0b1111_1111);
}

#[test]
fn partial_output_porta() {
    let mut x = Mos6522::new(0x0000);
    x.tick(VIA6522_DDRA as u16, 0b1010_1010, false, true);
    x.tick(VIA6522_ORA as u16,0b1111_1111, false, true);
    assert_eq!(x.porta, 0b1010_1010);
}

#[test]
fn partial_output_portb() {
    let mut x = Mos6522::new(0x0000);
    x.tick(VIA6522_DDRB as u16, 0b0101_0101, false, true);
    x.tick(VIA6522_ORB as u16, 0b1111_1111, false, true);
    assert_eq!(x.portb, 0b0101_0101);
}