Пример #1
0
        /// <summary>
        /// Searches for the requested sector
        /// </summary>
        /// <returns></returns>
        private FloppyDisk.Sector GetSector()
        {
            FloppyDisk.Sector sector = null;

            // get the current track
            var trk = ActiveDrive.Disk.DiskTracks[ActiveDrive.TrackIndex];

            // get the current sector index
            int index = ActiveDrive.SectorIndex;

            // make sure this index exists
            if (index > trk.Sectors.Length)
            {
                index = 0;
            }

            // index hole count
            int iHole = 0;

            // loop through the sectors in a track
            // the loop ends with either the sector being found
            // or the index hole being passed twice
            while (iHole <= 2)
            {
                // does the requested sector match the current sector
                if (trk.Sectors[index].SectorIDInfo.C == ActiveCommandParams.Cylinder &&
                    trk.Sectors[index].SectorIDInfo.H == ActiveCommandParams.Head &&
                    trk.Sectors[index].SectorIDInfo.R == ActiveCommandParams.Sector &&
                    trk.Sectors[index].SectorIDInfo.N == ActiveCommandParams.SectorSize)
                {
                    // sector has been found
                    sector = trk.Sectors[index];

                    UnSetBit(SR2_BC, ref Status2);
                    UnSetBit(SR2_WC, ref Status2);
                    break;
                }

                // check for bad cylinder
                if (trk.Sectors[index].SectorIDInfo.C == 255)
                {
                    SetBit(SR2_BC, ref Status2);
                }
                // check for no cylinder
                else if (trk.Sectors[index].SectorIDInfo.C != ActiveCommandParams.Cylinder)
                {
                    SetBit(SR2_WC, ref Status2);
                }

                // incrememnt sector index
                index++;

                // have we reached the index hole?
                if (trk.Sectors.Length <= index)
                {
                    // wrap around
                    index = 0;
                    iHole++;
                }
            }

            // search loop has completed and the sector may or may not have been found

            // bad cylinder detected?
            if (Status2.Bit(SR2_BC))
            {
                // remove WC
                UnSetBit(SR2_WC, ref Status2);
            }

            // update sectorindex on drive
            ActiveDrive.SectorIndex = index;

            return(sector);
        }