示例#1
0
        public static PULS_Block GetPulse(byte[] _buffer, int _counter, uint size)
        {
            PULS_Block block = new PULS_Block();

            int baseCount = _counter;

            while (_counter < baseCount + size)
            {
                Pulse p = new Pulse();
                p.count    = 1;
                p.duration = (System.BitConverter.ToUInt16(_buffer, _counter));
                _counter  += 2;
                if (p.duration > 0x8000)
                {
                    p.count    = (ushort)(p.duration & 0x7FFF);
                    p.duration = System.BitConverter.ToUInt16(_buffer, _counter);
                    _counter  += 2;
                }
                if (p.duration >= 0x8000)
                {
                    p.duration  &= 0x7FFF;
                    p.duration <<= 16;
                    p.duration  |= System.BitConverter.ToUInt16(_buffer, _counter);
                    _counter    += 2;
                }

                block.pulse.Add(p);
            }
            return(block);
        }
示例#2
0
        public static bool LoadPZX(System.IO.Stream fs)
        {
            blocks.Clear();
            tapeBlockInfo.Clear();
            using (System.IO.BinaryReader r = new System.IO.BinaryReader(fs)) {
                int bytesToRead = (int)fs.Length;

                byte[] buffer    = new byte[bytesToRead];
                int    bytesRead = r.Read(buffer, 0, bytesToRead);

                if (bytesRead == 0)
                {
                    return(false); //something bad happened!
                }
                int counter = 0;

                while (counter < bytesRead)
                {
                    //Read tag first (in a really lame way)
                    string blockTag = null;
                    for (int i = 0; i < 4; i++)
                    {
                        blockTag += (char)(buffer[counter++]);
                    }

                    uint blockSize = System.BitConverter.ToUInt32(buffer, counter);
                    counter += 4;

                    switch (blockTag)
                    {
                    case "PZXT":
                        PZXT_Header header = GetHeader(buffer, counter, blockSize);
                        header.tag  = "PZXT Header";
                        header.size = blockSize;
                        blocks.Add(header);
                        break;

                    case "PULS":
                        PULS_Block pblock = GetPulse(buffer, counter, blockSize);
                        pblock.tag  = "PULS";
                        pblock.size = blockSize;
                        blocks.Add(pblock);
                        break;

                    case "DATA":
                        DATA_Block dblock = GetData(buffer, counter, blockSize);
                        dblock.tag  = "DATA";
                        dblock.size = blockSize;
                        blocks.Add(dblock);
                        break;

                    case "PAUS":
                        PAUS_Block pauseBlock = new PAUS_Block();
                        pauseBlock.tag = "PAUS";
                        uint d = System.BitConverter.ToUInt32(buffer, counter);
                        pauseBlock.initialPulseLevel = ((d & 0x80000000) == 0 ? 0 : 1);
                        pauseBlock.duration          = (d & 0x7FFFFFFF);
                        pauseBlock.size = blockSize;
                        blocks.Add(pauseBlock);
                        break;

                    case "BRWS":
                        BRWS_Block brwsBlock = new BRWS_Block();
                        brwsBlock.tag = "BRWS";
                        int baseCount = counter;
                        brwsBlock.text = GetString(buffer, ref counter, (uint)counter + blockSize);
                        brwsBlock.size = blockSize;
                        counter        = baseCount;
                        blocks.Add(brwsBlock);
                        break;

                    case "STOP":
                        STOP_Block stopBlock = new STOP_Block();
                        stopBlock.tag  = "STOP";
                        stopBlock.flag = System.BitConverter.ToUInt16(buffer, counter);
                        stopBlock.size = blockSize;
                        blocks.Add(stopBlock);
                        break;

                    default:
                        break;
                    }
                    counter += (int)blockSize;
                }
            }
            return(true);
        }