From 02a6df73c5094993fa85a0bc44c1893578836c48 Mon Sep 17 00:00:00 2001 From: tomcw Date: Sat, 20 Jan 2018 17:18:24 +0000 Subject: [PATCH] DiskFormat: tweaks and fixed some TODOs in comments --- source/DiskDefs.h | 2 ++ source/DiskFormatTrack.cpp | 30 +++++++++++++----------------- source/DiskFormatTrack.h | 1 - source/DiskImageHelper.cpp | 18 ++++++++++-------- source/DiskImageHelper.h | 3 ++- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/source/DiskDefs.h b/source/DiskDefs.h index cd89cbf1..90a2e17b 100644 --- a/source/DiskDefs.h +++ b/source/DiskDefs.h @@ -1,3 +1,5 @@ #pragma once #define NIBBLES_PER_TRACK 0x1A00 + +const UINT NUM_SECTORS = 16; diff --git a/source/DiskFormatTrack.cpp b/source/DiskFormatTrack.cpp index 5e821b04..75ae977e 100644 --- a/source/DiskFormatTrack.cpp +++ b/source/DiskFormatTrack.cpp @@ -120,13 +120,13 @@ void FormatTrack::DriveSwitchedToReadMode(Disk_t* const fptr) // Either up to 0x18F0 (if less than 0x18F0) or up to 0x1A00 (for .nib). // When there's no spin (enhanced=1), then 0x18F0 is still too long, eg: (see GH#125) - // Gap1 = 0x81, Gap3 = 0x1D (29), TrackSize = 0x1963 - // Gap1 = 0x81, Gap3 = 0x1C (28), TrackSize = 0x1954 - // Gap1 = 0x81, Gap3 = 0x1B (27), TrackSize = 0x1945 - // Gap1 = 0x81, Gap3 = 0x1A (26), TrackSize = 0x1936 + // Gap1 = 0x81, Gap2 = 0x05, Gap3 = 0x1D (29), TrackSize = 0x1963 + // Gap1 = 0x81, Gap2 = 0x05, Gap3 = 0x1C (28), TrackSize = 0x1954 + // Gap1 = 0x81, Gap2 = 0x05, Gap3 = 0x1B (27), TrackSize = 0x1945 + // Gap1 = 0x81, Gap2 = 0x05, Gap3 = 0x1A (26), TrackSize = 0x1936 // - // 0x1936 - 0x81(gap1) = 0x18B5 - // So need a track size of 0x18B0 (rounding down) + // And 0x1936 - 0x81(gap1) = 0x18B5 + // So need a track size between 0x18B0 (rounding down) and 0x182F const UINT kShortTrackLen = 0x18B0; LPBYTE TrackBuffer = fptr->trackimage; @@ -171,22 +171,18 @@ void FormatTrack::DriveSwitchedToReadMode(Disk_t* const fptr) void FormatTrack::DriveSwitchedToWriteMode(UINT uTrackIndex) { - DecodeLatchNibbleReset(); - - if (m_bmWrittenSectorAddrFields == 0x0000) // written no sectors - { - m_WriteTrackStartIndex = (UINT)-1; // wait for 1st write - } -} - -void FormatTrack::DecodeLatchNibbleReset(void) -{ - // ProDOS: switches to write mode between Address Field & Gap2; and between Data Field & Gap3 + // ProDOS/DOS3.3: during track write, switches to read mode then back to write mode: + // . between Address Field & Gap2; and between Data Field & Gap3 // . so if at TS_GAP2_START then stay at TS_GAP2_START if (m_trackState != TS_GAP2_START) m_trackState = (m_bmWrittenSectorAddrFields == 0x0000) ? TS_GAP1 : TS_GAP3; m_uLast3Bytes = 0; m_4and4idx = 0; + + if (m_bmWrittenSectorAddrFields == 0x0000) // written no sectors + { + m_WriteTrackStartIndex = (UINT)-1; // wait for 1st write + } } // This is just for debug/logging: used to output when a new Address Field has been read diff --git a/source/DiskFormatTrack.h b/source/DiskFormatTrack.h index 1c03fb04..4db08d29 100644 --- a/source/DiskFormatTrack.h +++ b/source/DiskFormatTrack.h @@ -43,7 +43,6 @@ public: void LoadSnapshot(class YamlLoadHelper& yamlLoadHelper); private: - void DecodeLatchNibbleReset(void); void UpdateOnWriteLatch(UINT uSpinNibbleCount, const Disk_t* const fptr); void DecodeLatchNibble(BYTE floppylatch, BOOL bIsWrite); diff --git a/source/DiskImageHelper.cpp b/source/DiskImageHelper.cpp index a9d7f453..56b9f688 100644 --- a/source/DiskImageHelper.cpp +++ b/source/DiskImageHelper.cpp @@ -419,8 +419,8 @@ void CImageBase::DenibblizeTrack(LPBYTE trackimage, SectorOrder_e SectorOrder, i #endif int offset = 0; - int partsleft = 33; // TODO-TC: 32 = 16*2 prologues - int sector = 0; + int partsleft = NUM_SECTORS*2+1; // TC: 32+1 prologues - need 1 extra if trackimage starts between Addr Field & Data Field + int sector = -1; while (partsleft--) { BYTE byteval[3] = {0,0,0}; @@ -454,8 +454,8 @@ void CImageBase::DenibblizeTrack(LPBYTE trackimage, SectorOrder_e SectorOrder, i | (*(ms_pWorkBuffer+TRACK_DENIBBLIZED_SIZE+5) & 0x55); #ifdef _DEBUG - _ASSERT( sector <= 15 ); - if (partsleft != 0) // Don't need this if partsleft is initialised to 32 (not 33) + _ASSERT( sector < NUM_SECTORS ); + if (partsleft != 0) { _ASSERT( (bmWrittenSectorAddrFields & (1<= 0 && sector < NUM_SECTORS) + { #ifdef _DEBUG - uWriteDataFieldPrologueCount++; - _ASSERT(uWriteDataFieldPrologueCount <= 16); + uWriteDataFieldPrologueCount++; + _ASSERT(uWriteDataFieldPrologueCount <= NUM_SECTORS); #endif - - Decode62(ms_pWorkBuffer+(ms_SectorNumber[SectorOrder][sector] << 8)); + Decode62(ms_pWorkBuffer+(ms_SectorNumber[SectorOrder][sector] << 8)); + } sector = 0; } } diff --git a/source/DiskImageHelper.h b/source/DiskImageHelper.h index 01a07b49..2b8a8a4d 100644 --- a/source/DiskImageHelper.h +++ b/source/DiskImageHelper.h @@ -1,5 +1,6 @@ #pragma once +#include "DiskDefs.h" #include "zip.h" #define GZ_SUFFIX ".gz" @@ -90,7 +91,7 @@ public: protected: static BYTE ms_DiskByte[0x40]; - static BYTE ms_SectorNumber[NUM_SECTOR_ORDERS][0x10]; + static BYTE ms_SectorNumber[NUM_SECTOR_ORDERS][NUM_SECTORS]; BYTE m_uVolumeNumber; };