2016-09-18 23:21:02 +00:00
|
|
|
//
|
|
|
|
// SSD.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 18/09/2016.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2016 Thomas Harte. All rights reserved.
|
2016-09-18 23:21:02 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "SSD.hpp"
|
|
|
|
|
2017-09-30 02:07:23 +00:00
|
|
|
namespace {
|
2019-12-22 05:22:17 +00:00
|
|
|
constexpr int sectors_per_track = 10;
|
|
|
|
constexpr int sector_size = 1;
|
2017-09-30 02:07:23 +00:00
|
|
|
}
|
2016-09-18 23:21:02 +00:00
|
|
|
|
|
|
|
using namespace Storage::Disk;
|
|
|
|
|
2018-04-06 21:42:24 +00:00
|
|
|
SSD::SSD(const std::string &file_name) : MFMSectorDump(file_name) {
|
2016-09-18 23:21:02 +00:00
|
|
|
// very loose validation: the file needs to be a multiple of 256 bytes
|
|
|
|
// and not ungainly large
|
|
|
|
|
2018-04-28 03:18:45 +00:00
|
|
|
if(file_.stats().st_size & 255) throw Error::InvalidFormat;
|
|
|
|
if(file_.stats().st_size < 512) throw Error::InvalidFormat;
|
|
|
|
if(file_.stats().st_size > 800*256) throw Error::InvalidFormat;
|
2016-09-18 23:32:08 +00:00
|
|
|
|
|
|
|
// this has two heads if the suffix is .dsd, one if it's .ssd
|
2018-04-06 21:42:24 +00:00
|
|
|
head_count_ = (tolower(file_name[file_name.size() - 3]) == 'd') ? 2 : 1;
|
2019-11-13 04:22:56 +00:00
|
|
|
track_count_ = int(file_.stats().st_size / (256 * 10 * head_count_));
|
2016-11-21 12:14:09 +00:00
|
|
|
if(track_count_ < 40) track_count_ = 40;
|
|
|
|
else if(track_count_ < 80) track_count_ = 80;
|
2017-10-01 00:30:15 +00:00
|
|
|
|
2018-01-08 02:59:18 +00:00
|
|
|
set_geometry(sectors_per_track, sector_size, 0, false);
|
2016-09-18 23:21:02 +00:00
|
|
|
}
|
|
|
|
|
2018-05-07 03:17:36 +00:00
|
|
|
HeadPosition SSD::get_maximum_head_position() {
|
|
|
|
return HeadPosition(track_count_);
|
2016-09-18 23:21:02 +00:00
|
|
|
}
|
|
|
|
|
2017-10-07 01:45:12 +00:00
|
|
|
int SSD::get_head_count() {
|
2016-11-21 12:14:09 +00:00
|
|
|
return head_count_;
|
2016-09-18 23:21:02 +00:00
|
|
|
}
|
|
|
|
|
2017-10-07 01:45:12 +00:00
|
|
|
long SSD::get_file_offset_for_position(Track::Address address) {
|
2018-05-07 03:17:36 +00:00
|
|
|
return (address.position.as_int() * head_count_ + address.head) * 256 * 10;
|
2016-12-30 03:15:58 +00:00
|
|
|
}
|