From 56c0d70c1fc82c5375635337f12f76172a1f8c6c Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 27 Aug 2016 17:15:09 -0400 Subject: [PATCH] Gave disks their own namespace. --- Machines/Commodore/1540/C1540.cpp | 4 ++-- Machines/Commodore/1540/C1540.hpp | 4 ++-- Machines/Commodore/Vic-20/Vic20.cpp | 2 +- Machines/Commodore/Vic-20/Vic20.hpp | 2 +- .../Clock Signal/Machine/Wrappers/CSVic20.mm | 12 +++++----- StaticAnalyser/StaticAnalyser.cpp | 6 ++--- StaticAnalyser/StaticAnalyser.hpp | 2 +- Storage/Disk/Disk.hpp | 2 ++ Storage/Disk/DiskDrive.cpp | 23 ++++++++++--------- Storage/Disk/DiskDrive.hpp | 6 +++-- Storage/Disk/Formats/D64.cpp | 2 +- Storage/Disk/Formats/D64.hpp | 5 +++- Storage/Disk/Formats/G64.cpp | 1 + Storage/Disk/Formats/G64.hpp | 4 +++- Storage/Disk/PCMTrack.cpp | 4 ++-- Storage/Disk/PCMTrack.hpp | 2 ++ 16 files changed, 47 insertions(+), 34 deletions(-) diff --git a/Machines/Commodore/1540/C1540.cpp b/Machines/Commodore/1540/C1540.cpp index d4a45dff7..2756ad058 100644 --- a/Machines/Commodore/1540/C1540.cpp +++ b/Machines/Commodore/1540/C1540.cpp @@ -14,7 +14,7 @@ using namespace Commodore::C1540; Machine::Machine() : _shift_register(0), - Storage::DiskDrive(1000000, 4, 300) + Storage::Disk::Drive(1000000, 4, 300) { // create a serial port and a VIA to run it _serialPortVIA.reset(new SerialPortVIA); @@ -106,7 +106,7 @@ void Machine::run_for_cycles(int number_of_cycles) { CPU6502::Processor::run_for_cycles(number_of_cycles); if(_driveVIA.get_motor_enabled()) // TODO: motor speed up/down - Storage::DiskDrive::run_for_cycles(number_of_cycles); + Storage::Disk::Drive::run_for_cycles(number_of_cycles); } #pragma mark - 6522 delegate diff --git a/Machines/Commodore/1540/C1540.hpp b/Machines/Commodore/1540/C1540.hpp index f052ea7bc..7a1b5e0e4 100644 --- a/Machines/Commodore/1540/C1540.hpp +++ b/Machines/Commodore/1540/C1540.hpp @@ -216,7 +216,7 @@ class Machine: public CPU6502::Processor, public MOS::MOS6522IRQDelegate::Delegate, public DriveVIA::Delegate, - public Storage::DiskDrive { + public Storage::Disk::Drive { public: Machine(); @@ -251,7 +251,7 @@ class Machine: std::shared_ptr _serialPort; DriveVIA _driveVIA; - std::shared_ptr _disk; + std::shared_ptr _disk; int _shift_register, _bit_window_offset; virtual void process_input_bit(int value, unsigned int cycles_since_index_hole); diff --git a/Machines/Commodore/Vic-20/Vic20.cpp b/Machines/Commodore/Vic-20/Vic20.cpp index 5b8f61de4..e1a7b993c 100644 --- a/Machines/Commodore/Vic-20/Vic20.cpp +++ b/Machines/Commodore/Vic-20/Vic20.cpp @@ -282,7 +282,7 @@ void Machine::tape_did_change_input(Tape *tape) #pragma mark - Disc -void Machine::set_disk(std::shared_ptr disk) +void Machine::set_disk(std::shared_ptr disk) { // construct the 1540 _c1540.reset(new ::Commodore::C1540::Machine); diff --git a/Machines/Commodore/Vic-20/Vic20.hpp b/Machines/Commodore/Vic-20/Vic20.hpp index 5ab24cc98..59fec787b 100644 --- a/Machines/Commodore/Vic-20/Vic20.hpp +++ b/Machines/Commodore/Vic-20/Vic20.hpp @@ -262,7 +262,7 @@ class Machine: void set_rom(ROMSlot slot, size_t length, const uint8_t *data); void set_prg(const char *file_name, size_t length, const uint8_t *data); void set_tape(std::shared_ptr tape); - void set_disk(std::shared_ptr disk); + void set_disk(std::shared_ptr disk); void set_key_state(Key key, bool isPressed) { _keyboardVIA->set_key_state(key, isPressed); } void clear_all_keys() { _keyboardVIA->clear_all_keys(); } diff --git a/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.mm b/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.mm index 720f41509..7198aafe7 100644 --- a/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.mm +++ b/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.mm @@ -59,21 +59,21 @@ using namespace Commodore::Vic20; } - (BOOL)openG64AtURL:(NSURL *)URL { - return [self openDisk:^std::shared_ptr{ - return std::shared_ptr(new Storage::G64([URL fileSystemRepresentation])); + return [self openDisk:^std::shared_ptr{ + return std::shared_ptr(new Storage::Disk::G64([URL fileSystemRepresentation])); }]; } - (BOOL)openD64AtURL:(NSURL *)URL { - return [self openDisk:^std::shared_ptr{ - return std::shared_ptr(new Storage::D64([URL fileSystemRepresentation])); + return [self openDisk:^std::shared_ptr{ + return std::shared_ptr(new Storage::Disk::D64([URL fileSystemRepresentation])); }]; } -- (BOOL)openDisk:(std::shared_ptr (^)())opener { +- (BOOL)openDisk:(std::shared_ptr (^)())opener { @synchronized(self) { try { - std::shared_ptr disk = opener(); + std::shared_ptr disk = opener(); _vic20.set_disk(disk); return YES; } catch(...) { diff --git a/StaticAnalyser/StaticAnalyser.cpp b/StaticAnalyser/StaticAnalyser.cpp index 526764f13..6755343de 100644 --- a/StaticAnalyser/StaticAnalyser.cpp +++ b/StaticAnalyser/StaticAnalyser.cpp @@ -48,7 +48,7 @@ std::list StaticAnalyser::GetTargets(const char *file_name) // Collect all disks, tapes and ROMs as can be extrapolated from this file, forming the // union of all platforms this file might be a target for. - std::list> disks; + std::list> disks; std::list> tapes; TargetPlatformType potential_platforms = 0; @@ -71,8 +71,8 @@ std::list StaticAnalyser::GetTargets(const char *file_name) { } - Format("d64", disks, D64, TargetPlatform::Commodore) // D64 - Format("g64", disks, G64, TargetPlatform::Commodore) // G64 + Format("d64", disks, Disk::D64, TargetPlatform::Commodore) // D64 + Format("g64", disks, Disk::G64, TargetPlatform::Commodore) // G64 // PRG if(!strcmp(lowercase_extension, "prg")) diff --git a/StaticAnalyser/StaticAnalyser.hpp b/StaticAnalyser/StaticAnalyser.hpp index 0a9785413..f229128b1 100644 --- a/StaticAnalyser/StaticAnalyser.hpp +++ b/StaticAnalyser/StaticAnalyser.hpp @@ -52,7 +52,7 @@ struct Target { } acorn; } loadingMethod; - std::list> disks; + std::list> disks; std::list> tapes; // TODO: ROMs. Probably can't model as raw data, but then how to handle bus complexities? }; diff --git a/Storage/Disk/Disk.hpp b/Storage/Disk/Disk.hpp index 08e3ee607..c17712b85 100644 --- a/Storage/Disk/Disk.hpp +++ b/Storage/Disk/Disk.hpp @@ -13,6 +13,7 @@ #include "../Storage.hpp" namespace Storage { +namespace Disk { /*! Models a single track on a disk as a series of events, each event being of arbitrary length @@ -78,6 +79,7 @@ class Disk { virtual std::shared_ptr get_track_at_position(unsigned int position) = 0; }; +} } #endif /* Disk_hpp */ diff --git a/Storage/Disk/DiskDrive.cpp b/Storage/Disk/DiskDrive.cpp index 3492a5bcb..c9953b40c 100644 --- a/Storage/Disk/DiskDrive.cpp +++ b/Storage/Disk/DiskDrive.cpp @@ -9,8 +9,9 @@ #include "DiskDrive.hpp" using namespace Storage; +using namespace Disk; -DiskDrive::DiskDrive(unsigned int clock_rate, unsigned int clock_rate_multiplier, unsigned int revolutions_per_minute) : +Drive::Drive(unsigned int clock_rate, unsigned int clock_rate_multiplier, unsigned int revolutions_per_minute) : _clock_rate(clock_rate * clock_rate_multiplier), _clock_rate_multiplier(clock_rate_multiplier), _head_position(0), @@ -22,7 +23,7 @@ DiskDrive::DiskDrive(unsigned int clock_rate, unsigned int clock_rate_multiplier _rotational_multiplier.simplify(); } -void DiskDrive::set_expected_bit_length(Time bit_length) +void Drive::set_expected_bit_length(Time bit_length) { _bit_length = bit_length; @@ -33,23 +34,23 @@ void DiskDrive::set_expected_bit_length(Time bit_length) _pll->set_delegate(this); } -void DiskDrive::set_disk(std::shared_ptr disk) +void Drive::set_disk(std::shared_ptr disk) { _disk = disk; set_track(Time()); } -bool DiskDrive::has_disk() +bool Drive::has_disk() { return (bool)_disk; } -bool DiskDrive::get_is_track_zero() +bool Drive::get_is_track_zero() { return _head_position == 0; } -void DiskDrive::step(int direction) +void Drive::step(int direction) { _head_position = std::max(_head_position + direction, 0); Time extra_time = get_time_into_next_event() / _rotational_multiplier; @@ -58,7 +59,7 @@ void DiskDrive::step(int direction) set_track(_time_into_track); } -void DiskDrive::set_track(Time initial_offset) +void Drive::set_track(Time initial_offset) { _track = _disk->get_track_at_position((unsigned int)_head_position); // TODO: probably a better implementation of the empty track? @@ -80,7 +81,7 @@ void DiskDrive::set_track(Time initial_offset) reset_timer_to_offset(offset * _rotational_multiplier); } -void DiskDrive::run_for_cycles(int number_of_cycles) +void Drive::run_for_cycles(int number_of_cycles) { if(has_disk()) { @@ -96,7 +97,7 @@ void DiskDrive::run_for_cycles(int number_of_cycles) #pragma mark - Track timed event loop -void DiskDrive::get_next_event() +void Drive::get_next_event() { if(_track) _current_event = _track->get_next_event(); @@ -112,7 +113,7 @@ void DiskDrive::get_next_event() set_next_event_time_interval(_current_event.length * _rotational_multiplier); } -void DiskDrive::process_next_event() +void Drive::process_next_event() { switch(_current_event.type) { @@ -131,7 +132,7 @@ void DiskDrive::process_next_event() #pragma mark - PLL delegate -void DiskDrive::digital_phase_locked_loop_output_bit(int value) +void Drive::digital_phase_locked_loop_output_bit(int value) { process_input_bit(value, _cycles_since_index_hole); } diff --git a/Storage/Disk/DiskDrive.hpp b/Storage/Disk/DiskDrive.hpp index 216a1626b..017e34464 100644 --- a/Storage/Disk/DiskDrive.hpp +++ b/Storage/Disk/DiskDrive.hpp @@ -14,6 +14,7 @@ #include "../TimedEventLoop.hpp" namespace Storage { +namespace Disk { /*! Provides the shell for emulating a disk drive — something that takes a disk and has a drive head @@ -26,13 +27,13 @@ namespace Storage { TODO: double sided disks, communication of head size and permissible stepping extents, appropriate simulation of gain. */ -class DiskDrive: public DigitalPhaseLockedLoop::Delegate, public TimedEventLoop { +class Drive: public DigitalPhaseLockedLoop::Delegate, public TimedEventLoop { public: /*! Constructs a @c DiskDrive that will be run at @c clock_rate and runs its PLL at @c clock_rate*clock_rate_multiplier, spinning inserted disks at @c revolutions_per_minute. */ - DiskDrive(unsigned int clock_rate, unsigned int clock_rate_multiplier, unsigned int revolutions_per_minute); + Drive(unsigned int clock_rate, unsigned int clock_rate_multiplier, unsigned int revolutions_per_minute); /*! Communicates to the PLL the expected length of a bit. @@ -106,6 +107,7 @@ class DiskDrive: public DigitalPhaseLockedLoop::Delegate, public TimedEventLoop Time _time_into_track; }; +} } #endif /* DiskDrive_hpp */ diff --git a/Storage/Disk/Formats/D64.cpp b/Storage/Disk/Formats/D64.cpp index 38765eb50..4bba3eb5a 100644 --- a/Storage/Disk/Formats/D64.cpp +++ b/Storage/Disk/Formats/D64.cpp @@ -13,7 +13,7 @@ #include "../PCMTrack.hpp" #include "../../../Storage/Disk/Encodings/CommodoreGCR.hpp" -using namespace Storage; +using namespace Storage::Disk; D64::D64(const char *file_name) { diff --git a/Storage/Disk/Formats/D64.hpp b/Storage/Disk/Formats/D64.hpp index eefc32f80..93c4d4cb5 100644 --- a/Storage/Disk/Formats/D64.hpp +++ b/Storage/Disk/Formats/D64.hpp @@ -12,6 +12,7 @@ #include "../Disk.hpp" namespace Storage { +namespace Disk { /*! Provies a @c Disk containing a D64 disk image — a decoded sector dump of a C1540-format disk. @@ -42,5 +43,7 @@ class D64: public Disk { uint16_t _disk_id; }; -}; +} +} + #endif /* D64_hpp */ diff --git a/Storage/Disk/Formats/G64.cpp b/Storage/Disk/Formats/G64.cpp index 475537929..3403e0188 100644 --- a/Storage/Disk/Formats/G64.cpp +++ b/Storage/Disk/Formats/G64.cpp @@ -13,6 +13,7 @@ #include "../Encodings/CommodoreGCR.hpp" using namespace Storage; +using namespace Disk; G64::G64(const char *file_name) { diff --git a/Storage/Disk/Formats/G64.hpp b/Storage/Disk/Formats/G64.hpp index 957c83c42..82ab9ae97 100644 --- a/Storage/Disk/Formats/G64.hpp +++ b/Storage/Disk/Formats/G64.hpp @@ -12,6 +12,7 @@ #include "../Disk.hpp" namespace Storage { +namespace Disk { /*! Provies a @c Disk containing a G64 disk image — a raw but perfectly-clocked GCR stream. @@ -45,6 +46,7 @@ class G64: public Disk { uint16_t _maximum_track_size; }; -}; +} +} #endif /* G64_hpp */ diff --git a/Storage/Disk/PCMTrack.cpp b/Storage/Disk/PCMTrack.cpp index 2a8d53f56..a655ab969 100644 --- a/Storage/Disk/PCMTrack.cpp +++ b/Storage/Disk/PCMTrack.cpp @@ -9,7 +9,7 @@ #include "PCMTrack.hpp" #include "../../NumberTheory/Factors.hpp" -using namespace Storage; +using namespace Storage::Disk; PCMTrack::PCMTrack(std::vector segments) { @@ -61,7 +61,7 @@ PCMTrack::Event PCMTrack::get_next_event() return _next_event; } -Time PCMTrack::seek_to(Time time_since_index_hole) +Storage::Time PCMTrack::seek_to(Time time_since_index_hole) { _segment_pointer = 0; diff --git a/Storage/Disk/PCMTrack.hpp b/Storage/Disk/PCMTrack.hpp index 99e426281..751473ef5 100644 --- a/Storage/Disk/PCMTrack.hpp +++ b/Storage/Disk/PCMTrack.hpp @@ -13,6 +13,7 @@ #include namespace Storage { +namespace Disk { /*! A segment of PCM-sampled data. @@ -68,6 +69,7 @@ class PCMTrack: public Track { size_t _bit_pointer; }; +} } #endif /* PCMTrack_hpp */