Search for FM or MFM sector record */
| 80 | |
| 81 | /* Search for FM or MFM sector record */ |
| 82 | nanoseconds_t advanceToNextRecord() override |
| 83 | { |
| 84 | nanoseconds_t now = tell().ns(); |
| 85 | |
| 86 | /* For all but the first sector, seek to the next sector pulse. |
| 87 | * The first sector does not contain the sector pulse in the fluxmap. |
| 88 | */ |
| 89 | if (now != 0) |
| 90 | { |
| 91 | seekToIndexMark(); |
| 92 | now = tell().ns(); |
| 93 | } |
| 94 | |
| 95 | /* Discard a possible partial sector at the end of the track. |
| 96 | * This partial sector could be mistaken for a conflicted sector, if |
| 97 | * whatever data read happens to match the checksum of 0, which is |
| 98 | * rare, but has been observed on some disks. |
| 99 | */ |
| 100 | if (now > (getFluxmapDuration() - 21e6)) |
| 101 | { |
| 102 | seekToIndexMark(); |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | int msSinceIndex = std::round(now / 1e6); |
| 107 | |
| 108 | /* Note that the seekToPattern ignores the sector pulses, so if |
| 109 | * a sector is not found for some reason, the seek will advance |
| 110 | * past one or more sector pulses. For this reason, calculate |
| 111 | * _hardSectorId after the sector header is found. |
| 112 | */ |
| 113 | nanoseconds_t clock = seekToPattern(ANY_SECTOR_PATTERN); |
| 114 | _sector->headerStartTime = tell().ns(); |
| 115 | |
| 116 | /* Discard a possible partial sector. */ |
| 117 | if (_sector->headerStartTime > (getFluxmapDuration() - 21e6)) |
| 118 | { |
| 119 | return 0; |
| 120 | } |
| 121 | |
| 122 | int sectorFoundTimeRaw = std::round(_sector->headerStartTime / 1e6); |
| 123 | int sectorFoundTime; |
| 124 | |
| 125 | /* Round time to the nearest 20ms */ |
| 126 | if ((sectorFoundTimeRaw % 20) < 10) |
| 127 | { |
| 128 | sectorFoundTime = (sectorFoundTimeRaw / 20) * 20; |
| 129 | } |
| 130 | else |
| 131 | { |
| 132 | sectorFoundTime = ((sectorFoundTimeRaw + 20) / 20) * 20; |
| 133 | } |
| 134 | |
| 135 | /* Calculate the sector ID based on time since the index */ |
| 136 | _hardSectorId = (sectorFoundTime / 20) % 10; |
| 137 | |
| 138 | return clock; |
| 139 | } |