示例#1
0
        private byte DetermineCartridgeMapperId(uint romCrc, byte romMapperId)
        {
            NstDatabaseEntry nstDatabaseEntry = nstDatabase[romCrc];

            if (nstDatabaseEntry == null)
            {
                return(romMapperId);
            }

            if (nstDatabaseEntry.MapperId != romMapperId)
            {
                statusHistoryLabel.Text = "Incorrect Mapper ID detected (" + romMapperId + "), should be " + nstDatabaseEntry.MapperId;
            }

            return(nstDatabaseEntry.MapperId);
        }
示例#2
0
        private bool LoadCartridgeRom(string cartridgeRomPath)
        {
            try
            {
                // save previous SRAM if applicable
                if (this.cartridge != null && this.cartridge.SaveRam.Modified)
                {
                    StoreSaveRam();
                }

                Stream cartridgeRomStream = GetCartridgeRomStream(cartridgeRomPath);

                BinaryReader romBinaryReader = new BinaryReader(cartridgeRomStream);
                Cartridge    newCartridge    = new Cartridge(romBinaryReader);
                romBinaryReader.Close();

                // load SRAM if file exists
                this.cartridgeSaveRamFilename = ReplaceRomExtension(cartridgeRomPath, ".sram");

                if (File.Exists(this.cartridgeSaveRamFilename))
                {
                    BinaryReader saveRamBinaryReader = new BinaryReader(new FileStream(this.cartridgeSaveRamFilename, FileMode.Open));
                    newCartridge.SaveRam.Load(saveRamBinaryReader);
                    saveRamBinaryReader.Close();
                    statusHistoryLabel.Text = "SaveRam file detected and loaded";
                }

                Console.LoadCartridge(newCartridge);

                this.cartridge = newCartridge;

                this.cartridgeRomFilename = Path.GetFileNameWithoutExtension(cartridgeRomPath);

                this.Text = cartridgeRomFilename + " - " + Application.ProductName;

                // enable some menu items dependent on a loaded cartridge
                filePropertiesMenuItem.Enabled = true;
                gameMenuItem.Enabled           = true;
                optionsCheatsMenuItem.Enabled  = true;

                if (traceEnabled)
                {
                    Console.Cartridge.Map.ProgramBankSwitch =
                        (address, size) => codeDisassemblyForm.InvalidateMemoryRange(address, size);
                }

                OnGameStop(this, EventArgs.Empty);
                OnGameRunPause(this, EventArgs.Empty);

                recentFileManager.AddRecentFile(cartridgeRomPath);

                // set video file paths
                this.videoPathMp4 = ReplaceRomExtension(cartridgeRomPath, ".mp4");
                this.videoPathGif = ReplaceRomExtension(cartridgeRomPath, ".gif");

                // set cursor to crosshairs if it is a gun-based game
                cartridgeUsesGun = false;
                NstDatabaseEntry nstDatabaseEntry = nstDatabase[cartridge.Crc];
                if (nstDatabaseEntry != null && nstDatabaseEntry.Peripherals.Contains(Peripheral.Zapper))
                {
                    cartridgeUsesGun = true;
                }
                videoPanel.Cursor = cartridgeUsesGun ? Cursors.Cross : Cursors.Default;

                // load cheat file if present
                cheatSystem.Clear();
                string cheatFilePath = ReplaceRomExtension(cartridgeRomPath, ".cht");
                if (File.Exists(cheatFilePath))
                {
                    cheatSystem.Load(cheatFilePath);
                    statusHistoryLabel.Text = "Cheat file loaded";
                }

                return(true);
            }
            catch (Exception exception)
            {
                MessageBox.Show(this, "Unable to load cartridge rom. Reason: " + exception.Message, "Open Game ROM", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
        }