From d22639c563b3de2adee61a8ab3c952a28ebac63e Mon Sep 17 00:00:00 2001 From: Sean Fausett Date: Sun, 6 Jun 2010 21:48:51 +0000 Subject: [PATCH] Added debug service. Fixed code analysis warnings. --HG-- extra : convert_revision : svn%3Affd33b8c-2492-42e0-bdc5-587b920b7d6d/trunk%4047095 --- Library/GeneralSecurity.cs | 4 +++ Library/SafeAllocHandle.cs | 4 +++ Library/Silverlight/ApplicationBase.cs | 7 +++- Library/Wpf/ApplicationBase.cs | 8 ++++- Library/XmlSerializerHelpers.cs | 2 ++ Virtu/Services/AudioService.cs | 4 ++- Virtu/Services/DebugService.cs | 18 ++++++++++ Virtu/Services/MachineService.cs | 1 + Virtu/Services/StorageService.cs | 2 ++ .../Jellyfish.Virtu.Silverlight.csproj | 4 +++ Virtu/Silverlight/MainPage.xaml | 4 +-- Virtu/Silverlight/MainPage.xaml.cs | 4 +++ .../Jellyfish.Virtu.Silverlight.Phone.csproj | 6 ++++ Virtu/Silverlight/Phone/MainPage.xaml | 4 +-- .../Services/SilverlightAudioService.cs | 8 ++--- .../Services/SilverlightDebugService.cs | 34 +++++++++++++++++++ .../Services/SilverlightKeyboardService.cs | 4 +-- Virtu/Wpf/Jellyfish.Virtu.Wpf.csproj | 4 +++ Virtu/Wpf/MainWindow.xaml | 4 +-- Virtu/Wpf/MainWindow.xaml.cs | 4 +++ Virtu/Wpf/Services/WpfAudioService.cs | 5 +-- Virtu/Wpf/Services/WpfDebugService.cs | 34 +++++++++++++++++++ Virtu/Wpf/Services/WpfKeyboardService.cs | 4 +-- Virtu/Xna/Jellyfish.Virtu.Xna.Phone.csproj | 3 ++ Virtu/Xna/Jellyfish.Virtu.Xna.Xbox.csproj | 3 ++ Virtu/Xna/Jellyfish.Virtu.Xna.csproj | 3 ++ Virtu/Xna/MainGame.cs | 4 +++ Virtu/Xna/Services/XnaAudioService.cs | 6 ++++ Virtu/Xna/Services/XnaKeyboardService.cs | 4 +++ 29 files changed, 174 insertions(+), 22 deletions(-) create mode 100644 Virtu/Services/DebugService.cs create mode 100644 Virtu/Silverlight/Services/SilverlightDebugService.cs create mode 100644 Virtu/Wpf/Services/WpfDebugService.cs diff --git a/Library/GeneralSecurity.cs b/Library/GeneralSecurity.cs index 7b0aacd..d29274b 100644 --- a/Library/GeneralSecurity.cs +++ b/Library/GeneralSecurity.cs @@ -71,11 +71,13 @@ public GeneralSecurity(bool isContainer, ResourceType resourceType) : { } + [SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")] public GeneralSecurity(bool isContainer, ResourceType resourceType, SafeHandle handle, AccessControlSections includeSections = AccessControlSections.Access | AccessControlSections.Group | AccessControlSections.Owner) : base(isContainer, resourceType, handle, includeSections) { } + [SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")] public GeneralSecurity(bool isContainer, ResourceType resourceType, string name, AccessControlSections includeSections = AccessControlSections.Access | AccessControlSections.Group | AccessControlSections.Owner) : base(isContainer, resourceType, name, includeSections) { @@ -103,12 +105,14 @@ public void AddAuditRule(GeneralAuditRule rule) base.AddAuditRule(rule); } + [SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")] [SecurityCritical] public void GetSecurityAttributes(Action action, bool inheritable = false) { GetSecurityAttributes(this, action, inheritable); } + [SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")] [SecurityCritical] public static void GetSecurityAttributes(ObjectSecurity security, Action action, bool inheritable = false) { diff --git a/Library/SafeAllocHandle.cs b/Library/SafeAllocHandle.cs index ff6a800..0c91d3a 100644 --- a/Library/SafeAllocHandle.cs +++ b/Library/SafeAllocHandle.cs @@ -47,6 +47,8 @@ public static SafeGlobalAllocHandle Allocate(byte[] value) return alloc; } + [SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")] + [SuppressMessage("Microsoft.Naming", "CA1726:UsePreferredTerms", MessageId = "flags")] [SecurityCritical] public static SafeGlobalAllocHandle Allocate(int size, uint flags = 0x0) { @@ -110,6 +112,8 @@ public static SafeLocalAllocHandle Allocate(byte[] value) return alloc; } + [SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")] + [SuppressMessage("Microsoft.Naming", "CA1726:UsePreferredTerms", MessageId = "flags")] [SecurityCritical] public static SafeLocalAllocHandle Allocate(int size, uint flags = 0x0) { diff --git a/Library/Silverlight/ApplicationBase.cs b/Library/Silverlight/ApplicationBase.cs index fa35c17..335c5b2 100644 --- a/Library/Silverlight/ApplicationBase.cs +++ b/Library/Silverlight/ApplicationBase.cs @@ -6,7 +6,12 @@ namespace Jellyfish.Library { public class ApplicationBase : Application { - public ApplicationBase(string name = null) + public ApplicationBase() : + this(null) + { + } + + public ApplicationBase(string name) { Name = name; diff --git a/Library/Wpf/ApplicationBase.cs b/Library/Wpf/ApplicationBase.cs index dc335b4..0049cd3 100644 --- a/Library/Wpf/ApplicationBase.cs +++ b/Library/Wpf/ApplicationBase.cs @@ -10,7 +10,13 @@ namespace Jellyfish.Library public class ApplicationBase : Application { [SecurityCritical] - public ApplicationBase(string name = null) + public ApplicationBase() : + this(null) + { + } + + [SecurityCritical] + public ApplicationBase(string name) { Name = name; diff --git a/Library/XmlSerializerHelpers.cs b/Library/XmlSerializerHelpers.cs index 7f68fab..0fa486c 100644 --- a/Library/XmlSerializerHelpers.cs +++ b/Library/XmlSerializerHelpers.cs @@ -8,6 +8,7 @@ namespace Jellyfish.Library public static class XmlSerializerHelpers { [SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")] + [SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")] public static T Deserialize(Stream stream, string defaultNamespace = null) { using (var reader = XmlReader.Create(stream)) @@ -17,6 +18,7 @@ public static T Deserialize(Stream stream, string defaultNamespace = null) } } + [SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")] public static void Serialize(Stream stream, T instance, string defaultNamespace = null) { using (var writer = XmlWriter.Create(stream)) diff --git a/Virtu/Services/AudioService.cs b/Virtu/Services/AudioService.cs index f41acda..dd6b0ff 100644 --- a/Virtu/Services/AudioService.cs +++ b/Virtu/Services/AudioService.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Threading; namespace Jellyfish.Virtu.Services @@ -13,7 +14,7 @@ public AudioService(Machine machine) : public void Output(int data) // machine thread { _buffer[_index + 0] = (byte)(data & 0xFF); - _buffer[_index + 1] = (byte)((data >> 8) & 0xFF); + _buffer[_index + 1] = (byte)(data >> 8); _index = (_index + 2) % SampleSize; if (_index == 0) { @@ -55,6 +56,7 @@ protected void Update(int bufferSize, Action updateBuffer) // audio public const int SampleLatency = 40; // ms public const int SampleSize = (SampleRate * SampleLatency / 1000) * SampleChannels * (SampleBits / 8); + [SuppressMessage("Microsoft.Security", "CA2105:ArrayFieldsShouldNotBeReadOnly")] protected static readonly byte[] SampleZero = new byte[SampleSize]; private byte[] _buffer = new byte[SampleSize]; diff --git a/Virtu/Services/DebugService.cs b/Virtu/Services/DebugService.cs new file mode 100644 index 0000000..40ee580 --- /dev/null +++ b/Virtu/Services/DebugService.cs @@ -0,0 +1,18 @@ +using System; +using System.Diagnostics; + +namespace Jellyfish.Virtu.Services +{ + public class DebugService : MachineService + { + public DebugService(Machine machine) : + base(machine) + { + } + + public virtual void WriteLine(string message) + { + Debug.WriteLine(string.Concat(DateTime.Now, " ", message)); + } + } +} diff --git a/Virtu/Services/MachineService.cs b/Virtu/Services/MachineService.cs index cfa3463..cfb77a3 100644 --- a/Virtu/Services/MachineService.cs +++ b/Virtu/Services/MachineService.cs @@ -35,5 +35,6 @@ protected virtual void Dispose(bool disposing) } protected Machine Machine { get; private set; } + protected DebugService DebugService { get { return Machine.Services.GetService(); } } } } diff --git a/Virtu/Services/StorageService.cs b/Virtu/Services/StorageService.cs index fb837a4..42c4526 100644 --- a/Virtu/Services/StorageService.cs +++ b/Virtu/Services/StorageService.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; using System.Reflection; @@ -14,6 +15,7 @@ protected StorageService(Machine machine) : { } + [SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")] public static Stream GetResourceStream(string resourceName, int resourceSize = 0) { var resourceManager = new ResourceManager("Jellyfish.Virtu.g", Assembly.GetExecutingAssembly()) { IgnoreCase = true }; diff --git a/Virtu/Silverlight/Jellyfish.Virtu.Silverlight.csproj b/Virtu/Silverlight/Jellyfish.Virtu.Silverlight.csproj index 31eb4ee..03d36c9 100644 --- a/Virtu/Silverlight/Jellyfish.Virtu.Silverlight.csproj +++ b/Virtu/Silverlight/Jellyfish.Virtu.Silverlight.csproj @@ -155,6 +155,9 @@ Services\AudioService.cs + + Services\DebugService.cs + Services\GamePortService.cs @@ -187,6 +190,7 @@ + diff --git a/Virtu/Silverlight/MainPage.xaml b/Virtu/Silverlight/MainPage.xaml index 58d115f..9adc007 100644 --- a/Virtu/Silverlight/MainPage.xaml +++ b/Virtu/Silverlight/MainPage.xaml @@ -13,9 +13,9 @@ - + diff --git a/Virtu/Silverlight/MainPage.xaml.cs b/Virtu/Silverlight/MainPage.xaml.cs index 9a6da19..9ad8ea0 100644 --- a/Virtu/Silverlight/MainPage.xaml.cs +++ b/Virtu/Silverlight/MainPage.xaml.cs @@ -13,12 +13,14 @@ public MainPage() { InitializeComponent(); + _debugService = new SilverlightDebugService(_machine, this); _storageService = new IsolatedStorageService(_machine); _keyboardService = new SilverlightKeyboardService(_machine, this); _gamePortService = new GamePortService(_machine); // not connected _audioService = new SilverlightAudioService(_machine, this, _media); _videoService = new SilverlightVideoService(_machine, this, _image); + _machine.Services.AddService(typeof(DebugService), _debugService); _machine.Services.AddService(typeof(StorageService), _storageService); _machine.Services.AddService(typeof(KeyboardService), _keyboardService); _machine.Services.AddService(typeof(GamePortService), _gamePortService); @@ -36,6 +38,7 @@ public MainPage() public void Dispose() { _machine.Dispose(); + _debugService.Dispose(); _storageService.Dispose(); _keyboardService.Dispose(); _gamePortService.Dispose(); @@ -68,6 +71,7 @@ private void OnDiskButtonClick(int drive) private Machine _machine = new Machine(); + private DebugService _debugService; private StorageService _storageService; private KeyboardService _keyboardService; private GamePortService _gamePortService; diff --git a/Virtu/Silverlight/Phone/Jellyfish.Virtu.Silverlight.Phone.csproj b/Virtu/Silverlight/Phone/Jellyfish.Virtu.Silverlight.Phone.csproj index 4d505bf..c652d0f 100644 --- a/Virtu/Silverlight/Phone/Jellyfish.Virtu.Silverlight.Phone.csproj +++ b/Virtu/Silverlight/Phone/Jellyfish.Virtu.Silverlight.Phone.csproj @@ -141,6 +141,9 @@ Services\AudioService.cs + + Services\DebugService.cs + Services\GamePortService.cs @@ -174,6 +177,9 @@ Services\SilverlightAudioService.cs + + Services\SilverlightDebugService.cs + Services\SilverlightKeyboardService.cs diff --git a/Virtu/Silverlight/Phone/MainPage.xaml b/Virtu/Silverlight/Phone/MainPage.xaml index 8aca00a..360fb52 100644 --- a/Virtu/Silverlight/Phone/MainPage.xaml +++ b/Virtu/Silverlight/Phone/MainPage.xaml @@ -23,9 +23,9 @@ - + diff --git a/Virtu/Silverlight/Services/SilverlightAudioService.cs b/Virtu/Silverlight/Services/SilverlightAudioService.cs index 440a0b9..3e71f05 100644 --- a/Virtu/Silverlight/Services/SilverlightAudioService.cs +++ b/Virtu/Silverlight/Services/SilverlightAudioService.cs @@ -21,8 +21,9 @@ public SilverlightAudioService(Machine machine, UserControl page, MediaElement m _page = page; _media = media; _mediaSource = new WaveMediaStreamSource(SampleRate, SampleChannels, SampleBits, SampleSize, SampleLatency, OnMediaSourceUpdate); + _media.SetSource(_mediaSource); - _page.Loaded += (sender, e) => { _media.SetSource(_mediaSource); _media.Play(); }; + _page.Loaded += (sender, e) => _media.Play(); #if !WINDOWS_PHONE _page.Unloaded += (sender, e) => _media.Stop(); #endif @@ -42,10 +43,7 @@ private void OnMediaSourceUpdate(byte[] buffer, int bufferSize) // audio thread { //if (_count++ % (1000 / SampleLatency) == 0) //{ - // _page.Dispatcher.BeginInvoke(() => - // { - // ((MainPage)_page)._debug.Text += string.Concat(DateTime.Now, " OnMediaSourceUpdate", Environment.NewLine); - // }); + // DebugService.WriteLine("OnMediaSourceUpdate"); //} Update(bufferSize, (source, count) => Buffer.BlockCopy(source, 0, buffer, 0, count)); diff --git a/Virtu/Silverlight/Services/SilverlightDebugService.cs b/Virtu/Silverlight/Services/SilverlightDebugService.cs new file mode 100644 index 0000000..8edd8be --- /dev/null +++ b/Virtu/Silverlight/Services/SilverlightDebugService.cs @@ -0,0 +1,34 @@ +using System; + +namespace Jellyfish.Virtu.Services +{ + public sealed class SilverlightDebugService : DebugService + { + public SilverlightDebugService(Machine machine, MainPage page) : + base(machine) + { + if (page == null) + { + throw new ArgumentNullException("page"); + } + + _page = page; + } + + public override void WriteLine(string message) + { + message = string.Concat(DateTime.Now, " ", message, Environment.NewLine); + + if (_page.CheckAccess()) + { + _page._debug.Text += message; + } + else + { + _page.Dispatcher.BeginInvoke(() => _page._debug.Text += message); + } + } + + private MainPage _page; + } +} diff --git a/Virtu/Silverlight/Services/SilverlightKeyboardService.cs b/Virtu/Silverlight/Services/SilverlightKeyboardService.cs index 57923d8..ed65b1a 100644 --- a/Virtu/Silverlight/Services/SilverlightKeyboardService.cs +++ b/Virtu/Silverlight/Services/SilverlightKeyboardService.cs @@ -62,7 +62,7 @@ private bool IsKeyDown(Key key) private void OnPageKeyDown(object sender, KeyEventArgs e) { - //((MainPage)_page)._debug.Text += string.Concat("OnPageKeyDn: Key=", e.Key, " PlatformKeyCode=", e.PlatformKeyCode, Environment.NewLine); + //DebugService.WriteLine(string.Concat("OnPageKeyDn: Key=", e.Key, " PlatformKeyCode=", e.PlatformKeyCode)); _states[(int)e.Key] = true; _updateAnyKeyDown = false; @@ -80,7 +80,7 @@ private void OnPageKeyDown(object sender, KeyEventArgs e) private void OnPageKeyUp(object sender, KeyEventArgs e) { - //((MainPage)_page)._debug.Text += string.Concat("OnPageKeyUp: Key=", e.Key, " PlatformKeyCode=", e.PlatformKeyCode, Environment.NewLine); + //DebugService.WriteLine(string.Concat("OnPageKeyUp: Key=", e.Key, " PlatformKeyCode=", e.PlatformKeyCode)); _states[(int)e.Key] = false; _updateAnyKeyDown = true; diff --git a/Virtu/Wpf/Jellyfish.Virtu.Wpf.csproj b/Virtu/Wpf/Jellyfish.Virtu.Wpf.csproj index 0d8779b..b144071 100644 --- a/Virtu/Wpf/Jellyfish.Virtu.Wpf.csproj +++ b/Virtu/Wpf/Jellyfish.Virtu.Wpf.csproj @@ -135,6 +135,9 @@ Services\AudioService.cs + + Services\DebugService.cs + Services\GamePortService.cs @@ -167,6 +170,7 @@ + diff --git a/Virtu/Wpf/MainWindow.xaml b/Virtu/Wpf/MainWindow.xaml index f579cb3..66cd15f 100644 --- a/Virtu/Wpf/MainWindow.xaml +++ b/Virtu/Wpf/MainWindow.xaml @@ -11,9 +11,9 @@ - + diff --git a/Virtu/Wpf/MainWindow.xaml.cs b/Virtu/Wpf/MainWindow.xaml.cs index 15a4453..93e7af2 100644 --- a/Virtu/Wpf/MainWindow.xaml.cs +++ b/Virtu/Wpf/MainWindow.xaml.cs @@ -14,12 +14,14 @@ public MainWindow() { InitializeComponent(); + _debugService = new WpfDebugService(_machine, this); _storageService = new WpfStorageService(_machine); _keyboardService = new WpfKeyboardService(_machine, this); _gamePortService = new GamePortService(_machine); // not connected _audioService = new WpfAudioService(_machine, this); _videoService = new WpfVideoService(_machine, this, _image); + _machine.Services.AddService(typeof(DebugService), _debugService); _machine.Services.AddService(typeof(StorageService), _storageService); _machine.Services.AddService(typeof(KeyboardService), _keyboardService); _machine.Services.AddService(typeof(GamePortService), _gamePortService); @@ -37,6 +39,7 @@ public MainWindow() public void Dispose() { _machine.Dispose(); + _debugService.Dispose(); _storageService.Dispose(); _keyboardService.Dispose(); _gamePortService.Dispose(); @@ -78,6 +81,7 @@ private void OnDiskButtonClick(int drive) private Machine _machine = new Machine(); + private DebugService _debugService; private StorageService _storageService; private KeyboardService _keyboardService; private GamePortService _gamePortService; diff --git a/Virtu/Wpf/Services/WpfAudioService.cs b/Virtu/Wpf/Services/WpfAudioService.cs index abcb9a7..117cb53 100644 --- a/Virtu/Wpf/Services/WpfAudioService.cs +++ b/Virtu/Wpf/Services/WpfAudioService.cs @@ -38,10 +38,7 @@ private void OnDirectSoundUpdate(IntPtr buffer, int bufferSize) // audio thread { //if (_count++ % (1000 / SampleLatency) == 0) //{ - // _window.Dispatcher.BeginInvoke(() => - // { - // ((MainWindow)_window)._debug.Text += string.Concat(DateTime.Now, " OnDirectSoundUpdate", Environment.NewLine); - // }); + // DebugService.WriteLine("OnDirectSoundUpdate"); //} Update(bufferSize, (source, count) => Marshal.Copy(source, 0, buffer, count)); diff --git a/Virtu/Wpf/Services/WpfDebugService.cs b/Virtu/Wpf/Services/WpfDebugService.cs new file mode 100644 index 0000000..6c15a9d --- /dev/null +++ b/Virtu/Wpf/Services/WpfDebugService.cs @@ -0,0 +1,34 @@ +using System; + +namespace Jellyfish.Virtu.Services +{ + public sealed class WpfDebugService : DebugService + { + public WpfDebugService(Machine machine, MainWindow window) : + base(machine) + { + if (window == null) + { + throw new ArgumentNullException("window"); + } + + _window = window; + } + + public override void WriteLine(string message) + { + message = string.Concat(DateTime.Now, " ", message, Environment.NewLine); + + if (_window.CheckAccess()) + { + _window._debug.Text += message; + } + else + { + _window.Dispatcher.BeginInvoke(new Action(() => _window._debug.Text += message)); + } + } + + private MainWindow _window; + } +} diff --git a/Virtu/Wpf/Services/WpfKeyboardService.cs b/Virtu/Wpf/Services/WpfKeyboardService.cs index 018a9ec..0a81c73 100644 --- a/Virtu/Wpf/Services/WpfKeyboardService.cs +++ b/Virtu/Wpf/Services/WpfKeyboardService.cs @@ -62,7 +62,7 @@ private bool IsKeyDown(Key key) private void OnWindowKeyDown(object sender, KeyEventArgs e) { - //((MainWindow)_window)._debug.Text += string.Concat("OnWindowKeyDn: Key=", e.Key, Environment.NewLine); + //DebugService.WriteLine(string.Concat("OnWindowKeyDn: Key=", e.Key)); _states[(int)((e.Key == Key.System) ? e.SystemKey : e.Key)] = true; _updateAnyKeyDown = false; @@ -80,7 +80,7 @@ private void OnWindowKeyDown(object sender, KeyEventArgs e) private void OnWindowKeyUp(object sender, KeyEventArgs e) { - //((MainWindow)_window)._debug.Text += string.Concat("OnWindowKeyUp: Key=", e.Key, Environment.NewLine); + //DebugService.WriteLine(string.Concat("OnWindowKeyUp: Key=", e.Key)); _states[(int)((e.Key == Key.System) ? e.SystemKey : e.Key)] = false; _updateAnyKeyDown = true; diff --git a/Virtu/Xna/Jellyfish.Virtu.Xna.Phone.csproj b/Virtu/Xna/Jellyfish.Virtu.Xna.Phone.csproj index 326506e..462df5b 100644 --- a/Virtu/Xna/Jellyfish.Virtu.Xna.Phone.csproj +++ b/Virtu/Xna/Jellyfish.Virtu.Xna.Phone.csproj @@ -147,6 +147,9 @@ Services\AudioService.cs + + Services\DebugService.cs + Services\GamePortService.cs diff --git a/Virtu/Xna/Jellyfish.Virtu.Xna.Xbox.csproj b/Virtu/Xna/Jellyfish.Virtu.Xna.Xbox.csproj index bfc6540..041e2dc 100644 --- a/Virtu/Xna/Jellyfish.Virtu.Xna.Xbox.csproj +++ b/Virtu/Xna/Jellyfish.Virtu.Xna.Xbox.csproj @@ -158,6 +158,9 @@ Services\AudioService.cs + + Services\DebugService.cs + Services\GamePortService.cs diff --git a/Virtu/Xna/Jellyfish.Virtu.Xna.csproj b/Virtu/Xna/Jellyfish.Virtu.Xna.csproj index 90d6336..07ef9d1 100644 --- a/Virtu/Xna/Jellyfish.Virtu.Xna.csproj +++ b/Virtu/Xna/Jellyfish.Virtu.Xna.csproj @@ -159,6 +159,9 @@ Services\AudioService.cs + + Services\DebugService.cs + Services\GamePortService.cs diff --git a/Virtu/Xna/MainGame.cs b/Virtu/Xna/MainGame.cs index dcab58f..b0da6f1 100644 --- a/Virtu/Xna/MainGame.cs +++ b/Virtu/Xna/MainGame.cs @@ -22,6 +22,7 @@ public MainGame() : frameRateCounter.DrawOrder = 1; frameRateCounter.FontName = "Consolas"; + _debugService = new DebugService(_machine); #if WINDOWS_PHONE _storageService = new IsolatedStorageService(_machine); #else @@ -32,6 +33,7 @@ public MainGame() : _audioService = new XnaAudioService(_machine, this); _videoService = new XnaVideoService(_machine, this); + _machine.Services.AddService(typeof(DebugService), _debugService); _machine.Services.AddService(typeof(StorageService), _storageService); _machine.Services.AddService(typeof(KeyboardService), _keyboardService); _machine.Services.AddService(typeof(GamePortService), _gamePortService); @@ -44,6 +46,7 @@ protected override void Dispose(bool disposing) if (disposing) { _machine.Dispose(); + _debugService.Dispose(); _storageService.Dispose(); _keyboardService.Dispose(); _gamePortService.Dispose(); @@ -82,6 +85,7 @@ protected override void EndRun() private Machine _machine = new Machine(); + private DebugService _debugService; private StorageService _storageService; private KeyboardService _keyboardService; private GamePortService _gamePortService; diff --git a/Virtu/Xna/Services/XnaAudioService.cs b/Virtu/Xna/Services/XnaAudioService.cs index 9ed122c..da150fb 100644 --- a/Virtu/Xna/Services/XnaAudioService.cs +++ b/Virtu/Xna/Services/XnaAudioService.cs @@ -35,10 +35,16 @@ protected override void Dispose(bool disposing) private void OnDynamicSoundEffectBufferNeeded(object sender, EventArgs e) // audio thread { + //if (_count++ % (1000 / SampleLatency) == 0) + //{ + // DebugService.WriteLine("OnDynamicSoundEffectBufferNeeded"); + //} + Update(SampleSize, (source, count) => _dynamicSoundEffect.SubmitBuffer(source, 0, count)); } private GameBase _game; private DynamicSoundEffectInstance _dynamicSoundEffect = new DynamicSoundEffectInstance(SampleRate, (AudioChannels)SampleChannels); + //private int _count; } } diff --git a/Virtu/Xna/Services/XnaKeyboardService.cs b/Virtu/Xna/Services/XnaKeyboardService.cs index ebc1452..43af711 100644 --- a/Virtu/Xna/Services/XnaKeyboardService.cs +++ b/Virtu/Xna/Services/XnaKeyboardService.cs @@ -83,6 +83,8 @@ private bool IsKeyDown(Keys key) private void OnKeyDown(Keys key, bool gamePadControl) { + //DebugService.WriteLine(string.Concat("OnKeyDn: Key=", key)); + int asciiKey = GetAsciiKey(key, gamePadControl); if (asciiKey >= 0) { @@ -92,6 +94,8 @@ private void OnKeyDown(Keys key, bool gamePadControl) private void OnKeyUp(Keys key, bool gamePadControl) { + //DebugService.WriteLine(string.Concat("OnKeyUp: Key=", key)); + bool control = IsKeyDown(Keys.LeftControl) || IsKeyDown(Keys.RightControl); if (key == Keys.CapsLock)