Exemple #1
0
        /// <summary>
        /// Create a new JVC disk associated with the given stream.
        /// </summary>
        /// <param name="image">Stream for storing the disk image.</param>
        /// <param name="heads">Number of disk heads.</param>
        /// <param name="tracks">Number of tracks per head.</param>
        /// <param name="sectors">Number of sectors per track.</param>
        /// <param name="sectorsize">Sector size in bytes</param>
        /// <returns>A disk object</returns>
        public static JvcDisk Create(Stream image, int heads, int tracks, int sectors, int sectorsize)
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }
            if (!image.CanRead)
            {
                throw new NotSupportedException("Disk image stream does not support reading");
            }
            if (!image.CanSeek)
            {
                throw new NotSupportedException("Disk image stream does not support seeking");
            }
            if (!image.CanWrite)
            {
                throw new NotSupportedException("Disk image stream does not support writing");
            }

            var disk = new JvcDisk(image, heads, tracks, sectors, sectorsize);

            var header    = new JvcHeader(heads, tracks, sectors, sectorsize, false);
            var headerRaw = header.Encode();

            disk.diskHeaderSize   = headerRaw.Length;
            disk.sectorHeaderSize = 0;
            disk.IsWriteable      = true;
            disk.IsModified       = true;

            disk.DiskData = new byte[heads * tracks * sectors * sectorsize + disk.diskHeaderSize];
            Array.Copy(headerRaw, disk.DiskData, headerRaw.Length);

            return(disk);
        }
Exemple #2
0
            public static JvcHeader Parse(byte[] raw)
            {
                int  headersize      = raw.Length % 256;
                int  sectors         = headersize >= 1 ? raw[0] : DefaultSectors;
                int  heads           = headersize >= 2 ? raw[1] : DefaultHeads;
                int  sectorsize      = headersize >= 3 ? (128 << raw[2]) : DefaultSectorSize;
                bool sectorattribute = headersize >= 5 ? (raw[4] != 0) : DefaultSectorAttribute;

                if (sectorattribute)
                {
                    headersize = raw.Length % 257;
                }

                int tracks = (raw.Length - headersize) / heads / sectors / sectorsize;

                var header = new JvcHeader(heads, tracks, sectors, sectorsize, sectorattribute);

                header.HeaderSize = headersize;
                return(header);
            }
Exemple #3
0
        /// <summary>
        /// Reads a JVC disk image from a given stream.
        /// </summary>
        /// <param name="image">Stream containing the disk image.</param>
        /// <param name="isWriteable">Allow write operations to this disk.</param>
        /// <returns>A disk object.</returns>
        public static JvcDisk Open(Stream image, bool isWriteable)
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }
            if (!image.CanRead)
            {
                throw new NotSupportedException("Disk image stream does not support reading");
            }

            var imageData = IOUtils.ReadStreamFully(image);
            var header    = JvcHeader.Parse(imageData);

            var disk = new JvcDisk(image, header.Heads, header.Tracks, header.Sectors, header.SectorSize);

            disk.DiskData         = imageData;
            disk.diskHeaderSize   = header.HeaderSize;
            disk.sectorHeaderSize = header.SectorAttribute ? 1 : 0;
            disk.IsWriteable      = (isWriteable && image.CanSeek && image.CanWrite);

            return(disk);
        }