public TAPHeader GetHeader() { if (!IsHeader || !IsValid) { return(null); } TAPHeader header = new TAPHeader(); header.Type = (TAPSpectrumDataType)Data[1]; header.BinaryName = new byte[10]; Buffer.BlockCopy(Data, 2, header.BinaryName, 0, 10); header.Length = Word(Data, 12); header.Param1 = Word(Data, 14); header.Param2 = Word(Data, 16); header.Checksum = Data[18]; return(header); }
public static TAPFile Load(string FileName) { TAPFile file = new TAPFile(); byte[] data = File.ReadAllBytes(FileName); List <TAPBlock> blocks = new List <TAPBlock>(); int pos = 0; while (pos < data.Length) { TAPBlock block = TAPBlock.LoadBlock(data, pos, out pos); if (block == null) { return(null); } blocks.Add(block); } byte[] basicLoader = null; while (blocks.Count > 0) { if (blocks.Count < 2) { return(null); } TAPBlock headerBlock = blocks[0]; blocks.RemoveAt(0); TAPBlock dataBlock = blocks[0]; blocks.RemoveAt(0); if (!headerBlock.IsHeader || dataBlock.IsHeader || !headerBlock.IsValid || !dataBlock.IsValid) { return(null); } TAPHeader realHeader = headerBlock.GetHeader(); byte[] realData = dataBlock.GetData(); if (realHeader.Type == TAPSpectrumDataType.Program) { if (basicLoader != null) { return(null); } basicLoader = realData; } else if (realHeader.Type == TAPSpectrumDataType.Code) { if (realHeader.Length != realData.Length) { return(null); } Buffer.BlockCopy(realData, 0, file.Data, realHeader.Param1, realData.Length); if (realHeader.Param1 < file.StartAddress) { file.StartAddress = realHeader.Param1; } if (realHeader.Param1 + realData.Length > file.EndAddress) { file.EndAddress = realHeader.Param1 + realData.Length; } } else { return(null); } } if (basicLoader == null) { return(null); } file.Header = FindEntryPoint(basicLoader); if (file.Header == null) { return(null); } return(file); }