Exemplo n.º 1
0
        /// <summary>
        /// ZXSTBETA128 - Beta 128 disk interface from Technology Research UK Ltd.
        /// </summary>
        #endregion
        private void applyB128(byte[] data)
        {
            var betaDisk = _spec.BusManager.FindDevice <IBetaDiskDevice>();

            if (betaDisk != null)
            {
                int    offset      = 0;
                int    dwFlags     = BitConverter.ToInt32(data, offset); offset += 4;
                byte   chNumDrives = data[offset]; offset += 1;
                byte   chSysReg    = data[offset]; offset += 1;
                byte   chTrackReg  = data[offset]; offset += 1;
                byte   chSectorReg = data[offset]; offset += 1;
                byte   chDataReg   = data[offset]; offset += 1;
                byte   chStatusReg = data[offset]; offset += 1;
                byte[] chRomData   = new byte[data.Length - offset];
                for (int i = 0; i < chRomData.Length; i++)
                {
                    chRomData[i] = data[i + offset];
                }

                if (chRomData.Length > 0 && (dwFlags & ZXSTBETAF_COMPRESSED) != 0)
                {
                    byte[] dataDecompressed = new byte[0x4000];
                    using (MemoryStream ms = new MemoryStream(chRomData))
                    {
                        ZipLib.Zip.Compression.Streams.InflaterInputStream inflater = new ZipLib.Zip.Compression.Streams.InflaterInputStream(ms);
                        inflater.Read(dataDecompressed, 0, dataDecompressed.Length);
                    }
                    chRomData = dataDecompressed;
                }

                betaDisk.DOSEN = (dwFlags & ZXSTBETAF_PAGED) != 0;
            }
        }
Exemplo n.º 2
0
        private static IEnumerable <int> LoadRleData(
            Stream stream,
            byte type,
            int dataSize)
        {
            if (type == 2)   // Z-RLE
            {
                stream = new ZipLib.Zip.Compression.Streams.InflaterInputStream(stream);
            }
            else if (type != 1)
            {
                throw new NotSupportedException(
                          string.Format(
                              "Unknown compression type: 0x{0:X2}!",
                              type));
            }
            var list = new List <int>();

            while ((type == 1 && stream.Position < stream.Length) ||
                   (type == 2 && list.Count < dataSize))
            {
                var buf  = new byte[4];
                var read = stream.Read(buf, 0, 1);
                if (read != 1)
                {
                    throw new EndOfStreamException("Unexpected end of stream");
                }
                if (buf[0] == 0)
                {
                    read = stream.Read(buf, 0, 4);
                    if (read != 4)
                    {
                        throw new EndOfStreamException("Unexpected end of stream");
                    }
                }
                var rle =
                    (buf[0] << 0) |
                    (buf[1] << 8) |
                    (buf[2] << 16) |
                    (buf[3] << 24);
                list.Add(rle);
            }
            return(list);
        }
Exemplo n.º 3
0
        /// <summary>
        /// ZXSTRAMPAGE - 16KB RAM page blocks, depending on the specific Spectrum model.
        /// </summary>
        #endregion
        private void apply_RAMP(byte[] data)
        {
            int    offset   = 0;
            UInt16 wFlags   = BitConverter.ToUInt16(data, offset); offset += 2;
            byte   chPageNo = data[offset]; offset += 1;

            var memory = _spec.BusManager.FindDevice <IMemoryDevice>();

            if (chPageNo >= memory.RamPages.Length)
            {
                Logger.Warn(
                    "SzxSerializer: skip block 'RAMP' chPageNo={0} (incompatible)",
                    chPageNo);
                return;
            }
            byte[] chData = new byte[data.Length - offset];
            for (int i = 0; i < chData.Length; i++)
            {
                chData[i] = data[i + offset];
            }

            if ((wFlags & ZXSTRF_COMPRESSED) != 0)
            {
                byte[] dataDecompressed = new byte[0x4000];
                using (MemoryStream ms = new MemoryStream(chData))
                {
                    ZipLib.Zip.Compression.Streams.InflaterInputStream inflater = new ZipLib.Zip.Compression.Streams.InflaterInputStream(ms);
                    inflater.Read(dataDecompressed, 0, dataDecompressed.Length);
                }
                chData = dataDecompressed;
            }

            //using (FileStream fs = new FileStream("_RAMP" + chPageNo.ToString("D2") + ".bin", FileMode.Create, FileAccess.Write, FileShare.Read))
            //    fs.Write(chData, 0, chData.Length);

            for (int i = 0; i < 0x4000; i++)
            {
                memory.RamPages[chPageNo][i] = chData[i];
            }
        }
Exemplo n.º 4
0
        private void apply_RAMP(byte[] data)
        {
            int offset = 0;
            UInt16 wFlags = BitConverter.ToUInt16(data, offset); offset += 2;
            byte chPageNo = data[offset]; offset += 1;

            var memory = _spec.BusManager.FindDevice<IMemoryDevice>();
            if (chPageNo >= memory.RamPages.Length)
            {
                LogAgent.Warn(
                    "SzxSerializer: skip block 'RAMP' chPageNo={0} (incompatible)",
                    chPageNo);
                return;
            }
            byte[] chData = new byte[data.Length - offset];
            for (int i = 0; i < chData.Length; i++)
            {
                chData[i] = data[i + offset];
            }

            if ((wFlags & ZXSTRF_COMPRESSED) != 0)
            {
                byte[] dataDecompressed = new byte[0x4000];
                using (MemoryStream ms = new MemoryStream(chData))
                {
                    ZipLib.Zip.Compression.Streams.InflaterInputStream inflater = new ZipLib.Zip.Compression.Streams.InflaterInputStream(ms);
                    inflater.Read(dataDecompressed, 0, dataDecompressed.Length);
                }
                chData = dataDecompressed;
            }

            //using (FileStream fs = new FileStream("_RAMP" + chPageNo.ToString("D2") + ".bin", FileMode.Create, FileAccess.Write, FileShare.Read))
            //    fs.Write(chData, 0, chData.Length);

            for (int i = 0; i < 0x4000; i++)
            {
                memory.RamPages[chPageNo][i] = chData[i];
            }
        }
Exemplo n.º 5
0
        private void applyB128(byte[] data)
        {
            var betaDisk = _spec.BusManager.FindDevice<IBetaDiskDevice>();
            if (betaDisk != null)
            {
                int offset = 0;
                int dwFlags = BitConverter.ToInt32(data, offset); offset += 4;
                byte chNumDrives = data[offset]; offset += 1;
                byte chSysReg = data[offset]; offset += 1;
                byte chTrackReg = data[offset]; offset += 1;
                byte chSectorReg = data[offset]; offset += 1;
                byte chDataReg = data[offset]; offset += 1;
                byte chStatusReg = data[offset]; offset += 1;
                byte[] chRomData = new byte[data.Length-offset];
                for (int i = 0; i < chRomData.Length; i++)
                    chRomData[i] = data[i + offset];

                if (chRomData.Length > 0 && (dwFlags & ZXSTBETAF_COMPRESSED) != 0)
                {
                    byte[] dataDecompressed = new byte[0x4000];
                    using (MemoryStream ms = new MemoryStream(chRomData))
                    {
                        ZipLib.Zip.Compression.Streams.InflaterInputStream inflater = new ZipLib.Zip.Compression.Streams.InflaterInputStream(ms);
                        inflater.Read(dataDecompressed, 0, dataDecompressed.Length);
                    }
                    chRomData = dataDecompressed;
                }

                betaDisk.DOSEN = (dwFlags & ZXSTBETAF_PAGED) != 0;
            }
        }