1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-01-13 07:30:21 +00:00

Gave disks their own namespace.

This commit is contained in:
Thomas Harte 2016-08-27 17:15:09 -04:00
parent c0402d0c2b
commit 56c0d70c1f
16 changed files with 47 additions and 34 deletions

View File

@ -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<Machine>::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

View File

@ -216,7 +216,7 @@ class Machine:
public CPU6502::Processor<Machine>,
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> _serialPort;
DriveVIA _driveVIA;
std::shared_ptr<Storage::Disk> _disk;
std::shared_ptr<Storage::Disk::Disk> _disk;
int _shift_register, _bit_window_offset;
virtual void process_input_bit(int value, unsigned int cycles_since_index_hole);

View File

@ -282,7 +282,7 @@ void Machine::tape_did_change_input(Tape *tape)
#pragma mark - Disc
void Machine::set_disk(std::shared_ptr<Storage::Disk> disk)
void Machine::set_disk(std::shared_ptr<Storage::Disk::Disk> disk)
{
// construct the 1540
_c1540.reset(new ::Commodore::C1540::Machine);

View File

@ -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<Storage::Tape::Tape> tape);
void set_disk(std::shared_ptr<Storage::Disk> disk);
void set_disk(std::shared_ptr<Storage::Disk::Disk> disk);
void set_key_state(Key key, bool isPressed) { _keyboardVIA->set_key_state(key, isPressed); }
void clear_all_keys() { _keyboardVIA->clear_all_keys(); }

View File

@ -59,21 +59,21 @@ using namespace Commodore::Vic20;
}
- (BOOL)openG64AtURL:(NSURL *)URL {
return [self openDisk:^std::shared_ptr<Storage::Disk>{
return std::shared_ptr<Storage::Disk>(new Storage::G64([URL fileSystemRepresentation]));
return [self openDisk:^std::shared_ptr<Storage::Disk::Disk>{
return std::shared_ptr<Storage::Disk::Disk>(new Storage::Disk::G64([URL fileSystemRepresentation]));
}];
}
- (BOOL)openD64AtURL:(NSURL *)URL {
return [self openDisk:^std::shared_ptr<Storage::Disk>{
return std::shared_ptr<Storage::Disk>(new Storage::D64([URL fileSystemRepresentation]));
return [self openDisk:^std::shared_ptr<Storage::Disk::Disk>{
return std::shared_ptr<Storage::Disk::Disk>(new Storage::Disk::D64([URL fileSystemRepresentation]));
}];
}
- (BOOL)openDisk:(std::shared_ptr<Storage::Disk> (^)())opener {
- (BOOL)openDisk:(std::shared_ptr<Storage::Disk::Disk> (^)())opener {
@synchronized(self) {
try {
std::shared_ptr<Storage::Disk> disk = opener();
std::shared_ptr<Storage::Disk::Disk> disk = opener();
_vic20.set_disk(disk);
return YES;
} catch(...) {

View File

@ -48,7 +48,7 @@ std::list<Target> 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<std::shared_ptr<Storage::Disk>> disks;
std::list<std::shared_ptr<Storage::Disk::Disk>> disks;
std::list<std::shared_ptr<Storage::Tape::Tape>> tapes;
TargetPlatformType potential_platforms = 0;
@ -71,8 +71,8 @@ std::list<Target> 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"))

View File

@ -52,7 +52,7 @@ struct Target {
} acorn;
} loadingMethod;
std::list<std::shared_ptr<Storage::Disk>> disks;
std::list<std::shared_ptr<Storage::Disk::Disk>> disks;
std::list<std::shared_ptr<Storage::Tape::Tape>> tapes;
// TODO: ROMs. Probably can't model as raw data, but then how to handle bus complexities?
};

View File

@ -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<Track> get_track_at_position(unsigned int position) = 0;
};
}
}
#endif /* Disk_hpp */

View File

@ -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> disk)
void Drive::set_disk(std::shared_ptr<Disk> 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);
}

View File

@ -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 */

View File

@ -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)
{

View File

@ -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 */

View File

@ -13,6 +13,7 @@
#include "../Encodings/CommodoreGCR.hpp"
using namespace Storage;
using namespace Disk;
G64::G64(const char *file_name)
{

View File

@ -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 */

View File

@ -9,7 +9,7 @@
#include "PCMTrack.hpp"
#include "../../NumberTheory/Factors.hpp"
using namespace Storage;
using namespace Storage::Disk;
PCMTrack::PCMTrack(std::vector<PCMSegment> 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;

View File

@ -13,6 +13,7 @@
#include <vector>
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 */