コード例 #1
0
        private void GenerateDataBlock(byte[] programbytes)
        {
            byte sectorCount = (byte)((programbytes.Length + 255) / 256);
            byte sectorIndex = 1;

            m_CrcGenerator.GeneratedCrcValue = 0;

            EncodeBlockLeading();

            TapeBlockHeader blockHeader =
                new TapeBlockHeader(m_CopyProtect)
            {
                SectorsInBlock = (byte)((programbytes.Length + 255) / 256)
            };

            m_CrcGenerator.AddBlock(blockHeader.ToByteArray(false));
            EncodeBlock(blockHeader.ToByteArray());

            while (sectorIndex <= sectorCount)
            {
                int sectorSize = programbytes.Length - 256 * (sectorIndex - 1);
                if (sectorSize > 255)
                {
                    sectorSize = 256;
                }

                TapeSectorHeader sectorHeader = new TapeSectorHeader
                {
                    SectorNumber  = sectorIndex,
                    BytesInSector = (byte)(sectorSize > 255 ? 0 : (byte)sectorSize)
                };

                m_CrcGenerator.AddBlock(sectorHeader.ToByteArray());
                EncodeBlock(sectorHeader.ToByteArray());
                byte[] sectorData  = new byte[sectorSize];
                int    sourceIndex = (sectorIndex - 1) * 256;
                Array.Copy(programbytes, sourceIndex, sectorData, 0, sectorSize);

                m_CrcGenerator.AddBlock(sectorData);
                EncodeBlock(sectorData);

                TapeSectorEnd sectorEnd =
                    new TapeSectorEnd {
                    EofFlag = (byte)(sectorIndex == sectorCount ? 0xff : 0x00)
                };

                m_CrcGenerator.AddByte(sectorEnd.EofFlag);
                sectorEnd.Crc = m_CrcGenerator.GeneratedCrcValue;
                EncodeBlock(sectorEnd.ToByteArray());
                m_CrcGenerator.GeneratedCrcValue = 0;
                sectorIndex++;
            }

            DirectDigitalSyntheser.GenerateSignal(GenerateFrequenyFromOffset(FreqLeading), 5, m_OutputWaves);
            DirectDigitalSyntheser.GenerateSilence(50, m_OutputWaves);
        }
コード例 #2
0
        private void GenerateHeaderBlock(int programlength)
        {
            // block leading
            EncodeBlockLeading();

            TapeBlockHeader blockHeader = new TapeBlockHeader(m_CopyProtect)
            {
                BlockType      = 0xff, // Header block
                SectorsInBlock = 1
            };

            m_CrcGenerator.AddBlock(blockHeader.ToByteArray(false));
            EncodeBlock(blockHeader.ToByteArray());

            TapeSectorHeader sectorHeader = new TapeSectorHeader
            {
                SectorNumber  = 0,
                BytesInSector = (byte)(m_FileName.Length + m_CasHeader.ToByteArray().Length + 1)
            };

            m_CrcGenerator.AddBlock(sectorHeader.ToByteArray());
            EncodeBlock(sectorHeader.ToByteArray());

            m_CrcGenerator.AddByte((byte)m_FileName.Length);
            EncodeByte((byte)m_FileName.Length);

            byte[] asciiFileName = Encoding.ASCII.GetBytes(m_FileName);
            m_CrcGenerator.AddBlock(asciiFileName);
            EncodeBlock(asciiFileName);

            m_CasHeader.FileLength = (ushort)programlength;
            m_CrcGenerator.AddBlock(m_CasHeader.ToByteArray());
            EncodeBlock(m_CasHeader.ToByteArray());

            TapeSectorEnd sectorEnd = new TapeSectorEnd
            {
                EofFlag = 0x00,
            };

            m_CrcGenerator.AddByte(sectorEnd.EofFlag);
            sectorEnd.Crc = m_CrcGenerator.GeneratedCrcValue;
            EncodeBlock(sectorEnd.ToByteArray());
            DirectDigitalSyntheser.GenerateSignal(GenerateFrequenyFromOffset(FreqLeading), 5, m_OutputWaves);
        }