Beispiel #1
0
 private void UpdateOffsetAndSpeed()
 {
     offset = Data.GetRomSettingOffset(mode);
     if (offset >= data.Length)
     {
         speed        = Data.ROMSpeed.Unknown;
         okay.Enabled = false;
     }
     else
     {
         okay.Enabled = true;
         speed        = (data[offset] & 0x10) != 0 ? Data.ROMSpeed.FastROM : Data.ROMSpeed.SlowROM;
     }
 }
Beispiel #2
0
        private static bool ValidateROM(string filename, string romName, int checksums, Data.ROMMapMode mode, out byte[] rom, OpenFileDialog open)
        {
            bool validFile = false, matchingROM = false;

            rom = null;
            open.InitialDirectory = currentFile;

            while (!matchingROM)
            {
                string error = null;
                matchingROM = false;

                while (!validFile)
                {
                    error     = null;
                    validFile = false;

                    try
                    {
                        byte[] smc = File.ReadAllBytes(filename);
                        rom = new byte[smc.Length & 0x7FFFFC00];

                        if ((smc.Length & 0x3FF) == 0x200)
                        {
                            for (int i = 0; i < rom.Length; i++)
                            {
                                rom[i] = smc[i + 0x200];
                            }
                        }
                        else if ((smc.Length & 0x3FF) != 0)
                        {
                            error = "The linked ROM has an unusual size. It can't be opened.";
                        }
                        else
                        {
                            rom = smc;
                        }

                        if (error == null)
                        {
                            validFile = true;
                        }
                    }
                    catch (Exception)
                    {
                        error = string.Format("The linked ROM file '{0}' couldn't be found.", filename);
                    }

                    if (!validFile)
                    {
                        DialogResult result = MessageBox.Show(string.Format("{0} Link a new ROM now?", error), "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                        if (result == DialogResult.No)
                        {
                            return(false);
                        }
                        result = open.ShowDialog();
                        if (result == DialogResult.OK)
                        {
                            filename = open.FileName;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }

                validFile = false;
                int offset = Data.GetRomSettingOffset(mode);
                if (rom.Length <= offset + 10)
                {
                    error = "The linked ROM is too small. It can't be opened.";
                }

                string myName = "";
                for (int i = 0; i < 0x15; i++)
                {
                    myName += (char)rom[offset - 0x15 + i];
                }
                int myChecksums = Util.ByteArrayToInteger(rom, offset + 7);

                if (myName != romName)
                {
                    error = string.Format("The linked ROM's internal name '{0}' doesn't match the project's internal name of '{1}'.", myName, romName);
                }
                else if (checksums != myChecksums)
                {
                    error = string.Format("The linked ROM's checksums '{0:X8}' don't match the project's checksums of '{1:X8}'.", myChecksums, checksums);
                }

                if (error == null)
                {
                    matchingROM = true;
                }

                if (!matchingROM)
                {
                    DialogResult result = MessageBox.Show(string.Format("{0} Link a new ROM now?", error), "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                    if (result == DialogResult.No)
                    {
                        return(false);
                    }
                    result = open.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        filename = open.FileName;
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            if (currentROMFile != filename)
            {
                currentROMFile = filename;
                unsavedChanges = true;
            }
            return(true);
        }