mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-26 08:49:37 +00:00
Introduces a route from a PCMSegment
to a list of [M]FM sectors.
This commit is contained in:
parent
a8524daecb
commit
3982e375e3
@ -11,14 +11,17 @@
|
|||||||
|
|
||||||
using namespace Storage::Encodings::MFM;
|
using namespace Storage::Encodings::MFM;
|
||||||
|
|
||||||
std::map<Storage::Encodings::MFM::Sector::Address, Storage::Encodings::MFM::Sector> Storage::Encodings::MFM::SectorsFromSegment(const Storage::Disk::PCMSegment &&segment) {
|
std::map<size_t, Storage::Encodings::MFM::Sector> Storage::Encodings::MFM::SectorsFromSegment(const Storage::Disk::PCMSegment &&segment, bool is_double_density) {
|
||||||
std::map<Sector::Address, Sector> result;
|
std::map<size_t, Sector> result;
|
||||||
Shifter shifter;
|
Shifter shifter;
|
||||||
|
shifter.set_is_double_density(is_double_density);
|
||||||
|
shifter.set_should_obey_syncs(true);
|
||||||
|
|
||||||
std::unique_ptr<Storage::Encodings::MFM::Sector> new_sector;
|
std::unique_ptr<Storage::Encodings::MFM::Sector> new_sector;
|
||||||
bool is_reading = false;
|
bool is_reading = false;
|
||||||
size_t position = 0;
|
size_t position = 0;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
|
size_t start_location = 0;
|
||||||
|
|
||||||
for(unsigned int bit = 0; bit < segment.number_of_bits; ++bit) {
|
for(unsigned int bit = 0; bit < segment.number_of_bits; ++bit) {
|
||||||
shifter.add_input_bit(segment.bit(bit));
|
shifter.add_input_bit(segment.bit(bit));
|
||||||
@ -31,13 +34,16 @@ std::map<Storage::Encodings::MFM::Sector::Address, Storage::Encodings::MFM::Sect
|
|||||||
case Shifter::Token::ID:
|
case Shifter::Token::ID:
|
||||||
new_sector.reset(new Storage::Encodings::MFM::Sector);
|
new_sector.reset(new Storage::Encodings::MFM::Sector);
|
||||||
is_reading = true;
|
is_reading = true;
|
||||||
|
start_location = bit;
|
||||||
position = 0;
|
position = 0;
|
||||||
|
shifter.set_should_obey_syncs(false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Shifter::Token::Data:
|
case Shifter::Token::Data:
|
||||||
case Shifter::Token::DeletedData:
|
case Shifter::Token::DeletedData:
|
||||||
if(new_sector) {
|
if(new_sector) {
|
||||||
is_reading = true;
|
is_reading = true;
|
||||||
|
shifter.set_should_obey_syncs(false);
|
||||||
new_sector->is_deleted = (shifter.get_token() == Shifter::Token::DeletedData);
|
new_sector->is_deleted = (shifter.get_token() == Shifter::Token::DeletedData);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -53,13 +59,15 @@ std::map<Storage::Encodings::MFM::Sector::Address, Storage::Encodings::MFM::Sect
|
|||||||
size = (size_t)(128 << new_sector->size);
|
size = (size_t)(128 << new_sector->size);
|
||||||
++position;
|
++position;
|
||||||
is_reading = false;
|
is_reading = false;
|
||||||
|
shifter.set_should_obey_syncs(true);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
new_sector->data.push_back(shifter.get_byte());
|
new_sector->data.push_back(shifter.get_byte());
|
||||||
++position;
|
++position;
|
||||||
if(position == size + 4) {
|
if(position == size + 4) {
|
||||||
result.insert(std::make_pair(new_sector->address, std::move(*new_sector)));
|
result.insert(std::make_pair(start_location, std::move(*new_sector)));
|
||||||
is_reading = false;
|
is_reading = false;
|
||||||
|
shifter.set_should_obey_syncs(true);
|
||||||
new_sector.reset();
|
new_sector.reset();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -17,7 +17,11 @@ namespace Storage {
|
|||||||
namespace Encodings {
|
namespace Encodings {
|
||||||
namespace MFM {
|
namespace MFM {
|
||||||
|
|
||||||
std::map<Sector::Address, Sector> SectorsFromSegment(const Disk::PCMSegment &&segment);
|
/*!
|
||||||
|
Scans @c segment for all included sectors, returning a set that maps from location within
|
||||||
|
the segment (counted in bits from the beginning) to sector.
|
||||||
|
*/
|
||||||
|
std::map<size_t, Sector> SectorsFromSegment(const Disk::PCMSegment &&segment, bool is_double_density);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user