mirror of
https://github.com/TomHarte/CLK.git
synced 2024-12-11 15:49:38 +00:00
Eliminate std::shared_ptr outside of DiskImageHolder.
This commit is contained in:
parent
657960e7d0
commit
7cc6f8604e
@ -67,7 +67,7 @@ Analyser::Static::TargetList Analyser::Static::DiskII::GetTargets(
|
||||
|
||||
// Grab track 0, sector 0: the boot sector.
|
||||
const auto track_zero =
|
||||
disk->get_track_at_position(Storage::Disk::Track::Address(0, Storage::Disk::HeadPosition(0)));
|
||||
disk->track_at_position(Storage::Disk::Track::Address(0, Storage::Disk::HeadPosition(0)));
|
||||
const auto sector_map = Storage::Encodings::AppleGCR::sectors_from_segment(
|
||||
Storage::Disk::track_serialisation(*track_zero, Storage::Time(1, 50000)));
|
||||
|
||||
|
@ -44,7 +44,7 @@ Analyser::Static::TargetList Analyser::Static::FAT12::GetTargets(
|
||||
|
||||
// Attempt to grab MFM track 0, sector 1: the boot sector.
|
||||
const auto track_zero =
|
||||
disk->get_track_at_position(Storage::Disk::Track::Address(0, Storage::Disk::HeadPosition(0)));
|
||||
disk->track_at_position(Storage::Disk::Track::Address(0, Storage::Disk::HeadPosition(0)));
|
||||
const auto sector_map = Storage::Encodings::MFM::sectors_from_segment(
|
||||
Storage::Disk::track_serialisation(
|
||||
*track_zero,
|
||||
|
@ -24,8 +24,8 @@
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = ""
|
||||
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
disableMainThreadChecker = "YES"
|
||||
codeCoverageEnabled = "YES">
|
||||
|
@ -43,12 +43,12 @@ public:
|
||||
@returns the @c Track at @c position underneath @c head if there are any detectable events there;
|
||||
returns @c nullptr otherwise.
|
||||
*/
|
||||
virtual std::shared_ptr<Track> get_track_at_position(Track::Address address) = 0;
|
||||
virtual Track *track_at_position(Track::Address) = 0;
|
||||
|
||||
/*!
|
||||
Replaces the Track at position @c position underneath @c head with @c track. Ignored if this disk is read-only.
|
||||
*/
|
||||
virtual void set_track_at_position(Track::Address address, const std::shared_ptr<Track> &track) = 0;
|
||||
virtual void set_track_at_position(Track::Address, const std::shared_ptr<Track> &) = 0;
|
||||
|
||||
/*!
|
||||
Provides a hint that no further tracks are likely to be written for a while.
|
||||
|
@ -103,7 +103,7 @@ public:
|
||||
|
||||
HeadPosition get_maximum_head_position();
|
||||
int get_head_count();
|
||||
std::shared_ptr<Track> get_track_at_position(Track::Address address);
|
||||
Track *track_at_position(Track::Address address);
|
||||
void set_track_at_position(Track::Address address, const std::shared_ptr<Track> &track);
|
||||
void flush_tracks();
|
||||
bool get_is_read_only();
|
||||
|
@ -42,18 +42,18 @@ template <typename T> void DiskImageHolder<T>::set_track_at_position(Track::Addr
|
||||
cached_tracks_[address] = track;
|
||||
}
|
||||
|
||||
template <typename T> std::shared_ptr<Track> DiskImageHolder<T>::get_track_at_position(Track::Address address) {
|
||||
template <typename T> Track *DiskImageHolder<T>::track_at_position(Track::Address address) {
|
||||
if(address.head >= get_head_count()) return nullptr;
|
||||
if(address.position >= get_maximum_head_position()) return nullptr;
|
||||
|
||||
const auto canonical_address = disk_image_.canonical_address(address);
|
||||
auto cached_track = cached_tracks_.find(canonical_address);
|
||||
if(cached_track != cached_tracks_.end()) return cached_track->second;
|
||||
if(cached_track != cached_tracks_.end()) return cached_track->second.get();
|
||||
|
||||
std::shared_ptr<Track> track = disk_image_.track_at_position(canonical_address);
|
||||
if(!track) return nullptr;
|
||||
cached_tracks_[canonical_address] = track;
|
||||
return track;
|
||||
return track.get();
|
||||
}
|
||||
|
||||
template <typename T> DiskImageHolder<T>::~DiskImageHolder() {
|
||||
|
@ -8,8 +8,6 @@
|
||||
|
||||
#include "Drive.hpp"
|
||||
|
||||
#include "Track/UnformattedTrack.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
@ -107,7 +105,7 @@ void Drive::step(HeadPosition offset) {
|
||||
did_step(head_position_);
|
||||
}
|
||||
|
||||
std::shared_ptr<Track> Drive::step_to(HeadPosition offset) {
|
||||
Track *Drive::step_to(HeadPosition offset) {
|
||||
HeadPosition old_head_position = head_position_;
|
||||
head_position_ = std::max(offset, HeadPosition(0));
|
||||
|
||||
@ -343,8 +341,8 @@ void Drive::process_next_event() {
|
||||
|
||||
// MARK: - Track management
|
||||
|
||||
std::shared_ptr<Track> Drive::get_track() {
|
||||
if(disk_) return disk_->get_track_at_position(Track::Address(head_, head_position_));
|
||||
Track *Drive::get_track() {
|
||||
if(disk_) return disk_->track_at_position(Track::Address(head_, head_position_));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -355,7 +353,7 @@ void Drive::set_track(const std::shared_ptr<Track> &track) {
|
||||
void Drive::setup_track() {
|
||||
track_ = get_track();
|
||||
if(!track_) {
|
||||
track_ = std::make_shared<UnformattedTrack>();
|
||||
track_ = &unformatted_track_;
|
||||
}
|
||||
|
||||
float offset = 0.0f;
|
||||
@ -426,11 +424,11 @@ void Drive::end_writing() {
|
||||
|
||||
if(!patched_track_) {
|
||||
// Avoid creating a new patched track if this one is already patched
|
||||
patched_track_ = std::dynamic_pointer_cast<PCMTrack>(track_);
|
||||
if(!patched_track_ || !patched_track_->is_resampled_clone()) {
|
||||
Track *const tr = track_.get();
|
||||
// patched_track_ = dynamic_cast<PCMTrack *>(track_);
|
||||
// if(!patched_track_ || !patched_track_->is_resampled_clone()) {
|
||||
Track *const tr = track_;
|
||||
patched_track_.reset(PCMTrack::resampled_clone(tr, high_resolution_track_rate));
|
||||
}
|
||||
// }
|
||||
}
|
||||
patched_track_->add_segment(write_start_time_, write_segment_, clamp_writing_to_index_hole_);
|
||||
cycles_since_index_hole_ %= cycles_per_revolution_;
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "Disk.hpp"
|
||||
#include "Track/PCMSegment.hpp"
|
||||
#include "Track/PCMTrack.hpp"
|
||||
#include "Track/UnformattedTrack.hpp"
|
||||
|
||||
#include "../TimedEventLoop.hpp"
|
||||
#include "../../Activity/Observer.hpp"
|
||||
@ -174,7 +175,7 @@ public:
|
||||
|
||||
It's for the benefit of user-optional fast-loading mechanisms **ONLY**.
|
||||
*/
|
||||
std::shared_ptr<Track> step_to(HeadPosition offset);
|
||||
Track *step_to(HeadPosition offset);
|
||||
|
||||
/*!
|
||||
Alters the rotational velocity of this drive.
|
||||
@ -209,7 +210,8 @@ private:
|
||||
// Drives contain an entire disk; from that a certain track
|
||||
// will be currently under the head.
|
||||
std::shared_ptr<Disk> disk_;
|
||||
std::shared_ptr<Track> track_;
|
||||
UnformattedTrack unformatted_track_;
|
||||
Track *track_ = nullptr;
|
||||
bool has_disk_ = false;
|
||||
|
||||
// Contains the multiplier that converts between track-relative lengths
|
||||
@ -274,7 +276,7 @@ private:
|
||||
/*!
|
||||
@returns the track underneath the current head at the location now stepped to.
|
||||
*/
|
||||
std::shared_ptr<Track> get_track();
|
||||
Track *get_track();
|
||||
|
||||
/*!
|
||||
Attempts to set @c track as the track underneath the current head at the location now stepped to.
|
||||
|
@ -25,7 +25,7 @@ void Parser::install_track(const Storage::Disk::Track::Address &address) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto track = disk_->get_track_at_position(address);
|
||||
const auto track = disk_->track_at_position(address);
|
||||
if(!track) {
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user