From 06fb2ff1c704752d20263d965a250416366acafc Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 18 Jun 2016 09:28:46 -0400 Subject: [PATCH] Started endeavouring to sketch out the boilerplate for writing a 6522 test harness. Added a default implementation of `synchronise` to the 6522 too, since not everybody is going to want one. --- .../Clock Signal.xcodeproj/project.pbxproj | 16 +++++- .../Mac/Clock SignalTests/6522Tests.swift | 13 +++++ .../Clock SignalTests-Bridging-Header.h | 1 + .../Mac/Clock SignalTests/MOS6522Bridge.h | 20 +++++++ .../Mac/Clock SignalTests/MOS6522Bridge.mm | 55 +++++++++++++++++++ Processors/6502/CPU6502.hpp | 7 +++ 6 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 OSBindings/Mac/Clock SignalTests/6522Tests.swift create mode 100644 OSBindings/Mac/Clock SignalTests/MOS6522Bridge.h create mode 100644 OSBindings/Mac/Clock SignalTests/MOS6522Bridge.mm diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index 057575c69..1571aec89 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -313,6 +313,8 @@ 4BBF99181C8FBA6F0075DAFB /* TextureTarget.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BBF99121C8FBA6F0075DAFB /* TextureTarget.cpp */; }; 4BC3B74F1CD194CC00F86E85 /* Shader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BC3B74D1CD194CC00F86E85 /* Shader.cpp */; }; 4BC3B7521CD1956900F86E85 /* OutputShader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BC3B7501CD1956900F86E85 /* OutputShader.cpp */; }; + 4BC751B21D157E61006C31D9 /* 6522Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BC751B11D157E61006C31D9 /* 6522Tests.swift */; }; + 4BC751B61D157EB3006C31D9 /* MOS6522Bridge.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4BC751B51D157EB3006C31D9 /* MOS6522Bridge.mm */; }; 4BC76E691C98E31700E6EF73 /* FIRFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BC76E671C98E31700E6EF73 /* FIRFilter.cpp */; }; 4BC76E6B1C98F43700E6EF73 /* Accelerate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BC76E6A1C98F43700E6EF73 /* Accelerate.framework */; }; 4BC9DF451D044FCA00F44158 /* ROMImages in Resources */ = {isa = PBXBuildFile; fileRef = 4BC9DF441D044FCA00F44158 /* ROMImages */; }; @@ -685,6 +687,9 @@ 4BC3B74E1CD194CC00F86E85 /* Shader.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Shader.hpp; sourceTree = ""; }; 4BC3B7501CD1956900F86E85 /* OutputShader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OutputShader.cpp; sourceTree = ""; }; 4BC3B7511CD1956900F86E85 /* OutputShader.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = OutputShader.hpp; sourceTree = ""; }; + 4BC751B11D157E61006C31D9 /* 6522Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = 6522Tests.swift; sourceTree = ""; }; + 4BC751B41D157EB3006C31D9 /* MOS6522Bridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MOS6522Bridge.h; sourceTree = ""; }; + 4BC751B51D157EB3006C31D9 /* MOS6522Bridge.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MOS6522Bridge.mm; sourceTree = ""; }; 4BC76E671C98E31700E6EF73 /* FIRFilter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FIRFilter.cpp; sourceTree = ""; }; 4BC76E681C98E31700E6EF73 /* FIRFilter.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = FIRFilter.hpp; sourceTree = ""; }; 4BC76E6A1C98F43700E6EF73 /* Accelerate.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accelerate.framework; path = System/Library/Frameworks/Accelerate.framework; sourceTree = SDKROOT; }; @@ -1214,15 +1219,18 @@ 4BB73EB51B587A5100552FC2 /* Clock SignalTests */ = { isa = PBXGroup; children = ( - 4BB73EB81B587A5100552FC2 /* Info.plist */, 4BB297DF1B587D8200A49093 /* Clock SignalTests-Bridging-Header.h */, - 4B1414631B588A1100E04248 /* Test Binaries */, + 4BC751B41D157EB3006C31D9 /* MOS6522Bridge.h */, 4BB297E21B587D8300A49093 /* TestMachine.h */, + 4BC751B51D157EB3006C31D9 /* MOS6522Bridge.mm */, 4BB297E31B587D8300A49093 /* TestMachine.mm */, + 4BB73EB81B587A5100552FC2 /* Info.plist */, + 4BC751B11D157E61006C31D9 /* 6522Tests.swift */, 4BB73EB61B587A5100552FC2 /* AllSuiteATests.swift */, 4B1414611B58888700E04248 /* KlausDormannTests.swift */, - 4B14145F1B58885000E04248 /* WolfgangLorenzTests.swift */, 4B92EAC91B7C112B00246143 /* TimingTests.swift */, + 4B14145F1B58885000E04248 /* WolfgangLorenzTests.swift */, + 4B1414631B588A1100E04248 /* Test Binaries */, ); path = "Clock SignalTests"; sourceTree = ""; @@ -1774,10 +1782,12 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 4BC751B61D157EB3006C31D9 /* MOS6522Bridge.mm in Sources */, 4B14145E1B5887AA00E04248 /* CPU6502AllRAM.cpp in Sources */, 4B14145D1B5887A600E04248 /* CPU6502.cpp in Sources */, 4B92EACA1B7C112B00246143 /* TimingTests.swift in Sources */, 4BB73EB71B587A5100552FC2 /* AllSuiteATests.swift in Sources */, + 4BC751B21D157E61006C31D9 /* 6522Tests.swift in Sources */, 4B1414621B58888700E04248 /* KlausDormannTests.swift in Sources */, 4BB298F01B587D8400A49093 /* TestMachine.mm in Sources */, 4B1414601B58885000E04248 /* WolfgangLorenzTests.swift in Sources */, diff --git a/OSBindings/Mac/Clock SignalTests/6522Tests.swift b/OSBindings/Mac/Clock SignalTests/6522Tests.swift new file mode 100644 index 000000000..833d17621 --- /dev/null +++ b/OSBindings/Mac/Clock SignalTests/6522Tests.swift @@ -0,0 +1,13 @@ +// +// 6522Tests.swift +// Clock Signal +// +// Created by Thomas Harte on 18/06/2016. +// Copyright © 2016 Thomas Harte. All rights reserved. +// + +import XCTest +import Foundation + +class MOS6522Tests: XCTestCase { +} diff --git a/OSBindings/Mac/Clock SignalTests/Clock SignalTests-Bridging-Header.h b/OSBindings/Mac/Clock SignalTests/Clock SignalTests-Bridging-Header.h index a628ea2a9..0bcb4a76b 100644 --- a/OSBindings/Mac/Clock SignalTests/Clock SignalTests-Bridging-Header.h +++ b/OSBindings/Mac/Clock SignalTests/Clock SignalTests-Bridging-Header.h @@ -3,3 +3,4 @@ // #import "TestMachine.h" +#import "MOS6522Bridge.h" diff --git a/OSBindings/Mac/Clock SignalTests/MOS6522Bridge.h b/OSBindings/Mac/Clock SignalTests/MOS6522Bridge.h new file mode 100644 index 000000000..d2bed3fe8 --- /dev/null +++ b/OSBindings/Mac/Clock SignalTests/MOS6522Bridge.h @@ -0,0 +1,20 @@ +// +// MOS6522Bridge.h +// Clock Signal +// +// Created by Thomas Harte on 18/06/2016. +// Copyright © 2016 Thomas Harte. All rights reserved. +// + +#import + +@interface MOS6522Bridge : NSObject + +@property (nonatomic, readonly) BOOL irqLine; + +- (void)setValue:(uint8_t)value forRegister:(NSUInteger)registerNumber; +- (uint8_t)valueForRegister:(NSUInteger)registerNumber; + +- (void)runForHalfCycles:(NSUInteger)numberOfHalfCycles; + +@end diff --git a/OSBindings/Mac/Clock SignalTests/MOS6522Bridge.mm b/OSBindings/Mac/Clock SignalTests/MOS6522Bridge.mm new file mode 100644 index 000000000..0f1a725ed --- /dev/null +++ b/OSBindings/Mac/Clock SignalTests/MOS6522Bridge.mm @@ -0,0 +1,55 @@ +// +// 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" + +@class MOS6522Bridge; + +class VanillaVIA: public MOS::MOS6522 { + public: + MOS6522Bridge *bridge; + bool irq_line; + + void set_interrupt_status(bool new_status) + { + irq_line = new_status; + } +}; + +@implementation MOS6522Bridge +{ + VanillaVIA _via; +} + +- (instancetype)init +{ + self = [super init]; + if(self) + { + _via.bridge = self; + } + return self; +} + +- (void)setValue:(uint8_t)value forRegister:(NSUInteger)registerNumber +{ + _via.set_register((int)registerNumber, value); +} + +- (uint8_t)valueForRegister:(NSUInteger)registerNumber +{ + return _via.get_register((int)registerNumber); +} + +- (void)runForHalfCycles:(NSUInteger)numberOfHalfCycles +{ + _via.run_for_cycles(numberOfHalfCycles); +} + +@end diff --git a/Processors/6502/CPU6502.hpp b/Processors/6502/CPU6502.hpp index e4e884a06..e335df436 100644 --- a/Processors/6502/CPU6502.hpp +++ b/Processors/6502/CPU6502.hpp @@ -1057,6 +1057,13 @@ template class Processor { static_cast(this)->synchronise(); } + /*! + Called to announce the end of a run_for_cycles period, allowing deferred work to take place. + + Users of the 6502 template may override this. + */ + void synchronise() {} + /*! Gets the value of a register.