update in skewsettings

This commit is contained in:
wybren1971
2022-06-09 23:26:28 +02:00
parent c4d72d3c11
commit c6fd31564d

View File

@@ -49,7 +49,7 @@ static unsigned getModulationandSpeed(uint8_t flags, bool *fm)
break; break;
default: default:
Error() << fmt::format("don't understand IMD disks with this modulation and speed {}", flags); Error() << fmt::format("IMD: don't understand IMD disks with this modulation and speed {}", flags);
throw 0; throw 0;
} }
} }
@@ -63,20 +63,23 @@ struct TrackHeader
uint8_t SectorSize; uint8_t SectorSize;
}; };
static std::string copytostring(std::vector<char> tocopy) // static std::string copytostring(std::vector<unsigned char> tocopy)
{ // {
std::string result; // std::string result;
for (int i = 0; i< tocopy.size(); i++) // for (int i = 0; i< tocopy.size(); i++)
{ // {
result.push_back(tocopy[i]); // result.push_back(tocopy[i]);
} // // Logger() << "IMD DEBUG: sector map:" << fmt::format("{}", tocopy[i]);
return result;
} // }
// Logger() << "IMD DEBUG: sector map:" << fmt::format("{}", result);
// return result;
// }
static uint8_t setsectorskew(int sectornumber) static uint8_t setsectorskew(int sectornumber)
{//IMD lets the sector map start with 1 so everything we read in the sectormap has to be 1 less for fluxengine {//IMD lets the sector map start with 1 so everything we read in the sectormap has to be 1 less for fluxengine
sectornumber--;
switch (sectornumber) switch (sectornumber)
{ {
case 0: case 0:
@@ -133,8 +136,11 @@ static uint8_t setsectorskew(int sectornumber)
case 17: case 17:
return 'h'; return 'h';
break; break;
case 18:
return 'i';
break;
} }
Error() << fmt::format("Sector skew {} not in standard range (0-17).", sectornumber); Error() << fmt::format("IMD: Sector skew {} not in standard range (0-17).", sectornumber);
} }
static unsigned getSectorSize(uint8_t flags) static unsigned getSectorSize(uint8_t flags)
@@ -187,7 +193,7 @@ public:
//Read File //Read File
std::ifstream inputFile(_config.filename(), std::ios::in | std::ios::binary); std::ifstream inputFile(_config.filename(), std::ios::in | std::ios::binary);
if (!inputFile.is_open()) if (!inputFile.is_open())
Error() << "cannot open input file"; Error() << "IMD: cannot open input file";
//define some variables //define some variables
bool fm = false; //define coding just to show in comment for setting the right write parameters bool fm = false; //define coding just to show in comment for setting the right write parameters
inputFile.seekg(0, inputFile.end); inputFile.seekg(0, inputFile.end);
@@ -205,15 +211,14 @@ public:
unsigned Modulation_Speed = 0; unsigned Modulation_Speed = 0;
unsigned sectorSize = 0; unsigned sectorSize = 0;
//std::string sector_skew; //std::string sector_skew;
std::vector<char> sector_skew; std::string sector_skew;
std::vector<char> previous_sector_skew; // sector_skew.clear();
sector_skew.clear();
int b; int b;
std::string comment; std::string comment;
bool blnOptionalCylinderMap = false; bool blnOptionalCylinderMap = false;
bool blnOptionalHeadMap = false; bool blnOptionalHeadMap = false;
bool blnBase0 = false;
// unsigned char comment[8192]; //i choose a fixed value. dont know how to make dynamic arrays in C++. This should be enough // unsigned char comment[8192]; //i choose a fixed value. dont know how to make dynamic arrays in C++. This should be enough
// Read comment // Read comment
comment.clear(); comment.clear();
@@ -221,7 +226,8 @@ public:
{ {
comment.push_back(b); comment.push_back(b);
n++; n++;
} headerPtr = n; //set pointer to after comment }
headerPtr = n; //set pointer to after comment
// comment[n] = '\0'; // null-terminate the string // comment[n] = '\0'; // null-terminate the string
//write comment to screen //write comment to screen
// Logger() << fmt::format("IMD: comment: {}", comment); // Logger() << fmt::format("IMD: comment: {}", comment);
@@ -229,8 +235,6 @@ public:
<< fmt::format("{}", << fmt::format("{}",
comment); comment);
bool blnBaseOne = false;
for (;;) for (;;)
{ {
if (headerPtr >= inputFileSize-1) if (headerPtr >= inputFileSize-1)
@@ -279,17 +283,29 @@ public:
header.Head = header.Head^SEC_HEAD_MAP_FLAG; //remove flag 01000001 ^ 01000001 = 00000001 and 01000000 ^ 0100000 = 00000000 for writing sector head later header.Head = header.Head^SEC_HEAD_MAP_FLAG; //remove flag 01000001 ^ 01000001 = 00000001 and 01000000 ^ 0100000 = 00000000 for writing sector head later
} }
//read sector numbering map //read sector numbering map
std::vector<unsigned> sector_map(header.numSectors); // std::vector<unsigned> sector_map(header.numSectors);
sector_skew.clear(); blnBase0 = false;
sector_skew.clear();
uint8_t t_low = 1;
uint8_t t_high = 1;
for (b = 0; b < header.numSectors; b++) for (b = 0; b < header.numSectors; b++)
{ {
uint8_t t; uint8_t t;
t = br.read_8(); t = br.read_8();
headerPtr++; // Logger() << "IMD DEBUG: t:" << fmt::format(" {0:d}", t);
sector_map[b] = b+1; //fluxengine always starts with 1?? if (t < t_low) t_low = t;
if (t > t_high) t_high = t;
// if (t == 0) blnBase0 = true;
sector_skew.push_back(setsectorskew(t)); sector_skew.push_back(setsectorskew(t));
headerPtr++;
// sector_map[b] = b;
} }
auto ibm = config.mutable_encoder()->mutable_ibm();
// for (int i = 0; i < header.numSectors; i++)
// {
// Logger() << "IMD DEBUG: sector map:", sector_skew[1];
// }
auto ibm = config.mutable_encoder()->mutable_ibm();
// if (!config.drive().has_rotational_period_ms()) // if (!config.drive().has_rotational_period_ms())
// config.mutable_drive()->set_rotational_period_ms(200); // config.mutable_drive()->set_rotational_period_ms(200);
@@ -297,8 +313,9 @@ public:
auto trackdata = ibm->add_trackdata(); auto trackdata = ibm->add_trackdata();
trackdata->set_target_clock_period_us(1e3 / Modulation_Speed); trackdata->set_target_clock_period_us(1e3 / Modulation_Speed);
trackdata->set_target_rotational_period_ms(200); trackdata->set_target_rotational_period_ms(200);
//trackdata->sector_range().max_sector()=t_high;
trackdata->set_use_fm(fm); trackdata->set_use_fm(fm);
//trackdata->set_allocated_sector_range(_IbmDecoderProto_TrackdataProto_SectorRangeProto_default_instance_)
auto sectors = trackdata->mutable_sectors(); auto sectors = trackdata->mutable_sectors();
@@ -307,8 +324,31 @@ public:
{ {
Bytes sectordata; Bytes sectordata;
Bytes compressed(sectorSize); Bytes compressed(sectorSize);
unsigned int SectorID;
const auto& sector = image->put(header.track, header.Head, sector_map[s]); switch (sector_skew[s])
{
case '0': SectorID = 0; break;
case '1': SectorID = 1; break;
case '2': SectorID = 2; break;
case '3': SectorID = 3; break;
case '4': SectorID = 4; break;
case '5': SectorID = 5; break;
case '6': SectorID = 6; break;
case '7': SectorID = 7; break;
case '8': SectorID = 8; break;
case '9': SectorID = 9; break;
case 'a': SectorID = 10; break;
case 'b': SectorID = 11; break;
case 'c': SectorID = 12; break;
case 'd': SectorID = 13; break;
case 'e': SectorID = 14; break;
case 'f': SectorID = 15; break;
case 'g': SectorID = 16; break;
case 'h': SectorID = 17; break;
case 'i': SectorID = 18;
}
// const auto& sector = image->put(header.track, header.Head, sector_map[s]);
const auto& sector = image->put(header.track, header.Head, SectorID);
//read the status of the sector //read the status of the sector
unsigned int Status_Sector = br.read_8(); unsigned int Status_Sector = br.read_8();
headerPtr++; headerPtr++;
@@ -359,10 +399,16 @@ public:
break; break;
case 4: /* Compressed with "Deleted-Data address mark"*/ case 4: /* Compressed with "Deleted-Data address mark"*/
compressed[0] = br.read_8();
headerPtr++;
for (int k = 1; k < sectorSize; k++)
{
//fill data till sector is full
br.seek(headerPtr);
compressed[k] = br.read_8();
}
sector->data.writer().append(compressed);
sector->status = Sector::DATA_MISSING; sector->status = Sector::DATA_MISSING;
sectordata = br.read(sectorSize);
headerPtr += sectorSize;
sector->data.writer().append(sectordata);
break; break;
case 5: /* Normal data read with data error*/ case 5: /* Normal data read with data error*/
@@ -373,10 +419,16 @@ public:
break; break;
case 6: /* Compressed read with data error*/ case 6: /* Compressed read with data error*/
sectordata = br.read(sectorSize); compressed[0] = br.read_8();
headerPtr += sectorSize; headerPtr++;
for (int k = 1; k < sectorSize; k++)
{
//fill data till sector is full
br.seek(headerPtr);
compressed[k] = br.read_8();
}
sector->data.writer().append(compressed);
sector->status = Sector::BAD_CHECKSUM; sector->status = Sector::BAD_CHECKSUM;
sector->data.writer().append(sectordata);
break; break;
case 7: /* Deleted data read with data error*/ case 7: /* Deleted data read with data error*/
@@ -387,14 +439,20 @@ public:
break; break;
case 8: /* Compressed, Deleted read with data error*/ case 8: /* Compressed, Deleted read with data error*/
sectordata = br.read(sectorSize); compressed[0] = br.read_8();
headerPtr += sectorSize; headerPtr++;
for (int k = 1; k < sectorSize; k++)
{
//fill data till sector is full
br.seek(headerPtr);
compressed[k] = br.read_8();
}
sector->data.writer().append(compressed);
sector->status = Sector::BAD_CHECKSUM; sector->status = Sector::BAD_CHECKSUM;
sector->data.writer().append(sectordata);
break; break;
default: default:
Error() << fmt::format("Don't understand IMD files with sector status {}, track {}, sector {}", Status_Sector, header.track, s); Error() << fmt::format("IMD: Don't understand IMD files with sector status {}, track {}, sector {}", Status_Sector, header.track, s);
} }
if (blnOptionalCylinderMap) //there was een optional cylinder map. write it to the sector if (blnOptionalCylinderMap) //there was een optional cylinder map. write it to the sector
//The Sector Cylinder Map has one entry for each sector, and contains the logical Cylinder ID for the corresponding sector in the Sector Numbering Map. //The Sector Cylinder Map has one entry for each sector, and contains the logical Cylinder ID for the corresponding sector in the Sector Numbering Map.
@@ -423,7 +481,7 @@ public:
sector->logicalSide = header.Head; sector->logicalSide = header.Head;
sector->physicalHead = header.Head; sector->physicalHead = header.Head;
} }
sector->logicalSector = (sector_map[s]); sector->logicalSector = SectorID;
} }
} }
@@ -443,7 +501,7 @@ public:
<< fmt::format("{} tracks, {} heads; {}; {} kbps; {} sectoren; sectorsize {}; sectormap {}; {} kB total.", << fmt::format("{} tracks, {} heads; {}; {} kbps; {} sectoren; sectorsize {}; sectormap {}; {} kB total.",
header.track + 1, header.Head + 1, header.track + 1, header.Head + 1,
fm ? "FM" : "MFM", fm ? "FM" : "MFM",
Modulation_Speed, header.numSectors, sectorSize, copytostring(sector_skew), (header.track+1) * trackSize / 1024); Modulation_Speed, header.numSectors, sectorSize, sector_skew, (header.track+1) * trackSize / 1024);
if (!config.has_heads()) if (!config.has_heads())
{ {
@@ -458,6 +516,10 @@ public:
tracks->set_start(0); tracks->set_start(0);
tracks->set_end(geometry.numTracks - 1); tracks->set_end(geometry.numTracks - 1);
} }
if (!config.has_sector_mapping())
{
}
return image; return image;