From c04ab77f43db3350a55128dc6061fdddfe1ef03d Mon Sep 17 00:00:00 2001 From: "Christopher A. Mosher" Date: Sun, 11 Dec 2022 03:35:44 -0500 Subject: [PATCH] clearPulse was happening too soon for reading 13-sector disks --- src/addressbus.cpp | 30 +++---- src/diskcontroller.cpp | 9 +-- src/lss.cpp | 176 ++++++++++++++++++----------------------- src/lss.h | 2 +- src/wozfile.cpp | 9 ++- 5 files changed, 101 insertions(+), 125 deletions(-) diff --git a/src/addressbus.cpp b/src/addressbus.cpp index d3cdd96..5730272 100644 --- a/src/addressbus.cpp +++ b/src/addressbus.cpp @@ -156,23 +156,23 @@ void AddressBus::readSwitch(unsigned short address) { this->data = this->slts.io(islot, iswch, this->data, false); /////////////////////////////////////////////// // debug raw nibble disk reads - if (islot==6 && ((this->data & 0x80u) != 0u)) { - if (debugfirst) { - debugfirst = false; - for (int i = 0; i < 128; ++i) { - printf("%02X", i); - } - printf("\n"); - } - printf("%02X", this->data); - ++debugoutpos; - if (128 <= debugoutpos) { - debugoutpos = 0; - printf("\n"); +// if (islot==6 && ((this->data & 0x80u) != 0u)) { +// if (debugfirst) { +// debugfirst = false; +// for (int i = 0; i < 128; ++i) { +// printf("%02X", i); +// } +// printf("\n"); +// } +// printf("%02X", this->data); +// ++debugoutpos; +// if (128 <= debugoutpos) { +// debugoutpos = 0; +// printf("\n"); // DiskController* dsk = (DiskController*)(this->slts.get(6)); // dsk->dumpLss(); - } - } +// } +// } /////////////////////////////////////////////// } } diff --git a/src/diskcontroller.cpp b/src/diskcontroller.cpp index 23d09ed..eaf78e3 100644 --- a/src/diskcontroller.cpp +++ b/src/diskcontroller.cpp @@ -109,15 +109,14 @@ void DiskController::tick() { // run two LSS cycles = 2MHz - + rotateCurrentDisk(); + stepLss(); rotateCurrentDisk(); stepLss(); - // pulse lasts only 500 nanoseconds (1 LSS clock cycle), so clear it now: + + this->currentDrive->clearPulse(); - - rotateCurrentDisk(); - stepLss(); } void DiskController::rotateCurrentDisk() { diff --git a/src/lss.cpp b/src/lss.cpp index ce83053..81c5ce5 100644 --- a/src/lss.cpp +++ b/src/lss.cpp @@ -22,19 +22,11 @@ #include #include -static void setcmd(std::array &lssrom, std::uint8_t x, std::uint8_t cmd) { - lssrom.at(x) = (lssrom.at(x) & 0xF0u) | cmd; -} -static void setseq(std::array &lssrom, std::uint8_t x, std::uint8_t seq) { - lssrom.at(x) = (lssrom.at(x) & 0x0Fu) | seq; -} -static void setbth(std::array &lssrom, std::uint8_t x, std::uint8_t both) { - lssrom.at(x) = both; -} -static void inst(std::uint8_t seq, std::uint8_t inst) { + +static void inst_sym(std::uint8_t seq, std::uint8_t inst) { const std::uint8_t next_seq((inst & 0xF0u) >> 4); const bool stdseq((seq == 0x0Fu && next_seq == 0x00u) || next_seq == seq+1); const std::uint8_t cmd(inst & 0x0Fu); @@ -71,34 +63,89 @@ static void inst(std::uint8_t seq, std::uint8_t inst) { printf(" "); } -static void showua2seq(const std::array &lssrom, std::uint8_t seq) { +static void inst_hex(std::uint8_t seq, std::uint8_t inst) { + const std::uint8_t next_seq((inst & 0xF0u) >> 4); + const bool stdseq((seq == 0x0Fu && next_seq == 0x00u) || next_seq == seq+1); + const std::uint8_t cmd(inst & 0x0Fu); + + printf("%02X ", inst); +} + +static void inst(std::uint8_t seq, std::uint8_t inst, bool sym = true) { + if (sym) { + inst_sym(seq, inst); + } else { + inst_hex(seq, inst); + } +} + +static void showua2seq(const std::array &lssrom, std::uint8_t seq, bool sym = true) { const std::uint8_t s(seq >> 4); printf("%1X: | ", s); - inst(s,lssrom.at(seq|0x9)); - inst(s,lssrom.at(seq|0xB)); - inst(s,lssrom.at(seq|0xD)); - inst(s,lssrom.at(seq|0xF)); + inst(s,lssrom.at(seq|0x9),sym); + inst(s,lssrom.at(seq|0xB),sym); + inst(s,lssrom.at(seq|0xD),sym); + inst(s,lssrom.at(seq|0xF),sym); printf("| "); - inst(s,lssrom.at(seq|0x8)); - inst(s,lssrom.at(seq|0xA)); - inst(s,lssrom.at(seq|0xC)); - inst(s,lssrom.at(seq|0xE)); + inst(s,lssrom.at(seq|0x8),sym); + inst(s,lssrom.at(seq|0xA),sym); + inst(s,lssrom.at(seq|0xC),sym); + inst(s,lssrom.at(seq|0xE),sym); printf("| "); - inst(s,lssrom.at(seq|0x1)); - inst(s,lssrom.at(seq|0x0)); - inst(s,lssrom.at(seq|0x3)); - inst(s,lssrom.at(seq|0x2)); + inst(s,lssrom.at(seq|0x1),sym); + inst(s,lssrom.at(seq|0x0),sym); + inst(s,lssrom.at(seq|0x3),sym); + inst(s,lssrom.at(seq|0x2),sym); printf("| "); - inst(s,lssrom.at(seq|0x5)); - inst(s,lssrom.at(seq|0x4)); - inst(s,lssrom.at(seq|0x7)); - inst(s,lssrom.at(seq|0x6)); + inst(s,lssrom.at(seq|0x5),sym); + inst(s,lssrom.at(seq|0x4),sym); + inst(s,lssrom.at(seq|0x7),sym); + inst(s,lssrom.at(seq|0x6),sym); printf("\n"); if (s == 7) { printf(" +-------------------------+-------------------------+-------------------------+------------------------\n"); } } +void LSS::dump() const { + printf("%s\n", "Disk ][ Controller Logic State Sequencer ROM:"); + if (this->use13Sector) { + printf("%s\n", "for 13-sector disks"); + for (unsigned int seq = 0; seq < 0x100u; seq += 0x10u) { + showua2seq(this->lss13rom,seq); + } +// printf("%s\n", "==================================================="); +// for (unsigned int seq = 0; seq < 0x100u; seq += 0x10u) { +// showua2seq(this->lss13rom,seq,false); +// } + } else { + printf("%s\n", "for 16-sector disks"); + for (unsigned int seq = 0; seq < 0x100u; seq += 0x10u) { + showua2seq(this->lssrom,seq); + } +// printf("%s\n", "==================================================="); +// for (unsigned int seq = 0; seq < 0x100u; seq += 0x10u) { +// showua2seq(this->lssrom,seq,false); +// } + } +} + + + + + +static void setcmd(std::array &lssrom, std::uint8_t x, std::uint8_t cmd) { + lssrom.at(x) = (lssrom.at(x) & 0xF0u) | cmd; +} + +static void setseq(std::array &lssrom, std::uint8_t x, std::uint8_t seq) { + lssrom.at(x) = (lssrom.at(x) & 0x0Fu) | seq; +} + +static void setbth(std::array &lssrom, std::uint8_t x, std::uint8_t both) { + lssrom.at(x) = both; +} + LSS::LSS(bool use13SectorDos32LSS): use13Sector(use13SectorDos32LSS) { @@ -230,77 +277,6 @@ LSS::LSS(bool use13SectorDos32LSS): LSS::~LSS() { } -void LSS::dump() const { - printf("%s\n", "Disk ][ Controller Logic State Sequencer ROM:"); - if (this->use13Sector) { - printf("%s\n", "for 13-sector disks"); - for (unsigned int seq = 0; seq < 0x100u; seq += 0x10u) { - showua2seq(this->lss13rom,seq); - } -// printf("%s\n", "==================================================="); -// for (int r = 0; r < 0x10; ++r) { -// for (int c = 0; c < 0x10; ++c) { -// printf("%02X ", this->lss13rom.at(r*0x10+c)); -// } -// printf("\n"); -// } - } else { - printf("%s\n", "for 16-sector disks"); - for (unsigned int seq = 0; seq < 0x100u; seq += 0x10u) { - showua2seq(this->lssrom,seq); - } -// printf("%s\n", "==================================================="); -// for (int r = 0; r < 0x10; ++r) { -// for (int c = 0; c < 0x10; ++c) { -// printf("%02X ", this->lssrom.at(r*0x10+c)); -// } -// printf("\n"); -// } - } -} - -/* - * AA 10101010 - * AE 10101110 - - * B6 10110110 - * BA 10111010 - * BE 10111110 - - * D6 11010110 - * DA 11011010 - * DE 11011110 - - * EA 11101010 - * EE 11101110 - - * F6 11110110 - * FA 11111010 - * FE 11111110 - */ - -std::uint8_t LSS::read(const std::uint8_t addr) { - int i = addr; - i &= 0x000000FF; - if (0x100 <= i) { - throw std::runtime_error("bad lss ROM read"); - } - - //return use13Sector ? lss13rom[addr] : lssrom[addr]; - std::uint8_t r = 0; - if (this->use13Sector) { - const std::uint8_t candidate = this->lss13rom.at(i); - if (candidate == 0x44u) { - throw std::runtime_error("attempt to read uninitialized LSS ROM"); - } - r = candidate; - } else { - const std::uint8_t candidate = this->lssrom.at(i); - if (candidate == 0x44u) { - throw std::runtime_error("attempt to read uninitialized LSS ROM"); - } - r = candidate; - } - - return r; +std::uint8_t LSS::read(const std::uint8_t addr) const { + return this->use13Sector ? this->lss13rom.at(addr) : this->lssrom.at(addr); } diff --git a/src/lss.h b/src/lss.h index 6835ef6..4986d65 100644 --- a/src/lss.h +++ b/src/lss.h @@ -34,7 +34,7 @@ public: LSS(bool use13SectorDos32LSS); ~LSS(); - std::uint8_t read(const std::uint8_t addr); + std::uint8_t read(const std::uint8_t addr) const; void dump() const; }; diff --git a/src/wozfile.cpp b/src/wozfile.cpp index c9c9e70..6483f6c 100644 --- a/src/wozfile.cpp +++ b/src/wozfile.cpp @@ -544,17 +544,18 @@ void WozFile::rotateOneBit(std::uint8_t currentQuarterTrack) { // previous, based on each track's length (tracks can be of // different lengths in the WOZ image). if (currentQuarterTrack != this->lastQuarterTrack) { - printf("\nswitching from tmap[%02x] --> [%02x]\n", this->lastQuarterTrack, currentQuarterTrack); +// printf("switching from tmap[%02x] --> [%02x]\n", this->lastQuarterTrack, currentQuarterTrack); const double oldLen = this->trk_bits[this->tmap[this->lastQuarterTrack]]; const double newLen = this->trk_bits[this->tmap[currentQuarterTrack]]; const double ratio = newLen/oldLen; if (!(fabs(1-ratio) < 0.0001)) { const std::uint16_t newBit = static_cast(round((this->byt*8+bc(this->bit)) * ratio)); - printf("... detected non 1:1 ratio: %f\n", ratio); - printf("... old byt/bit: %hu/%hu\n", this->byt, this->bit); + const std::uint8_t orig_bit = this->bit; + const std::uint16_t orig_byt = this->byt; this->byt = newBit / 8; this->bit = cb(newBit % 8); - printf("... new byt/bit: %hu/%hu\n", this->byt, this->bit); + printf("woz detected non 1:1 track size ratio: %f; adjusting byte/bit: %04X/%02X --> %04X/%02X\n", + ratio, orig_byt, orig_bit, this->byt, this->bit); } this->lastQuarterTrack = currentQuarterTrack; }