| 127 | } |
| 128 | |
| 129 | void FormatTrack::DriveSwitchedToReadMode(FloppyDisk* const pFloppy) |
| 130 | { |
| 131 | if (m_bAddressPrologueIsDOS3_2) |
| 132 | { |
| 133 | if (m_bmWrittenSectorAddrFields != 0x1FFF) // written all 13 sectors? (NB. data field not written by formatter) |
| 134 | return; |
| 135 | } |
| 136 | else |
| 137 | { |
| 138 | if (m_bmWrittenSectorAddrFields != 0xFFFF || m_WriteDataFieldPrologueCount != 16) // written all 16 sectors? |
| 139 | return; |
| 140 | } |
| 141 | |
| 142 | // Zero-fill the remainder of the track buffer: |
| 143 | // Either up to 0x18F0 (if less than 0x18F0) or up to 0x1A00 (for .nib). |
| 144 | |
| 145 | // When there's no spin (enhanced=1), then 0x18F0 is still too long, eg: (see GH#125) |
| 146 | // Gap1 = 0x81, Gap2 = 0x05, Gap3 = 0x1D (29), TrackSize = 0x1963 |
| 147 | // Gap1 = 0x81, Gap2 = 0x05, Gap3 = 0x1C (28), TrackSize = 0x1954 |
| 148 | // Gap1 = 0x81, Gap2 = 0x05, Gap3 = 0x1B (27), TrackSize = 0x1945 |
| 149 | // Gap1 = 0x81, Gap2 = 0x05, Gap3 = 0x1A (26), TrackSize = 0x1936 |
| 150 | // |
| 151 | // And 0x1936 - 0x81(gap1) = 0x18B5 |
| 152 | // So need a track size between 0x18B0 (rounding down) and 0x182F |
| 153 | const UINT kShortTrackLen = 0x18B0; |
| 154 | |
| 155 | LPBYTE TrackBuffer = pFloppy->m_trackimage; |
| 156 | const UINT kLongTrackLen = pFloppy->m_nibbles; |
| 157 | |
| 158 | UINT uWriteTrackEndIndex = pFloppy->m_byte; |
| 159 | UINT uWrittenTrackSize = m_WriteTrackHasWrapped ? kLongTrackLen : 0; |
| 160 | |
| 161 | if (m_WriteTrackStartIndex <= uWriteTrackEndIndex) |
| 162 | uWrittenTrackSize += uWriteTrackEndIndex - m_WriteTrackStartIndex; |
| 163 | else |
| 164 | uWrittenTrackSize += (kLongTrackLen - m_WriteTrackStartIndex) + uWriteTrackEndIndex; |
| 165 | |
| 166 | #if LOG_DISK_NIBBLES_WRITE_TRACK_GAPS |
| 167 | LOG_DISK("Gap1 = 0x%02X, Gap2 = 0x%02X, Gap3 = 0x%02X (%02d), TrackSize = 0x%04X\n", m_DbgGap1Size, m_DbgGap2Size, m_DbgGap3Size, m_DbgGap3Size, uWrittenTrackSize); |
| 168 | #endif |
| 169 | |
| 170 | if (uWrittenTrackSize > kShortTrackLen) |
| 171 | uWrittenTrackSize = kShortTrackLen; |
| 172 | |
| 173 | int iSrc = uWriteTrackEndIndex - uWrittenTrackSize; // Rewind to start of non-overwritten part of short track |
| 174 | if (iSrc < 0) |
| 175 | iSrc += kLongTrackLen; |
| 176 | |
| 177 | // S < E: | S-------E | |
| 178 | // S > E: |----E S---| |
| 179 | if ((UINT)iSrc < uWriteTrackEndIndex) |
| 180 | { |
| 181 | memset(&TrackBuffer[0], 0, iSrc); |
| 182 | memset(&TrackBuffer[uWriteTrackEndIndex], 0, kLongTrackLen - uWriteTrackEndIndex); |
| 183 | } |
| 184 | else |
| 185 | { |
| 186 | // NB. For the iSrc == uWriteTrackEndIndex case: memset() size=0 |