Пример #1
0
        /// <summary>
        /// High level format a disk
        /// </summary>
        public void FormatDisk()
        {
            byte fillByte = 0xff;

            if (!(this.DiskImage is PhysicalDisk))
            {
                byte[] buffer = new byte[this.LogicalTracks * this.LogicalHeads * this.LogicalSectors * this.LogicalSectorSize].Initialize(fillByte);
                this.WriteSectors(0, 0, 1, buffer);
            }
            else
            {
                byte[] trackBuffer = new byte[this.LogicalSectors * this.LogicalSectorSize].Initialize(fillByte);

                FormatDiskForm fdf = new FormatDiskForm();
                ((PhysicalDisk)DiskImage).FormatChanged += new FormatChangedEventHandler(fdf.Update);

                for (int track = 0; track < this.LogicalTracks; track++)
                {
                    for (int head = 0; head < this.LogicalHeads; head++)
                    {
                        ((PhysicalDisk)DiskImage).WriteTrack(track, head, trackBuffer);
                    }
                }

                fdf.Close();
            }

            this.DiskLabel = string.Empty;
        }
Пример #2
0
        /// <summary>
        /// High level format a disk
        /// </summary>
        public void FormatDisk()
        {
            // Create Empty Disk
            byte fillByte = 0xe5;

            byte[] buffer;

            if (!(DiskImage is PhysicalDisk))
            {
                buffer = new byte[this.LogicalTracks * this.LogicalHeads * this.LogicalSectors * this.LogicalSectorSize].Initialize(fillByte);
                this.WriteLSNs(0, buffer);
            }
            else
            {
                buffer = new byte[this.LogicalSectors * this.LogicalSectorSize].Initialize(fillByte);

                FormatDiskForm fdf = new FormatDiskForm();
                ((PhysicalDisk)DiskImage).FormatChanged += new FormatChangedEventHandler(fdf.Update);

                for (int track = 0; track < this.LogicalTracks; track++)
                {
                    for (int head = 0; head < this.LogicalHeads; head++)
                    {
                        ((PhysicalDisk)DiskImage).WriteTrack(track, head, buffer);
                    }
                }

                fdf.Close();
            }

            // Create LSN0
            this.lsn0 = new LSN0();
            this.lsn0.TotalSectors = this.LogicalTracks * this.LogicalHeads * this.LogicalSectors;
            this.lsn0.TrackSize    = (byte)this.LogicalSectors;
            this.lsn0.MapBytes     = (ushort)((this.lsn0.TotalSectors + 7) / 8);
            this.lsn0.ClusterSize  = 1;
            this.lsn0.Owner        = 0;
            this.lsn0.Attributes   = 0xff;
            Random rnd = new Random(DateTime.Now.Second);

            this.lsn0.DiskID = (ushort)rnd.Next(0xffff);
            if (this.DiskImage is PartitionedVHDImage || this.DiskImage is VHDImage)
            {
                this.lsn0.DiskFormat = 0x82;
            }
            else
            {
                this.lsn0.DiskFormat = (byte)(0x02 + (this.LogicalHeads - 1));
            }

            this.lsn0.BootStrap                       = 0;
            this.lsn0.BootStrapSize                   = 0;
            this.lsn0.CreatedDate                     = DateTime.Now;
            this.lsn0.VolumeName                      = string.Empty;
            this.lsn0.SectorSize                      = (ushort)this.LogicalSectorSize;
            this.lsn0.RootDirectory                   = 1 + ((this.lsn0.MapBytes + (this.LogicalSectorSize - 1)) / this.LogicalSectorSize);
            this.lsn0.PathDescriptor.DeviceType       = 0x01;
            this.lsn0.PathDescriptor.DriveNumber      = 0x00;
            this.lsn0.PathDescriptor.DeviceType       = 0x20;
            this.lsn0.PathDescriptor.Density          = 0x01;
            this.lsn0.PathDescriptor.Cylinders        = (ushort)this.DiskImage.PhysicalTracks;
            this.lsn0.PathDescriptor.Sides            = (byte)this.DiskImage.PhysicalHeads;
            this.lsn0.PathDescriptor.SectorsPerTrack  = (ushort)this.DiskImage.PhysicalSectors;
            this.lsn0.PathDescriptor.SectorsPerTrack0 = this.lsn0.PathDescriptor.SectorsPerTrack;
            this.lsn0.PathDescriptor.Interleave       = (byte)this.DiskImage.Interleave;
            if (this.DiskImage is PartitionedVHDImage || this.DiskImage is VHDImage)
            {
                this.lsn0.PathDescriptor.SegmentAllocationSize = 0x20;
            }
            else
            {
                this.lsn0.PathDescriptor.SegmentAllocationSize = 8;
            }

            this.WriteLSN(0, (byte[])this.lsn0);

            // Create Allocation Bitmap
            int bitmapBits       = this.LogicalTracks * this.LogicalHeads * this.LogicalSectors;
            int bitmapLSNs       = ((bitmapBits / 8) + this.LogicalSectorSize - 1) / this.LogicalSectorSize;
            int allocatedSectors = 1 + bitmapLSNs + 8;

            byte[] bitmap = new byte[bitmapLSNs * this.LogicalSectorSize].Initialize(0xff);
            for (int i = 0; i < this.lsn0.TotalSectors; i++)
            {
                this.DeallocateLSN(i, bitmap);
            }

            for (int i = 0; i < allocatedSectors; i++)
            {
                this.AllocateLSN(i, bitmap);
            }

            this.WriteLSNs(0, bitmap);

            // Create root directory file descriptor
            FileDescriptor rootDescriptor = new FileDescriptor(0xbf, 0, this.lsn0.PackedCreationDate, 2, 0x40, Util.CreatedDateBytes(this.lsn0.CreatedDate));

            rootDescriptor.SegmentList    = new FileSegment[48];
            rootDescriptor.SegmentList[0] = new FileSegment(this.lsn0.RootDirectory + 1, 7);
            this.WriteLSN(this.lsn0.RootDirectory, (byte[])rootDescriptor);

            // Create root directory
            buffer = new byte[7 * this.LogicalSectorSize];
            Directory rootDirectory = new Directory();

            rootDirectory.FormatType = DiskFormatType.OS9Format;
            rootDirectory.Add(new DirectoryEntry("..", this.lsn0.RootDirectory));
            rootDirectory.Add(new DirectoryEntry(".", this.lsn0.RootDirectory));
            Array.Copy((byte[])rootDirectory, 0, buffer, 0, 0x40);
            this.WriteLSNs(this.lsn0.RootDirectory + 1, buffer);
        }
Пример #3
0
        /// <summary>
        /// High level format a disk
        /// </summary>
        public void FormatDisk()
        {
            byte fillByte = 0xff;

            if (!(this.DiskImage is PhysicalDisk))
            {
                byte[] buffer = new byte[this.LogicalTracks * this.LogicalHeads * this.LogicalSectors * this.LogicalSectorSize].Initialize(fillByte);
                this.WriteSectors(0, 0, 1, buffer);
            }
            else
            {
                byte[] trackBuffer = new byte[LogicalSectors * LogicalSectorSize].Initialize(fillByte);

                FormatDiskForm fdf = new FormatDiskForm();
                ((PhysicalDisk)DiskImage).FormatChanged += new FormatChangedEventHandler(fdf.Update);

                for (int track = 0; track < this.LogicalTracks; track++)
                {
                    for (int head = 0; head < this.LogicalHeads; head++)
                    {
                        ((PhysicalDisk)DiskImage).WriteTrack(track, head, trackBuffer);
                    }
                }

                fdf.Close();
            }

            Directory directory = new Directory();

            this.WriteSectors(20, 0, 3, directory);
            this.WriteSectors(16, 0, 3, directory);

            byte[] bitmap0 = new byte[256];
            for (int i = 0; i < (40 * this.LogicalHeads * this.LogicalSectors); i++)
            {
                this.DeallocateSector(i, bitmap0);
            }

            for (int i = 1; i < 18; i++)
            {
                this.AllocateSector(16, 0, i, bitmap0);
                this.AllocateSector(20, 0, i, bitmap0);
            }

            bitmap0[0xfc] = (byte)this.LogicalTracks;
            bitmap0[0xfd] = (byte)(this.LogicalSectors * this.LogicalHeads);
            bitmap0[0xfe] = (byte)~bitmap0[0xfc];
            bitmap0[0xff] = (byte)~bitmap0[0xfd];

            this.DiskImage.WriteSector(20, 0, 1, bitmap0);
            this.DiskImage.WriteSector(16, 0, 1, bitmap0);

            if (this.LogicalTracks > 40)
            {
                byte[] bitmap1 = new byte[256];
                Array.Copy(new byte[0xb4].Initialize(0xff), 0, bitmap1, 0, 0xb4);

                this.DiskImage.WriteSector(20, 0, 2, bitmap1);
                this.DiskImage.WriteSector(16, 0, 2, bitmap1);
            }

            this.DiskLabel = string.Empty;
        }