Пример #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);
            }
Пример #2
0
 public static Td0Serializer.TD0_TRACK Deserialize(Stream stream)
 {
     Td0Serializer.TD0_TRACK td0_TRACK = new Td0Serializer.TD0_TRACK();
     stream.Read(td0_TRACK._rawData, 0, 4);
     if (td0_TRACK._rawData[0] != 255)
     {
         ushort num = Td0Serializer.CalculateTD0CRC(td0_TRACK._rawData, 0, 3);
         if ((ushort)td0_TRACK._rawData[3] != (num & 255))
         {
             Logger.GetLogger().LogWarning(string.Concat(new string[]
             {
                 "TD0 loader: Track header had bad CRC=0x",
                 num.ToString("X4"),
                 " (stamp crc=0x",
                 td0_TRACK._rawData[3].ToString("X2"),
                 ") [CYL:0x",
                 td0_TRACK._rawData[1].ToString("X2"),
                 ";SIDE:",
                 td0_TRACK._rawData[2].ToString("X2")
             }));
             PlatformFactory.Platform.ShowWarning("Track header had bad CRC", "TD0 loader");
         }
         new ArrayList(td0_TRACK.SectorCount);
         for (int i = 0; i < td0_TRACK.SectorCount; i++)
         {
             td0_TRACK._sectorList.Add(Td0Serializer.TD0_SECTOR.Deserialize(stream));
         }
     }
     return(td0_TRACK);
 }
Пример #3
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);
            }
Пример #4
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);
        }