File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11using OldBit . Spectron . Files . Serialization ;
2+ using OldBit . Spectron . Files . Szx . Extensions ;
23using OldBit . Spectron . Files . Tap ;
34using OldBit . Spectron . Files . Tzx . Blocks ;
45
@@ -12,20 +13,28 @@ internal class DataWriter(Stream stream)
1213 /// <summary>
1314 /// Writes a data block to the stream.
1415 /// </summary>
15- /// <param name="block">The block to write.</param>
16+ /// <param name="block">The block to write to the stream .</param>
1617 internal void Write ( IBlock block )
1718 {
1819 var data = FileDataSerializer . Serialize ( block ) ;
20+
1921 stream . Write ( data , 0 , data . Length ) ;
2022 }
2123
2224 /// <summary>
2325 /// Writes a TAP data to the stream.
2426 /// </summary>
25- /// <param name="tapData">The data to write.</param>
27+ /// <param name="tapData">The TAP data to write to the stream. .</param>
2628 internal void Write ( TapData tapData )
2729 {
2830 var data = FileDataSerializer . Serialize ( tapData ) ;
31+
2932 stream . Write ( data , 0 , data . Length ) ;
3033 }
34+
35+ /// <summary>
36+ /// Writes a word to the stream.
37+ /// </summary>
38+ /// <param name="value">The word value to write to the stream..</param>
39+ internal void WriteWord ( Word value ) => stream . WriteWord ( value ) ;
3140}
Original file line number Diff line number Diff line change @@ -9,6 +9,11 @@ namespace OldBit.Spectron.Files.Tap;
99/// </summary>
1010public sealed class TapData
1111{
12+ /// <summary>
13+ /// Gets the length of the block data.
14+ /// </summary>
15+ public Word Length => ( Word ) ( Data . Count + 2 ) ;
16+
1217 /// <summary>
1318 /// Gets or sets type of the block data.
1419 /// Typically, there are two standard values: 0x00 for header and 0xFF for data.
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ public static TapFile Load(Stream stream)
2828 {
2929 throw new InvalidDataException ( "Invalid TAP data." ) ;
3030 }
31+
3132 tapFile . Blocks . Add ( tapData ) ;
3233 }
3334
@@ -42,6 +43,7 @@ public static TapFile Load(Stream stream)
4243 public static TapFile Load ( string fileName )
4344 {
4445 using var stream = File . OpenRead ( fileName ) ;
46+
4547 return Load ( stream ) ;
4648 }
4749
@@ -52,8 +54,10 @@ public static TapFile Load(string fileName)
5254 public void Save ( Stream stream )
5355 {
5456 var writer = new DataWriter ( stream ) ;
57+
5558 foreach ( var block in Blocks )
5659 {
60+ writer . WriteWord ( block . Length ) ;
5761 writer . Write ( block ) ;
5862 }
5963 }
@@ -65,6 +69,7 @@ public void Save(Stream stream)
6569 public void Save ( string fileName )
6670 {
6771 using var stream = File . Create ( fileName ) ;
72+
6873 Save ( stream ) ;
6974 }
7075}
You can’t perform that action at this time.
0 commit comments