From d559d8b901372582638a0a61a924d0f0ff73b507 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 16 May 2017 21:19:17 -0400 Subject: [PATCH] Continued edging towards getting the absolute basics of a testable Z80, for test-driven development. Corrected old-fashioned instance naming issues with the corresponding 6502 class and removed an unnecessary source file while at it. --- .../Clock Signal.xcodeproj/project.pbxproj | 10 +++--- Processors/6502/6502AllRAM.cpp | 10 +++--- Processors/6502/6502AllRAM.hpp | 6 ++-- Processors/RegisterSizes.cpp | 9 ----- Processors/Z80/Z80.hpp | 2 +- Processors/Z80/Z80AllRAM.cpp | 27 +++++++++++++++ Processors/Z80/Z80AllRAM.hpp | 34 +++++++++++++++++++ 7 files changed, 75 insertions(+), 23 deletions(-) delete mode 100644 Processors/RegisterSizes.cpp create mode 100644 Processors/Z80/Z80AllRAM.cpp create mode 100644 Processors/Z80/Z80AllRAM.hpp diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index 4963cc28a..832cc270b 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -33,7 +33,6 @@ 4B2BFC5F1D613E0200BA3AA9 /* TapePRG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B2BFC5D1D613E0200BA3AA9 /* TapePRG.cpp */; }; 4B2BFDB21DAEF5FF001A68B8 /* Video.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B2BFDB01DAEF5FF001A68B8 /* Video.cpp */; }; 4B2C45421E3C3896002A2389 /* cartridge.png in Resources */ = {isa = PBXBuildFile; fileRef = 4B2C45411E3C3896002A2389 /* cartridge.png */; }; - 4B2C455D1EC9442600FC74DD /* RegisterSizes.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B2C455B1EC9442600FC74DD /* RegisterSizes.cpp */; }; 4B2E2D9A1C3A06EC00138695 /* Atari2600.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B2E2D971C3A06EC00138695 /* Atari2600.cpp */; }; 4B2E2D9D1C3A070400138695 /* Electron.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B2E2D9B1C3A070400138695 /* Electron.cpp */; }; 4B30512D1D989E2200B4FED8 /* Drive.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B30512B1D989E2200B4FED8 /* Drive.cpp */; }; @@ -412,6 +411,7 @@ 4BF8295D1D8F048B001BAE39 /* MFM.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BF8295B1D8F048B001BAE39 /* MFM.cpp */; }; 4BF829631D8F536B001BAE39 /* SSD.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BF829611D8F536B001BAE39 /* SSD.cpp */; }; 4BF829661D8F732B001BAE39 /* Disk.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BF829641D8F732B001BAE39 /* Disk.cpp */; }; + 4BFCA1201ECBDC1500AC40C1 /* Z80AllRAM.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BFCA11D1ECBD9BD00AC40C1 /* Z80AllRAM.cpp */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -481,7 +481,6 @@ 4B2BFDB01DAEF5FF001A68B8 /* Video.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Video.cpp; path = Oric/Video.cpp; sourceTree = ""; }; 4B2BFDB11DAEF5FF001A68B8 /* Video.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Video.hpp; path = Oric/Video.hpp; sourceTree = ""; }; 4B2C45411E3C3896002A2389 /* cartridge.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = cartridge.png; sourceTree = ""; }; - 4B2C455B1EC9442600FC74DD /* RegisterSizes.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RegisterSizes.cpp; sourceTree = ""; }; 4B2C455C1EC9442600FC74DD /* RegisterSizes.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = RegisterSizes.hpp; sourceTree = ""; }; 4B2E2D971C3A06EC00138695 /* Atari2600.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Atari2600.cpp; sourceTree = ""; }; 4B2E2D981C3A06EC00138695 /* Atari2600.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Atari2600.hpp; sourceTree = ""; }; @@ -974,6 +973,8 @@ 4BF829641D8F732B001BAE39 /* Disk.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Disk.cpp; path = ../../StaticAnalyser/Acorn/Disk.cpp; sourceTree = ""; }; 4BF829651D8F732B001BAE39 /* Disk.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Disk.hpp; path = ../../StaticAnalyser/Acorn/Disk.hpp; sourceTree = ""; }; 4BF829681D8F7361001BAE39 /* File.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = File.hpp; path = ../../StaticAnalyser/Acorn/File.hpp; sourceTree = ""; }; + 4BFCA11D1ECBD9BD00AC40C1 /* Z80AllRAM.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Z80AllRAM.cpp; path = Z80/Z80AllRAM.cpp; sourceTree = ""; }; + 4BFCA11E1ECBD9BD00AC40C1 /* Z80AllRAM.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Z80AllRAM.hpp; path = Z80/Z80AllRAM.hpp; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -1327,6 +1328,8 @@ children = ( 4B77069B1EC904570053B588 /* Z80.cpp */, 4B77069C1EC904570053B588 /* Z80.hpp */, + 4BFCA11D1ECBD9BD00AC40C1 /* Z80AllRAM.cpp */, + 4BFCA11E1ECBD9BD00AC40C1 /* Z80AllRAM.hpp */, ); name = Z80; sourceTree = ""; @@ -1809,7 +1812,6 @@ 4B1414561B58879D00E04248 /* 6502 */, 4B77069E1EC9045B0053B588 /* Z80 */, 4B7706A01EC9398D0053B588 /* MicroOpScheduler.hpp */, - 4B2C455B1EC9442600FC74DD /* RegisterSizes.cpp */, 4B2C455C1EC9442600FC74DD /* RegisterSizes.hpp */, ); name = Processors; @@ -2516,7 +2518,6 @@ 4B9CCDA11DA279CA0098B625 /* Vic20OptionsPanel.swift in Sources */, 4B8805F01DCFC99C003085B1 /* Acorn.cpp in Sources */, 4B3051301D98ACC600B4FED8 /* Plus3.cpp in Sources */, - 4B2C455D1EC9442600FC74DD /* RegisterSizes.cpp in Sources */, 4B30512D1D989E2200B4FED8 /* Drive.cpp in Sources */, 4BCA6CC81D9DD9F000C2D7B2 /* CommodoreROM.cpp in Sources */, 4BA22B071D8817CE0008C640 /* Disk.cpp in Sources */, @@ -2555,6 +2556,7 @@ 4B3BA0CE1D318B44005DD7A7 /* C1540Bridge.mm in Sources */, 4B3BA0D11D318B44005DD7A7 /* TestMachine6502.mm in Sources */, 4B92EACA1B7C112B00246143 /* 6502TimingTests.swift in Sources */, + 4BFCA1201ECBDC1500AC40C1 /* Z80AllRAM.cpp in Sources */, 4BB73EB71B587A5100552FC2 /* AllSuiteATests.swift in Sources */, 4B121F9B1E06293F00BFDA12 /* PCMSegmentEventSourceTests.mm in Sources */, 4BEF6AAC1D35D1C400E73575 /* DPLLTests.swift in Sources */, diff --git a/Processors/6502/6502AllRAM.cpp b/Processors/6502/6502AllRAM.cpp index 3e4cdf080..875490712 100644 --- a/Processors/6502/6502AllRAM.cpp +++ b/Processors/6502/6502AllRAM.cpp @@ -17,12 +17,12 @@ AllRAMProcessor::AllRAMProcessor() : _timestamp(0) { } int AllRAMProcessor::perform_bus_operation(MOS6502::BusOperation operation, uint16_t address, uint8_t *value) { - _timestamp++; + timestamp_++; if(isReadOperation(operation)) { - *value = _memory[address]; + *value = memory_[address]; } else { - _memory[address] = *value; + memory_[address] = *value; } return 1; @@ -30,9 +30,9 @@ int AllRAMProcessor::perform_bus_operation(MOS6502::BusOperation operation, uint void AllRAMProcessor::set_data_at_address(uint16_t startAddress, size_t length, const uint8_t *data) { size_t endAddress = std::min(startAddress + length, (size_t)65536); - memcpy(&_memory[startAddress], data, endAddress - startAddress); + memcpy(&memory_[startAddress], data, endAddress - startAddress); } uint32_t AllRAMProcessor::get_timestamp() { - return _timestamp; + return timestamp_; } diff --git a/Processors/6502/6502AllRAM.hpp b/Processors/6502/6502AllRAM.hpp index 0a89c48e9..ae2ce5680 100644 --- a/Processors/6502/6502AllRAM.hpp +++ b/Processors/6502/6502AllRAM.hpp @@ -15,9 +15,7 @@ namespace CPU { namespace MOS6502 { class AllRAMProcessor: public Processor { - public: - AllRAMProcessor(); int perform_bus_operation(MOS6502::BusOperation operation, uint16_t address, uint8_t *value); @@ -26,8 +24,8 @@ class AllRAMProcessor: public Processor { uint32_t get_timestamp(); private: - uint8_t _memory[65536]; - uint32_t _timestamp; + uint8_t memory_[65536]; + uint32_t timestamp_; }; } diff --git a/Processors/RegisterSizes.cpp b/Processors/RegisterSizes.cpp deleted file mode 100644 index 96d3f03a4..000000000 --- a/Processors/RegisterSizes.cpp +++ /dev/null @@ -1,9 +0,0 @@ -// -// RegisterSizes.cpp -// Clock Signal -// -// Created by Thomas Harte on 14/05/2017. -// Copyright © 2017 Thomas Harte. All rights reserved. -// - -#include "RegisterSizes.hpp" diff --git a/Processors/Z80/Z80.hpp b/Processors/Z80/Z80.hpp index fff8fd578..f7e171de4 100644 --- a/Processors/Z80/Z80.hpp +++ b/Processors/Z80/Z80.hpp @@ -167,7 +167,7 @@ template class Processor: public MicroOpScheduler { */ void flush() {} - void perform_machine_cycle(const MachineCycle *cycle) { + int perform_machine_cycle(const MachineCycle *cycle) { } /*! diff --git a/Processors/Z80/Z80AllRAM.cpp b/Processors/Z80/Z80AllRAM.cpp new file mode 100644 index 000000000..0d3d61dbe --- /dev/null +++ b/Processors/Z80/Z80AllRAM.cpp @@ -0,0 +1,27 @@ +// +// Z80AllRAM.cpp +// Clock Signal +// +// Created by Thomas Harte on 16/05/2017. +// Copyright © 2017 Thomas Harte. All rights reserved. +// + +#include "Z80AllRAM.hpp" +#include + +using namespace CPU::Z80; + +AllRAMProcessor::AllRAMProcessor() {} + +int AllRAMProcessor::perform_machine_cycle(const MachineCycle *cycle) { + return 0; +} + +void AllRAMProcessor::set_data_at_address(uint16_t startAddress, size_t length, const uint8_t *data) { + size_t endAddress = std::min(startAddress + length, (size_t)65536); + memcpy(&memory_[startAddress], data, endAddress - startAddress); +} + +uint32_t AllRAMProcessor::get_timestamp() { + return timestamp_; +} diff --git a/Processors/Z80/Z80AllRAM.hpp b/Processors/Z80/Z80AllRAM.hpp new file mode 100644 index 000000000..d7ae59b6e --- /dev/null +++ b/Processors/Z80/Z80AllRAM.hpp @@ -0,0 +1,34 @@ +// +// Z80AllRAM.hpp +// Clock Signal +// +// Created by Thomas Harte on 16/05/2017. +// Copyright © 2017 Thomas Harte. All rights reserved. +// + +#ifndef Z80AllRAM_hpp +#define Z80AllRAM_hpp + +#include "Z80.hpp" + +namespace CPU { +namespace Z80 { + +class AllRAMProcessor: public Processor { + public: + AllRAMProcessor(); + + int perform_machine_cycle(const MachineCycle *cycle); + + void set_data_at_address(uint16_t startAddress, size_t length, const uint8_t *data); + uint32_t get_timestamp(); + + private: + uint8_t memory_[65536]; + uint32_t timestamp_; +}; + +} +} + +#endif /* Z80AllRAM_hpp */