From 254cc41fd60e24cf5fc1892ebbd76cba219f879c Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 17 Dec 2016 21:13:57 -0500 Subject: [PATCH] Made an attempt to separate and isolate the stuff of creating flux events from a `PCMSegment`, eventually to factor that out of `PCMTrack` and make it available also to `PCMPatchedTrack`. --- .../Clock Signal.xcodeproj/project.pbxproj | 10 ++-- .../Mac/Clock SignalTests/ArrayBuilderTests.h | 13 ----- .../Clock SignalTests/ArrayBuilderTests.mm | 6 ++- .../Clock SignalTests/PCMPatchedTrackTests.h | 13 ----- .../Clock SignalTests/PCMPatchedTrackTests.mm | 15 +++++- Storage/Disk/PCMSegment.cpp | 48 +++++++++++++++++++ Storage/Disk/PCMSegment.hpp | 48 +++++++++++++++++++ Storage/Disk/PCMTrack.hpp | 12 +---- 8 files changed, 122 insertions(+), 43 deletions(-) delete mode 100644 OSBindings/Mac/Clock SignalTests/ArrayBuilderTests.h delete mode 100644 OSBindings/Mac/Clock SignalTests/PCMPatchedTrackTests.h create mode 100644 Storage/Disk/PCMSegment.cpp create mode 100644 Storage/Disk/PCMSegment.hpp diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index 1f2c83a93..7da9dfb84 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -11,6 +11,7 @@ 4B0BE4281D3481E700D5256B /* DigitalPhaseLockedLoop.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B0BE4261D3481E700D5256B /* DigitalPhaseLockedLoop.cpp */; }; 4B0CCC451C62D0B3001CAC5F /* CRT.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B0CCC421C62D0B3001CAC5F /* CRT.cpp */; }; 4B121F951E05E66800BFDA12 /* PCMPatchedTrackTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4B121F941E05E66800BFDA12 /* PCMPatchedTrackTests.mm */; }; + 4B121F981E060CF000BFDA12 /* PCMSegment.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B121F961E060CF000BFDA12 /* PCMSegment.cpp */; }; 4B14145B1B58879D00E04248 /* CPU6502.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B1414571B58879D00E04248 /* CPU6502.cpp */; }; 4B14145D1B5887A600E04248 /* CPU6502.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B1414571B58879D00E04248 /* CPU6502.cpp */; }; 4B14145E1B5887AA00E04248 /* CPU6502AllRAM.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B1414591B58879D00E04248 /* CPU6502AllRAM.cpp */; }; @@ -426,8 +427,9 @@ 4B0BE4271D3481E700D5256B /* DigitalPhaseLockedLoop.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = DigitalPhaseLockedLoop.hpp; sourceTree = ""; }; 4B0CCC421C62D0B3001CAC5F /* CRT.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CRT.cpp; sourceTree = ""; }; 4B0CCC431C62D0B3001CAC5F /* CRT.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = CRT.hpp; sourceTree = ""; }; - 4B121F931E05E66800BFDA12 /* PCMPatchedTrackTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PCMPatchedTrackTests.h; sourceTree = ""; }; 4B121F941E05E66800BFDA12 /* PCMPatchedTrackTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PCMPatchedTrackTests.mm; sourceTree = ""; }; + 4B121F961E060CF000BFDA12 /* PCMSegment.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PCMSegment.cpp; sourceTree = ""; }; + 4B121F971E060CF000BFDA12 /* PCMSegment.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = PCMSegment.hpp; sourceTree = ""; }; 4B1414501B58848C00E04248 /* ClockSignal-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ClockSignal-Bridging-Header.h"; sourceTree = ""; }; 4B1414571B58879D00E04248 /* CPU6502.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CPU6502.cpp; sourceTree = ""; }; 4B1414581B58879D00E04248 /* CPU6502.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = CPU6502.hpp; sourceTree = ""; }; @@ -503,7 +505,6 @@ 4B4DC82A1D2C27A4003C5BF8 /* SerialBus.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = SerialBus.hpp; sourceTree = ""; }; 4B5073051DDD3B9400C48FBD /* ArrayBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ArrayBuilder.cpp; sourceTree = ""; }; 4B5073061DDD3B9400C48FBD /* ArrayBuilder.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = ArrayBuilder.hpp; sourceTree = ""; }; - 4B5073081DDFCFDF00C48FBD /* ArrayBuilderTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ArrayBuilderTests.h; sourceTree = ""; }; 4B5073091DDFCFDF00C48FBD /* ArrayBuilderTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ArrayBuilderTests.mm; sourceTree = ""; }; 4B55CE5B1C3B7D6F0093A61B /* CSOpenGLView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSOpenGLView.h; sourceTree = ""; }; 4B55CE5C1C3B7D6F0093A61B /* CSOpenGLView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSOpenGLView.m; sourceTree = ""; }; @@ -1302,12 +1303,14 @@ 4B6C73BB1D387AE500AFCFCA /* DiskController.cpp */, 4B30512B1D989E2200B4FED8 /* Drive.cpp */, 4B3F1B441E0388D200DB26EE /* PCMPatchedTrack.cpp */, + 4B121F961E060CF000BFDA12 /* PCMSegment.cpp */, 4BAB62B61D3302CA00DF5BA0 /* PCMTrack.cpp */, 4B0BE4271D3481E700D5256B /* DigitalPhaseLockedLoop.hpp */, 4BAB62AC1D3272D200DF5BA0 /* Disk.hpp */, 4B6C73BC1D387AE500AFCFCA /* DiskController.hpp */, 4B30512C1D989E2200B4FED8 /* Drive.hpp */, 4B3F1B451E0388D200DB26EE /* PCMPatchedTrack.hpp */, + 4B121F971E060CF000BFDA12 /* PCMSegment.hpp */, 4BAB62B71D3302CA00DF5BA0 /* PCMTrack.hpp */, 4BB697CF1D4BA44900248BDF /* Encodings */, 4BAB62B21D327F7E00DF5BA0 /* Formats */, @@ -1681,8 +1684,6 @@ 4BB73EB51B587A5100552FC2 /* Clock SignalTests */ = { isa = PBXGroup; children = ( - 4B5073081DDFCFDF00C48FBD /* ArrayBuilderTests.h */, - 4B121F931E05E66800BFDA12 /* PCMPatchedTrackTests.h */, 4B121F941E05E66800BFDA12 /* PCMPatchedTrackTests.mm */, 4B5073091DDFCFDF00C48FBD /* ArrayBuilderTests.mm */, 4BB73EB81B587A5100552FC2 /* Info.plist */, @@ -2450,6 +2451,7 @@ 4B3BA0D11D318B44005DD7A7 /* TestMachine.mm in Sources */, 4B92EACA1B7C112B00246143 /* 6502TimingTests.swift in Sources */, 4BB73EB71B587A5100552FC2 /* AllSuiteATests.swift in Sources */, + 4B121F981E060CF000BFDA12 /* PCMSegment.cpp in Sources */, 4BEF6AAC1D35D1C400E73575 /* DPLLTests.swift in Sources */, 4B3BA0CF1D318B44005DD7A7 /* MOS6522Bridge.mm in Sources */, 4BC751B21D157E61006C31D9 /* 6522Tests.swift in Sources */, diff --git a/OSBindings/Mac/Clock SignalTests/ArrayBuilderTests.h b/OSBindings/Mac/Clock SignalTests/ArrayBuilderTests.h deleted file mode 100644 index ff1800b4d..000000000 --- a/OSBindings/Mac/Clock SignalTests/ArrayBuilderTests.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// ArrayBuilderTests.h -// Clock Signal -// -// Created by Thomas Harte on 19/11/2016. -// Copyright © 2016 Thomas Harte. All rights reserved. -// - -#import - -@interface ArrayBuilderTests : XCTestCase - -@end diff --git a/OSBindings/Mac/Clock SignalTests/ArrayBuilderTests.mm b/OSBindings/Mac/Clock SignalTests/ArrayBuilderTests.mm index 9b10f2588..0dc82b606 100644 --- a/OSBindings/Mac/Clock SignalTests/ArrayBuilderTests.mm +++ b/OSBindings/Mac/Clock SignalTests/ArrayBuilderTests.mm @@ -6,7 +6,8 @@ // Copyright © 2016 Thomas Harte. All rights reserved. // -#import "ArrayBuilderTests.h" +#import + #include "ArrayBuilder.hpp" static NSData *inputData, *outputData; @@ -17,6 +18,9 @@ static void setData(bool is_input, uint8_t *data, size_t size) if(is_input) inputData = dataObject; else outputData = dataObject; } +@interface ArrayBuilderTests : XCTestCase +@end + @implementation ArrayBuilderTests + (void)setUp diff --git a/OSBindings/Mac/Clock SignalTests/PCMPatchedTrackTests.h b/OSBindings/Mac/Clock SignalTests/PCMPatchedTrackTests.h deleted file mode 100644 index 67c243416..000000000 --- a/OSBindings/Mac/Clock SignalTests/PCMPatchedTrackTests.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// PCMPatchedTrackTests.h -// Clock Signal -// -// Created by Thomas Harte on 17/12/2016. -// Copyright © 2016 Thomas Harte. All rights reserved. -// - -#import - -@interface PCMPatchedTrackTests : XCTestCase - -@end diff --git a/OSBindings/Mac/Clock SignalTests/PCMPatchedTrackTests.mm b/OSBindings/Mac/Clock SignalTests/PCMPatchedTrackTests.mm index 2f43924d6..a8d1b4d95 100644 --- a/OSBindings/Mac/Clock SignalTests/PCMPatchedTrackTests.mm +++ b/OSBindings/Mac/Clock SignalTests/PCMPatchedTrackTests.mm @@ -6,11 +6,14 @@ // Copyright © 2016 Thomas Harte. All rights reserved. // -#import "PCMPatchedTrackTests.h" +#import #include "PCMTrack.hpp" #include "PCMPatchedTrack.hpp" +@interface PCMPatchedTrackTests : XCTestCase +@end + @implementation PCMPatchedTrackTests - (std::shared_ptr)togglingTrack @@ -50,4 +53,14 @@ [self assertOneThirtyTwosForTrack:self.patchableTogglingTrack]; } +- (void)testZeroPatch +{ + std::shared_ptr patchableTrack = self.togglingTrack; + Storage::Disk::PCMPatchedTrack *patchable = dynamic_cast(patchableTrack.get()); + if(patchable) + { + printf("."); + } +} + @end diff --git a/Storage/Disk/PCMSegment.cpp b/Storage/Disk/PCMSegment.cpp new file mode 100644 index 000000000..055b369c4 --- /dev/null +++ b/Storage/Disk/PCMSegment.cpp @@ -0,0 +1,48 @@ +// +// PCMSegment.cpp +// Clock Signal +// +// Created by Thomas Harte on 17/12/2016. +// Copyright © 2016 Thomas Harte. All rights reserved. +// + +#include "PCMSegment.hpp" + +using namespace Storage::Disk; + +PCMSegmentEventSource::PCMSegmentEventSource(const PCMSegment &segment) : + segment_(segment) +{ + if(segment_.length_of_a_bit.length&1) + { + segment_.length_of_a_bit.length <<= 1; + segment_.length_of_a_bit.clock_rate <<= 1; + } + next_event_.length.clock_rate = segment_.length_of_a_bit.clock_rate; + reset(); +} + +void PCMSegmentEventSource::reset() +{ + bit_pointer_ = 0; + next_event_.length.length = -(segment_.length_of_a_bit.length >> 1); + next_event_.type = Track::Event::FluxTransition; +} + +Storage::Disk::Track::Event PCMSegmentEventSource::get_next_event() +{ + Storage::Disk::Track::Event next_event; + + const uint8_t *segment_data = segment_.data.data(); + while(bit_pointer_ < segment_.number_of_bits) + { + int bit = segment_data[bit_pointer_ >> 3] & (0x80 >> (bit_pointer_&7)); + bit_pointer_++; + next_event_.length.length += segment_.length_of_a_bit.length; + + if(bit) return next_event_; + } + + next_event_.type = Track::Event::IndexHole; + return next_event; +} diff --git a/Storage/Disk/PCMSegment.hpp b/Storage/Disk/PCMSegment.hpp new file mode 100644 index 000000000..874a2f0ee --- /dev/null +++ b/Storage/Disk/PCMSegment.hpp @@ -0,0 +1,48 @@ +// +// PCMSegment.hpp +// Clock Signal +// +// Created by Thomas Harte on 17/12/2016. +// Copyright © 2016 Thomas Harte. All rights reserved. +// + +#ifndef PCMSegment_hpp +#define PCMSegment_hpp + +#include +#include + +#include "../Storage.hpp" +#include "Disk.hpp" + +namespace Storage { +namespace Disk { + +/*! + A segment of PCM-sampled data. + + Bits from each byte are taken MSB to LSB. +*/ +struct PCMSegment { + Time length_of_a_bit; + unsigned int number_of_bits; + std::vector data; +}; + +class PCMSegmentEventSource { + public: + PCMSegmentEventSource(const PCMSegment &segment); + + Track::Event get_next_event(); + void reset(); + + private: + PCMSegment segment_; + size_t bit_pointer_; + Track::Event next_event_; +}; + +} +} + +#endif /* PCMSegment_hpp */ diff --git a/Storage/Disk/PCMTrack.hpp b/Storage/Disk/PCMTrack.hpp index 1cbd767db..c3ae19e62 100644 --- a/Storage/Disk/PCMTrack.hpp +++ b/Storage/Disk/PCMTrack.hpp @@ -10,22 +10,12 @@ #define PCMTrack_hpp #include "Disk.hpp" +#include "PCMSegment.hpp" #include namespace Storage { namespace Disk { -/*! - A segment of PCM-sampled data. - - Bits from each byte are taken MSB to LSB. -*/ -struct PCMSegment { - Time length_of_a_bit; - unsigned int number_of_bits; - std::vector data; -}; - /*! A subclass of @c Track that provides its @c Events by querying a pulse-code modulated record of original flux detections, with an implied index hole at the very start of the data.