mirror of
https://github.com/TomHarte/CLK.git
synced 2025-01-13 22:32:03 +00:00
Isolates those Sector
fields that describe its address and makes them usable as a set key.
This commit is contained in:
parent
c7f27b2db4
commit
3319a4f589
@ -67,9 +67,9 @@ std::shared_ptr<Track> AcornADF::get_track_at_position(unsigned int head, unsign
|
||||
|
||||
for(unsigned int sector = 0; sector < sectors_per_track; sector++) {
|
||||
Storage::Encodings::MFM::Sector new_sector;
|
||||
new_sector.track = (uint8_t)position;
|
||||
new_sector.side = (uint8_t)head;
|
||||
new_sector.sector = (uint8_t)sector;
|
||||
new_sector.address.track = (uint8_t)position;
|
||||
new_sector.address.side = (uint8_t)head;
|
||||
new_sector.address.sector = (uint8_t)sector;
|
||||
new_sector.size = sector_size;
|
||||
|
||||
new_sector.data.resize(bytes_per_sector);
|
||||
|
@ -114,9 +114,9 @@ std::shared_ptr<Track> CPCDSK::get_track_at_position(unsigned int head, unsigned
|
||||
std::vector<Storage::Encodings::MFM::Sector> sectors;
|
||||
for(auto §or_info : sector_infos) {
|
||||
Storage::Encodings::MFM::Sector new_sector;
|
||||
new_sector.track = sector_info.track;
|
||||
new_sector.side = sector_info.side;
|
||||
new_sector.sector = sector_info.sector;
|
||||
new_sector.address.track = sector_info.track;
|
||||
new_sector.address.side = sector_info.side;
|
||||
new_sector.address.sector = sector_info.sector;
|
||||
new_sector.size = sector_info.length;
|
||||
|
||||
size_t data_size;
|
||||
|
@ -57,9 +57,9 @@ std::shared_ptr<Track> SSD::get_track_at_position(unsigned int head, unsigned in
|
||||
|
||||
for(int sector = 0; sector < 10; sector++) {
|
||||
Storage::Encodings::MFM::Sector new_sector;
|
||||
new_sector.track = (uint8_t)position;
|
||||
new_sector.side = 0;
|
||||
new_sector.sector = (uint8_t)sector;
|
||||
new_sector.address.track = (uint8_t)position;
|
||||
new_sector.address.side = 0;
|
||||
new_sector.address.sector = (uint8_t)sector;
|
||||
new_sector.size = 1;
|
||||
|
||||
new_sector.data.resize(256);
|
||||
|
@ -143,9 +143,9 @@ template<class T> std::shared_ptr<Storage::Disk::Track>
|
||||
|
||||
// sector header
|
||||
shifter.add_ID_address_mark();
|
||||
shifter.add_byte(sector.track);
|
||||
shifter.add_byte(sector.side);
|
||||
shifter.add_byte(sector.sector);
|
||||
shifter.add_byte(sector.address.track);
|
||||
shifter.add_byte(sector.address.side);
|
||||
shifter.add_byte(sector.address.sector);
|
||||
shifter.add_byte(sector.size);
|
||||
shifter.add_crc(sector.has_header_crc_error);
|
||||
|
||||
|
@ -68,10 +68,10 @@ std::shared_ptr<Sector> Parser::get_sector(uint8_t head, uint8_t track, uint8_t
|
||||
while(1) {
|
||||
std::shared_ptr<Sector> next_sector = get_next_sector();
|
||||
if(next_sector) {
|
||||
if(visited_sectors.find(next_sector->sector) != visited_sectors.end()) {
|
||||
if(visited_sectors.find(next_sector->address.sector) != visited_sectors.end()) {
|
||||
break;
|
||||
}
|
||||
visited_sectors.insert(next_sector->sector);
|
||||
visited_sectors.insert(next_sector->address.sector);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -242,9 +242,9 @@ std::shared_ptr<Sector> Parser::get_next_sector() {
|
||||
}
|
||||
|
||||
crc_generator_.add(IDAddressByte);
|
||||
sector->track = get_next_byte();
|
||||
sector->side = get_next_byte();
|
||||
sector->sector = get_next_byte();
|
||||
sector->address.track = get_next_byte();
|
||||
sector->address.side = get_next_byte();
|
||||
sector->address.sector = get_next_byte();
|
||||
sector->size = get_next_byte();
|
||||
uint16_t header_crc = crc_generator_.get_value();
|
||||
if((header_crc >> 8) != get_next_byte()) sector->has_header_crc_error = true;
|
||||
@ -285,7 +285,7 @@ std::shared_ptr<Sector> Parser::get_next_sector() {
|
||||
if((data_crc & 0xff) != get_next_byte()) sector->has_data_crc_error = true;
|
||||
|
||||
// Put this sector into the cache.
|
||||
int index = get_index(head_, track_, sector->sector);
|
||||
int index = get_index(head_, track_, sector->address.sector);
|
||||
sectors_by_index_[index] = sector;
|
||||
|
||||
return sector;
|
||||
@ -299,13 +299,13 @@ std::shared_ptr<Sector> Parser::get_sector(uint8_t sector) {
|
||||
index_count_ = 0;
|
||||
while(!first_sector && index_count_ < 2) first_sector = get_next_sector();
|
||||
if(!first_sector) return nullptr;
|
||||
if(first_sector->sector == sector) return first_sector;
|
||||
if(first_sector->address.sector == sector) return first_sector;
|
||||
|
||||
while(1) {
|
||||
std::shared_ptr<Sector> next_sector = get_next_sector();
|
||||
if(!next_sector) continue;
|
||||
if(next_sector->sector == first_sector->sector) return nullptr;
|
||||
if(next_sector->sector == sector) return next_sector;
|
||||
if(next_sector->address.sector == first_sector->address.sector) return nullptr;
|
||||
if(next_sector->address.sector == sector) return next_sector;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,14 +21,24 @@ namespace MFM {
|
||||
and a few extra flags of metadata.
|
||||
*/
|
||||
struct Sector {
|
||||
uint8_t track, side, sector, size;
|
||||
/*!
|
||||
Describes the location of a sector, implementing < to allow for use as a set key.
|
||||
*/
|
||||
struct Address {
|
||||
uint8_t track = 0, side = 0, sector = 0;
|
||||
|
||||
bool operator < (Address &rhs) {
|
||||
return ((track << 24) | (side << 8) | sector) < ((rhs.track << 24) | (rhs.side << 8) | rhs.sector);
|
||||
}
|
||||
};
|
||||
|
||||
Address address;
|
||||
uint8_t size = 0;
|
||||
std::vector<uint8_t> data;
|
||||
|
||||
bool has_data_crc_error;
|
||||
bool has_header_crc_error;
|
||||
bool is_deleted;
|
||||
|
||||
Sector() : track(0), side(0), sector(0), size(0), has_data_crc_error(false), has_header_crc_error(false), is_deleted(false) {}
|
||||
bool has_data_crc_error = false;
|
||||
bool has_header_crc_error = false;
|
||||
bool is_deleted = false;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user