Beispiel #1
0
        public bool Identify(IFilter imageFilter)
        {
            Stream stream = imageFilter.GetDataForkStream();

            stream.Seek(0, SeekOrigin.Begin);
            // Even if comment is supposedly ASCII, I'm pretty sure most emulators allow Shift-JIS to be used :p
            Encoding shiftjis = Encoding.GetEncoding("shift_jis");

            v98Hdr = new Virtual98Header();

            if (stream.Length < Marshal.SizeOf(v98Hdr))
            {
                return(false);
            }

            byte[] hdrB = new byte[Marshal.SizeOf(v98Hdr)];
            stream.Read(hdrB, 0, hdrB.Length);

            GCHandle handle = GCHandle.Alloc(hdrB, GCHandleType.Pinned);

            v98Hdr =
                (Virtual98Header)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(Virtual98Header));
            handle.Free();

            if (!v98Hdr.signature.SequenceEqual(signature))
            {
                return(false);
            }

            DicConsole.DebugWriteLine("Virtual98 plugin", "v98hdr.signature = \"{0}\"",
                                      StringHandlers.CToString(v98Hdr.signature, shiftjis));
            DicConsole.DebugWriteLine("Virtual98 plugin", "v98hdr.comment = \"{0}\"",
                                      StringHandlers.CToString(v98Hdr.comment, shiftjis));
            DicConsole.DebugWriteLine("Virtual98 plugin", "v98hdr.padding = {0}", v98Hdr.padding);
            DicConsole.DebugWriteLine("Virtual98 plugin", "v98hdr.mbsize = {0}", v98Hdr.mbsize);
            DicConsole.DebugWriteLine("Virtual98 plugin", "v98hdr.sectorsize = {0}", v98Hdr.sectorsize);
            DicConsole.DebugWriteLine("Virtual98 plugin", "v98hdr.sectors = {0}", v98Hdr.sectors);
            DicConsole.DebugWriteLine("Virtual98 plugin", "v98hdr.surfaces = {0}", v98Hdr.surfaces);
            DicConsole.DebugWriteLine("Virtual98 plugin", "v98hdr.cylinders = {0}", v98Hdr.cylinders);
            DicConsole.DebugWriteLine("Virtual98 plugin", "v98hdr.totals = {0}", v98Hdr.totals);

            return(true);
        }
Beispiel #2
0
        public bool Open(IFilter imageFilter)
        {
            Stream stream = imageFilter.GetDataForkStream();

            stream.Seek(0, SeekOrigin.Begin);
            // Even if comment is supposedly ASCII, I'm pretty sure most emulators allow Shift-JIS to be used :p
            Encoding shiftjis = Encoding.GetEncoding("shift_jis");

            v98Hdr = new Virtual98Header();

            if (stream.Length < Marshal.SizeOf(v98Hdr))
            {
                return(false);
            }

            byte[] hdrB = new byte[Marshal.SizeOf(v98Hdr)];
            stream.Read(hdrB, 0, hdrB.Length);

            GCHandle handle = GCHandle.Alloc(hdrB, GCHandleType.Pinned);

            v98Hdr =
                (Virtual98Header)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(Virtual98Header));
            handle.Free();

            imageInfo.MediaType = MediaType.GENERIC_HDD;

            imageInfo.ImageSize            = (ulong)(stream.Length - 0xDC);
            imageInfo.CreationTime         = imageFilter.GetCreationTime();
            imageInfo.LastModificationTime = imageFilter.GetLastWriteTime();
            imageInfo.MediaTitle           = Path.GetFileNameWithoutExtension(imageFilter.GetFilename());
            imageInfo.Sectors         = v98Hdr.totals;
            imageInfo.XmlMediaType    = XmlMediaType.BlockMedia;
            imageInfo.SectorSize      = v98Hdr.sectorsize;
            imageInfo.Cylinders       = v98Hdr.cylinders;
            imageInfo.Heads           = v98Hdr.surfaces;
            imageInfo.SectorsPerTrack = v98Hdr.sectors;
            imageInfo.Comments        = StringHandlers.CToString(v98Hdr.comment, shiftjis);

            nhdImageFilter = imageFilter;

            return(true);
        }
Beispiel #3
0
        public bool Close()
        {
            if (!IsWriting)
            {
                ErrorMessage = "Image is not opened for writing";

                return(false);
            }

            if (imageInfo.Cylinders == 0)
            {
                imageInfo.Cylinders       = (uint)(imageInfo.Sectors / 16 / 63);
                imageInfo.Heads           = 16;
                imageInfo.SectorsPerTrack = 63;

                while (imageInfo.Cylinders == 0)
                {
                    imageInfo.Heads--;

                    if (imageInfo.Heads == 0)
                    {
                        imageInfo.SectorsPerTrack--;
                        imageInfo.Heads = 16;
                    }

                    imageInfo.Cylinders = (uint)(imageInfo.Sectors / imageInfo.Heads / imageInfo.SectorsPerTrack);

                    if (imageInfo.Cylinders == 0 &&
                        imageInfo.Heads == 0 &&
                        imageInfo.SectorsPerTrack == 0)
                    {
                        break;
                    }
                }
            }

            byte[] commentsBytes = null;

            if (!string.IsNullOrEmpty(imageInfo.Comments))
            {
                commentsBytes = Encoding.GetEncoding("shift_jis").GetBytes(imageInfo.Comments);
            }

            v98Hdr = new Virtual98Header
            {
                comment   = new byte[128], cylinders = (ushort)imageInfo.Cylinders,
                padding2  = new byte[0x44],
                sectors   = (byte)imageInfo.SectorsPerTrack, sectorsize = (ushort)imageInfo.SectorSize,
                signature = signature, surfaces = (byte)imageInfo.Heads,
                totals    = (uint)imageInfo.Sectors
            };

            if (commentsBytes != null)
            {
                Array.Copy(commentsBytes, 0, v98Hdr.comment, 0,
                           commentsBytes.Length >= 128 ? 128 : commentsBytes.Length);
            }

            byte[] hdr    = new byte[Marshal.SizeOf <Virtual98Header>()];
            IntPtr hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf <Virtual98Header>());

            System.Runtime.InteropServices.Marshal.StructureToPtr(v98Hdr, hdrPtr, true);
            System.Runtime.InteropServices.Marshal.Copy(hdrPtr, hdr, 0, hdr.Length);
            System.Runtime.InteropServices.Marshal.FreeHGlobal(hdrPtr);

            writingStream.Seek(0, SeekOrigin.Begin);
            writingStream.Write(hdr, 0, hdr.Length);

            writingStream.Flush();
            writingStream.Close();

            IsWriting    = false;
            ErrorMessage = "";

            return(true);
        }