示例#1
0
        public void LoadRom(FileStream file)
        {
            byte[] tempromData = new byte[file.Length];
            file.Read(tempromData, 0, (int)file.Length);

            if (IsRomHeadered((int)file.Length))
            {
                Console.WriteLine("Header Detected");
                romData = new byte[file.Length - 0x200];
                Array.Copy(tempromData, 0x200, romData, 0, (file.Length - 0x200));
            }
            else
            {
                romData = new byte[file.Length];
                Array.Copy(tempromData, 0, romData, 0, (file.Length));
            }

            romRegion = DetectRomRegion(romData);
            //Create all gfx data in Graphics static class as 4bpp indexed format
            ZGraphics.CreateAllGfxData(romData);
            Palettes.CreateAllPalettes(romData);


            LogData.SaveToFile("Logs.txt");
            Console.WriteLine("Rom Region Detected : " + romRegion.ToString());
        }
示例#2
0
        public void Read_FromRegion_ReadSuccess(uint startAddress)
        {
            byte[] dummyData = CreateDummyData();

            AgbMemoryMap map    = new AgbMemoryMap();
            RomRegion    region = new RomRegion(dummyData);

            map.RegisterRegion(region);

            for (uint address = startAddress; address < startAddress + RomRegion.REGION_SIZE; address++)
            {
                Assert.Equal(dummyData[address - startAddress], map.Read(address));
            }
        }
示例#3
0
        private void checkROM()
        {
            if (bytes[0] == 0x80 && bytes[1] == 0x37)
            {
                endian = RomEndian.Big;
            }
            else if (bytes[0] == 0x37 && bytes[1] == 0x80)
            {
                endian = RomEndian.Mixed;
            }
            else if (bytes[0] == 0x40 && bytes[1] == 0x12)
            {
                endian = RomEndian.Little;
            }

            if (endian == RomEndian.Mixed)
            {
                swapMixedBig();
            }
            else if (endian == RomEndian.Little)
            {
                swapLittleBig();
            }

            if (bytes[0x3E] == 0x45)
            {
                region = RomRegion.NorthAmerica;
            }
            else if (bytes[0x3E] == 0x50)
            {
                region = RomRegion.Europe;
            }
            else if (bytes[0x3E] == 0x4A)
            {
                if (bytes[0x3F] < 3)
                {
                    region = RomRegion.Japan;
                }
                else
                {
                    region = RomRegion.JapanShindou;
                }
            }

            // Setup segment 0x02 & segment 0x15 addresses
            if (region == RomRegion.NorthAmerica)
            {
                Globals.macro_preset_table   = 0xEC7E0;
                Globals.special_preset_table = 0xED350;
                // Globals.seg02_location = new[] { (uint)0x108A40, (uint)0x114750 };
                Globals.seg15_location = new[] { (uint)0x2ABCA0, (uint)0x2AC6B0 };
            }
            else if (region == RomRegion.Europe)
            {
                Globals.macro_preset_table   = 0xBD590;
                Globals.special_preset_table = 0xBE100;
                // Globals.seg02_location = new[] { (uint)0xDE190, (uint)0xE49F0 };
                Globals.seg15_location = new[] { (uint)0x28CEE0, (uint)0x28D8F0 };
            }
            else if (region == RomRegion.Japan)
            {
                Globals.macro_preset_table   = 0xEB6D0;
                Globals.special_preset_table = 0xEC240;
                // Globals.seg02_location = new[] { (uint)0x1076D0, (uint)0x112B50 };
                Globals.seg15_location = new[] { (uint)0x2AA240, (uint)0x2AAC50 };
            }
            else if (region == RomRegion.JapanShindou)
            {
                Globals.macro_preset_table   = 0xC8D60;
                Globals.special_preset_table = 0xC98D0;
                //Globals.seg02_location = new[] { (uint)0xE42F0, (uint)0xEF770 };
                Globals.seg15_location = new[] { (uint)0x286AC0, (uint)0x2874D0 };
            }

            findAndSetSegment02();
            Console.WriteLine("Segment2 location: 0x" + Globals.seg02_location[0].ToString("X8") +
                              " to 0x" + Globals.seg02_location[1].ToString("X8"));

            if (bytes[Globals.seg15_location[0]] == 0x17)
            {
                type = RomType.Extended;
            }
            else
            {
                type = RomType.Vanilla;
            }


            Console.WriteLine("ROM = " + filepath);
            Console.WriteLine("ROM Endian = " + endian);
            Console.WriteLine("ROM Region = " + region);
            Console.WriteLine("ROM Type = " + type);
            Console.WriteLine("-----------------------");
        }
示例#4
0
        void ReplaceRomButtonClick(object sender, EventArgs e)
        {
            try
            {
                replaceFileDialog.Title = "Replace ROM";
                if (replaceFileDialog.ShowDialog(this) == DialogResult.OK)
                {
                    changed = true;
                    byte[] rom = File.ReadAllBytes(replaceFileDialog.FileName);
                    pak.SetImage(rom);
                    romSizeLabel.Text     = (pak.ImageSize / 1024) + " KB";
                    dumpRomButton.Enabled = true;

                    // Attempt to auto-load some info from ROM
                    try
                    {
                        using (var ms = new MemoryStream(rom))
                        {
                            var br = new BinaryReader(ms);

                            // Game name
                            ms.Seek(0x120, SeekOrigin.Begin);
                            nameTextBox.Text = new string(br.ReadChars(0x30)).TrimEnd(' ');

                            // SRAM configuration
                            ms.Seek(0x1b0, SeekOrigin.Begin);
                            if (br.ReadChar() == 'R' && br.ReadChar() == 'A')
                            {
                                byte          x              = br.ReadByte();
                                byte          y              = br.ReadByte();
                                uint          ramStart       = (uint)((br.ReadByte() << 24) | (br.ReadByte() << 16) | (br.ReadByte() << 8) | br.ReadByte());
                                uint          ramEnd         = (uint)((br.ReadByte() << 24) | (br.ReadByte() << 16) | (br.ReadByte() << 8) | br.ReadByte());
                                ExtraSaveMode mode           = ExtraSaveMode.None;
                                ushort        ramStartPacked = (ushort)((ramStart >> 0x0c) & 0x3fff);
                                if (y == 0x20)
                                {
                                    uint ramSize = ramEnd - ramStart;
                                    mode = ExtraSaveMode.Sram;
                                    extraPageMaskTextBox.Text = ramStartPacked.ToString("X4");
                                    extraSizeMaskTextbox.Text = (((ramSize + 0xff) >> 8) & 0xffff).ToString("X4");
                                }
                                else
                                {
                                    // Probably EEPROM
                                    mode = ExtraSaveMode.EepromMode1; // Give a reasonable default
                                    extraPageMaskTextBox.Text = ramStartPacked.ToString("X4");
                                    extraSizeMaskTextbox.Text = (256 >> 8).ToString("X4");
                                }
                                extraSaveModeComboBox.SelectedIndex = (int)mode;
                            }
                            else
                            {
                                extraSaveModeComboBox.SelectedIndex = (int)ExtraSaveMode.None;
                            }

                            // Game region
                            ms.Seek(0x1f0, SeekOrigin.Begin);
                            string regions = new string(br.ReadChars(0x10)).TrimEnd(' ');
                            int    rflags  = 0;
                            if (regions.Contains("U"))
                            {
                                rflags |= 1 << 0;
                            }
                            if (regions.Contains("J"))
                            {
                                rflags |= 1 << 1;
                            }
                            if (regions.Contains("E"))
                            {
                                rflags |= 1 << 2;
                            }
                            RomRegion renum = RomRegion.Worldwide;
                            if (rflags != 0 && (rflags & (rflags - 1)) == 0) // Only one flag present
                            {
                                switch (rflags)
                                {
                                case 1 << 0:
                                        renum = RomRegion.Usa;
                                    break;

                                case 1 << 1:
                                        renum = RomRegion.Japan;
                                    break;

                                case 1 << 2:
                                        renum = RomRegion.Europe;
                                    break;
                                }
                            }
                            regionComboBox.SelectedIndex = (int)renum;
                        }
                    }
                    catch { }

                    saveButton.Enabled         = true;
                    replaceThumbButton.Enabled = true;
                    MessageBox.Show(this, "ROM replaced.", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "Error replacing ROM: " + ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }