diff --git a/OSBindings/Mac/Clock SignalTests/6522Tests.swift b/OSBindings/Mac/Clock SignalTests/6522Tests.swift index 66617a990..41100aacc 100644 --- a/OSBindings/Mac/Clock SignalTests/6522Tests.swift +++ b/OSBindings/Mac/Clock SignalTests/6522Tests.swift @@ -16,6 +16,8 @@ class MOS6522Tests: XCTestCase { action(bridge) } + // MARK: Timer tests + func testTimerCount() { with6522 { // set timer 1 to a value of $000a @@ -90,4 +92,22 @@ class MOS6522Tests: XCTestCase { XCTAssert($0.valueForRegister(5) == 0x00, "High order byte should be 0x00; was \($0.valueForRegister(5))") } } + + + // MARK: Data direction tests + func testDataDirection() { + with6522 { + // set low four bits of register B as output, the top four as input + $0.setValue(0x0f, forRegister: 2) + + // ask to output 0x8c + $0.setValue(0x8c, forRegister: 0) + + // set current input as 0xda + $0.portBInput = 0xda + + // test that the result of reading register B is therefore 0x8a + XCTAssert($0.valueForRegister(0) == 0x8a, "Data direction register should mix input and output; got \($0.valueForRegister(0))") + } + } } diff --git a/OSBindings/Mac/Clock SignalTests/MOS6522Bridge.h b/OSBindings/Mac/Clock SignalTests/MOS6522Bridge.h index d2bed3fe8..b5110ae86 100644 --- a/OSBindings/Mac/Clock SignalTests/MOS6522Bridge.h +++ b/OSBindings/Mac/Clock SignalTests/MOS6522Bridge.h @@ -11,6 +11,8 @@ @interface MOS6522Bridge : NSObject @property (nonatomic, readonly) BOOL irqLine; +@property (nonatomic) uint8_t portBInput; +@property (nonatomic) uint8_t portAInput; - (void)setValue:(uint8_t)value forRegister:(NSUInteger)registerNumber; - (uint8_t)valueForRegister:(NSUInteger)registerNumber; diff --git a/OSBindings/Mac/Clock SignalTests/MOS6522Bridge.mm b/OSBindings/Mac/Clock SignalTests/MOS6522Bridge.mm index e47ccc844..8dd444a05 100644 --- a/OSBindings/Mac/Clock SignalTests/MOS6522Bridge.mm +++ b/OSBindings/Mac/Clock SignalTests/MOS6522Bridge.mm @@ -15,11 +15,18 @@ class VanillaVIA: public MOS::MOS6522 { public: MOS6522Bridge *bridge; bool irq_line; + uint8_t port_a_value; + uint8_t port_b_value; void set_interrupt_status(bool new_status) { irq_line = new_status; } + + uint8_t get_port_input(int port) + { + return port ? port_b_value : port_a_value; + } }; @implementation MOS6522Bridge @@ -57,4 +64,24 @@ class VanillaVIA: public MOS::MOS6522 { return _via.irq_line; } +- (void)setPortAInput:(uint8_t)portAInput +{ + _via.port_a_value = portAInput; +} + +- (uint8_t)portAInput +{ + return _via.port_a_value; +} + +- (void)setPortBInput:(uint8_t)portBInput +{ + _via.port_b_value = portBInput; +} + +- (uint8_t)portBInput +{ + return _via.port_b_value; +} + @end