From 2167383a00fafa6fa01d4a330981baed29c44b0a Mon Sep 17 00:00:00 2001 From: Sean Fausett Date: Fri, 16 Jul 2010 09:36:41 +0000 Subject: [PATCH] Upgraded to Windows Phone 7 Beta. Upgraded to FxCop 10.0. Dropped Silverlight Toolkit dependency (for now). Modified AudioService to avoid deadlocks by using timeouts. Refactored DebugService and implementations. Modified SilverlightVideoService to handle browser zoom. Split Wpf MainWindow into MainPage child control. --HG-- extra : convert_revision : svn%3Affd33b8c-2492-42e0-bdc5-587b920b7d6d/trunk%4048619 --- Library/DispatcherExtensions.cs | 52 ++ Library/Jellyfish.Library.FxCop | 10 +- Library/Silverlight/ApplicationBase.cs | 73 ++- .../Jellyfish.Library.Silverlight.csproj | 9 + ...Jellyfish.Library.Silverlight.Phone.csproj | 10 + Library/ThreadExtensions.cs | 23 + Library/WaitHandleExtensions.cs | 20 + Library/Wpf/ApplicationBase.cs | 37 +- Library/Wpf/Jellyfish.Library.Wpf.csproj | 9 + Library/Xna/FrameRateCounter.cs | 9 +- Library/Xna/GameBase.cs | 12 +- .../Xna/Jellyfish.Library.Xna.Phone.csproj | 6 + Library/Xna/Jellyfish.Library.Xna.Xbox.csproj | 6 + Library/Xna/Jellyfish.Library.Xna.csproj | 6 + Virtu/Cpu.cs | 1 - Virtu/DiskII.cs | 1 - Virtu/Drive525.cs | 2 - Virtu/GamePort.cs | 1 - Virtu/Jellyfish.Virtu.FxCop | 46 +- Virtu/Machine.cs | 12 +- Virtu/MachineSettings.cs | 38 +- Virtu/Services/AudioService.cs | 11 +- Virtu/Services/DebugService.cs | 9 +- Virtu/Services/KeyboardService.cs | 4 +- Virtu/Services/MachineService.cs | 10 - Virtu/Services/MachineServices.cs | 6 - .../Jellyfish.Virtu.Silverlight.csproj | 2 +- Virtu/Silverlight/MainApp.xaml | 2 +- Virtu/Silverlight/MainPage.xaml | 30 +- Virtu/Silverlight/MainPage.xaml.cs | 46 +- .../Jellyfish.Virtu.Silverlight.Phone.csproj | 3 +- Virtu/Silverlight/Phone/MainApp.xaml | 567 +----------------- Virtu/Silverlight/Phone/MainApp.xaml.cs | 1 + Virtu/Silverlight/Phone/MainPage.xaml | 45 +- Virtu/Silverlight/Phone/MainPage.xaml.cs | 46 +- .../Phone/Properties/WMAppManifest.xml | 4 +- .../Services/SilverlightAudioService.cs | 6 +- .../Services/SilverlightDebugService.cs | 14 +- .../Services/SilverlightKeyboardService.cs | 9 +- .../Services/SilverlightVideoService.cs | 25 +- Virtu/Wpf/Jellyfish.Virtu.Wpf.csproj | 7 + Virtu/Wpf/MainPage.xaml | 23 + Virtu/Wpf/MainPage.xaml.cs | 102 ++++ Virtu/Wpf/MainWindow.xaml | 18 +- Virtu/Wpf/MainWindow.xaml.cs | 83 +-- Virtu/Wpf/Services/WpfAudioService.cs | 17 +- Virtu/Wpf/Services/WpfDebugService.cs | 24 +- Virtu/Wpf/Services/WpfKeyboardService.cs | 25 +- Virtu/Wpf/Services/WpfVideoService.cs | 47 +- Virtu/Xna/Background.png | Bin 0 -> 12776 bytes Virtu/Xna/Jellyfish.Virtu.Xna.Phone.csproj | 17 +- Virtu/Xna/Jellyfish.Virtu.Xna.Xbox.csproj | 7 +- Virtu/Xna/Jellyfish.Virtu.Xna.csproj | 7 +- Virtu/Xna/MainGame.cs | 8 +- Virtu/Xna/Properties/WMAppManifest.xml | 29 + Virtu/Xna/Services/XnaStorageService.cs | 13 +- Virtu/Xna/Services/XnaVideoService.cs | 24 +- 57 files changed, 651 insertions(+), 1023 deletions(-) create mode 100644 Library/DispatcherExtensions.cs create mode 100644 Library/ThreadExtensions.cs create mode 100644 Library/WaitHandleExtensions.cs create mode 100644 Virtu/Wpf/MainPage.xaml create mode 100644 Virtu/Wpf/MainPage.xaml.cs create mode 100644 Virtu/Xna/Background.png create mode 100644 Virtu/Xna/Properties/WMAppManifest.xml diff --git a/Library/DispatcherExtensions.cs b/Library/DispatcherExtensions.cs new file mode 100644 index 0000000..f2df1b2 --- /dev/null +++ b/Library/DispatcherExtensions.cs @@ -0,0 +1,52 @@ +using System; +using System.Windows.Threading; + +namespace Jellyfish.Library +{ + public static class DispatcherExtensions + { + public static void CheckBeginInvoke(this Dispatcher dispatcher, Action action) + { + if (dispatcher == null) + { + throw new ArgumentNullException("dispatcher"); + } + if (action == null) + { + throw new ArgumentNullException("action"); + } + + if (dispatcher.CheckAccess()) + { + action(); + } + else + { + dispatcher.BeginInvoke(action); + } + } + +#if WINDOWS + public static void CheckInvoke(this Dispatcher dispatcher, Action action) + { + if (dispatcher == null) + { + throw new ArgumentNullException("dispatcher"); + } + if (action == null) + { + throw new ArgumentNullException("action"); + } + + if (dispatcher.CheckAccess()) + { + action(); + } + else + { + dispatcher.Invoke(action); + } + } +#endif + } +} diff --git a/Library/Jellyfish.Library.FxCop b/Library/Jellyfish.Library.FxCop index 9902a60..8733a56 100644 --- a/Library/Jellyfish.Library.FxCop +++ b/Library/Jellyfish.Library.FxCop @@ -1,8 +1,8 @@  - + True - c:\program files\microsoft fxcop 1.36\Xml\FxCopReport.xsl + $(FxCopDir)\Xml\FxCopReport.xsl @@ -19,11 +19,10 @@ True 120 True - 3.5 - + @@ -35,10 +34,11 @@ + - + diff --git a/Library/Silverlight/ApplicationBase.cs b/Library/Silverlight/ApplicationBase.cs index 335c5b2..308f988 100644 --- a/Library/Silverlight/ApplicationBase.cs +++ b/Library/Silverlight/ApplicationBase.cs @@ -1,6 +1,11 @@ -using System; +using System.Diagnostics; using System.Text; using System.Windows; +#if WINDOWS_PHONE +using System.Windows.Navigation; +using Microsoft.Phone.Controls; +using Microsoft.Phone.Shell; +#endif namespace Jellyfish.Library { @@ -19,24 +24,25 @@ public ApplicationBase(string name) //AppDomain.CurrentDomain.UnhandledException += OnAppDomainUnhandledException; } - private void OnApplicationUnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) +#if WINDOWS_PHONE + protected void InitializePhoneApplication() { - MessageBox.Show(GetExceptionMessage(e.ExceptionObject), GetExceptionCaption("Application Exception"), MessageBoxButton.OK); - e.Handled = true; + if (!_phoneApplicationInitialized) + { + RootFrame = new PhoneApplicationFrame(); + RootFrame.Navigated += OnRootFrameNavigated; + RootFrame.NavigationFailed += OnRootFrameNavigationFailed; + _phoneApplicationInitialized = true; + } } - - //private void OnAppDomainUnhandledException(object sender, UnhandledExceptionEventArgs e) - //{ - // MessageBox.Show(GetExceptionMessage(e.ExceptionObject as Exception), GetExceptionCaption("AppDomain Exception", e.IsTerminating), MessageBoxButton.OK); - //} +#endif private string GetExceptionCaption(string title, bool isTerminating = false) { var caption = new StringBuilder(); if (!string.IsNullOrEmpty(Name)) { - caption.Append(Name); - caption.Append(" "); + caption.Append(Name).Append(' '); } caption.Append(title); if (isTerminating) @@ -47,19 +53,48 @@ private string GetExceptionCaption(string title, bool isTerminating = false) return caption.ToString(); } - private static string GetExceptionMessage(Exception exception) + private void OnApplicationUnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) { - var message = new StringBuilder(); - if (exception != null) + MessageBox.Show(e.ExceptionObject.ToString(), GetExceptionCaption("Application Exception"), MessageBoxButton.OK); + if (Debugger.IsAttached) { - message.Append(exception.Message.ToString()); - message.Append(Environment.NewLine); - message.Append(exception.StackTrace.ToString()); + Debugger.Break(); } - - return message.ToString(); } + //private void OnAppDomainUnhandledException(object sender, UnhandledExceptionEventArgs e) + //{ + // MessageBox.Show(e.ExceptionObject.ToString(), GetExceptionCaption("AppDomain Exception", e.IsTerminating), MessageBoxButton.OK); + // if (Debugger.IsAttached) + // { + // Debugger.Break(); + // } + //} + +#if WINDOWS_PHONE + private void OnRootFrameNavigated(object sender, NavigationEventArgs e) + { + if (RootVisual != RootFrame) + { + RootVisual = RootFrame; + } + RootFrame.Navigated -= OnRootFrameNavigated; + } + + private void OnRootFrameNavigationFailed(object sender, NavigationFailedEventArgs e) + { + if (Debugger.IsAttached) + { + Debugger.Break(); + } + } +#endif + public string Name { get; private set; } +#if WINDOWS_PHONE + public PhoneApplicationFrame RootFrame { get; private set; } + + private bool _phoneApplicationInitialized; +#endif } } diff --git a/Library/Silverlight/Jellyfish.Library.Silverlight.csproj b/Library/Silverlight/Jellyfish.Library.Silverlight.csproj index 03d2548..6c4e1fc 100644 --- a/Library/Silverlight/Jellyfish.Library.Silverlight.csproj +++ b/Library/Silverlight/Jellyfish.Library.Silverlight.csproj @@ -67,6 +67,9 @@ AssemblyCommentAttribute.cs + + DispatcherExtensions.cs + FrameRateCounter.xaml.cs FrameRateCounter.xaml @@ -89,6 +92,12 @@ StringBuilderExtensions.cs + + ThreadExtensions.cs + + + WaitHandleExtensions.cs + WaveFormat.cs diff --git a/Library/Silverlight/Phone/Jellyfish.Library.Silverlight.Phone.csproj b/Library/Silverlight/Phone/Jellyfish.Library.Silverlight.Phone.csproj index 473c3f1..8b4e7aa 100644 --- a/Library/Silverlight/Phone/Jellyfish.Library.Silverlight.Phone.csproj +++ b/Library/Silverlight/Phone/Jellyfish.Library.Silverlight.Phone.csproj @@ -47,6 +47,7 @@ false + @@ -59,6 +60,9 @@ AssemblyCommentAttribute.cs + + DispatcherExtensions.cs + GlobalSuppressions.cs @@ -77,6 +81,12 @@ StringBuilderExtensions.cs + + ThreadExtensions.cs + + + WaitHandleExtensions.cs + WaveFormat.cs diff --git a/Library/ThreadExtensions.cs b/Library/ThreadExtensions.cs new file mode 100644 index 0000000..b58869c --- /dev/null +++ b/Library/ThreadExtensions.cs @@ -0,0 +1,23 @@ +using System; +using System.Threading; + +namespace Jellyfish.Library +{ + public static class ThreadExtensions + { + public static void IsAliveJoin(this Thread thread) + { + if (thread == null) + { + throw new ArgumentNullException("thread"); + } + +#if !XBOX + if (thread.IsAlive) +#endif + { + thread.Join(); + } + } + } +} diff --git a/Library/WaitHandleExtensions.cs b/Library/WaitHandleExtensions.cs new file mode 100644 index 0000000..77767ab --- /dev/null +++ b/Library/WaitHandleExtensions.cs @@ -0,0 +1,20 @@ +using System; +using System.Threading; + +namespace Jellyfish.Library +{ + public static class WaitHandleExtensions + { +#if XBOX + public static bool WaitOne(this WaitHandle waitHandle, int millisecondsTimeout) + { + if (waitHandle == null) + { + throw new ArgumentNullException("waitHandle"); + } + + return waitHandle.WaitOne(millisecondsTimeout, false); + } +#endif + } +} diff --git a/Library/Wpf/ApplicationBase.cs b/Library/Wpf/ApplicationBase.cs index 0049cd3..50ee4e1 100644 --- a/Library/Wpf/ApplicationBase.cs +++ b/Library/Wpf/ApplicationBase.cs @@ -24,26 +24,12 @@ public ApplicationBase(string name) AppDomain.CurrentDomain.UnhandledException += OnAppDomainUnhandledException; } - private void OnApplicationDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) - { - MessageBox.Show(GetExceptionMessage(e.Exception), GetExceptionCaption("Application Dispatcher Exception", isTerminating: true)); - e.Handled = true; - Shutdown(); - } - - private void OnAppDomainUnhandledException(object sender, UnhandledExceptionEventArgs e) - { - MessageBox.Show(GetExceptionMessage(e.ExceptionObject as Exception), GetExceptionCaption("AppDomain Exception", e.IsTerminating)); - } - private string GetExceptionCaption(string title, bool isTerminating = false) { var caption = new StringBuilder(); - caption.AppendFormat("[{0}] ", Process.GetCurrentProcess().Id); if (!string.IsNullOrEmpty(Name)) { - caption.Append(Name); - caption.Append(" "); + caption.Append(Name).Append(' '); } caption.Append(title); if (isTerminating) @@ -54,17 +40,24 @@ private string GetExceptionCaption(string title, bool isTerminating = false) return caption.ToString(); } - private static string GetExceptionMessage(Exception exception) + private void OnApplicationDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) { - var message = new StringBuilder(); - if (exception != null) + MessageBox.Show(e.Exception.ToString(), GetExceptionCaption("Application Dispatcher Exception", isTerminating: true)); + if (Debugger.IsAttached) { - message.Append(exception.Message.ToString()); - message.Append(Environment.NewLine); - message.Append(exception.StackTrace.ToString()); + Debugger.Break(); } + e.Handled = true; + Shutdown(); + } - return message.ToString(); + private void OnAppDomainUnhandledException(object sender, UnhandledExceptionEventArgs e) + { + MessageBox.Show(e.ExceptionObject.ToString(), GetExceptionCaption("AppDomain Exception", e.IsTerminating)); + if (Debugger.IsAttached) + { + Debugger.Break(); + } } public string Name { get; private set; } diff --git a/Library/Wpf/Jellyfish.Library.Wpf.csproj b/Library/Wpf/Jellyfish.Library.Wpf.csproj index 4b1c515..2c993df 100644 --- a/Library/Wpf/Jellyfish.Library.Wpf.csproj +++ b/Library/Wpf/Jellyfish.Library.Wpf.csproj @@ -58,6 +58,9 @@ DirectSoundInterop.cs + + DispatcherExtensions.cs + FrameRateCounter.xaml.cs FrameRateCounter.xaml @@ -95,6 +98,12 @@ StringBuilderExtensions.cs + + ThreadExtensions.cs + + + WaitHandleExtensions.cs + WaveFormat.cs diff --git a/Library/Xna/FrameRateCounter.cs b/Library/Xna/FrameRateCounter.cs index 2aa7a7b..4d13bb1 100644 --- a/Library/Xna/FrameRateCounter.cs +++ b/Library/Xna/FrameRateCounter.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -12,12 +13,6 @@ public FrameRateCounter(GameBase game) : { FontColor = Color.White; FontName = "Default"; - - //game.IsFixedTimeStep = true; // fixed (default) - //game.TargetElapsedTime = TimeSpan.FromSeconds(1 / 60f); - - //game.IsFixedTimeStep = false; // flatout - //game.GraphicsDeviceManager.SynchronizeWithVerticalRetrace = false; } protected override void LoadContent() @@ -29,6 +24,7 @@ protected override void LoadContent() Position = new Vector2(titleSafeArea.X, titleSafeArea.Y); } + [SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")] public override void Draw(GameTime gameTime) { _frameCount++; @@ -44,6 +40,7 @@ public override void Draw(GameTime gameTime) _spriteBatch.End(); } + [SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")] public override void Update(GameTime gameTime) { if (gameTime == null) diff --git a/Library/Xna/GameBase.cs b/Library/Xna/GameBase.cs index c0d56de..ecfb876 100644 --- a/Library/Xna/GameBase.cs +++ b/Library/Xna/GameBase.cs @@ -1,5 +1,6 @@ -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.GamerServices; +using System; +using System.Diagnostics.CodeAnalysis; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; @@ -16,16 +17,21 @@ public GameBase(string name) { Name = name; + Content.RootDirectory = "Content"; GraphicsDeviceManager = new GraphicsDeviceManager(this); +#if WINDOWS_PHONE + GraphicsDeviceManager.IsFullScreen = true; + TargetElapsedTime = TimeSpan.FromTicks(333333); // 30 fps +#endif GraphicsDeviceService = (IGraphicsDeviceService)Services.GetService(typeof(IGraphicsDeviceService)); - Content.RootDirectory = "Content"; if (!string.IsNullOrEmpty(Name)) { Window.Title = Name; } } + [SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")] protected override void Update(GameTime gameTime) { var gamePadState = GamePad.GetState(PlayerIndex.One); diff --git a/Library/Xna/Jellyfish.Library.Xna.Phone.csproj b/Library/Xna/Jellyfish.Library.Xna.Phone.csproj index 2556585..efeeb42 100644 --- a/Library/Xna/Jellyfish.Library.Xna.Phone.csproj +++ b/Library/Xna/Jellyfish.Library.Xna.Phone.csproj @@ -110,6 +110,12 @@ StringBuilderExtensions.cs + + ThreadExtensions.cs + + + WaitHandleExtensions.cs + XmlSerializerHelpers.cs diff --git a/Library/Xna/Jellyfish.Library.Xna.Xbox.csproj b/Library/Xna/Jellyfish.Library.Xna.Xbox.csproj index fcdd66c..cd59486 100644 --- a/Library/Xna/Jellyfish.Library.Xna.Xbox.csproj +++ b/Library/Xna/Jellyfish.Library.Xna.Xbox.csproj @@ -122,6 +122,12 @@ StringBuilderExtensions.cs + + ThreadExtensions.cs + + + WaitHandleExtensions.cs + XmlSerializerHelpers.cs diff --git a/Library/Xna/Jellyfish.Library.Xna.csproj b/Library/Xna/Jellyfish.Library.Xna.csproj index 2fe383d..7b161fe 100644 --- a/Library/Xna/Jellyfish.Library.Xna.csproj +++ b/Library/Xna/Jellyfish.Library.Xna.csproj @@ -134,6 +134,12 @@ StringBuilderExtensions.cs + + ThreadExtensions.cs + + + WaitHandleExtensions.cs + XmlSerializerHelpers.cs diff --git a/Virtu/Cpu.cs b/Virtu/Cpu.cs index 40ab5d3..ca5ab5f 100644 --- a/Virtu/Cpu.cs +++ b/Virtu/Cpu.cs @@ -1,7 +1,6 @@ using System; using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Threading; namespace Jellyfish.Virtu { diff --git a/Virtu/DiskII.cs b/Virtu/DiskII.cs index d1b3017..2b8fe9e 100644 --- a/Virtu/DiskII.cs +++ b/Virtu/DiskII.cs @@ -1,6 +1,5 @@ using System.Diagnostics.CodeAnalysis; using Jellyfish.Virtu.Services; -using Jellyfish.Virtu.Settings; namespace Jellyfish.Virtu { diff --git a/Virtu/Drive525.cs b/Virtu/Drive525.cs index 40356b1..8b50aa6 100644 --- a/Virtu/Drive525.cs +++ b/Virtu/Drive525.cs @@ -15,9 +15,7 @@ public Drive525() DriveArmStepDelta[3] = new int[] { 0, 1, 0, 1, -1, 0, -1, 0, 0, 1, 0, 1, -1, 0, -1, 0 }; // phase 3 } -#if !XBOX [SecurityCritical] -#endif public void InsertDisk(string fileName, bool isWriteProtected) { using (var stream = File.OpenRead(fileName)) diff --git a/Virtu/GamePort.cs b/Virtu/GamePort.cs index 5a456f4..d8f8164 100644 --- a/Virtu/GamePort.cs +++ b/Virtu/GamePort.cs @@ -2,7 +2,6 @@ using System.Diagnostics.CodeAnalysis; using Jellyfish.Library; using Jellyfish.Virtu.Services; -using Jellyfish.Virtu.Settings; namespace Jellyfish.Virtu { diff --git a/Virtu/Jellyfish.Virtu.FxCop b/Virtu/Jellyfish.Virtu.FxCop index 6288a3e..0b7057e 100644 --- a/Virtu/Jellyfish.Virtu.FxCop +++ b/Virtu/Jellyfish.Virtu.FxCop @@ -1,8 +1,8 @@  - + True - c:\program files\microsoft fxcop 1.36\Xml\FxCopReport.xsl + $(FxCopDir)\Xml\FxCopReport.xsl @@ -19,11 +19,10 @@ True 120 True - 3.5 - + @@ -35,46 +34,11 @@ + - - - - - - - - - - - - - - - 'target' - 'Button' - 'MainWindow.IComponentConnector.Connect(int, object)' - castclass - - - - - - - - - - - - - - - - {0}, a parameter, is cast to type {1} multiple times in method {2}. Cache the result of the 'as' operator or direct cast in order to eliminate the redundant {3} instruction. - - - + diff --git a/Virtu/Machine.cs b/Virtu/Machine.cs index e6c8dbe..5646033 100644 --- a/Virtu/Machine.cs +++ b/Virtu/Machine.cs @@ -47,8 +47,6 @@ public void Start() _storageService.Load(MachineSettings.FileName, stream => Settings.Deserialize(stream)); State = MachineState.Starting; - Services.ForEach(service => service.Start()); - Thread.Start(); } @@ -68,14 +66,14 @@ public void Unpause() public void Stop() { State = MachineState.Stopping; - Services.ForEach(service => service.Stop()); - - _pauseEvent.Set(); _unpauseEvent.Set(); - Thread.Join(); + Thread.IsAliveJoin(); State = MachineState.Stopped; - _storageService.Save(MachineSettings.FileName, stream => Settings.Serialize(stream)); + if (_storageService != null) + { + _storageService.Save(MachineSettings.FileName, stream => Settings.Serialize(stream)); + } } private void Run() // machine thread diff --git a/Virtu/MachineSettings.cs b/Virtu/MachineSettings.cs index 17be26d..4cdaa59 100644 --- a/Virtu/MachineSettings.cs +++ b/Virtu/MachineSettings.cs @@ -36,29 +36,33 @@ public MachineSettings() Button0 = 0, Button1 = 0, Button2 = 0 } }; +#if WINDOWS_PHONE + Audio = new AudioSettings { Volume = 0.85 }; +#else Audio = new AudioSettings { Volume = 0.5 }; +#endif Video = new VideoSettings { IsFullScreen = false, IsMonochrome = false, ScannerOptions = ScannerOptions.None, Color = new ColorSettings { - Black = 0x000000, - DarkBlue = 0x000099, - DarkGreen = 0x117722, - MediumBlue = 0x0000FF, - Brown = 0x885500, - LightGrey = 0x99AAAA, - Green = 0x00EE11, - Aquamarine = 0x55FFAA, - DeepRed = 0xFF1111, - Purple = 0xDD00DD, - DarkGrey = 0x445555, - LightBlue = 0x33AAFF, - Orange = 0xFF4411, - Pink = 0xFF9988, - Yellow = 0xFFFF11, - White = 0xFFFFFF, - Monochrome = 0x00AA00 + Black = 0xFF000000, // BGRA + DarkBlue = 0xFF000099, + DarkGreen = 0xFF117722, + MediumBlue = 0xFF0000FF, + Brown = 0xFF885500, + LightGrey = 0xFF99AAAA, + Green = 0xFF00EE11, + Aquamarine = 0xFF55FFAA, + DeepRed = 0xFFFF1111, + Purple = 0xFFDD00DD, + DarkGrey = 0xFF445555, + LightBlue = 0xFF33AAFF, + Orange = 0xFFFF4411, + Pink = 0xFFFF9988, + Yellow = 0xFFFFFF11, + White = 0xFFFFFFFF, + Monochrome = 0xFF00AA00 } }; } diff --git a/Virtu/Services/AudioService.cs b/Virtu/Services/AudioService.cs index 4c8434d..9cebad0 100644 --- a/Virtu/Services/AudioService.cs +++ b/Virtu/Services/AudioService.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics.CodeAnalysis; using System.Threading; +using Jellyfish.Library; namespace Jellyfish.Virtu.Services { @@ -21,7 +22,7 @@ public void Output(int data) // machine thread _readEvent.Set(); if (Machine.Settings.Cpu.IsThrottled) { - _writeEvent.WaitOne(); + _writeEvent.WaitOne(SampleLatency * 2); // allow timeout; avoids deadlock } } } @@ -33,17 +34,11 @@ public void Reset() public abstract void SetVolume(double volume); // machine thread - public override void Stop() // main thread - { - _readEvent.Set(); // signal events; avoids deadlock - _writeEvent.Set(); - } - protected void Update(int bufferSize, Action updateBuffer) // audio thread { if (Machine.State == MachineState.Running) { - _readEvent.WaitOne(); + _readEvent.WaitOne(SampleLatency * 2); // allow timeout; avoids deadlock } if (updateBuffer != null) { diff --git a/Virtu/Services/DebugService.cs b/Virtu/Services/DebugService.cs index 40ee580..5368de7 100644 --- a/Virtu/Services/DebugService.cs +++ b/Virtu/Services/DebugService.cs @@ -10,9 +10,14 @@ public DebugService(Machine machine) : { } - public virtual void WriteLine(string message) + public void WriteLine(string message) { - Debug.WriteLine(string.Concat(DateTime.Now, " ", message)); + OnWriteLine(string.Concat(DateTime.Now, ' ', message)); + } + + protected virtual void OnWriteLine(string message) + { + Debug.WriteLine(message); } } } diff --git a/Virtu/Services/KeyboardService.cs b/Virtu/Services/KeyboardService.cs index 557c5ce..353c1f2 100644 --- a/Virtu/Services/KeyboardService.cs +++ b/Virtu/Services/KeyboardService.cs @@ -1,6 +1,4 @@ -using System; - -namespace Jellyfish.Virtu.Services +namespace Jellyfish.Virtu.Services { public abstract class KeyboardService : MachineService { diff --git a/Virtu/Services/MachineService.cs b/Virtu/Services/MachineService.cs index cfb77a3..064a63c 100644 --- a/Virtu/Services/MachineService.cs +++ b/Virtu/Services/MachineService.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics.CodeAnalysis; namespace Jellyfish.Virtu.Services { @@ -21,15 +20,6 @@ public void Dispose() GC.SuppressFinalize(this); } - public virtual void Start() - { - } - - [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Stop")] - public virtual void Stop() - { - } - protected virtual void Dispose(bool disposing) { } diff --git a/Virtu/Services/MachineServices.cs b/Virtu/Services/MachineServices.cs index 0b3627e..eb7e642 100644 --- a/Virtu/Services/MachineServices.cs +++ b/Virtu/Services/MachineServices.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Globalization; -using Jellyfish.Library; using Jellyfish.Virtu.Properties; namespace Jellyfish.Virtu.Services @@ -31,11 +30,6 @@ public void AddService(Type serviceType, MachineService serviceProvider) _serviceProviders.Add(serviceType, serviceProvider); } - public void ForEach(Action action) - { - _serviceProviders.Values.ForEach(action); - } - [SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")] public T GetService() { diff --git a/Virtu/Silverlight/Jellyfish.Virtu.Silverlight.csproj b/Virtu/Silverlight/Jellyfish.Virtu.Silverlight.csproj index 03d36c9..c884441 100644 --- a/Virtu/Silverlight/Jellyfish.Virtu.Silverlight.csproj +++ b/Virtu/Silverlight/Jellyfish.Virtu.Silverlight.csproj @@ -72,7 +72,7 @@ - + True diff --git a/Virtu/Silverlight/MainApp.xaml b/Virtu/Silverlight/MainApp.xaml index 8712cfc..6178bd4 100644 --- a/Virtu/Silverlight/MainApp.xaml +++ b/Virtu/Silverlight/MainApp.xaml @@ -4,7 +4,7 @@ xmlns:jl="clr-namespace:Jellyfish.Library;assembly=Jellyfish.Library" xmlns:jv="clr-namespace:Jellyfish.Virtu;assembly=Jellyfish.Virtu"> - + diff --git a/Virtu/Silverlight/MainPage.xaml b/Virtu/Silverlight/MainPage.xaml index 9adc007..adb677c 100644 --- a/Virtu/Silverlight/MainPage.xaml +++ b/Virtu/Silverlight/MainPage.xaml @@ -1,21 +1,23 @@  - - -