public Emulator(TVSystem tvFormat) { this.TVFormat = tvFormat; this.InitializeComponents( out this.ppu, out this.interrupts, out this.memory, out this.dma, out this.apu, out this.cpu, out this.input, out this.legacyNesEmu); this.input.InitializeInput(); this.emulationState = new EmulationState( this, this.ppu, this.interrupts, this.memory, this.dma, this.apu, this.cpu, this.input, this.ppu.videoOut); switch (TVFormat) { case TVSystem.NTSC: this.apu.SystemIndex = 0; this.apu.audio_playback_samplePeriod = 1789772.67f; break; case TVSystem.PALB: this.apu.SystemIndex = 1; this.apu.audio_playback_samplePeriod = 1662607f; break; case TVSystem.DENDY: this.apu.SystemIndex = 2; this.apu.audio_playback_samplePeriod = 1773448f; break; } if (TVFormat == TVSystem.NTSC) { FramePeriod = (1.0 / (FPS = 60.0)); } else //PALB, DENDY { FramePeriod = (1.0 / (FPS = 50.0)); } }
private string TVSystemToPreset(TVSystem tvsystem) { if (tvsystem == TVSystem.PAL) { return(Preset.Video.DVD.PAL_4x3_MP2); } else { return(Preset.Video.DVD.NTSC_4x3_PCM); } }
private static void hardReset() { switch (TVFormatSetting) { case TVSystemSetting.AUTO: { if (board.GameInfo.Cartridges != null) { if (board.GameCartInfo.System.ToUpper().Contains("PAL")) { TVFormat = TVSystem.PALB; } else if (board.GameCartInfo.System.ToUpper().Contains("DENDY")) { TVFormat = TVSystem.DENDY; } else { TVFormat = TVSystem.NTSC; } } else { TVFormat = TVSystem.NTSC; // force NTSC } break; } case TVSystemSetting.NTSC: { TVFormat = TVSystem.NTSC; break; } case TVSystemSetting.PALB: { TVFormat = TVSystem.PALB; break; } case TVSystemSetting.DENDY: { TVFormat = TVSystem.DENDY; break; } } DoPalAdditionalClock = TVFormat == TVSystem.PALB; palCyc = 0; setupSpeedLimiter(); MEMHardReset(); CPUHardReset(); PPUHardReset(); APUHardReset(); DMAHardReset(); }
public void VideoFormatTest(byte videoFmtByte, AspectRatio expectedAspectRatio, TVSystem expectedTVSystem) { byte[] copyTestBytes = (byte[])testBytes.Clone(); copyTestBytes[0x80] = videoFmtByte; MOIFile moiFile = ParseMOIExpectSuccess(copyTestBytes); Assert.AreEqual(expectedAspectRatio, moiFile.AspectRatio); Assert.AreEqual(expectedTVSystem, moiFile.TVSystem); }
private void HardReset() { switch (TVFormatSetting) { case TVSystemSetting.AUTO: { if (this.memory.board.GameInfo.Cartridges != null) { if (this.memory.board.GameCartInfo.System.ToUpper().Contains("PAL")) { TVFormat = TVSystem.PALB; } else if (this.memory.board.GameCartInfo.System.ToUpper().Contains("DENDY")) { TVFormat = TVSystem.DENDY; } else { TVFormat = TVSystem.NTSC; } } else { TVFormat = TVSystem.NTSC; // force NTSC } break; } case TVSystemSetting.NTSC: { TVFormat = TVSystem.NTSC; break; } case TVSystemSetting.PALB: { TVFormat = TVSystem.PALB; break; } case TVSystemSetting.DENDY: { TVFormat = TVSystem.DENDY; break; } } DoPalAdditionalClock = TVFormat == TVSystem.PALB; palCyc = 0; // SPEED LIMITTER SpeedLimitterON = true; // NOTE !! // These values are calculated depending on cpu speed // provided by Nes Wiki. // NTSC = 1789772.67 Hz // PALB = 1662607 Hz // DENDY = 1773448 Hz if (TVFormat == TVSystem.NTSC) { FramePeriod = (1.0 / (FPS = 61.58)); // Yes not 60.0988 for 1789772.67 Hz } else if (TVFormat == TVSystem.PALB) { FramePeriod = (1.0 / (FPS = 51.33)); // Not 50.070 for 1662607 Hz } else if (TVFormat == TVSystem.DENDY) { FramePeriod = (1.0 / (FPS = 51.25)); // Not 50.070 for 1773448 Hz } // Changing any value of FPS or CPU FREQ will slightly affect // sound playback sync and the sound itself for high frequencies. // // For example, if we put NTSC = 1789772 Hz instead of 1789772.67 Hz // and the FPS = 60.0988 as provided in wiki, the sound record (record // by adding sample sample on nes cpu clock, **not via playback on run // time**) show bad sample on high freq generated by square 1 and 2. // The best game to test this is Rygar at the first stage music. // Silence all channels but the square 2, record the sound and see the choppy. // // The question is: is there something wrong I did or the // Nes Wiki infromation is not accurate ? // I'm sure all sound channels implemented exactly as it should by Wiki // and APU passes all tests. // Anyway, it sounds good using these values :) this.memory.MEMHardReset(); this.cpu.HardReset(); this.ppu.PPUHardReset(); this.apu.HardReset(); this.dma.DMAHardReset(); }
private static void hardReset() { switch (TVFormatSetting) { case TVSystemSetting.AUTO: { if (board.GameInfo.Cartridges != null) { if (board.GameCartInfo.System.ToUpper().Contains("PAL")) TVFormat = TVSystem.PALB; else if (board.GameCartInfo.System.ToUpper().Contains("DENDY")) TVFormat = TVSystem.DENDY; else TVFormat = TVSystem.NTSC; } else { TVFormat = TVSystem.NTSC;// force NTSC } break; } case TVSystemSetting.NTSC: { TVFormat = TVSystem.NTSC; break; } case TVSystemSetting.PALB: { TVFormat = TVSystem.PALB; break; } case TVSystemSetting.DENDY: { TVFormat = TVSystem.DENDY; break; } } DoPalAdditionalClock = TVFormat == TVSystem.PALB; palCyc = 0; setupSpeedLimiter(); MEMHardReset(); CPUHardReset(); PPUHardReset(); APUHardReset(); DMAHardReset(); }
public SDLVideo(TVSystem system) { LoadSettings(); initialized = false; canRender = false; Console.WriteLine("->Initializing video ..."); fontPath = System.IO.Path.Combine(Program.ApplicationFolder, "FreeSans.ttf"); // Initialize the video Video.Initialize(); Video.WindowIcon(); Video.WindowCaption = "My Nes SDL"; fullscreenModes = Video.ListModes(); Video.GLDoubleBufferEnabled = !ImmediateMode; windowW = 256 * stretchMultiply; switch (system) { case TVSystem.NTSC: { Events.TargetFps = 60; break; } case TVSystem.PALB: case TVSystem.DENDY: { Events.TargetFps = 50; break; } } if (cutLines) { if (system == TVSystem.NTSC) { scanlines = 224; firstToCut = 8; } else { scanlines = 238; firstToCut = 1; } } else { scanlines = 240; firstToCut = 0; } screenBufferSize = 256 * scanlines; originalRect = new Rectangle(0, 0, 256, scanlines); screen_back = new Surface(256, scanlines, 32); windowH = scanlines * stretchMultiply; pointer = screen_back.Pixels; screen_pointer = (int*)screen_back.Pixels; NesEmu.SetupVideoRenderer(this, true, screen_back.Pixels, firstToCut * 256, 256 * (240 - firstToCut)); // Create texts Console.WriteLine("-->Loading fonts ..."); fpsTextSprite = new TextSprite(new SdlDotNet.Graphics.Font(fontPath, 15)); fpsTextSprite.Color = Color.White; fpsTextSprite.BackgroundColor = Color.Black; notTextSprite = new TextSprite(new SdlDotNet.Graphics.Font(fontPath, 15)); notTextSprite.BackgroundColor = Color.Black; soundRecordTextSprite = new TextSprite(new SdlDotNet.Graphics.Font(fontPath, 15)); soundRecordTextSprite.BackgroundColor = Color.Black; statusTextSprite = new TextSprite(new SdlDotNet.Graphics.Font(fontPath, 15)); statusTextSprite.BackgroundColor = Color.Black; // set video mode. Resize(FullScreen, true, windowW, windowH); Events.VideoResize += VideoResize; Events.MouseButtonDown += Events_MouseButtonDown; Events.MouseButtonUp += Events_MouseButtonUp; Events.Tick += OnTick; canRender = true; initialized = true; Console.WriteLine("->Video initialized successfully"); }
public SDLVideo(TVSystem system) { LoadSettings(); initialized = false; canRender = false; Console.WriteLine("->Initializing video ..."); fontPath = System.IO.Path.Combine(Program.ApplicationFolder, "FreeSans.ttf"); // Initialize the video Video.Initialize(); Video.WindowIcon(); Video.WindowCaption = "My Nes SDL"; fullscreenModes = Video.ListModes(); Video.GLDoubleBufferEnabled = !ImmediateMode; windowW = 256 * stretchMultiply; switch (system) { case TVSystem.NTSC: { Events.TargetFps = 60; break; } case TVSystem.PALB: case TVSystem.DENDY: { Events.TargetFps = 50; break; } } if (cutLines) { if (system == TVSystem.NTSC) { scanlines = 224; firstToCut = 8; } else { scanlines = 238; firstToCut = 1; } } else { scanlines = 240; firstToCut = 0; } screenBufferSize = 256 * scanlines; originalRect = new Rectangle(0, 0, 256, scanlines); screen_back = new Surface(256, scanlines, 32); windowH = scanlines * stretchMultiply; pointer = screen_back.Pixels; screen_pointer = (int *)screen_back.Pixels; NesEmu.SetupVideoRenderer(this, true, screen_back.Pixels, firstToCut * 256, 256 * (240 - firstToCut)); // Create texts Console.WriteLine("-->Loading fonts ..."); fpsTextSprite = new TextSprite(new SdlDotNet.Graphics.Font(fontPath, 15)); fpsTextSprite.Color = Color.White; fpsTextSprite.BackgroundColor = Color.Black; notTextSprite = new TextSprite(new SdlDotNet.Graphics.Font(fontPath, 15)); notTextSprite.BackgroundColor = Color.Black; soundRecordTextSprite = new TextSprite(new SdlDotNet.Graphics.Font(fontPath, 15)); soundRecordTextSprite.BackgroundColor = Color.Black; statusTextSprite = new TextSprite(new SdlDotNet.Graphics.Font(fontPath, 15)); statusTextSprite.BackgroundColor = Color.Black; // set video mode. Resize(FullScreen, true, windowW, windowH); Events.VideoResize += VideoResize; Events.MouseButtonDown += Events_MouseButtonDown; Events.MouseButtonUp += Events_MouseButtonUp; Events.Tick += OnTick; canRender = true; initialized = true; Console.WriteLine("->Video initialized successfully"); }