Exemple #1
0
            public static TD0_SECTOR Deserialize(Stream stream)
            {
                var sector = new TD0_SECTOR();

                // C,H,R,N,Flags,hdrcrc low,hdrcrc high
                var adm = new byte[6];

                stream.Read(adm, 0, 6);
                sector._admark = adm;

                // data size low, data size high, encoding method, rawdata,...
                var datahdr = new byte[2];

                stream.Read(datahdr, 0, 2);
                var rawdata = new byte[getUInt16(datahdr, 0)];

                stream.Read(rawdata, 0, rawdata.Length);
                sector._data = unpackData(rawdata);

                var crc = CrcTd0.Calculate(sector._data, 0, sector._data.Length);

                if (adm[5] != (crc & 0xFF))
                {
                    Logger.Warn(
                        "TD0 loader: Sector data had bad CRC=0x{0:X4} (stamp crc=0x{1:X2}) [C:{2:X2};H:{3:X2};R:{4:X2};N:{5:X2}",
                        crc,
                        adm[5],
                        sector.C,
                        sector.H,
                        sector.R,
                        sector.N);
                    Locator.Resolve <IUserMessage>()
                    .Warning("TD0 loader\n\nSector data had bad CRC");
                }

                sector.SetAdCrc(true);
                sector.SetDataCrc((sector.Td0Flags & SectorFlags.BadCrc) == 0);
                return(sector);
            }
Exemple #2
0
            public static TD0_TRACK Deserialize(Stream stream)
            {
                var hdr = new TD0_TRACK();

                stream.Read(hdr._rawData, 0, 4);
                if (hdr._rawData[0] != 0xFF)                    // 0xFF - terminator
                {
                    var crc = CrcTd0.Calculate(hdr._rawData, 0, 3);
                    if (hdr._rawData[3] != (crc & 0xFF))
                    {
                        Logger.Warn("TD0 loader: Track header had bad CRC=0x" + crc.ToString("X4") + " (stamp crc=0x" + hdr._rawData[3].ToString("X2") + ") [CYL:0x" + hdr._rawData[1].ToString("X2") + ";SIDE:" + hdr._rawData[2].ToString("X2"));
                        Locator.Resolve <IUserMessage>()
                        .Warning("TD0 loader\n\nTrack header had bad CRC");
                    }

                    var sectors = new List <Sector>(hdr.SectorCount);
                    for (int s = 0; s < hdr.SectorCount; s++)
                    {
                        hdr._sectorList.Add(TD0_SECTOR.Deserialize(stream));
                    }
                }
                return(hdr);
            }
            public static TD0_SECTOR Deserialize(Stream stream)
            {
                TD0_SECTOR sector = new TD0_SECTOR();

                // C,H,R,N,Flags,hdrcrc low,hdrcrc high
                byte[] adm = new byte[6];
                stream.Read(adm, 0, 6);
                sector._admark = adm;

                // data size low, data size high, encoding method, rawdata,...
                byte[] datahdr = new byte[2];
                stream.Read(datahdr, 0, 2);
                byte[] rawdata = new byte[getUInt16(datahdr, 0)];
                stream.Read(rawdata, 0, rawdata.Length);
                sector._data = unpackData(rawdata);

                ushort crc = CalculateTD0CRC(sector._data, 0, sector._data.Length);
                if (adm[5] != (crc & 0xFF))
                {
                    LogAgent.Warn(
                        "TD0 loader: Sector data had bad CRC=0x{0:X4} (stamp crc=0x{1:X2}) [C:{2:X2};H:{3:X2};R:{4:X2};N:{5:X2}",
                        crc,
                        adm[5],
                        sector.C,
                        sector.H,
                        sector.R,
                        sector.N);
                    DialogProvider.Show(
                        "Sector data had bad CRC",
                        "TD0 loader",
                        DlgButtonSet.OK,
                        DlgIcon.Warning);
                }

                sector.SetAdCrc(true);
                sector.SetDataCrc((sector.Td0Flags & SectorFlags.BadCrc) == 0);
                return sector;
            }