2016-07-09 19:40:25 +00:00
|
|
|
//
|
|
|
|
// C1540Bridge.m
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 09/07/2016.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2016 Thomas Harte. All rights reserved.
|
2016-07-09 19:40:25 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#import "C1540Bridge.h"
|
2016-07-10 11:46:20 +00:00
|
|
|
#include "C1540.hpp"
|
2017-07-16 21:00:39 +00:00
|
|
|
#include "NSData+StdVector.h"
|
2018-01-01 21:04:13 +00:00
|
|
|
#include "CSROMFetcher.hpp"
|
2016-07-09 19:40:25 +00:00
|
|
|
|
|
|
|
class VanillaSerialPort: public Commodore::Serial::Port {
|
|
|
|
public:
|
2017-07-16 21:00:39 +00:00
|
|
|
void set_input(Commodore::Serial::Line line, Commodore::Serial::LineLevel value) {
|
2016-07-09 19:40:25 +00:00
|
|
|
_input_line_levels[(int)line] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
Commodore::Serial::LineLevel _input_line_levels[5];
|
|
|
|
};
|
|
|
|
|
2017-07-16 21:00:39 +00:00
|
|
|
@implementation C1540Bridge {
|
2018-01-01 21:04:13 +00:00
|
|
|
std::unique_ptr<Commodore::C1540::Machine> _c1540;
|
2016-07-09 19:40:25 +00:00
|
|
|
std::shared_ptr<Commodore::Serial::Bus> _serialBus;
|
|
|
|
std::shared_ptr<VanillaSerialPort> _serialPort;
|
|
|
|
}
|
|
|
|
|
2017-07-16 21:00:39 +00:00
|
|
|
- (instancetype)init {
|
2016-07-09 19:40:25 +00:00
|
|
|
self = [super init];
|
2017-07-16 21:00:39 +00:00
|
|
|
if(self) {
|
2016-07-09 19:40:25 +00:00
|
|
|
_serialBus.reset(new ::Commodore::Serial::Bus);
|
|
|
|
_serialPort.reset(new VanillaSerialPort);
|
|
|
|
|
2018-01-01 21:04:13 +00:00
|
|
|
_c1540.reset(new Commodore::C1540::Machine(Commodore::C1540::Machine::C1540));
|
2018-01-25 23:28:19 +00:00
|
|
|
_c1540->set_rom_fetcher(CSROMFetcher());
|
2018-01-01 21:04:13 +00:00
|
|
|
_c1540->set_serial_bus(_serialBus);
|
2016-07-10 11:46:20 +00:00
|
|
|
Commodore::Serial::AttachPortAndBus(_serialPort, _serialBus);
|
2016-07-09 19:40:25 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2017-07-16 21:00:39 +00:00
|
|
|
- (void)runForCycles:(NSUInteger)numberOfCycles {
|
2018-01-01 21:04:13 +00:00
|
|
|
_c1540->run_for(Cycles((int)numberOfCycles));
|
2016-07-09 19:40:25 +00:00
|
|
|
}
|
|
|
|
|
2017-07-16 21:00:39 +00:00
|
|
|
- (void)setAttentionLine:(BOOL)attentionLine {
|
2016-07-09 21:22:10 +00:00
|
|
|
_serialPort->set_output(Commodore::Serial::Line::Attention, attentionLine ? Commodore::Serial::LineLevel::High : Commodore::Serial::LineLevel::Low);
|
2016-07-09 19:40:25 +00:00
|
|
|
}
|
|
|
|
|
2017-07-16 21:00:39 +00:00
|
|
|
- (BOOL)attentionLine {
|
2016-07-09 19:40:25 +00:00
|
|
|
return _serialPort->_input_line_levels[Commodore::Serial::Line::Attention];
|
|
|
|
}
|
|
|
|
|
2017-07-16 21:00:39 +00:00
|
|
|
- (void)setDataLine:(BOOL)dataLine {
|
2016-07-09 21:22:10 +00:00
|
|
|
_serialPort->set_output(Commodore::Serial::Line::Data, dataLine ? Commodore::Serial::LineLevel::High : Commodore::Serial::LineLevel::Low);
|
2016-07-09 19:40:25 +00:00
|
|
|
}
|
|
|
|
|
2017-07-16 21:00:39 +00:00
|
|
|
- (BOOL)dataLine {
|
2016-07-09 19:40:25 +00:00
|
|
|
return _serialPort->_input_line_levels[Commodore::Serial::Line::Data];
|
|
|
|
}
|
|
|
|
|
2017-07-16 21:00:39 +00:00
|
|
|
- (void)setClockLine:(BOOL)clockLine {
|
2016-07-09 21:22:10 +00:00
|
|
|
_serialPort->set_output(Commodore::Serial::Line::Clock, clockLine ? Commodore::Serial::LineLevel::High : Commodore::Serial::LineLevel::Low);
|
2016-07-09 19:40:25 +00:00
|
|
|
}
|
|
|
|
|
2017-07-16 21:00:39 +00:00
|
|
|
- (BOOL)clockLine {
|
2016-07-09 19:40:25 +00:00
|
|
|
return _serialPort->_input_line_levels[Commodore::Serial::Line::Clock];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|