Skip to content

Commit b147d70

Browse files
committed
Added bitstream support for Japanese 2HD images
Bug fixes
1 parent d3da2d7 commit b147d70

26 files changed

+217
-154
lines changed

DiskImageTool/Bitstream/Functions.vb

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,15 @@ Namespace Bitstream
2929
Return HashBytesToString(HashAlgorithm.Hash)
3030
End Function
3131

32-
Public Function BitstreamGetImageFormat(Image As IBitstreamImage) As FloppyDiskFormat
32+
Public Function BitstreamGetImageFormat(Image As IBitstreamImage, BytesPerSector As UInteger) As FloppyDiskFormat
3333
Dim DiskFormat As FloppyDiskFormat
3434

35-
Dim SectorCount = InferSectorCount(Image)
35+
Dim SectorCount = InferSectorCount(Image, BytesPerSector)
3636

37-
If Image.TrackCount \ Image.TrackStep >= 79 Then
37+
If BytesPerSector = 1024 And SectorCount = 8 Then
38+
DiskFormat = FloppyDiskFormat.Floppy2HD
39+
40+
ElseIf Image.TrackCount \ Image.TrackStep >= 79 Then
3841
If SectorCount >= 36 Then
3942
DiskFormat = FloppyDiskFormat.Floppy2880
4043
ElseIf SectorCount >= 18 Then
@@ -77,6 +80,25 @@ Namespace Bitstream
7780
Return RoundRPM((60 * 1000000) / MicrosecondsPerRev)
7881
End Function
7982

83+
Public Function GetBytesPerSector(Image As IBitstreamImage) As UInteger
84+
Dim BytesPerSector As UInteger = 512
85+
86+
Dim Track = Image.GetTrack(0, 0)
87+
If Track IsNot Nothing Then
88+
Dim MFMData = Track.MFMData
89+
If MFMData IsNot Nothing Then
90+
For Each Sector In MFMData.Sectors
91+
If Sector.SectorId = 1 Then
92+
BytesPerSector = Sector.GetSizeBytes
93+
Exit For
94+
End If
95+
Next
96+
End If
97+
End If
98+
99+
Return BytesPerSector
100+
End Function
101+
80102
Public Function InferBitRate(BitCount As UInteger) As UShort
81103
BitCount = Math.Round(BitCount / 5000) * 5000
82104

@@ -126,7 +148,7 @@ Namespace Bitstream
126148
End If
127149
End Function
128150

129-
Public Function InferSectorCount(Image As IBitstreamImage) As UShort
151+
Public Function InferSectorCount(Image As IBitstreamImage, BytesPerSector As UInteger) As UShort
130152
Dim Track As IBitstreamTrack
131153
Dim SectorCount As Byte = 0
132154
Dim TotalSize As UShort
@@ -137,7 +159,7 @@ Namespace Bitstream
137159
Track = Image.GetTrack(i, j)
138160
If Track IsNot Nothing AndAlso Track.MFMData IsNot Nothing Then
139161
TotalSize = GetSectorSize(Track.MFMData.Sectors)
140-
SectorCount = TotalSize \ 512
162+
SectorCount = TotalSize \ BytesPerSector
141163
If ValidSectorCount.Contains(SectorCount) Then
142164
CountFound = True
143165
Exit For

DiskImageTool/DiskImage/BasicSectorImage.vb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
End Get
2323
End Property
2424

25+
Public ReadOnly Property BytesPerSector As UInteger Implements IFloppyImage.BytesPerSector
26+
Get
27+
Return 512
28+
End Get
29+
End Property
30+
2531
Public ReadOnly Property CanResize As Boolean Implements IFloppyImage.CanResize
2632
Get
2733
Return True

DiskImageTool/DiskImage/Disk.vb

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
_FloppyImage.History.Enabled = True
1414

1515
_BootSector = New BootSector(_FloppyImage, BootSector.BOOT_SECTOR_OFFSET)
16-
_BPB = GetBPB()
16+
_BPB = GetBPB(FloppyImage.BytesPerSector)
1717

1818
_FATTables = New FATTables(_BPB, _FloppyImage, FatIndex)
1919
_DiskFormat = InferFloppyDiskFormat()
@@ -129,7 +129,7 @@
129129
End Function
130130

131131
Public Sub Reinitialize()
132-
_BPB = GetBPB()
132+
_BPB = GetBPB(_FloppyImage.BytesPerSector)
133133
_FATTables.Reinitialize(_BPB)
134134
_DiskFormat = InferFloppyDiskFormat()
135135
_FATTables.SyncFATs = Not IsDiskFormatXDF(_DiskFormat)
@@ -142,7 +142,7 @@
142142
Return _FloppyImage.SetBytes(Value, Offset, _BPB.BytesPerSector, 0)
143143
End Function
144144

145-
Private Function GetBPB() As BiosParameterBlock
145+
Private Function GetBPB(BytesPerSector As UInteger) As BiosParameterBlock
146146
Dim BPB As BiosParameterBlock
147147

148148
If _BootSector.BPB.IsValid Then
@@ -155,8 +155,8 @@
155155
Else
156156
Dim FATMediaDescriptor = GetFATMediaDescriptor()
157157

158-
Dim DiskFormatFAT = GetFloppyDiskFomat(FATMediaDescriptor)
159158
Dim DiskFormatSize = GetFloppyDiskFormat(_FloppyImage.Length)
159+
Dim DiskFormatFAT = GetFloppyDiskFomat(FATMediaDescriptor)
160160

161161
If DiskFormatFAT = FloppyDiskFormat.Floppy360 And DiskFormatSize = FloppyDiskFormat.Floppy180 Then
162162
FATMediaDescriptor = GetFloppyDiskMediaDescriptor(DiskFormatSize)
@@ -165,6 +165,14 @@
165165
End If
166166

167167
BPB = BuildBPB(FATMediaDescriptor)
168+
169+
If BPB.BytesPerSector = 0 Then
170+
BPB.BytesPerSector = BuildBPB(DiskFormatSize).BytesPerSector
171+
End If
172+
173+
If BPB.BytesPerSector = 0 Then
174+
BPB.BytesPerSector = BytesPerSector
175+
End If
168176
End If
169177

170178
Return BPB
@@ -173,8 +181,8 @@
173181
Private Function GetFATMediaDescriptor() As Byte
174182
Dim Result As Byte = 0
175183

176-
If _FloppyImage.Length >= 515 Then
177-
Dim b = _FloppyImage.GetBytes(512, 3)
184+
If _FloppyImage.Length >= _FloppyImage.BytesPerSector + 3 Then
185+
Dim b = _FloppyImage.GetBytes(_FloppyImage.BytesPerSector, 3)
178186
If b(1) = &HFF And b(2) = &HFF Then
179187
Result = b(0)
180188
End If

DiskImageTool/DiskImage/Interfaces/IFloppyImage.vb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Namespace DiskImage
1515
Public Interface IFloppyImage
1616
ReadOnly Property AdditionalTracks As HashSet(Of UShort)
1717
ReadOnly Property BitstreamImage As IBitstreamImage
18+
ReadOnly Property BytesPerSector As UInteger
1819
ReadOnly Property CanResize As Boolean
1920
ReadOnly Property HasWeakBitsSupport As Boolean
2021
ReadOnly Property HasWeakBits As Boolean

DiskImageTool/DiskImage/MappedFloppyImage.vb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Namespace DiskImage
66

77
Friend Const SECTOR_COUNT As Byte = 36
88
Private ReadOnly _AdditionalTracks As HashSet(Of UShort)
9+
Private ReadOnly _BytesPerSector As UInteger
910
Private ReadOnly _Image As IBitstreamImage
1011
Private ReadOnly _NonStandardTracks As HashSet(Of UShort)
1112
Private ReadOnly _ProtectedSectors As HashSet(Of UInteger)
@@ -18,12 +19,13 @@ Namespace DiskImage
1819
Private _TrackCount As UShort
1920
Private _Tracks() As TrackData
2021

21-
Public Sub New(Image As IBitstreamImage)
22+
Public Sub New(Image As IBitstreamImage, BytesPerSector As UInteger)
2223
_Image = Image
2324
_History = New ImageHistory(Me)
2425
_ProtectedSectors = New HashSet(Of UInteger)
2526
_AdditionalTracks = New HashSet(Of UShort)
2627
_NonStandardTracks = New HashSet(Of UShort)
28+
_BytesPerSector = BytesPerSector
2729

2830
If _Image IsNot Nothing Then
2931
BuildSectorMap()
@@ -42,6 +44,12 @@ Namespace DiskImage
4244
End Get
4345
End Property
4446

47+
Public ReadOnly Property BytesPerSector As UInteger Implements IFloppyImage.BytesPerSector
48+
Get
49+
Return _BytesPerSector
50+
End Get
51+
End Property
52+
4553
Public ReadOnly Property CanResize As Boolean Implements IFloppyImage.CanResize
4654
Get
4755
Return False
@@ -401,7 +409,7 @@ Namespace DiskImage
401409
SetTrack(MappedTrack, Side, BitstreamTrack.MFMData, BitstreamTrack.TrackType)
402410

403411
If BitstreamTrack.MFMData IsNot Nothing Then
404-
If BitstreamTrack.MFMData.FirstSector = 1 And BitstreamTrack.MFMData.LastSector = 4 And BitstreamTrack.MFMData.SectorSize = 1024 Then
412+
If _BytesPerSector = 512 And BitstreamTrack.MFMData.FirstSector = 1 And BitstreamTrack.MFMData.LastSector = 4 And BitstreamTrack.MFMData.SectorSize = 1024 Then
405413
ProcessMFMSectors1024(Track, Side, BitstreamTrack.MFMData)
406414
Else
407415
ProcessMFMSectors(MappedTrack, Side, BitstreamTrack.MFMData)
@@ -562,12 +570,12 @@ Namespace DiskImage
562570
Sector = GetSector(Track, Side, MFMSector.SectorId)
563571
If Sector Is Nothing Then
564572
SectorSize = MFMSector.GetSizeBytes
565-
If SectorSize > 0 And SectorSize < 512 Then
566-
Buffer = New Byte(511) {}
573+
If SectorSize > 0 And SectorSize < _BytesPerSector Then
574+
Buffer = New Byte(_BytesPerSector - 1) {}
567575
Array.Copy(MFMSector.Data, 0, Buffer, 0, SectorSize)
568576
BitstreamSector = New BitstreamSector(Buffer, Buffer.Length, False)
569577
SetSector(Track, Side, MFMSector.SectorId, BitstreamSector)
570-
ElseIf SectorSize = 512 Then
578+
ElseIf SectorSize = _BytesPerSector Then
571579
BitstreamSector = New BitstreamSector(MFMSector, IsStandard)
572580
SetSector(Track, Side, MFMSector.SectorId, BitstreamSector)
573581
End If

DiskImageTool/DiskImage/Modules/FloppyDiskFunctions.vb

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Namespace DiskImage
1919
FloppyXDFMicro = 14
2020
FloppyTandy2000 = 15
2121
FloppyNoBPB = 16
22-
FloppyJapanese = 17
22+
Floppy2HD = 17
2323
End Enum
2424

2525
Public Function BPBCompare(BPB As BiosParameterBlock, Params As FloppyDiskParams, CheckMediaDescriptor As Boolean) As Boolean
@@ -102,7 +102,7 @@ Namespace DiskImage
102102
Return &HF9
103103
Case FloppyDiskFormat.FloppyTandy2000
104104
Return &HED
105-
Case FloppyDiskFormat.FloppyJapanese
105+
Case FloppyDiskFormat.Floppy2HD
106106
Return &HFE
107107
Case Else
108108
Return &HF0
@@ -293,7 +293,7 @@ Namespace DiskImage
293293
Params.SectorsPerFAT = 2
294294
Params.SectorsPerTrack = 9
295295

296-
Case FloppyDiskFormat.FloppyJapanese
296+
Case FloppyDiskFormat.Floppy2HD
297297
Params.BytesPerSector = 1024
298298
Params.MediaDescriptor = &HFE
299299
Params.NumberOfFATs = 2
@@ -305,7 +305,7 @@ Namespace DiskImage
305305
Params.SectorsPerFAT = 2
306306
Params.SectorsPerTrack = 8
307307

308-
Case FloppyDiskFormat.FloppyNoBPB
308+
Case Else
309309
Params.BytesPerSector = 0
310310
Params.MediaDescriptor = 0
311311
Params.NumberOfFATs = 0
@@ -362,72 +362,78 @@ Namespace DiskImage
362362
End Function
363363

364364
Public Function GetFloppyDiskSize(DiskFormat As FloppyDiskFormat) As Integer
365+
Dim Size As Integer
366+
365367
Select Case DiskFormat
366368
Case FloppyDiskFormat.Floppy160
367-
Return 163840
369+
Size = 160
368370
Case FloppyDiskFormat.Floppy180
369-
Return 184320
371+
Size = 180
370372
Case FloppyDiskFormat.Floppy320
371-
Return 327680
373+
Size = 320
372374
Case FloppyDiskFormat.Floppy360
373-
Return 368640
375+
Size = 360
374376
Case FloppyDiskFormat.Floppy720
375-
Return 737280
377+
Size = 720
376378
Case FloppyDiskFormat.Floppy1200
377-
Return 1228800
379+
Size = 1200
378380
Case FloppyDiskFormat.Floppy1440
379-
Return 1474560
381+
Size = 1440
380382
Case FloppyDiskFormat.FloppyDMF1024
381-
Return 1720320
383+
Size = 1680
382384
Case FloppyDiskFormat.FloppyDMF2048
383-
Return 1720320
385+
Size = 1680
384386
Case FloppyDiskFormat.FloppyProCopy
385-
Return 1474560
387+
Size = 1440
386388
Case FloppyDiskFormat.FloppyXDF525
387-
Return 1556480
389+
Size = 1520
388390
Case FloppyDiskFormat.FloppyXDF35
389-
Return 1884160
391+
Size = 1840
390392
Case FloppyDiskFormat.FloppyXDFMicro
391-
Return 4096
393+
Size = 4
392394
Case FloppyDiskFormat.Floppy2880
393-
Return 2949120
395+
Size = 2880
394396
Case FloppyDiskFormat.FloppyTandy2000
395-
Return 737280
396-
Case FloppyDiskFormat.FloppyJapanese
397-
Return 1261568
397+
Size = 720
398+
Case FloppyDiskFormat.Floppy2HD
399+
Size = 1232
398400
Case Else
399-
Return 0
401+
Size = 0
400402
End Select
403+
404+
Return Size * 1024
401405
End Function
402406

403407
Public Function GetFloppyDiskFormat(Size As Integer) As FloppyDiskFormat
408+
Size = Math.Round(Size / 2048, 0, MidpointRounding.AwayFromZero) * 2
409+
404410
Select Case Size
405-
Case 163840
411+
Case 160
406412
Return FloppyDiskFormat.Floppy160
407-
Case 184320
413+
Case 180
408414
Return FloppyDiskFormat.Floppy180
409-
Case 327680
415+
Case 320
410416
Return FloppyDiskFormat.Floppy320
411-
Case 368640
417+
Case 360
412418
Return FloppyDiskFormat.Floppy360
413-
Case 737280
419+
Case 720
414420
Return FloppyDiskFormat.Floppy720
415-
Case 1228800
421+
Case 1200
416422
Return FloppyDiskFormat.Floppy1200
417-
Case 1474560
423+
Case 1440
418424
Return FloppyDiskFormat.Floppy1440
419-
Case 1720320
425+
Case 1680
420426
Return FloppyDiskFormat.FloppyDMF2048
421-
Case 1556480
427+
Case 1520
422428
Return FloppyDiskFormat.FloppyXDF525
423-
Case 1884160
429+
Case 1840
424430
Return FloppyDiskFormat.FloppyXDF35
425-
Case 4096
431+
Case 4
426432
Return FloppyDiskFormat.FloppyXDFMicro
427-
Case 2949120
433+
Case 2880
428434
Return FloppyDiskFormat.Floppy2880
429-
Case 1261568
430-
Return FloppyDiskFormat.FloppyJapanese
435+
Case 1232
436+
Return FloppyDiskFormat.Floppy2HD
431437
Case Else
432438
Return FloppyDiskFormat.FloppyUnknown
433439
End Select
@@ -466,7 +472,7 @@ Namespace DiskImage
466472
Case "Tandy 2000"
467473
Return FloppyDiskFormat.FloppyTandy2000
468474
Case "2HD (1.23M)"
469-
Return FloppyDiskFormat.FloppyJapanese
475+
Return FloppyDiskFormat.Floppy2HD
470476
Case "NO BPB"
471477
Return FloppyDiskFormat.FloppyNoBPB
472478
Case Else
@@ -514,7 +520,7 @@ Namespace DiskImage
514520
Return "XDF Micro"
515521
Case FloppyDiskFormat.FloppyTandy2000
516522
Return "Tandy 2000"
517-
Case FloppyDiskFormat.FloppyJapanese
523+
Case FloppyDiskFormat.Floppy2HD
518524
Return "2HD (1.23M)"
519525
Case FloppyDiskFormat.FloppyNoBPB
520526
Return "No BPB"
@@ -553,7 +559,7 @@ Namespace DiskImage
553559
Return ".xdf"
554560
Case FloppyDiskFormat.FloppyXDFMicro
555561
Return ".xdf"
556-
Case FloppyDiskFormat.FloppyJapanese
562+
Case FloppyDiskFormat.Floppy2HD
557563
Return ".hdm"
558564
Case Else
559565
Return ""
@@ -601,7 +607,6 @@ Namespace DiskImage
601607
Or DiskFormat = FloppyDiskFormat.FloppyProCopy _
602608
Or DiskFormat = FloppyDiskFormat.FloppyXDF35 _
603609
Or DiskFormat = FloppyDiskFormat.FloppyXDF525 _
604-
Or DiskFormat = FloppyDiskFormat.FloppyJapanese _
605610
Or DiskFormat = FloppyDiskFormat.FloppyXDFMicro Then
606611
Return False
607612
End If

DiskImageTool/DiskImageTool.vbproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<ProductName>DiskImageTool</ProductName>
3232
<PublisherName>Digitoxin</PublisherName>
3333
<ApplicationRevision>0</ApplicationRevision>
34-
<ApplicationVersion>2.13.0.%2a</ApplicationVersion>
34+
<ApplicationVersion>2.14.0.%2a</ApplicationVersion>
3535
<UseApplicationTrust>false</UseApplicationTrust>
3636
<PublishWizardCompleted>true</PublishWizardCompleted>
3737
<BootstrapperEnabled>true</BootstrapperEnabled>

0 commit comments

Comments
 (0)