private static TzxDataBlock ReadTzxDataBlock(BinaryReader fileReader) { TzxDataBlock resultDataBlock = null; byte id = fileReader.ReadByte(); TzxDataBlockType dataBlockType = TzxDataBlock.GetTZXDataBlockTypeFromID(id); switch (dataBlockType) { // ID 10 - Standard Speed Data Block case TzxDataBlockType.StandardSpeedDataBlock: resultDataBlock = new StandardSpeedDataBlock(); ReadStandardSpeedDataBlock(fileReader, (StandardSpeedDataBlock)resultDataBlock); break; // ID 11 - Turbo Speed Data Block case TzxDataBlockType.TurboSpeedDataBlock: resultDataBlock = new TurboSpeedDataBlock(); ReadTurboSpeedDataBlock(fileReader, (TurboSpeedDataBlock)resultDataBlock); break; // ID 12 - Pure Tone case TzxDataBlockType.PureTone: resultDataBlock = new PureTone(); ReadPureTone(fileReader, (PureTone)resultDataBlock); break; // ID 13 - Pulse sequence case TzxDataBlockType.PulseSequence: resultDataBlock = new PulseSequence(); ReadPulseSequence(fileReader, (PulseSequence)resultDataBlock); break; // ID 14 - Pure Data Block case TzxDataBlockType.PureDataBlock: resultDataBlock = new PureDataBlock(); ReadPureDataBlock(fileReader, (PureDataBlock)resultDataBlock); break; // ID 15 - Direct Recording case TzxDataBlockType.DirectRecording: resultDataBlock = new DirectRecording(); ReadDirectRecording(fileReader, (DirectRecording)resultDataBlock); break; // ID 20 - Pause (silence) or 'Stop the Tape' command case TzxDataBlockType.PauseOrStopTheTape: resultDataBlock = new PauseOrStopTheTape(); ReadPauseOrStopTheTape(fileReader, (PauseOrStopTheTape)resultDataBlock); break; // ID 21 - Group start case TzxDataBlockType.GroupStart: resultDataBlock = new GroupStart(); ReadGroupStart(fileReader, (GroupStart)resultDataBlock); break; // ID 22 - Group end case TzxDataBlockType.GroupEnd: resultDataBlock = new GroupEnd(); break; // ID 30 - Text description case TzxDataBlockType.TextDescription: resultDataBlock = new TextDescription(); ReadTextDescription(fileReader, (TextDescription)resultDataBlock); break; // ID 32 - Archive info case TzxDataBlockType.ArchiveInfo: resultDataBlock = new ArchiveInfo(); ReadArchiveInfo(fileReader, (ArchiveInfo)resultDataBlock); break; default: throw new NotImplementedException("TZX data block ID "+ id.ToString("X") + " is not yet implemented"); } return resultDataBlock; }
private static void ReadTextDescription(BinaryReader fileReader, TextDescription textDescription) { textDescription.Length = fileReader.ReadByte(); textDescription.Text = Encoding.GetEncoding("ISO-8859-1").GetString(fileReader.ReadBytes(textDescription.Length)); }