Added debug service.

Fixed code analysis warnings.

--HG--
extra : convert_revision : svn%3Affd33b8c-2492-42e0-bdc5-587b920b7d6d/trunk%4047095
This commit is contained in:
Sean Fausett 2010-06-06 21:48:51 +00:00
parent 2ba3146299
commit d22639c563
29 changed files with 174 additions and 22 deletions

View File

@ -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) : public GeneralSecurity(bool isContainer, ResourceType resourceType, SafeHandle handle, AccessControlSections includeSections = AccessControlSections.Access | AccessControlSections.Group | AccessControlSections.Owner) :
base(isContainer, resourceType, handle, includeSections) 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) : public GeneralSecurity(bool isContainer, ResourceType resourceType, string name, AccessControlSections includeSections = AccessControlSections.Access | AccessControlSections.Group | AccessControlSections.Owner) :
base(isContainer, resourceType, name, includeSections) base(isContainer, resourceType, name, includeSections)
{ {
@ -103,12 +105,14 @@ public void AddAuditRule(GeneralAuditRule rule)
base.AddAuditRule(rule); base.AddAuditRule(rule);
} }
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
[SecurityCritical] [SecurityCritical]
public void GetSecurityAttributes(Action<SecurityAttributes> action, bool inheritable = false) public void GetSecurityAttributes(Action<SecurityAttributes> action, bool inheritable = false)
{ {
GetSecurityAttributes(this, action, inheritable); GetSecurityAttributes(this, action, inheritable);
} }
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
[SecurityCritical] [SecurityCritical]
public static void GetSecurityAttributes(ObjectSecurity security, Action<SecurityAttributes> action, bool inheritable = false) public static void GetSecurityAttributes(ObjectSecurity security, Action<SecurityAttributes> action, bool inheritable = false)
{ {

View File

@ -47,6 +47,8 @@ public static SafeGlobalAllocHandle Allocate(byte[] value)
return alloc; return alloc;
} }
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
[SuppressMessage("Microsoft.Naming", "CA1726:UsePreferredTerms", MessageId = "flags")]
[SecurityCritical] [SecurityCritical]
public static SafeGlobalAllocHandle Allocate(int size, uint flags = 0x0) public static SafeGlobalAllocHandle Allocate(int size, uint flags = 0x0)
{ {
@ -110,6 +112,8 @@ public static SafeLocalAllocHandle Allocate(byte[] value)
return alloc; return alloc;
} }
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
[SuppressMessage("Microsoft.Naming", "CA1726:UsePreferredTerms", MessageId = "flags")]
[SecurityCritical] [SecurityCritical]
public static SafeLocalAllocHandle Allocate(int size, uint flags = 0x0) public static SafeLocalAllocHandle Allocate(int size, uint flags = 0x0)
{ {

View File

@ -6,7 +6,12 @@ namespace Jellyfish.Library
{ {
public class ApplicationBase : Application public class ApplicationBase : Application
{ {
public ApplicationBase(string name = null) public ApplicationBase() :
this(null)
{
}
public ApplicationBase(string name)
{ {
Name = name; Name = name;

View File

@ -10,7 +10,13 @@ namespace Jellyfish.Library
public class ApplicationBase : Application public class ApplicationBase : Application
{ {
[SecurityCritical] [SecurityCritical]
public ApplicationBase(string name = null) public ApplicationBase() :
this(null)
{
}
[SecurityCritical]
public ApplicationBase(string name)
{ {
Name = name; Name = name;

View File

@ -8,6 +8,7 @@ namespace Jellyfish.Library
public static class XmlSerializerHelpers public static class XmlSerializerHelpers
{ {
[SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")] [SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")]
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
public static T Deserialize<T>(Stream stream, string defaultNamespace = null) public static T Deserialize<T>(Stream stream, string defaultNamespace = null)
{ {
using (var reader = XmlReader.Create(stream)) using (var reader = XmlReader.Create(stream))
@ -17,6 +18,7 @@ public static T Deserialize<T>(Stream stream, string defaultNamespace = null)
} }
} }
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
public static void Serialize<T>(Stream stream, T instance, string defaultNamespace = null) public static void Serialize<T>(Stream stream, T instance, string defaultNamespace = null)
{ {
using (var writer = XmlWriter.Create(stream)) using (var writer = XmlWriter.Create(stream))

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Diagnostics.CodeAnalysis;
using System.Threading; using System.Threading;
namespace Jellyfish.Virtu.Services namespace Jellyfish.Virtu.Services
@ -13,7 +14,7 @@ public AudioService(Machine machine) :
public void Output(int data) // machine thread public void Output(int data) // machine thread
{ {
_buffer[_index + 0] = (byte)(data & 0xFF); _buffer[_index + 0] = (byte)(data & 0xFF);
_buffer[_index + 1] = (byte)((data >> 8) & 0xFF); _buffer[_index + 1] = (byte)(data >> 8);
_index = (_index + 2) % SampleSize; _index = (_index + 2) % SampleSize;
if (_index == 0) if (_index == 0)
{ {
@ -55,6 +56,7 @@ protected void Update(int bufferSize, Action<byte[], int> updateBuffer) // audio
public const int SampleLatency = 40; // ms public const int SampleLatency = 40; // ms
public const int SampleSize = (SampleRate * SampleLatency / 1000) * SampleChannels * (SampleBits / 8); public const int SampleSize = (SampleRate * SampleLatency / 1000) * SampleChannels * (SampleBits / 8);
[SuppressMessage("Microsoft.Security", "CA2105:ArrayFieldsShouldNotBeReadOnly")]
protected static readonly byte[] SampleZero = new byte[SampleSize]; protected static readonly byte[] SampleZero = new byte[SampleSize];
private byte[] _buffer = new byte[SampleSize]; private byte[] _buffer = new byte[SampleSize];

View File

@ -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));
}
}
}

View File

@ -35,5 +35,6 @@ protected virtual void Dispose(bool disposing)
} }
protected Machine Machine { get; private set; } protected Machine Machine { get; private set; }
protected DebugService DebugService { get { return Machine.Services.GetService<DebugService>(); } }
} }
} }

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using System.Reflection; 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) public static Stream GetResourceStream(string resourceName, int resourceSize = 0)
{ {
var resourceManager = new ResourceManager("Jellyfish.Virtu.g", Assembly.GetExecutingAssembly()) { IgnoreCase = true }; var resourceManager = new ResourceManager("Jellyfish.Virtu.g", Assembly.GetExecutingAssembly()) { IgnoreCase = true };

View File

@ -155,6 +155,9 @@
<Compile Include="..\Services\AudioService.cs"> <Compile Include="..\Services\AudioService.cs">
<Link>Services\AudioService.cs</Link> <Link>Services\AudioService.cs</Link>
</Compile> </Compile>
<Compile Include="..\Services\DebugService.cs">
<Link>Services\DebugService.cs</Link>
</Compile>
<Compile Include="..\Services\GamePortService.cs"> <Compile Include="..\Services\GamePortService.cs">
<Link>Services\GamePortService.cs</Link> <Link>Services\GamePortService.cs</Link>
</Compile> </Compile>
@ -187,6 +190,7 @@
</Compile> </Compile>
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\SilverlightAudioService.cs" /> <Compile Include="Services\SilverlightAudioService.cs" />
<Compile Include="Services\SilverlightDebugService.cs" />
<Compile Include="Services\SilverlightKeyboardService.cs" /> <Compile Include="Services\SilverlightKeyboardService.cs" />
<Compile Include="Services\SilverlightVideoService.cs" /> <Compile Include="Services\SilverlightVideoService.cs" />
</ItemGroup> </ItemGroup>

View File

@ -13,9 +13,9 @@
<Grid> <Grid>
<Image x:Name="_image" MinWidth="280" MinHeight="192"/> <Image x:Name="_image" MinWidth="280" MinHeight="192"/>
<MediaElement x:Name="_media"/> <MediaElement x:Name="_media"/>
<!--<ScrollViewer BorderThickness="0" IsTabStop="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" VerticalScrollBarVisibility="Auto"> <ScrollViewer BorderThickness="0" IsTabStop="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" VerticalScrollBarVisibility="Auto">
<TextBlock x:Name="_debug" FontFamily="Consolas" FontSize="12" Foreground="White"/> <TextBlock x:Name="_debug" FontFamily="Consolas" FontSize="12" Foreground="White"/>
</ScrollViewer>--> </ScrollViewer>
</Grid> </Grid>
</tk:DockPanel> </tk:DockPanel>
</UserControl> </UserControl>

View File

@ -13,12 +13,14 @@ public MainPage()
{ {
InitializeComponent(); InitializeComponent();
_debugService = new SilverlightDebugService(_machine, this);
_storageService = new IsolatedStorageService(_machine); _storageService = new IsolatedStorageService(_machine);
_keyboardService = new SilverlightKeyboardService(_machine, this); _keyboardService = new SilverlightKeyboardService(_machine, this);
_gamePortService = new GamePortService(_machine); // not connected _gamePortService = new GamePortService(_machine); // not connected
_audioService = new SilverlightAudioService(_machine, this, _media); _audioService = new SilverlightAudioService(_machine, this, _media);
_videoService = new SilverlightVideoService(_machine, this, _image); _videoService = new SilverlightVideoService(_machine, this, _image);
_machine.Services.AddService(typeof(DebugService), _debugService);
_machine.Services.AddService(typeof(StorageService), _storageService); _machine.Services.AddService(typeof(StorageService), _storageService);
_machine.Services.AddService(typeof(KeyboardService), _keyboardService); _machine.Services.AddService(typeof(KeyboardService), _keyboardService);
_machine.Services.AddService(typeof(GamePortService), _gamePortService); _machine.Services.AddService(typeof(GamePortService), _gamePortService);
@ -36,6 +38,7 @@ public MainPage()
public void Dispose() public void Dispose()
{ {
_machine.Dispose(); _machine.Dispose();
_debugService.Dispose();
_storageService.Dispose(); _storageService.Dispose();
_keyboardService.Dispose(); _keyboardService.Dispose();
_gamePortService.Dispose(); _gamePortService.Dispose();
@ -68,6 +71,7 @@ private void OnDiskButtonClick(int drive)
private Machine _machine = new Machine(); private Machine _machine = new Machine();
private DebugService _debugService;
private StorageService _storageService; private StorageService _storageService;
private KeyboardService _keyboardService; private KeyboardService _keyboardService;
private GamePortService _gamePortService; private GamePortService _gamePortService;

View File

@ -141,6 +141,9 @@
<Compile Include="..\..\Services\AudioService.cs"> <Compile Include="..\..\Services\AudioService.cs">
<Link>Services\AudioService.cs</Link> <Link>Services\AudioService.cs</Link>
</Compile> </Compile>
<Compile Include="..\..\Services\DebugService.cs">
<Link>Services\DebugService.cs</Link>
</Compile>
<Compile Include="..\..\Services\GamePortService.cs"> <Compile Include="..\..\Services\GamePortService.cs">
<Link>Services\GamePortService.cs</Link> <Link>Services\GamePortService.cs</Link>
</Compile> </Compile>
@ -174,6 +177,9 @@
<Compile Include="..\Services\SilverlightAudioService.cs"> <Compile Include="..\Services\SilverlightAudioService.cs">
<Link>Services\SilverlightAudioService.cs</Link> <Link>Services\SilverlightAudioService.cs</Link>
</Compile> </Compile>
<Compile Include="..\Services\SilverlightDebugService.cs">
<Link>Services\SilverlightDebugService.cs</Link>
</Compile>
<Compile Include="..\Services\SilverlightKeyboardService.cs"> <Compile Include="..\Services\SilverlightKeyboardService.cs">
<Link>Services\SilverlightKeyboardService.cs</Link> <Link>Services\SilverlightKeyboardService.cs</Link>
</Compile> </Compile>

View File

@ -23,9 +23,9 @@
<Grid> <Grid>
<Image x:Name="_image" MinWidth="280" MinHeight="192"/> <Image x:Name="_image" MinWidth="280" MinHeight="192"/>
<MediaElement x:Name="_media"/> <MediaElement x:Name="_media"/>
<!--<ScrollViewer BorderThickness="0" IsTabStop="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" VerticalScrollBarVisibility="Auto"> <ScrollViewer BorderThickness="0" IsTabStop="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" VerticalScrollBarVisibility="Auto">
<TextBlock x:Name="_debug" FontFamily="Consolas" FontSize="12" Foreground="White"/> <TextBlock x:Name="_debug" FontFamily="Consolas" FontSize="12" Foreground="White"/>
</ScrollViewer>--> </ScrollViewer>
</Grid> </Grid>
</Grid> </Grid>
<!--</tk:DockPanel>--> <!--</tk:DockPanel>-->

View File

@ -21,8 +21,9 @@ public SilverlightAudioService(Machine machine, UserControl page, MediaElement m
_page = page; _page = page;
_media = media; _media = media;
_mediaSource = new WaveMediaStreamSource(SampleRate, SampleChannels, SampleBits, SampleSize, SampleLatency, OnMediaSourceUpdate); _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 #if !WINDOWS_PHONE
_page.Unloaded += (sender, e) => _media.Stop(); _page.Unloaded += (sender, e) => _media.Stop();
#endif #endif
@ -42,10 +43,7 @@ private void OnMediaSourceUpdate(byte[] buffer, int bufferSize) // audio thread
{ {
//if (_count++ % (1000 / SampleLatency) == 0) //if (_count++ % (1000 / SampleLatency) == 0)
//{ //{
// _page.Dispatcher.BeginInvoke(() => // DebugService.WriteLine("OnMediaSourceUpdate");
// {
// ((MainPage)_page)._debug.Text += string.Concat(DateTime.Now, " OnMediaSourceUpdate", Environment.NewLine);
// });
//} //}
Update(bufferSize, (source, count) => Buffer.BlockCopy(source, 0, buffer, 0, count)); Update(bufferSize, (source, count) => Buffer.BlockCopy(source, 0, buffer, 0, count));

View File

@ -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;
}
}

View File

@ -62,7 +62,7 @@ private bool IsKeyDown(Key key)
private void OnPageKeyDown(object sender, KeyEventArgs e) 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; _states[(int)e.Key] = true;
_updateAnyKeyDown = false; _updateAnyKeyDown = false;
@ -80,7 +80,7 @@ private void OnPageKeyDown(object sender, KeyEventArgs e)
private void OnPageKeyUp(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; _states[(int)e.Key] = false;
_updateAnyKeyDown = true; _updateAnyKeyDown = true;

View File

@ -135,6 +135,9 @@
<Compile Include="..\Services\AudioService.cs"> <Compile Include="..\Services\AudioService.cs">
<Link>Services\AudioService.cs</Link> <Link>Services\AudioService.cs</Link>
</Compile> </Compile>
<Compile Include="..\Services\DebugService.cs">
<Link>Services\DebugService.cs</Link>
</Compile>
<Compile Include="..\Services\GamePortService.cs"> <Compile Include="..\Services\GamePortService.cs">
<Link>Services\GamePortService.cs</Link> <Link>Services\GamePortService.cs</Link>
</Compile> </Compile>
@ -167,6 +170,7 @@
</Compile> </Compile>
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\WpfAudioService.cs" /> <Compile Include="Services\WpfAudioService.cs" />
<Compile Include="Services\WpfDebugService.cs" />
<Compile Include="Services\WpfKeyboardService.cs" /> <Compile Include="Services\WpfKeyboardService.cs" />
<Compile Include="Services\WpfStorageService.cs" /> <Compile Include="Services\WpfStorageService.cs" />
<Compile Include="Services\WpfVideoService.cs" /> <Compile Include="Services\WpfVideoService.cs" />

View File

@ -11,9 +11,9 @@
</StackPanel> </StackPanel>
<Grid> <Grid>
<Image x:Name="_image" MinWidth="560" MinHeight="384" RenderOptions.BitmapScalingMode="NearestNeighbor"/> <Image x:Name="_image" MinWidth="560" MinHeight="384" RenderOptions.BitmapScalingMode="NearestNeighbor"/>
<!--<ScrollViewer BorderThickness="0" Focusable="False" IsTabStop="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" VerticalScrollBarVisibility="Auto"> <ScrollViewer BorderThickness="0" Focusable="False" IsTabStop="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" VerticalScrollBarVisibility="Auto">
<TextBlock x:Name="_debug" FontFamily="Consolas" FontSize="12" Foreground="White"/> <TextBlock x:Name="_debug" FontFamily="Consolas" FontSize="12" Foreground="White"/>
</ScrollViewer>--> </ScrollViewer>
</Grid> </Grid>
</DockPanel> </DockPanel>
</Window> </Window>

View File

@ -14,12 +14,14 @@ public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
_debugService = new WpfDebugService(_machine, this);
_storageService = new WpfStorageService(_machine); _storageService = new WpfStorageService(_machine);
_keyboardService = new WpfKeyboardService(_machine, this); _keyboardService = new WpfKeyboardService(_machine, this);
_gamePortService = new GamePortService(_machine); // not connected _gamePortService = new GamePortService(_machine); // not connected
_audioService = new WpfAudioService(_machine, this); _audioService = new WpfAudioService(_machine, this);
_videoService = new WpfVideoService(_machine, this, _image); _videoService = new WpfVideoService(_machine, this, _image);
_machine.Services.AddService(typeof(DebugService), _debugService);
_machine.Services.AddService(typeof(StorageService), _storageService); _machine.Services.AddService(typeof(StorageService), _storageService);
_machine.Services.AddService(typeof(KeyboardService), _keyboardService); _machine.Services.AddService(typeof(KeyboardService), _keyboardService);
_machine.Services.AddService(typeof(GamePortService), _gamePortService); _machine.Services.AddService(typeof(GamePortService), _gamePortService);
@ -37,6 +39,7 @@ public MainWindow()
public void Dispose() public void Dispose()
{ {
_machine.Dispose(); _machine.Dispose();
_debugService.Dispose();
_storageService.Dispose(); _storageService.Dispose();
_keyboardService.Dispose(); _keyboardService.Dispose();
_gamePortService.Dispose(); _gamePortService.Dispose();
@ -78,6 +81,7 @@ private void OnDiskButtonClick(int drive)
private Machine _machine = new Machine(); private Machine _machine = new Machine();
private DebugService _debugService;
private StorageService _storageService; private StorageService _storageService;
private KeyboardService _keyboardService; private KeyboardService _keyboardService;
private GamePortService _gamePortService; private GamePortService _gamePortService;

View File

@ -38,10 +38,7 @@ private void OnDirectSoundUpdate(IntPtr buffer, int bufferSize) // audio thread
{ {
//if (_count++ % (1000 / SampleLatency) == 0) //if (_count++ % (1000 / SampleLatency) == 0)
//{ //{
// _window.Dispatcher.BeginInvoke(() => // DebugService.WriteLine("OnDirectSoundUpdate");
// {
// ((MainWindow)_window)._debug.Text += string.Concat(DateTime.Now, " OnDirectSoundUpdate", Environment.NewLine);
// });
//} //}
Update(bufferSize, (source, count) => Marshal.Copy(source, 0, buffer, count)); Update(bufferSize, (source, count) => Marshal.Copy(source, 0, buffer, count));

View File

@ -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;
}
}

View File

@ -62,7 +62,7 @@ private bool IsKeyDown(Key key)
private void OnWindowKeyDown(object sender, KeyEventArgs e) 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; _states[(int)((e.Key == Key.System) ? e.SystemKey : e.Key)] = true;
_updateAnyKeyDown = false; _updateAnyKeyDown = false;
@ -80,7 +80,7 @@ private void OnWindowKeyDown(object sender, KeyEventArgs e)
private void OnWindowKeyUp(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; _states[(int)((e.Key == Key.System) ? e.SystemKey : e.Key)] = false;
_updateAnyKeyDown = true; _updateAnyKeyDown = true;

View File

@ -147,6 +147,9 @@
<Compile Include="..\Services\AudioService.cs"> <Compile Include="..\Services\AudioService.cs">
<Link>Services\AudioService.cs</Link> <Link>Services\AudioService.cs</Link>
</Compile> </Compile>
<Compile Include="..\Services\DebugService.cs">
<Link>Services\DebugService.cs</Link>
</Compile>
<Compile Include="..\Services\GamePortService.cs"> <Compile Include="..\Services\GamePortService.cs">
<Link>Services\GamePortService.cs</Link> <Link>Services\GamePortService.cs</Link>
</Compile> </Compile>

View File

@ -158,6 +158,9 @@
<Compile Include="..\Services\AudioService.cs"> <Compile Include="..\Services\AudioService.cs">
<Link>Services\AudioService.cs</Link> <Link>Services\AudioService.cs</Link>
</Compile> </Compile>
<Compile Include="..\Services\DebugService.cs">
<Link>Services\DebugService.cs</Link>
</Compile>
<Compile Include="..\Services\GamePortService.cs"> <Compile Include="..\Services\GamePortService.cs">
<Link>Services\GamePortService.cs</Link> <Link>Services\GamePortService.cs</Link>
</Compile> </Compile>

View File

@ -159,6 +159,9 @@
<Compile Include="..\Services\AudioService.cs"> <Compile Include="..\Services\AudioService.cs">
<Link>Services\AudioService.cs</Link> <Link>Services\AudioService.cs</Link>
</Compile> </Compile>
<Compile Include="..\Services\DebugService.cs">
<Link>Services\DebugService.cs</Link>
</Compile>
<Compile Include="..\Services\GamePortService.cs"> <Compile Include="..\Services\GamePortService.cs">
<Link>Services\GamePortService.cs</Link> <Link>Services\GamePortService.cs</Link>
</Compile> </Compile>

View File

@ -22,6 +22,7 @@ public MainGame() :
frameRateCounter.DrawOrder = 1; frameRateCounter.DrawOrder = 1;
frameRateCounter.FontName = "Consolas"; frameRateCounter.FontName = "Consolas";
_debugService = new DebugService(_machine);
#if WINDOWS_PHONE #if WINDOWS_PHONE
_storageService = new IsolatedStorageService(_machine); _storageService = new IsolatedStorageService(_machine);
#else #else
@ -32,6 +33,7 @@ public MainGame() :
_audioService = new XnaAudioService(_machine, this); _audioService = new XnaAudioService(_machine, this);
_videoService = new XnaVideoService(_machine, this); _videoService = new XnaVideoService(_machine, this);
_machine.Services.AddService(typeof(DebugService), _debugService);
_machine.Services.AddService(typeof(StorageService), _storageService); _machine.Services.AddService(typeof(StorageService), _storageService);
_machine.Services.AddService(typeof(KeyboardService), _keyboardService); _machine.Services.AddService(typeof(KeyboardService), _keyboardService);
_machine.Services.AddService(typeof(GamePortService), _gamePortService); _machine.Services.AddService(typeof(GamePortService), _gamePortService);
@ -44,6 +46,7 @@ protected override void Dispose(bool disposing)
if (disposing) if (disposing)
{ {
_machine.Dispose(); _machine.Dispose();
_debugService.Dispose();
_storageService.Dispose(); _storageService.Dispose();
_keyboardService.Dispose(); _keyboardService.Dispose();
_gamePortService.Dispose(); _gamePortService.Dispose();
@ -82,6 +85,7 @@ protected override void EndRun()
private Machine _machine = new Machine(); private Machine _machine = new Machine();
private DebugService _debugService;
private StorageService _storageService; private StorageService _storageService;
private KeyboardService _keyboardService; private KeyboardService _keyboardService;
private GamePortService _gamePortService; private GamePortService _gamePortService;

View File

@ -35,10 +35,16 @@ protected override void Dispose(bool disposing)
private void OnDynamicSoundEffectBufferNeeded(object sender, EventArgs e) // audio thread 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)); Update(SampleSize, (source, count) => _dynamicSoundEffect.SubmitBuffer(source, 0, count));
} }
private GameBase _game; private GameBase _game;
private DynamicSoundEffectInstance _dynamicSoundEffect = new DynamicSoundEffectInstance(SampleRate, (AudioChannels)SampleChannels); private DynamicSoundEffectInstance _dynamicSoundEffect = new DynamicSoundEffectInstance(SampleRate, (AudioChannels)SampleChannels);
//private int _count;
} }
} }

View File

@ -83,6 +83,8 @@ private bool IsKeyDown(Keys key)
private void OnKeyDown(Keys key, bool gamePadControl) private void OnKeyDown(Keys key, bool gamePadControl)
{ {
//DebugService.WriteLine(string.Concat("OnKeyDn: Key=", key));
int asciiKey = GetAsciiKey(key, gamePadControl); int asciiKey = GetAsciiKey(key, gamePadControl);
if (asciiKey >= 0) if (asciiKey >= 0)
{ {
@ -92,6 +94,8 @@ private void OnKeyDown(Keys key, bool gamePadControl)
private void OnKeyUp(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); bool control = IsKeyDown(Keys.LeftControl) || IsKeyDown(Keys.RightControl);
if (key == Keys.CapsLock) if (key == Keys.CapsLock)