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 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);
        }