2016-06-18 13:28:46 +00:00
|
|
|
//
|
|
|
|
// MOS6522Bridge.m
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 18/06/2016.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2016 Thomas Harte. All rights reserved.
|
2016-06-18 13:28:46 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#import "MOS6522Bridge.h"
|
2017-09-05 01:56:21 +00:00
|
|
|
|
2016-06-18 13:28:46 +00:00
|
|
|
#include "6522.hpp"
|
2017-09-05 01:56:21 +00:00
|
|
|
#include <memory>
|
2016-06-18 13:28:46 +00:00
|
|
|
|
|
|
|
@class MOS6522Bridge;
|
|
|
|
|
2017-09-05 01:56:21 +00:00
|
|
|
class VanillaVIAPortHandler: public MOS::MOS6522::PortHandler {
|
2016-06-18 13:28:46 +00:00
|
|
|
public:
|
|
|
|
MOS6522Bridge *bridge;
|
|
|
|
bool irq_line;
|
2016-06-18 20:40:01 +00:00
|
|
|
uint8_t port_a_value;
|
|
|
|
uint8_t port_b_value;
|
2016-06-18 13:28:46 +00:00
|
|
|
|
2017-07-25 02:33:49 +00:00
|
|
|
void set_interrupt_status(bool new_status) {
|
2016-06-18 13:28:46 +00:00
|
|
|
irq_line = new_status;
|
|
|
|
}
|
2016-06-18 20:40:01 +00:00
|
|
|
|
2017-09-05 01:56:21 +00:00
|
|
|
uint8_t get_port_input(MOS::MOS6522::Port port) {
|
2016-06-18 20:40:01 +00:00
|
|
|
return port ? port_b_value : port_a_value;
|
|
|
|
}
|
2016-06-18 13:28:46 +00:00
|
|
|
};
|
|
|
|
|
2017-07-25 02:33:49 +00:00
|
|
|
@implementation MOS6522Bridge {
|
2017-09-05 01:56:21 +00:00
|
|
|
VanillaVIAPortHandler _viaPortHandler;
|
|
|
|
std::unique_ptr<MOS::MOS6522::MOS6522<VanillaVIAPortHandler>> _via;
|
2016-06-18 13:28:46 +00:00
|
|
|
}
|
|
|
|
|
2017-07-25 02:33:49 +00:00
|
|
|
- (instancetype)init {
|
2016-06-18 13:28:46 +00:00
|
|
|
self = [super init];
|
2017-07-25 02:33:49 +00:00
|
|
|
if(self) {
|
2017-09-05 01:56:21 +00:00
|
|
|
_via.reset(new MOS::MOS6522::MOS6522<VanillaVIAPortHandler>(_viaPortHandler));
|
|
|
|
_viaPortHandler.bridge = self;
|
2016-06-18 13:28:46 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2017-07-25 02:33:49 +00:00
|
|
|
- (void)setValue:(uint8_t)value forRegister:(NSUInteger)registerNumber {
|
2017-09-05 01:56:21 +00:00
|
|
|
_via->set_register((int)registerNumber, value);
|
2016-06-18 13:28:46 +00:00
|
|
|
}
|
|
|
|
|
2017-07-25 02:33:49 +00:00
|
|
|
- (uint8_t)valueForRegister:(NSUInteger)registerNumber {
|
2017-09-05 01:56:21 +00:00
|
|
|
return _via->get_register((int)registerNumber);
|
2016-06-18 13:28:46 +00:00
|
|
|
}
|
|
|
|
|
2017-07-25 02:33:49 +00:00
|
|
|
- (void)runForHalfCycles:(NSUInteger)numberOfHalfCycles {
|
2017-09-05 01:56:21 +00:00
|
|
|
_via->run_for(HalfCycles((int)numberOfHalfCycles));
|
2016-06-18 18:30:23 +00:00
|
|
|
}
|
|
|
|
|
2017-07-25 02:33:49 +00:00
|
|
|
- (BOOL)irqLine {
|
2017-09-05 01:56:21 +00:00
|
|
|
return _viaPortHandler.irq_line;
|
2016-06-18 13:28:46 +00:00
|
|
|
}
|
|
|
|
|
2017-07-25 02:33:49 +00:00
|
|
|
- (void)setPortAInput:(uint8_t)portAInput {
|
2017-09-05 01:56:21 +00:00
|
|
|
_viaPortHandler.port_a_value = portAInput;
|
2016-06-18 20:40:01 +00:00
|
|
|
}
|
|
|
|
|
2017-07-25 02:33:49 +00:00
|
|
|
- (uint8_t)portAInput {
|
2017-09-05 01:56:21 +00:00
|
|
|
return _viaPortHandler.port_a_value;
|
2016-06-18 20:40:01 +00:00
|
|
|
}
|
|
|
|
|
2017-07-25 02:33:49 +00:00
|
|
|
- (void)setPortBInput:(uint8_t)portBInput {
|
2017-09-05 01:56:21 +00:00
|
|
|
_viaPortHandler.port_b_value = portBInput;
|
2016-06-18 20:40:01 +00:00
|
|
|
}
|
|
|
|
|
2017-07-25 02:33:49 +00:00
|
|
|
- (uint8_t)portBInput {
|
2017-09-05 01:56:21 +00:00
|
|
|
return _viaPortHandler.port_b_value;
|
2016-06-18 20:40:01 +00:00
|
|
|
}
|
|
|
|
|
2016-06-18 13:28:46 +00:00
|
|
|
@end
|