1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-29 12:50:28 +00:00
CLK/OSBindings/Mac/Clock SignalTests/Bridges/MOS6522Bridge.mm

92 lines
2.0 KiB
Plaintext
Raw Normal View History

//
// MOS6522Bridge.m
// Clock Signal
//
// Created by Thomas Harte on 18/06/2016.
// Copyright 2016 Thomas Harte. All rights reserved.
//
#import "MOS6522Bridge.h"
#include "6522.hpp"
#include <memory>
@class MOS6522Bridge;
class VanillaVIAPortHandler: public MOS::MOS6522::PortHandler {
public:
MOS6522Bridge *bridge;
bool irq_line;
uint8_t port_a_value;
uint8_t port_b_value;
bool control_line_values[2][2];
/*
All methods below here are to replace those defined by
MOS::MOS6522::PortHandler.
*/
2017-07-25 02:33:49 +00:00
void set_interrupt_status(bool new_status) {
irq_line = new_status;
}
uint8_t get_port_input(MOS::MOS6522::Port port) {
return port ? port_b_value : port_a_value;
}
void set_control_line_output(MOS::MOS6522::Port port, MOS::MOS6522::Line line, bool value) {
control_line_values[int(port)][int(line)] = value;
}
};
2017-07-25 02:33:49 +00:00
@implementation MOS6522Bridge {
VanillaVIAPortHandler _viaPortHandler;
std::unique_ptr<MOS::MOS6522::MOS6522<VanillaVIAPortHandler>> _via;
}
2017-07-25 02:33:49 +00:00
- (instancetype)init {
self = [super init];
2017-07-25 02:33:49 +00:00
if(self) {
2019-12-24 03:13:25 +00:00
_via = std::make_unique<MOS::MOS6522::MOS6522<VanillaVIAPortHandler>>(_viaPortHandler);
_viaPortHandler.bridge = self;
}
return self;
}
2017-07-25 02:33:49 +00:00
- (void)setValue:(uint8_t)value forRegister:(NSUInteger)registerNumber {
_via->write((int)registerNumber, value);
}
2017-07-25 02:33:49 +00:00
- (uint8_t)valueForRegister:(NSUInteger)registerNumber {
return _via->read((int)registerNumber);
}
2017-07-25 02:33:49 +00:00
- (void)runForHalfCycles:(NSUInteger)numberOfHalfCycles {
_via->run_for(HalfCycles((int)numberOfHalfCycles));
}
2017-07-25 02:33:49 +00:00
- (BOOL)irqLine {
return _viaPortHandler.irq_line;
}
2017-07-25 02:33:49 +00:00
- (void)setPortAInput:(uint8_t)portAInput {
_viaPortHandler.port_a_value = portAInput;
}
2017-07-25 02:33:49 +00:00
- (uint8_t)portAInput {
return _viaPortHandler.port_a_value;
}
2017-07-25 02:33:49 +00:00
- (void)setPortBInput:(uint8_t)portBInput {
_viaPortHandler.port_b_value = portBInput;
}
2017-07-25 02:33:49 +00:00
- (uint8_t)portBInput {
return _viaPortHandler.port_b_value;
}
- (BOOL)valueForControlLine:(MOS6522BridgeLine)line port:(MOS6522BridgePort)port {
return _viaPortHandler.control_line_values[port][line];
}
@end