From 06aec06ec30f0908d2b77393f7b8c1d648c2e1fd Mon Sep 17 00:00:00 2001 From: Ian C Date: Wed, 27 Jun 2012 22:51:27 +0000 Subject: Added some state storage interfaces. --- wpspec/wpspec/Resources/Strings.Designer.cs | 2 +- wpspec/wpspec/Resources/Strings.resx | 2 +- wpspec/wpspec/Settings.cs | 48 +++++++++++++++++++++++++++-- wpspec/wpspec/SettingsPage.xaml | 1 + wpspec/wpspec/Shared.cs | 1 + wpspec/wpspec/Spectrum/Emulation.cs | 33 ++++++++++++++++++-- 6 files changed, 81 insertions(+), 6 deletions(-) diff --git a/wpspec/wpspec/Resources/Strings.Designer.cs b/wpspec/wpspec/Resources/Strings.Designer.cs index 8e505a0..2c02935 100644 --- a/wpspec/wpspec/Resources/Strings.Designer.cs +++ b/wpspec/wpspec/Resources/Strings.Designer.cs @@ -452,7 +452,7 @@ namespace wpspec.Resources { } /// - /// Looks up a localized string similar to Reserve joystick/buttons. + /// Looks up a localized string similar to Reverse joystick/buttons. /// public static string SettingsJoystickLeftHanded { get { diff --git a/wpspec/wpspec/Resources/Strings.resx b/wpspec/wpspec/Resources/Strings.resx index 40ec107..8e8e5aa 100644 --- a/wpspec/wpspec/Resources/Strings.resx +++ b/wpspec/wpspec/Resources/Strings.resx @@ -305,6 +305,6 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY Value - Reserve joystick/buttons + Reverse joystick/buttons \ No newline at end of file diff --git a/wpspec/wpspec/Settings.cs b/wpspec/wpspec/Settings.cs index e87c071..2b73b62 100644 --- a/wpspec/wpspec/Settings.cs +++ b/wpspec/wpspec/Settings.cs @@ -13,13 +13,15 @@ using System.Collections.Generic; using Noddybox.Emulation.Xna.Input.Joystick; using wpspec.Spectrum; using wpspec.ViewModels; +using Noddybox.Emulation; +using System.IO; namespace wpspec { /// - /// Holds global settings + /// Holds global settings. Also acts as state saver for per-game settings and shared settings. /// - public class Settings + public class Settings : IEmulationState { /// /// Get/set whether sound is enabled. @@ -215,5 +217,47 @@ namespace wpspec private SettingValue joystickLeftHanded; #endregion + + #region IEmulationState Members + + public int Version + { + get { return 1; } + } + + public void SaveState(EmulationStateSaveManager manager) + { + BinaryWriter str = manager.Stream; + + str.Write(Shared.IsJoystickDisplayed); + str.Write(Shared.IsZoomed); + str.Write(keyboardJoystick.Setting); + str.Write((int)joystickKeyUp.Setting); + str.Write((int)joystickKeyDown.Setting); + str.Write((int)joystickKeyLeft.Setting); + str.Write((int)joystickKeyRight.Setting); + str.Write((int)joystickKeyFire1.Setting); + str.Write((int)joystickKeyFire2.Setting); + str.Write((int)joystickLock.Setting); + str.Write(joystickLeftHanded.Setting); + } + + public void LoadState(EmulationStateLoadManager manager) + { + BinaryReader str = manager.Stream; + + Shared.IsJoystickDisplayed = str.ReadBoolean(); + Shared.IsZoomed = str.ReadBoolean(); + keyboardJoystick.Setting = str.ReadBoolean(); + joystickKeyUp.Setting = (SpectrumKeySymbol)str.ReadInt32(); + joystickKeyDown.Setting = (SpectrumKeySymbol)str.ReadInt32(); + joystickKeyLeft.Setting = (SpectrumKeySymbol)str.ReadInt32(); + joystickKeyRight.Setting = (SpectrumKeySymbol)str.ReadInt32(); + joystickKeyFire1.Setting = (SpectrumKeySymbol)str.ReadInt32(); + joystickKeyFire2.Setting = (SpectrumKeySymbol)str.ReadInt32(); + joystickLeftHanded.Setting = str.ReadBoolean(); + } + + #endregion } } diff --git a/wpspec/wpspec/SettingsPage.xaml b/wpspec/wpspec/SettingsPage.xaml index 4a3e846..f8ad53e 100644 --- a/wpspec/wpspec/SettingsPage.xaml +++ b/wpspec/wpspec/SettingsPage.xaml @@ -116,6 +116,7 @@ diff --git a/wpspec/wpspec/Shared.cs b/wpspec/wpspec/Shared.cs index 38c391b..0c59f4d 100644 --- a/wpspec/wpspec/Shared.cs +++ b/wpspec/wpspec/Shared.cs @@ -1,5 +1,6 @@ using Noddybox.Emulation.Keyboard.Schema; using wpspec.Spectrum; +using Noddybox.Emulation; namespace wpspec { diff --git a/wpspec/wpspec/Spectrum/Emulation.cs b/wpspec/wpspec/Spectrum/Emulation.cs index 9d1bbef..603ef3c 100644 --- a/wpspec/wpspec/Spectrum/Emulation.cs +++ b/wpspec/wpspec/Spectrum/Emulation.cs @@ -34,7 +34,7 @@ namespace wpspec.Spectrum /// /// Provides the emulation for the Spectrum /// - public class Emulation: IMemory, IDevice + public class Emulation: IMemory, IDevice, IEmulationState { #region Private Data @@ -70,7 +70,7 @@ namespace wpspec.Spectrum 0xff // End of patch }; - private readonly byte[] mem = new byte[0x10000]; + private byte[] mem = new byte[0x10000]; private readonly Clock clock = new Clock(0, 224, 312, 0); // Keyboard matrix. The 9th entry is used to store the joystick state. @@ -715,5 +715,34 @@ namespace wpspec.Spectrum } #endregion + + #region IEmulationState Members + + public int Version + { + get { return 1; } + } + + public void SaveState(EmulationStateSaveManager manager) + { + BinaryWriter str = manager.Stream; + + str.Write(mem); + str.Write(flash); + str.Write(flashCounter); + str.Write(border); + } + + public void LoadState(EmulationStateLoadManager manager) + { + BinaryReader str = manager.Stream; + + mem = str.ReadBytes(mem.Length); + flash = str.ReadBoolean(); + flashCounter = str.ReadInt32(); + border = str.ReadInt32(); + } + + #endregion } } -- cgit v1.2.3