コード例 #1
0
ファイル: Frm_RomInfo.cs プロジェクト: afonsof/nes-hd
 public Frm_RomInfo(string RomPath)
 {
     InitializeComponent();
     var header = new NesHeaderReader(RomPath);
     if (header.ValidRom)
     {
         textBox1_Name.Text = Path.GetFileNameWithoutExtension(RomPath);
         textBox1_prgs.Text = header.PrgRomPageCount.ToString();
         textBox2_Mapper.Text = header.MemoryMapper.ToString() + ", " + header.GetMapperName();
         textBox2_chr.Text = header.ChrRomPageCount.ToString();
         textBox3_mirroring.Text = header.VerticalMirroring ? "Vertical" : "Horizontal";
         checkBox1_four.Checked = header.FourScreenVRamLayout;
         checkBox1_saveram.Checked = header.SRamEnabled;
         checkBox2_trainer.Checked = header.TrainerPresent512;
     }
 }
コード例 #2
0
ファイル: BrowserForm.cs プロジェクト: afonsof/nes-hd
 private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
 {
     if (treeView1.SelectedNode == null)
         return;
     listView1.Items.Clear();
     pictureBox1.Image = Resources.NESDoc;
     richTextBox1.Text = "";
     var TR = (TreeNodeFolder) treeView1.SelectedNode;
     _SelectedFolder = TR;
     //Properties
     listView2.Items.Clear();
     listView2.Items.Add("Name");
     listView2.Items[listView2.Items.Count - 1].SubItems.Add(TR.Folder.Name);
     listView2.Items.Add("Path");
     listView2.Items[listView2.Items.Count - 1].SubItems.Add(TR.Folder.Path);
     listView2.Items.Add("Snapshots Path");
     listView2.Items[listView2.Items.Count - 1].SubItems.Add(TR.Folder.ImagesFolder);
     listView2.Items.Add("Info Texts Path");
     listView2.Items[listView2.Items.Count - 1].SubItems.Add(TR.Folder.InfosFolder);
     TextBox1_mapper.Text = _SelectedFolder.Folder.Mapper.ToString();
     switch (_SelectedFolder.Folder.Filter)
     {
         case FolderFilter.All:
             ComboBox1_nav.SelectedIndex = 0;
             TextBox1_mapper.Enabled = false;
             break;
         case FolderFilter.SupportedMappersOnly:
             ComboBox1_nav.SelectedIndex = 1;
             TextBox1_mapper.Enabled = false;
             break;
         case FolderFilter.Mapper:
             ComboBox1_nav.SelectedIndex = 2;
             TextBox1_mapper.Enabled = true;
             break;
     }
     if (!Directory.Exists(TR.Folder.Path))
     {
         MessageBox.Show("This folder isn't exist on the disk !!");
         DeleteFolder(this, null);
     }
     else
     {
         var Dirs = Directory.GetFiles(TR.Folder.Path);
         foreach (var Dir in Dirs)
         {
             var EXT = Path.GetExtension(Dir);
             switch (EXT.ToLower())
             {
                 case ".nes":
                     var IT = new ListViewItemRom();
                     IT.RomPath = Dir;
                     IT.ImageIndex = 2;
                     IT.Text = Path.GetFileName(Dir);
                     IT.SubItems.Add(Program.GetFileSize(Dir));
                     var header = new NesHeaderReader(Dir);
                     if (header.ValidRom)
                         IT.SubItems.Add(header.MemoryMapper.ToString() + ", " + header.GetMapperName());
                     switch (TR.Folder.Filter)
                     {
                         case FolderFilter.All:
                             listView1.Items.Add(IT);
                             break;
                         case FolderFilter.SupportedMappersOnly:
                             if (header.SupportedMapper())
                                 listView1.Items.Add(IT);
                             break;
                         case FolderFilter.Mapper:
                             if (header.MemoryMapper == Convert.ToInt32(TextBox1_mapper.Text))
                                 listView1.Items.Add(IT);
                             break;
                     }
                     break;
                 case ".rar":
                     var IT1 = new ListViewItemRom();
                     IT1.ImageIndex = 3;
                     IT1.RomPath = Dir;
                     IT1.Text = Path.GetFileName(Dir);
                     IT1.SubItems.Add(Program.GetFileSize(Dir));
                     IT1.SubItems.Add("N/A");
                     listView1.Items.Add(IT1);
                     break;
                 case ".zip":
                     var IT2 = new ListViewItemRom();
                     IT2.ImageIndex = 3;
                     IT2.RomPath = Dir;
                     IT2.Text = Path.GetFileName(Dir);
                     IT2.SubItems.Add(Program.GetFileSize(Dir));
                     IT2.SubItems.Add("N/A");
                     listView1.Items.Add(IT2);
                     break;
                 case ".7z":
                     var IT3 = new ListViewItemRom();
                     IT3.ImageIndex = 3;
                     IT3.RomPath = Dir;
                     IT3.Text = Path.GetFileName(Dir);
                     IT3.SubItems.Add(Program.GetFileSize(Dir));
                     IT3.SubItems.Add("N/A");
                     listView1.Items.Add(IT3);
                     break;
             }
         }
         label1_status.Text = listView1.Items.Count.ToString() + " items found.";
     }
 }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: afonsof/nes-hd
        public void OpenRom(string romPath)
        {
            _romFileName = romPath;
            if (File.Exists(romPath))
            {
                #region Check if archive

                var extension = Path.GetExtension(romPath);
                if (extension != null && extension.ToLower() != ".nes")
                {
                    try
                    {
                        _extractor = new SevenZipExtractor(romPath);
                    }
                    catch
                    {
                    }
                    if (_extractor.ArchiveFileData.Count == 1)
                    {
                        if (
                            _extractor.ArchiveFileData[0].FileName.Substring(
                                _extractor.ArchiveFileData[0].FileName.Length - 4, 4).ToLower() == ".nes")
                        {
                            _extractor.ExtractArchive(Path.GetTempPath());
                            romPath = Path.GetTempPath() + _extractor.ArchiveFileData[0].FileName;
                        }
                    }
                    else
                    {
                        var ar = new ArchivesForm(_extractor.ArchiveFileData.Select(file => file.FileName).ToArray());
                        ar.ShowDialog(this);
                        if (ar.Ok)
                        {
                            string[] fil = { ar.SelectedRom };
                            _extractor.ExtractFiles(Path.GetTempPath(), fil);
                            romPath = Path.GetTempPath() + ar.SelectedRom;
                        }
                        else
                        {
                            return;
                        }
                    }
                }

                #endregion

                #region Check the rom

                var header = new NesHeaderReader(romPath);
                if (header.ValidRom)
                {
                    if (!header.SupportedMapper())
                    {
                        MessageBox.Show("Can't load rom:\n" + romPath +
                                        "\n\nUNSUPPORTED MAPPER # " +
                                        header.MemoryMapper);
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("Can't load rom:\n" + romPath +
                                    "\n\nRom is damaged or not an INES format file");
                    return;
                }

                #endregion

                //Exit current thread
                if (_engine != null)
                {
                    _engine.ShutDown();
                    _engine = null;
                }
                if (_gameThread != null)
                {
                    _gameThread.Abort();
                }
                //Start new nes !!
                if (Program.Settings.PaletteFormat == null)
                    Program.Settings.PaletteFormat = new PaletteFormat();
                _engine = new NesEngine(Program.Settings.TV, Program.Settings.PaletteFormat);
                _engine.PauseToggle += NesPauseToggle;
                if (_engine.LoadRom(romPath))
                {
                    #region Setup input

                    var manager = new InputManager(Handle);
                    var joy1 = new Joypad(manager);
                    joy1.A.Input = Program.Settings.CurrentControlProfile.Player1A;
                    joy1.B.Input = Program.Settings.CurrentControlProfile.Player1B;
                    joy1.Up.Input = Program.Settings.CurrentControlProfile.Player1Up;
                    joy1.Down.Input = Program.Settings.CurrentControlProfile.Player1Down;
                    joy1.Left.Input = Program.Settings.CurrentControlProfile.Player1Left;
                    joy1.Right.Input = Program.Settings.CurrentControlProfile.Player1Right;
                    joy1.Select.Input = Program.Settings.CurrentControlProfile.Player1Select;
                    joy1.Start.Input = Program.Settings.CurrentControlProfile.Player1Start;
                    var joy2 = new Joypad(manager);
                    joy2.A.Input = Program.Settings.CurrentControlProfile.Player2A;
                    joy2.B.Input = Program.Settings.CurrentControlProfile.Player2B;
                    joy2.Up.Input = Program.Settings.CurrentControlProfile.Player2Up;
                    joy2.Down.Input = Program.Settings.CurrentControlProfile.Player2Down;
                    joy2.Left.Input = Program.Settings.CurrentControlProfile.Player2Left;
                    joy2.Right.Input = Program.Settings.CurrentControlProfile.Player2Right;
                    joy2.Select.Input = Program.Settings.CurrentControlProfile.Player2Select;
                    joy2.Start.Input = Program.Settings.CurrentControlProfile.Player2Start;
                    _engine.SetupInput(manager, joy1, joy2);

                    #endregion

                    #region Output

                    //Set the size
                    switch (Program.Settings.Size.ToLower())
                    {
                        case "x1":
                            Size = new Size(265, 305);
                            FormBorderStyle = FormBorderStyle.FixedDialog;
                            statusStrip1.SizingGrip = false;
                            break;
                        case "x2":
                            Size = new Size(521, 529);
                            FormBorderStyle = FormBorderStyle.FixedDialog;
                            statusStrip1.SizingGrip = false;
                            break;
                        case "stretch":
                            FormBorderStyle = FormBorderStyle.Sizable;
                            statusStrip1.SizingGrip = true;
                            break;
                    }
                    //The output devices
                    var mon = new SoundDeviceGeneral16(statusStrip1) { Stereo = Program.Settings.Stereo };
                    switch (Program.Settings.GFXDevice)
                    {
                        case GraphicDevices.Gdi:
                            var gdi = new VideoGdi(Program.Settings.TV, panel1);
                            _engine.SetupOutput(gdi, mon);
                            break;
                        case GraphicDevices.GdiHiRes:
                            var gdih = new VideoGdiHiRes(Program.Settings.TV, panel1,
                                                         _engine.Memory.Map.Cartridge.RomPath,
                                                         _engine.Memory.Map.Cartridge.ChrPages);
                            _engine.SetupOutput(gdih, mon);
                            break;
                        case GraphicDevices.SlimDx:
                            var sl = new VideoSlimDx(Program.Settings.TV, panel1, _engine.Memory.Map.Cartridge.Multi);
                            _engine.SetupOutput(sl, mon);
                            break;
                        default:
                            Program.Settings.GFXDevice = GraphicDevices.SlimDx;
                            var sl1 = new VideoSlimDx(Program.Settings.TV, panel1, _engine.Memory.Map.Cartridge.Multi);
                            _engine.SetupOutput(sl1, mon);
                            break;
                    }
                    if (_engine.Ppu.OutputDevice.SupportFullScreen)
                        _engine.Ppu.OutputDevice.FullScreen = Program.Settings.Fullscreen;
                    //Audio
                    _engine.SoundEnabled = Program.Settings.SoundEnabled;
                    _engine.Apu.Square1Enabled = Program.Settings.Square1;
                    _engine.Apu.Square2Enabled = Program.Settings.Square2;
                    _engine.Apu.DMCEnabled = Program.Settings.DMC;
                    _engine.Apu.TriangleEnabled = Program.Settings.Triangle;
                    _engine.Apu.NoiseEnabled = Program.Settings.Noize;
                    _engine.Apu.VRC6P1Enabled = Program.Settings.VRC6Pulse1;
                    _engine.Apu.VRC6P2Enabled = Program.Settings.VRC6Pulse2;
                    _engine.Apu.VRC6SawToothEnabled = Program.Settings.VRC6Sawtooth;
                    _engine.Apu.SetVolume(Program.Settings.Volume);

                    #endregion

                    #region Misc

                    _engine.Ppu.NoLimiter = Program.Settings.NoLimiter;
                    _engine.AutoSaveSram = Program.Settings.AutoSaveSRAM;

                    #endregion

                    //Launch
                    _myThreadCreator = _engine.Run;
                    _gameThread = new Thread(_myThreadCreator);
                    _gameThread.Start();
                    timer_FPS.Start();
                    StatusLabel4_status.BackColor = Color.Green;
                    StatusLabel4_status.Text = "ON";
                    //Add to the recent
                    AddRecent(romPath);
                    RefreshRecents();
                    //Set the name
                    Text = "My Nes - " + Path.GetFileNameWithoutExtension(romPath);
                }
                else
                {
                    MessageBox.Show("Can't load rom:\n" + romPath +
                                    "\n\nRom is damaged or not an INES format file !!");
                    if (_engine != null)
                    {
                        _engine.ShutDown();
                        _engine = null;
                    }
                    if (_gameThread != null)
                    {
                        _gameThread.Abort();
                    }
                    return;
                }
            }
        }