コード例 #1
0
            /// <summary>
            /// Parses a new disk image and loads it into this floppy drive
            /// </summary>
            /// <param name="tapeData"></param>
            public void FDD_LoadDisk(byte[] diskData)
            {
                // try dsk first
                FloppyDisk fdd   = null;
                bool       found = false;

                foreach (DiskType type in Enum.GetValues(typeof(DiskType)))
                {
                    switch (type)
                    {
                    case DiskType.CPCExtended:
                        fdd   = new CPCExtendedFloppyDisk();
                        found = fdd.ParseDisk(diskData);
                        break;

                    case DiskType.CPC:
                        fdd   = new CPCFloppyDisk();
                        found = fdd.ParseDisk(diskData);
                        break;

                    case DiskType.IPF:
                        fdd   = new IPFFloppyDisk();
                        found = fdd.ParseDisk(diskData);
                        break;

                    case DiskType.UDI:
                        fdd   = new UDI1_0FloppyDisk();
                        found = fdd.ParseDisk(diskData);
                        break;
                    }

                    if (found)
                    {
                        Disk = fdd;
                        break;
                    }
                }

                if (!found)
                {
                    throw new Exception(this.GetType().ToString() +
                                        "\n\nDisk image file could not be parsed. Potentially an unknown format.");
                }
            }
コード例 #2
0
ファイル: IPFFloppyDisk.cs プロジェクト: KuSunda/BizHawk
            public static IPFBlock ParseNextBlock(ref int startPos, FloppyDisk disk, byte[] data, List <IPFBlock> blockCollection)
            {
                IPFBlock ipf = new IPFBlock();

                ipf.StartPos = startPos;

                if (startPos >= data.Length)
                {
                    // EOF
                    return(null);
                }

                // assume the startPos passed in is actually the start of a new block
                // look for record header ident
                string ident = Encoding.ASCII.GetString(data, startPos, 4);

                startPos += 4;
                try
                {
                    ipf.RecordType = (RecordHeaderType)Enum.Parse(typeof(RecordHeaderType), ident);
                }
                catch
                {
                    ipf.RecordType = RecordHeaderType.None;
                }

                // setup for actual block size
                ipf.BlockLength  = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                ipf.CRC          = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                ipf.RawBlockData = new byte[ipf.BlockLength];
                Array.Copy(data, ipf.StartPos, ipf.RawBlockData, 0, ipf.BlockLength);

                switch (ipf.RecordType)
                {
                // Nothing to process / unknown
                // just move ahead
                case RecordHeaderType.CAPS:
                case RecordHeaderType.TRCK:
                case RecordHeaderType.DUMP:
                case RecordHeaderType.CTEI:
                case RecordHeaderType.CTEX:
                default:
                    startPos = ipf.StartPos + ipf.BlockLength;
                    break;

                // INFO block
                case RecordHeaderType.INFO:
                    // INFO header is followed immediately by an INFO block
                    ipf.INFOmediaType    = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    ipf.INFOencoderType  = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    ipf.INFOencoderRev   = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    ipf.INFOfileKey      = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    ipf.INFOfileRev      = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    ipf.INFOorigin       = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    ipf.INFOminTrack     = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    ipf.INFOmaxTrack     = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    ipf.INFOminSide      = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    ipf.INFOmaxSide      = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    ipf.INFOcreationDate = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    ipf.INFOcreationTime = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    ipf.INFOplatform1    = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    ipf.INFOplatform2    = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    ipf.INFOplatform3    = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    ipf.INFOplatform4    = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    ipf.INFOdiskNumber   = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    ipf.INFOcreatorId    = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    startPos            += 12;                  // reserved
                    break;

                case RecordHeaderType.IMGE:
                    ipf.IMGEtrack          = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    ipf.IMGEside           = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    ipf.IMGEdensity        = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    ipf.IMGEsignalType     = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    ipf.IMGEtrackBytes     = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    ipf.IMGEstartBytePos   = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    ipf.IMGEstartBitPos    = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    ipf.IMGEdataBits       = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    ipf.IMGEgapBits        = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    ipf.IMGEtrackBits      = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    ipf.IMGEblockCount     = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    ipf.IMGEencoderProcess = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    ipf.IMGEtrackFlags     = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    ipf.IMGEdataKey        = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    startPos += 12;                             // reserved
                    break;

                case RecordHeaderType.DATA:
                    ipf.DATAlength = MediaConverter.GetBEInt32(data, startPos);
                    if (ipf.DATAlength == 0)
                    {
                        ipf.DATAextraDataRaw = new byte[0];
                        ipf.DATAlength       = 0;
                    }
                    else
                    {
                        ipf.DATAextraDataRaw = new byte[ipf.DATAlength];
                    }
                    startPos       += 4;
                    ipf.DATAbitSize = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    ipf.DATAcrc     = MediaConverter.GetBEInt32(data, startPos); startPos += 4;
                    ipf.DATAdataKey = MediaConverter.GetBEInt32(data, startPos); startPos += 4;

                    if (ipf.DATAlength != 0)
                    {
                        Array.Copy(data, startPos, ipf.DATAextraDataRaw, 0, ipf.DATAlength);
                    }

                    startPos += ipf.DATAlength;
                    break;
                }

                return(ipf);
            }