Example #1
0
            public static Td0Serializer.TD0_MAIN_HEADER Deserialize(Stream stream)
            {
                Td0Serializer.TD0_MAIN_HEADER td0_MAIN_HEADER = new Td0Serializer.TD0_MAIN_HEADER();
                stream.Read(td0_MAIN_HEADER._buffer, 0, td0_MAIN_HEADER._buffer.Length);
                ushort @uint = FormatSerializer.getUInt16(td0_MAIN_HEADER._buffer, 0);

                if (@uint != 17492 && @uint != 25716)
                {
                    Logger.GetLogger().LogError("TD0 loader: Invalid header ID");
                    PlatformFactory.Platform.ShowWarning("Invalid header ID", "TD0 loader");
                    return(null);
                }
                ushort num   = Td0Serializer.CalculateTD0CRC(td0_MAIN_HEADER._buffer, 0, td0_MAIN_HEADER._buffer.Length - 2);
                ushort uint2 = FormatSerializer.getUInt16(td0_MAIN_HEADER._buffer, 10);

                if (uint2 != num)
                {
                    Logger.GetLogger().LogWarning(string.Concat(new string[]
                    {
                        "TD0 loader: Main header had bad CRC=0x",
                        num.ToString("X4"),
                        " (stamp crc=0x",
                        uint2.ToString("X4"),
                        ")"
                    }));
                    PlatformFactory.Platform.ShowWarning("Wrong main header CRC", "TD0 loader");
                }
                return(td0_MAIN_HEADER);
            }
Example #2
0
        private void loadFromStream(Stream stream)
        {
            byte[] array  = new byte[49284];
            byte[] array2 = new byte[202];
            if (stream.Length != 49486L)
            {
                PlatformFactory.Platform.ShowWarning("Invalid file size, file corrupt!", "ZX loader");
                return;
            }
            stream.Read(array, 0, array.Length);
            stream.Read(array2, 0, array2.Length);
            this._spec.CPU.Tact += 1000UL;
            this._spec.DoReset();
            if (this._spec is IBetaDiskDevice)
            {
                ((IBetaDiskDevice)this._spec).SEL_TRDOS = false;
            }
            if (this._spec is ISpectrum128K)
            {
                ((ISpectrum128K)this._spec).Port7FFD = 48;
            }
            this._spec.SetRamImage(5, array, 132, 16384);
            this._spec.SetRamImage(2, array, 16516, 16384);
            this._spec.SetRamImage(0, array, 32900, 16384);
            this._spec.CPU.regs._HL = (ushort)((int)array2[160] << 8 | (int)array2[161]);
            this._spec.CPU.regs._DE = (ushort)((int)array2[156] << 8 | (int)array2[157]);
            this._spec.CPU.regs._BC = (ushort)((int)array2[152] << 8 | (int)array2[153]);
            this._spec.CPU.regs._AF = (ushort)((int)array2[171] << 8 | (int)array2[175]);
            this._spec.CPU.regs.HL  = (ushort)((int)array2[158] << 8 | (int)array2[159]);
            this._spec.CPU.regs.DE  = (ushort)((int)array2[154] << 8 | (int)array2[155]);
            this._spec.CPU.regs.BC  = (ushort)((int)array2[150] << 8 | (int)array2[151]);
            this._spec.CPU.regs.AF  = (ushort)((int)array2[173] << 8 | (int)array2[177]);
            this._spec.CPU.regs.IR  = (ushort)((int)array2[166] << 8 | (int)array2[167]);
            this._spec.CPU.regs.IX  = (ushort)((int)array2[162] << 8 | (int)array2[163]);
            this._spec.CPU.regs.IY  = (ushort)((int)array2[164] << 8 | (int)array2[165]);
            this._spec.CPU.regs.SP  = (ushort)((int)array2[184] << 8 | (int)array2[185]);
            this._spec.CPU.regs.PC  = (ushort)((int)array2[180] << 8 | (int)array2[181]);
            switch (FormatSerializer.getUInt16(array2, 190))
            {
            case 0:
                this._spec.CPU.IM = 1;
                break;

            case 1:
                this._spec.CPU.IM = 2;
                break;

            default:
                this._spec.CPU.IM = 0;
                break;
            }
            this._spec.CPU.IFF1   = ((array2[142] & 1) != 0);
            this._spec.CPU.IFF2   = ((array2[142] & 1) != 0);
            this._spec.CPU.HALTED = ((array2[189] & 1) != 0);
        }
Example #3
0
 private void loadFromStream(Stream stream)
 {
     byte[] array  = new byte[28];
     byte[] array2 = new byte[16384];
     byte[] array3 = new byte[49152];
     if (stream.Length != 65564L)
     {
         PlatformFactory.Platform.ShowWarning("Invalid data, file corrupt!", "SIT loader");
         return;
     }
     stream.Read(array, 0, array.Length);
     stream.Read(array2, 0, 16384);
     stream.Read(array3, 0, 49152);
     this._spec.CPU.Tact += 1000UL;
     this._spec.DoReset();
     if (this._spec is IBetaDiskDevice)
     {
         ((IBetaDiskDevice)this._spec).SEL_TRDOS = false;
     }
     if (this._spec is ISpectrum128K)
     {
         ((ISpectrum128K)this._spec).Port7FFD = 48;
     }
     this._spec.SetRomImage(RomName.ROM_48, array2, 0, 16384);
     this._spec.SetRamImage(5, array3, 0, 16384);
     this._spec.SetRamImage(2, array3, 16384, 16384);
     this._spec.SetRamImage(0, array3, 32768, 16384);
     this._spec.CPU.regs.BC  = FormatSerializer.getUInt16(array, 0);
     this._spec.CPU.regs.DE  = FormatSerializer.getUInt16(array, 2);
     this._spec.CPU.regs.HL  = FormatSerializer.getUInt16(array, 4);
     this._spec.CPU.regs.AF  = FormatSerializer.getUInt16(array, 6);
     this._spec.CPU.regs.IX  = FormatSerializer.getUInt16(array, 8);
     this._spec.CPU.regs.IY  = FormatSerializer.getUInt16(array, 10);
     this._spec.CPU.regs.SP  = FormatSerializer.getUInt16(array, 12);
     this._spec.CPU.regs.PC  = FormatSerializer.getUInt16(array, 14);
     this._spec.CPU.regs.IR  = FormatSerializer.getUInt16(array, 16);
     this._spec.CPU.regs._BC = FormatSerializer.getUInt16(array, 18);
     this._spec.CPU.regs._DE = FormatSerializer.getUInt16(array, 20);
     this._spec.CPU.regs._HL = FormatSerializer.getUInt16(array, 22);
     this._spec.CPU.regs._AF = FormatSerializer.getUInt16(array, 24);
     this._spec.CPU.IM       = (byte)((array[26] & 2));
     if (this._spec.CPU.IM == 0)
     {
         this._spec.CPU.IM = 1;
     }
     this._spec.CPU.IFF2 = ((array[26] & 1) != 0);
     this._spec.CPU.IFF2 = this._spec.CPU.IFF1;
     if (this._spec is ISpectrum)
     {
         ((ISpectrum)this._spec).PortFE = array[27];
     }
     this._spec.CPU.HALTED = false;
 }
Example #4
0
        private static ushort CalculateTD0CRC(byte[] buffer, int startIndex, int length)
        {
            ushort num = 0;

            for (int i = 0; i < length; i++)
            {
                num ^= (ushort)buffer[startIndex++];
                int num2 = (int)(num & 255);
                num &= 65280;
                num  = (ushort)((int)num << 8 | num >> 8);
                num ^= FormatSerializer.getUInt16(Td0Serializer.tbltd0crc, num2 * 2);
            }
            return((ushort)((int)num << 8 | num >> 8));
        }
Example #5
0
        public static string getBlockDescription(byte[] block, int indexOffset, int blockLength)
        {
            string str = string.Empty;
            byte   b   = 0;

            byte[] array = new byte[10];
            for (int i = 0; i < blockLength; i++)
            {
                b ^= block[indexOffset + i];
            }
            if (block[indexOffset] == 0 && blockLength == 19 && (block[indexOffset + 1] == 0 || block[indexOffset + 1] == 3))
            {
                for (int j = 0; j < 10; j++)
                {
                    array[j] = ((byte)((block[indexOffset + j + 2] < 32 || block[indexOffset + j + 2] >= 128) ? 63 : block[indexOffset + j + 2]));
                }
                string @string = Encoding.ASCII.GetString(array, 0, 10);
                string text    = (block[indexOffset + 1] != 0) ? "Bytes" : "Program";
                str = string.Format("{0}: \"{1}\" {2},{3}", new object[]
                {
                    text,
                    @string,
                    FormatSerializer.getUInt16(block, indexOffset + 14),
                    FormatSerializer.getUInt16(block, indexOffset + 12)
                });
            }
            else if (block[indexOffset] == 255)
            {
                str = string.Format("Data block, {0} bytes", blockLength - 2);
            }
            else
            {
                str = string.Format("#{0} block, {1} bytes", block[indexOffset].ToString("X2"), blockLength - 2);
            }
            return(str + string.Format(", crc {0}", (b != 0) ? "bad" : "ok"));
        }
Example #6
0
            public static Td0Serializer.TD0_SECTOR Deserialize(Stream stream)
            {
                Td0Serializer.TD0_SECTOR td0_SECTOR = new Td0Serializer.TD0_SECTOR();
                byte[] array = new byte[6];
                stream.Read(array, 0, 6);
                td0_SECTOR._admark = array;
                byte[] array2 = new byte[2];
                stream.Read(array2, 0, 2);
                byte[] array3 = new byte[(int)FormatSerializer.getUInt16(array2, 0)];
                stream.Read(array3, 0, array3.Length);
                td0_SECTOR._data = Td0Serializer.TD0_SECTOR.unpackData(array3);
                ushort num = Td0Serializer.CalculateTD0CRC(td0_SECTOR._data, 0, td0_SECTOR._data.Length);

                if ((ushort)array[5] != (num & 255))
                {
                    Logger.GetLogger().LogWarning(string.Concat(new string[]
                    {
                        "TD0 loader: Sector data had bad CRC=0x",
                        num.ToString("X4"),
                        " (stamp crc=0x",
                        array[5].ToString("X2"),
                        ") [C:",
                        td0_SECTOR.C.ToString("X2"),
                        ";H:",
                        td0_SECTOR.H.ToString("X2"),
                        ";R:",
                        td0_SECTOR.R.ToString("X2"),
                        ";N:",
                        td0_SECTOR.N.ToString("X2")
                    }));
                    PlatformFactory.Platform.ShowWarning("Sector data had bad CRC", "TD0 loader");
                }
                td0_SECTOR.SetAdCrc(true);
                td0_SECTOR.SetDataCrc((td0_SECTOR.Td0Flags & Td0Serializer.SectorFlags.BadCrc) == (Td0Serializer.SectorFlags) 0);
                return(td0_SECTOR);
            }
Example #7
0
        private void loadFromStream(Stream stream)
        {
            byte[] array  = new byte[30];
            byte[] array2 = new byte[25];
            stream.Read(array, 0, 30);
            if (array[12] == 255)
            {
                array[12] = 1;
            }
            int num = 1;

            if (FormatSerializer.getUInt16(array, 6) == 0)
            {
                num = 2;
                stream.Read(array2, 0, 25);
                if (array2[0] == 54)
                {
                    num = 3;
                    byte[] buffer = new byte[31];
                    stream.Read(buffer, 0, 31);
                }
                else if (array2[0] != 23)
                {
                    PlatformFactory.Platform.ShowWarning("Z80 format version not recognized!\n(ExtensionSize = " + array2[0].ToString() + ",\nsupported only ExtensionSize={0(old format), 23, 54})", "Z80 loader");
                    return;
                }
            }
            this._spec.CPU.Tact += 1000UL;
            this._spec.DoReset();
            if (this._spec is IBetaDiskDevice)
            {
                ((IBetaDiskDevice)this._spec).SEL_TRDOS = false;
            }
            this._spec.CPU.regs.A   = array[0];
            this._spec.CPU.regs.F   = array[1];
            this._spec.CPU.regs.HL  = FormatSerializer.getUInt16(array, 4);
            this._spec.CPU.regs.DE  = FormatSerializer.getUInt16(array, 13);
            this._spec.CPU.regs.BC  = FormatSerializer.getUInt16(array, 2);
            this._spec.CPU.regs._AF = (ushort)((int)array[21] * 256 + (int)array[22]);
            this._spec.CPU.regs._HL = FormatSerializer.getUInt16(array, 19);
            this._spec.CPU.regs._DE = FormatSerializer.getUInt16(array, 17);
            this._spec.CPU.regs._BC = FormatSerializer.getUInt16(array, 15);
            this._spec.CPU.regs.IX  = FormatSerializer.getUInt16(array, 25);
            this._spec.CPU.regs.IY  = FormatSerializer.getUInt16(array, 23);
            this._spec.CPU.regs.SP  = FormatSerializer.getUInt16(array, 8);
            this._spec.CPU.regs.I   = array[10];
            this._spec.CPU.regs.R   = (byte)((array[11] | (((array[12] & 1) != 0) ? 128 : 0)));
            if (num == 1)
            {
                this._spec.CPU.regs.PC = FormatSerializer.getUInt16(array, 6);
            }
            else
            {
                this._spec.CPU.regs.PC = FormatSerializer.getUInt16(array2, 2);
            }
            this._spec.CPU.IFF1   = (array[27] != 0);
            this._spec.CPU.IFF2   = (array[28] != 0);
            this._spec.CPU.IM     = (byte)((array[29] & 3));
            this._spec.CPU.HALTED = false;
            if (this._spec is ISpectrum)
            {
                ((ISpectrum)this._spec).PortFE = (byte)(array[12] >> 1 & 7);
            }
            if (num > 1)
            {
                if (array2[6] == 255)
                {
                    PlatformFactory.Platform.ShowWarning("Interface I not implemented, but Interface I ROM required!", "Z80 loader");
                }
                IAyDevice ayDevice = this._spec as IAyDevice;
                if (ayDevice != null)
                {
                    for (int i = 0; i < 16; i++)
                    {
                        ayDevice.Sound.ADDR_REG = (byte)i;
                        ayDevice.Sound.DATA_REG = array2[9 + i];
                    }
                }
            }
            bool flag  = (array[12] & 32) != 0;
            bool flag2 = false;

            if (num == 2)
            {
                switch (array2[4])
                {
                case 0:
                case 1:
                    goto IL_42F;

                case 2:
                    PlatformFactory.Platform.ShowWarning("SamRam not implemented!", "Z80 loader");
                    goto IL_42F;

                case 3:
                case 4:
                case 9:
                case 10:
                    flag2 = true;
                    goto IL_42F;
                }
                PlatformFactory.Platform.ShowWarning("Unrecognized ZX Spectrum config (" + array2[4].ToString() + ")!", "Z80 loader");
            }
IL_42F:
            if (num == 3)
            {
                switch (array2[4])
                {
                case 0:
                case 1:
                case 2:
                    PlatformFactory.Platform.ShowWarning("SamRam not implemented!", "Z80 loader");
                    goto IL_4B2;

                case 3:
                    goto IL_4B2;

                case 4:
                case 5:
                case 6:
                case 9:
                case 10:
                    flag2 = true;
                    goto IL_4B2;
                }
                PlatformFactory.Platform.ShowWarning("Unrecognized ZX Spectrum config (" + array2[4].ToString() + ")!", "Z80 loader");
            }
IL_4B2:
            byte b;

            if (num == 1)
            {
                b = 48;
            }
            else if (flag2)
            {
                b = array2[5];
            }
            else
            {
                b = 48;
            }
            if (this._spec is ISpectrum128K)
            {
                ((ISpectrum128K)this._spec).Port7FFD = b;
            }
            if (num == 1)
            {
                int num2 = (int)(stream.Length - stream.Position);
                if (num2 < 0)
                {
                    num2 = 0;
                }
                byte[] array3 = new byte[num2 + 1024];
                stream.Read(array3, 0, num2);
                byte[] array4 = new byte[131071];
                if (flag)
                {
                    this.DecompressZ80(array4, array3, 49152);
                }
                else
                {
                    for (int j = 0; j < 49152; j++)
                    {
                        array4[j] = array3[j];
                    }
                }
                int page = (int)(b & 7);
                this._spec.SetRamImage(5, array4, 0, 16384);
                this._spec.SetRamImage(2, array4, 16384, 16384);
                this._spec.SetRamImage(page, array4, 32768, 16384);
                return;
            }
            byte[] array5 = new byte[4];
            byte[] array6 = new byte[129000];
            byte[] array7 = new byte[16384];
            while (stream.Position < stream.Length)
            {
                stream.Read(array5, 0, 2);
                int @uint = (int)FormatSerializer.getUInt16(array5, 0);
                stream.Read(array5, 0, 1);
                int num3 = (int)array5[0];
                stream.Read(array6, 0, @uint);
                this.DecompressZ80(array7, array6, 16384);
                if (num3 >= 3 && num3 <= 10 && flag2)
                {
                    this._spec.SetRamImage(num3 - 3 & 7, array7, 0, 16384);
                }
                else if ((num3 == 4 || num3 == 5 || num3 == 8) && !flag2)
                {
                    int page2 = (int)(b & 7);
                    if (num3 == 8)
                    {
                        page2 = 5;
                    }
                    if (num3 == 4)
                    {
                        page2 = 2;
                    }
                    this._spec.SetRamImage(page2, array7, 0, 16384);
                }
                else if (num3 == 0)
                {
                    this._spec.SetRomImage(RomName.ROM_48, array7, 0, 16384);
                    PlatformFactory.Platform.ShowWarning("ROM 48K loaded from snapshot!", "Z80 loader");
                }
                else if (num3 == 2)
                {
                    this._spec.SetRomImage(RomName.ROM_128, array7, 0, 16384);
                    PlatformFactory.Platform.ShowWarning("ROM 128K loaded from snapshot!", "Z80 loader");
                }
            }
        }
Example #8
0
        private void saveToStream(Stream stream)
        {
            byte[] array  = new byte[30];
            byte[] array2 = new byte[25];
            FormatSerializer.setUint16(array, 6, 0);
            FormatSerializer.setUint16(array2, 0, 23);
            array[0] = this._spec.CPU.regs.A;
            array[1] = this._spec.CPU.regs.F;
            FormatSerializer.setUint16(array, 4, this._spec.CPU.regs.HL);
            FormatSerializer.setUint16(array, 13, this._spec.CPU.regs.DE);
            FormatSerializer.setUint16(array, 2, this._spec.CPU.regs.BC);
            array[21] = (byte)(this._spec.CPU.regs._AF >> 8);
            array[22] = (byte)this._spec.CPU.regs._AF;
            FormatSerializer.setUint16(array, 19, this._spec.CPU.regs._HL);
            FormatSerializer.setUint16(array, 17, this._spec.CPU.regs._DE);
            FormatSerializer.setUint16(array, 15, this._spec.CPU.regs._BC);
            FormatSerializer.setUint16(array, 25, this._spec.CPU.regs.IX);
            FormatSerializer.setUint16(array, 23, this._spec.CPU.regs.IY);
            FormatSerializer.setUint16(array, 8, this._spec.CPU.regs.SP);
            array[10] = this._spec.CPU.regs.I;
            array[11] = (byte)((this._spec.CPU.regs.R & 127));
            if ((this._spec.CPU.regs.R & 128) != 0)
            {
                byte[] array3 = array;
                int    num    = 12;
                array3[num] |= 1;
            }
            byte b = byte.MaxValue;

            if (this._spec is ISpectrum)
            {
                b = ((ISpectrum)this._spec).PortFE;
            }
            array[12] = (byte)((b & 7) << 1);
            byte[] array4 = array;
            int    num2   = 12;

            array4[num2] |= 32;
            FormatSerializer.setUint16(array2, 2, this._spec.CPU.regs.PC);
            if (this._spec.CPU.IFF1)
            {
                array[27] = byte.MaxValue;
            }
            else
            {
                array[27] = 0;
            }
            if (this._spec.CPU.IFF2)
            {
                array[28] = byte.MaxValue;
            }
            else
            {
                array[28] = 0;
            }
            array[29] = this._spec.CPU.IM;
            if (this._spec.CPU.IM > 2)
            {
                array[29] = 0;
            }
            byte b2 = 48;

            if (this._spec is ISpectrum128K)
            {
                b2 = ((ISpectrum128K)this._spec).Port7FFD;
            }
            bool flag = (b2 & 48) != 48;

            if (!flag)
            {
                FormatSerializer.setUint16(array, 6, this._spec.CPU.regs.PC);
            }
            array2[4] = 3;
            array2[5] = b2;
            array2[6] = 0;
            array2[7] = 3;
            array2[8] = 14;
            IAyDevice ayDevice = this._spec as IAyDevice;

            if (ayDevice != null)
            {
                byte addr_REG = ayDevice.Sound.ADDR_REG;
                for (int i = 0; i < 16; i++)
                {
                    ayDevice.Sound.ADDR_REG = (byte)i;
                    array2[9 + i]           = ayDevice.Sound.DATA_REG;
                }
                ayDevice.Sound.ADDR_REG = addr_REG;
            }
            byte[] array5 = new byte[200000];
            if (!flag)
            {
                byte[] array6 = new byte[65535];
                this._spec.GetRamImage(5).CopyTo(array6, 0);
                this._spec.GetRamImage(2).CopyTo(array6, 16384);
                this._spec.GetRamImage((int)(b2 & 7)).CopyTo(array6, 32768);
                int num3 = this.CompressZ80(array5, array6, 49152);
                if (num3 + 4 >= 49152)
                {
                    byte[] array7 = array;
                    int    num4   = 12;
                    array7[num4] &= 223;
                    num3          = 49152;
                    for (int j = 0; j < num3; j++)
                    {
                        array5[j] = array6[j];
                    }
                }
                stream.Write(array, 0, 30);
                stream.Write(array5, 0, num3);
                if ((array[12] & 32) != 0)
                {
                    byte[] array8 = new byte[4];
                    array8[1] = 237;
                    array8[2] = 237;
                    byte[] buffer = array8;
                    stream.Write(buffer, 0, 4);
                    return;
                }
            }
            else
            {
                stream.Write(array, 0, 30);
                stream.Write(array2, 0, 25);
                for (int k = 0; k < 8; k++)
                {
                    int num3  = this.CompressZ80(array5, this._spec.GetRamImage(k), 16384);
                    int value = (k & 7) + 3;
                    stream.Write(FormatSerializer.getBytes(num3), 0, 2);
                    stream.Write(FormatSerializer.getBytes(value), 0, 1);
                    stream.Write(array5, 0, num3);
                }
            }
        }
Example #9
0
        private bool loadData(Stream stream)
        {
            Td0Serializer.TD0_MAIN_HEADER td0_MAIN_HEADER = Td0Serializer.TD0_MAIN_HEADER.Deserialize(stream);
            if (td0_MAIN_HEADER == null)
            {
                return(false);
            }
            if (td0_MAIN_HEADER.Ver > 21 || td0_MAIN_HEADER.Ver < 10)
            {
                PlatformFactory.Platform.ShowWarning("Format version is not supported [0x" + td0_MAIN_HEADER.Ver.ToString("X2") + "]", "TD0 loader");
                return(false);
            }
            if (td0_MAIN_HEADER.DataDOS != 0)
            {
                PlatformFactory.Platform.ShowWarning("'DOS Allocated sectors were copied' option is not supported!", "TD0 loader");
                return(false);
            }
            Stream stream2 = stream;

            if (td0_MAIN_HEADER.IsAdvandcedCompression)
            {
                if (td0_MAIN_HEADER.Ver < 20)
                {
                    PlatformFactory.Platform.ShowWarning("Old Advanced compression is not implemented!", "TD0 loader");
                    return(false);
                }
                stream2 = new LzssHuffmanStream(stream);
            }
            string description = string.Empty;

            if ((td0_MAIN_HEADER.Info & 128) != 0)
            {
                byte[] array = new byte[4];
                stream2.Read(array, 0, 2);
                stream2.Read(array, 2, 2);
                byte[] array2 = new byte[(int)(FormatSerializer.getUInt16(array, 2) + 10)];
                for (int i = 0; i < 4; i++)
                {
                    array2[i] = array[i];
                }
                stream2.Read(array2, 4, 6);
                stream2.Read(array2, 10, array2.Length - 10);
                if (Td0Serializer.CalculateTD0CRC(array2, 2, (int)(8 + FormatSerializer.getUInt16(array2, 2))) != FormatSerializer.getUInt16(array2, 0))
                {
                    PlatformFactory.Platform.ShowWarning("Info crc wrong", "TD0 loader");
                }
                StringBuilder stringBuilder = new StringBuilder();
                int           num           = 10;
                for (int j = 10; j < array2.Length; j++)
                {
                    if (array2[j] == 0 && j > num)
                    {
                        stringBuilder.Append(Encoding.ASCII.GetString(array2, num, j - num));
                        stringBuilder.Append("\n");
                        num = j + 1;
                    }
                }
                description = stringBuilder.ToString();
            }
            int       num2      = -1;
            int       num3      = -1;
            ArrayList arrayList = new ArrayList();

            for (;;)
            {
                Td0Serializer.TD0_TRACK td0_TRACK = Td0Serializer.TD0_TRACK.Deserialize(stream2);
                if (td0_TRACK.SectorCount == 255)
                {
                    break;
                }
                arrayList.Add(td0_TRACK);
                if (num2 < td0_TRACK.Cylinder)
                {
                    num2 = td0_TRACK.Cylinder;
                }
                if (num3 < td0_TRACK.Side)
                {
                    num3 = td0_TRACK.Side;
                }
            }
            num2++;
            num3++;
            if (num2 < 1 || num3 < 1)
            {
                PlatformFactory.Platform.ShowWarning("Invalid disk structure", "td0");
                return(false);
            }
            this._diskImage.Init(num2, num3);
            foreach (object obj in arrayList)
            {
                Td0Serializer.TD0_TRACK td0_TRACK2 = (Td0Serializer.TD0_TRACK)obj;
                this._diskImage.GetTrackImage(td0_TRACK2.Cylinder, td0_TRACK2.Side).AssignSectors(td0_TRACK2.SectorList);
            }
            this._diskImage.Description = description;
            return(true);
        }
Example #10
0
            private static byte[] unpackData(byte[] buffer)
            {
                List <byte> list = new List <byte>();

                switch (buffer[0])
                {
                case 0:
                    for (int i = 1; i < buffer.Length; i++)
                    {
                        list.Add(buffer[i]);
                    }
                    break;

                case 1:
                {
                    int num = (int)FormatSerializer.getUInt16(buffer, 1);
                    for (int j = 0; j < num; j++)
                    {
                        list.Add(buffer[3]);
                        list.Add(buffer[4]);
                    }
                    break;
                }

                case 2:
                {
                    int num2 = 1;
                    do
                    {
                        switch (buffer[num2++])
                        {
                        case 0:
                        {
                            int num = (int)buffer[num2++];
                            for (int k = 0; k < num; k++)
                            {
                                list.Add(buffer[num2++]);
                            }
                            break;
                        }

                        case 1:
                        {
                            int num = (int)buffer[num2++];
                            for (int l = 0; l < num; l++)
                            {
                                list.Add(buffer[num2]);
                                list.Add(buffer[num2 + 1]);
                            }
                            num2 += 2;
                            break;
                        }

                        default:
                            PlatformFactory.Platform.ShowWarning("Unknown sector encoding!", "TD0 loader");
                            num2 = buffer.Length;
                            break;
                        }
                    }while (num2 < buffer.Length);
                    break;
                }
                }
                return(list.ToArray());
            }
Example #11
0
        public override void Deserialize(Stream stream)
        {
            byte[] array = new byte[stream.Length];
            stream.Read(array, 0, array.Length);
            if (Encoding.ASCII.GetString(array, 0, 7) != "ZXTape!" || array[7] != 26)
            {
                PlatformFactory.Platform.ShowWarning("Invalid TZX file, identifier not found! ", "TZX loader");
                return;
            }
            int i    = 0;
            int num  = 0;
            int num2 = 0;

            while (i < array.Length)
            {
                byte      b = array[i++];
                TapeBlock tapeBlock;
                switch (b)
                {
                case 16:
                {
                    tapeBlock = new TapeBlock();
                    int num3 = (int)FormatSerializer.getUInt16(array, i + 2);
                    int num4 = (int)FormatSerializer.getUInt16(array, i);
                    i += 4;
                    tapeBlock.Description = TapSerializer.getBlockDescription(array, i, num3);
                    tapeBlock.Periods     = TapSerializer.getBlockPeriods(array, i, num3, 2168, 667, 735, 855, 1710, (array[i] < 4) ? 8064 : 3220, num4, 8);
                    i += num3;
                    this._tape.Blocks.Add(tapeBlock);
                    continue;
                }

                case 17:
                {
                    tapeBlock = new TapeBlock();
                    int num3 = 16777215 & FormatSerializer.getInt32(array, i + 15);
                    tapeBlock.Description = TapSerializer.getBlockDescription(array, i + 18, num3);
                    tapeBlock.Periods     = TapSerializer.getBlockPeriods(array, i + 18, num3, (int)FormatSerializer.getUInt16(array, i), (int)FormatSerializer.getUInt16(array, i + 2), (int)FormatSerializer.getUInt16(array, i + 4), (int)FormatSerializer.getUInt16(array, i + 6), (int)FormatSerializer.getUInt16(array, i + 8), (int)FormatSerializer.getUInt16(array, i + 10), (int)FormatSerializer.getUInt16(array, i + 13), (int)array[i + 12]);
                    i += num3 + 18;
                    this._tape.Blocks.Add(tapeBlock);
                    continue;
                }

                case 18:
                {
                    tapeBlock             = new TapeBlock();
                    tapeBlock.Description = "Pure Tone";
                    int num5 = (int)FormatSerializer.getUInt16(array, i);
                    int num6 = (int)FormatSerializer.getUInt16(array, i + 2);
                    tapeBlock.Periods = new List <int>(num6);
                    for (int j = 0; j < num6; j++)
                    {
                        tapeBlock.Periods.Add(num5);
                    }
                    i += 4;
                    this._tape.Blocks.Add(tapeBlock);
                    continue;
                }

                case 19:
                {
                    tapeBlock             = new TapeBlock();
                    tapeBlock.Description = "Pulse sequence";
                    int num6 = (int)array[i++];
                    tapeBlock.Periods = new List <int>(num6);
                    int j = 0;
                    while (j < num6)
                    {
                        tapeBlock.Periods.Add((int)FormatSerializer.getUInt16(array, i));
                        j++;
                        i += 2;
                    }
                    this._tape.Blocks.Add(tapeBlock);
                    continue;
                }

                case 20:
                {
                    tapeBlock             = new TapeBlock();
                    tapeBlock.Description = "Pure Data Block";
                    int num3 = 16777215 & FormatSerializer.getInt32(array, i + 7);
                    tapeBlock.Periods = TapSerializer.getBlockPeriods(array, i + 10, num3, 0, 0, 0, (int)FormatSerializer.getUInt16(array, i), (int)FormatSerializer.getUInt16(array, i + 2), -1, (int)FormatSerializer.getUInt16(array, i + 5), (int)array[i + 4]);
                    i += num3 + 10;
                    this._tape.Blocks.Add(tapeBlock);
                    continue;
                }

                case 21:
                {
                    tapeBlock             = new TapeBlock();
                    tapeBlock.Description = "Direct Recording";
                    int num3  = 16777215 & FormatSerializer.getInt32(array, i + 5);
                    int @uint = (int)FormatSerializer.getUInt16(array, i);
                    int num4  = (int)FormatSerializer.getUInt16(array, i + 2);
                    int num7  = (int)array[i + 4];
                    i += 8;
                    int num5 = 0;
                    int num6 = 0;
                    int j;
                    for (j = 0; j < num3; j++)
                    {
                        for (int num8 = 128; num8 != 0; num8 >>= 1)
                        {
                            if ((((int)array[i + j] ^ num5) & num8) != 0)
                            {
                                num6++;
                                num5 ^= -1;
                            }
                        }
                    }
                    int num9 = 0;
                    num5 = 0;
                    tapeBlock.Periods = new List <int>(num6 + 2);
                    j = 1;
                    while (j < num3)
                    {
                        for (int num8 = 128; num8 != 0; num8 >>= 1)
                        {
                            num9 += @uint;
                            if ((((int)array[i] ^ num5) & num8) != 0)
                            {
                                tapeBlock.Periods.Add(num9);
                                num5 ^= -1;
                                num9  = 0;
                            }
                        }
                        j++;
                        i++;
                    }
                    for (int num8 = 128; num8 != (int)((byte)(128 >> num7)); num8 >>= 1)
                    {
                        num9 += @uint;
                        if ((((int)array[i] ^ num5) & num8) != 0)
                        {
                            tapeBlock.Periods.Add(num9);
                            num5 ^= -1;
                            num9  = 0;
                        }
                    }
                    i++;
                    tapeBlock.Periods.Add(num9);
                    if (num4 != 0)
                    {
                        tapeBlock.Periods.Add(num4 * 3500);
                    }
                    this._tape.Blocks.Add(tapeBlock);
                    continue;
                }

                case 22:
                case 23:
                case 24:
                case 25:
                case 26:
                case 27:
                case 28:
                case 29:
                case 30:
                case 31:
                case 41:
                case 43:
                case 44:
                case 45:
                case 46:
                case 47:
                    break;

                case 32:
                {
                    tapeBlock = new TapeBlock();
                    int num4 = (int)FormatSerializer.getUInt16(array, i);
                    tapeBlock.Description = ((num4 != 0) ? ("[Pause " + num4 + " ms]") : "[Stop the Tape]");
                    tapeBlock.Periods     = new List <int>(2);
                    i += 2;
                    if (num4 == 0)
                    {
                        tapeBlock.Command = TapeCommand.STOP_THE_TAPE;
                        tapeBlock.Periods.Add(3500);
                        num4 = -1;
                    }
                    else
                    {
                        num4 *= 3500;
                    }
                    tapeBlock.Periods.Add(num4);
                    this._tape.Blocks.Add(tapeBlock);
                    continue;
                }

                case 33:
                {
                    tapeBlock = new TapeBlock();
                    int num6 = (int)array[i++];
                    tapeBlock.Description = "[GROUP: " + Encoding.ASCII.GetString(array, i, num6) + "]";
                    tapeBlock.Command     = TapeCommand.BEGIN_GROUP;
                    i += num6;
                    tapeBlock.Periods = new List <int>();
                    this._tape.Blocks.Add(tapeBlock);
                    continue;
                }

                case 34:
                    tapeBlock             = new TapeBlock();
                    tapeBlock.Description = "[END GROUP]";
                    tapeBlock.Command     = TapeCommand.END_GROUP;
                    tapeBlock.Periods     = new List <int>();
                    this._tape.Blocks.Add(tapeBlock);
                    continue;

                case 35:
                    tapeBlock             = new TapeBlock();
                    tapeBlock.Description = "[JUMP TO BLOCK " + FormatSerializer.getUInt16(array, i) + "]";
                    tapeBlock.Periods     = new List <int>();
                    i += 2;
                    this._tape.Blocks.Add(tapeBlock);
                    continue;

                case 36:
                    num  = (int)FormatSerializer.getUInt16(array, i);
                    num2 = this._tape.Blocks.Count;
                    i   += 2;
                    continue;

                case 37:
                    if (num != 0)
                    {
                        int num3 = this._tape.Blocks.Count - num2;
                        for (int k = 0; k < num3; k++)
                        {
                            this._tape.Blocks.Add(this._tape.Blocks[num + k]);
                        }
                        num = 0;
                        continue;
                    }
                    continue;

                case 38:
                    tapeBlock             = new TapeBlock();
                    tapeBlock.Description = "[CALL SEQUENCE]";
                    tapeBlock.Periods     = new List <int>();
                    i += (int)(2 + 2 * FormatSerializer.getUInt16(array, i));
                    this._tape.Blocks.Add(tapeBlock);
                    continue;

                case 39:
                    tapeBlock             = new TapeBlock();
                    tapeBlock.Description = "[RETURN SEQUENCE]";
                    tapeBlock.Periods     = new List <int>();
                    this._tape.Blocks.Add(tapeBlock);
                    continue;

                case 40:
                    tapeBlock             = new TapeBlock();
                    tapeBlock.Description = "[SELECT BLOCK]";
                    tapeBlock.Periods     = new List <int>();
                    i += (int)(2 + FormatSerializer.getUInt16(array, i));
                    this._tape.Blocks.Add(tapeBlock);
                    continue;

                case 42:
                    tapeBlock             = new TapeBlock();
                    tapeBlock.Description = "[Stop tape if in 48K mode]";
                    tapeBlock.Command     = TapeCommand.STOP_THE_TAPE_48K;
                    tapeBlock.Periods     = new List <int>();
                    i += (int)(4 + FormatSerializer.getUInt16(array, i));
                    this._tape.Blocks.Add(tapeBlock);
                    continue;

                case 48:
                {
                    tapeBlock = new TapeBlock();
                    int num6 = (int)array[i++];
                    tapeBlock.Description = "[" + Encoding.ASCII.GetString(array, i, num6) + "]";
                    tapeBlock.Periods     = new List <int>();
                    i += num6;
                    this._tape.Blocks.Add(tapeBlock);
                    continue;
                }

                case 49:
                {
                    tapeBlock = new TapeBlock();
                    i++;
                    int num6 = (int)array[i++];
                    tapeBlock.Description = "[Message: " + Encoding.ASCII.GetString(array, i, num6) + "]";
                    tapeBlock.Command     = TapeCommand.SHOW_MESSAGE;
                    tapeBlock.Periods     = new List <int>();
                    i += num6;
                    this._tape.Blocks.Add(tapeBlock);
                    continue;
                }

                case 50:
                {
                    tapeBlock             = new TapeBlock();
                    tapeBlock.Description = "Archive info";
                    tapeBlock.Periods     = new List <int>();
                    int num10 = i + 3;
                    for (int j = 0; j < (int)array[i + 2]; j++)
                    {
                        byte   b2 = array[num10++];
                        string arg;
                        switch (b2)
                        {
                        case 0:
                            arg = "Full title";
                            break;

                        case 1:
                            arg = "Publisher";
                            break;

                        case 2:
                            arg = "Author";
                            break;

                        case 3:
                            arg = "Year";
                            break;

                        case 4:
                            arg = "Language";
                            break;

                        case 5:
                            arg = "Type";
                            break;

                        case 6:
                            arg = "Price";
                            break;

                        case 7:
                            arg = "Protection";
                            break;

                        case 8:
                            arg = "Origin";
                            break;

                        default:
                            if (b2 != 255)
                            {
                                arg = "info";
                            }
                            else
                            {
                                arg = "Comment";
                            }
                            break;
                        }
                        int num3 = (int)array[num10++];
                        tapeBlock.Description = string.Format("{0}: {1}", arg, Encoding.ASCII.GetString(array, num10, num3));
                        num10 += num3;
                    }
                    i += (int)(2 + FormatSerializer.getUInt16(array, i));
                    this._tape.Blocks.Add(tapeBlock);
                    continue;
                }

                case 51:
                {
                    tapeBlock = new TapeBlock();
                    int num6 = (int)array[i++];
                    tapeBlock.Description = "[HARDWARE TYPE]";
                    tapeBlock.Periods     = new List <int>();
                    i += 3 * num6;
                    this._tape.Blocks.Add(tapeBlock);
                    continue;
                }

                case 52:
                    tapeBlock             = new TapeBlock();
                    tapeBlock.Description = "[EMULATION INFO]";
                    tapeBlock.Periods     = new List <int>();
                    i += 8;
                    this._tape.Blocks.Add(tapeBlock);
                    continue;

                case 53:
                    tapeBlock             = new TapeBlock();
                    tapeBlock.Description = "[CUSTOM INFO - " + Encoding.ASCII.GetString(array, i, 10) + "]";
                    i += 10;
                    tapeBlock.Periods = new List <int>();
                    i += (int)(2 + FormatSerializer.getUInt16(array, i));
                    this._tape.Blocks.Add(tapeBlock);
                    continue;

                default:
                    if (b == 64)
                    {
                        tapeBlock             = new TapeBlock();
                        tapeBlock.Description = "[SNAPSHOT - ";
                        if (array[i] == 0)
                        {
                            TapeBlock tapeBlock2 = tapeBlock;
                            tapeBlock2.Description += ".Z80]";
                        }
                        else if (array[i] == 1)
                        {
                            TapeBlock tapeBlock3 = tapeBlock;
                            tapeBlock3.Description += ".SNA]";
                        }
                        else
                        {
                            TapeBlock tapeBlock4 = tapeBlock;
                            tapeBlock4.Description += "???]";
                        }
                        i++;
                        int num3 = (int)array[i] | (int)array[i + 1] << 8 | (int)array[i + 2] << 16;
                        i += 3;
                        tapeBlock.Periods = new List <int>();
                        i += num3;
                        this._tape.Blocks.Add(tapeBlock);
                        continue;
                    }
                    if (b == 90)
                    {
                        i += 9;
                        continue;
                    }
                    break;
                }
                tapeBlock             = new TapeBlock();
                tapeBlock.Description = "[UNKNOWN BLOCK 0x" + array[i - 1].ToString("X2") + "]";
                tapeBlock.Periods     = new List <int>();
                i += (FormatSerializer.getInt32(array, i) & 16777215);
                i += 4;
                this._tape.Blocks.Add(tapeBlock);
            }
        }
Example #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="textWriter"></param>
        /// <param name="translationContext"></param>
        /// <param name="format"></param>
        public static void Serialize(object obj, TextWriter textWriter, TranslationContext translationContext, StringFormat format)
        {
            StringSerializer serializer = FormatSerializer.GetStringSerializer(format);

            serializer.Serialize(obj, textWriter, translationContext);
        }
Example #13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="stream"></param>
        /// <param name="translationContext"></param>
        /// <param name="format"></param>
        public static void Serialize(object obj, Stream stream, TranslationContext translationContext, Format format)
        {
            FormatSerializer serializer = FormatSerializer.GetSerializer(format);

            serializer.Serialize(obj, stream, translationContext);
        }
Example #14
0
        public static String Serialize(object obj, TranslationContext translationContext, StringFormat format)
        {
            StringSerializer stringSerializer = FormatSerializer.GetStringSerializer(format);

            return(stringSerializer.Serialize(obj, translationContext));
        }
Example #15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="stringBuilder"></param>
        /// <param name="translationContext"></param>
        /// <param name="format"></param>
        public static void Serialize(object obj, StringBuilder stringBuilder, TranslationContext translationContext, StringFormat format)
        {
            StringSerializer stringSerializer = FormatSerializer.GetStringSerializer(format);

            stringSerializer.Serialize(obj, stringBuilder, translationContext);
        }