private void EmulatorThreadProc(string rom) { if (!String.IsNullOrEmpty(rom)) { emulator.LoadFile(rom); } else { //emulator.LoadFile(@"Z:\public\ROMs\NES\World\Super Mario Bros. (W) [!].nes"); //emulator.LoadFile(@"Z:\public\ROMs\NES\World\Mario Bros. (W) [!].nes"); //emulator.LoadFile(@"Z:\public\ROMs\NES\USA\Arkanoid (U) [!].nes"); //emulator.LoadFile(@"Z:\public\ROMs\NES\World\Donkey Kong (W) (PRG1) [!].nes"); //emulator.LoadFile(@"Z:\public\ROMs\NES\World\Duck Hunt (W) [!].nes"); //emulator.LoadFile(@"Z:\public\ROMs\NES\tests\spritecans-2011\spritecans.nes"); //emulator.LoadFile(@"Z:\public\ROMs\NES\USA\Balloon Fight (U) [!].nes"); //emulator.LoadFile(@"Z:\public\ROMs\NES\USA\Legend of Zelda, The (U) (PRG1) [!].nes"); //emulator.LoadFile(@"Z:\public\ROMs\NES\Tests\holy_diver\testroms\M4_P256K_C256K.nes"); //emulator.LoadFile(@"Z:\public\ROMs\NES\USA\Super Mario Bros. 2 (U) (PRG1) [!].nes"); //emulator.LoadFile(@"Z:\public\ROMs\NES\USA\Super Mario Bros. 3 (U) (PRG1) [!].nes"); //emulator.LoadFile(@"Z:\public\ROMs\NES\Tests\mmc3_test\1-clocking.nes"); emulator.LoadFile(@"Z:\public\ROMs\NES\USA\Kirby's Adventure (U) (PRG1) [!].nes"); //emulator.LoadFile(@"Z:\public\ROMs\NES\Unlicensed\Hot Dance 2000 (Unl).nes"); //emulator.LoadFile(@"Z:\public\ROMs\NES\Tests\apu_mixer\square.nes"); } emulator.Run(); }
public void Start(EmulationContext context, IEventAggregator eventAggregator, EmulationMode mode) { _emulator = _emulatorRegistry.GetEmulator(context.EmulatedSystem, _handle); IRomSource loader = null; if (context.Game.RomPath.ToLower().EndsWith(".zip")) { loader = new ZipRomSource(context.Game.RomPath); } else { loader = new FileRomSource(context.Game.RomPath); } using (var romData = loader.GetRomData()) { if (!_emulator.IsRomValid(romData)) return; romData.Seek(0, System.IO.SeekOrigin.Begin); _emulator.LoadRom(romData, null); } eventAggregator.Publish(new EmulatorStartingEvent(InstanceId, this, context.Game, mode)); while (_bus.HasMessages) { _bus.GetCommand().Execute(_emulator); } _emulator.Initialize(eventAggregator); int pixelWidth, pixelHeight; Wren.Core.PixelFormats requestedPixelFormat; Int32 framePerSecond; // assemble rendering pipeline _emulator.GetSpecifications(out pixelWidth, out pixelHeight, out framePerSecond, out requestedPixelFormat); var rSource = _renderingSourceFactory.Create(pixelWidth, pixelHeight, requestedPixelFormat); eventAggregator.Publish(new RenderingSurfaceCreatedEvent(this.InstanceId, rSource.MemorySection, rSource.RenderingSurface, rSource.SurfaceInformation)); _emulator.SetRenderingSurface(rSource.RenderingSurface); var input = _inputPipeline.BuildInputSource(context); eventAggregator.Publish(new EmulatorStartedEvent(this.InstanceId)); FrameRateTimer fp = _frameRateTimerFactory.GetFrameRateTimer(framePerSecond); fp.ScheduleAction(() => { while (_bus.HasMessages) { _bus.GetCommand().Execute(_emulator); } _emulator.SetInput(input.GetCurrentInputState()); Boolean isRunning; try { isRunning = _emulator.Run(); } catch { isRunning = false; } eventAggregator.Publish(new FrameRenderedEvent(this.InstanceId)); if (!isRunning) { eventAggregator.Publish(new EmulatorQuitEvent(this.InstanceId)); input.Close(); } return isRunning; }); if (!fp.IsRunning) { fp.Start(); } }