1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-04 18:29:40 +00:00

Worked on the all-around framework for decoding sectors back from tracks when closing down a file. Hit the wall that the parser is more observant of CRCs than the WD. No, really. So I guess I have to stop avoiding that whole issue.

This commit is contained in:
Thomas Harte 2016-12-26 14:24:33 -05:00
parent 83c433c142
commit 0490a47058
9 changed files with 62 additions and 8 deletions

View File

@ -535,7 +535,7 @@ void WD1770::posit_event(Event new_event_type)
}
if(distance_into_section_ == 7)
{
printf("Considering %d/%d at %0.4f\n", header_[0], header_[2], get_time_into_track().get_float());
printf("Considering %d/%d\n", header_[0], header_[2]);
is_reading_data_ = false;
if(header_[0] == track_ && header_[2] == sector_ &&
(has_motor_on_line() || !(command_&0x02) || ((command_&0x08) >> 3) == header_[1]))

View File

@ -66,6 +66,7 @@ class Track {
*/
class Disk {
public:
virtual ~Disk() {}
/*!
@returns the number of discrete positions that this disk uses to model its complete surface area.

View File

@ -110,7 +110,6 @@ class Controller: public DigitalPhaseLockedLoop::Delegate, public TimedEventLoop
void step(int direction);
virtual bool get_drive_is_ready();
bool get_drive_is_read_only();
Time get_time_into_track();
private:
Time bit_length_;
@ -136,6 +135,7 @@ class Controller: public DigitalPhaseLockedLoop::Delegate, public TimedEventLoop
Time cycles_per_bit_;
void setup_track();
Time get_time_into_track();
};
}

View File

@ -14,14 +14,21 @@ using namespace Storage::Disk;
Drive::Drive()
: head_position_(0), head_(0) {}
void Drive::set_disk(std::shared_ptr<Disk> disk)
void Drive::set_disk(const std::shared_ptr<Disk> &disk)
{
disk_ = disk;
track_ = nullptr;
}
void Drive::set_disk_with_track(const std::shared_ptr<Track> &track)
{
disk_ = nullptr;
track_ = track;
}
bool Drive::has_disk()
{
return (bool)disk_;
return (bool)disk_ || (bool)track_;
}
bool Drive::get_is_track_zero()
@ -42,12 +49,14 @@ void Drive::set_head(unsigned int head)
bool Drive::get_is_read_only()
{
if(disk_) return disk_->get_is_read_only();
if(track_) return true;
return false;
}
std::shared_ptr<Track> Drive::get_track()
{
if(disk_) return disk_->get_track_at_position(head_, (unsigned int)head_position_);
if(track_) return track_;
return nullptr;
}

View File

@ -20,9 +20,14 @@ class Drive {
Drive();
/*!
Inserts @c disk into the drive.
Replaces whatever is in the drive with @c disk.
*/
void set_disk(std::shared_ptr<Disk> disk);
void set_disk(const std::shared_ptr<Disk> &disk);
/*!
Replaces whatever is in the drive with a disk that contains endless copies of @c track.
*/
void set_disk_with_track(const std::shared_ptr<Track> &track);
/*!
@returns @c true if a disk is currently inserted; @c false otherwise.
@ -61,6 +66,7 @@ class Drive {
void set_track(const std::shared_ptr<Track> &track);
private:
std::shared_ptr<Track> track_;
std::shared_ptr<Disk> disk_;
int head_position_;
unsigned int head_;

View File

@ -214,7 +214,7 @@ std::unique_ptr<Encoder> Storage::Encodings::MFM::GetFMEncoder(std::vector<uint8
#pragma mark - Parser
Parser::Parser(bool is_mfm, const std::shared_ptr<Storage::Disk::Disk> &disk) :
Parser::Parser(bool is_mfm) :
Storage::Disk::Controller(4000000, 1, 300),
crc_generator_(0x1021, 0xffff),
shift_register_(0), track_(0), is_mfm_(is_mfm)
@ -225,11 +225,22 @@ Parser::Parser(bool is_mfm, const std::shared_ptr<Storage::Disk::Disk> &disk) :
set_expected_bit_length(bit_length);
drive.reset(new Storage::Disk::Drive);
drive->set_disk(disk);
set_drive(drive);
set_motor_on(true);
}
Parser::Parser(bool is_mfm, const std::shared_ptr<Storage::Disk::Disk> &disk) :
Parser(is_mfm)
{
drive->set_disk(disk);
}
Parser::Parser(bool is_mfm, const std::shared_ptr<Storage::Disk::Track> &track) :
Parser(is_mfm)
{
drive->set_disk_with_track(track);
}
std::shared_ptr<Storage::Encodings::MFM::Sector> Parser::get_sector(uint8_t track, uint8_t sector)
{
int difference = (int)track - (int)track_;

View File

@ -61,6 +61,7 @@ std::unique_ptr<Encoder> GetFMEncoder(std::vector<uint8_t> &target);
class Parser: public Storage::Disk::Controller {
public:
Parser(bool is_mfm, const std::shared_ptr<Storage::Disk::Disk> &disk);
Parser(bool is_mfm, const std::shared_ptr<Storage::Disk::Track> &track);
/*!
Attempts to read the sector located at @c track and @c sector.
@ -70,6 +71,8 @@ class Parser: public Storage::Disk::Controller {
std::shared_ptr<Storage::Encodings::MFM::Sector> get_sector(uint8_t track, uint8_t sector);
private:
Parser(bool is_mfm);
std::shared_ptr<Storage::Disk::Drive> drive;
unsigned int shift_register_;
int index_count_;

View File

@ -30,6 +30,29 @@ SSD::SSD(const char *file_name) :
else if(track_count_ < 80) track_count_ = 80;
}
SSD::~SSD()
{
if(get_is_modified())
{
for(unsigned int head = 0; head < head_count_; head++)
{
for(unsigned int track = 0; track < track_count_; track++)
{
std::shared_ptr<Storage::Disk::Track> modified_track = get_modified_track_at_position(head, track);
if(modified_track)
{
Storage::Encodings::MFM::Parser parser(false, modified_track);
for(unsigned int c = 0; c < 10; c++)
{
std::shared_ptr<Storage::Encodings::MFM::Sector> sector = parser.get_sector((uint8_t)track, (uint8_t)c);
printf("Sector %d: %p\n", c, sector.get());
}
}
}
}
}
}
unsigned int SSD::get_head_position_count()
{
return track_count_;

View File

@ -27,6 +27,7 @@ class SSD: public Disk, public Storage::FileHolder {
@throws ErrorNotSSD if the file doesn't appear to contain a .SSD format image.
*/
SSD(const char *file_name);
~SSD();
enum {
ErrorNotSSD,