Even better Smaky reads, and maybe with sector 0 in the right place.

This commit is contained in:
dg
2022-11-25 21:28:59 +00:00
parent f299ec1f8d
commit 5d65dcf3c8
4 changed files with 82 additions and 30 deletions

View File

@@ -24,29 +24,31 @@ public:
}
private:
void adjustForIndex(
const Fluxmap::Position& previous, const Fluxmap::Position& now)
/* Returns the sector ID of the _current_ sector. */
int advanceToNextSector()
{
if ((now.ns() - previous.ns()) < 8e6)
auto previous = tell();
seekToIndexMark();
auto now = tell();
if ((now.ns() - previous.ns()) < 9e6)
{
seekToIndexMark();
auto next = tell();
if ((next.ns() - now.ns()) < 8e6)
if ((next.ns() - now.ns()) < 9e6)
{
/* We have seen two short gaps in a row, so sector 0
* starts here. */
/* We just found sector 0. */
_sectorId = 0;
}
else
{
/* We have seen one short gap and one long gap. This
* means the index mark must be at the beginning of
* the long gap. */
/* Spurious... */
seek(now);
}
_sectorId = 0;
}
return _sectorId++;
}
public:
@@ -56,21 +58,23 @@ public:
* of about 6ms. */
seekToIndexMark();
_sectorId = -1;
while (_sectorId == -1)
_sectorId = 99;
for (;;)
{
auto previous = tell();
seekToIndexMark();
auto now = tell();
auto pos = tell();
advanceToNextSector();
if (_sectorId < 99)
{
seek(pos);
break;
}
if (eof())
return;
adjustForIndex(previous, now);
}
/* Now we know where to start counting, start finding sectors. */
_sectorId = 0;
_sectorStarts.clear();
for (;;)
{
@@ -78,14 +82,9 @@ public:
if (eof())
break;
if (_sectorId < 16)
_sectorStarts.push_back(std::make_pair(_sectorId, now));
_sectorId++;
seekToIndexMark();
auto next = tell();
adjustForIndex(now, next);
int id = advanceToNextSector();
if (id < 16)
_sectorStarts.push_back(std::make_pair(id, now));
}
_sectorIndex = 0;

View File

@@ -24,7 +24,8 @@ layout {
drive {
hard_sector_count: 16
sync_with_index: true
sync_with_index: false
revolutions: 2.2
}
decoder {

View File

@@ -7,6 +7,7 @@
#include "lib/sector.h"
#include "lib/layout.h"
#include "lib/decoders/fluxmapreader.h"
#include "lib/crc.h"
DECLARE_COLOUR(BACKGROUND, 192, 192, 192);
DECLARE_COLOUR(READ_SEPARATOR, 255, 0, 0);
@@ -414,6 +415,14 @@ void FluxViewerControl::ShowSectorMenu(std::shared_ptr<const Sector> sector)
{
wxMenu menu;
menu.Bind(
wxEVT_MENU,
[&](wxCommandEvent&)
{
DisplaySectorSummary(sector);
},
menu.Append(wxID_ANY, "Show sector summary")->GetId());
menu.Bind(
wxEVT_MENU,
[&](wxCommandEvent&)
@@ -462,7 +471,9 @@ static void dumpSectorMetadata(
<< fmt::format("Clock: {:.2f}us / {:.0f}kHz\n",
sector->clock / 1000.0,
1000000.0 / sector->clock)
<< fmt::format("Bytecode position: {}\n", sector->position);
<< fmt::format("Bytecode position: {}\n", sector->position)
<< fmt::format(
"Data CRC16: {:4x}\n", crc16(CCITT_POLY, sector->data));
}
static void dumpRecordMetadata(
@@ -472,7 +483,9 @@ static void dumpRecordMetadata(
<< fmt::format(
"Start: {:.2f}ms\n", record->startTime / 1000000.0)
<< fmt::format(
"End: {:.2f}ms\n", record->endTime / 1000000.0);
"End: {:.2f}ms\n", record->endTime / 1000000.0)
<< fmt::format(
"Data CRC16: {:4x}\n", crc16(CCITT_POLY, record->rawData));
}
void FluxViewerControl::DisplayDecodedData(std::shared_ptr<const Sector> sector)
@@ -492,6 +505,44 @@ void FluxViewerControl::DisplayDecodedData(std::shared_ptr<const Sector> sector)
TextViewerWindow::Create(this, title, s.str())->Show();
}
void FluxViewerControl::DisplaySectorSummary(
std::shared_ptr<const Sector> sector)
{
std::stringstream s;
auto title = fmt::format("Sector summary c{}.h{}.s{}",
sector->logicalTrack,
sector->logicalSide,
sector->logicalSector);
s << title << '\n';
std::vector<std::shared_ptr<const Sector>> sectors;
for (auto& trackdata : _flux->trackDatas)
{
if ((trackdata->trackInfo->logicalTrack == sector->logicalTrack) &&
(trackdata->trackInfo->logicalSide == sector->logicalSide))
{
for (auto& sec : trackdata->sectors)
{
if (*sec == *sector)
sectors.push_back(sec);
}
}
}
s << fmt::format("Number of times seen: {}\n", sectors.size());
for (int i = 0; i < sectors.size(); i++)
{
auto& sec = sectors[i];
s << fmt::format("\nInstance {}:\n\n", i);
dumpSectorMetadata(s, sec);
s << '\n';
}
TextViewerWindow::Create(this, title, s.str())->Show();
}
void FluxViewerControl::DisplayRawData(std::shared_ptr<const Sector> sector)
{
std::stringstream s;

View File

@@ -30,6 +30,7 @@ private:
void ShowRecordMenu(std::shared_ptr<const TrackInfo>& layout,
std::shared_ptr<const Record> record);
void DisplayDecodedData(std::shared_ptr<const Sector> sector);
void DisplaySectorSummary(std::shared_ptr<const Sector> sector);
void DisplayRawData(std::shared_ptr<const Sector> sector);
void DisplayRawData(std::shared_ptr<const TrackInfo>& layout,
std::shared_ptr<const Record> record);