From f992672051dc8ff8e678b8ba90f0e0b3b210e114 Mon Sep 17 00:00:00 2001 From: goyuken Date: Sun, 22 Dec 2013 21:47:16 +0000 Subject: [PATCH] NES add sound volume settings to config object --- BizHawk.Client.Common/config/Config.cs | 20 +++--- BizHawk.Client.EmuHawk/MainForm.cs | 14 ---- .../config/NES/NESSoundConfig.cs | 67 +++++++++---------- .../Consoles/Nintendo/NES/NES.cs | 13 ++++ 4 files changed, 54 insertions(+), 60 deletions(-) diff --git a/BizHawk.Client.Common/config/Config.cs b/BizHawk.Client.Common/config/Config.cs index e94685c0ee..19f2eb6ceb 100644 --- a/BizHawk.Client.Common/config/Config.cs +++ b/BizHawk.Client.Common/config/Config.cs @@ -600,17 +600,17 @@ namespace BizHawk.Client.Common public int Analog_SmallChange = 1; // NES Sound settings - public int NESSquare1 = 376; - public int NESSquare2 = 376; - public int NESTriangle = 426; - public int NESNoise = 247; - public int NESDMC = 167; + //public int NESSquare1 = 376; + //public int NESSquare2 = 376; + //public int NESTriangle = 426; + //public int NESNoise = 247; + //public int NESDMC = 167; - public const int NESSquare1Max = 376; - public const int NESSquare2Max = 376; - public const int NESTriangleMax = 426; - public const int NESNoiseMax = 247; - public const int NESDMCMax = 167; + //public const int NESSquare1Max = 376; + //public const int NESSquare2Max = 376; + //public const int NESTriangleMax = 426; + //public const int NESNoiseMax = 247; + //public const int NESDMCMax = 167; public struct AnalogBind { diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index 35d85b220b..bd34ae85cc 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -814,19 +814,6 @@ namespace BizHawk.Client.EmuHawk LogWindowAsConsoleMenuItem.Enabled = true; } - public void SetNesSoundChannels() - { - var nes = Global.Emulator as NES; - if (nes != null) - { - nes.SetSquare1(Global.Config.NESSquare1); - nes.SetSquare2(Global.Config.NESSquare2); - nes.SetTriangle(Global.Config.NESTriangle); - nes.SetNoise(Global.Config.NESNoise); - nes.SetDMC(Global.Config.NESDMC); - } - } - public void ClickSpeedItem(int num) { if ((ModifierKeys & Keys.Control) != 0) @@ -3571,7 +3558,6 @@ namespace BizHawk.Client.EmuHawk } Global.Game.Status = nes.RomStatus; - SetNesSoundChannels(); } Text = DisplayNameForSystem(game.System) + " - " + game.Name; diff --git a/BizHawk.Client.EmuHawk/config/NES/NESSoundConfig.cs b/BizHawk.Client.EmuHawk/config/NES/NESSoundConfig.cs index ccd0e9ac5d..b777591b8e 100644 --- a/BizHawk.Client.EmuHawk/config/NES/NESSoundConfig.cs +++ b/BizHawk.Client.EmuHawk/config/NES/NESSoundConfig.cs @@ -2,25 +2,27 @@ using System.Windows.Forms; using BizHawk.Client.Common; +using BizHawk.Emulation.Cores.Nintendo.NES; namespace BizHawk.Client.EmuHawk { public partial class NESSoundConfig : Form, IToolForm { - private int sq1, sq2, tr, no, dmc = 0; + private NES.NESSettings oldsettings; + private NES.NESSettings settings; public bool AskSave() { return true; } public bool UpdateBefore { get { return false; } } public void UpdateValues() { - if (!(Global.Emulator is NESDebugger)) + if (!(Global.Emulator is NES)) { Close(); } } public void Restart() { - if (!(Global.Emulator is NESDebugger)) + if (!(Global.Emulator is NES)) { Close(); } @@ -29,26 +31,25 @@ namespace BizHawk.Client.EmuHawk public NESSoundConfig() { InitializeComponent(); - trackBar1.Maximum = Config.NESSquare1Max; - trackBar2.Maximum = Config.NESSquare2Max; - trackBar3.Maximum = Config.NESTriangleMax; - trackBar4.Maximum = Config.NESNoiseMax; - trackBar5.Maximum = Config.NESDMCMax; + // get baseline maxes from a default config object + var d = new NES.NESSettings(); + trackBar1.Maximum = d.Square1; + trackBar2.Maximum = d.Square2; + trackBar3.Maximum = d.Triangle; + trackBar4.Maximum = d.Noise; + trackBar5.Maximum = d.DMC; } private void NESSoundConfig_Load(object sender, EventArgs e) { - trackBar1.Value = Global.Config.NESSquare1; - trackBar2.Value = Global.Config.NESSquare2; - trackBar3.Value = Global.Config.NESTriangle; - trackBar4.Value = Global.Config.NESNoise; - trackBar5.Value = Global.Config.NESDMC; - //save value for cancel - sq1 = Global.Config.NESSquare1; - sq2 = Global.Config.NESSquare2; - tr = Global.Config.NESTriangle; - no = Global.Config.NESNoise; - dmc = Global.Config.NESDMC; + oldsettings = (NES.NESSettings)Global.Emulator.GetSettings(); + settings = oldsettings.Clone(); + + trackBar1.Value = settings.Square1; + trackBar2.Value = settings.Square2; + trackBar3.Value = settings.Triangle; + trackBar4.Value = settings.Noise; + trackBar5.Value = settings.DMC; } private void OK_Click(object sender, EventArgs e) @@ -59,49 +60,43 @@ namespace BizHawk.Client.EmuHawk private void Cancel_Click(object sender, EventArgs e) { //restore previous value - //restore value - Global.Config.NESSquare1 = sq1; - Global.Config.NESSquare2 = sq2; - Global.Config.NESTriangle = tr; - Global.Config.NESNoise = no; - Global.Config.NESDMC = dmc; - GlobalWin.MainForm.SetNesSoundChannels(); + Global.Emulator.PutSettings(oldsettings); Close(); } private void trackBar1_ValueChanged(object sender, EventArgs e) { label6.Text = trackBar1.Value.ToString(); - Global.Config.NESSquare1 = trackBar1.Value; - GlobalWin.MainForm.SetNesSoundChannels(); + settings.Square1 = trackBar1.Value; + Global.Emulator.PutSettings(settings); } private void trackBar2_ValueChanged(object sender, EventArgs e) { label7.Text = trackBar2.Value.ToString(); - Global.Config.NESSquare2 = trackBar2.Value; - GlobalWin.MainForm.SetNesSoundChannels(); + settings.Square2 = trackBar2.Value; + Global.Emulator.PutSettings(settings); } private void trackBar3_ValueChanged(object sender, EventArgs e) { label8.Text = trackBar3.Value.ToString(); - Global.Config.NESTriangle = trackBar3.Value; - GlobalWin.MainForm.SetNesSoundChannels(); + settings.Triangle = trackBar3.Value; + Global.Emulator.PutSettings(settings); } private void trackBar4_ValueChanged(object sender, EventArgs e) { label9.Text = trackBar4.Value.ToString(); - Global.Config.NESNoise = trackBar4.Value; - GlobalWin.MainForm.SetNesSoundChannels(); + settings.Noise = trackBar4.Value; + Global.Emulator.PutSettings(settings); } private void trackBar5_ValueChanged(object sender, EventArgs e) { label10.Text = trackBar5.Value.ToString(); - Global.Config.NESDMC = trackBar5.Value; - GlobalWin.MainForm.SetNesSoundChannels(); + settings.DMC = trackBar5.Value; + Global.Emulator.PutSettings(settings); } } } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs index 9d2077afcb..9094eaf3c9 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs @@ -893,6 +893,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES CoreComm.ScreenLogicalOffsetY = DisplayType == DisplayType.NTSC ? Settings.NTSC_TopLine : Settings.PAL_TopLine; SetPalette(Settings.Palette); + + apu.Square1V = Settings.Square1; + apu.Square2V = Settings.Square2; + apu.TriangleV = Settings.Triangle; + apu.NoiseV = Settings.Noise; + apu.DMCV = Settings.DMC; + return false; } @@ -911,6 +918,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES public int[,] Palette; + public int Square1 = 376; + public int Square2 = 376; + public int Triangle = 426; + public int Noise = 247; + public int DMC = 167; + public NESSettings Clone() { return (NESSettings)MemberwiseClone();