diff --git a/DumpDT18/DumpDectape.csproj b/DumpDT18/DumpDectape.csproj index c1098fc..75316bf 100644 --- a/DumpDT18/DumpDectape.csproj +++ b/DumpDT18/DumpDectape.csproj @@ -47,7 +47,9 @@ - + + PreserveNewest + PreserveNewest diff --git a/DumpDT18/Program.cs b/DumpDT18/Program.cs index c9a3cdc..c3573d4 100644 --- a/DumpDT18/Program.cs +++ b/DumpDT18/Program.cs @@ -44,7 +44,10 @@ namespace DumpDectape diagOutput = new FileStream(diagFileName, FileMode.Create, FileAccess.Write)) { IBlockProcessor blockProcessor = null; - int tapeBits = 0; + int tapeBits = 0; + + StreamWriter diagText = new StreamWriter(diagOutput); + diagText.AutoFlush = true; switch (_configuration.TapeType) { @@ -54,7 +57,7 @@ namespace DumpDectape break; case TapeType.Sixteen: - blockProcessor = new BlockProcessor16(tapeOutput); + blockProcessor = new BlockProcessor16(tapeOutput, diagText); tapeBits = 16; break; @@ -66,9 +69,7 @@ namespace DumpDectape default: throw new InvalidOperationException("Unexpected tape type."); } - - StreamWriter diagText = new StreamWriter(diagOutput); - diagText.AutoFlush = true; + diagText.WriteLine("Summary log for {0}-bit DECTape image {1} captured on {2}:", tapeBits, tapeFileName, DateTime.Now); Console.WriteLine("Initialized, waiting for tape data."); @@ -541,13 +542,14 @@ namespace DumpDectape public class BlockProcessor16 : IBlockProcessor { - public BlockProcessor16(Stream outputStream) + public BlockProcessor16(Stream outputStream, StreamWriter logStream) { _outStream = outputStream; _byteIndex36 = 0; _thirtySix = 0; _wordCount16 = 0; _blockDone = true; + _warnEighteen = false; } public bool BlockDone @@ -649,15 +651,27 @@ namespace DumpDectape } } - private static void WriteThirtySix(Stream outStream, ulong thirtySix) + private void WriteThirtySix(Stream outStream, ulong thirtySix) { - WriteSixteen(outStream, (uint)(thirtySix & 0xffff)); + // + // Verify that the top 2 bits of the two 18-bit words here are zero. + // If not, we might be mistakenly reading an 18-bit tape as a 16-bit one. + // That would be bad. Log a single message indicating a potential issue. + // + if (!_warnEighteen && + ((thirtySix & 0x30000) != 0 || + (thirtySix & 0xc00000000) != 0)) + { + Console.WriteLine("Warning: 18-bit data detected on tape -- this may be an 18-bit tape."); + _logStream.WriteLine("Warning: 18-bit data detected on tape -- this may be an 18-bit tape."); + _warnEighteen = true; + } - // TODO: verify this is correct. + WriteSixteen(outStream, (uint)(thirtySix & 0xffff)); WriteSixteen(outStream, (uint)((thirtySix & 0x3fffc0000) >> 18)); } - private static void WriteSixteen(Stream outStream, uint sixteen) + private void WriteSixteen(Stream outStream, uint sixteen) { outStream.WriteByte((byte) (sixteen & 0x00ff)); outStream.WriteByte((byte)((sixteen & 0xff00) >> 8)); @@ -675,7 +689,7 @@ namespace DumpDectape private ulong _thirtySix; /// - /// The number of 18-bit words we've read. + /// The number of 16-bit words we've read. /// private int _wordCount16; @@ -684,10 +698,20 @@ namespace DumpDectape /// private bool _blockDone; + /// + /// Whether we've given the "hey, this might be an 18-bit tape" warning before. + /// + private bool _warnEighteen; + /// /// The stream we'll flush the data to. /// private Stream _outStream; + + /// + /// The log stream, in case we need to log a warning. + /// + private StreamWriter _logStream; } public class BlockProcessor12 : IBlockProcessor @@ -778,17 +802,17 @@ namespace DumpDectape } /// - /// The current byte index into the two 36-bit words we're building + /// The current byte index into the two 12-bit words we're building /// private int _byteIndex12; /// - /// The current 36-bit word we've built + /// The current 12-bit word we've built /// private ulong _twelve; /// - /// The number of 18-bit words we've read. + /// The number of 12-bit words we've read. /// private int _wordCount12;