From 6cfc3daacb6c225f35b0412348dcd9e5d012fc71 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 15 Aug 2017 21:52:12 -0400 Subject: [PATCH] Introduced a test within the disk controller so as not to request illegal tracks from disks, instead automatically substituting an 'unformatted' track. Which is just empty. --- .../Clock Signal.xcodeproj/project.pbxproj | 6 ++++ Storage/Disk/Disk.cpp | 3 ++ Storage/Disk/DiskController.cpp | 13 ++++---- Storage/Disk/PCMPatchedTrack.hpp | 2 +- Storage/Disk/UnformattedTrack.cpp | 26 ++++++++++++++++ Storage/Disk/UnformattedTrack.hpp | 30 +++++++++++++++++++ 6 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 Storage/Disk/UnformattedTrack.cpp create mode 100644 Storage/Disk/UnformattedTrack.hpp diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index b77bb0dd8..10b16ea4c 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -121,6 +121,7 @@ 4BAB62B51D327F7E00DF5BA0 /* G64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BAB62B31D327F7E00DF5BA0 /* G64.cpp */; }; 4BAB62B81D3302CA00DF5BA0 /* PCMTrack.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BAB62B61D3302CA00DF5BA0 /* PCMTrack.cpp */; }; 4BACC5B11F3DFF7C0037C015 /* CharacterMapper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BACC5AF1F3DFF7C0037C015 /* CharacterMapper.cpp */; }; + 4BAD9B961F43D7E900724854 /* UnformattedTrack.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BAD9B941F43D7E900724854 /* UnformattedTrack.cpp */; }; 4BB17D4E1ED7909F00ABD1E1 /* tests.expected.json in Resources */ = {isa = PBXBuildFile; fileRef = 4BB17D4C1ED7909F00ABD1E1 /* tests.expected.json */; }; 4BB17D4F1ED7909F00ABD1E1 /* tests.in.json in Resources */ = {isa = PBXBuildFile; fileRef = 4BB17D4D1ED7909F00ABD1E1 /* tests.in.json */; }; 4BB298F11B587D8400A49093 /* start in Resources */ = {isa = PBXBuildFile; fileRef = 4BB297E51B587D8300A49093 /* start */; }; @@ -673,6 +674,8 @@ 4BAB62B71D3302CA00DF5BA0 /* PCMTrack.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = PCMTrack.hpp; sourceTree = ""; }; 4BACC5AF1F3DFF7C0037C015 /* CharacterMapper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CharacterMapper.cpp; path = AmstradCPC/CharacterMapper.cpp; sourceTree = ""; }; 4BACC5B01F3DFF7C0037C015 /* CharacterMapper.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = CharacterMapper.hpp; path = AmstradCPC/CharacterMapper.hpp; sourceTree = ""; }; + 4BAD9B941F43D7E900724854 /* UnformattedTrack.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UnformattedTrack.cpp; sourceTree = ""; }; + 4BAD9B951F43D7E900724854 /* UnformattedTrack.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = UnformattedTrack.hpp; sourceTree = ""; }; 4BB06B211F316A3F00600C7A /* ForceInline.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ForceInline.h; sourceTree = ""; }; 4BB17D4C1ED7909F00ABD1E1 /* tests.expected.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = tests.expected.json; path = FUSE/tests.expected.json; sourceTree = ""; }; 4BB17D4D1ED7909F00ABD1E1 /* tests.in.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = tests.in.json; path = FUSE/tests.in.json; sourceTree = ""; }; @@ -1552,6 +1555,7 @@ 4B3F1B441E0388D200DB26EE /* PCMPatchedTrack.cpp */, 4B121F961E060CF000BFDA12 /* PCMSegment.cpp */, 4BAB62B61D3302CA00DF5BA0 /* PCMTrack.cpp */, + 4BAD9B941F43D7E900724854 /* UnformattedTrack.cpp */, 4B0BE4271D3481E700D5256B /* DigitalPhaseLockedLoop.hpp */, 4BAB62AC1D3272D200DF5BA0 /* Disk.hpp */, 4B6C73BC1D387AE500AFCFCA /* DiskController.hpp */, @@ -1560,6 +1564,7 @@ 4B3F1B451E0388D200DB26EE /* PCMPatchedTrack.hpp */, 4B121F971E060CF000BFDA12 /* PCMSegment.hpp */, 4BAB62B71D3302CA00DF5BA0 /* PCMTrack.hpp */, + 4BAD9B951F43D7E900724854 /* UnformattedTrack.hpp */, 4BB697CF1D4BA44900248BDF /* Encodings */, 4BAB62B21D327F7E00DF5BA0 /* Formats */, 4B3FE75F1F3CF6BA00448EE4 /* Parsers */, @@ -2709,6 +2714,7 @@ 4BD14B111D74627C0088EAD6 /* StaticAnalyser.cpp in Sources */, 4BBF99151C8FBA6F0075DAFB /* CRTOpenGL.cpp in Sources */, 4B95FA9D1F11893B0008E395 /* ZX8081OptionsPanel.swift in Sources */, + 4BAD9B961F43D7E900724854 /* UnformattedTrack.cpp in Sources */, 4B0CCC451C62D0B3001CAC5F /* CRT.cpp in Sources */, 4B8378DC1F336631005CA9E4 /* CharacterMapper.cpp in Sources */, 4B8378E51F3378C4005CA9E4 /* CharacterMapper.cpp in Sources */, diff --git a/Storage/Disk/Disk.cpp b/Storage/Disk/Disk.cpp index 406e99312..5844e1bea 100644 --- a/Storage/Disk/Disk.cpp +++ b/Storage/Disk/Disk.cpp @@ -28,6 +28,9 @@ void Disk::set_track_at_position(unsigned int head, unsigned int position, const } std::shared_ptr Disk::get_track_at_position(unsigned int head, unsigned int position) { + if(head >= get_head_count()) return nullptr; + if(position >= get_head_position_count()) return nullptr; + int address = get_id_for_track_at_position(head, position); std::map>::iterator cached_track = cached_tracks_.find(address); if(cached_track != cached_tracks_.end()) return cached_track->second; diff --git a/Storage/Disk/DiskController.cpp b/Storage/Disk/DiskController.cpp index cdee750b7..d90156816 100644 --- a/Storage/Disk/DiskController.cpp +++ b/Storage/Disk/DiskController.cpp @@ -7,6 +7,7 @@ // #include "DiskController.hpp" +#include "UnformattedTrack.hpp" #include "../../NumberTheory/Factors.hpp" #include @@ -30,15 +31,17 @@ Controller::Controller(Cycles clock_rate, int clock_rate_multiplier, int revolut void Controller::setup_track() { track_ = drive_->get_track(); + if(!track_) { + track_.reset(new UnformattedTrack); + } Time offset; Time track_time_now = get_time_into_track(); assert(track_time_now >= Time(0) && current_event_.length <= Time(1)); - if(track_) { - Time time_found = track_->seek_to(track_time_now); - assert(time_found >= Time(0) && time_found <= track_time_now); - offset = track_time_now - time_found; - } + + Time time_found = track_->seek_to(track_time_now); + assert(time_found >= Time(0) && time_found <= track_time_now); + offset = track_time_now - time_found; get_next_event(offset); } diff --git a/Storage/Disk/PCMPatchedTrack.hpp b/Storage/Disk/PCMPatchedTrack.hpp index 7d14adf30..842f16d0f 100644 --- a/Storage/Disk/PCMPatchedTrack.hpp +++ b/Storage/Disk/PCMPatchedTrack.hpp @@ -9,7 +9,7 @@ #ifndef PCMPatchedTrack_hpp #define PCMPatchedTrack_hpp -#include "PCMTrack.hpp" +#include "Disk.hpp" #include "PCMSegment.hpp" namespace Storage { diff --git a/Storage/Disk/UnformattedTrack.cpp b/Storage/Disk/UnformattedTrack.cpp new file mode 100644 index 000000000..b501bc8a0 --- /dev/null +++ b/Storage/Disk/UnformattedTrack.cpp @@ -0,0 +1,26 @@ +// +// UnformattedTrack.cpp +// Clock Signal +// +// Created by Thomas Harte on 15/08/2017. +// Copyright © 2017 Thomas Harte. All rights reserved. +// + +#include "UnformattedTrack.hpp" + +using namespace Storage::Disk; + +Track::Event UnformattedTrack::get_next_event() { + Track::Event event; + event.type = Event::IndexHole; + event.length = Time(1); + return event; +} + +Storage::Time UnformattedTrack::seek_to(const Time &time_since_index_hole) { + return Time(0); +} + +Track *UnformattedTrack::clone() { + return new UnformattedTrack; +} diff --git a/Storage/Disk/UnformattedTrack.hpp b/Storage/Disk/UnformattedTrack.hpp new file mode 100644 index 000000000..cdddbc8c1 --- /dev/null +++ b/Storage/Disk/UnformattedTrack.hpp @@ -0,0 +1,30 @@ +// +// UnformattedTrack.hpp +// Clock Signal +// +// Created by Thomas Harte on 15/08/2017. +// Copyright © 2017 Thomas Harte. All rights reserved. +// + +#ifndef UnformattedTrack_hpp +#define UnformattedTrack_hpp + +#include "Disk.hpp" + +namespace Storage { +namespace Disk { + +/*! + A subclass of @c Track with no contents. Just an index hole. +*/ +class UnformattedTrack: public Track { + public: + Event get_next_event(); + Time seek_to(const Time &time_since_index_hole); + Track *clone(); +}; + +} +} + +#endif /* UnformattedTrack_hpp */