Ejemplo n.º 1
0
        private static void OpenVersion1(byte[] unzipped, OpenFileDialog open)
        {
            Data.ROMMapMode mode = (Data.ROMMapMode)unzipped[HEADER_SIZE];
            Data.ROMSpeed   speed = (Data.ROMSpeed)unzipped[HEADER_SIZE + 1];
            int             size = Util.ByteArrayToInteger(unzipped, HEADER_SIZE + 2);
            string          romName = "", romLocation = "";

            byte[] rom;

            int pointer = HEADER_SIZE + 6;

            for (int i = 0; i < 0x15; i++)
            {
                romName += (char)unzipped[pointer++];
            }
            int checksums = Util.ByteArrayToInteger(unzipped, pointer);

            pointer += 4;
            while (unzipped[pointer] != 0)
            {
                romLocation += (char)unzipped[pointer++];
            }
            pointer++;

            if (ValidateROM(romLocation, romName, checksums, mode, out rom, open))
            {
                Data.Initiate(rom, mode, speed);

                for (int i = 0; i < size; i++)
                {
                    Data.SetDataBank(i, unzipped[pointer + i]);
                }
                for (int i = 0; i < size; i++)
                {
                    Data.SetDirectPage(i, unzipped[pointer + size + i] | (unzipped[pointer + 2 * size + i] << 8));
                }
                for (int i = 0; i < size; i++)
                {
                    Data.SetXFlag(i, unzipped[pointer + 3 * size + i] != 0);
                }
                for (int i = 0; i < size; i++)
                {
                    Data.SetMFlag(i, unzipped[pointer + 4 * size + i] != 0);
                }
                for (int i = 0; i < size; i++)
                {
                    Data.SetFlag(i, (Data.FlagType)unzipped[pointer + 5 * size + i]);
                }
                for (int i = 0; i < size; i++)
                {
                    Data.SetArchitechture(i, (Data.Architechture)unzipped[pointer + 6 * size + i]);
                }
                for (int i = 0; i < size; i++)
                {
                    Data.SetInOutPoint(i, (Data.InOutPoint)unzipped[pointer + 7 * size + i]);
                }

                pointer += 8 * size;
                int label_count = Util.ByteArrayToInteger(unzipped, pointer);
                pointer += 4;

                AliasList.me.Reset();
                for (int i = 0; i < label_count; i++)
                {
                    int offset = Util.ByteArrayToInteger(unzipped, pointer);
                    pointer += 4;

                    string label = "";
                    while (unzipped[pointer] != 0)
                    {
                        label += (char)unzipped[pointer++];
                    }
                    pointer++;

                    Data.AddLabel(offset, label, true);
                }

                int comment_count = Util.ByteArrayToInteger(unzipped, pointer);
                pointer += 4;

                for (int i = 0; i < comment_count; i++)
                {
                    int offset = Util.ByteArrayToInteger(unzipped, pointer);
                    pointer += 4;

                    string comment = "";
                    while (unzipped[pointer] != 0)
                    {
                        comment += (char)unzipped[pointer++];
                    }
                    pointer++;

                    Data.AddComment(offset, comment, true);
                }
            }
            else
            {
                throw new Exception("Couldn't open the ROM file!");
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        // differences between version 0 and version 1:
        // version 0: addresses for aliases and comments were stored in PC offset format.
        //            tables: B, D lo, D hi, X, M, flag, arch, inoutpoint
        //            lists: alias, comment
        // version 1: addresses for aliases and comments are stored in SNES address format.
        //            tables: B, D lo, D hi, X, M, flag, arch, inoutpoint, ???
        //            lists: alias, comment, ???
        private static void OpenVersion0(byte[] unzipped, OpenFileDialog open)
        {
            MessageBox.Show(
                "This project file is in an older format.\n" +
                "You may want to back up your work or 'Save As' in case the conversion goes wrong.\n" +
                "The project file will be untouched until it is saved again.",
                "Project File Out of Date", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

            Data.ROMMapMode mode = (Data.ROMMapMode)unzipped[HEADER_SIZE];
            Data.ROMSpeed   speed = (Data.ROMSpeed)unzipped[HEADER_SIZE + 1];
            int             size = Util.ByteArrayToInteger(unzipped, HEADER_SIZE + 2);
            string          romName = "", romLocation = "";

            byte[] rom;

            int pointer = HEADER_SIZE + 6;

            for (int i = 0; i < 0x15; i++)
            {
                romName += (char)unzipped[pointer++];
            }
            int checksums = Util.ByteArrayToInteger(unzipped, pointer);

            pointer += 4;
            while (unzipped[pointer] != 0)
            {
                romLocation += (char)unzipped[pointer++];
            }
            pointer++;

            if (ValidateROM(romLocation, romName, checksums, mode, out rom, open))
            {
                Data.Initiate(rom, mode, speed);

                for (int i = 0; i < size; i++)
                {
                    Data.SetDataBank(i, unzipped[pointer + i]);
                }
                for (int i = 0; i < size; i++)
                {
                    Data.SetDirectPage(i, unzipped[pointer + size + i] | (unzipped[pointer + 2 * size + i] << 8));
                }
                for (int i = 0; i < size; i++)
                {
                    Data.SetXFlag(i, unzipped[pointer + 3 * size + i] != 0);
                }
                for (int i = 0; i < size; i++)
                {
                    Data.SetMFlag(i, unzipped[pointer + 4 * size + i] != 0);
                }
                for (int i = 0; i < size; i++)
                {
                    Data.SetFlag(i, (Data.FlagType)unzipped[pointer + 5 * size + i]);
                }
                for (int i = 0; i < size; i++)
                {
                    Data.SetArchitechture(i, (Data.Architechture)unzipped[pointer + 6 * size + i]);
                }
                for (int i = 0; i < size; i++)
                {
                    Data.SetInOutPoint(i, (Data.InOutPoint)unzipped[pointer + 7 * size + i]);
                }

                pointer += 8 * size;
                int label_count = Util.ByteArrayToInteger(unzipped, pointer);
                pointer += 4;

                AliasList.me.Reset();
                for (int i = 0; i < label_count; i++)
                {
                    int offset = Util.ConvertPCtoSNES(Util.ByteArrayToInteger(unzipped, pointer)); // pc -> snes
                    pointer += 4;

                    string label = "";
                    while (unzipped[pointer] != 0)
                    {
                        label += (char)unzipped[pointer++];
                    }
                    pointer++;

                    Data.AddLabel(offset, label, true);
                }

                int comment_count = Util.ByteArrayToInteger(unzipped, pointer);
                pointer += 4;

                for (int i = 0; i < comment_count; i++)
                {
                    int offset = Util.ConvertPCtoSNES(Util.ByteArrayToInteger(unzipped, pointer)); // pc -> snes
                    pointer += 4;

                    string comment = "";
                    while (unzipped[pointer] != 0)
                    {
                        comment += (char)unzipped[pointer++];
                    }
                    pointer++;

                    Data.AddComment(offset, comment, true);
                }
            }
            else
            {
                throw new Exception("Couldn't open the ROM file!");
            }
        }