From 87a021ec2dff62d3de5d11786eacc468826af37b Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 16 May 2017 22:19:40 -0400 Subject: [PATCH] Made further attempt to get as fas as having the Z80 attempt to do something. --- .../Clock Signal.xcodeproj/project.pbxproj | 8 ++++++ .../Bridges/TestMachineZ80.h | 2 +- .../Bridges/TestMachineZ80.mm | 2 +- .../WolfgangLorenzTests.swift | 2 -- .../Mac/Clock SignalTests/ZexallTests.swift | 26 +++++++++++++++++++ Processors/Z80/Z80.hpp | 26 +++++++++++-------- 6 files changed, 51 insertions(+), 15 deletions(-) create mode 100644 OSBindings/Mac/Clock SignalTests/ZexallTests.swift diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index bf758dad4..3bbf1ffda 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -414,6 +414,8 @@ 4BFCA1201ECBDC1500AC40C1 /* Z80AllRAM.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BFCA11D1ECBD9BD00AC40C1 /* Z80AllRAM.cpp */; }; 4BFCA1241ECBDCB400AC40C1 /* AllRAMProcessor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BFCA1211ECBDCAF00AC40C1 /* AllRAMProcessor.cpp */; }; 4BFCA1271ECBE33200AC40C1 /* TestMachineZ80.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4BFCA1261ECBE33200AC40C1 /* TestMachineZ80.mm */; }; + 4BFCA1291ECBE7A700AC40C1 /* zexall.com in Resources */ = {isa = PBXBuildFile; fileRef = 4BFCA1281ECBE7A700AC40C1 /* zexall.com */; }; + 4BFCA12B1ECBE7C400AC40C1 /* ZexallTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BFCA12A1ECBE7C400AC40C1 /* ZexallTests.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -981,6 +983,8 @@ 4BFCA1221ECBDCAF00AC40C1 /* AllRAMProcessor.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = AllRAMProcessor.hpp; sourceTree = ""; }; 4BFCA1251ECBE33200AC40C1 /* TestMachineZ80.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestMachineZ80.h; sourceTree = ""; }; 4BFCA1261ECBE33200AC40C1 /* TestMachineZ80.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TestMachineZ80.mm; sourceTree = ""; }; + 4BFCA1281ECBE7A700AC40C1 /* zexall.com */ = {isa = PBXFileReference; lastKnownFileType = file; name = zexall.com; path = Zexall/zexall.com; sourceTree = ""; }; + 4BFCA12A1ECBE7C400AC40C1 /* ZexallTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ZexallTests.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -1036,6 +1040,7 @@ 4B1414631B588A1100E04248 /* Test Binaries */ = { isa = PBXGroup; children = ( + 4BFCA1281ECBE7A700AC40C1 /* zexall.com */, 4B9252CD1E74D28200B76AF1 /* Atari ROMs */, 4B44EBF61DC9883B00A7820C /* 6502_functional_test.bin */, 4B44EBF41DC987AE00A7820C /* AllSuiteA.bin */, @@ -1780,6 +1785,7 @@ 4BEF6AAB1D35D1C400E73575 /* DPLLTests.swift */, 4B1414611B58888700E04248 /* KlausDormannTests.swift */, 4B14145F1B58885000E04248 /* WolfgangLorenzTests.swift */, + 4BFCA12A1ECBE7C400AC40C1 /* ZexallTests.swift */, 4B3BA0C41D318B44005DD7A7 /* Bridges */, 4B1414631B588A1100E04248 /* Test Binaries */, ); @@ -2179,6 +2185,7 @@ 4BB2998A1B587D8400A49093 /* lseix in Resources */, 4BB2994E1B587D8400A49093 /* dexn in Resources */, 4BB299971B587D8400A49093 /* nopa in Resources */, + 4BFCA1291ECBE7A700AC40C1 /* zexall.com in Resources */, 4BB299521B587D8400A49093 /* eoray in Resources */, 4BB299411B587D8400A49093 /* cpyb in Resources */, 4BB299A61B587D8400A49093 /* phan in Resources */, @@ -2573,6 +2580,7 @@ 4BEF6AAC1D35D1C400E73575 /* DPLLTests.swift in Sources */, 4B3BA0CF1D318B44005DD7A7 /* MOS6522Bridge.mm in Sources */, 4BC751B21D157E61006C31D9 /* 6522Tests.swift in Sources */, + 4BFCA12B1ECBE7C400AC40C1 /* ZexallTests.swift in Sources */, 4BB2A9AF1E13367E001A5C23 /* CRCTests.mm in Sources */, 4B3BA0D01D318B44005DD7A7 /* MOS6532Bridge.mm in Sources */, 4B3BA0C31D318AEC005DD7A7 /* C1540Tests.swift in Sources */, diff --git a/OSBindings/Mac/Clock SignalTests/Bridges/TestMachineZ80.h b/OSBindings/Mac/Clock SignalTests/Bridges/TestMachineZ80.h index a9ce6d613..e934f84d3 100644 --- a/OSBindings/Mac/Clock SignalTests/Bridges/TestMachineZ80.h +++ b/OSBindings/Mac/Clock SignalTests/Bridges/TestMachineZ80.h @@ -13,7 +13,7 @@ typedef NS_ENUM(NSInteger, CSTestMachineZ80Register) { CSTestMachineZ80RegisterStackPointer, }; -@interface TestMachineZ80 : NSObject +@interface CSTestMachineZ80 : NSObject - (void)setData:(NSData *)data atAddress:(uint16_t)startAddress; - (void)runForNumberOfCycles:(int)cycles; diff --git a/OSBindings/Mac/Clock SignalTests/Bridges/TestMachineZ80.mm b/OSBindings/Mac/Clock SignalTests/Bridges/TestMachineZ80.mm index 28436f131..00de40840 100644 --- a/OSBindings/Mac/Clock SignalTests/Bridges/TestMachineZ80.mm +++ b/OSBindings/Mac/Clock SignalTests/Bridges/TestMachineZ80.mm @@ -16,7 +16,7 @@ static CPU::Z80::Register registerForRegister(CSTestMachineZ80Register reg) { } } -@implementation TestMachineZ80 { +@implementation CSTestMachineZ80 { CPU::Z80::AllRAMProcessor _processor; } diff --git a/OSBindings/Mac/Clock SignalTests/WolfgangLorenzTests.swift b/OSBindings/Mac/Clock SignalTests/WolfgangLorenzTests.swift index b647183e4..231937d95 100644 --- a/OSBindings/Mac/Clock SignalTests/WolfgangLorenzTests.swift +++ b/OSBindings/Mac/Clock SignalTests/WolfgangLorenzTests.swift @@ -195,7 +195,6 @@ class WolfgangLorenzTests: XCTestCase, CSTestMachine6502JamHandler { fileprivate var output: String = "" fileprivate func runWolfgangLorenzTest(_ name: String) { - var machine: CSTestMachine6502! if let filename = Bundle(for: type(of: self)).path(forResource: name, ofType: nil) { @@ -298,7 +297,6 @@ class WolfgangLorenzTests: XCTestCase, CSTestMachine6502JamHandler { } func testMachine(_ machine: CSTestMachine6502!, didJamAtAddress address: UInt16) { - switch address { case 0xffd2: machine.setValue(0x00, forAddress: 0x030c) diff --git a/OSBindings/Mac/Clock SignalTests/ZexallTests.swift b/OSBindings/Mac/Clock SignalTests/ZexallTests.swift new file mode 100644 index 000000000..19580acc8 --- /dev/null +++ b/OSBindings/Mac/Clock SignalTests/ZexallTests.swift @@ -0,0 +1,26 @@ +// +// ZexallTests.swift +// Clock Signal +// +// Created by Thomas Harte on 16/05/2017. +// Copyright © 2017 Thomas Harte. All rights reserved. +// + +import XCTest +import Foundation + +class ZexallTests: XCTestCase { + + func testZexall() { + if let filename = Bundle(for: type(of: self)).path(forResource: "zexall", ofType: "com") { + if let testData = try? Data(contentsOf: URL(fileURLWithPath: filename)) { + + let machine = CSTestMachineZ80() + machine.setData(testData, atAddress: 0x0100) + + machine.runForNumber(ofCycles: 20) + } + } + } + +} diff --git a/Processors/Z80/Z80.hpp b/Processors/Z80/Z80.hpp index f7e171de4..5b1e42a01 100644 --- a/Processors/Z80/Z80.hpp +++ b/Processors/Z80/Z80.hpp @@ -71,9 +71,19 @@ enum BusOperation { }; struct MachineCycle { - BusOperation operation; + const BusOperation operation; const uint16_t *address; - uint8_t *value; + uint8_t *const value; + + inline int cycle_length() const { + static const int cycles_by_bus_operation[6] = { + 4, + 3, 3, + 3, 3, + 3 + }; + return cycles_by_bus_operation[operation]; + } }; struct MicroOp { @@ -110,13 +120,6 @@ template class Processor: public MicroOpScheduler { uint8_t operation_; - constexpr static int cycles_by_bus_operation[6] = { - 4, - 3, 3, - 3, 3, - 3 - }; - public: /*! Runs the Z80 for a supplied number of cycles. @@ -135,12 +138,12 @@ template class Processor: public MicroOpScheduler { }; schedule_program(fetch_decode_execute); - MicroOp *operation = &scheduled_programs_[schedule_programs_read_pointer_][schedule_program_program_counter_]; + const MicroOp *operation = &scheduled_programs_[schedule_programs_read_pointer_][schedule_program_program_counter_]; number_of_cycles_ += number_of_cycles; while(1) { switch(operation->type) { case MicroOp::BusOperation: - if(number_of_cycles_ < cycles_by_bus_operation[operation->type]) { + if(number_of_cycles_ < operation->machine_cycle.cycle_length()) { return; } perform_machine_cycle(&operation->machine_cycle); @@ -168,6 +171,7 @@ template class Processor: public MicroOpScheduler { void flush() {} int perform_machine_cycle(const MachineCycle *cycle) { + return 0; } /*!