Skip to content

Commit b986af5

Browse files
committed
Fixed an MFM compliance issue when editing bitstream images
1 parent 07bd20f commit b986af5

File tree

6 files changed

+41
-22
lines changed

6 files changed

+41
-22
lines changed

DiskImageTool/Bitstream/BitstreamRegionSector.vb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@
99
Public Property HasData As Boolean
1010
Public Property IDAMChecksumValid As Boolean
1111
Public Property Length As UInteger
12+
Public Property Overlaps As Boolean
1213
Public Property SectorId As Byte
1314
Public Property SectorIndex As UShort
1415
Public Property Side As Byte
1516
Public Property StartIndex As UInteger
1617
Public Property Track As Byte
17-
Public Overrides Function ToString() As String
18-
'Return _SectorIndex & " (" & _SectorId & ")"
19-
Return _SectorId
20-
End Function
2118
End Class
2219
End Namespace
2320
End Namespace

DiskImageTool/Bitstream/IBM_MFM/IBM_MFM_Sector.vb

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150
Return MFMCRC16(_IDArea)
151151
End Function
152152

153-
Public Function GetDataBitstream() As BitArray
153+
Public Function GetDataBitstream(SeedBit As Boolean) As BitArray
154154
Dim DataSize = GetSizeBytes()
155155
Dim Buffer(DataSize + 2 - 1) As Byte
156156

@@ -159,7 +159,7 @@
159159
Offset += DataSize
160160
Array.Copy(BitConverter.GetBytes(_DataChecksum), 0, Buffer, Offset, 2)
161161

162-
Return MFMEncodeBytes(Buffer, 1)
162+
Return MFMEncodeBytes(Buffer, SeedBit)
163163
End Function
164164

165165
Public Function GetSizeBytes() As UInteger
@@ -173,11 +173,22 @@
173173
Public Sub UpdateBitstream()
174174
UpdateChecksum()
175175

176-
Dim Bitstream = GetDataBitstream()
176+
Dim SeedBit = GetSeedBit(_DataOffset)
177+
178+
Dim Bitstream = GetDataBitstream(SeedBit)
177179

178180
For i = 0 To Bitstream.Length - 1
179181
_Bitstream(_DataOffset + i) = Bitstream(i)
180182
Next
183+
184+
Dim Offset = _DataOffset + Bitstream.Length - 1
185+
If Offset < _Bitstream.Length - 2 Then
186+
Dim PrevDataBit = _Bitstream(Offset)
187+
Dim DataBit = _Bitstream(Offset + 2)
188+
Dim ClockBit = (Not DataBit And Not PrevDataBit)
189+
_Bitstream(Offset + 1) = ClockBit
190+
End If
191+
181192
End Sub
182193

183194
Public Sub UpdateChecksum()
@@ -190,6 +201,13 @@
190201
Return BitConverter.ToUInt16(Checksum, 0)
191202
End Function
192203

204+
Private Function GetSeedBit(Offset As UInteger) As Boolean
205+
If Offset > 0 Then
206+
Return _Bitstream(Offset - 1)
207+
Else
208+
Return True
209+
End If
210+
End Function
193211
Private Function ProcessDataField(BitStream As BitArray, Start As UInteger) As Integer
194212
Dim MFMPattern = BytesToBits(MFM_Sync_Bytes)
195213

DiskImageTool/Bitstream/IBM_MFM/IBM_MFM_Tools.vb

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -428,16 +428,17 @@
428428

429429
Dim SectorSize = DataLength
430430
Dim SectorLength = (SectorEnd - BitstreamIndex) \ MFM_BYTE_SIZE
431-
Dim Overlaps As Boolean = False
432431

433432
If SectorSize > SectorLength Then
434433
SectorSize = SectorLength
435-
Overlaps = True
434+
RegionSector.Overlaps = True
435+
Else
436+
RegionSector.Overlaps = False
436437
End If
437438

438439
SyncNullCount = 0
439440
GapCount = 0
440-
If Overlaps Then
441+
If RegionSector.Overlaps Then
441442
Buffer = MFMGetBytes(Bitstream, BitstreamIndex, SectorSize)
442443
SyncNullCount = GetByteCount(Buffer, 0, 0)
443444
SectorSize -= SyncNullCount
@@ -464,7 +465,7 @@
464465
ByteIndex += SectorSize
465466
BitstreamIndex += SectorSize * MFM_BYTE_SIZE
466467

467-
If Not Overlaps And SectorSize < SectorLength - 2 Then
468+
If Not RegionSector.Overlaps And SectorSize < SectorLength - 2 Then
468469
RegionData.Regions.Add(New BitstreamRegion(RegionType, ByteIndex, MFM_CRC_SIZE, RegionSector, BitOffset))
469470
ByteIndex += MFM_CRC_SIZE
470471
BitstreamIndex += MFM_CRC_SIZE * MFM_BYTE_SIZE
@@ -655,22 +656,18 @@
655656
Public Function MFMEncodeBytes(Data() As Byte, SeedBit As Boolean) As BitArray
656657
Dim Bitstream As New BitArray(Data.Length * 16)
657658
Dim bitCount As Integer = 0
658-
Dim dateBit As Boolean
659+
Dim dataBit As Boolean
659660
Dim clockBit As Boolean
660661

661662
Dim prevDataBit = SeedBit
662663
For i = 0 To Data.Length - 1
663664
For j = 7 To 0 Step -1
664-
dateBit = CBool((Data(i) And (1 << j)))
665-
If Not dateBit And Not prevDataBit Then
666-
clockBit = True
667-
Else
668-
clockBit = False
669-
End If
665+
dataBit = CBool((Data(i) And (1 << j)))
666+
clockBit = (Not dataBit And Not prevDataBit)
670667
Bitstream.Set(bitCount, clockBit)
671-
Bitstream.Set(bitCount + 1, dateBit)
668+
Bitstream.Set(bitCount + 1, dataBit)
672669

673-
prevDataBit = dateBit
670+
prevDataBit = dataBit
674671
bitCount += 2
675672
Next
676673
Next

DiskImageTool/DiskImageTool.vbproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<TargetCulture>en-US</TargetCulture>
3131
<ProductName>DiskImageTool</ProductName>
3232
<PublisherName>Digitoxin</PublisherName>
33-
<ApplicationRevision>0</ApplicationRevision>
33+
<ApplicationRevision>1</ApplicationRevision>
3434
<ApplicationVersion>2.8.0.%2a</ApplicationVersion>
3535
<UseApplicationTrust>false</UseApplicationTrust>
3636
<PublishWizardCompleted>true</PublishWizardCompleted>

DiskImageTool/Forms/HexViewRawForm.vb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,14 +1300,17 @@ Public Class HexViewRawForm
13001300
Dim Sector = _RegionData.Sectors(SectorIndex)
13011301
TooltipText = "Sector Id: " & vbTab & vbTab & Sector.SectorId
13021302
TooltipText &= vbCrLf & "Size: " & vbTab & vbTab & vbTab & Sector.DataLength
1303+
13031304
If Sector.Track <> _Track Then
13041305
TooltipText &= vbCrLf & "Track: " & vbTab & vbTab & vbTab & Sector.Track
13051306
End If
1307+
13061308
If Sector.Side <> _Side Then
13071309
TooltipText &= vbCrLf & "Side: " & vbTab & vbTab & vbTab & Sector.Side
13081310
End If
13091311

13101312
TooltipText &= vbCrLf & "Address Checksum: " & vbTab & If(Sector.IDAMChecksumValid, "Valid", "Invalid")
1313+
13111314
If Sector.HasData Then
13121315
TooltipText &= vbCrLf & "Data Checksum: " & vbTab & vbTab & If(Sector.DataChecksumValid, "Valid", "Invalid")
13131316
End If
@@ -1323,6 +1326,10 @@ Public Class HexViewRawForm
13231326
DAMText = "Unknown"
13241327
End If
13251328
TooltipText &= vbCrLf & "Data Address Mark: " & vbTab & DAMText
1329+
1330+
If Sector.Overlaps Then
1331+
TooltipText &= vbCrLf & "Overlaps"
1332+
End If
13261333
End If
13271334

13281335
If TooltipText <> _ToolTip.GetToolTip(PanelSectors) Then

DiskImageTool/My Project/AssemblyInfo.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ Imports System.Runtime.InteropServices
3131
' <Assembly: AssemblyVersion("1.0.*")>
3232

3333
<Assembly: AssemblyVersion("1.0.0.0")>
34-
<Assembly: AssemblyFileVersion("2.8.0.0")>
34+
<Assembly: AssemblyFileVersion("2.8.0.1")>

0 commit comments

Comments
 (0)