Ejemplo n.º 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;
                    }

                    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.");
                }
            }
Ejemplo n.º 2
0
        /// <summary>
        /// Attempts to load all media into the relevant structures
        /// </summary>
        protected void LoadAllMedia()
        {
            tapeImages = new List <byte[]>();
            diskImages = new List <byte[]>();

            int cnt = 0;

            foreach (var m in mediaImages)
            {
                switch (IdentifyMedia(m))
                {
                case CPCMediaType.Tape:
                    tapeImages.Add(m);
                    CPC._tapeInfo.Add(CPC._gameInfo[cnt]);
                    break;

                case CPCMediaType.Disk:
                    diskImages.Add(m);
                    CPC._diskInfo.Add(CPC._gameInfo[cnt]);
                    break;

                case CPCMediaType.DiskDoubleSided:
                    // this is a bit tricky. we will attempt to parse the double sided disk image byte array,
                    // then output two separate image byte arrays
                    List <byte[]> working = new List <byte[]>();
                    foreach (DiskType type in Enum.GetValues(typeof(DiskType)))
                    {
                        bool found = false;

                        switch (type)
                        {
                        case DiskType.CPCExtended:
                            found = CPCExtendedFloppyDisk.SplitDoubleSided(m, working);
                            break;

                        case DiskType.CPC:
                            found = CPCFloppyDisk.SplitDoubleSided(m, working);
                            break;
                        }

                        if (found)
                        {
                            // add side 1
                            diskImages.Add(working[0]);
                            // add side 2
                            diskImages.Add(working[1]);

                            Common.GameInfo one = new Common.GameInfo();
                            Common.GameInfo two = new Common.GameInfo();
                            var             gi  = CPC._gameInfo[cnt];
                            for (int i = 0; i < 2; i++)
                            {
                                Common.GameInfo work = new Common.GameInfo();
                                if (i == 0)
                                {
                                    work = one;
                                }
                                else if (i == 1)
                                {
                                    work = two;
                                }

                                work.FirmwareHash  = gi.FirmwareHash;
                                work.Hash          = gi.Hash;
                                work.Name          = gi.Name + " (Parsed Side " + (i + 1) + ")";
                                work.Region        = gi.Region;
                                work.NotInDatabase = gi.NotInDatabase;
                                work.Status        = gi.Status;
                                work.System        = gi.System;

                                CPC._diskInfo.Add(work);
                            }
                        }
                        else
                        {
                        }
                    }
                    break;
                }

                cnt++;
            }

            if (tapeImages.Count > 0)
            {
                LoadTapeMedia();
            }

            if (diskImages.Count > 0)
            {
                LoadDiskMedia();
            }
        }