1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-24 12:30:17 +00:00

Hit and hope is getting me nowhere. Time to unit test this thing.

This commit is contained in:
Thomas Harte 2016-07-09 15:40:25 -04:00
parent 8827597363
commit 7cc4bf3fe7
9 changed files with 124 additions and 14 deletions

View File

@ -117,15 +117,15 @@ template <class T> class MOS6522 {
_registers.peripheral_control = value;
// TODO: simplify below; tryig to avoid improper logging of unimplemented warnings in input mode
if(value & 0x08)
{
// if(value & 0x08)
// {
switch(value & 0x0e)
{
default: printf("Unimplemented control line mode %d\n", (value >> 1)&7); break;
case 0x0c: static_cast<T *>(this)->set_control_line_output(Port::A, Line::Two, false); break;
case 0x0e: static_cast<T *>(this)->set_control_line_output(Port::A, Line::Two, true); break;
}
}
// }
if(value & 0x80)
{
switch(value & 0xe0)

View File

@ -30,14 +30,14 @@ void Machine::set_serial_bus(std::shared_ptr<::Commodore::Serial::Bus> serial_bu
unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value)
{
static bool log = false;
/* static bool log = false;
if(operation == CPU6502::BusOperation::ReadOpcode)
{
log = (address >= 0xE85B && address <= 0xE907) || (address >= 0xE9C9 && address <= 0xEA2D);
if(log) printf("\n%04x: ", address);
}
if(log) printf("[%c %04x] ", isReadOperation(operation) ? 'r' : 'w', address);
if(log) printf("[%c %04x] ", isReadOperation(operation) ? 'r' : 'w', address);*/
if(address < 0x800)
{

View File

@ -34,7 +34,7 @@ class SerialPortVIA: public MOS::MOS6522<SerialPortVIA>, public MOS::MOS6522IRQD
if(port) {
std::shared_ptr<::Commodore::Serial::Port> serialPort = _serialPort.lock();
if(serialPort) {
printf("1540 output: %02x\n", value);
// printf("1540 output: %02x\n", value);
// "ATNA (Attention Acknowledge) is an output from PB4 which is sensed on the serial data line after being exclusively "ored" by the attention line and inverted"
_attention_acknowledge_level = !(value&0x10);
_data_level_output = (value&0x02);
@ -79,10 +79,7 @@ class SerialPortVIA: public MOS::MOS6522<SerialPortVIA>, public MOS::MOS6522IRQD
if(serialPort) {
serialPort->set_output(::Commodore::Serial::Line::Data,
(::Commodore::Serial::LineLevel)!(_data_level_output
|| (_attention_level_input == _attention_acknowledge_level))
);
//
|| (_attention_level_input == _attention_acknowledge_level)));
}
}
};

View File

@ -45,6 +45,7 @@ void Bus::set_line_output_did_change(Line line)
if(locked_port)
{
new_line_level = (LineLevel)((bool)new_line_level & (bool)locked_port->get_output(line));
// printf("[%s] %s is now %s\n", typeid(locked_port).name(), (bool)locked_port->get_output(line) ? "high" : "low");
}
}

View File

@ -48,9 +48,12 @@ namespace Serial {
Port() : _line_levels{High, High, High, High, High} {}
void set_output(Line line, LineLevel level) {
_line_levels[line] = level;
std::shared_ptr<Bus> bus = _serial_bus.lock();
if(bus) bus->set_line_output_did_change(line);
if(_line_levels[line] != level)
{
_line_levels[line] = level;
std::shared_ptr<Bus> bus = _serial_bus.lock();
if(bus) bus->set_line_output_did_change(line);
}
}
LineLevel get_output(Line line) {

View File

@ -25,6 +25,7 @@
4B2E2D951C399D1200138695 /* ElectronDocument.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4B2E2D931C399D1200138695 /* ElectronDocument.xib */; };
4B2E2D9A1C3A06EC00138695 /* Atari2600.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B2E2D971C3A06EC00138695 /* Atari2600.cpp */; };
4B2E2D9D1C3A070400138695 /* Electron.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B2E2D9B1C3A070400138695 /* Electron.cpp */; };
4B3BA0C11D31882D005DD7A7 /* C1540Bridge.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4B3BA0C01D31882D005DD7A7 /* C1540Bridge.mm */; };
4B4DC8211D2C2425003C5BF8 /* Vic20.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B4DC81F1D2C2425003C5BF8 /* Vic20.cpp */; };
4B4DC8281D2C2470003C5BF8 /* Commodore1540.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B4DC8261D2C2470003C5BF8 /* Commodore1540.cpp */; };
4B4DC82B1D2C27A4003C5BF8 /* SerialBus.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B4DC8291D2C27A4003C5BF8 /* SerialBus.cpp */; };
@ -386,6 +387,8 @@
4B2E2D991C3A06EC00138695 /* Atari2600Inputs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Atari2600Inputs.h; sourceTree = "<group>"; };
4B2E2D9B1C3A070400138695 /* Electron.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Electron.cpp; path = Electron/Electron.cpp; sourceTree = "<group>"; };
4B2E2D9C1C3A070400138695 /* Electron.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Electron.hpp; path = Electron/Electron.hpp; sourceTree = "<group>"; };
4B3BA0BF1D31882D005DD7A7 /* C1540Bridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = C1540Bridge.h; sourceTree = "<group>"; };
4B3BA0C01D31882D005DD7A7 /* C1540Bridge.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = C1540Bridge.mm; sourceTree = "<group>"; };
4B4DC81F1D2C2425003C5BF8 /* Vic20.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Vic20.cpp; sourceTree = "<group>"; };
4B4DC8201D2C2425003C5BF8 /* Vic20.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Vic20.hpp; sourceTree = "<group>"; };
4B4DC8261D2C2470003C5BF8 /* Commodore1540.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Commodore1540.cpp; sourceTree = "<group>"; };
@ -1285,6 +1288,8 @@
4B14145F1B58885000E04248 /* WolfgangLorenzTests.swift */,
4B1414631B588A1100E04248 /* Test Binaries */,
4BC9E1ED1D23449A003FCEE4 /* 6502InterruptTests.swift */,
4B3BA0BF1D31882D005DD7A7 /* C1540Bridge.h */,
4B3BA0C01D31882D005DD7A7 /* C1540Bridge.mm */,
);
path = "Clock SignalTests";
sourceTree = "<group>";
@ -1843,6 +1848,7 @@
files = (
4BC751B61D157EB3006C31D9 /* MOS6522Bridge.mm in Sources */,
4B14145E1B5887AA00E04248 /* CPU6502AllRAM.cpp in Sources */,
4B3BA0C11D31882D005DD7A7 /* C1540Bridge.mm in Sources */,
4B14145D1B5887A600E04248 /* CPU6502.cpp in Sources */,
4B1E85811D176468001EF87D /* 6532Tests.swift in Sources */,
4BC9E1EE1D23449A003FCEE4 /* 6502InterruptTests.swift in Sources */,

View File

@ -126,7 +126,7 @@ using namespace Commodore::Vic20;
{
switch(key)
{
case VK_UpArrow: _vic20.set_joystick_state(JoystickInput::Up, isPressed); break;
case VK_UpArrow: _vic20.set_joystick_state(JoystickInput::Up, isPressed); break;
case VK_DownArrow: _vic20.set_joystick_state(JoystickInput::Down, isPressed); break;
case VK_LeftArrow: _vic20.set_joystick_state(JoystickInput::Left, isPressed); break;
case VK_RightArrow: _vic20.set_joystick_state(JoystickInput::Right, isPressed); break;

View File

@ -0,0 +1,20 @@
//
// C1540Bridge.h
// Clock Signal
//
// Created by Thomas Harte on 09/07/2016.
// Copyright © 2016 Thomas Harte. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface C1540Bridge : NSObject
@property (nonatomic) BOOL attentionLine;
@property (nonatomic) BOOL dataLine;
@property (nonatomic) BOOL clockLine;
- (void)runForCycles:(NSUInteger)numberOfCycles;
- (void)setROM:(NSData *)ROM;
@end

View File

@ -0,0 +1,83 @@
//
// C1540Bridge.m
// Clock Signal
//
// Created by Thomas Harte on 09/07/2016.
// Copyright © 2016 Thomas Harte. All rights reserved.
//
#import "C1540Bridge.h"
#include "Commodore1540.hpp"
class VanillaSerialPort: public Commodore::Serial::Port {
public:
void set_input(Commodore::Serial::Line line, Commodore::Serial::LineLevel value)
{
_input_line_levels[(int)line] = value;
}
Commodore::Serial::LineLevel _input_line_levels[5];
};
@implementation C1540Bridge
{
Commodore::C1540::Machine _c1540;
std::shared_ptr<Commodore::Serial::Bus> _serialBus;
std::shared_ptr<VanillaSerialPort> _serialPort;
}
- (instancetype)init
{
self = [super init];
if(self)
{
_serialBus.reset(new ::Commodore::Serial::Bus);
_serialPort.reset(new VanillaSerialPort);
_c1540.set_serial_bus(_serialBus);
_serialBus->add_port(_serialPort);
}
return self;
}
- (void)setROM:(NSData *)ROM
{
_c1540.set_rom((uint8_t *)ROM.bytes);
}
- (void)runForCycles:(NSUInteger)numberOfCycles
{
_c1540.run_for_cycles((int)numberOfCycles);
}
- (void)setAttentionLine:(BOOL)attentionLine
{
_serialPort->set_input(Commodore::Serial::Line::Attention, attentionLine ? Commodore::Serial::LineLevel::High : Commodore::Serial::LineLevel::Low);
}
- (BOOL)attentionLine
{
return _serialPort->_input_line_levels[Commodore::Serial::Line::Attention];
}
- (void)setDataLine:(BOOL)dataLine
{
_serialPort->set_input(Commodore::Serial::Line::Data, dataLine ? Commodore::Serial::LineLevel::High : Commodore::Serial::LineLevel::Low);
}
- (BOOL)dataLine
{
return _serialPort->_input_line_levels[Commodore::Serial::Line::Data];
}
- (void)setClockLine:(BOOL)clockLine
{
_serialPort->set_input(Commodore::Serial::Line::Clock, clockLine ? Commodore::Serial::LineLevel::High : Commodore::Serial::LineLevel::Low);
}
- (BOOL)clockLine
{
return _serialPort->_input_line_levels[Commodore::Serial::Line::Clock];
}
@end