Пример #1
0
        private void StartEmu()
        {
            bool logState = false;
            if (this.cpu != null)
                logState = this.cpu.debug.logging;
            if (renderer != null)
                renderer.Destroy();
            if (audio != null)
                audio.Destroy();
            if (input != null)
                input.Destroy();
            if (config["audio"] == "DXS") //DirectSound has some issues with unusual samplerates
                config["sampleRate"] = 48000.ToString();
            try
            {
                if (Path.GetExtension(romPath).ToLower() == ".fds")
                    this.cpu = new NESCore((SystemType)Convert.ToInt32(config["region"]), config["fdsBios"], this.romPath, this.appPath, Convert.ToInt32(this.config["sampleRate"]));
                else if (Path.GetExtension(romPath).ToLower() == ".nsf")
                    this.cpu = new NESCore(this.romPath, Convert.ToInt32(this.config["sampleRate"]));
                else
                    this.cpu = new NESCore((SystemType)Convert.ToInt32(config["region"]), this.romPath, this.appPath, Convert.ToInt32(this.config["sampleRate"]));
            }
            catch (BadHeaderException e)
            {
                if (MessageBox.Show("File appears to be invalid. Attempt load anyway?", "Error", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    if (Path.GetExtension(romPath).ToLower() == ".fds")
                        this.cpu = new NESCore((SystemType)Convert.ToInt32(config["region"]), config["fdsBios"], this.romPath, this.appPath, Convert.ToInt32(this.config["sampleRate"]), true);
                    else if (Path.GetExtension(romPath).ToLower() == ".nsf")
                        this.cpu = new NESCore(this.romPath, Convert.ToInt32(this.config["sampleRate"]), true);
                    else
                        this.cpu = new NESCore((SystemType)Convert.ToInt32(config["region"]), this.romPath, this.appPath, Convert.ToInt32(this.config["sampleRate"]), true);
                else
                    throw (e);
            }
            catch (FDSBiosException e)
            {
                MessageBox.Show("FDS BIOS image (" + config["fdsBios"] + ") not found.");
                return;
            }
            this.frame = 0;
            moviePtr = 0;
            this.saveBufferAvaliable = 0;
            this.cpu.debug.logging = logState;
            this.cpu.PPU.displayBG = (config["displayBG"] == "1");
            this.cpu.PPU.displaySprites = (config["displaySprites"] == "1");
            this.cpu.PPU.enforceSpriteLimit = !(config["disableSpriteLimit"] == "1");
            if (config["simulatedPalette"] == "1")
            {
                NTSCFilter.gamma = double.Parse(config["gamma"]);
                NTSCFilter.hue = double.Parse(config["hue"]);
                NTSCFilter.sat = double.Parse(config["saturation"]);
                NTSCFilter.brightness = double.Parse(config["brightness"]);
                this.cpu.PPU.colorChart = NTSCFilter.NesPalette;
            }
            else
            {
                this.cpu.PPU.colorChart = this.colorChart;
            }
            if (config["rawNESPalette"] == "1")
            {
                for (uint i = 0; i < 0x200; i++)
                    this.cpu.PPU.colorChart[i] = i;
            }
            this.cpu.APU.mute = !(config["sound"] == "1");
            this.cpu.APU.volume = volume;
            this.LoadGame();
            this.LoadSaveStateFiles();
            this.cpu.gameGenieCodeNum = this.gameGenieCodeCount;
            this.cpu.gameGenieCodes = this.gameGenieCodes;
            this.Text = this.cpu.rom.fileName + " - Emu-o-Tron";
            this.state = SystemState.Playing;
            this.surfaceControl.Visible = true;
            if (this.cpu.rom.vsUnisystem)
            {
                this.state = SystemState.SystemPause;
                DipDialog DipDiag = new DipDialog();
                DipDiag.FormClosing += new FormClosingEventHandler(DipDiag_FormClosing);
                DipDiag.ShowDialog();
            }
            if (debugger != null)
                debugger.Close();
            debugger = new Debugger(cpu.debug);
            debugger.UpdateDebug();
            ejectDiskToolStripMenuItem.DropDownItems.Clear();
            ejectDiskToolStripMenuItem.Text = "Eject Disk";
            ejectDiskToolStripMenuItem.Visible = (cpu.GetSideCount() != 0);
            cpu.SetControllers((ControllerType)Enum.Parse(typeof(ControllerType), config["portOne"]), (ControllerType)Enum.Parse(typeof(ControllerType), config["portTwo"]), (ControllerType)Enum.Parse(typeof(ControllerType), config["expansion"]), config["fourScore"] == "1", config["filterIllegalInput"] == "1");

            if (cpu.nsfPlayer)
                nsfScreen = new NSFScreen(cpu);

            switch (config["renderer"])
            {
            #if NO_DX

                default:
                case "GDI":
                    config["renderer"] = "GDI";
                    renderer = new GDIRenderer(surfaceControl, imageScaler, cpu.PPU.screen, smoothOutputToolStripMenuItem.Checked);
                    break;
            #else
                case "GDI":
                    renderer = new GDIRenderer(surfaceControl, imageScaler, cpu.PPU.screen, smoothOutputToolStripMenuItem.Checked);
                    break;
                default:
                case "DX9":
                    config["renderer"] = "DX9";
                    renderer = new DX9Renderer(surfaceControl, imageScaler, cpu.PPU.screen, smoothOutputToolStripMenuItem.Checked);
                    break;
                case "DX10":
                    renderer = new DX10Renderer(surfaceControl, imageScaler, cpu.PPU.screen, smoothOutputToolStripMenuItem.Checked);
                    break;
            #endif
                case "OGL":
                    renderer = new OpenGLRenderer(surfaceControl, imageScaler, cpu.PPU.screen, smoothOutputToolStripMenuItem.Checked);
                    break;
                case "Null":
                    renderer = new NullRenderer();
                    break;
            }
            renderer.DrawMessageEvent += new EventHandler(renderer_DrawMessageEvent);
            renderer.Create();

            switch (config["audio"])
            {
                case "OAL":
                    audio = new OpenALAudio(cpu.APU.sampleRate, cpu.APU.output, Convert.ToInt32(config["volume"]) / 100f);
                    break;

            #if NO_DX
                default:
                case "Null":
                    config["audio"] = "Null";
                    audio = new NullAudio(cpu.APU.sampleRate);
                    break;
            #else
                default:
                case "XA2":
                    config["audio"] = "XA2";
                    audio = new XA2Audio(cpu.APU.sampleRate, cpu.APU.output, Convert.ToInt32(config["volume"]) / 100f);
                    break;
                case "DXS":
                    audio = new DXSAudio(cpu.APU.sampleRate, cpu.APU.output, Convert.ToInt32(config["volume"]) / 100f, this.Handle);
                    break;
                case "Null":
                    audio = new NullAudio(cpu.APU.sampleRate);
                    break;
            #endif
            }
            audio.Create();

            switch (config["input"])
            {
                default:
                case "Win":
                    config["input"] = "Win";
                    input = new WinInput(this, surfaceControl);
                    break;
            #if !NO_DX
                case "DX":
                    input = new DXInput(this);
                    break;
                case "XIn":
                    input = new XInInput();
                    break;
            #endif
                case "Null":
                    input = new NullInput();
                    break;
            }
            input.Create();
            input.InputEvent += new InputHandler(input_InputEvent);
            input.InputScalerEvent += new InputScalerHandler(input_InputScalerEvent);
        }