Skip to content

Commit 72acfd5

Browse files
committed
Update descriptions, convert tzx to tap
1 parent e25e57b commit 72acfd5

25 files changed

Lines changed: 112 additions & 27 deletions

src/Spectron.Files/Extensions/TapFileExtensions.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,25 @@ public static TzxFile ToTzx(this TapFile tapFile)
2828

2929
return tzx;
3030
}
31+
32+
/// <summary>
33+
/// Converts a TzxFile to a TapFile, only including standard speed data blocks.
34+
/// Any other block types will be ignored since they cannot be represented in a TapFile.
35+
/// </summary>
36+
/// <param name="tzxFile">The TzxFile to convert.</param>
37+
/// <returns>A TapFile containing the standard speed data blocks.</returns>
38+
public static TapFile ToTap(this TzxFile tzxFile)
39+
{
40+
var tap = new TapFile();
41+
42+
foreach (var block in tzxFile.Blocks.Where(b => b is StandardSpeedDataBlock).Cast<StandardSpeedDataBlock>())
43+
{
44+
if (TapData.TryParse(block.Data, out var tapData))
45+
{
46+
tap.Blocks.Add(tapData);
47+
}
48+
}
49+
50+
return tap;
51+
}
3152
}

src/Spectron.Files/Tzx/Blocks/ArchiveInfoBlock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ internal TextInfo(ByteStreamReader reader)
125125
/// <summary>
126126
/// Converts the TextInfo class to its equivalent string representation.
127127
/// </summary>
128-
/// <returns>The string representation of this object.</returns>
128+
/// <returns>A string representation of TextInfo object.</returns>
129129
public override string ToString() => Text;
130130
}
131131
}

src/Spectron.Files/Tzx/Blocks/CallSequenceBlock.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,10 @@ internal CallSequenceBlock(ByteStreamReader reader)
4545
.ReadWords(length)
4646
.Select(offset => (short)offset).ToList();
4747
}
48+
49+
/// <summary>
50+
/// Converts the 'Call Sequence' block class to its equivalent string representation.
51+
/// </summary>
52+
/// <returns>A string representation of 'Call Sequence' object.</returns>
53+
public override string ToString() => $"{Offsets.Count} call(s)";
4854
}

src/Spectron.Files/Tzx/Blocks/CustomInfoBlock.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,10 @@ internal CustomInfoBlock(ByteStreamReader reader)
5151
var length = reader.ReadDWord();
5252
Info.AddRange(reader.ReadBytes((int)length));
5353
}
54+
55+
/// <summary>
56+
/// Converts the 'Custom Info' block class to its equivalent string representation.
57+
/// </summary>
58+
/// <returns>A string representation of 'Custom Info' object.</returns>
59+
public override string ToString() => $"Custom Info: {Identification}";
5460
}

src/Spectron.Files/Tzx/Blocks/DirectRecordingBlock.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using OldBit.Spectron.Files.IO;
22
using OldBit.Spectron.Files.Serialization;
3+
using OldBit.Spectron.Files.Tap;
34

45
namespace OldBit.Spectron.Files.Tzx.Blocks;
56

@@ -65,4 +66,19 @@ internal DirectRecordingBlock(ByteStreamReader reader)
6566
var length = reader.ReadByte() | reader.ReadByte() << 8 | reader.ReadByte() << 16;
6667
Data.AddRange(reader.ReadBytes(length));
6768
}
69+
70+
/// <summary>
71+
/// Converts the 'Direct Recording' block to its equivalent string representation.
72+
/// </summary>
73+
/// <returns>A string representation of the 'Direct Recording' object which corresponds to
74+
/// Program name or Length value.</returns>
75+
public override string ToString()
76+
{
77+
if (TapData.TryParse(Data, out var tap))
78+
{
79+
return tap.ToString();
80+
}
81+
82+
return Length == 1 ? "1 byte" : $"{Length} bytes";
83+
}
6884
}

src/Spectron.Files/Tzx/Blocks/GlueBlock.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,10 @@ internal GlueBlock(ByteStreamReader reader)
3636
{
3737
Data = new List<byte>(reader.ReadBytes(9));
3838
}
39+
40+
/// <summary>
41+
/// Converts the 'Glue' block to its equivalent string representation.
42+
/// </summary>
43+
/// <returns>A string representation of the 'Glue' object.</returns>
44+
public override string ToString() => "Glue";
3945
}

src/Spectron.Files/Tzx/Blocks/GroupEndBlock.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,10 @@ public class GroupEndBlock : IBlock
1212
/// </summary>
1313
[FileData(Order = 0)]
1414
public byte BlockId => BlockCode.GroupEnd;
15+
16+
/// <summary>
17+
/// Converts the 'Group End' block to its equivalent string representation.
18+
/// </summary>
19+
/// <returns>A string representation of 'Group End' object.</returns>
20+
public override string ToString() => "Group End";
1521
}

src/Spectron.Files/Tzx/Blocks/GroupStartBlock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ internal GroupStartBlock(ByteStreamReader reader)
4848
/// <summary>
4949
/// Converts the 'Group Start' block to its equivalent string representation.
5050
/// </summary>
51-
/// <returns>The string representation of this object which corresponds to Name value.</returns>
51+
/// <returns>A string representation of the 'Group Start' object which corresponds to Name value.</returns>
5252
public override string ToString() => Name;
5353
}

src/Spectron.Files/Tzx/Blocks/HardwareTypeBlock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ internal HardwareInfo(ByteStreamReader reader)
9797
/// <summary>
9898
/// Converts the 'Hardware Info' to its equivalent string representation.
9999
/// </summary>
100-
/// <returns>The string representation of this object.</returns>
100+
/// <returns>A string representation of the 'Hardware Info' object.</returns>
101101
public override string ToString() => HardwareNames.GetName(HardwareTypeId, HardwareId);
102102
}
103103
}

src/Spectron.Files/Tzx/Blocks/JumpToBlock.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,10 @@ internal JumpToBlock(ByteStreamReader reader)
3535
{
3636
Jump = (short)reader.ReadWord();
3737
}
38+
39+
/// <summary>
40+
/// Converts the 'Jump To' block to its equivalent string representation.
41+
/// </summary>
42+
/// <returns>A string representation of the 'Jump To' object which corresponds to Name value.</returns>
43+
public override string ToString() => $"Jump to {Jump}";
3844
}

0 commit comments

Comments
 (0)