Exemplo n.º 1
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!");
            }
        }
Exemplo n.º 2
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!");
            }
        }
Exemplo n.º 3
0
        public static bool NewProject(string filename)
        {
            try
            {
                byte[] smc = File.ReadAllBytes(filename);
                byte[] 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)
                {
                    throw new Exception("This ROM has an unusual size. It can't be opened.");
                }
                else
                {
                    rom = smc;
                }

                if (rom.Length < 0x8000)
                {
                    throw new Exception("This ROM is too small. It can't be opened.");
                }

                currentROMFile = filename;

                ImportROMDialog import = new ImportROMDialog(rom);
                DialogResult    result = import.ShowDialog();
                if (result == DialogResult.OK)
                {
                    Data.Initiate(rom, import.GetROMMapMode(), import.GetROMSpeed());
                    unsavedChanges = false;
                    currentFile    = null;

                    AliasList.me.Reset();
                    Dictionary <int, string> generatedLabels = import.GetGeneratedLabels();
                    if (generatedLabels.Count > 0)
                    {
                        foreach (KeyValuePair <int, string> pair in generatedLabels)
                        {
                            Data.AddLabel(pair.Key, pair.Value, true);
                        }
                        unsavedChanges = true;
                    }

                    Dictionary <int, Data.FlagType> generatedFlags = import.GetHeaderFlags();
                    if (generatedFlags.Count > 0)
                    {
                        foreach (KeyValuePair <int, Data.FlagType> pair in generatedFlags)
                        {
                            Data.SetFlag(pair.Key, pair.Value);
                        }
                        unsavedChanges = true;
                    }

                    return(true);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(false);
        }