Deleted all svn:eol-style properties on files.

--HG--
extra : convert_revision : svn%3Affd33b8c-2492-42e0-bdc5-587b920b7d6d/trunk%4050811
This commit is contained in:
Sean Fausett 2010-08-28 11:34:14 +00:00
parent ee4c69dddf
commit 365e5723c1
101 changed files with 14459 additions and 14459 deletions

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Dictionary> <Dictionary>
<Words> <Words>
<Recognized> <Recognized>
<Word>Alloc</Word> <Word>Alloc</Word>
</Recognized> </Recognized>
</Words> </Words>
</Dictionary> </Dictionary>

View File

@ -1,173 +1,173 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security; using System.Security;
using System.Threading; using System.Threading;
namespace Jellyfish.Library namespace Jellyfish.Library
{ {
public sealed partial class DirectSound : IDisposable public sealed partial class DirectSound : IDisposable
{ {
[SecurityCritical] [SecurityCritical]
public DirectSound(int sampleRate, int sampleChannels, int sampleBits, int sampleSize, Action<IntPtr, int> updater) public DirectSound(int sampleRate, int sampleChannels, int sampleBits, int sampleSize, Action<IntPtr, int> updater)
{ {
_sampleRate = sampleRate; _sampleRate = sampleRate;
_sampleChannels = sampleChannels; _sampleChannels = sampleChannels;
_sampleBits = sampleBits; _sampleBits = sampleBits;
_sampleSize = sampleSize; _sampleSize = sampleSize;
_thread = new Thread(Run) { Name = "DirectSound" }; _thread = new Thread(Run) { Name = "DirectSound" };
_updater = updater; _updater = updater;
} }
public void Dispose() public void Dispose()
{ {
_position1Event.Close(); _position1Event.Close();
_position2Event.Close(); _position2Event.Close();
_stopEvent.Close(); _stopEvent.Close();
} }
public void SetVolume(double volume) public void SetVolume(double volume)
{ {
int attenuation = (volume < 0.01) ? (int)BufferVolume.Min : (int)Math.Floor(100 * 20 * Math.Log10(volume)); // 100 db int attenuation = (volume < 0.01) ? (int)BufferVolume.Min : (int)Math.Floor(100 * 20 * Math.Log10(volume)); // 100 db
lock (_bufferLock) lock (_bufferLock)
{ {
if (_buffer != null) if (_buffer != null)
{ {
_buffer.SetVolume(attenuation); _buffer.SetVolume(attenuation);
} }
} }
} }
public void Start(IntPtr window) public void Start(IntPtr window)
{ {
_window = window; _window = window;
_thread.Start(); _thread.Start();
} }
public void Stop() public void Stop()
{ {
_stopEvent.Set(); _stopEvent.Set();
_thread.Join(); _thread.Join();
} }
[SecurityCritical] [SecurityCritical]
private void Initialize() private void Initialize()
{ {
int hresult = NativeMethods.DirectSoundCreate(IntPtr.Zero, out _device, IntPtr.Zero); int hresult = NativeMethods.DirectSoundCreate(IntPtr.Zero, out _device, IntPtr.Zero);
if (hresult < 0) if (hresult < 0)
{ {
Marshal.ThrowExceptionForHR(hresult); Marshal.ThrowExceptionForHR(hresult);
} }
_device.SetCooperativeLevel(_window, CooperativeLevel.Normal); _device.SetCooperativeLevel(_window, CooperativeLevel.Normal);
GCHandleHelpers.Pin(new WaveFormat(_sampleRate, _sampleChannels, _sampleBits), waveFormat => GCHandleHelpers.Pin(new WaveFormat(_sampleRate, _sampleChannels, _sampleBits), waveFormat =>
{ {
var description = new BufferDescription(BufferCapabilities.CtrlPositionNotify | BufferCapabilities.CtrlVolume, BlockCount * _sampleSize, waveFormat); var description = new BufferDescription(BufferCapabilities.CtrlPositionNotify | BufferCapabilities.CtrlVolume, BlockCount * _sampleSize, waveFormat);
_device.CreateSoundBuffer(description, out _buffer, IntPtr.Zero); _device.CreateSoundBuffer(description, out _buffer, IntPtr.Zero);
}); });
ClearBuffer(); ClearBuffer();
var positionEvents = new BufferPositionNotify[BlockCount] var positionEvents = new BufferPositionNotify[BlockCount]
{ {
new BufferPositionNotify(0 * _sampleSize, _position1Event), new BufferPositionNotify(1 * _sampleSize, _position2Event) new BufferPositionNotify(0 * _sampleSize, _position1Event), new BufferPositionNotify(1 * _sampleSize, _position2Event)
}; };
((IDirectSoundNotify)_buffer).SetNotificationPositions(positionEvents.Length, positionEvents); ((IDirectSoundNotify)_buffer).SetNotificationPositions(positionEvents.Length, positionEvents);
_buffer.Play(0, 0, BufferPlay.Looping); _buffer.Play(0, 0, BufferPlay.Looping);
} }
[SecurityCritical] [SecurityCritical]
private void ClearBuffer() private void ClearBuffer()
{ {
UpdateBuffer(0, 0, BufferLock.EntireBuffer, (buffer, bufferSize) => MarshalHelpers.ZeroMemory(buffer, bufferSize)); UpdateBuffer(0, 0, BufferLock.EntireBuffer, (buffer, bufferSize) => MarshalHelpers.ZeroMemory(buffer, bufferSize));
} }
private void RestoreBuffer() private void RestoreBuffer()
{ {
BufferStatus status; BufferStatus status;
_buffer.GetStatus(out status); _buffer.GetStatus(out status);
if ((status & BufferStatus.BufferLost) != 0) if ((status & BufferStatus.BufferLost) != 0)
{ {
_buffer.Restore(); _buffer.Restore();
} }
} }
private void UpdateBuffer(int offset, int count, BufferLock flags, Action<IntPtr, int> updater) private void UpdateBuffer(int offset, int count, BufferLock flags, Action<IntPtr, int> updater)
{ {
RestoreBuffer(); RestoreBuffer();
IntPtr buffer1, buffer2; IntPtr buffer1, buffer2;
int buffer1Size, buffer2Size; int buffer1Size, buffer2Size;
_buffer.Lock(offset, count, out buffer1, out buffer1Size, out buffer2, out buffer2Size, flags); _buffer.Lock(offset, count, out buffer1, out buffer1Size, out buffer2, out buffer2Size, flags);
try try
{ {
if (buffer1 != IntPtr.Zero) if (buffer1 != IntPtr.Zero)
{ {
updater(buffer1, buffer1Size); updater(buffer1, buffer1Size);
} }
if (buffer2 != IntPtr.Zero) if (buffer2 != IntPtr.Zero)
{ {
updater(buffer2, buffer2Size); updater(buffer2, buffer2Size);
} }
} }
finally finally
{ {
_buffer.Unlock(buffer1, buffer1Size, buffer2, buffer2Size); _buffer.Unlock(buffer1, buffer1Size, buffer2, buffer2Size);
} }
} }
private void Uninitialize() private void Uninitialize()
{ {
lock (_bufferLock) lock (_bufferLock)
{ {
if (_buffer != null) if (_buffer != null)
{ {
_buffer.Stop(); _buffer.Stop();
Marshal.ReleaseComObject(_buffer); Marshal.ReleaseComObject(_buffer);
_buffer = null; _buffer = null;
} }
} }
if (_device != null) if (_device != null)
{ {
Marshal.ReleaseComObject(_device); Marshal.ReleaseComObject(_device);
_device = null; _device = null;
} }
} }
[SecurityCritical] [SecurityCritical]
private void Run() // com mta thread private void Run() // com mta thread
{ {
Initialize(); Initialize();
var eventHandles = new EventWaitHandle[] { _position1Event, _position2Event, _stopEvent }; var eventHandles = new EventWaitHandle[] { _position1Event, _position2Event, _stopEvent };
int index = WaitHandle.WaitAny(eventHandles); int index = WaitHandle.WaitAny(eventHandles);
while (index < BlockCount) while (index < BlockCount)
{ {
UpdateBuffer(((index + 1) % BlockCount) * _sampleSize, _sampleSize, BufferLock.None, _updater); // update next block in circular buffer UpdateBuffer(((index + 1) % BlockCount) * _sampleSize, _sampleSize, BufferLock.None, _updater); // update next block in circular buffer
index = WaitHandle.WaitAny(eventHandles); index = WaitHandle.WaitAny(eventHandles);
} }
Uninitialize(); Uninitialize();
} }
private const int BlockCount = 2; private const int BlockCount = 2;
private int _sampleRate; private int _sampleRate;
private int _sampleChannels; private int _sampleChannels;
private int _sampleBits; private int _sampleBits;
private int _sampleSize; private int _sampleSize;
private Thread _thread; private Thread _thread;
private IntPtr _window; private IntPtr _window;
private IDirectSound _device; private IDirectSound _device;
private IDirectSoundBuffer _buffer; private IDirectSoundBuffer _buffer;
private object _bufferLock = new object(); private object _bufferLock = new object();
private Action<IntPtr, int> _updater; private Action<IntPtr, int> _updater;
private AutoResetEvent _position1Event = new AutoResetEvent(false); private AutoResetEvent _position1Event = new AutoResetEvent(false);
private AutoResetEvent _position2Event = new AutoResetEvent(false); private AutoResetEvent _position2Event = new AutoResetEvent(false);
private ManualResetEvent _stopEvent = new ManualResetEvent(false); private ManualResetEvent _stopEvent = new ManualResetEvent(false);
} }
} }

View File

@ -1,110 +1,110 @@
using System; using System;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security; using System.Security;
using System.Threading; using System.Threading;
namespace Jellyfish.Library namespace Jellyfish.Library
{ {
public sealed partial class DirectSound public sealed partial class DirectSound
{ {
[Flags] [Flags]
private enum BufferCapabilities { PrimaryBuffer = 0x00000001, CtrlVolume = 0x00000080, CtrlPositionNotify = 0x00000100, StickyFocus = 0x00004000, GlobalFocus = 0x00008000 } private enum BufferCapabilities { PrimaryBuffer = 0x00000001, CtrlVolume = 0x00000080, CtrlPositionNotify = 0x00000100, StickyFocus = 0x00004000, GlobalFocus = 0x00008000 }
[Flags] [Flags]
private enum BufferLock { None = 0x00000000, FromWriteCursor = 0x00000001, EntireBuffer = 0x00000002 } private enum BufferLock { None = 0x00000000, FromWriteCursor = 0x00000001, EntireBuffer = 0x00000002 }
[Flags] [Flags]
private enum BufferPlay { Looping = 0x00000001 } private enum BufferPlay { Looping = 0x00000001 }
[Flags] [Flags]
private enum BufferStatus { Playing = 0x00000001, BufferLost = 0x00000002, Looping = 0x00000004, Terminated = 0x00000020 } private enum BufferStatus { Playing = 0x00000001, BufferLost = 0x00000002, Looping = 0x00000004, Terminated = 0x00000020 }
private enum BufferVolume { Min = -10000, Max = 0 } private enum BufferVolume { Min = -10000, Max = 0 }
private enum CooperativeLevel { Normal = 1, Priority = 2 } private enum CooperativeLevel { Normal = 1, Priority = 2 }
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
private sealed class BufferDescription private sealed class BufferDescription
{ {
public BufferDescription(BufferCapabilities capabilities, int size, IntPtr format) public BufferDescription(BufferCapabilities capabilities, int size, IntPtr format)
{ {
dwSize = Marshal.SizeOf(typeof(BufferDescription)); dwSize = Marshal.SizeOf(typeof(BufferDescription));
dwFlags = capabilities; dwFlags = capabilities;
dwBufferBytes = size; dwBufferBytes = size;
lpwfxFormat = format; lpwfxFormat = format;
} }
public int dwSize; public int dwSize;
public BufferCapabilities dwFlags; public BufferCapabilities dwFlags;
public int dwBufferBytes; public int dwBufferBytes;
public int dwReserved; public int dwReserved;
public IntPtr lpwfxFormat; public IntPtr lpwfxFormat;
public Guid guid3DAlgorithm; public Guid guid3DAlgorithm;
} }
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
private struct BufferPositionNotify private struct BufferPositionNotify
{ {
[SuppressMessage("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods", MessageId = "System.Runtime.InteropServices.SafeHandle.DangerousGetHandle")] [SuppressMessage("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods", MessageId = "System.Runtime.InteropServices.SafeHandle.DangerousGetHandle")]
public BufferPositionNotify(int offset, EventWaitHandle notifyEvent) public BufferPositionNotify(int offset, EventWaitHandle notifyEvent)
{ {
dwOffset = offset; dwOffset = offset;
hEventNotify = notifyEvent.SafeWaitHandle.DangerousGetHandle(); hEventNotify = notifyEvent.SafeWaitHandle.DangerousGetHandle();
} }
public int dwOffset; public int dwOffset;
public IntPtr hEventNotify; public IntPtr hEventNotify;
} }
[ComImport, Guid("279AFA83-4981-11CE-A521-0020AF0BE560"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [ComImport, Guid("279AFA83-4981-11CE-A521-0020AF0BE560"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
private interface IDirectSound private interface IDirectSound
{ {
void CreateSoundBuffer(BufferDescription pcDSBufferDesc, [MarshalAs(UnmanagedType.Interface)] out IDirectSoundBuffer pDSBuffer, IntPtr pUnkOuter); void CreateSoundBuffer(BufferDescription pcDSBufferDesc, [MarshalAs(UnmanagedType.Interface)] out IDirectSoundBuffer pDSBuffer, IntPtr pUnkOuter);
void GetCaps(IntPtr pDSCaps); void GetCaps(IntPtr pDSCaps);
void DuplicateSoundBuffer([MarshalAs(UnmanagedType.Interface)] IDirectSoundBuffer pDSBufferOriginal, [MarshalAs(UnmanagedType.Interface)] out IDirectSoundBuffer pDSBufferDuplicate); void DuplicateSoundBuffer([MarshalAs(UnmanagedType.Interface)] IDirectSoundBuffer pDSBufferOriginal, [MarshalAs(UnmanagedType.Interface)] out IDirectSoundBuffer pDSBufferDuplicate);
void SetCooperativeLevel(IntPtr hwnd, CooperativeLevel dwLevel); void SetCooperativeLevel(IntPtr hwnd, CooperativeLevel dwLevel);
void Compact(); void Compact();
void GetSpeakerConfig(out int dwSpeakerConfig); void GetSpeakerConfig(out int dwSpeakerConfig);
void SetSpeakerConfig(int dwSpeakerConfig); void SetSpeakerConfig(int dwSpeakerConfig);
void Initialize([MarshalAs(UnmanagedType.LPStruct)] Guid pcGuidDevice); void Initialize([MarshalAs(UnmanagedType.LPStruct)] Guid pcGuidDevice);
} }
[ComImport, Guid("279AFA85-4981-11CE-A521-0020AF0BE560"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [ComImport, Guid("279AFA85-4981-11CE-A521-0020AF0BE560"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
private interface IDirectSoundBuffer private interface IDirectSoundBuffer
{ {
void GetCaps(IntPtr pDSBufferCaps); void GetCaps(IntPtr pDSBufferCaps);
void GetCurrentPosition(out int dwCurrentPlayCursor, out int dwCurrentWriteCursor); void GetCurrentPosition(out int dwCurrentPlayCursor, out int dwCurrentWriteCursor);
void GetFormat(IntPtr pwfxFormat, int dwSizeAllocated, out int dwSizeWritten); void GetFormat(IntPtr pwfxFormat, int dwSizeAllocated, out int dwSizeWritten);
void GetVolume(out int lVolume); void GetVolume(out int lVolume);
void GetPan(out int lPan); void GetPan(out int lPan);
void GetFrequency(out int dwFrequency); void GetFrequency(out int dwFrequency);
void GetStatus(out BufferStatus dwStatus); void GetStatus(out BufferStatus dwStatus);
void Initialize([MarshalAs(UnmanagedType.Interface)] IDirectSound pDirectSound, BufferDescription pcDSBufferDesc); void Initialize([MarshalAs(UnmanagedType.Interface)] IDirectSound pDirectSound, BufferDescription pcDSBufferDesc);
void Lock(int dwOffset, int dwBytes, out IntPtr pvAudioPtr1, out int dwAudioBytes1, out IntPtr pvAudioPtr2, out int dwAudioBytes2, BufferLock dwFlags); void Lock(int dwOffset, int dwBytes, out IntPtr pvAudioPtr1, out int dwAudioBytes1, out IntPtr pvAudioPtr2, out int dwAudioBytes2, BufferLock dwFlags);
void Play(int dwReserved1, int dwPriority, BufferPlay dwFlags); void Play(int dwReserved1, int dwPriority, BufferPlay dwFlags);
void SetCurrentPosition(int dwNewPosition); void SetCurrentPosition(int dwNewPosition);
void SetFormat(WaveFormat pcfxFormat); void SetFormat(WaveFormat pcfxFormat);
void SetVolume(int lVolume); void SetVolume(int lVolume);
void SetPan(int lPan); void SetPan(int lPan);
void SetFrequency(int dwFrequency); void SetFrequency(int dwFrequency);
void Stop(); void Stop();
void Unlock(IntPtr pvAudioPtr1, int dwAudioBytes1, IntPtr pvAudioPtr2, int dwAudioBytes2); void Unlock(IntPtr pvAudioPtr1, int dwAudioBytes1, IntPtr pvAudioPtr2, int dwAudioBytes2);
void Restore(); void Restore();
} }
[ComImport, Guid("B0210783-89CD-11D0-AF08-00A0C925CD16"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [ComImport, Guid("B0210783-89CD-11D0-AF08-00A0C925CD16"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
private interface IDirectSoundNotify private interface IDirectSoundNotify
{ {
void SetNotificationPositions(int dwPositionNotifies, [MarshalAs(UnmanagedType.LPArray)] BufferPositionNotify[] pcPositionNotifies); void SetNotificationPositions(int dwPositionNotifies, [MarshalAs(UnmanagedType.LPArray)] BufferPositionNotify[] pcPositionNotifies);
} }
[SecurityCritical] [SecurityCritical]
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
private static class NativeMethods private static class NativeMethods
{ {
[DllImport("dsound.dll")] [DllImport("dsound.dll")]
public static extern int DirectSoundCreate(IntPtr pcGuidDevice, [MarshalAs(UnmanagedType.Interface)] out IDirectSound pDS, IntPtr pUnkOuter); public static extern int DirectSoundCreate(IntPtr pcGuidDevice, [MarshalAs(UnmanagedType.Interface)] out IDirectSound pDS, IntPtr pUnkOuter);
} }
} }
} }

View File

@ -1,52 +1,52 @@
using System; using System;
using System.Windows.Threading; using System.Windows.Threading;
namespace Jellyfish.Library namespace Jellyfish.Library
{ {
public static class DispatcherExtensions public static class DispatcherExtensions
{ {
public static void CheckBeginInvoke(this Dispatcher dispatcher, Action action) public static void CheckBeginInvoke(this Dispatcher dispatcher, Action action)
{ {
if (dispatcher == null) if (dispatcher == null)
{ {
throw new ArgumentNullException("dispatcher"); throw new ArgumentNullException("dispatcher");
} }
if (action == null) if (action == null)
{ {
throw new ArgumentNullException("action"); throw new ArgumentNullException("action");
} }
if (dispatcher.CheckAccess()) if (dispatcher.CheckAccess())
{ {
action(); action();
} }
else else
{ {
dispatcher.BeginInvoke(action); dispatcher.BeginInvoke(action);
} }
} }
#if WINDOWS #if WINDOWS
public static void CheckInvoke(this Dispatcher dispatcher, Action action) public static void CheckInvoke(this Dispatcher dispatcher, Action action)
{ {
if (dispatcher == null) if (dispatcher == null)
{ {
throw new ArgumentNullException("dispatcher"); throw new ArgumentNullException("dispatcher");
} }
if (action == null) if (action == null)
{ {
throw new ArgumentNullException("action"); throw new ArgumentNullException("action");
} }
if (dispatcher.CheckAccess()) if (dispatcher.CheckAccess())
{ {
action(); action();
} }
else else
{ {
dispatcher.Invoke(action); dispatcher.Invoke(action);
} }
} }
#endif #endif
} }
} }

View File

@ -1,32 +1,32 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security; using System.Security;
namespace Jellyfish.Library namespace Jellyfish.Library
{ {
public static class GCHandleHelpers public static class GCHandleHelpers
{ {
[SecurityCritical] [SecurityCritical]
public static void Pin(object value, Action<IntPtr> action) public static void Pin(object value, Action<IntPtr> action)
{ {
if (action == null) if (action == null)
{ {
throw new ArgumentNullException("action"); throw new ArgumentNullException("action");
} }
var gcHandle = new GCHandle(); var gcHandle = new GCHandle();
try try
{ {
gcHandle = GCHandle.Alloc(value, GCHandleType.Pinned); gcHandle = GCHandle.Alloc(value, GCHandleType.Pinned);
action(gcHandle.AddrOfPinnedObject()); action(gcHandle.AddrOfPinnedObject());
} }
finally finally
{ {
if (gcHandle.IsAllocated) if (gcHandle.IsAllocated)
{ {
gcHandle.Free(); gcHandle.Free();
} }
} }
} }
} }
} }

View File

@ -1,266 +1,266 @@
using System; using System;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security; using System.Security;
using System.Security.AccessControl; using System.Security.AccessControl;
using System.Security.Principal; using System.Security.Principal;
namespace Jellyfish.Library namespace Jellyfish.Library
{ {
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public sealed class SecurityAttributes public sealed class SecurityAttributes
{ {
public SecurityAttributes() public SecurityAttributes()
{ {
_length = Marshal.SizeOf(typeof(SecurityAttributes)); _length = Marshal.SizeOf(typeof(SecurityAttributes));
} }
public int Length { get { return _length; } } public int Length { get { return _length; } }
public IntPtr SecurityDescriptor { get { return _securityDescriptor; } set { _securityDescriptor = value; } } public IntPtr SecurityDescriptor { get { return _securityDescriptor; } set { _securityDescriptor = value; } }
public bool InheritHandle { get { return _inheritHandle; } set { _inheritHandle = value; } } public bool InheritHandle { get { return _inheritHandle; } set { _inheritHandle = value; } }
private int _length; private int _length;
private IntPtr _securityDescriptor; private IntPtr _securityDescriptor;
private bool _inheritHandle; private bool _inheritHandle;
} }
public sealed class GeneralAccessRule : AccessRule public sealed class GeneralAccessRule : AccessRule
{ {
public GeneralAccessRule(IdentityReference identity, int rights, AccessControlType type) : public GeneralAccessRule(IdentityReference identity, int rights, AccessControlType type) :
base(identity, rights, false, InheritanceFlags.None, PropagationFlags.None, type) base(identity, rights, false, InheritanceFlags.None, PropagationFlags.None, type)
{ {
} }
public GeneralAccessRule(IdentityReference identity, int rights, InheritanceFlags inheritance, PropagationFlags propagation, AccessControlType type) : public GeneralAccessRule(IdentityReference identity, int rights, InheritanceFlags inheritance, PropagationFlags propagation, AccessControlType type) :
base(identity, rights, false, inheritance, propagation, type) base(identity, rights, false, inheritance, propagation, type)
{ {
} }
public GeneralAccessRule(IdentityReference identity, int rights, bool isInherited, InheritanceFlags inheritance, PropagationFlags propagation, AccessControlType type) : public GeneralAccessRule(IdentityReference identity, int rights, bool isInherited, InheritanceFlags inheritance, PropagationFlags propagation, AccessControlType type) :
base(identity, rights, isInherited, inheritance, propagation, type) base(identity, rights, isInherited, inheritance, propagation, type)
{ {
} }
public int AccessRights { get { return AccessMask; } } public int AccessRights { get { return AccessMask; } }
} }
public sealed class GeneralAuditRule : AuditRule public sealed class GeneralAuditRule : AuditRule
{ {
public GeneralAuditRule(IdentityReference identity, int rights, AuditFlags audit) : public GeneralAuditRule(IdentityReference identity, int rights, AuditFlags audit) :
base(identity, rights, false, InheritanceFlags.None, PropagationFlags.None, audit) base(identity, rights, false, InheritanceFlags.None, PropagationFlags.None, audit)
{ {
} }
public GeneralAuditRule(IdentityReference identity, int rights, InheritanceFlags inheritance, PropagationFlags propagation, AuditFlags audit) : public GeneralAuditRule(IdentityReference identity, int rights, InheritanceFlags inheritance, PropagationFlags propagation, AuditFlags audit) :
base(identity, rights, false, inheritance, propagation, audit) base(identity, rights, false, inheritance, propagation, audit)
{ {
} }
public GeneralAuditRule(IdentityReference identity, int rights, bool isInherited, InheritanceFlags inheritance, PropagationFlags propagation, AuditFlags audit) : public GeneralAuditRule(IdentityReference identity, int rights, bool isInherited, InheritanceFlags inheritance, PropagationFlags propagation, AuditFlags audit) :
base(identity, rights, isInherited, inheritance, propagation, audit) base(identity, rights, isInherited, inheritance, propagation, audit)
{ {
} }
public int AccessRights { get { return AccessMask; } } public int AccessRights { get { return AccessMask; } }
} }
public sealed class GeneralSecurity : NativeObjectSecurity public sealed class GeneralSecurity : NativeObjectSecurity
{ {
public GeneralSecurity(bool isContainer, ResourceType resourceType) : public GeneralSecurity(bool isContainer, ResourceType resourceType) :
base(isContainer, resourceType) base(isContainer, resourceType)
{ {
} }
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")] [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")] [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)
{ {
} }
public override AccessRule AccessRuleFactory(IdentityReference identityReference, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AccessControlType type) public override AccessRule AccessRuleFactory(IdentityReference identityReference, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AccessControlType type)
{ {
return new GeneralAccessRule(identityReference, accessMask, isInherited, inheritanceFlags, propagationFlags, type); return new GeneralAccessRule(identityReference, accessMask, isInherited, inheritanceFlags, propagationFlags, type);
} }
public override AuditRule AuditRuleFactory(IdentityReference identityReference, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AuditFlags flags) public override AuditRule AuditRuleFactory(IdentityReference identityReference, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AuditFlags flags)
{ {
return new GeneralAuditRule(identityReference, accessMask, isInherited, inheritanceFlags, propagationFlags, flags); return new GeneralAuditRule(identityReference, accessMask, isInherited, inheritanceFlags, propagationFlags, flags);
} }
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
public void AddAccessRule(GeneralAccessRule rule) public void AddAccessRule(GeneralAccessRule rule)
{ {
base.AddAccessRule(rule); base.AddAccessRule(rule);
} }
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
public void AddAuditRule(GeneralAuditRule rule) public void AddAuditRule(GeneralAuditRule rule)
{ {
base.AddAuditRule(rule); base.AddAuditRule(rule);
} }
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")] [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")] [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)
{ {
if (action == null) if (action == null)
{ {
throw new ArgumentNullException("action"); throw new ArgumentNullException("action");
} }
if (security != null) if (security != null)
{ {
GCHandleHelpers.Pin(security.GetSecurityDescriptorBinaryForm(), securityDescriptor => GCHandleHelpers.Pin(security.GetSecurityDescriptorBinaryForm(), securityDescriptor =>
{ {
action(new SecurityAttributes() { SecurityDescriptor = securityDescriptor, InheritHandle = inheritable }); action(new SecurityAttributes() { SecurityDescriptor = securityDescriptor, InheritHandle = inheritable });
}); });
} }
else if (inheritable) else if (inheritable)
{ {
action(new SecurityAttributes() { InheritHandle = inheritable }); action(new SecurityAttributes() { InheritHandle = inheritable });
} }
else else
{ {
action(null); action(null);
} }
} }
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
public bool RemoveAccessRule(GeneralAccessRule rule) public bool RemoveAccessRule(GeneralAccessRule rule)
{ {
return base.RemoveAccessRule(rule); return base.RemoveAccessRule(rule);
} }
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
public void RemoveAccessRuleAll(GeneralAccessRule rule) public void RemoveAccessRuleAll(GeneralAccessRule rule)
{ {
base.RemoveAccessRuleAll(rule); base.RemoveAccessRuleAll(rule);
} }
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
public void RemoveAccessRuleSpecific(GeneralAccessRule rule) public void RemoveAccessRuleSpecific(GeneralAccessRule rule)
{ {
base.RemoveAccessRuleSpecific(rule); base.RemoveAccessRuleSpecific(rule);
} }
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
public bool RemoveAuditRule(GeneralAuditRule rule) public bool RemoveAuditRule(GeneralAuditRule rule)
{ {
return base.RemoveAuditRule(rule); return base.RemoveAuditRule(rule);
} }
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
public void RemoveAuditRuleAll(GeneralAuditRule rule) public void RemoveAuditRuleAll(GeneralAuditRule rule)
{ {
base.RemoveAuditRuleAll(rule); base.RemoveAuditRuleAll(rule);
} }
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
public void RemoveAuditRuleSpecific(GeneralAuditRule rule) public void RemoveAuditRuleSpecific(GeneralAuditRule rule)
{ {
base.RemoveAuditRuleSpecific(rule); base.RemoveAuditRuleSpecific(rule);
} }
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
public void ResetAccessRule(GeneralAccessRule rule) public void ResetAccessRule(GeneralAccessRule rule)
{ {
base.ResetAccessRule(rule); base.ResetAccessRule(rule);
} }
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
public void SetAccessRule(GeneralAccessRule rule) public void SetAccessRule(GeneralAccessRule rule)
{ {
base.SetAccessRule(rule); base.SetAccessRule(rule);
} }
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
public void SetAuditRule(GeneralAuditRule rule) public void SetAuditRule(GeneralAuditRule rule)
{ {
base.SetAuditRule(rule); base.SetAuditRule(rule);
} }
public void Persist(SafeHandle handle) public void Persist(SafeHandle handle)
{ {
WriteLock(); WriteLock();
try try
{ {
var sectionsModified = GetAccessControlSectionsModified(); var sectionsModified = GetAccessControlSectionsModified();
if (sectionsModified != AccessControlSections.None) if (sectionsModified != AccessControlSections.None)
{ {
Persist(handle, sectionsModified); Persist(handle, sectionsModified);
ResetAccessControlSectionsModified(); ResetAccessControlSectionsModified();
} }
} }
finally finally
{ {
WriteUnlock(); WriteUnlock();
} }
} }
public void Persist(string name) public void Persist(string name)
{ {
WriteLock(); WriteLock();
try try
{ {
var sectionsModified = GetAccessControlSectionsModified(); var sectionsModified = GetAccessControlSectionsModified();
if (sectionsModified != AccessControlSections.None) if (sectionsModified != AccessControlSections.None)
{ {
Persist(name, sectionsModified); Persist(name, sectionsModified);
ResetAccessControlSectionsModified(); ResetAccessControlSectionsModified();
} }
} }
finally finally
{ {
WriteUnlock(); WriteUnlock();
} }
} }
private AccessControlSections GetAccessControlSectionsModified() private AccessControlSections GetAccessControlSectionsModified()
{ {
var sectionsModified = AccessControlSections.None; var sectionsModified = AccessControlSections.None;
if (AccessRulesModified) if (AccessRulesModified)
{ {
sectionsModified = AccessControlSections.Access; sectionsModified = AccessControlSections.Access;
} }
if (AuditRulesModified) if (AuditRulesModified)
{ {
sectionsModified |= AccessControlSections.Audit; sectionsModified |= AccessControlSections.Audit;
} }
if (OwnerModified) if (OwnerModified)
{ {
sectionsModified |= AccessControlSections.Owner; sectionsModified |= AccessControlSections.Owner;
} }
if (GroupModified) if (GroupModified)
{ {
sectionsModified |= AccessControlSections.Group; sectionsModified |= AccessControlSections.Group;
} }
return sectionsModified; return sectionsModified;
} }
private void ResetAccessControlSectionsModified() private void ResetAccessControlSectionsModified()
{ {
AccessRulesModified = false; AccessRulesModified = false;
AuditRulesModified = false; AuditRulesModified = false;
OwnerModified = false; OwnerModified = false;
GroupModified = false; GroupModified = false;
} }
public override Type AccessRightType { get { return typeof(int); } } public override Type AccessRightType { get { return typeof(int); } }
public override Type AccessRuleType { get { return typeof(GeneralAccessRule); } } public override Type AccessRuleType { get { return typeof(GeneralAccessRule); } }
public override Type AuditRuleType { get { return typeof(GeneralAuditRule); } } public override Type AuditRuleType { get { return typeof(GeneralAuditRule); } }
} }
} }

View File

@ -1,4 +1,4 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("Microsoft.Design", "CA2210:AssembliesShouldHaveValidStrongNames")] [assembly: SuppressMessage("Microsoft.Design", "CA2210:AssembliesShouldHaveValidStrongNames")]
[assembly: SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields", Scope = "member", Target = "Jellyfish.Library.FrameRateCounter.#frameRateControl")] [assembly: SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields", Scope = "member", Target = "Jellyfish.Library.FrameRateCounter.#frameRateControl")]

View File

@ -1,25 +1,25 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Jellyfish.Library namespace Jellyfish.Library
{ {
public static class IEnumerableExtensions public static class IEnumerableExtensions
{ {
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action) public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
{ {
if (source == null) if (source == null)
{ {
throw new ArgumentNullException("source"); throw new ArgumentNullException("source");
} }
if (action == null) if (action == null)
{ {
throw new ArgumentNullException("action"); throw new ArgumentNullException("action");
} }
foreach (T item in source) foreach (T item in source)
{ {
action(item); action(item);
} }
} }
} }
} }

View File

@ -1,37 +1,37 @@
using System; using System;
using System.Threading; using System.Threading;
namespace Jellyfish.Library namespace Jellyfish.Library
{ {
public sealed class Lazy<T> where T : class public sealed class Lazy<T> where T : class
{ {
public Lazy(Func<T> initializer) public Lazy(Func<T> initializer)
{ {
_initializer = initializer; _initializer = initializer;
} }
public T Value public T Value
{ {
get get
{ {
if (_value == null) if (_value == null)
{ {
T value = _initializer(); T value = _initializer();
if (Interlocked.CompareExchange(ref _value, value, null) != null) if (Interlocked.CompareExchange(ref _value, value, null) != null)
{ {
var disposable = value as IDisposable; // dispose preempted instance var disposable = value as IDisposable; // dispose preempted instance
if (disposable != null) if (disposable != null)
{ {
disposable.Dispose(); disposable.Dispose();
} }
} }
} }
return _value; return _value;
} }
} }
private Func<T> _initializer; private Func<T> _initializer;
private T _value; private T _value;
} }
} }

View File

@ -1,35 +1,35 @@
using System; using System;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security; using System.Security;
namespace Jellyfish.Library namespace Jellyfish.Library
{ {
public static class MarshalHelpers public static class MarshalHelpers
{ {
[SecurityCritical] [SecurityCritical]
public static void FillMemory(IntPtr buffer, int bufferSize, byte value) public static void FillMemory(IntPtr buffer, int bufferSize, byte value)
{ {
NativeMethods.FillMemory(buffer, (IntPtr)bufferSize, value); NativeMethods.FillMemory(buffer, (IntPtr)bufferSize, value);
} }
[SecurityCritical] [SecurityCritical]
public static void ZeroMemory(IntPtr buffer, int bufferSize) public static void ZeroMemory(IntPtr buffer, int bufferSize)
{ {
NativeMethods.ZeroMemory(buffer, (IntPtr)bufferSize); NativeMethods.ZeroMemory(buffer, (IntPtr)bufferSize);
} }
[SecurityCritical] [SecurityCritical]
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
private static class NativeMethods private static class NativeMethods
{ {
[SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage")] [SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage")]
[DllImport("kernel32.dll", SetLastError = true)] [DllImport("kernel32.dll", SetLastError = true)]
public static extern void FillMemory(IntPtr destination, IntPtr length, byte fill); public static extern void FillMemory(IntPtr destination, IntPtr length, byte fill);
[SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage")] [SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage")]
[DllImport("kernel32.dll", SetLastError = true)] [DllImport("kernel32.dll", SetLastError = true)]
public static extern void ZeroMemory(IntPtr destination, IntPtr length); public static extern void ZeroMemory(IntPtr destination, IntPtr length);
} }
} }
} }

View File

@ -1,20 +1,20 @@
namespace Jellyfish.Library namespace Jellyfish.Library
{ {
public static class MathHelpers public static class MathHelpers
{ {
public static int Clamp(int value, int min, int max) public static int Clamp(int value, int min, int max)
{ {
return (value < min) ? min : (value > max) ? max : value; return (value < min) ? min : (value > max) ? max : value;
} }
public static double Clamp(double value, double min, double max) public static double Clamp(double value, double min, double max)
{ {
return (value < min) ? min : (value > max) ? max : value; return (value < min) ? min : (value > max) ? max : value;
} }
public static int ClampByte(int value) public static int ClampByte(int value)
{ {
return Clamp(value, byte.MinValue, byte.MaxValue); return Clamp(value, byte.MinValue, byte.MaxValue);
} }
} }
} }

View File

@ -1,149 +1,149 @@
using System; using System;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Runtime.ConstrainedExecution; using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security; using System.Security;
using Microsoft.Win32.SafeHandles; using Microsoft.Win32.SafeHandles;
namespace Jellyfish.Library namespace Jellyfish.Library
{ {
[SecurityCritical] [SecurityCritical]
public abstract class SafeAllocHandle : SafeHandleZeroOrMinusOneIsInvalid public abstract class SafeAllocHandle : SafeHandleZeroOrMinusOneIsInvalid
{ {
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
protected SafeAllocHandle(bool ownsHandle) : protected SafeAllocHandle(bool ownsHandle) :
base(ownsHandle) base(ownsHandle)
{ {
} }
} }
[SecurityCritical] [SecurityCritical]
public sealed class SafeGlobalAllocHandle : SafeAllocHandle public sealed class SafeGlobalAllocHandle : SafeAllocHandle
{ {
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
public SafeGlobalAllocHandle() : public SafeGlobalAllocHandle() :
base(ownsHandle: true) base(ownsHandle: true)
{ {
} }
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
public SafeGlobalAllocHandle(IntPtr existingHandle, bool ownsHandle) : public SafeGlobalAllocHandle(IntPtr existingHandle, bool ownsHandle) :
base(ownsHandle) base(ownsHandle)
{ {
SetHandle(existingHandle); SetHandle(existingHandle);
} }
[SecurityCritical] [SecurityCritical]
public static SafeGlobalAllocHandle Allocate(byte[] value) public static SafeGlobalAllocHandle Allocate(byte[] value)
{ {
if (value == null) if (value == null)
{ {
throw new ArgumentNullException("value"); throw new ArgumentNullException("value");
} }
var alloc = Allocate(value.Length); var alloc = Allocate(value.Length);
Marshal.Copy(value, 0, alloc.DangerousGetHandle(), value.Length); Marshal.Copy(value, 0, alloc.DangerousGetHandle(), value.Length);
return alloc; return alloc;
} }
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")] [SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
[SuppressMessage("Microsoft.Naming", "CA1726:UsePreferredTerms", MessageId = "flags")] [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)
{ {
var alloc = NativeMethods.GlobalAlloc(flags, (IntPtr)size); var alloc = NativeMethods.GlobalAlloc(flags, (IntPtr)size);
if (alloc.IsInvalid) if (alloc.IsInvalid)
{ {
Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
} }
return alloc; return alloc;
} }
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
[SecurityCritical] [SecurityCritical]
protected override bool ReleaseHandle() protected override bool ReleaseHandle()
{ {
return (NativeMethods.GlobalFree(handle) == IntPtr.Zero); return (NativeMethods.GlobalFree(handle) == IntPtr.Zero);
} }
[SecurityCritical] [SecurityCritical]
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
private static class NativeMethods private static class NativeMethods
{ {
[SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage")] [SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage")]
[DllImport("kernel32.dll", SetLastError = true)] [DllImport("kernel32.dll", SetLastError = true)]
public static extern SafeGlobalAllocHandle GlobalAlloc(uint dwFlags, IntPtr sizetBytes); public static extern SafeGlobalAllocHandle GlobalAlloc(uint dwFlags, IntPtr sizetBytes);
[DllImport("kernel32.dll", SetLastError = true)] [DllImport("kernel32.dll", SetLastError = true)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
public static extern IntPtr GlobalFree(IntPtr hMem); public static extern IntPtr GlobalFree(IntPtr hMem);
} }
} }
[SecurityCritical] [SecurityCritical]
public sealed class SafeLocalAllocHandle : SafeAllocHandle public sealed class SafeLocalAllocHandle : SafeAllocHandle
{ {
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
public SafeLocalAllocHandle() : public SafeLocalAllocHandle() :
base(ownsHandle: true) base(ownsHandle: true)
{ {
} }
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
public SafeLocalAllocHandle(IntPtr existingHandle, bool ownsHandle) : public SafeLocalAllocHandle(IntPtr existingHandle, bool ownsHandle) :
base(ownsHandle) base(ownsHandle)
{ {
SetHandle(existingHandle); SetHandle(existingHandle);
} }
[SecurityCritical] [SecurityCritical]
public static SafeLocalAllocHandle Allocate(byte[] value) public static SafeLocalAllocHandle Allocate(byte[] value)
{ {
if (value == null) if (value == null)
{ {
throw new ArgumentNullException("value"); throw new ArgumentNullException("value");
} }
var alloc = Allocate(value.Length); var alloc = Allocate(value.Length);
Marshal.Copy(value, 0, alloc.DangerousGetHandle(), value.Length); Marshal.Copy(value, 0, alloc.DangerousGetHandle(), value.Length);
return alloc; return alloc;
} }
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")] [SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
[SuppressMessage("Microsoft.Naming", "CA1726:UsePreferredTerms", MessageId = "flags")] [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)
{ {
var alloc = NativeMethods.LocalAlloc(flags, (IntPtr)size); var alloc = NativeMethods.LocalAlloc(flags, (IntPtr)size);
if (alloc.IsInvalid) if (alloc.IsInvalid)
{ {
Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
} }
return alloc; return alloc;
} }
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
[SecurityCritical] [SecurityCritical]
protected override bool ReleaseHandle() protected override bool ReleaseHandle()
{ {
return (NativeMethods.LocalFree(handle) == IntPtr.Zero); return (NativeMethods.LocalFree(handle) == IntPtr.Zero);
} }
[SecurityCritical] [SecurityCritical]
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
private static class NativeMethods private static class NativeMethods
{ {
[SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage")] [SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage")]
[DllImport("kernel32.dll", SetLastError = true)] [DllImport("kernel32.dll", SetLastError = true)]
public static extern SafeLocalAllocHandle LocalAlloc(uint dwFlags, IntPtr sizetBytes); public static extern SafeLocalAllocHandle LocalAlloc(uint dwFlags, IntPtr sizetBytes);
[DllImport("kernel32.dll", SetLastError = true)] [DllImport("kernel32.dll", SetLastError = true)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
public static extern IntPtr LocalFree(IntPtr hMem); public static extern IntPtr LocalFree(IntPtr hMem);
} }
} }
} }

View File

@ -1,97 +1,97 @@
using System; using System;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.IO; using System.IO;
using System.Runtime.ConstrainedExecution; using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security; using System.Security;
using System.Security.AccessControl; using System.Security.AccessControl;
using Microsoft.Win32.SafeHandles; using Microsoft.Win32.SafeHandles;
namespace Jellyfish.Library namespace Jellyfish.Library
{ {
[SecurityCritical] [SecurityCritical]
public sealed class SafeFileHandle : SafeHandleZeroOrMinusOneIsInvalid public sealed class SafeFileHandle : SafeHandleZeroOrMinusOneIsInvalid
{ {
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
public SafeFileHandle() : public SafeFileHandle() :
base(ownsHandle: true) base(ownsHandle: true)
{ {
} }
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
public SafeFileHandle(IntPtr existingHandle, bool ownsHandle) : public SafeFileHandle(IntPtr existingHandle, bool ownsHandle) :
base(ownsHandle) base(ownsHandle)
{ {
SetHandle(existingHandle); SetHandle(existingHandle);
} }
[SecurityCritical] [SecurityCritical]
public static SafeFileHandle CreateFile(string fileName, FileAccess fileAccess, FileShare fileShare, FileMode fileMode, GeneralSecurity fileSecurity) public static SafeFileHandle CreateFile(string fileName, FileAccess fileAccess, FileShare fileShare, FileMode fileMode, GeneralSecurity fileSecurity)
{ {
if (fileMode == FileMode.Append) if (fileMode == FileMode.Append)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
bool inheritable = ((fileShare & FileShare.Inheritable) != 0); bool inheritable = ((fileShare & FileShare.Inheritable) != 0);
fileShare &= ~FileShare.Inheritable; fileShare &= ~FileShare.Inheritable;
return CreateFile(fileName, (uint)fileAccess, (uint)fileShare, (uint)fileMode, 0x0, fileSecurity, inheritable); return CreateFile(fileName, (uint)fileAccess, (uint)fileShare, (uint)fileMode, 0x0, fileSecurity, inheritable);
} }
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
[SecurityCritical] [SecurityCritical]
protected override bool ReleaseHandle() protected override bool ReleaseHandle()
{ {
return NativeMethods.CloseHandle(handle); return NativeMethods.CloseHandle(handle);
} }
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
public GeneralSecurity GetAccessControl() public GeneralSecurity GetAccessControl()
{ {
return new GeneralSecurity(false, ResourceType.FileObject, this); return new GeneralSecurity(false, ResourceType.FileObject, this);
} }
public void SetAccessControl(GeneralSecurity fileSecurity) public void SetAccessControl(GeneralSecurity fileSecurity)
{ {
if (fileSecurity == null) if (fileSecurity == null)
{ {
throw new ArgumentNullException("fileSecurity"); throw new ArgumentNullException("fileSecurity");
} }
fileSecurity.Persist(this); fileSecurity.Persist(this);
} }
[SecurityCritical] [SecurityCritical]
private static SafeFileHandle CreateFile(string fileName, uint fileAccess, uint fileShare, uint fileMode, uint fileOptions, GeneralSecurity fileSecurity, private static SafeFileHandle CreateFile(string fileName, uint fileAccess, uint fileShare, uint fileMode, uint fileOptions, GeneralSecurity fileSecurity,
bool inheritable = false) bool inheritable = false)
{ {
var file = new SafeFileHandle(); var file = new SafeFileHandle();
GeneralSecurity.GetSecurityAttributes(fileSecurity, securityAttributes => GeneralSecurity.GetSecurityAttributes(fileSecurity, securityAttributes =>
{ {
file = NativeMethods.CreateFile(fileName, fileAccess, fileShare, securityAttributes, fileMode, fileOptions, IntPtr.Zero); file = NativeMethods.CreateFile(fileName, fileAccess, fileShare, securityAttributes, fileMode, fileOptions, IntPtr.Zero);
if (file.IsInvalid) if (file.IsInvalid)
{ {
Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
} }
}, inheritable); }, inheritable);
return file; return file;
} }
[SecurityCritical] [SecurityCritical]
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
private static class NativeMethods private static class NativeMethods
{ {
[DllImport("kernel32.dll", SetLastError = true)] [DllImport("kernel32.dll", SetLastError = true)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CloseHandle(IntPtr handle); public static extern bool CloseHandle(IntPtr handle);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern SafeFileHandle CreateFile(string lpFileName, uint dwDesiredAccess, uint dwShareMode, SecurityAttributes lpSecurityAttributes, public static extern SafeFileHandle CreateFile(string lpFileName, uint dwDesiredAccess, uint dwShareMode, SecurityAttributes lpSecurityAttributes,
uint dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile); uint dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile);
} }
} }
} }

View File

@ -1,133 +1,133 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Text; using System.Text;
using System.Windows; using System.Windows;
#if WINDOWS_PHONE #if WINDOWS_PHONE
using System.Windows.Navigation; using System.Windows.Navigation;
using Microsoft.Phone.Controls; using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell; using Microsoft.Phone.Shell;
#endif #endif
namespace Jellyfish.Library namespace Jellyfish.Library
{ {
public class ApplicationBase : Application public class ApplicationBase : Application
{ {
public ApplicationBase() : public ApplicationBase() :
this(null) this(null)
{ {
} }
public ApplicationBase(string name) public ApplicationBase(string name)
{ {
Name = name; Name = name;
UnhandledException += OnApplicationUnhandledException; UnhandledException += OnApplicationUnhandledException;
//AppDomain.CurrentDomain.UnhandledException += OnAppDomainUnhandledException; //AppDomain.CurrentDomain.UnhandledException += OnAppDomainUnhandledException;
} }
#if !WINDOWS_PHONE #if !WINDOWS_PHONE
protected void InitializeOutOfBrowserUpdate() protected void InitializeOutOfBrowserUpdate()
{ {
if (IsRunningOutOfBrowser) if (IsRunningOutOfBrowser)
{ {
CheckAndDownloadUpdateCompleted += OnApplicationCheckAndDownloadUpdateCompleted; CheckAndDownloadUpdateCompleted += OnApplicationCheckAndDownloadUpdateCompleted;
CheckAndDownloadUpdateAsync(); CheckAndDownloadUpdateAsync();
} }
} }
#endif #endif
#if WINDOWS_PHONE #if WINDOWS_PHONE
protected void InitializePhoneApplication() protected void InitializePhoneApplication()
{ {
if (!_phoneApplicationInitialized) if (!_phoneApplicationInitialized)
{ {
RootFrame = new PhoneApplicationFrame(); RootFrame = new PhoneApplicationFrame();
RootFrame.Navigated += OnRootFrameNavigated; RootFrame.Navigated += OnRootFrameNavigated;
RootFrame.NavigationFailed += OnRootFrameNavigationFailed; RootFrame.NavigationFailed += OnRootFrameNavigationFailed;
_phoneApplicationInitialized = true; _phoneApplicationInitialized = true;
} }
} }
#endif #endif
private string GetExceptionCaption(string title, bool isTerminating = false) private string GetExceptionCaption(string title, bool isTerminating = false)
{ {
var caption = new StringBuilder(); var caption = new StringBuilder();
if (!string.IsNullOrEmpty(Name)) if (!string.IsNullOrEmpty(Name))
{ {
caption.Append(Name).Append(' '); caption.Append(Name).Append(' ');
} }
caption.Append(title); caption.Append(title);
if (isTerminating) if (isTerminating)
{ {
caption.Append(" (Terminating)"); caption.Append(" (Terminating)");
} }
return caption.ToString(); return caption.ToString();
} }
#if !WINDOWS_PHONE #if !WINDOWS_PHONE
private void OnApplicationCheckAndDownloadUpdateCompleted(object sender, CheckAndDownloadUpdateCompletedEventArgs e) private void OnApplicationCheckAndDownloadUpdateCompleted(object sender, CheckAndDownloadUpdateCompletedEventArgs e)
{ {
if (e.Error != null) if (e.Error != null)
{ {
if (e.Error is PlatformNotSupportedException) if (e.Error is PlatformNotSupportedException)
{ {
MessageBox.Show("An application update is available, but it requires the latest version of Silverlight."); MessageBox.Show("An application update is available, but it requires the latest version of Silverlight.");
} }
else if (Debugger.IsAttached) else if (Debugger.IsAttached)
{ {
Debugger.Break(); Debugger.Break();
} }
} }
else if (e.UpdateAvailable) else if (e.UpdateAvailable)
{ {
MessageBox.Show("An application update was downloaded. Restart the application to run the latest version."); MessageBox.Show("An application update was downloaded. Restart the application to run the latest version.");
} }
} }
#endif #endif
private void OnApplicationUnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) private void OnApplicationUnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{ {
MessageBox.Show(e.ExceptionObject.ToString(), GetExceptionCaption("Application Exception"), MessageBoxButton.OK); MessageBox.Show(e.ExceptionObject.ToString(), GetExceptionCaption("Application Exception"), MessageBoxButton.OK);
if (Debugger.IsAttached) if (Debugger.IsAttached)
{ {
Debugger.Break(); Debugger.Break();
} }
} }
//private void OnAppDomainUnhandledException(object sender, UnhandledExceptionEventArgs e) //private void OnAppDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
//{ //{
// MessageBox.Show(e.ExceptionObject.ToString(), GetExceptionCaption("AppDomain Exception", e.IsTerminating), MessageBoxButton.OK); // MessageBox.Show(e.ExceptionObject.ToString(), GetExceptionCaption("AppDomain Exception", e.IsTerminating), MessageBoxButton.OK);
// if (Debugger.IsAttached) // if (Debugger.IsAttached)
// { // {
// Debugger.Break(); // Debugger.Break();
// } // }
//} //}
#if WINDOWS_PHONE #if WINDOWS_PHONE
private void OnRootFrameNavigated(object sender, NavigationEventArgs e) private void OnRootFrameNavigated(object sender, NavigationEventArgs e)
{ {
if (RootVisual != RootFrame) if (RootVisual != RootFrame)
{ {
RootVisual = RootFrame; RootVisual = RootFrame;
} }
RootFrame.Navigated -= OnRootFrameNavigated; RootFrame.Navigated -= OnRootFrameNavigated;
} }
private void OnRootFrameNavigationFailed(object sender, NavigationFailedEventArgs e) private void OnRootFrameNavigationFailed(object sender, NavigationFailedEventArgs e)
{ {
if (Debugger.IsAttached) if (Debugger.IsAttached)
{ {
Debugger.Break(); Debugger.Break();
} }
} }
#endif #endif
public string Name { get; private set; } public string Name { get; private set; }
#if WINDOWS_PHONE #if WINDOWS_PHONE
public PhoneApplicationFrame RootFrame { get; private set; } public PhoneApplicationFrame RootFrame { get; private set; }
private bool _phoneApplicationInitialized; private bool _phoneApplicationInitialized;
#endif #endif
} }
} }

View File

@ -1,22 +1,22 @@
using System; using System;
using System.Reflection; using System.Reflection;
using System.Resources; using System.Resources;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Jellyfish.Library; using Jellyfish.Library;
[assembly: AssemblyTitle("Library")] [assembly: AssemblyTitle("Library")]
[assembly: AssemblyDescription("Common Library")] [assembly: AssemblyDescription("Common Library")]
[assembly: AssemblyProduct("Jellyfish.Library.Silverlight.Phone")] [assembly: AssemblyProduct("Jellyfish.Library.Silverlight.Phone")]
[assembly: AssemblyCompany("Digital Jellyfish Design Ltd")] [assembly: AssemblyCompany("Digital Jellyfish Design Ltd")]
[assembly: AssemblyCopyright("Copyright © 2009-2010 Digital Jellyfish Design Ltd")] [assembly: AssemblyCopyright("Copyright © 2009-2010 Digital Jellyfish Design Ltd")]
[assembly: AssemblyComment("Developed by Sean Fausett")] [assembly: AssemblyComment("Developed by Sean Fausett")]
[assembly: AssemblyVersion("0.1.3.0")] [assembly: AssemblyVersion("0.1.3.0")]
[assembly: AssemblyFileVersion("0.1.3.0")] [assembly: AssemblyFileVersion("0.1.3.0")]
[assembly: AssemblyInformationalVersion("0.1.3.0")] [assembly: AssemblyInformationalVersion("0.1.3.0")]
[assembly: CLSCompliant(false)] [assembly: CLSCompliant(false)]
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
[assembly: Guid("66034b9e-9f0b-47b0-aac4-cade9a748891")] [assembly: Guid("66034b9e-9f0b-47b0-aac4-cade9a748891")]
[assembly: NeutralResourcesLanguage("en")] [assembly: NeutralResourcesLanguage("en")]

View File

@ -1,22 +1,22 @@
using System; using System;
using System.Reflection; using System.Reflection;
using System.Resources; using System.Resources;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Jellyfish.Library; using Jellyfish.Library;
[assembly: AssemblyTitle("Library")] [assembly: AssemblyTitle("Library")]
[assembly: AssemblyDescription("Common Library")] [assembly: AssemblyDescription("Common Library")]
[assembly: AssemblyProduct("Jellyfish.Library.Silverlight")] [assembly: AssemblyProduct("Jellyfish.Library.Silverlight")]
[assembly: AssemblyCompany("Digital Jellyfish Design Ltd")] [assembly: AssemblyCompany("Digital Jellyfish Design Ltd")]
[assembly: AssemblyCopyright("Copyright © 2009-2010 Digital Jellyfish Design Ltd")] [assembly: AssemblyCopyright("Copyright © 2009-2010 Digital Jellyfish Design Ltd")]
[assembly: AssemblyComment("Developed by Sean Fausett")] [assembly: AssemblyComment("Developed by Sean Fausett")]
[assembly: AssemblyVersion("0.1.3.0")] [assembly: AssemblyVersion("0.1.3.0")]
[assembly: AssemblyFileVersion("0.1.3.0")] [assembly: AssemblyFileVersion("0.1.3.0")]
[assembly: AssemblyInformationalVersion("0.1.3.0")] [assembly: AssemblyInformationalVersion("0.1.3.0")]
[assembly: CLSCompliant(false)] [assembly: CLSCompliant(false)]
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
[assembly: Guid("66034b9e-9f0b-47b0-aac4-cade9a748891")] [assembly: Guid("66034b9e-9f0b-47b0-aac4-cade9a748891")]
[assembly: NeutralResourcesLanguage("en")] [assembly: NeutralResourcesLanguage("en")]

View File

@ -1,76 +1,76 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Windows.Media; using System.Windows.Media;
namespace Jellyfish.Library namespace Jellyfish.Library
{ {
public sealed class WaveMediaStreamSource : MediaStreamSource, IDisposable public sealed class WaveMediaStreamSource : MediaStreamSource, IDisposable
{ {
public WaveMediaStreamSource(int sampleRate, int sampleChannels, int sampleBits, int sampleSize, int sampleLatency, Action<byte[], int> updater) public WaveMediaStreamSource(int sampleRate, int sampleChannels, int sampleBits, int sampleSize, int sampleLatency, Action<byte[], int> updater)
{ {
_bufferSize = sampleSize; _bufferSize = sampleSize;
_buffer = new byte[_bufferSize]; _buffer = new byte[_bufferSize];
_bufferStream = new MemoryStream(_buffer); _bufferStream = new MemoryStream(_buffer);
_waveFormat = new WaveFormat(sampleRate, sampleChannels, sampleBits); _waveFormat = new WaveFormat(sampleRate, sampleChannels, sampleBits);
AudioBufferLength = sampleLatency; // ms; avoids audio delay AudioBufferLength = sampleLatency; // ms; avoids audio delay
_updater = updater; _updater = updater;
} }
public void Dispose() public void Dispose()
{ {
_bufferStream.Dispose(); _bufferStream.Dispose();
} }
protected override void CloseMedia() protected override void CloseMedia()
{ {
_audioDescription = null; _audioDescription = null;
} }
protected override void GetDiagnosticAsync(MediaStreamSourceDiagnosticKind diagnosticKind) protected override void GetDiagnosticAsync(MediaStreamSourceDiagnosticKind diagnosticKind)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
protected override void GetSampleAsync(MediaStreamType mediaStreamType) protected override void GetSampleAsync(MediaStreamType mediaStreamType)
{ {
_updater(_buffer, _bufferSize); _updater(_buffer, _bufferSize);
var sample = new MediaStreamSample(_audioDescription, _bufferStream, 0, _bufferSize, _timestamp, _emptySampleDict); var sample = new MediaStreamSample(_audioDescription, _bufferStream, 0, _bufferSize, _timestamp, _emptySampleDict);
_timestamp += _bufferSize * 10000000L / _waveFormat.AverageBytesPerSec; // 100 ns _timestamp += _bufferSize * 10000000L / _waveFormat.AverageBytesPerSec; // 100 ns
ReportGetSampleCompleted(sample); ReportGetSampleCompleted(sample);
} }
protected override void OpenMediaAsync() protected override void OpenMediaAsync()
{ {
_timestamp = 0; _timestamp = 0;
var sourceAttributes = new Dictionary<MediaSourceAttributesKeys, string>() { { MediaSourceAttributesKeys.Duration, "0" }, { MediaSourceAttributesKeys.CanSeek, "false" } }; var sourceAttributes = new Dictionary<MediaSourceAttributesKeys, string>() { { MediaSourceAttributesKeys.Duration, "0" }, { MediaSourceAttributesKeys.CanSeek, "false" } };
var streamAttributes = new Dictionary<MediaStreamAttributeKeys, string>() { { MediaStreamAttributeKeys.CodecPrivateData, _waveFormat.ToHexString() } }; var streamAttributes = new Dictionary<MediaStreamAttributeKeys, string>() { { MediaStreamAttributeKeys.CodecPrivateData, _waveFormat.ToHexString() } };
_audioDescription = new MediaStreamDescription(MediaStreamType.Audio, streamAttributes); _audioDescription = new MediaStreamDescription(MediaStreamType.Audio, streamAttributes);
var availableStreams = new List<MediaStreamDescription>() { _audioDescription }; var availableStreams = new List<MediaStreamDescription>() { _audioDescription };
ReportOpenMediaCompleted(sourceAttributes, availableStreams); ReportOpenMediaCompleted(sourceAttributes, availableStreams);
} }
protected override void SeekAsync(long seekToTime) protected override void SeekAsync(long seekToTime)
{ {
ReportSeekCompleted(seekToTime); ReportSeekCompleted(seekToTime);
} }
protected override void SwitchMediaStreamAsync(MediaStreamDescription mediaStreamDescription) protected override void SwitchMediaStreamAsync(MediaStreamDescription mediaStreamDescription)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
private byte[] _buffer; private byte[] _buffer;
private int _bufferSize; private int _bufferSize;
private MemoryStream _bufferStream; private MemoryStream _bufferStream;
private Action<byte[], int> _updater; private Action<byte[], int> _updater;
private WaveFormat _waveFormat; private WaveFormat _waveFormat;
private long _timestamp; private long _timestamp;
private MediaStreamDescription _audioDescription; private MediaStreamDescription _audioDescription;
private Dictionary<MediaSampleAttributeKeys, string> _emptySampleDict = new Dictionary<MediaSampleAttributeKeys, string>(); private Dictionary<MediaSampleAttributeKeys, string> _emptySampleDict = new Dictionary<MediaSampleAttributeKeys, string>();
} }
} }

View File

@ -1,18 +1,18 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
namespace Jellyfish.Library namespace Jellyfish.Library
{ {
public static class SingletonFactory<T> where T : class, new() public static class SingletonFactory<T> where T : class, new()
{ {
[SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes")] [SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes")]
public static T Create() public static T Create()
{ {
return _instance; return _instance;
} }
[SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes")] [SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes")]
public static T Instance { get { return _instance; } } public static T Instance { get { return _instance; } }
private static readonly T _instance = new T(); private static readonly T _instance = new T();
} }
} }

View File

@ -1,40 +1,40 @@
using System; using System;
using System.IO; using System.IO;
namespace Jellyfish.Library namespace Jellyfish.Library
{ {
public static class StreamExtensions public static class StreamExtensions
{ {
public static byte[] ReadAllBytes(this Stream stream) public static byte[] ReadAllBytes(this Stream stream)
{ {
if (stream == null) if (stream == null)
{ {
throw new ArgumentNullException("stream"); throw new ArgumentNullException("stream");
} }
int count = (int)stream.Length; int count = (int)stream.Length;
byte[] buffer = new byte[count]; byte[] buffer = new byte[count];
ReadBlock(stream, buffer, 0, count); ReadBlock(stream, buffer, 0, count);
return buffer; return buffer;
} }
public static int ReadBlock(this Stream stream, byte[] buffer, int offset, int count) public static int ReadBlock(this Stream stream, byte[] buffer, int offset, int count)
{ {
if (stream == null) if (stream == null)
{ {
throw new ArgumentNullException("stream"); throw new ArgumentNullException("stream");
} }
int total = 0; int total = 0;
int read; int read;
do do
{ {
total += read = stream.Read(buffer, offset + total, count - total); total += read = stream.Read(buffer, offset + total, count - total);
} }
while ((read > 0) && (total < count)); while ((read > 0) && (total < count));
return total; return total;
} }
} }
} }

View File

@ -1,68 +1,68 @@
using System; using System;
using System.Globalization; using System.Globalization;
using System.Text; using System.Text;
namespace Jellyfish.Library namespace Jellyfish.Library
{ {
public static class StringBuilderExtensions public static class StringBuilderExtensions
{ {
public static StringBuilder AppendHex(this StringBuilder builder, short value) // little endian public static StringBuilder AppendHex(this StringBuilder builder, short value) // little endian
{ {
if (builder == null) if (builder == null)
{ {
throw new ArgumentNullException("builder"); throw new ArgumentNullException("builder");
} }
return builder.AppendFormat(CultureInfo.InvariantCulture, "{0:X2}{1:X2}", value & 0xFF, value >> 8); return builder.AppendFormat(CultureInfo.InvariantCulture, "{0:X2}{1:X2}", value & 0xFF, value >> 8);
} }
public static StringBuilder AppendHex(this StringBuilder builder, int value) // little endian public static StringBuilder AppendHex(this StringBuilder builder, int value) // little endian
{ {
if (builder == null) if (builder == null)
{ {
throw new ArgumentNullException("builder"); throw new ArgumentNullException("builder");
} }
return builder.AppendFormat(CultureInfo.InvariantCulture, "{0:X2}{1:X2}{2:X2}{3:X2}", value & 0xFF, (value >> 8) & 0xFF, (value >> 16) & 0xFF, value >> 24); return builder.AppendFormat(CultureInfo.InvariantCulture, "{0:X2}{1:X2}{2:X2}{3:X2}", value & 0xFF, (value >> 8) & 0xFF, (value >> 16) & 0xFF, value >> 24);
} }
public static StringBuilder AppendWithoutGarbage(this StringBuilder builder, int value) public static StringBuilder AppendWithoutGarbage(this StringBuilder builder, int value)
{ {
if (builder == null) if (builder == null)
{ {
throw new ArgumentNullException("builder"); throw new ArgumentNullException("builder");
} }
if (value < 0) if (value < 0)
{ {
builder.Append('-'); builder.Append('-');
} }
int index = builder.Length; int index = builder.Length;
do do
{ {
builder.Insert(index, Digits, (value % 10) + 9, 1); builder.Insert(index, Digits, (value % 10) + 9, 1);
value /= 10; value /= 10;
} }
while (value != 0); while (value != 0);
return builder; return builder;
} }
#if WINDOWS_PHONE || XBOX #if WINDOWS_PHONE || XBOX
public static StringBuilder Clear(this StringBuilder builder) public static StringBuilder Clear(this StringBuilder builder)
{ {
if (builder == null) if (builder == null)
{ {
throw new ArgumentNullException("builder"); throw new ArgumentNullException("builder");
} }
builder.Length = 0; builder.Length = 0;
return builder; return builder;
} }
#endif #endif
private static readonly char[] Digits = new char[] { '9', '8', '7', '6', '5', '4', '3', '2', '1', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; private static readonly char[] Digits = new char[] { '9', '8', '7', '6', '5', '4', '3', '2', '1', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
} }
} }

View File

@ -1,23 +1,23 @@
using System; using System;
using System.Threading; using System.Threading;
namespace Jellyfish.Library namespace Jellyfish.Library
{ {
public static class ThreadExtensions public static class ThreadExtensions
{ {
public static void IsAliveJoin(this Thread thread) public static void IsAliveJoin(this Thread thread)
{ {
if (thread == null) if (thread == null)
{ {
throw new ArgumentNullException("thread"); throw new ArgumentNullException("thread");
} }
#if !XBOX #if !XBOX
if (thread.IsAlive) if (thread.IsAlive)
#endif #endif
{ {
thread.Join(); thread.Join();
} }
} }
} }
} }

View File

@ -1,20 +1,20 @@
using System; using System;
using System.Threading; using System.Threading;
namespace Jellyfish.Library namespace Jellyfish.Library
{ {
public static class WaitHandleExtensions public static class WaitHandleExtensions
{ {
#if XBOX #if XBOX
public static bool WaitOne(this WaitHandle waitHandle, int millisecondsTimeout) public static bool WaitOne(this WaitHandle waitHandle, int millisecondsTimeout)
{ {
if (waitHandle == null) if (waitHandle == null)
{ {
throw new ArgumentNullException("waitHandle"); throw new ArgumentNullException("waitHandle");
} }
return waitHandle.WaitOne(millisecondsTimeout, false); return waitHandle.WaitOne(millisecondsTimeout, false);
} }
#endif #endif
} }
} }

View File

@ -1,49 +1,49 @@
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
namespace Jellyfish.Library namespace Jellyfish.Library
{ {
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public sealed class WaveFormat public sealed class WaveFormat
{ {
public WaveFormat(int sampleRate, int sampleChannels, int sampleBits) public WaveFormat(int sampleRate, int sampleChannels, int sampleBits)
{ {
_formatTag = WaveFormatPcm; _formatTag = WaveFormatPcm;
_samplesPerSec = sampleRate; _samplesPerSec = sampleRate;
_channels = (short)sampleChannels; _channels = (short)sampleChannels;
_bitsPerSample = (short)sampleBits; _bitsPerSample = (short)sampleBits;
_blockAlign = (short)(sampleChannels * sampleBits / 8); _blockAlign = (short)(sampleChannels * sampleBits / 8);
_averageBytesPerSec = sampleRate * _blockAlign; _averageBytesPerSec = sampleRate * _blockAlign;
} }
public string ToHexString() // little endian public string ToHexString() // little endian
{ {
var builder = new StringBuilder(); var builder = new StringBuilder();
builder.AppendHex(_formatTag); builder.AppendHex(_formatTag);
builder.AppendHex(_channels); builder.AppendHex(_channels);
builder.AppendHex(_samplesPerSec); builder.AppendHex(_samplesPerSec);
builder.AppendHex(_averageBytesPerSec); builder.AppendHex(_averageBytesPerSec);
builder.AppendHex(_blockAlign); builder.AppendHex(_blockAlign);
builder.AppendHex(_bitsPerSample); builder.AppendHex(_bitsPerSample);
builder.AppendHex(_size); builder.AppendHex(_size);
return builder.ToString(); return builder.ToString();
} }
public int SamplesPerSec { get { return _samplesPerSec; } } // no auto props public int SamplesPerSec { get { return _samplesPerSec; } } // no auto props
public int Channels { get { return _channels; } } public int Channels { get { return _channels; } }
public int BitsPerSample { get { return _bitsPerSample; } } public int BitsPerSample { get { return _bitsPerSample; } }
public int AverageBytesPerSec { get { return _averageBytesPerSec; } } public int AverageBytesPerSec { get { return _averageBytesPerSec; } }
private const int WaveFormatPcm = 1; private const int WaveFormatPcm = 1;
private short _formatTag; private short _formatTag;
private short _channels; private short _channels;
private int _samplesPerSec; private int _samplesPerSec;
private int _averageBytesPerSec; private int _averageBytesPerSec;
private short _blockAlign; private short _blockAlign;
private short _bitsPerSample; private short _bitsPerSample;
private short _size; private short _size;
} }
} }

View File

@ -1,65 +1,65 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Security; using System.Security;
using System.Text; using System.Text;
using System.Windows; using System.Windows;
using System.Windows.Threading; using System.Windows.Threading;
namespace Jellyfish.Library namespace Jellyfish.Library
{ {
public class ApplicationBase : Application public class ApplicationBase : Application
{ {
[SecurityCritical] [SecurityCritical]
public ApplicationBase() : public ApplicationBase() :
this(null) this(null)
{ {
} }
[SecurityCritical] [SecurityCritical]
public ApplicationBase(string name) public ApplicationBase(string name)
{ {
Name = name; Name = name;
DispatcherUnhandledException += OnApplicationDispatcherUnhandledException; DispatcherUnhandledException += OnApplicationDispatcherUnhandledException;
AppDomain.CurrentDomain.UnhandledException += OnAppDomainUnhandledException; AppDomain.CurrentDomain.UnhandledException += OnAppDomainUnhandledException;
} }
private string GetExceptionCaption(string title, bool isTerminating = false) private string GetExceptionCaption(string title, bool isTerminating = false)
{ {
var caption = new StringBuilder(); var caption = new StringBuilder();
if (!string.IsNullOrEmpty(Name)) if (!string.IsNullOrEmpty(Name))
{ {
caption.Append(Name).Append(' '); caption.Append(Name).Append(' ');
} }
caption.Append(title); caption.Append(title);
if (isTerminating) if (isTerminating)
{ {
caption.Append(" (Terminating)"); caption.Append(" (Terminating)");
} }
return caption.ToString(); return caption.ToString();
} }
private void OnApplicationDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) private void OnApplicationDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{ {
MessageBox.Show(e.Exception.ToString(), GetExceptionCaption("Application Dispatcher Exception", isTerminating: true)); MessageBox.Show(e.Exception.ToString(), GetExceptionCaption("Application Dispatcher Exception", isTerminating: true));
if (Debugger.IsAttached) if (Debugger.IsAttached)
{ {
Debugger.Break(); Debugger.Break();
} }
e.Handled = true; e.Handled = true;
Shutdown(); Shutdown();
} }
private void OnAppDomainUnhandledException(object sender, UnhandledExceptionEventArgs e) private void OnAppDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
{ {
MessageBox.Show(e.ExceptionObject.ToString(), GetExceptionCaption("AppDomain Exception", e.IsTerminating)); MessageBox.Show(e.ExceptionObject.ToString(), GetExceptionCaption("AppDomain Exception", e.IsTerminating));
if (Debugger.IsAttached) if (Debugger.IsAttached)
{ {
Debugger.Break(); Debugger.Break();
} }
} }
public string Name { get; private set; } public string Name { get; private set; }
} }
} }

View File

@ -1,22 +1,22 @@
using System; using System;
using System.Reflection; using System.Reflection;
using System.Resources; using System.Resources;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Jellyfish.Library; using Jellyfish.Library;
[assembly: AssemblyTitle("Library")] [assembly: AssemblyTitle("Library")]
[assembly: AssemblyDescription("Common Library")] [assembly: AssemblyDescription("Common Library")]
[assembly: AssemblyProduct("Jellyfish.Library.Wpf")] [assembly: AssemblyProduct("Jellyfish.Library.Wpf")]
[assembly: AssemblyCompany("Digital Jellyfish Design Ltd")] [assembly: AssemblyCompany("Digital Jellyfish Design Ltd")]
[assembly: AssemblyCopyright("Copyright © 2009-2010 Digital Jellyfish Design Ltd")] [assembly: AssemblyCopyright("Copyright © 2009-2010 Digital Jellyfish Design Ltd")]
[assembly: AssemblyComment("Developed by Sean Fausett")] [assembly: AssemblyComment("Developed by Sean Fausett")]
[assembly: AssemblyVersion("0.1.3.0")] [assembly: AssemblyVersion("0.1.3.0")]
[assembly: AssemblyFileVersion("0.1.3.0")] [assembly: AssemblyFileVersion("0.1.3.0")]
[assembly: AssemblyInformationalVersion("0.1.3.0")] [assembly: AssemblyInformationalVersion("0.1.3.0")]
[assembly: CLSCompliant(false)] [assembly: CLSCompliant(false)]
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
[assembly: Guid("66034b9e-9f0b-47b0-aac4-cade9a748891")] [assembly: Guid("66034b9e-9f0b-47b0-aac4-cade9a748891")]
[assembly: NeutralResourcesLanguage("en")] [assembly: NeutralResourcesLanguage("en")]

View File

@ -1,14 +1,14 @@
using System; using System;
using System.Windows; using System.Windows;
using System.Windows.Interop; using System.Windows.Interop;
namespace Jellyfish.Library namespace Jellyfish.Library
{ {
public static class WindowExtensions public static class WindowExtensions
{ {
public static IntPtr GetHandle(this Window window) public static IntPtr GetHandle(this Window window)
{ {
return new WindowInteropHelper(window).Handle; return new WindowInteropHelper(window).Handle;
} }
} }
} }

View File

@ -1,31 +1,31 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.IO; using System.IO;
using System.Xml; using System.Xml;
using System.Xml.Serialization; using System.Xml.Serialization;
namespace Jellyfish.Library 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")] [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))
{ {
var serializer = new XmlSerializer(typeof(T), defaultNamespace); var serializer = new XmlSerializer(typeof(T), defaultNamespace);
return (T)serializer.Deserialize(reader); return (T)serializer.Deserialize(reader);
} }
} }
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")] [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))
{ {
var serializer = new XmlSerializer(typeof(T), defaultNamespace); var serializer = new XmlSerializer(typeof(T), defaultNamespace);
serializer.Serialize(writer, instance); serializer.Serialize(writer, instance);
} }
} }
} }
} }

View File

@ -1,72 +1,72 @@
using System; using System;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Text; using System.Text;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
namespace Jellyfish.Library namespace Jellyfish.Library
{ {
public sealed class FrameRateCounter : DrawableGameComponent public sealed class FrameRateCounter : DrawableGameComponent
{ {
public FrameRateCounter(GameBase game) : public FrameRateCounter(GameBase game) :
base(game) base(game)
{ {
FontColor = Color.White; FontColor = Color.White;
FontName = "Default"; FontName = "Default";
} }
protected override void LoadContent() protected override void LoadContent()
{ {
_spriteBatch = new SpriteBatch(GraphicsDevice); _spriteBatch = new SpriteBatch(GraphicsDevice);
_spriteFont = Game.Content.Load<SpriteFont>(FontName); _spriteFont = Game.Content.Load<SpriteFont>(FontName);
var titleSafeArea = Game.GraphicsDevice.DisplayMode.TitleSafeArea; var titleSafeArea = Game.GraphicsDevice.DisplayMode.TitleSafeArea;
Position = new Vector2(titleSafeArea.X, titleSafeArea.Y); Position = new Vector2(titleSafeArea.X, titleSafeArea.Y);
} }
[SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")] [SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")]
public override void Draw(GameTime gameTime) public override void Draw(GameTime gameTime)
{ {
_frameCount++; _frameCount++;
_frameRateBuilder.Clear().AppendWithoutGarbage(_frameRate).Append(" fps"); _frameRateBuilder.Clear().AppendWithoutGarbage(_frameRate).Append(" fps");
_spriteBatch.Begin(); _spriteBatch.Begin();
//_spriteBatch.DrawString(_spriteFont, _frameRateBuilder, Position - Vector2.UnitX, Color.Black); // rough outline //_spriteBatch.DrawString(_spriteFont, _frameRateBuilder, Position - Vector2.UnitX, Color.Black); // rough outline
//_spriteBatch.DrawString(_spriteFont, _frameRateBuilder, Position + Vector2.UnitX, Color.Black); //_spriteBatch.DrawString(_spriteFont, _frameRateBuilder, Position + Vector2.UnitX, Color.Black);
//_spriteBatch.DrawString(_spriteFont, _frameRateBuilder, Position - Vector2.UnitY, Color.Black); //_spriteBatch.DrawString(_spriteFont, _frameRateBuilder, Position - Vector2.UnitY, Color.Black);
//_spriteBatch.DrawString(_spriteFont, _frameRateBuilder, Position + Vector2.UnitY, Color.Black); //_spriteBatch.DrawString(_spriteFont, _frameRateBuilder, Position + Vector2.UnitY, Color.Black);
_spriteBatch.DrawString(_spriteFont, _frameRateBuilder, Position, FontColor); _spriteBatch.DrawString(_spriteFont, _frameRateBuilder, Position, FontColor);
_spriteBatch.End(); _spriteBatch.End();
} }
[SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")] [SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")]
public override void Update(GameTime gameTime) public override void Update(GameTime gameTime)
{ {
if (gameTime == null) if (gameTime == null)
{ {
throw new ArgumentNullException("gameTime"); throw new ArgumentNullException("gameTime");
} }
_elapsedTime += gameTime.ElapsedGameTime.Ticks; _elapsedTime += gameTime.ElapsedGameTime.Ticks;
if (_elapsedTime >= TimeSpan.TicksPerSecond) if (_elapsedTime >= TimeSpan.TicksPerSecond)
{ {
_elapsedTime -= TimeSpan.TicksPerSecond; _elapsedTime -= TimeSpan.TicksPerSecond;
_frameRate = _frameCount; _frameRate = _frameCount;
_frameCount = 0; _frameCount = 0;
} }
} }
public Color FontColor { get; set; } public Color FontColor { get; set; }
public string FontName { get; set; } public string FontName { get; set; }
public Vector2 Position { get; set; } public Vector2 Position { get; set; }
private SpriteBatch _spriteBatch; private SpriteBatch _spriteBatch;
private SpriteFont _spriteFont; private SpriteFont _spriteFont;
private long _elapsedTime; private long _elapsedTime;
private int _frameCount; private int _frameCount;
private int _frameRate; private int _frameRate;
private StringBuilder _frameRateBuilder = new StringBuilder(); // cache builder; avoids garbage private StringBuilder _frameRateBuilder = new StringBuilder(); // cache builder; avoids garbage
} }
} }

View File

@ -1,50 +1,50 @@
using System; using System;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
namespace Jellyfish.Library namespace Jellyfish.Library
{ {
public class GameBase : Game public class GameBase : Game
{ {
public GameBase() : public GameBase() :
this(null) this(null)
{ {
} }
public GameBase(string name) public GameBase(string name)
{ {
Name = name; Name = name;
Content.RootDirectory = "Content"; Content.RootDirectory = "Content";
GraphicsDeviceManager = new GraphicsDeviceManager(this); GraphicsDeviceManager = new GraphicsDeviceManager(this);
#if WINDOWS_PHONE #if WINDOWS_PHONE
GraphicsDeviceManager.IsFullScreen = true; GraphicsDeviceManager.IsFullScreen = true;
TargetElapsedTime = TimeSpan.FromTicks(333333); // 30 fps TargetElapsedTime = TimeSpan.FromTicks(333333); // 30 fps
#endif #endif
GraphicsDeviceService = (IGraphicsDeviceService)Services.GetService(typeof(IGraphicsDeviceService)); GraphicsDeviceService = (IGraphicsDeviceService)Services.GetService(typeof(IGraphicsDeviceService));
if (!string.IsNullOrEmpty(Name)) if (!string.IsNullOrEmpty(Name))
{ {
Window.Title = Name; Window.Title = Name;
} }
} }
[SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")] [SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")]
protected override void Update(GameTime gameTime) protected override void Update(GameTime gameTime)
{ {
var gamePadState = GamePad.GetState(PlayerIndex.One); var gamePadState = GamePad.GetState(PlayerIndex.One);
if (gamePadState.Buttons.Back == ButtonState.Pressed) if (gamePadState.Buttons.Back == ButtonState.Pressed)
{ {
Exit(); Exit();
} }
base.Update(gameTime); base.Update(gameTime);
} }
public string Name { get; private set; } public string Name { get; private set; }
public GraphicsDeviceManager GraphicsDeviceManager { get; private set; } public GraphicsDeviceManager GraphicsDeviceManager { get; private set; }
public IGraphicsDeviceService GraphicsDeviceService { get; private set; } public IGraphicsDeviceService GraphicsDeviceService { get; private set; }
} }
} }

View File

@ -1,28 +1,28 @@
using System; using System;
using System.Reflection; using System.Reflection;
using System.Resources; using System.Resources;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Jellyfish.Library; using Jellyfish.Library;
[assembly: AssemblyTitle("Library")] [assembly: AssemblyTitle("Library")]
[assembly: AssemblyDescription("Common Library")] [assembly: AssemblyDescription("Common Library")]
#if WINDOWS_PHONE #if WINDOWS_PHONE
[assembly: AssemblyProduct("Jellyfish.Library.Xna.Phone")] [assembly: AssemblyProduct("Jellyfish.Library.Xna.Phone")]
#elif XBOX #elif XBOX
[assembly: AssemblyProduct("Jellyfish.Library.Xna.Xbox")] [assembly: AssemblyProduct("Jellyfish.Library.Xna.Xbox")]
#else #else
[assembly: AssemblyProduct("Jellyfish.Library.Xna")] [assembly: AssemblyProduct("Jellyfish.Library.Xna")]
#endif #endif
[assembly: AssemblyCompany("Digital Jellyfish Design Ltd")] [assembly: AssemblyCompany("Digital Jellyfish Design Ltd")]
[assembly: AssemblyCopyright("Copyright © 2009-2010 Digital Jellyfish Design Ltd")] [assembly: AssemblyCopyright("Copyright © 2009-2010 Digital Jellyfish Design Ltd")]
[assembly: AssemblyComment("Developed by Sean Fausett")] [assembly: AssemblyComment("Developed by Sean Fausett")]
[assembly: AssemblyVersion("0.1.3.0")] [assembly: AssemblyVersion("0.1.3.0")]
[assembly: AssemblyFileVersion("0.1.3.0")] [assembly: AssemblyFileVersion("0.1.3.0")]
[assembly: AssemblyInformationalVersion("0.1.3.0")] [assembly: AssemblyInformationalVersion("0.1.3.0")]
[assembly: CLSCompliant(false)] [assembly: CLSCompliant(false)]
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
[assembly: Guid("66034b9e-9f0b-47b0-aac4-cade9a748891")] [assembly: Guid("66034b9e-9f0b-47b0-aac4-cade9a748891")]
[assembly: NeutralResourcesLanguage("en")] [assembly: NeutralResourcesLanguage("en")]

View File

@ -1,339 +1,339 @@
GNU GENERAL PUBLIC LICENSE GNU GENERAL PUBLIC LICENSE
Version 2, June 1991 Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc., Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed. of this license document, but changing it is not allowed.
Preamble Preamble
The licenses for most software are designed to take away your The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to the GNU Lesser General Public License instead.) You can apply it to
your programs, too. your programs, too.
When we speak of free software, we are referring to freedom, not When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things. in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights. anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it. distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their source code. And you must show them these terms so they know their
rights. rights.
We protect your rights with two steps: (1) copyright the software, and We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy, (2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software. distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original that any problems introduced by others will not reflect on the original
authors' reputations. authors' reputations.
Finally, any free program is threatened constantly by software Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all. patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and The precise terms and conditions for copying, distribution and
modification follow. modification follow.
GNU GENERAL PUBLIC LICENSE GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains 0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below, under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program" refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law: means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it, that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you". the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program). Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does. Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's 1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty; notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License and give any other recipients of the Program a copy of this License
along with the Program. along with the Program.
You may charge a fee for the physical act of transferring a copy, and You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee. you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion 2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1 distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions: above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change. stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License. parties under the terms of this License.
c) If the modified program normally reads commands interactively c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on does not normally print such an announcement, your work based on
the Program is not required to print an announcement.) the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program, identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it. entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or exercise the right to control the distribution of derivative or
collective works based on the Program. collective works based on the Program.
In addition, mere aggregation of another work not based on the Program In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under a storage or distribution medium does not bring the other work under
the scope of this License. the scope of this License.
3. You may copy and distribute the Program (or a work based on it, 3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following: Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or, 1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or, customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such received the program in object code or executable form with such
an offer, in accord with Subsection b above.) an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component operating system on which the executable runs, unless that component
itself accompanies the executable. itself accompanies the executable.
If distribution of executable or object code is made by offering If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not distribution of the source code, even though third parties are not
compelled to copy the source along with the object code. compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program 4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License. void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such this License will not have their licenses terminated so long as such
parties remain in full compliance. parties remain in full compliance.
5. You are not required to accept this License, since you have not 5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying all its terms and conditions for copying, distributing or modifying
the Program or works based on it. the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the 6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein. restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to You are not responsible for enforcing compliance by third parties to
this License. this License.
7. If, as a consequence of a court judgment or allegation of patent 7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues), infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program. refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other apply and the section as a whole is intended to apply in other
circumstances. circumstances.
It is not the purpose of this section to induce you to infringe any It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is integrity of the free software distribution system, which is
implemented by public license practices. Many people have made implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot to distribute software through any other system and a licensee cannot
impose that choice. impose that choice.
This section is intended to make thoroughly clear what is believed to This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License. be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in 8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License. the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions 9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to be similar in spirit to the present version, but may differ in detail to
address new problems or concerns. address new problems or concerns.
Each version is given a distinguishing version number. If the Program Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software this License, you may choose any version ever published by the Free Software
Foundation. Foundation.
10. If you wish to incorporate parts of the Program into other free 10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally. of promoting the sharing and reuse of software generally.
NO WARRANTY NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION. REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES. POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms. free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found. the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.> <one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author> Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License along You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc., with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail. Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this If the program is interactive, make it output a short notice like this
when it starts in an interactive mode: when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details. under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program. mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names: necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker. `Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989 <signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice Ty Coon, President of Vice
This General Public License does not permit incorporating your program into This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. Public License instead of this License.

View File

@ -1,23 +1,23 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
namespace Jellyfish.Virtu namespace Jellyfish.Virtu
{ {
public sealed class Cassette : MachineComponent public sealed class Cassette : MachineComponent
{ {
public Cassette(Machine machine) : public Cassette(Machine machine) :
base(machine) base(machine)
{ {
} }
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
public bool ReadInput() public bool ReadInput()
{ {
return false; return false;
} }
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
public void ToggleOutput() public void ToggleOutput()
{ {
} }
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,83 +1,83 @@
using System; using System;
namespace Jellyfish.Virtu namespace Jellyfish.Virtu
{ {
public partial class Cpu public partial class Cpu
{ {
private const int OpCodeCount = 256; private const int OpCodeCount = 256;
private readonly Action[] ExecuteOpCode65N02; private readonly Action[] ExecuteOpCode65N02;
private readonly Action[] ExecuteOpCode65C02; private readonly Action[] ExecuteOpCode65C02;
private const int PC = 0x01; private const int PC = 0x01;
private const int PZ = 0x02; private const int PZ = 0x02;
private const int PI = 0x04; private const int PI = 0x04;
private const int PD = 0x08; private const int PD = 0x08;
private const int PB = 0x10; private const int PB = 0x10;
private const int PR = 0x20; private const int PR = 0x20;
private const int PV = 0x40; private const int PV = 0x40;
private const int PN = 0x80; private const int PN = 0x80;
private const int DataCount = 256; private const int DataCount = 256;
private static readonly int[] DataPN = new int[DataCount] private static readonly int[] DataPN = new int[DataCount]
{ {
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN
}; };
private static readonly int[] DataPZ = new int[DataCount] private static readonly int[] DataPZ = new int[DataCount]
{ {
PZ, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, PZ, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
}; };
private static readonly int[] DataPNZ = new int[DataCount] private static readonly int[] DataPNZ = new int[DataCount]
{ {
PZ, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, PZ, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN
}; };
} }
} }

View File

@ -1,24 +1,24 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Dictionary> <Dictionary>
<Acronyms> <Acronyms>
<CasingExceptions> <CasingExceptions>
<Acronym>Io</Acronym> <Acronym>Io</Acronym>
<Acronym>RPC</Acronym> <Acronym>RPC</Acronym>
</CasingExceptions> </CasingExceptions>
</Acronyms> </Acronyms>
<Words> <Words>
<Recognized> <Recognized>
<Word>Annunciator</Word> <Word>Annunciator</Word>
<Word>Dsk</Word> <Word>Dsk</Word>
<Word>Unpause</Word> <Word>Unpause</Word>
<Word>Virtu</Word> <Word>Virtu</Word>
<Word>Xna</Word> <Word>Xna</Word>
<Word>x</Word> <Word>x</Word>
<Word>y</Word> <Word>y</Word>
</Recognized> </Recognized>
<Unrecognized> <Unrecognized>
<Word>DownRight</Word> <Word>DownRight</Word>
<Word>UpRight</Word> <Word>UpRight</Word>
</Unrecognized> </Unrecognized>
</Words> </Words>
</Dictionary> </Dictionary>

View File

@ -1,52 +1,52 @@
using System; using System;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
namespace Jellyfish.Virtu namespace Jellyfish.Virtu
{ {
public abstract class Disk525 public abstract class Disk525
{ {
protected Disk525(string name, byte[] data, bool isWriteProtected) protected Disk525(string name, byte[] data, bool isWriteProtected)
{ {
Name = name; Name = name;
Data = data; Data = data;
IsWriteProtected = isWriteProtected; IsWriteProtected = isWriteProtected;
} }
public static Disk525 CreateDisk(string name, byte[] data, bool isWriteProtected) public static Disk525 CreateDisk(string name, byte[] data, bool isWriteProtected)
{ {
if (name == null) if (name == null)
{ {
throw new ArgumentNullException("name"); throw new ArgumentNullException("name");
} }
if (data == null) if (data == null)
{ {
throw new ArgumentNullException("data"); throw new ArgumentNullException("data");
} }
if (name.EndsWith(".nib", StringComparison.OrdinalIgnoreCase) && (data.Length == TrackCount * TrackSize)) if (name.EndsWith(".nib", StringComparison.OrdinalIgnoreCase) && (data.Length == TrackCount * TrackSize))
{ {
return new DiskNib(name, data, isWriteProtected); return new DiskNib(name, data, isWriteProtected);
} }
else if (name.EndsWith(".dsk", StringComparison.OrdinalIgnoreCase) && (data.Length == TrackCount * SectorCount * SectorSize)) else if (name.EndsWith(".dsk", StringComparison.OrdinalIgnoreCase) && (data.Length == TrackCount * SectorCount * SectorSize))
{ {
return new DiskDsk(name, data, isWriteProtected); return new DiskDsk(name, data, isWriteProtected);
} }
return null; return null;
} }
public abstract void ReadTrack(int number, int fraction, byte[] buffer); public abstract void ReadTrack(int number, int fraction, byte[] buffer);
public abstract void WriteTrack(int number, int fraction, byte[] buffer); public abstract void WriteTrack(int number, int fraction, byte[] buffer);
public string Name { get; private set; } public string Name { get; private set; }
public bool IsWriteProtected { get; private set; } public bool IsWriteProtected { get; private set; }
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
protected byte[] Data { get; private set; } protected byte[] Data { get; private set; }
public const int SectorCount = 16; public const int SectorCount = 16;
public const int SectorSize = 0x100; public const int SectorSize = 0x100;
public const int TrackCount = 35; public const int TrackCount = 35;
public const int TrackSize = 0x1A00; public const int TrackSize = 0x1A00;
} }
} }

View File

@ -1,289 +1,289 @@
using System; using System;
namespace Jellyfish.Virtu namespace Jellyfish.Virtu
{ {
public sealed class DiskDsk : Disk525 public sealed class DiskDsk : Disk525
{ {
public DiskDsk(string name, byte[] data, bool isWriteProtected) : public DiskDsk(string name, byte[] data, bool isWriteProtected) :
base(name, data, isWriteProtected) base(name, data, isWriteProtected)
{ {
} }
public override void ReadTrack(int number, int fraction, byte[] buffer) public override void ReadTrack(int number, int fraction, byte[] buffer)
{ {
int track = number / 2; int track = number / 2;
_trackBuffer = buffer; _trackBuffer = buffer;
_trackOffset = 0; _trackOffset = 0;
WriteNibble(0xFF, 48); // gap 0 WriteNibble(0xFF, 48); // gap 0
for (int sector = 0; sector < SectorCount; sector++) for (int sector = 0; sector < SectorCount; sector++)
{ {
WriteNibble(0xD5); // address prologue WriteNibble(0xD5); // address prologue
WriteNibble(0xAA); WriteNibble(0xAA);
WriteNibble(0x96); WriteNibble(0x96);
WriteNibble44(Volume); WriteNibble44(Volume);
WriteNibble44(track); WriteNibble44(track);
WriteNibble44(sector); WriteNibble44(sector);
WriteNibble44(Volume ^ track ^ sector); WriteNibble44(Volume ^ track ^ sector);
WriteNibble(0xDE); // address epilogue WriteNibble(0xDE); // address epilogue
WriteNibble(0xAA); WriteNibble(0xAA);
WriteNibble(0xEB); WriteNibble(0xEB);
WriteNibble(0xFF, 8); WriteNibble(0xFF, 8);
WriteNibble(0xD5); // data prologue WriteNibble(0xD5); // data prologue
WriteNibble(0xAA); WriteNibble(0xAA);
WriteNibble(0xAD); WriteNibble(0xAD);
WriteDataNibbles((track * SectorCount + DosOrderToLogicalSector[sector]) * SectorSize); WriteDataNibbles((track * SectorCount + DosOrderToLogicalSector[sector]) * SectorSize);
WriteNibble(0xDE); // data epilogue WriteNibble(0xDE); // data epilogue
WriteNibble(0xAA); WriteNibble(0xAA);
WriteNibble(0xEB); WriteNibble(0xEB);
WriteNibble(0xFF, 16); WriteNibble(0xFF, 16);
} }
} }
public override void WriteTrack(int number, int fraction, byte[] buffer) public override void WriteTrack(int number, int fraction, byte[] buffer)
{ {
if (IsWriteProtected) if (IsWriteProtected)
return; return;
int track = number / 2; int track = number / 2;
_trackBuffer = buffer; _trackBuffer = buffer;
_trackOffset = 0; _trackOffset = 0;
int sectorsDone = 0; int sectorsDone = 0;
for (int sector = 0; sector < SectorCount; sector++) for (int sector = 0; sector < SectorCount; sector++)
{ {
if (!Read3Nibbles(0xD5, 0xAA, 0x96, 0x304)) if (!Read3Nibbles(0xD5, 0xAA, 0x96, 0x304))
break; // no address prologue break; // no address prologue
/*int readVolume = */ReadNibble44(); /*int readVolume = */ReadNibble44();
int readTrack = ReadNibble44(); int readTrack = ReadNibble44();
if (readTrack != track) if (readTrack != track)
break; // bad track number break; // bad track number
int readSector = ReadNibble44(); int readSector = ReadNibble44();
if (readSector > SectorCount) if (readSector > SectorCount)
break; // bad sector number break; // bad sector number
if ((sectorsDone & (0x1 << readSector)) != 0) if ((sectorsDone & (0x1 << readSector)) != 0)
break; // already done this sector break; // already done this sector
if (ReadNibble44() != (Volume ^ readTrack ^ readSector)) if (ReadNibble44() != (Volume ^ readTrack ^ readSector))
break; // bad address checksum break; // bad address checksum
if ((ReadNibble() != 0xDE) || (ReadNibble() != 0xAA)) if ((ReadNibble() != 0xDE) || (ReadNibble() != 0xAA))
break; // bad address epilogue break; // bad address epilogue
if (!Read3Nibbles(0xD5, 0xAA, 0xAD, 0x20)) if (!Read3Nibbles(0xD5, 0xAA, 0xAD, 0x20))
break; // no data prologue break; // no data prologue
if (!ReadDataNibbles((track * SectorCount + DosOrderToLogicalSector[sector]) * SectorSize)) if (!ReadDataNibbles((track * SectorCount + DosOrderToLogicalSector[sector]) * SectorSize))
break; // bad data checksum break; // bad data checksum
if ((ReadNibble() != 0xDE) || (ReadNibble() != 0xAA)) if ((ReadNibble() != 0xDE) || (ReadNibble() != 0xAA))
break; // bad data epilogue break; // bad data epilogue
sectorsDone |= 0x1 << sector; sectorsDone |= 0x1 << sector;
} }
if (sectorsDone != 0xFFFF) if (sectorsDone != 0xFFFF)
throw new InvalidOperationException("disk error"); // TODO: we should alert the user and "dump" a NIB throw new InvalidOperationException("disk error"); // TODO: we should alert the user and "dump" a NIB
} }
private byte ReadNibble() private byte ReadNibble()
{ {
byte data = _trackBuffer[_trackOffset]; byte data = _trackBuffer[_trackOffset];
if (_trackOffset++ == TrackSize) if (_trackOffset++ == TrackSize)
{ {
_trackOffset = 0; _trackOffset = 0;
} }
return data; return data;
} }
private bool Read3Nibbles(byte data1, byte data2, byte data3, int maxReads) private bool Read3Nibbles(byte data1, byte data2, byte data3, int maxReads)
{ {
bool result = false; bool result = false;
while (--maxReads > 0) while (--maxReads > 0)
{ {
if (ReadNibble() != data1) if (ReadNibble() != data1)
continue; continue;
if (ReadNibble() != data2) if (ReadNibble() != data2)
continue; continue;
if (ReadNibble() != data3) if (ReadNibble() != data3)
continue; continue;
result = true; result = true;
break; break;
} }
return result; return result;
} }
private int ReadNibble44() private int ReadNibble44()
{ {
return (((ReadNibble() << 1) | 0x1) & ReadNibble()); return (((ReadNibble() << 1) | 0x1) & ReadNibble());
} }
private byte ReadTranslatedNibble() private byte ReadTranslatedNibble()
{ {
byte data = NibbleToByte[ReadNibble()]; byte data = NibbleToByte[ReadNibble()];
// TODO: check that invalid nibbles aren't used // TODO: check that invalid nibbles aren't used
// (put 0xFFs for invalid nibbles in the table) // (put 0xFFs for invalid nibbles in the table)
//if (data == 0xFF) //if (data == 0xFF)
//{ //{
//throw an exception //throw an exception
//} //}
return data; return data;
} }
private bool ReadDataNibbles(int sectorOffset) private bool ReadDataNibbles(int sectorOffset)
{ {
byte a, x, y; byte a, x, y;
y = SecondaryBufferLength; y = SecondaryBufferLength;
a = 0; a = 0;
do // fill and de-nibblize secondary buffer do // fill and de-nibblize secondary buffer
{ {
a = _secondaryBuffer[--y] = (byte)(a ^ ReadTranslatedNibble()); a = _secondaryBuffer[--y] = (byte)(a ^ ReadTranslatedNibble());
} }
while (y > 0); while (y > 0);
do // fill and de-nibblize secondary buffer do // fill and de-nibblize secondary buffer
{ {
a = _primaryBuffer[y++] = (byte)(a ^ ReadTranslatedNibble()); a = _primaryBuffer[y++] = (byte)(a ^ ReadTranslatedNibble());
} }
while (y != 0); while (y != 0);
int checksum = a ^ ReadTranslatedNibble(); // should be 0 int checksum = a ^ ReadTranslatedNibble(); // should be 0
x = y = 0; x = y = 0;
do // decode data do // decode data
{ {
if (x == 0) if (x == 0)
{ {
x = SecondaryBufferLength; x = SecondaryBufferLength;
} }
a = (byte)((_primaryBuffer[y] << 2) | SwapBits[_secondaryBuffer[--x] & 0x03]); a = (byte)((_primaryBuffer[y] << 2) | SwapBits[_secondaryBuffer[--x] & 0x03]);
_secondaryBuffer[x] >>= 2; _secondaryBuffer[x] >>= 2;
Data[sectorOffset + y] = a; Data[sectorOffset + y] = a;
} }
while (++y != 0); while (++y != 0);
return (checksum == 0); return (checksum == 0);
} }
private void WriteNibble(int data) private void WriteNibble(int data)
{ {
_trackBuffer[_trackOffset++] = (byte)data; _trackBuffer[_trackOffset++] = (byte)data;
} }
private void WriteNibble(int data, int count) private void WriteNibble(int data, int count)
{ {
while (count-- > 0) while (count-- > 0)
{ {
WriteNibble(data); WriteNibble(data);
} }
} }
private void WriteNibble44(int data) private void WriteNibble44(int data)
{ {
WriteNibble((data >> 1) | 0xAA); WriteNibble((data >> 1) | 0xAA);
WriteNibble(data | 0xAA); WriteNibble(data | 0xAA);
} }
private void WriteDataNibbles(int sectorOffset) private void WriteDataNibbles(int sectorOffset)
{ {
byte a, x, y; byte a, x, y;
for (x = 0; x < SecondaryBufferLength; x++) for (x = 0; x < SecondaryBufferLength; x++)
{ {
_secondaryBuffer[x] = 0; // zero secondary buffer _secondaryBuffer[x] = 0; // zero secondary buffer
} }
y = 2; y = 2;
do // fill buffers do // fill buffers
{ {
x = 0; x = 0;
do do
{ {
a = Data[sectorOffset + --y]; a = Data[sectorOffset + --y];
_secondaryBuffer[x] = (byte)((_secondaryBuffer[x] << 2) | SwapBits[a & 0x03]); // b1,b0 -> secondary buffer _secondaryBuffer[x] = (byte)((_secondaryBuffer[x] << 2) | SwapBits[a & 0x03]); // b1,b0 -> secondary buffer
_primaryBuffer[y] = (byte)(a >> 2); // b7-b2 -> primary buffer _primaryBuffer[y] = (byte)(a >> 2); // b7-b2 -> primary buffer
} }
while (++x < SecondaryBufferLength); while (++x < SecondaryBufferLength);
} }
while (y != 0); while (y != 0);
y = SecondaryBufferLength; y = SecondaryBufferLength;
do // write secondary buffer do // write secondary buffer
{ {
WriteNibble(ByteToNibble[_secondaryBuffer[y] ^ _secondaryBuffer[y - 1]]); WriteNibble(ByteToNibble[_secondaryBuffer[y] ^ _secondaryBuffer[y - 1]]);
} }
while (--y != 0); while (--y != 0);
a = _secondaryBuffer[0]; a = _secondaryBuffer[0];
do // write primary buffer do // write primary buffer
{ {
WriteNibble(ByteToNibble[a ^ _primaryBuffer[y]]); WriteNibble(ByteToNibble[a ^ _primaryBuffer[y]]);
a = _primaryBuffer[y]; a = _primaryBuffer[y];
} }
while (++y != 0); while (++y != 0);
WriteNibble(ByteToNibble[a]); // data checksum WriteNibble(ByteToNibble[a]); // data checksum
} }
private byte[] _trackBuffer; private byte[] _trackBuffer;
private int _trackOffset; private int _trackOffset;
private byte[] _primaryBuffer = new byte[0x100]; private byte[] _primaryBuffer = new byte[0x100];
private const int SecondaryBufferLength = 0x56; private const int SecondaryBufferLength = 0x56;
private byte[] _secondaryBuffer = new byte[SecondaryBufferLength + 1]; private byte[] _secondaryBuffer = new byte[SecondaryBufferLength + 1];
private const int Volume = 0xFE; private const int Volume = 0xFE;
private static readonly byte[] SwapBits = { 0, 2, 1, 3 }; private static readonly byte[] SwapBits = { 0, 2, 1, 3 };
private static readonly int[] DosOrderToLogicalSector = new int[] private static readonly int[] DosOrderToLogicalSector = new int[]
{ {
0x0, 0x7, 0xE, 0x6, 0xD, 0x5, 0xC, 0x4, 0xB, 0x3, 0xA, 0x2, 0x9, 0x1, 0x8, 0xF 0x0, 0x7, 0xE, 0x6, 0xD, 0x5, 0xC, 0x4, 0xB, 0x3, 0xA, 0x2, 0x9, 0x1, 0x8, 0xF
}; };
private static readonly byte[] ByteToNibble = new byte[] private static readonly byte[] ByteToNibble = new byte[]
{ {
0x96, 0x97, 0x9A, 0x9B, 0x9D, 0x9E, 0x9F, 0xA6, 0xA7, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB2, 0xB3, 0x96, 0x97, 0x9A, 0x9B, 0x9D, 0x9E, 0x9F, 0xA6, 0xA7, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB2, 0xB3,
0xB4, 0xB5, 0xB6, 0xB7, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, 0xCB, 0xCD, 0xCE, 0xCF, 0xD3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, 0xCB, 0xCD, 0xCE, 0xCF, 0xD3,
0xD6, 0xD7, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, 0xE5, 0xE6, 0xE7, 0xE9, 0xEA, 0xEB, 0xEC, 0xD6, 0xD7, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, 0xE5, 0xE6, 0xE7, 0xE9, 0xEA, 0xEB, 0xEC,
0xED, 0xEE, 0xEF, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF 0xED, 0xEE, 0xEF, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF
}; };
private static readonly byte[] NibbleToByte = new byte[] private static readonly byte[] NibbleToByte = new byte[]
{ {
// padding for offset (not used) // padding for offset (not used)
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95,
// nibble translate table // nibble translate table
0x00, 0x01, 0x98, 0x99, 0x02, 0x03, 0x9C, 0x04, 0x05, 0x06, 0x00, 0x01, 0x98, 0x99, 0x02, 0x03, 0x9C, 0x04, 0x05, 0x06,
0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0x07, 0x08, 0xA8, 0xA9, 0xAA, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0x07, 0x08, 0xA8, 0xA9, 0xAA, 0x09, 0x0A, 0x0B, 0x0C, 0x0D,
0xB0, 0xB1, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0xB8, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0xB0, 0xB1, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0xB8, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A,
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0x1B, 0xCC, 0x1C, 0x1D, 0x1E, 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0x1B, 0xCC, 0x1C, 0x1D, 0x1E,
0xD0, 0xD1, 0xD2, 0x1F, 0xD4, 0xD5, 0x20, 0x21, 0xD8, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0xD0, 0xD1, 0xD2, 0x1F, 0xD4, 0xD5, 0x20, 0x21, 0xD8, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0x29, 0x2A, 0x2B, 0xE8, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0x29, 0x2A, 0x2B, 0xE8, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32,
0xF0, 0xF1, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0xF8, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F 0xF0, 0xF1, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0xF8, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F
}; };
} }
} }

View File

@ -1,251 +1,251 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using Jellyfish.Library; using Jellyfish.Library;
using Jellyfish.Virtu.Services; using Jellyfish.Virtu.Services;
using Jellyfish.Virtu.Settings; using Jellyfish.Virtu.Settings;
namespace Jellyfish.Virtu namespace Jellyfish.Virtu
{ {
public sealed class DiskIIController : PeripheralCard public sealed class DiskIIController : PeripheralCard
{ {
public DiskIIController(Machine machine) : public DiskIIController(Machine machine) :
base(machine) base(machine)
{ {
} }
public override void Initialize() public override void Initialize()
{ {
var romStream = StorageService.GetResourceStream("Roms/DiskII.rom", 0x0100); var romStream = StorageService.GetResourceStream("Roms/DiskII.rom", 0x0100);
romStream.ReadBlock(_romRegionC1C7, 0x0000, 0x0100); romStream.ReadBlock(_romRegionC1C7, 0x0000, 0x0100);
_drives[0].InsertDisk("Default.dsk", StorageService.GetResourceStream("Disks/Default.dsk", 0x23000), false); _drives[0].InsertDisk("Default.dsk", StorageService.GetResourceStream("Disks/Default.dsk", 0x23000), false);
#if WINDOWS #if WINDOWS
var settings = Machine.Settings.DiskII; var settings = Machine.Settings.DiskII;
if (settings.Disk1.Name.Length > 0) if (settings.Disk1.Name.Length > 0)
{ {
_drives[0].InsertDisk(settings.Disk1.Name, settings.Disk1.IsWriteProtected); _drives[0].InsertDisk(settings.Disk1.Name, settings.Disk1.IsWriteProtected);
} }
if (settings.Disk2.Name.Length > 0) if (settings.Disk2.Name.Length > 0)
{ {
_drives[1].InsertDisk(settings.Disk2.Name, settings.Disk2.IsWriteProtected); _drives[1].InsertDisk(settings.Disk2.Name, settings.Disk2.IsWriteProtected);
} }
#endif #endif
} }
public override void Reset() public override void Reset()
{ {
_phaseStates = 0; _phaseStates = 0;
SetMotorOn(false); SetMotorOn(false);
SetDriveNumber(0); SetDriveNumber(0);
_loadMode = false; _loadMode = false;
_writeMode = false; _writeMode = false;
} }
public override void Uninitialize() public override void Uninitialize()
{ {
Flush(); Flush();
} }
[SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")] [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
public override int ReadIoRegionC0C0(int address) public override int ReadIoRegionC0C0(int address)
{ {
switch (address & 0xF) switch (address & 0xF)
{ {
case 0x0: case 0x1: case 0x2: case 0x3: case 0x4: case 0x5: case 0x6: case 0x7: case 0x0: case 0x1: case 0x2: case 0x3: case 0x4: case 0x5: case 0x6: case 0x7:
SetPhase(address); SetPhase(address);
break; break;
case 0x8: case 0x8:
SetMotorOn(false); SetMotorOn(false);
break; break;
case 0x9: case 0x9:
SetMotorOn(true); SetMotorOn(true);
break; break;
case 0xA: case 0xA:
SetDriveNumber(0); SetDriveNumber(0);
break; break;
case 0xB: case 0xB:
SetDriveNumber(1); SetDriveNumber(1);
break; break;
case 0xC: case 0xC:
_loadMode = false; _loadMode = false;
if (_motorOn) if (_motorOn)
{ {
if (!_writeMode) if (!_writeMode)
{ {
return _latch = _drives[_driveNumber].Read(); return _latch = _drives[_driveNumber].Read();
} }
else else
{ {
WriteLatch(); WriteLatch();
} }
} }
break; break;
case 0xD: case 0xD:
_loadMode = true; _loadMode = true;
if (_motorOn && !_writeMode) if (_motorOn && !_writeMode)
{ {
// write protect is forced if phase 1 is on [F9.7] // write protect is forced if phase 1 is on [F9.7]
_latch &= 0x7F; _latch &= 0x7F;
if (_drives[_driveNumber].IsWriteProtected || if (_drives[_driveNumber].IsWriteProtected ||
(_phaseStates & Phase1On) != 0) (_phaseStates & Phase1On) != 0)
{ {
_latch |= 0x80; _latch |= 0x80;
} }
} }
break; break;
case 0xE: case 0xE:
_writeMode = false; _writeMode = false;
break; break;
case 0xF: case 0xF:
_writeMode = true; _writeMode = true;
break; break;
} }
if ((address & 1) == 0) if ((address & 1) == 0)
{ {
// only even addresses return the latch // only even addresses return the latch
if (_motorOn) if (_motorOn)
{ {
return _latch; return _latch;
} }
// simple hack to fool DOS SAMESLOT drive spin check (usually at $BD34) // simple hack to fool DOS SAMESLOT drive spin check (usually at $BD34)
_driveSpin = !_driveSpin; _driveSpin = !_driveSpin;
return _driveSpin ? 0x7E : 0x7F; return _driveSpin ? 0x7E : 0x7F;
} }
return ReadFloatingBus(); return ReadFloatingBus();
} }
public override int ReadIoRegionC1C7(int address) public override int ReadIoRegionC1C7(int address)
{ {
return _romRegionC1C7[address & 0xFF]; return _romRegionC1C7[address & 0xFF];
} }
public override void WriteIoRegionC0C0(int address, int data) public override void WriteIoRegionC0C0(int address, int data)
{ {
switch (address & 0xF) switch (address & 0xF)
{ {
case 0x0: case 0x1: case 0x2: case 0x3: case 0x4: case 0x5: case 0x6: case 0x7: case 0x0: case 0x1: case 0x2: case 0x3: case 0x4: case 0x5: case 0x6: case 0x7:
SetPhase(address); SetPhase(address);
break; break;
case 0x8: case 0x8:
SetMotorOn(false); SetMotorOn(false);
break; break;
case 0x9: case 0x9:
SetMotorOn(true); SetMotorOn(true);
break; break;
case 0xA: case 0xA:
SetDriveNumber(0); SetDriveNumber(0);
break; break;
case 0xB: case 0xB:
SetDriveNumber(1); SetDriveNumber(1);
break; break;
case 0xC: case 0xC:
_loadMode = false; _loadMode = false;
if (_writeMode) if (_writeMode)
{ {
WriteLatch(); WriteLatch();
} }
break; break;
case 0xD: case 0xD:
_loadMode = true; _loadMode = true;
break; break;
case 0xE: case 0xE:
_writeMode = false; _writeMode = false;
break; break;
case 0xF: case 0xF:
_writeMode = true; _writeMode = true;
break; break;
} }
if (_motorOn && _writeMode) if (_motorOn && _writeMode)
{ {
if (_loadMode) if (_loadMode)
{ {
// any address writes latch for sequencer LD; OE1/2 irrelevant ['323 datasheet] // any address writes latch for sequencer LD; OE1/2 irrelevant ['323 datasheet]
_latch = data; _latch = data;
} }
} }
} }
private void WriteLatch() private void WriteLatch()
{ {
// write protect is forced if phase 1 is on [F9.7] // write protect is forced if phase 1 is on [F9.7]
if ((_phaseStates & Phase1On) == 0) if ((_phaseStates & Phase1On) == 0)
{ {
_drives[_driveNumber].Write(_latch); _drives[_driveNumber].Write(_latch);
} }
} }
private void Flush() private void Flush()
{ {
_drives[_driveNumber].FlushTrack(); _drives[_driveNumber].FlushTrack();
} }
private void SetDriveNumber(int driveNumber) private void SetDriveNumber(int driveNumber)
{ {
if (_driveNumber != driveNumber) if (_driveNumber != driveNumber)
{ {
Flush(); Flush();
_driveNumber = driveNumber; _driveNumber = driveNumber;
} }
} }
private void SetMotorOn(bool state) private void SetMotorOn(bool state)
{ {
if (_motorOn && !state) if (_motorOn && !state)
{ {
Flush(); Flush();
} }
_motorOn = state; _motorOn = state;
} }
private void SetPhase(int address) private void SetPhase(int address)
{ {
int phase = (address >> 1) & 0x3; int phase = (address >> 1) & 0x3;
int state = address & 1; int state = address & 1;
_phaseStates &= ~(1 << phase); _phaseStates &= ~(1 << phase);
_phaseStates |= (state << phase); _phaseStates |= (state << phase);
if (_motorOn) if (_motorOn)
{ {
_drives[_driveNumber].ApplyPhaseChange(_phaseStates); _drives[_driveNumber].ApplyPhaseChange(_phaseStates);
} }
} }
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
public DiskIIDrive[] Drives { get { return _drives; } } public DiskIIDrive[] Drives { get { return _drives; } }
private const int Phase0On = 1 << 0; private const int Phase0On = 1 << 0;
private const int Phase1On = 1 << 1; private const int Phase1On = 1 << 1;
private const int Phase2On = 1 << 2; private const int Phase2On = 1 << 2;
private const int Phase3On = 1 << 3; private const int Phase3On = 1 << 3;
private DiskIIDrive[] _drives = new DiskIIDrive[] { new DiskIIDrive(), new DiskIIDrive() }; private DiskIIDrive[] _drives = new DiskIIDrive[] { new DiskIIDrive(), new DiskIIDrive() };
private int _latch; private int _latch;
private int _phaseStates; private int _phaseStates;
private bool _motorOn; private bool _motorOn;
private int _driveNumber; private int _driveNumber;
private bool _loadMode; private bool _loadMode;
private bool _writeMode; private bool _writeMode;
private bool _driveSpin; private bool _driveSpin;
private byte[] _romRegionC1C7 = new byte[0x0100]; private byte[] _romRegionC1C7 = new byte[0x0100];
} }
} }

View File

@ -1,120 +1,120 @@
using System; using System;
using System.IO; using System.IO;
using System.Security; using System.Security;
using Jellyfish.Library; using Jellyfish.Library;
namespace Jellyfish.Virtu namespace Jellyfish.Virtu
{ {
public sealed class DiskIIDrive public sealed class DiskIIDrive
{ {
public DiskIIDrive() public DiskIIDrive()
{ {
DriveArmStepDelta[0] = new int[] { 0, 0, 1, 1, 0, 0, 1, 1, -1, -1, 0, 0, -1, -1, 0, 0 }; // phase 0 DriveArmStepDelta[0] = new int[] { 0, 0, 1, 1, 0, 0, 1, 1, -1, -1, 0, 0, -1, -1, 0, 0 }; // phase 0
DriveArmStepDelta[1] = new int[] { 0, -1, 0, -1, 1, 0, 1, 0, 0, -1, 0, -1, 1, 0, 1, 0 }; // phase 1 DriveArmStepDelta[1] = new int[] { 0, -1, 0, -1, 1, 0, 1, 0, 0, -1, 0, -1, 1, 0, 1, 0 }; // phase 1
DriveArmStepDelta[2] = new int[] { 0, 0, -1, -1, 0, 0, -1, -1, 1, 1, 0, 0, 1, 1, 0, 0 }; // phase 2 DriveArmStepDelta[2] = new int[] { 0, 0, -1, -1, 0, 0, -1, -1, 1, 1, 0, 0, 1, 1, 0, 0 }; // phase 2
DriveArmStepDelta[3] = new int[] { 0, 1, 0, 1, -1, 0, -1, 0, 0, 1, 0, 1, -1, 0, -1, 0 }; // phase 3 DriveArmStepDelta[3] = new int[] { 0, 1, 0, 1, -1, 0, -1, 0, 0, 1, 0, 1, -1, 0, -1, 0 }; // phase 3
} }
[SecurityCritical] [SecurityCritical]
public void InsertDisk(string fileName, bool isWriteProtected) public void InsertDisk(string fileName, bool isWriteProtected)
{ {
using (var stream = File.OpenRead(fileName)) using (var stream = File.OpenRead(fileName))
{ {
InsertDisk(fileName, stream, isWriteProtected); InsertDisk(fileName, stream, isWriteProtected);
} }
} }
public void InsertDisk(string name, Stream stream, bool isWriteProtected) public void InsertDisk(string name, Stream stream, bool isWriteProtected)
{ {
FlushTrack(); FlushTrack();
// TODO handle null param/empty string for eject, or add Eject() // TODO handle null param/empty string for eject, or add Eject()
_disk = Disk525.CreateDisk(name, stream.ReadAllBytes(), isWriteProtected); _disk = Disk525.CreateDisk(name, stream.ReadAllBytes(), isWriteProtected);
_trackLoaded = false; _trackLoaded = false;
} }
public void ApplyPhaseChange(int phaseState) public void ApplyPhaseChange(int phaseState)
{ {
// step the drive head according to stepper magnet changes // step the drive head according to stepper magnet changes
int delta = DriveArmStepDelta[_trackNumber & 0x3][phaseState]; int delta = DriveArmStepDelta[_trackNumber & 0x3][phaseState];
if (delta != 0) if (delta != 0)
{ {
int newTrackNumber = MathHelpers.Clamp(_trackNumber + delta, 0, TrackNumberMax); int newTrackNumber = MathHelpers.Clamp(_trackNumber + delta, 0, TrackNumberMax);
if (newTrackNumber != _trackNumber) if (newTrackNumber != _trackNumber)
{ {
FlushTrack(); FlushTrack();
_trackNumber = newTrackNumber; _trackNumber = newTrackNumber;
_trackOffset = 0; _trackOffset = 0;
_trackLoaded = false; _trackLoaded = false;
} }
} }
} }
public int Read() public int Read()
{ {
if (LoadTrack()) if (LoadTrack())
{ {
int data = _trackData[_trackOffset++]; int data = _trackData[_trackOffset++];
if (_trackOffset >= Disk525.TrackSize) if (_trackOffset >= Disk525.TrackSize)
{ {
_trackOffset = 0; _trackOffset = 0;
} }
return data; return data;
} }
return _random.Next(0x01, 0xFF); return _random.Next(0x01, 0xFF);
} }
public void Write(int data) public void Write(int data)
{ {
if (LoadTrack()) if (LoadTrack())
{ {
_trackChanged = true; _trackChanged = true;
_trackData[_trackOffset++] = (byte)data; _trackData[_trackOffset++] = (byte)data;
if (_trackOffset >= Disk525.TrackSize) if (_trackOffset >= Disk525.TrackSize)
{ {
_trackOffset = 0; _trackOffset = 0;
} }
} }
} }
private bool LoadTrack() private bool LoadTrack()
{ {
if (!_trackLoaded && (_disk != null)) if (!_trackLoaded && (_disk != null))
{ {
_disk.ReadTrack(_trackNumber, 0, _trackData); _disk.ReadTrack(_trackNumber, 0, _trackData);
_trackLoaded = true; _trackLoaded = true;
} }
return _trackLoaded; return _trackLoaded;
} }
public void FlushTrack() public void FlushTrack()
{ {
if (_trackChanged) if (_trackChanged)
{ {
_disk.WriteTrack(_trackNumber, 0, _trackData); _disk.WriteTrack(_trackNumber, 0, _trackData);
_trackChanged = false; _trackChanged = false;
} }
} }
public bool IsWriteProtected { get { return _disk.IsWriteProtected; } } public bool IsWriteProtected { get { return _disk.IsWriteProtected; } }
private const int TrackNumberMax = 0x44; private const int TrackNumberMax = 0x44;
private const int PhaseCount = 4; private const int PhaseCount = 4;
private readonly int[][] DriveArmStepDelta = new int[PhaseCount][]; private readonly int[][] DriveArmStepDelta = new int[PhaseCount][];
private Disk525 _disk; private Disk525 _disk;
private bool _trackLoaded; private bool _trackLoaded;
private bool _trackChanged; private bool _trackChanged;
private int _trackNumber; private int _trackNumber;
private int _trackOffset; private int _trackOffset;
private byte[] _trackData = new byte[Disk525.TrackSize]; private byte[] _trackData = new byte[Disk525.TrackSize];
private Random _random = new Random(); private Random _random = new Random();
} }
} }

View File

@ -1,22 +1,22 @@
using System; using System;
namespace Jellyfish.Virtu namespace Jellyfish.Virtu
{ {
public sealed class DiskNib : Disk525 public sealed class DiskNib : Disk525
{ {
public DiskNib(string name, byte[] data, bool isWriteProtected) : public DiskNib(string name, byte[] data, bool isWriteProtected) :
base(name, data, isWriteProtected) base(name, data, isWriteProtected)
{ {
} }
public override void ReadTrack(int number, int fraction, byte[] buffer) public override void ReadTrack(int number, int fraction, byte[] buffer)
{ {
Buffer.BlockCopy(Data, (number / 2) * TrackSize, buffer, 0, TrackSize); Buffer.BlockCopy(Data, (number / 2) * TrackSize, buffer, 0, TrackSize);
} }
public override void WriteTrack(int number, int fraction, byte[] buffer) public override void WriteTrack(int number, int fraction, byte[] buffer)
{ {
Buffer.BlockCopy(buffer, 0, Data, (number / 2) * TrackSize, TrackSize); Buffer.BlockCopy(buffer, 0, Data, (number / 2) * TrackSize, TrackSize);
} }
} }
} }

View File

@ -1,157 +1,157 @@
using System; using System;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using Jellyfish.Library; using Jellyfish.Library;
using Jellyfish.Virtu.Services; using Jellyfish.Virtu.Services;
namespace Jellyfish.Virtu namespace Jellyfish.Virtu
{ {
public sealed class GamePort : MachineComponent public sealed class GamePort : MachineComponent
{ {
public GamePort(Machine machine) : public GamePort(Machine machine) :
base(machine) base(machine)
{ {
_resetPaddle0StrobeEvent = ResetPaddle0StrobeEvent; // cache delegates; avoids garbage _resetPaddle0StrobeEvent = ResetPaddle0StrobeEvent; // cache delegates; avoids garbage
_resetPaddle1StrobeEvent = ResetPaddle1StrobeEvent; _resetPaddle1StrobeEvent = ResetPaddle1StrobeEvent;
_resetPaddle2StrobeEvent = ResetPaddle2StrobeEvent; _resetPaddle2StrobeEvent = ResetPaddle2StrobeEvent;
_resetPaddle3StrobeEvent = ResetPaddle3StrobeEvent; _resetPaddle3StrobeEvent = ResetPaddle3StrobeEvent;
} }
public override void Initialize() public override void Initialize()
{ {
_keyboardService = Machine.Services.GetService<KeyboardService>(); _keyboardService = Machine.Services.GetService<KeyboardService>();
_gamePortService = Machine.Services.GetService<GamePortService>(); _gamePortService = Machine.Services.GetService<GamePortService>();
} }
public bool ReadButton0() public bool ReadButton0()
{ {
var settings = Machine.Settings.GamePort; var settings = Machine.Settings.GamePort;
return (_gamePortService.IsButton0Down || _keyboardService.IsOpenAppleKeyDown || return (_gamePortService.IsButton0Down || _keyboardService.IsOpenAppleKeyDown ||
(settings.UseKeyboard && (settings.Key.Button0 > 0) && _keyboardService.IsKeyDown(settings.Key.Button0))); (settings.UseKeyboard && (settings.Key.Button0 > 0) && _keyboardService.IsKeyDown(settings.Key.Button0)));
} }
public bool ReadButton1() public bool ReadButton1()
{ {
var settings = Machine.Settings.GamePort; var settings = Machine.Settings.GamePort;
return (_gamePortService.IsButton1Down || _keyboardService.IsCloseAppleKeyDown || return (_gamePortService.IsButton1Down || _keyboardService.IsCloseAppleKeyDown ||
(settings.UseKeyboard && (settings.Key.Button1 > 0) && _keyboardService.IsKeyDown(settings.Key.Button1))); (settings.UseKeyboard && (settings.Key.Button1 > 0) && _keyboardService.IsKeyDown(settings.Key.Button1)));
} }
public bool ReadButton2() public bool ReadButton2()
{ {
var settings = Machine.Settings.GamePort; var settings = Machine.Settings.GamePort;
return (_gamePortService.IsButton2Down || _keyboardService.IsShiftKeyDown || // [TN9] return (_gamePortService.IsButton2Down || _keyboardService.IsShiftKeyDown || // [TN9]
(settings.UseKeyboard && (settings.Key.Button2 > 0) && _keyboardService.IsKeyDown(settings.Key.Button2))); (settings.UseKeyboard && (settings.Key.Button2 > 0) && _keyboardService.IsKeyDown(settings.Key.Button2)));
} }
[SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")] [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
public void TriggerTimers() public void TriggerTimers()
{ {
int paddle0 = _gamePortService.Paddle0; int paddle0 = _gamePortService.Paddle0;
int paddle1 = _gamePortService.Paddle1; int paddle1 = _gamePortService.Paddle1;
int paddle2 = _gamePortService.Paddle2; int paddle2 = _gamePortService.Paddle2;
int paddle3 = _gamePortService.Paddle3; int paddle3 = _gamePortService.Paddle3;
var settings = Machine.Settings.GamePort; var settings = Machine.Settings.GamePort;
if (settings.UseKeyboard) // override if (settings.UseKeyboard) // override
{ {
if (((settings.Key.Joystick0.UpLeft > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick0.UpLeft)) || if (((settings.Key.Joystick0.UpLeft > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick0.UpLeft)) ||
((settings.Key.Joystick0.Left > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick0.Left)) || ((settings.Key.Joystick0.Left > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick0.Left)) ||
((settings.Key.Joystick0.DownLeft > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick0.DownLeft))) ((settings.Key.Joystick0.DownLeft > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick0.DownLeft)))
{ {
paddle0 -= 128; paddle0 -= 128;
} }
if (((settings.Key.Joystick0.UpRight > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick0.UpRight)) || if (((settings.Key.Joystick0.UpRight > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick0.UpRight)) ||
((settings.Key.Joystick0.Right > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick0.Right)) || ((settings.Key.Joystick0.Right > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick0.Right)) ||
((settings.Key.Joystick0.DownRight > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick0.DownRight))) ((settings.Key.Joystick0.DownRight > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick0.DownRight)))
{ {
paddle0 += 128; paddle0 += 128;
} }
if (((settings.Key.Joystick0.UpLeft > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick0.UpLeft)) || if (((settings.Key.Joystick0.UpLeft > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick0.UpLeft)) ||
((settings.Key.Joystick0.Up > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick0.Up)) || ((settings.Key.Joystick0.Up > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick0.Up)) ||
((settings.Key.Joystick0.UpRight > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick0.UpRight))) ((settings.Key.Joystick0.UpRight > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick0.UpRight)))
{ {
paddle1 -= 128; paddle1 -= 128;
} }
if (((settings.Key.Joystick0.DownLeft > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick0.DownLeft)) || if (((settings.Key.Joystick0.DownLeft > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick0.DownLeft)) ||
((settings.Key.Joystick0.Down > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick0.Down)) || ((settings.Key.Joystick0.Down > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick0.Down)) ||
((settings.Key.Joystick0.DownRight > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick0.DownRight))) ((settings.Key.Joystick0.DownRight > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick0.DownRight)))
{ {
paddle1 += 128; paddle1 += 128;
} }
if (((settings.Key.Joystick1.UpLeft > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick1.UpLeft)) || if (((settings.Key.Joystick1.UpLeft > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick1.UpLeft)) ||
((settings.Key.Joystick1.Left > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick1.Left)) || ((settings.Key.Joystick1.Left > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick1.Left)) ||
((settings.Key.Joystick1.DownLeft > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick1.DownLeft))) ((settings.Key.Joystick1.DownLeft > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick1.DownLeft)))
{ {
paddle2 -= 128; paddle2 -= 128;
} }
if (((settings.Key.Joystick1.UpRight > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick1.UpRight)) || if (((settings.Key.Joystick1.UpRight > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick1.UpRight)) ||
((settings.Key.Joystick1.Right > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick1.Right)) || ((settings.Key.Joystick1.Right > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick1.Right)) ||
((settings.Key.Joystick1.DownRight > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick1.DownRight))) ((settings.Key.Joystick1.DownRight > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick1.DownRight)))
{ {
paddle2 += 128; paddle2 += 128;
} }
if (((settings.Key.Joystick1.UpLeft > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick1.UpLeft)) || if (((settings.Key.Joystick1.UpLeft > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick1.UpLeft)) ||
((settings.Key.Joystick1.Up > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick1.Up)) || ((settings.Key.Joystick1.Up > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick1.Up)) ||
((settings.Key.Joystick1.UpRight > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick1.UpRight))) ((settings.Key.Joystick1.UpRight > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick1.UpRight)))
{ {
paddle3 -= 128; paddle3 -= 128;
} }
if (((settings.Key.Joystick1.DownLeft > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick1.DownLeft)) || if (((settings.Key.Joystick1.DownLeft > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick1.DownLeft)) ||
((settings.Key.Joystick1.Down > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick1.Down)) || ((settings.Key.Joystick1.Down > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick1.Down)) ||
((settings.Key.Joystick1.DownRight > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick1.DownRight))) ((settings.Key.Joystick1.DownRight > 0) && _keyboardService.IsKeyDown(settings.Key.Joystick1.DownRight)))
{ {
paddle3 += 128; paddle3 += 128;
} }
} }
Paddle0Strobe = true; Paddle0Strobe = true;
Paddle1Strobe = true; Paddle1Strobe = true;
Paddle2Strobe = true; Paddle2Strobe = true;
Paddle3Strobe = true; Paddle3Strobe = true;
Machine.Events.AddEvent(MathHelpers.ClampByte(paddle0) * CyclesPerValue, _resetPaddle0StrobeEvent); // [7-29] Machine.Events.AddEvent(MathHelpers.ClampByte(paddle0) * CyclesPerValue, _resetPaddle0StrobeEvent); // [7-29]
Machine.Events.AddEvent(MathHelpers.ClampByte(paddle1) * CyclesPerValue, _resetPaddle1StrobeEvent); Machine.Events.AddEvent(MathHelpers.ClampByte(paddle1) * CyclesPerValue, _resetPaddle1StrobeEvent);
Machine.Events.AddEvent(MathHelpers.ClampByte(paddle2) * CyclesPerValue, _resetPaddle2StrobeEvent); Machine.Events.AddEvent(MathHelpers.ClampByte(paddle2) * CyclesPerValue, _resetPaddle2StrobeEvent);
Machine.Events.AddEvent(MathHelpers.ClampByte(paddle3) * CyclesPerValue, _resetPaddle3StrobeEvent); Machine.Events.AddEvent(MathHelpers.ClampByte(paddle3) * CyclesPerValue, _resetPaddle3StrobeEvent);
} }
private void ResetPaddle0StrobeEvent() private void ResetPaddle0StrobeEvent()
{ {
Paddle0Strobe = false; Paddle0Strobe = false;
} }
private void ResetPaddle1StrobeEvent() private void ResetPaddle1StrobeEvent()
{ {
Paddle1Strobe = false; Paddle1Strobe = false;
} }
private void ResetPaddle2StrobeEvent() private void ResetPaddle2StrobeEvent()
{ {
Paddle2Strobe = false; Paddle2Strobe = false;
} }
private void ResetPaddle3StrobeEvent() private void ResetPaddle3StrobeEvent()
{ {
Paddle3Strobe = false; Paddle3Strobe = false;
} }
public bool Paddle0Strobe { get; private set; } public bool Paddle0Strobe { get; private set; }
public bool Paddle1Strobe { get; private set; } public bool Paddle1Strobe { get; private set; }
public bool Paddle2Strobe { get; private set; } public bool Paddle2Strobe { get; private set; }
public bool Paddle3Strobe { get; private set; } public bool Paddle3Strobe { get; private set; }
private const int CyclesPerValue = 11; private const int CyclesPerValue = 11;
private Action _resetPaddle0StrobeEvent; private Action _resetPaddle0StrobeEvent;
private Action _resetPaddle1StrobeEvent; private Action _resetPaddle1StrobeEvent;
private Action _resetPaddle2StrobeEvent; private Action _resetPaddle2StrobeEvent;
private Action _resetPaddle3StrobeEvent; private Action _resetPaddle3StrobeEvent;
private KeyboardService _keyboardService; private KeyboardService _keyboardService;
private GamePortService _gamePortService; private GamePortService _gamePortService;
} }
} }

View File

@ -1,3 +1,3 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("Microsoft.Design", "CA2210:AssembliesShouldHaveValidStrongNames")] [assembly: SuppressMessage("Microsoft.Design", "CA2210:AssembliesShouldHaveValidStrongNames")]

View File

@ -1,128 +1,128 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using Jellyfish.Virtu.Services; using Jellyfish.Virtu.Services;
namespace Jellyfish.Virtu namespace Jellyfish.Virtu
{ {
public sealed class Keyboard : MachineComponent public sealed class Keyboard : MachineComponent
{ {
public Keyboard(Machine machine) : public Keyboard(Machine machine) :
base(machine) base(machine)
{ {
} }
public override void Initialize() public override void Initialize()
{ {
_keyboardService = Machine.Services.GetService<KeyboardService>(); _keyboardService = Machine.Services.GetService<KeyboardService>();
_gamePortService = Machine.Services.GetService<GamePortService>(); _gamePortService = Machine.Services.GetService<GamePortService>();
} }
[SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")] [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
public int ReadLatch() public int ReadLatch()
{ {
if (Strobe) if (Strobe)
{ {
return Latch; return Latch;
} }
var settings = Machine.Settings.Keyboard; var settings = Machine.Settings.Keyboard;
if (settings.UseGamePort) if (settings.UseGamePort)
{ {
if ((settings.Key.Joystick0.UpLeft > 0) && _gamePortService.Joystick0.IsUp && _gamePortService.Joystick0.IsLeft) if ((settings.Key.Joystick0.UpLeft > 0) && _gamePortService.Joystick0.IsUp && _gamePortService.Joystick0.IsLeft)
{ {
Latch = settings.Key.Joystick0.UpLeft; Latch = settings.Key.Joystick0.UpLeft;
} }
else if ((settings.Key.Joystick0.UpRight > 0) && _gamePortService.Joystick0.IsUp && _gamePortService.Joystick0.IsRight) else if ((settings.Key.Joystick0.UpRight > 0) && _gamePortService.Joystick0.IsUp && _gamePortService.Joystick0.IsRight)
{ {
Latch = settings.Key.Joystick0.UpRight; Latch = settings.Key.Joystick0.UpRight;
} }
else if ((settings.Key.Joystick0.DownLeft > 0) && _gamePortService.Joystick0.IsDown && _gamePortService.Joystick0.IsLeft) else if ((settings.Key.Joystick0.DownLeft > 0) && _gamePortService.Joystick0.IsDown && _gamePortService.Joystick0.IsLeft)
{ {
Latch = settings.Key.Joystick0.DownLeft; Latch = settings.Key.Joystick0.DownLeft;
} }
else if ((settings.Key.Joystick0.DownRight > 0) && _gamePortService.Joystick0.IsDown && _gamePortService.Joystick0.IsRight) else if ((settings.Key.Joystick0.DownRight > 0) && _gamePortService.Joystick0.IsDown && _gamePortService.Joystick0.IsRight)
{ {
Latch = settings.Key.Joystick0.DownRight; Latch = settings.Key.Joystick0.DownRight;
} }
else if ((settings.Key.Joystick0.Up > 0) && _gamePortService.Joystick0.IsUp) else if ((settings.Key.Joystick0.Up > 0) && _gamePortService.Joystick0.IsUp)
{ {
Latch = settings.Key.Joystick0.Up; Latch = settings.Key.Joystick0.Up;
} }
else if ((settings.Key.Joystick0.Left > 0) && _gamePortService.Joystick0.IsLeft) else if ((settings.Key.Joystick0.Left > 0) && _gamePortService.Joystick0.IsLeft)
{ {
Latch = settings.Key.Joystick0.Left; Latch = settings.Key.Joystick0.Left;
} }
else if ((settings.Key.Joystick0.Right > 0) && _gamePortService.Joystick0.IsRight) else if ((settings.Key.Joystick0.Right > 0) && _gamePortService.Joystick0.IsRight)
{ {
Latch = settings.Key.Joystick0.Right; Latch = settings.Key.Joystick0.Right;
} }
else if ((settings.Key.Joystick0.Down > 0) && _gamePortService.Joystick0.IsDown) else if ((settings.Key.Joystick0.Down > 0) && _gamePortService.Joystick0.IsDown)
{ {
Latch = settings.Key.Joystick0.Down; Latch = settings.Key.Joystick0.Down;
} }
if ((settings.Key.Joystick1.UpLeft > 0) && _gamePortService.Joystick1.IsUp && _gamePortService.Joystick1.IsLeft) // override if ((settings.Key.Joystick1.UpLeft > 0) && _gamePortService.Joystick1.IsUp && _gamePortService.Joystick1.IsLeft) // override
{ {
Latch = settings.Key.Joystick1.UpLeft; Latch = settings.Key.Joystick1.UpLeft;
} }
else if ((settings.Key.Joystick1.UpRight > 0) && _gamePortService.Joystick1.IsUp && _gamePortService.Joystick1.IsRight) else if ((settings.Key.Joystick1.UpRight > 0) && _gamePortService.Joystick1.IsUp && _gamePortService.Joystick1.IsRight)
{ {
Latch = settings.Key.Joystick1.UpRight; Latch = settings.Key.Joystick1.UpRight;
} }
else if ((settings.Key.Joystick1.DownLeft > 0) && _gamePortService.Joystick1.IsDown && _gamePortService.Joystick1.IsLeft) else if ((settings.Key.Joystick1.DownLeft > 0) && _gamePortService.Joystick1.IsDown && _gamePortService.Joystick1.IsLeft)
{ {
Latch = settings.Key.Joystick1.DownLeft; Latch = settings.Key.Joystick1.DownLeft;
} }
else if ((settings.Key.Joystick1.DownRight > 0) && _gamePortService.Joystick1.IsDown && _gamePortService.Joystick1.IsRight) else if ((settings.Key.Joystick1.DownRight > 0) && _gamePortService.Joystick1.IsDown && _gamePortService.Joystick1.IsRight)
{ {
Latch = settings.Key.Joystick1.DownRight; Latch = settings.Key.Joystick1.DownRight;
} }
else if ((settings.Key.Joystick1.Up > 0) && _gamePortService.Joystick1.IsUp) else if ((settings.Key.Joystick1.Up > 0) && _gamePortService.Joystick1.IsUp)
{ {
Latch = settings.Key.Joystick1.Up; Latch = settings.Key.Joystick1.Up;
} }
else if ((settings.Key.Joystick1.Left > 0) && _gamePortService.Joystick1.IsLeft) else if ((settings.Key.Joystick1.Left > 0) && _gamePortService.Joystick1.IsLeft)
{ {
Latch = settings.Key.Joystick1.Left; Latch = settings.Key.Joystick1.Left;
} }
else if ((settings.Key.Joystick1.Right > 0) && _gamePortService.Joystick1.IsRight) else if ((settings.Key.Joystick1.Right > 0) && _gamePortService.Joystick1.IsRight)
{ {
Latch = settings.Key.Joystick1.Right; Latch = settings.Key.Joystick1.Right;
} }
else if ((settings.Key.Joystick1.Down > 0) && _gamePortService.Joystick1.IsDown) else if ((settings.Key.Joystick1.Down > 0) && _gamePortService.Joystick1.IsDown)
{ {
Latch = settings.Key.Joystick1.Down; Latch = settings.Key.Joystick1.Down;
} }
if ((settings.Key.Button0 > 0) && _gamePortService.IsButton0Down) // override if ((settings.Key.Button0 > 0) && _gamePortService.IsButton0Down) // override
{ {
Latch = settings.Key.Button0; Latch = settings.Key.Button0;
} }
else if ((settings.Key.Button1 > 0) && _gamePortService.IsButton1Down) else if ((settings.Key.Button1 > 0) && _gamePortService.IsButton1Down)
{ {
Latch = settings.Key.Button1; Latch = settings.Key.Button1;
} }
else if ((settings.Key.Button2 > 0) && _gamePortService.IsButton2Down) else if ((settings.Key.Button2 > 0) && _gamePortService.IsButton2Down)
{ {
Latch = settings.Key.Button2; Latch = settings.Key.Button2;
} }
} }
return Latch; return Latch;
} }
public void ResetStrobe() public void ResetStrobe()
{ {
Strobe = false; Strobe = false;
} }
public bool IsAnyKeyDown { get { return _keyboardService.IsAnyKeyDown; } } public bool IsAnyKeyDown { get { return _keyboardService.IsAnyKeyDown; } }
public int Latch { get { return _latch; } set { _latch = value; Strobe = true; } } public int Latch { get { return _latch; } set { _latch = value; Strobe = true; } }
public bool Strobe { get; private set; } public bool Strobe { get; private set; }
private KeyboardService _keyboardService; private KeyboardService _keyboardService;
private GamePortService _gamePortService; private GamePortService _gamePortService;
private int _latch; private int _latch;
} }
} }

View File

@ -1,161 +1,161 @@
using System; using System;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Threading; using System.Threading;
using Jellyfish.Library; using Jellyfish.Library;
using Jellyfish.Virtu.Services; using Jellyfish.Virtu.Services;
using Jellyfish.Virtu.Settings; using Jellyfish.Virtu.Settings;
namespace Jellyfish.Virtu namespace Jellyfish.Virtu
{ {
public enum MachineState { Stopped = 0, Starting, Running, Pausing, Paused, Stopping } public enum MachineState { Stopped = 0, Starting, Running, Pausing, Paused, Stopping }
public sealed class Machine : IDisposable public sealed class Machine : IDisposable
{ {
public Machine() public Machine()
{ {
Events = new MachineEvents(); Events = new MachineEvents();
Services = new MachineServices(); Services = new MachineServices();
Settings = new MachineSettings(); Settings = new MachineSettings();
Cpu = new Cpu(this); Cpu = new Cpu(this);
Memory = new Memory(this); Memory = new Memory(this);
Keyboard = new Keyboard(this); Keyboard = new Keyboard(this);
GamePort = new GamePort(this); GamePort = new GamePort(this);
Cassette = new Cassette(this); Cassette = new Cassette(this);
Speaker = new Speaker(this); Speaker = new Speaker(this);
Video = new Video(this); Video = new Video(this);
NoSlotClock = new NoSlotClock(); NoSlotClock = new NoSlotClock();
var emptySlot = new PeripheralCard(this); var emptySlot = new PeripheralCard(this);
Slot1 = emptySlot; Slot1 = emptySlot;
Slot2 = emptySlot; Slot2 = emptySlot;
Slot3 = emptySlot; Slot3 = emptySlot;
Slot4 = emptySlot; Slot4 = emptySlot;
Slot5 = emptySlot; Slot5 = emptySlot;
Slot6 = new DiskIIController(this); Slot6 = new DiskIIController(this);
Slot7 = emptySlot; Slot7 = emptySlot;
Slots = new Collection<PeripheralCard> { null, Slot1, Slot2, Slot3, Slot4, Slot5, Slot6, Slot7 }; Slots = new Collection<PeripheralCard> { null, Slot1, Slot2, Slot3, Slot4, Slot5, Slot6, Slot7 };
Components = new Collection<MachineComponent> { Cpu, Memory, Keyboard, GamePort, Cassette, Speaker, Video, Slot1, Slot2, Slot3, Slot4, Slot5, Slot6, Slot7 }; Components = new Collection<MachineComponent> { Cpu, Memory, Keyboard, GamePort, Cassette, Speaker, Video, Slot1, Slot2, Slot3, Slot4, Slot5, Slot6, Slot7 };
Thread = new Thread(Run) { Name = "Machine" }; Thread = new Thread(Run) { Name = "Machine" };
} }
public void Dispose() public void Dispose()
{ {
_pauseEvent.Close(); _pauseEvent.Close();
_unpauseEvent.Close(); _unpauseEvent.Close();
} }
public void Reset() public void Reset()
{ {
Components.ForEach(component => component.Reset()); // while machine starting or paused Components.ForEach(component => component.Reset()); // while machine starting or paused
} }
public void Start() public void Start()
{ {
_storageService = Services.GetService<StorageService>(); _storageService = Services.GetService<StorageService>();
_storageService.Load(MachineSettings.FileName, stream => Settings.Deserialize(stream)); _storageService.Load(MachineSettings.FileName, stream => Settings.Deserialize(stream));
State = MachineState.Starting; State = MachineState.Starting;
Thread.Start(); Thread.Start();
} }
public void Pause() public void Pause()
{ {
State = MachineState.Pausing; State = MachineState.Pausing;
_pauseEvent.WaitOne(); _pauseEvent.WaitOne();
State = MachineState.Paused; State = MachineState.Paused;
} }
public void Unpause() public void Unpause()
{ {
State = MachineState.Running; State = MachineState.Running;
_unpauseEvent.Set(); _unpauseEvent.Set();
} }
public void Stop() public void Stop()
{ {
State = MachineState.Stopping; State = MachineState.Stopping;
_unpauseEvent.Set(); _unpauseEvent.Set();
Thread.IsAliveJoin(); Thread.IsAliveJoin();
State = MachineState.Stopped; State = MachineState.Stopped;
if (_storageService != null) if (_storageService != null)
{ {
_storageService.Save(MachineSettings.FileName, stream => Settings.Serialize(stream)); _storageService.Save(MachineSettings.FileName, stream => Settings.Serialize(stream));
} }
} }
public DiskIIController FindDiskIIController() public DiskIIController FindDiskIIController()
{ {
for (int i = 7; i >= 1; i--) for (int i = 7; i >= 1; i--)
{ {
var diskII = Slots[i] as DiskIIController; var diskII = Slots[i] as DiskIIController;
if (diskII != null) if (diskII != null)
{ {
return diskII; return diskII;
} }
} }
return null; return null;
} }
private void Run() // machine thread private void Run() // machine thread
{ {
Components.ForEach(component => component.Initialize()); Components.ForEach(component => component.Initialize());
Reset(); Reset();
State = MachineState.Running; State = MachineState.Running;
do do
{ {
do do
{ {
Events.HandleEvents(Cpu.Execute()); Events.HandleEvents(Cpu.Execute());
} }
while (State == MachineState.Running); while (State == MachineState.Running);
if (State == MachineState.Pausing) if (State == MachineState.Pausing)
{ {
_pauseEvent.Set(); _pauseEvent.Set();
_unpauseEvent.WaitOne(); _unpauseEvent.WaitOne();
} }
} }
while (State != MachineState.Stopping); while (State != MachineState.Stopping);
Components.ForEach(component => component.Uninitialize()); Components.ForEach(component => component.Uninitialize());
} }
public MachineEvents Events { get; private set; } public MachineEvents Events { get; private set; }
public MachineServices Services { get; private set; } public MachineServices Services { get; private set; }
public MachineSettings Settings { get; private set; } public MachineSettings Settings { get; private set; }
public MachineState State { get; private set; } public MachineState State { get; private set; }
public Cpu Cpu { get; private set; } public Cpu Cpu { get; private set; }
public Memory Memory { get; private set; } public Memory Memory { get; private set; }
public Keyboard Keyboard { get; private set; } public Keyboard Keyboard { get; private set; }
public GamePort GamePort { get; private set; } public GamePort GamePort { get; private set; }
public Cassette Cassette { get; private set; } public Cassette Cassette { get; private set; }
public Speaker Speaker { get; private set; } public Speaker Speaker { get; private set; }
public Video Video { get; private set; } public Video Video { get; private set; }
public NoSlotClock NoSlotClock { get; private set; } public NoSlotClock NoSlotClock { get; private set; }
public PeripheralCard Slot1 { get; private set; } public PeripheralCard Slot1 { get; private set; }
public PeripheralCard Slot2 { get; private set; } public PeripheralCard Slot2 { get; private set; }
public PeripheralCard Slot3 { get; private set; } public PeripheralCard Slot3 { get; private set; }
public PeripheralCard Slot4 { get; private set; } public PeripheralCard Slot4 { get; private set; }
public PeripheralCard Slot5 { get; private set; } public PeripheralCard Slot5 { get; private set; }
public PeripheralCard Slot6 { get; private set; } public PeripheralCard Slot6 { get; private set; }
public PeripheralCard Slot7 { get; private set; } public PeripheralCard Slot7 { get; private set; }
public Collection<PeripheralCard> Slots { get; private set; } public Collection<PeripheralCard> Slots { get; private set; }
public Collection<MachineComponent> Components { get; private set; } public Collection<MachineComponent> Components { get; private set; }
public Thread Thread { get; private set; } public Thread Thread { get; private set; }
private AutoResetEvent _pauseEvent = new AutoResetEvent(false); private AutoResetEvent _pauseEvent = new AutoResetEvent(false);
private AutoResetEvent _unpauseEvent = new AutoResetEvent(false); private AutoResetEvent _unpauseEvent = new AutoResetEvent(false);
private StorageService _storageService; private StorageService _storageService;
} }
} }

View File

@ -1,24 +1,24 @@
namespace Jellyfish.Virtu namespace Jellyfish.Virtu
{ {
public abstract class MachineComponent public abstract class MachineComponent
{ {
protected MachineComponent(Machine machine) protected MachineComponent(Machine machine)
{ {
Machine = machine; Machine = machine;
} }
public virtual void Initialize() public virtual void Initialize()
{ {
} }
public virtual void Reset() public virtual void Reset()
{ {
} }
public virtual void Uninitialize() public virtual void Uninitialize()
{ {
} }
protected Machine Machine { get; private set; } protected Machine Machine { get; private set; }
} }
} }

View File

@ -1,107 +1,107 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
namespace Jellyfish.Virtu namespace Jellyfish.Virtu
{ {
public sealed class MachineEvent public sealed class MachineEvent
{ {
public MachineEvent(int delta, Action action) public MachineEvent(int delta, Action action)
{ {
Delta = delta; Delta = delta;
Action = action; Action = action;
} }
public override string ToString() public override string ToString()
{ {
return string.Format(CultureInfo.CurrentCulture, "Delta = {0} Action = {{{1}.{2}}}", Delta, Action.Method.DeclaringType.Name, Action.Method.Name); return string.Format(CultureInfo.CurrentCulture, "Delta = {0} Action = {{{1}.{2}}}", Delta, Action.Method.DeclaringType.Name, Action.Method.Name);
} }
public int Delta { get; set; } public int Delta { get; set; }
public Action Action { get; set; } public Action Action { get; set; }
} }
public sealed class MachineEvents public sealed class MachineEvents
{ {
public void AddEvent(int delta, Action action) public void AddEvent(int delta, Action action)
{ {
var node = _used.First; var node = _used.First;
for (; node != null; node = node.Next) for (; node != null; node = node.Next)
{ {
if (delta < node.Value.Delta) if (delta < node.Value.Delta)
{ {
node.Value.Delta -= delta; node.Value.Delta -= delta;
break; break;
} }
if (node.Value.Delta > 0) if (node.Value.Delta > 0)
{ {
delta -= node.Value.Delta; delta -= node.Value.Delta;
} }
} }
var newNode = _free.First; var newNode = _free.First;
if (newNode != null) if (newNode != null)
{ {
_free.RemoveFirst(); _free.RemoveFirst();
newNode.Value.Delta = delta; newNode.Value.Delta = delta;
newNode.Value.Action = action; newNode.Value.Action = action;
} }
else else
{ {
newNode = new LinkedListNode<MachineEvent>(new MachineEvent(delta, action)); newNode = new LinkedListNode<MachineEvent>(new MachineEvent(delta, action));
} }
if (node != null) if (node != null)
{ {
_used.AddBefore(node, newNode); _used.AddBefore(node, newNode);
} }
else else
{ {
_used.AddLast(newNode); _used.AddLast(newNode);
} }
} }
public int FindEvent(Action action) public int FindEvent(Action action)
{ {
int delta = 0; int delta = 0;
for (var node = _used.First; node != null; node = node.Next) for (var node = _used.First; node != null; node = node.Next)
{ {
delta += node.Value.Delta; delta += node.Value.Delta;
if (object.ReferenceEquals(node.Value.Action, action)) // assumes delegate cached if (object.ReferenceEquals(node.Value.Action, action)) // assumes delegate cached
{ {
return delta; return delta;
} }
} }
return 0; return 0;
} }
public void HandleEvents(int delta) public void HandleEvents(int delta)
{ {
var node = _used.First; var node = _used.First;
node.Value.Delta -= delta; node.Value.Delta -= delta;
while (node.Value.Delta <= 0) while (node.Value.Delta <= 0)
{ {
node.Value.Action(); node.Value.Action();
RemoveEvent(node); RemoveEvent(node);
node = _used.First; node = _used.First;
} }
} }
private void RemoveEvent(LinkedListNode<MachineEvent> node) private void RemoveEvent(LinkedListNode<MachineEvent> node)
{ {
if (node.Next != null) if (node.Next != null)
{ {
node.Next.Value.Delta += node.Value.Delta; node.Next.Value.Delta += node.Value.Delta;
} }
_used.Remove(node); _used.Remove(node);
_free.AddFirst(node); // cache node; avoids garbage _free.AddFirst(node); // cache node; avoids garbage
} }
private LinkedList<MachineEvent> _used = new LinkedList<MachineEvent>(); private LinkedList<MachineEvent> _used = new LinkedList<MachineEvent>();
private LinkedList<MachineEvent> _free = new LinkedList<MachineEvent>(); private LinkedList<MachineEvent> _free = new LinkedList<MachineEvent>();
} }
} }

View File

@ -1,412 +1,412 @@
using System; using System;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.IO; using System.IO;
using System.Xml; using System.Xml;
using System.Xml.Linq; using System.Xml.Linq;
namespace Jellyfish.Virtu.Settings namespace Jellyfish.Virtu.Settings
{ {
public sealed class MachineSettings public sealed class MachineSettings
{ {
public MachineSettings() public MachineSettings()
{ {
Cpu = new CpuSettings { Is65C02 = true, IsThrottled = true, Multiplier = 1 }; Cpu = new CpuSettings { Is65C02 = true, IsThrottled = true, Multiplier = 1 };
DiskII = new DiskIISettings DiskII = new DiskIISettings
{ {
Disk1 = new DiskSettings { Name = string.Empty, IsWriteProtected = false }, Disk1 = new DiskSettings { Name = string.Empty, IsWriteProtected = false },
Disk2 = new DiskSettings { Name = string.Empty, IsWriteProtected = false } Disk2 = new DiskSettings { Name = string.Empty, IsWriteProtected = false }
}; };
Keyboard = new KeyboardSettings Keyboard = new KeyboardSettings
{ {
UseGamePort = false, UseGamePort = false,
Key = new KeySettings Key = new KeySettings
{ {
Joystick0 = new JoystickSettings { UpLeft = 0, Up = 'I', UpRight = 0, Left = 'J', Right = 'L', DownLeft = 0, Down = 'K', DownRight = 0 }, Joystick0 = new JoystickSettings { UpLeft = 0, Up = 'I', UpRight = 0, Left = 'J', Right = 'L', DownLeft = 0, Down = 'K', DownRight = 0 },
Joystick1 = new JoystickSettings { UpLeft = 0, Up = 'E', UpRight = 0, Left = 'S', Right = 'F', DownLeft = 0, Down = 'D', DownRight = 0 }, Joystick1 = new JoystickSettings { UpLeft = 0, Up = 'E', UpRight = 0, Left = 'S', Right = 'F', DownLeft = 0, Down = 'D', DownRight = 0 },
Button0 = 0, Button1 = 0, Button2 = 0 Button0 = 0, Button1 = 0, Button2 = 0
} }
}; };
GamePort = new GamePortSettings GamePort = new GamePortSettings
{ {
UseKeyboard = false, UseKeyboard = false,
Key = new KeySettings Key = new KeySettings
{ {
Joystick0 = new JoystickSettings { UpLeft = 0, Up = 0, UpRight = 0, Left = 0, Right = 0, DownLeft = 0, Down = 0, DownRight = 0 }, Joystick0 = new JoystickSettings { UpLeft = 0, Up = 0, UpRight = 0, Left = 0, Right = 0, DownLeft = 0, Down = 0, DownRight = 0 },
Joystick1 = new JoystickSettings { UpLeft = 0, Up = 0, UpRight = 0, Left = 0, Right = 0, DownLeft = 0, Down = 0, DownRight = 0 }, Joystick1 = new JoystickSettings { UpLeft = 0, Up = 0, UpRight = 0, Left = 0, Right = 0, DownLeft = 0, Down = 0, DownRight = 0 },
Button0 = 0, Button1 = 0, Button2 = 0 Button0 = 0, Button1 = 0, Button2 = 0
} }
}; };
#if WINDOWS_PHONE #if WINDOWS_PHONE
Audio = new AudioSettings { Volume = 0.85 }; Audio = new AudioSettings { Volume = 0.85 };
#else #else
Audio = new AudioSettings { Volume = 0.5 }; Audio = new AudioSettings { Volume = 0.5 };
#endif #endif
Video = new VideoSettings Video = new VideoSettings
{ {
IsFullScreen = false, IsMonochrome = false, ScannerOptions = ScannerOptions.None, IsFullScreen = false, IsMonochrome = false, ScannerOptions = ScannerOptions.None,
Color = new ColorSettings Color = new ColorSettings
{ {
Black = 0xFF000000, // BGRA Black = 0xFF000000, // BGRA
DarkBlue = 0xFF000099, DarkBlue = 0xFF000099,
DarkGreen = 0xFF117722, DarkGreen = 0xFF117722,
MediumBlue = 0xFF0000FF, MediumBlue = 0xFF0000FF,
Brown = 0xFF885500, Brown = 0xFF885500,
LightGrey = 0xFF99AAAA, LightGrey = 0xFF99AAAA,
Green = 0xFF00EE11, Green = 0xFF00EE11,
Aquamarine = 0xFF55FFAA, Aquamarine = 0xFF55FFAA,
DeepRed = 0xFFFF1111, DeepRed = 0xFFFF1111,
Purple = 0xFFDD00DD, Purple = 0xFFDD00DD,
DarkGrey = 0xFF445555, DarkGrey = 0xFF445555,
LightBlue = 0xFF33AAFF, LightBlue = 0xFF33AAFF,
Orange = 0xFFFF4411, Orange = 0xFFFF4411,
Pink = 0xFFFF9988, Pink = 0xFFFF9988,
Yellow = 0xFFFFFF11, Yellow = 0xFFFFFF11,
White = 0xFFFFFFFF, White = 0xFFFFFFFF,
Monochrome = 0xFF00AA00 Monochrome = 0xFF00AA00
} }
}; };
} }
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")] [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
public void Deserialize(Stream stream) public void Deserialize(Stream stream)
{ {
try try
{ {
using (var reader = XmlReader.Create(stream)) using (var reader = XmlReader.Create(stream))
{ {
var ns = Namespace; var ns = Namespace;
var root = XElement.Load(reader); var root = XElement.Load(reader);
var cpu = root.Element(ns + "Cpu"); var cpu = root.Element(ns + "Cpu");
Cpu = new CpuSettings Cpu = new CpuSettings
{ {
Is65C02 = (bool)cpu.Attribute("Is65C02"), Is65C02 = (bool)cpu.Attribute("Is65C02"),
IsThrottled = (bool)cpu.Attribute("IsThrottled"), IsThrottled = (bool)cpu.Attribute("IsThrottled"),
Multiplier = (int)cpu.Attribute("Multiplier") Multiplier = (int)cpu.Attribute("Multiplier")
}; };
var diskII = root.Element(ns + "DiskII"); var diskII = root.Element(ns + "DiskII");
var disk1 = diskII.Element(ns + "Disk1"); var disk1 = diskII.Element(ns + "Disk1");
var disk2 = diskII.Element(ns + "Disk2"); var disk2 = diskII.Element(ns + "Disk2");
DiskII = new DiskIISettings DiskII = new DiskIISettings
{ {
Disk1 = new DiskSettings Disk1 = new DiskSettings
{ {
Name = (string)disk1.Attribute("Name") ?? string.Empty, Name = (string)disk1.Attribute("Name") ?? string.Empty,
IsWriteProtected = (bool)disk1.Attribute("IsWriteProtected") IsWriteProtected = (bool)disk1.Attribute("IsWriteProtected")
}, },
Disk2 = new DiskSettings Disk2 = new DiskSettings
{ {
Name = (string)disk2.Attribute("Name") ?? string.Empty, Name = (string)disk2.Attribute("Name") ?? string.Empty,
IsWriteProtected = (bool)disk2.Attribute("IsWriteProtected") IsWriteProtected = (bool)disk2.Attribute("IsWriteProtected")
}, },
}; };
var keyboard = root.Element(ns + "Keyboard"); var keyboard = root.Element(ns + "Keyboard");
var key = keyboard.Element(ns + "Key"); var key = keyboard.Element(ns + "Key");
var joystick0 = key.Element(ns + "Joystick0"); var joystick0 = key.Element(ns + "Joystick0");
var joystick1 = key.Element(ns + "Joystick1"); var joystick1 = key.Element(ns + "Joystick1");
var buttons = key.Element(ns + "Buttons"); var buttons = key.Element(ns + "Buttons");
Keyboard = new KeyboardSettings Keyboard = new KeyboardSettings
{ {
UseGamePort = (bool)keyboard.Attribute("UseGamePort"), UseGamePort = (bool)keyboard.Attribute("UseGamePort"),
Key = new KeySettings Key = new KeySettings
{ {
Joystick0 = new JoystickSettings Joystick0 = new JoystickSettings
{ {
UpLeft = (int)joystick0.Attribute("UpLeft"), UpLeft = (int)joystick0.Attribute("UpLeft"),
Up = (int)joystick0.Attribute("Up"), Up = (int)joystick0.Attribute("Up"),
UpRight = (int)joystick0.Attribute("UpRight"), UpRight = (int)joystick0.Attribute("UpRight"),
Left = (int)joystick0.Attribute("Left"), Left = (int)joystick0.Attribute("Left"),
Right = (int)joystick0.Attribute("Right"), Right = (int)joystick0.Attribute("Right"),
DownLeft = (int)joystick0.Attribute("DownLeft"), DownLeft = (int)joystick0.Attribute("DownLeft"),
Down = (int)joystick0.Attribute("Down"), Down = (int)joystick0.Attribute("Down"),
DownRight = (int)joystick0.Attribute("DownRight") DownRight = (int)joystick0.Attribute("DownRight")
}, },
Joystick1 = new JoystickSettings Joystick1 = new JoystickSettings
{ {
UpLeft = (int)joystick1.Attribute("UpLeft"), UpLeft = (int)joystick1.Attribute("UpLeft"),
Up = (int)joystick1.Attribute("Up"), Up = (int)joystick1.Attribute("Up"),
UpRight = (int)joystick1.Attribute("UpRight"), UpRight = (int)joystick1.Attribute("UpRight"),
Left = (int)joystick1.Attribute("Left"), Left = (int)joystick1.Attribute("Left"),
Right = (int)joystick1.Attribute("Right"), Right = (int)joystick1.Attribute("Right"),
DownLeft = (int)joystick1.Attribute("DownLeft"), DownLeft = (int)joystick1.Attribute("DownLeft"),
Down = (int)joystick1.Attribute("Down"), Down = (int)joystick1.Attribute("Down"),
DownRight = (int)joystick1.Attribute("DownRight") DownRight = (int)joystick1.Attribute("DownRight")
}, },
Button0 = (int)buttons.Attribute("Button0"), Button0 = (int)buttons.Attribute("Button0"),
Button1 = (int)buttons.Attribute("Button1"), Button1 = (int)buttons.Attribute("Button1"),
Button2 = (int)buttons.Attribute("Button2") Button2 = (int)buttons.Attribute("Button2")
} }
}; };
var gamePort = root.Element(ns + "GamePort"); var gamePort = root.Element(ns + "GamePort");
key = gamePort.Element(ns + "Key"); key = gamePort.Element(ns + "Key");
joystick0 = key.Element(ns + "Joystick0"); joystick0 = key.Element(ns + "Joystick0");
joystick1 = key.Element(ns + "Joystick1"); joystick1 = key.Element(ns + "Joystick1");
buttons = key.Element(ns + "Buttons"); buttons = key.Element(ns + "Buttons");
GamePort = new GamePortSettings GamePort = new GamePortSettings
{ {
UseKeyboard = (bool)gamePort.Attribute("UseKeyboard"), UseKeyboard = (bool)gamePort.Attribute("UseKeyboard"),
Key = new KeySettings Key = new KeySettings
{ {
Joystick0 = new JoystickSettings Joystick0 = new JoystickSettings
{ {
UpLeft = (int)joystick0.Attribute("UpLeft"), UpLeft = (int)joystick0.Attribute("UpLeft"),
Up = (int)joystick0.Attribute("Up"), Up = (int)joystick0.Attribute("Up"),
UpRight = (int)joystick0.Attribute("UpRight"), UpRight = (int)joystick0.Attribute("UpRight"),
Left = (int)joystick0.Attribute("Left"), Left = (int)joystick0.Attribute("Left"),
Right = (int)joystick0.Attribute("Right"), Right = (int)joystick0.Attribute("Right"),
DownLeft = (int)joystick0.Attribute("DownLeft"), DownLeft = (int)joystick0.Attribute("DownLeft"),
Down = (int)joystick0.Attribute("Down"), Down = (int)joystick0.Attribute("Down"),
DownRight = (int)joystick0.Attribute("DownRight") DownRight = (int)joystick0.Attribute("DownRight")
}, },
Joystick1 = new JoystickSettings Joystick1 = new JoystickSettings
{ {
UpLeft = (int)joystick1.Attribute("UpLeft"), UpLeft = (int)joystick1.Attribute("UpLeft"),
Up = (int)joystick1.Attribute("Up"), Up = (int)joystick1.Attribute("Up"),
UpRight = (int)joystick1.Attribute("UpRight"), UpRight = (int)joystick1.Attribute("UpRight"),
Left = (int)joystick1.Attribute("Left"), Left = (int)joystick1.Attribute("Left"),
Right = (int)joystick1.Attribute("Right"), Right = (int)joystick1.Attribute("Right"),
DownLeft = (int)joystick1.Attribute("DownLeft"), DownLeft = (int)joystick1.Attribute("DownLeft"),
Down = (int)joystick1.Attribute("Down"), Down = (int)joystick1.Attribute("Down"),
DownRight = (int)joystick1.Attribute("DownRight") DownRight = (int)joystick1.Attribute("DownRight")
}, },
Button0 = (int)buttons.Attribute("Button0"), Button0 = (int)buttons.Attribute("Button0"),
Button1 = (int)buttons.Attribute("Button1"), Button1 = (int)buttons.Attribute("Button1"),
Button2 = (int)buttons.Attribute("Button2") Button2 = (int)buttons.Attribute("Button2")
} }
}; };
var audio = root.Element(ns + "Audio"); var audio = root.Element(ns + "Audio");
Audio = new AudioSettings Audio = new AudioSettings
{ {
Volume = (double)audio.Attribute("Volume") Volume = (double)audio.Attribute("Volume")
}; };
var video = root.Element(ns + "Video"); var video = root.Element(ns + "Video");
var color = video.Element(ns + "Color"); var color = video.Element(ns + "Color");
Video = new VideoSettings Video = new VideoSettings
{ {
IsFullScreen = (bool)video.Attribute("IsFullScreen"), IsFullScreen = (bool)video.Attribute("IsFullScreen"),
IsMonochrome = (bool)video.Attribute("IsMonochrome"), IsMonochrome = (bool)video.Attribute("IsMonochrome"),
ScannerOptions = (ScannerOptions)Enum.Parse(typeof(ScannerOptions), (string)video.Attribute("ScannerOptions"), true), ScannerOptions = (ScannerOptions)Enum.Parse(typeof(ScannerOptions), (string)video.Attribute("ScannerOptions"), true),
Color = new ColorSettings Color = new ColorSettings
{ {
Black = (uint)color.Attribute("Black"), Black = (uint)color.Attribute("Black"),
DarkBlue = (uint)color.Attribute("DarkBlue"), DarkBlue = (uint)color.Attribute("DarkBlue"),
DarkGreen = (uint)color.Attribute("DarkGreen"), DarkGreen = (uint)color.Attribute("DarkGreen"),
MediumBlue = (uint)color.Attribute("MediumBlue"), MediumBlue = (uint)color.Attribute("MediumBlue"),
Brown = (uint)color.Attribute("Brown"), Brown = (uint)color.Attribute("Brown"),
LightGrey = (uint)color.Attribute("LightGrey"), LightGrey = (uint)color.Attribute("LightGrey"),
Green = (uint)color.Attribute("Green"), Green = (uint)color.Attribute("Green"),
Aquamarine = (uint)color.Attribute("Aquamarine"), Aquamarine = (uint)color.Attribute("Aquamarine"),
DeepRed = (uint)color.Attribute("DeepRed"), DeepRed = (uint)color.Attribute("DeepRed"),
Purple = (uint)color.Attribute("Purple"), Purple = (uint)color.Attribute("Purple"),
DarkGrey = (uint)color.Attribute("DarkGrey"), DarkGrey = (uint)color.Attribute("DarkGrey"),
LightBlue = (uint)color.Attribute("LightBlue"), LightBlue = (uint)color.Attribute("LightBlue"),
Orange = (uint)color.Attribute("Orange"), Orange = (uint)color.Attribute("Orange"),
Pink = (uint)color.Attribute("Pink"), Pink = (uint)color.Attribute("Pink"),
Yellow = (uint)color.Attribute("Yellow"), Yellow = (uint)color.Attribute("Yellow"),
White = (uint)color.Attribute("White"), White = (uint)color.Attribute("White"),
Monochrome = (uint)color.Attribute("Monochrome") Monochrome = (uint)color.Attribute("Monochrome")
} }
}; };
} }
} }
catch (Exception) catch (Exception)
{ {
} }
} }
public void Serialize(Stream stream) public void Serialize(Stream stream)
{ {
var ns = Namespace; var ns = Namespace;
var xml = new XElement(ns + "MachineSettings", var xml = new XElement(ns + "MachineSettings",
new XElement(ns + "Cpu", new XElement(ns + "Cpu",
new XAttribute("Is65C02", Cpu.Is65C02), new XAttribute("Is65C02", Cpu.Is65C02),
new XAttribute("IsThrottled", Cpu.IsThrottled), new XAttribute("IsThrottled", Cpu.IsThrottled),
new XAttribute("Multiplier", Cpu.Multiplier)), new XAttribute("Multiplier", Cpu.Multiplier)),
new XElement(ns + "DiskII", new XElement(ns + "DiskII",
new XElement(ns + "Disk1", new XElement(ns + "Disk1",
new XAttribute("Name", DiskII.Disk1.Name), new XAttribute("Name", DiskII.Disk1.Name),
new XAttribute("IsWriteProtected", DiskII.Disk1.IsWriteProtected)), new XAttribute("IsWriteProtected", DiskII.Disk1.IsWriteProtected)),
new XElement(ns + "Disk2", new XElement(ns + "Disk2",
new XAttribute("Name", DiskII.Disk2.Name), new XAttribute("Name", DiskII.Disk2.Name),
new XAttribute("IsWriteProtected", DiskII.Disk2.IsWriteProtected))), new XAttribute("IsWriteProtected", DiskII.Disk2.IsWriteProtected))),
new XElement(ns + "Keyboard", new XElement(ns + "Keyboard",
new XAttribute("UseGamePort", Keyboard.UseGamePort), new XAttribute("UseGamePort", Keyboard.UseGamePort),
new XElement(ns + "Key", new XElement(ns + "Key",
new XElement(ns + "Joystick0", new XElement(ns + "Joystick0",
new XAttribute("UpLeft", Keyboard.Key.Joystick0.UpLeft), new XAttribute("UpLeft", Keyboard.Key.Joystick0.UpLeft),
new XAttribute("Up", Keyboard.Key.Joystick0.Up), new XAttribute("Up", Keyboard.Key.Joystick0.Up),
new XAttribute("UpRight", Keyboard.Key.Joystick0.UpRight), new XAttribute("UpRight", Keyboard.Key.Joystick0.UpRight),
new XAttribute("Left", Keyboard.Key.Joystick0.Left), new XAttribute("Left", Keyboard.Key.Joystick0.Left),
new XAttribute("Right", Keyboard.Key.Joystick0.Right), new XAttribute("Right", Keyboard.Key.Joystick0.Right),
new XAttribute("DownLeft", Keyboard.Key.Joystick0.DownLeft), new XAttribute("DownLeft", Keyboard.Key.Joystick0.DownLeft),
new XAttribute("Down", Keyboard.Key.Joystick0.Down), new XAttribute("Down", Keyboard.Key.Joystick0.Down),
new XAttribute("DownRight", Keyboard.Key.Joystick0.DownRight)), new XAttribute("DownRight", Keyboard.Key.Joystick0.DownRight)),
new XElement(ns + "Joystick1", new XElement(ns + "Joystick1",
new XAttribute("UpLeft", Keyboard.Key.Joystick1.UpLeft), new XAttribute("UpLeft", Keyboard.Key.Joystick1.UpLeft),
new XAttribute("Up", Keyboard.Key.Joystick1.Up), new XAttribute("Up", Keyboard.Key.Joystick1.Up),
new XAttribute("UpRight", Keyboard.Key.Joystick1.UpRight), new XAttribute("UpRight", Keyboard.Key.Joystick1.UpRight),
new XAttribute("Left", Keyboard.Key.Joystick1.Left), new XAttribute("Left", Keyboard.Key.Joystick1.Left),
new XAttribute("Right", Keyboard.Key.Joystick1.Right), new XAttribute("Right", Keyboard.Key.Joystick1.Right),
new XAttribute("DownLeft", Keyboard.Key.Joystick1.DownLeft), new XAttribute("DownLeft", Keyboard.Key.Joystick1.DownLeft),
new XAttribute("Down", Keyboard.Key.Joystick1.Down), new XAttribute("Down", Keyboard.Key.Joystick1.Down),
new XAttribute("DownRight", Keyboard.Key.Joystick1.DownRight)), new XAttribute("DownRight", Keyboard.Key.Joystick1.DownRight)),
new XElement(ns + "Buttons", new XElement(ns + "Buttons",
new XAttribute("Button0", Keyboard.Key.Button0), new XAttribute("Button0", Keyboard.Key.Button0),
new XAttribute("Button1", Keyboard.Key.Button1), new XAttribute("Button1", Keyboard.Key.Button1),
new XAttribute("Button2", Keyboard.Key.Button2)))), new XAttribute("Button2", Keyboard.Key.Button2)))),
new XElement(ns + "GamePort", new XElement(ns + "GamePort",
new XAttribute("UseKeyboard", GamePort.UseKeyboard), new XAttribute("UseKeyboard", GamePort.UseKeyboard),
new XElement(ns + "Key", new XElement(ns + "Key",
new XElement(ns + "Joystick0", new XElement(ns + "Joystick0",
new XAttribute("UpLeft", GamePort.Key.Joystick0.UpLeft), new XAttribute("UpLeft", GamePort.Key.Joystick0.UpLeft),
new XAttribute("Up", GamePort.Key.Joystick0.Up), new XAttribute("Up", GamePort.Key.Joystick0.Up),
new XAttribute("UpRight", GamePort.Key.Joystick0.UpRight), new XAttribute("UpRight", GamePort.Key.Joystick0.UpRight),
new XAttribute("Left", GamePort.Key.Joystick0.Left), new XAttribute("Left", GamePort.Key.Joystick0.Left),
new XAttribute("Right", GamePort.Key.Joystick0.Right), new XAttribute("Right", GamePort.Key.Joystick0.Right),
new XAttribute("DownLeft", GamePort.Key.Joystick0.DownLeft), new XAttribute("DownLeft", GamePort.Key.Joystick0.DownLeft),
new XAttribute("Down", GamePort.Key.Joystick0.Down), new XAttribute("Down", GamePort.Key.Joystick0.Down),
new XAttribute("DownRight", GamePort.Key.Joystick0.DownRight)), new XAttribute("DownRight", GamePort.Key.Joystick0.DownRight)),
new XElement(ns + "Joystick1", new XElement(ns + "Joystick1",
new XAttribute("UpLeft", GamePort.Key.Joystick1.UpLeft), new XAttribute("UpLeft", GamePort.Key.Joystick1.UpLeft),
new XAttribute("Up", GamePort.Key.Joystick1.Up), new XAttribute("Up", GamePort.Key.Joystick1.Up),
new XAttribute("UpRight", GamePort.Key.Joystick1.UpRight), new XAttribute("UpRight", GamePort.Key.Joystick1.UpRight),
new XAttribute("Left", GamePort.Key.Joystick1.Left), new XAttribute("Left", GamePort.Key.Joystick1.Left),
new XAttribute("Right", GamePort.Key.Joystick1.Right), new XAttribute("Right", GamePort.Key.Joystick1.Right),
new XAttribute("DownLeft", GamePort.Key.Joystick1.DownLeft), new XAttribute("DownLeft", GamePort.Key.Joystick1.DownLeft),
new XAttribute("Down", GamePort.Key.Joystick1.Down), new XAttribute("Down", GamePort.Key.Joystick1.Down),
new XAttribute("DownRight", GamePort.Key.Joystick1.DownRight)), new XAttribute("DownRight", GamePort.Key.Joystick1.DownRight)),
new XElement(ns + "Buttons", new XElement(ns + "Buttons",
new XAttribute("Button0", Keyboard.Key.Button0), new XAttribute("Button0", Keyboard.Key.Button0),
new XAttribute("Button1", Keyboard.Key.Button1), new XAttribute("Button1", Keyboard.Key.Button1),
new XAttribute("Button2", Keyboard.Key.Button2)))), new XAttribute("Button2", Keyboard.Key.Button2)))),
new XElement(ns + "Audio", new XElement(ns + "Audio",
new XAttribute("Volume", Audio.Volume)), new XAttribute("Volume", Audio.Volume)),
new XElement(ns + "Video", new XElement(ns + "Video",
new XAttribute("IsFullScreen", Video.IsFullScreen), new XAttribute("IsFullScreen", Video.IsFullScreen),
new XAttribute("IsMonochrome", Video.IsMonochrome), new XAttribute("IsMonochrome", Video.IsMonochrome),
new XAttribute("ScannerOptions", Video.ScannerOptions), new XAttribute("ScannerOptions", Video.ScannerOptions),
new XElement(ns + "Color", new XElement(ns + "Color",
new XAttribute("Black", Video.Color.Black), new XAttribute("Black", Video.Color.Black),
new XAttribute("DarkBlue", Video.Color.DarkBlue), new XAttribute("DarkBlue", Video.Color.DarkBlue),
new XAttribute("DarkGreen", Video.Color.DarkGreen), new XAttribute("DarkGreen", Video.Color.DarkGreen),
new XAttribute("MediumBlue", Video.Color.MediumBlue), new XAttribute("MediumBlue", Video.Color.MediumBlue),
new XAttribute("Brown", Video.Color.Brown), new XAttribute("Brown", Video.Color.Brown),
new XAttribute("LightGrey", Video.Color.LightGrey), new XAttribute("LightGrey", Video.Color.LightGrey),
new XAttribute("Green", Video.Color.Green), new XAttribute("Green", Video.Color.Green),
new XAttribute("Aquamarine", Video.Color.Aquamarine), new XAttribute("Aquamarine", Video.Color.Aquamarine),
new XAttribute("DeepRed", Video.Color.DeepRed), new XAttribute("DeepRed", Video.Color.DeepRed),
new XAttribute("Purple", Video.Color.Purple), new XAttribute("Purple", Video.Color.Purple),
new XAttribute("DarkGrey", Video.Color.DarkGrey), new XAttribute("DarkGrey", Video.Color.DarkGrey),
new XAttribute("LightBlue", Video.Color.LightBlue), new XAttribute("LightBlue", Video.Color.LightBlue),
new XAttribute("Orange", Video.Color.Orange), new XAttribute("Orange", Video.Color.Orange),
new XAttribute("Pink", Video.Color.Pink), new XAttribute("Pink", Video.Color.Pink),
new XAttribute("Yellow", Video.Color.Yellow), new XAttribute("Yellow", Video.Color.Yellow),
new XAttribute("White", Video.Color.White), new XAttribute("White", Video.Color.White),
new XAttribute("Monochrome", Video.Color.Monochrome)))); new XAttribute("Monochrome", Video.Color.Monochrome))));
using (var writer = XmlWriter.Create(stream)) using (var writer = XmlWriter.Create(stream))
{ {
xml.WriteTo(writer); xml.WriteTo(writer);
} }
} }
public CpuSettings Cpu { get; set; } public CpuSettings Cpu { get; set; }
public DiskIISettings DiskII { get; set; } public DiskIISettings DiskII { get; set; }
public KeyboardSettings Keyboard { get; set; } public KeyboardSettings Keyboard { get; set; }
public GamePortSettings GamePort { get; set; } public GamePortSettings GamePort { get; set; }
public AudioSettings Audio { get; set; } public AudioSettings Audio { get; set; }
public VideoSettings Video { get; set; } public VideoSettings Video { get; set; }
public const string FileName = "Settings.xml"; public const string FileName = "Settings.xml";
[SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")] [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
public static readonly XNamespace Namespace = "http://schemas.jellyfish.co.nz/virtu/settings"; public static readonly XNamespace Namespace = "http://schemas.jellyfish.co.nz/virtu/settings";
} }
public sealed class CpuSettings public sealed class CpuSettings
{ {
public bool Is65C02 { get; set; } public bool Is65C02 { get; set; }
public bool IsThrottled { get; set; } public bool IsThrottled { get; set; }
public int Multiplier { get; set; } public int Multiplier { get; set; }
} }
public sealed class DiskSettings public sealed class DiskSettings
{ {
public string Name { get; set; } public string Name { get; set; }
public bool IsWriteProtected { get; set; } public bool IsWriteProtected { get; set; }
}; };
public sealed class DiskIISettings public sealed class DiskIISettings
{ {
public DiskSettings Disk1 { get; set; } public DiskSettings Disk1 { get; set; }
public DiskSettings Disk2 { get; set; } public DiskSettings Disk2 { get; set; }
}; };
public sealed class JoystickSettings public sealed class JoystickSettings
{ {
public int UpLeft { get; set; } public int UpLeft { get; set; }
public int Up { get; set; } public int Up { get; set; }
public int UpRight { get; set; } public int UpRight { get; set; }
public int Left { get; set; } public int Left { get; set; }
public int Right { get; set; } public int Right { get; set; }
public int DownLeft { get; set; } public int DownLeft { get; set; }
public int Down { get; set; } public int Down { get; set; }
public int DownRight { get; set; } public int DownRight { get; set; }
}; };
public sealed class KeySettings public sealed class KeySettings
{ {
public JoystickSettings Joystick0 { get; set; } public JoystickSettings Joystick0 { get; set; }
public JoystickSettings Joystick1 { get; set; } public JoystickSettings Joystick1 { get; set; }
public int Button0 { get; set; } public int Button0 { get; set; }
public int Button1 { get; set; } public int Button1 { get; set; }
public int Button2 { get; set; } public int Button2 { get; set; }
}; };
public sealed class KeyboardSettings public sealed class KeyboardSettings
{ {
public bool UseGamePort { get; set; } public bool UseGamePort { get; set; }
public KeySettings Key { get; set; } public KeySettings Key { get; set; }
} }
public sealed class GamePortSettings public sealed class GamePortSettings
{ {
public bool UseKeyboard { get; set; } public bool UseKeyboard { get; set; }
public KeySettings Key { get; set; } public KeySettings Key { get; set; }
} }
public sealed class AudioSettings public sealed class AudioSettings
{ {
public double Volume { get; set; } public double Volume { get; set; }
}; };
public sealed class ColorSettings public sealed class ColorSettings
{ {
public uint Black { get; set; } public uint Black { get; set; }
public uint DarkBlue { get; set; } public uint DarkBlue { get; set; }
public uint DarkGreen { get; set; } public uint DarkGreen { get; set; }
public uint MediumBlue { get; set; } public uint MediumBlue { get; set; }
public uint Brown { get; set; } public uint Brown { get; set; }
public uint LightGrey { get; set; } public uint LightGrey { get; set; }
public uint Green { get; set; } public uint Green { get; set; }
public uint Aquamarine { get; set; } public uint Aquamarine { get; set; }
public uint DeepRed { get; set; } public uint DeepRed { get; set; }
public uint Purple { get; set; } public uint Purple { get; set; }
public uint DarkGrey { get; set; } public uint DarkGrey { get; set; }
public uint LightBlue { get; set; } public uint LightBlue { get; set; }
public uint Orange { get; set; } public uint Orange { get; set; }
public uint Pink { get; set; } public uint Pink { get; set; }
public uint Yellow { get; set; } public uint Yellow { get; set; }
public uint White { get; set; } public uint White { get; set; }
public uint Monochrome { get; set; } public uint Monochrome { get; set; }
} }
[Flags] [Flags]
public enum ScannerOptions { None = 0x0, AppleII = 0x1, Pal = 0x2 } // defaults to AppleIIe, Ntsc public enum ScannerOptions { None = 0x0, AppleII = 0x1, Pal = 0x2 } // defaults to AppleIIe, Ntsc
public sealed class VideoSettings public sealed class VideoSettings
{ {
public bool IsFullScreen { get; set; } public bool IsFullScreen { get; set; }
public bool IsMonochrome { get; set; } public bool IsMonochrome { get; set; }
public ScannerOptions ScannerOptions { get; set; } public ScannerOptions ScannerOptions { get; set; }
public ColorSettings Color { get; set; } public ColorSettings Color { get; set; }
}; };
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,106 +1,106 @@
using System; using System;
namespace Jellyfish.Virtu namespace Jellyfish.Virtu
{ {
public partial class Memory public partial class Memory
{ {
private const int BankCount = 2; private const int BankCount = 2;
private const int BankMain = 0; private const int BankMain = 0;
private const int BankAux = 1; private const int BankAux = 1;
private const int RegionCount = 12; private const int RegionCount = 12;
private const int Region0001 = 0; private const int Region0001 = 0;
private const int Region02BF = 1; private const int Region02BF = 1;
private const int Region0407 = 2; private const int Region0407 = 2;
private const int Region080B = 3; private const int Region080B = 3;
private const int Region203F = 4; private const int Region203F = 4;
private const int Region405F = 5; private const int Region405F = 5;
private const int RegionC0C0 = 6; private const int RegionC0C0 = 6;
private const int RegionC1C7 = 7; private const int RegionC1C7 = 7;
private const int RegionC3C3 = 8; private const int RegionC3C3 = 8;
private const int RegionC8CF = 9; private const int RegionC8CF = 9;
private const int RegionD0DF = 10; private const int RegionD0DF = 10;
private const int RegionE0FF = 11; private const int RegionE0FF = 11;
private static readonly int[] RegionBaseAddress = new int[RegionCount] private static readonly int[] RegionBaseAddress = new int[RegionCount]
{ {
0x0000, 0x0200, 0x0200, 0x0200, 0x0200, 0x0200, 0xC000, 0xC100, 0xC100, 0xC100, 0xD000, 0xE000 0x0000, 0x0200, 0x0200, 0x0200, 0x0200, 0x0200, 0xC000, 0xC100, 0xC100, 0xC100, 0xD000, 0xE000
}; };
private const int PageCount = 256; private const int PageCount = 256;
private static readonly int[] PageRegion = new int[PageCount] private static readonly int[] PageRegion = new int[PageCount]
{ {
Region0001, Region0001, Region02BF, Region02BF, Region0407, Region0407, Region0407, Region0407, Region0001, Region0001, Region02BF, Region02BF, Region0407, Region0407, Region0407, Region0407,
Region080B, Region080B, Region080B, Region080B, Region02BF, Region02BF, Region02BF, Region02BF, Region080B, Region080B, Region080B, Region080B, Region02BF, Region02BF, Region02BF, Region02BF,
Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF,
Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF,
Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F,
Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F,
Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F,
Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F, Region203F,
Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F,
Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F,
Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F,
Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F, Region405F,
Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF,
Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF,
Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF,
Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF,
Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF,
Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF,
Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF,
Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF,
Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF,
Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF,
Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF,
Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF, Region02BF,
RegionC0C0, RegionC1C7, RegionC1C7, RegionC3C3, RegionC1C7, RegionC1C7, RegionC1C7, RegionC1C7, RegionC0C0, RegionC1C7, RegionC1C7, RegionC3C3, RegionC1C7, RegionC1C7, RegionC1C7, RegionC1C7,
RegionC8CF, RegionC8CF, RegionC8CF, RegionC8CF, RegionC8CF, RegionC8CF, RegionC8CF, RegionC8CF, RegionC8CF, RegionC8CF, RegionC8CF, RegionC8CF, RegionC8CF, RegionC8CF, RegionC8CF, RegionC8CF,
RegionD0DF, RegionD0DF, RegionD0DF, RegionD0DF, RegionD0DF, RegionD0DF, RegionD0DF, RegionD0DF, RegionD0DF, RegionD0DF, RegionD0DF, RegionD0DF, RegionD0DF, RegionD0DF, RegionD0DF, RegionD0DF,
RegionD0DF, RegionD0DF, RegionD0DF, RegionD0DF, RegionD0DF, RegionD0DF, RegionD0DF, RegionD0DF, RegionD0DF, RegionD0DF, RegionD0DF, RegionD0DF, RegionD0DF, RegionD0DF, RegionD0DF, RegionD0DF,
RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF,
RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF,
RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF,
RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF, RegionE0FF
}; };
private const int State80Col = 0x000001; private const int State80Col = 0x000001;
private const int StateText = 0x000002; private const int StateText = 0x000002;
private const int StateMixed = 0x000004; private const int StateMixed = 0x000004;
private const int StateHires = 0x000008; private const int StateHires = 0x000008;
private const int StateDRes = 0x000010; private const int StateDRes = 0x000010;
private const int State80Store = 0x000020; private const int State80Store = 0x000020;
private const int StateAltChrSet = 0x000040; private const int StateAltChrSet = 0x000040;
private const int StateAltZP = 0x000080; private const int StateAltZP = 0x000080;
private const int StateBank1 = 0x000100; private const int StateBank1 = 0x000100;
private const int StateHRamRd = 0x000200; private const int StateHRamRd = 0x000200;
private const int StateHRamPreWrt = 0x000400; private const int StateHRamPreWrt = 0x000400;
private const int StateHRamWrt = 0x000800; private const int StateHRamWrt = 0x000800;
private const int StatePage2 = 0x001000; private const int StatePage2 = 0x001000;
private const int StateRamRd = 0x002000; private const int StateRamRd = 0x002000;
private const int StateRamWrt = 0x004000; private const int StateRamWrt = 0x004000;
private const int StateSlotC3Rom = 0x008000; private const int StateSlotC3Rom = 0x008000;
private const int StateIntC8Rom = 0x010000; // [5-28] private const int StateIntC8Rom = 0x010000; // [5-28]
private const int StateIntCXRom = 0x020000; private const int StateIntCXRom = 0x020000;
private const int StateAn0 = 0x040000; private const int StateAn0 = 0x040000;
private const int StateAn1 = 0x080000; private const int StateAn1 = 0x080000;
private const int StateAn2 = 0x100000; private const int StateAn2 = 0x100000;
private const int StateAn3 = 0x200000; private const int StateAn3 = 0x200000;
private const int StateVideo = State80Col | StateText | StateMixed | StateHires | StateDRes; private const int StateVideo = State80Col | StateText | StateMixed | StateHires | StateDRes;
private const int StateVideoModeCount = 32; private const int StateVideoModeCount = 32;
private static readonly int[] StateVideoMode = new int[StateVideoModeCount] private static readonly int[] StateVideoMode = new int[StateVideoModeCount]
{ {
Video.Mode0, Video.Mode0, Video.Mode1, Video.Mode2, Video.Mode3, Video.Mode4, Video.Mode1, Video.Mode2, Video.Mode0, Video.Mode0, Video.Mode1, Video.Mode2, Video.Mode3, Video.Mode4, Video.Mode1, Video.Mode2,
Video.Mode5, Video.Mode5, Video.Mode1, Video.Mode2, Video.Mode6, Video.Mode7, Video.Mode1, Video.Mode2, Video.Mode5, Video.Mode5, Video.Mode1, Video.Mode2, Video.Mode6, Video.Mode7, Video.Mode1, Video.Mode2,
Video.Mode8, Video.Mode9, Video.Mode1, Video.Mode2, Video.ModeA, Video.ModeB, Video.Mode1, Video.Mode2, Video.Mode8, Video.Mode9, Video.Mode1, Video.Mode2, Video.ModeA, Video.ModeB, Video.Mode1, Video.Mode2,
Video.ModeC, Video.ModeD, Video.Mode1, Video.Mode2, Video.ModeE, Video.ModeF, Video.Mode1, Video.Mode2 Video.ModeC, Video.ModeD, Video.Mode1, Video.Mode2, Video.ModeE, Video.ModeF, Video.Mode1, Video.Mode2
}; };
private readonly Action<int, byte>[][][] WriteRamModeBankRegion; private readonly Action<int, byte>[][][] WriteRamModeBankRegion;
} }
} }

View File

@ -1,18 +1,18 @@
namespace Jellyfish.Virtu namespace Jellyfish.Virtu
{ {
public sealed class NoSlotClock public sealed class NoSlotClock
{ {
public NoSlotClock() public NoSlotClock()
{ {
} }
public int Read(int address, int data) public int Read(int address, int data)
{ {
return data; return data;
} }
public void Write(int address) public void Write(int address)
{ {
} }
} }
} }

View File

@ -1,48 +1,48 @@
namespace Jellyfish.Virtu namespace Jellyfish.Virtu
{ {
public class PeripheralCard : MachineComponent public class PeripheralCard : MachineComponent
{ {
public PeripheralCard(Machine machine) : public PeripheralCard(Machine machine) :
base(machine) base(machine)
{ {
} }
public virtual int ReadIoRegionC0C0(int address) public virtual int ReadIoRegionC0C0(int address)
{ {
// read Device Select' address $C0nX; n = slot number + 8 // read Device Select' address $C0nX; n = slot number + 8
return ReadFloatingBus(); return ReadFloatingBus();
} }
public virtual int ReadIoRegionC1C7(int address) public virtual int ReadIoRegionC1C7(int address)
{ {
// read I/O Select' address $CsXX; s = slot number // read I/O Select' address $CsXX; s = slot number
return ReadFloatingBus(); return ReadFloatingBus();
} }
public virtual int ReadIoRegionC8CF(int address) public virtual int ReadIoRegionC8CF(int address)
{ {
// read I/O Strobe' address $C800-$CFFF // read I/O Strobe' address $C800-$CFFF
return ReadFloatingBus(); return ReadFloatingBus();
} }
public virtual void WriteIoRegionC0C0(int address, int data) public virtual void WriteIoRegionC0C0(int address, int data)
{ {
// write Device Select' address $C0nX; n = slot number + 8 // write Device Select' address $C0nX; n = slot number + 8
} }
public virtual void WriteIoRegionC1C7(int address, int data) public virtual void WriteIoRegionC1C7(int address, int data)
{ {
// write I/O Select' address $CsXX; s = slot number // write I/O Select' address $CsXX; s = slot number
} }
public virtual void WriteIoRegionC8CF(int address, int data) public virtual void WriteIoRegionC8CF(int address, int data)
{ {
// write I/O Strobe' address $C800-$CFFF // write I/O Strobe' address $C800-$CFFF
} }
protected int ReadFloatingBus() protected int ReadFloatingBus()
{ {
return Machine.Video.ReadFloatingBus(); return Machine.Video.ReadFloatingBus();
} }
} }
} }

View File

@ -1,65 +1,65 @@
using System; using System;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Threading; using System.Threading;
using Jellyfish.Library; using Jellyfish.Library;
namespace Jellyfish.Virtu.Services namespace Jellyfish.Virtu.Services
{ {
public abstract class AudioService : MachineService public abstract class AudioService : MachineService
{ {
protected AudioService(Machine machine) : protected AudioService(Machine machine) :
base(machine) base(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); _buffer[_index + 1] = (byte)(data >> 8);
_index = (_index + 2) % SampleSize; _index = (_index + 2) % SampleSize;
if (_index == 0) if (_index == 0)
{ {
_readEvent.Set(); _readEvent.Set();
if (Machine.Settings.Cpu.IsThrottled) if (Machine.Settings.Cpu.IsThrottled)
{ {
_writeEvent.WaitOne(SampleLatency * 2); // allow timeout; avoids deadlock _writeEvent.WaitOne(SampleLatency * 2); // allow timeout; avoids deadlock
} }
} }
} }
public void Reset() public void Reset()
{ {
Buffer.BlockCopy(SampleZero, 0, _buffer, 0, SampleSize); Buffer.BlockCopy(SampleZero, 0, _buffer, 0, SampleSize);
} }
public abstract void SetVolume(double volume); // machine thread public abstract void SetVolume(double volume); // machine thread
protected void Update(int bufferSize, Action<byte[], int> updateBuffer) // audio thread protected void Update(int bufferSize, Action<byte[], int> updateBuffer) // audio thread
{ {
if (Machine.State == MachineState.Running) if (Machine.State == MachineState.Running)
{ {
_readEvent.WaitOne(SampleLatency * 2); // allow timeout; avoids deadlock _readEvent.WaitOne(SampleLatency * 2); // allow timeout; avoids deadlock
} }
if (updateBuffer != null) if (updateBuffer != null)
{ {
updateBuffer(_buffer, bufferSize); updateBuffer(_buffer, bufferSize);
} }
_writeEvent.Set(); _writeEvent.Set();
} }
public const int SampleRate = 44100; // hz public const int SampleRate = 44100; // hz
public const int SampleChannels = 1; public const int SampleChannels = 1;
public const int SampleBits = 16; public const int SampleBits = 16;
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")] [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];
private int _index; private int _index;
private AutoResetEvent _readEvent = new AutoResetEvent(false); private AutoResetEvent _readEvent = new AutoResetEvent(false);
private AutoResetEvent _writeEvent = new AutoResetEvent(false); private AutoResetEvent _writeEvent = new AutoResetEvent(false);
} }
} }

View File

@ -1,23 +1,23 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
namespace Jellyfish.Virtu.Services namespace Jellyfish.Virtu.Services
{ {
public class DebugService : MachineService public class DebugService : MachineService
{ {
public DebugService(Machine machine) : public DebugService(Machine machine) :
base(machine) base(machine)
{ {
} }
public void WriteLine(string message) public void WriteLine(string message)
{ {
OnWriteLine(string.Concat(DateTime.Now.TimeOfDay, ' ', message)); OnWriteLine(string.Concat(DateTime.Now.TimeOfDay, ' ', message));
} }
protected virtual void OnWriteLine(string message) protected virtual void OnWriteLine(string message)
{ {
Debug.WriteLine(message); Debug.WriteLine(message);
} }
} }
} }

View File

@ -1,73 +1,73 @@
namespace Jellyfish.Virtu.Services namespace Jellyfish.Virtu.Services
{ {
public struct Joystick public struct Joystick
{ {
public Joystick(bool isUp, bool isLeft, bool isRight, bool isDown) public Joystick(bool isUp, bool isLeft, bool isRight, bool isDown)
{ {
_isUp = isUp; _isUp = isUp;
_isLeft = isLeft; _isLeft = isLeft;
_isRight = isRight; _isRight = isRight;
_isDown = isDown; _isDown = isDown;
} }
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
return ((obj is Joystick) && (this == (Joystick)obj)); return ((obj is Joystick) && (this == (Joystick)obj));
} }
public override int GetHashCode() public override int GetHashCode()
{ {
return (_isUp.GetHashCode() ^ _isLeft.GetHashCode() ^ _isRight.GetHashCode() ^ _isDown.GetHashCode()); return (_isUp.GetHashCode() ^ _isLeft.GetHashCode() ^ _isRight.GetHashCode() ^ _isDown.GetHashCode());
} }
public override string ToString() public override string ToString()
{ {
return !(_isUp || _isDown || _isLeft || _isRight) ? "Position = Center" : return !(_isUp || _isDown || _isLeft || _isRight) ? "Position = Center" :
string.Concat("Position = ", _isUp ? "Up" : _isDown ? "Down" : string.Empty, _isLeft ? "Left" : _isRight ? "Right" : string.Empty); string.Concat("Position = ", _isUp ? "Up" : _isDown ? "Down" : string.Empty, _isLeft ? "Left" : _isRight ? "Right" : string.Empty);
} }
public static bool operator ==(Joystick joystick1, Joystick joystick2) public static bool operator ==(Joystick joystick1, Joystick joystick2)
{ {
return ((joystick1._isUp == joystick2._isUp) && (joystick1._isLeft == joystick2._isLeft) && return ((joystick1._isUp == joystick2._isUp) && (joystick1._isLeft == joystick2._isLeft) &&
(joystick1._isRight == joystick2._isRight) && (joystick1._isDown == joystick2._isDown)); (joystick1._isRight == joystick2._isRight) && (joystick1._isDown == joystick2._isDown));
} }
public static bool operator !=(Joystick joystick1, Joystick joystick2) public static bool operator !=(Joystick joystick1, Joystick joystick2)
{ {
return !(joystick1 == joystick2); return !(joystick1 == joystick2);
} }
public bool IsUp { get { return _isUp; } } // no auto props public bool IsUp { get { return _isUp; } } // no auto props
public bool IsLeft { get { return _isLeft; } } public bool IsLeft { get { return _isLeft; } }
public bool IsRight { get { return _isRight; } } public bool IsRight { get { return _isRight; } }
public bool IsDown { get { return _isDown; } } public bool IsDown { get { return _isDown; } }
private bool _isUp; private bool _isUp;
private bool _isLeft; private bool _isLeft;
private bool _isRight; private bool _isRight;
private bool _isDown; private bool _isDown;
} }
public class GamePortService : MachineService public class GamePortService : MachineService
{ {
public GamePortService(Machine machine) : public GamePortService(Machine machine) :
base(machine) base(machine)
{ {
Paddle0 = Paddle1 = Paddle2 = Paddle3 = 255; // not connected Paddle0 = Paddle1 = Paddle2 = Paddle3 = 255; // not connected
} }
public virtual void Update() { } // main thread public virtual void Update() { } // main thread
public int Paddle0 { get; protected set; } public int Paddle0 { get; protected set; }
public int Paddle1 { get; protected set; } public int Paddle1 { get; protected set; }
public int Paddle2 { get; protected set; } public int Paddle2 { get; protected set; }
public int Paddle3 { get; protected set; } public int Paddle3 { get; protected set; }
public Joystick Joystick0 { get; protected set; } public Joystick Joystick0 { get; protected set; }
public Joystick Joystick1 { get; protected set; } public Joystick Joystick1 { get; protected set; }
public bool IsButton0Down { get; protected set; } public bool IsButton0Down { get; protected set; }
public bool IsButton1Down { get; protected set; } public bool IsButton1Down { get; protected set; }
public bool IsButton2Down { get; protected set; } public bool IsButton2Down { get; protected set; }
} }
} }

View File

@ -1,41 +1,41 @@
namespace Jellyfish.Virtu.Services namespace Jellyfish.Virtu.Services
{ {
public abstract class KeyboardService : MachineService public abstract class KeyboardService : MachineService
{ {
protected KeyboardService(Machine machine) : protected KeyboardService(Machine machine) :
base(machine) base(machine)
{ {
} }
public abstract bool IsKeyDown(int key); public abstract bool IsKeyDown(int key);
public virtual void Update() // main thread public virtual void Update() // main thread
{ {
if (IsResetKeyDown) if (IsResetKeyDown)
{ {
if (!_resetKeyDown) if (!_resetKeyDown)
{ {
_resetKeyDown = true; // entering reset; pause until key released _resetKeyDown = true; // entering reset; pause until key released
Machine.Pause(); Machine.Pause();
Machine.Reset(); Machine.Reset();
} }
} }
else if (_resetKeyDown) else if (_resetKeyDown)
{ {
_resetKeyDown = false; // leaving reset _resetKeyDown = false; // leaving reset
Machine.Unpause(); Machine.Unpause();
} }
} }
public bool IsAnyKeyDown { get; protected set; } public bool IsAnyKeyDown { get; protected set; }
public bool IsControlKeyDown { get; protected set; } public bool IsControlKeyDown { get; protected set; }
public bool IsShiftKeyDown { get; protected set; } public bool IsShiftKeyDown { get; protected set; }
public bool IsOpenAppleKeyDown { get; protected set; } public bool IsOpenAppleKeyDown { get; protected set; }
public bool IsCloseAppleKeyDown { get; protected set; } public bool IsCloseAppleKeyDown { get; protected set; }
protected bool IsResetKeyDown { get; set; } protected bool IsResetKeyDown { get; set; }
private bool _resetKeyDown; private bool _resetKeyDown;
} }
} }

View File

@ -1,30 +1,30 @@
using System; using System;
namespace Jellyfish.Virtu.Services namespace Jellyfish.Virtu.Services
{ {
public abstract class MachineService : IDisposable public abstract class MachineService : IDisposable
{ {
protected MachineService(Machine machine) protected MachineService(Machine machine)
{ {
Machine = machine; Machine = machine;
} }
~MachineService() ~MachineService()
{ {
Dispose(false); Dispose(false);
} }
public void Dispose() public void Dispose()
{ {
Dispose(true); Dispose(true);
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
} }
protected virtual void Dispose(bool disposing) 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>(); } } protected DebugService DebugService { get { return Machine.Services.GetService<DebugService>(); } }
} }
} }

View File

@ -1,51 +1,51 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Globalization; using System.Globalization;
using Jellyfish.Virtu.Properties; using Jellyfish.Virtu.Properties;
namespace Jellyfish.Virtu.Services namespace Jellyfish.Virtu.Services
{ {
public sealed class MachineServices : IServiceProvider public sealed class MachineServices : IServiceProvider
{ {
public void AddService(Type serviceType, MachineService serviceProvider) public void AddService(Type serviceType, MachineService serviceProvider)
{ {
if (serviceType == null) if (serviceType == null)
{ {
throw new ArgumentNullException("serviceType"); throw new ArgumentNullException("serviceType");
} }
if (_serviceProviders.ContainsKey(serviceType)) if (_serviceProviders.ContainsKey(serviceType))
{ {
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Strings.ServiceAlreadyPresent, serviceType.FullName), "serviceType"); throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Strings.ServiceAlreadyPresent, serviceType.FullName), "serviceType");
} }
if (serviceProvider == null) if (serviceProvider == null)
{ {
throw new ArgumentNullException("serviceProvider"); throw new ArgumentNullException("serviceProvider");
} }
if (!serviceType.IsAssignableFrom(serviceProvider.GetType())) if (!serviceType.IsAssignableFrom(serviceProvider.GetType()))
{ {
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Strings.ServiceMustBeAssignable, serviceType.FullName, serviceProvider.GetType().FullName)); throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Strings.ServiceMustBeAssignable, serviceType.FullName, serviceProvider.GetType().FullName));
} }
_serviceProviders.Add(serviceType, serviceProvider); _serviceProviders.Add(serviceType, serviceProvider);
} }
[SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")] [SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")]
public T GetService<T>() public T GetService<T>()
{ {
return (T)((IServiceProvider)this).GetService(typeof(T)); return (T)((IServiceProvider)this).GetService(typeof(T));
} }
public void RemoveService(Type serviceType) public void RemoveService(Type serviceType)
{ {
_serviceProviders.Remove(serviceType); _serviceProviders.Remove(serviceType);
} }
object IServiceProvider.GetService(Type serviceType) object IServiceProvider.GetService(Type serviceType)
{ {
return _serviceProviders.ContainsKey(serviceType) ? _serviceProviders[serviceType] : null; return _serviceProviders.ContainsKey(serviceType) ? _serviceProviders[serviceType] : null;
} }
private Dictionary<Type, MachineService> _serviceProviders = new Dictionary<Type, MachineService>(); private Dictionary<Type, MachineService> _serviceProviders = new Dictionary<Type, MachineService>();
} }
} }

View File

@ -1,38 +1,38 @@
using System; using System;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
using System.Resources; using System.Resources;
using Jellyfish.Virtu.Properties; using Jellyfish.Virtu.Properties;
namespace Jellyfish.Virtu.Services namespace Jellyfish.Virtu.Services
{ {
public abstract class StorageService : MachineService public abstract class StorageService : MachineService
{ {
protected StorageService(Machine machine) : protected StorageService(Machine machine) :
base(machine) base(machine)
{ {
} }
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")] [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 };
var resourceStream = (Stream)resourceManager.GetObject(resourceName); var resourceStream = (Stream)resourceManager.GetObject(resourceName);
if (resourceStream == null) if (resourceStream == null)
{ {
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Strings.ResourceNotFound, resourceName)); throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Strings.ResourceNotFound, resourceName));
} }
if ((resourceSize > 0) && (resourceStream.Length != resourceSize)) if ((resourceSize > 0) && (resourceStream.Length != resourceSize))
{ {
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Strings.ResourceInvalid, resourceName)); throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Strings.ResourceInvalid, resourceName));
} }
return resourceStream; return resourceStream;
} }
public abstract void Load(string path, Action<Stream> reader); public abstract void Load(string path, Action<Stream> reader);
public abstract void Save(string path, Action<Stream> writer); public abstract void Save(string path, Action<Stream> writer);
} }
} }

View File

@ -1,20 +1,20 @@
namespace Jellyfish.Virtu.Services namespace Jellyfish.Virtu.Services
{ {
public abstract class VideoService : MachineService public abstract class VideoService : MachineService
{ {
protected VideoService(Machine machine) : protected VideoService(Machine machine) :
base(machine) base(machine)
{ {
} }
public abstract void SetPixel(int x, int y, uint color); public abstract void SetPixel(int x, int y, uint color);
public abstract void Update(); // main thread public abstract void Update(); // main thread
public void ToggleFullScreen() public void ToggleFullScreen()
{ {
IsFullScreen ^= true; IsFullScreen ^= true;
} }
public bool IsFullScreen { get; private set; } public bool IsFullScreen { get; private set; }
} }
} }

View File

@ -1,11 +1,11 @@
<jl:ApplicationBase x:Class="Jellyfish.Virtu.MainApp" <jl:ApplicationBase x:Class="Jellyfish.Virtu.MainApp"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:jl="clr-namespace:Jellyfish.Library;assembly=Jellyfish.Library" xmlns:jl="clr-namespace:Jellyfish.Library;assembly=Jellyfish.Library"
xmlns:jv="clr-namespace:Jellyfish.Virtu;assembly=Jellyfish.Virtu"> xmlns:jv="clr-namespace:Jellyfish.Virtu;assembly=Jellyfish.Virtu">
<Application.RootVisual> <Application.RootVisual>
<jv:MainPage /> <jv:MainPage />
</Application.RootVisual> </Application.RootVisual>
<Application.Resources> <Application.Resources>
</Application.Resources> </Application.Resources>
</jl:ApplicationBase> </jl:ApplicationBase>

View File

@ -1,14 +1,14 @@
using Jellyfish.Library; using Jellyfish.Library;
namespace Jellyfish.Virtu namespace Jellyfish.Virtu
{ {
public sealed partial class MainApp : ApplicationBase public sealed partial class MainApp : ApplicationBase
{ {
public MainApp() : public MainApp() :
base("Virtu") base("Virtu")
{ {
InitializeComponent(); InitializeComponent();
InitializeOutOfBrowserUpdate(); InitializeOutOfBrowserUpdate();
} }
} }
} }

View File

@ -1,23 +1,23 @@
<UserControl x:Class="Jellyfish.Virtu.MainPage" <UserControl x:Class="Jellyfish.Virtu.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:jl="clr-namespace:Jellyfish.Library;assembly=Jellyfish.Library"> xmlns:jl="clr-namespace:Jellyfish.Library;assembly=Jellyfish.Library">
<Grid Background="Black"> <Grid Background="Black">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition /> <RowDefinition />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<Button x:Name="_disk1Button" Content="Disk 1" IsTabStop="False" Margin="4,4,0,4" /> <Button x:Name="_disk1Button" Content="Disk 1" IsTabStop="False" Margin="4,4,0,4" />
<Button x:Name="_disk2Button" Content="Disk 2" IsTabStop="False" Margin="4,4,0,4" /> <Button x:Name="_disk2Button" Content="Disk 2" IsTabStop="False" Margin="4,4,0,4" />
</StackPanel> </StackPanel>
<jl:FrameRateCounter Margin="0,0,4,0" HorizontalAlignment="Right" VerticalAlignment="Center" /> <jl:FrameRateCounter Margin="0,0,4,0" HorizontalAlignment="Right" VerticalAlignment="Center" />
<Grid Grid.Row="1"> <Grid Grid.Row="1">
<Image x:Name="_image" MinWidth="560" MinHeight="384" HorizontalAlignment="Center" VerticalAlignment="Center" /> <Image x:Name="_image" MinWidth="560" MinHeight="384" HorizontalAlignment="Center" VerticalAlignment="Center" />
<MediaElement x:Name="_media" /> <MediaElement x:Name="_media" />
<ScrollViewer x:Name="_debugScrollViewer" BorderThickness="0" IsTabStop="False" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"> <ScrollViewer x:Name="_debugScrollViewer" BorderThickness="0" IsTabStop="False" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<TextBlock x:Name="_debugText" FontFamily="Consolas" FontSize="12" Foreground="White" /> <TextBlock x:Name="_debugText" FontFamily="Consolas" FontSize="12" Foreground="White" />
</ScrollViewer> </ScrollViewer>
</Grid> </Grid>
</Grid> </Grid>
</UserControl> </UserControl>

View File

@ -1,95 +1,95 @@
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media; using System.Windows.Media;
using Jellyfish.Virtu.Services; using Jellyfish.Virtu.Services;
namespace Jellyfish.Virtu namespace Jellyfish.Virtu
{ {
public sealed partial class MainPage : UserControl, IDisposable public sealed partial class MainPage : UserControl, IDisposable
{ {
public MainPage() public MainPage()
{ {
InitializeComponent(); InitializeComponent();
if (!DesignerProperties.IsInDesignTool) if (!DesignerProperties.IsInDesignTool)
{ {
_debugService = new SilverlightDebugService(_machine, this); _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(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);
_machine.Services.AddService(typeof(AudioService), _audioService); _machine.Services.AddService(typeof(AudioService), _audioService);
_machine.Services.AddService(typeof(VideoService), _videoService); _machine.Services.AddService(typeof(VideoService), _videoService);
Loaded += (sender, e) => _machine.Start(); Loaded += (sender, e) => _machine.Start();
CompositionTarget.Rendering += OnCompositionTargetRendering; CompositionTarget.Rendering += OnCompositionTargetRendering;
Application.Current.Exit += (sender, e) => _machine.Stop(); Application.Current.Exit += (sender, e) => _machine.Stop();
_disk1Button.Click += (sender, e) => OnDiskButtonClick(0); _disk1Button.Click += (sender, e) => OnDiskButtonClick(0);
_disk2Button.Click += (sender, e) => OnDiskButtonClick(1); _disk2Button.Click += (sender, e) => OnDiskButtonClick(1);
} }
} }
public void Dispose() public void Dispose()
{ {
_machine.Dispose(); _machine.Dispose();
_debugService.Dispose(); _debugService.Dispose();
_storageService.Dispose(); _storageService.Dispose();
_keyboardService.Dispose(); _keyboardService.Dispose();
_gamePortService.Dispose(); _gamePortService.Dispose();
_audioService.Dispose(); _audioService.Dispose();
_videoService.Dispose(); _videoService.Dispose();
} }
public void WriteLine(string message) public void WriteLine(string message)
{ {
_debugText.Text += message; _debugText.Text += message;
_debugScrollViewer.UpdateLayout(); _debugScrollViewer.UpdateLayout();
_debugScrollViewer.ScrollToVerticalOffset(double.MaxValue); _debugScrollViewer.ScrollToVerticalOffset(double.MaxValue);
} }
private void OnCompositionTargetRendering(object sender, EventArgs e) private void OnCompositionTargetRendering(object sender, EventArgs e)
{ {
_keyboardService.Update(); _keyboardService.Update();
_gamePortService.Update(); _gamePortService.Update();
_videoService.Update(); _videoService.Update();
} }
private void OnDiskButtonClick(int drive) private void OnDiskButtonClick(int drive)
{ {
var dialog = new OpenFileDialog() { Filter = "Disk Files (*.dsk;*.nib)|*.dsk;*.nib|All Files (*.*)|*.*" }; var dialog = new OpenFileDialog() { Filter = "Disk Files (*.dsk;*.nib)|*.dsk;*.nib|All Files (*.*)|*.*" };
bool? result = dialog.ShowDialog(); bool? result = dialog.ShowDialog();
if (result.HasValue && result.Value) if (result.HasValue && result.Value)
{ {
using (var stream = dialog.File.OpenRead()) using (var stream = dialog.File.OpenRead())
{ {
_machine.Pause(); _machine.Pause();
var diskII = _machine.FindDiskIIController(); var diskII = _machine.FindDiskIIController();
if (diskII != null) if (diskII != null)
{ {
diskII.Drives[drive].InsertDisk(dialog.File.Name, stream, false); diskII.Drives[drive].InsertDisk(dialog.File.Name, stream, false);
} }
_machine.Unpause(); _machine.Unpause();
} }
} }
} }
private Machine _machine = new Machine(); private Machine _machine = new Machine();
private DebugService _debugService; private DebugService _debugService;
private StorageService _storageService; private StorageService _storageService;
private KeyboardService _keyboardService; private KeyboardService _keyboardService;
private GamePortService _gamePortService; private GamePortService _gamePortService;
private AudioService _audioService; private AudioService _audioService;
private VideoService _videoService; private VideoService _videoService;
} }
} }

View File

@ -1,13 +1,13 @@
<jl:ApplicationBase x:Class="Jellyfish.Virtu.MainApp" <jl:ApplicationBase x:Class="Jellyfish.Virtu.MainApp"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:jl="clr-namespace:Jellyfish.Library;assembly=Jellyfish.Library"> xmlns:jl="clr-namespace:Jellyfish.Library;assembly=Jellyfish.Library">
<Application.Resources> <Application.Resources>
</Application.Resources> </Application.Resources>
<Application.ApplicationLifetimeObjects> <Application.ApplicationLifetimeObjects>
<shell:PhoneApplicationService /> <shell:PhoneApplicationService />
</Application.ApplicationLifetimeObjects> </Application.ApplicationLifetimeObjects>
</jl:ApplicationBase> </jl:ApplicationBase>

View File

@ -1,14 +1,14 @@
using Jellyfish.Library; using Jellyfish.Library;
namespace Jellyfish.Virtu namespace Jellyfish.Virtu
{ {
public sealed partial class MainApp : ApplicationBase public sealed partial class MainApp : ApplicationBase
{ {
public MainApp() : public MainApp() :
base("Virtu") base("Virtu")
{ {
InitializeComponent(); InitializeComponent();
InitializePhoneApplication(); InitializePhoneApplication();
} }
} }
} }

View File

@ -1,32 +1,32 @@
<phone:PhoneApplicationPage <phone:PhoneApplicationPage
x:Class="Jellyfish.Virtu.MainPage" x:Class="Jellyfish.Virtu.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:jl="clr-namespace:Jellyfish.Library;assembly=Jellyfish.Library" xmlns:jl="clr-namespace:Jellyfish.Library;assembly=Jellyfish.Library"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="480" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="480"
FontFamily="{StaticResource PhoneFontFamilyNormal}" FontSize="{StaticResource PhoneFontSizeNormal}" FontFamily="{StaticResource PhoneFontFamilyNormal}" FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}" Foreground="{StaticResource PhoneForegroundBrush}"
Orientation="Landscape" SupportedOrientations="Landscape" Title="Virtu"> Orientation="Landscape" SupportedOrientations="Landscape" Title="Virtu">
<Grid Background="Black"> <Grid Background="Black">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition /> <RowDefinition />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<!--<StackPanel Orientation="Horizontal"> <!--<StackPanel Orientation="Horizontal">
<Button x:Name="_disk1Button" Content="Disk 1" IsTabStop="False" Margin="4,4,0,4" /> <Button x:Name="_disk1Button" Content="Disk 1" IsTabStop="False" Margin="4,4,0,4" />
<Button x:Name="_disk2Button" Content="Disk 2" IsTabStop="False" Margin="4,4,0,4" /> <Button x:Name="_disk2Button" Content="Disk 2" IsTabStop="False" Margin="4,4,0,4" />
</StackPanel>--> </StackPanel>-->
<jl:FrameRateCounter Margin="0,0,4,0" HorizontalAlignment="Right" VerticalAlignment="Center" /> <jl:FrameRateCounter Margin="0,0,4,0" HorizontalAlignment="Right" VerticalAlignment="Center" />
<Grid Grid.Row="1"> <Grid Grid.Row="1">
<Image x:Name="_image" MinWidth="560" MinHeight="384" HorizontalAlignment="Center" VerticalAlignment="Center" /> <Image x:Name="_image" MinWidth="560" MinHeight="384" HorizontalAlignment="Center" VerticalAlignment="Center" />
<MediaElement x:Name="_media" /> <MediaElement x:Name="_media" />
<ScrollViewer x:Name="_debugScrollViewer" BorderThickness="0" IsTabStop="False" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"> <ScrollViewer x:Name="_debugScrollViewer" BorderThickness="0" IsTabStop="False" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<TextBlock x:Name="_debugText" FontFamily="Consolas" FontSize="12" Foreground="White" /> <TextBlock x:Name="_debugText" FontFamily="Consolas" FontSize="12" Foreground="White" />
</ScrollViewer> </ScrollViewer>
</Grid> </Grid>
</Grid> </Grid>
</phone:PhoneApplicationPage> </phone:PhoneApplicationPage>

View File

@ -1,91 +1,91 @@
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using System.Windows; using System.Windows;
using System.Windows.Media; using System.Windows.Media;
using Jellyfish.Virtu.Services; using Jellyfish.Virtu.Services;
using Microsoft.Phone.Controls; using Microsoft.Phone.Controls;
namespace Jellyfish.Virtu namespace Jellyfish.Virtu
{ {
public sealed partial class MainPage : PhoneApplicationPage, IDisposable public sealed partial class MainPage : PhoneApplicationPage, IDisposable
{ {
public MainPage() public MainPage()
{ {
InitializeComponent(); InitializeComponent();
if (!DesignerProperties.IsInDesignTool) if (!DesignerProperties.IsInDesignTool)
{ {
_debugService = new SilverlightDebugService(_machine, this); _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(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);
_machine.Services.AddService(typeof(AudioService), _audioService); _machine.Services.AddService(typeof(AudioService), _audioService);
_machine.Services.AddService(typeof(VideoService), _videoService); _machine.Services.AddService(typeof(VideoService), _videoService);
Loaded += (sender, e) => _machine.Start(); Loaded += (sender, e) => _machine.Start();
CompositionTarget.Rendering += OnCompositionTargetRendering; CompositionTarget.Rendering += OnCompositionTargetRendering;
Application.Current.Exit += (sender, e) => _machine.Stop(); Application.Current.Exit += (sender, e) => _machine.Stop();
//_disk1Button.Click += (sender, e) => OnDiskButtonClick(0); // TODO //_disk1Button.Click += (sender, e) => OnDiskButtonClick(0); // TODO
//_disk2Button.Click += (sender, e) => OnDiskButtonClick(1); //_disk2Button.Click += (sender, e) => OnDiskButtonClick(1);
} }
} }
public void Dispose() public void Dispose()
{ {
_machine.Dispose(); _machine.Dispose();
_debugService.Dispose(); _debugService.Dispose();
_storageService.Dispose(); _storageService.Dispose();
_keyboardService.Dispose(); _keyboardService.Dispose();
_gamePortService.Dispose(); _gamePortService.Dispose();
_audioService.Dispose(); _audioService.Dispose();
_videoService.Dispose(); _videoService.Dispose();
} }
public void WriteLine(string message) public void WriteLine(string message)
{ {
_debugText.Text += message; _debugText.Text += message;
_debugScrollViewer.UpdateLayout(); _debugScrollViewer.UpdateLayout();
_debugScrollViewer.ScrollToVerticalOffset(double.MaxValue); _debugScrollViewer.ScrollToVerticalOffset(double.MaxValue);
} }
private void OnCompositionTargetRendering(object sender, EventArgs e) private void OnCompositionTargetRendering(object sender, EventArgs e)
{ {
_keyboardService.Update(); _keyboardService.Update();
_gamePortService.Update(); _gamePortService.Update();
_videoService.Update(); _videoService.Update();
} }
//private void OnDiskButtonClick(int drive) // TODO //private void OnDiskButtonClick(int drive) // TODO
//{ //{
// var dialog = new OpenFileDialog() { Filter = "Disk Files (*.dsk;*.nib)|*.dsk;*.nib|All Files (*.*)|*.*" }; // var dialog = new OpenFileDialog() { Filter = "Disk Files (*.dsk;*.nib)|*.dsk;*.nib|All Files (*.*)|*.*" };
// bool? result = dialog.ShowDialog(); // bool? result = dialog.ShowDialog();
// if (result.HasValue && result.Value) // if (result.HasValue && result.Value)
// { // {
// using (var stream = dialog.File.OpenRead()) // using (var stream = dialog.File.OpenRead())
// { // {
// _machine.Pause(); // _machine.Pause();
// _machine.DiskII.Drives[drive].InsertDisk(dialog.File.Name, stream, false); // _machine.DiskII.Drives[drive].InsertDisk(dialog.File.Name, stream, false);
// _machine.Unpause(); // _machine.Unpause();
// } // }
// } // }
//} //}
private Machine _machine = new Machine(); private Machine _machine = new Machine();
private DebugService _debugService; private DebugService _debugService;
private StorageService _storageService; private StorageService _storageService;
private KeyboardService _keyboardService; private KeyboardService _keyboardService;
private GamePortService _gamePortService; private GamePortService _gamePortService;
private AudioService _audioService; private AudioService _audioService;
private VideoService _videoService; private VideoService _videoService;
} }
} }

View File

@ -1,5 +1,5 @@
<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment" <Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Deployment.Parts> <Deployment.Parts>
</Deployment.Parts> </Deployment.Parts>
</Deployment> </Deployment>

View File

@ -1,22 +1,22 @@
using System; using System;
using System.Reflection; using System.Reflection;
using System.Resources; using System.Resources;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Jellyfish.Library; using Jellyfish.Library;
[assembly: AssemblyTitle("Virtu")] [assembly: AssemblyTitle("Virtu")]
[assembly: AssemblyDescription("Apple IIe Emulator")] [assembly: AssemblyDescription("Apple IIe Emulator")]
[assembly: AssemblyProduct("Jellyfish.Virtu.Silverlight.Phone")] [assembly: AssemblyProduct("Jellyfish.Virtu.Silverlight.Phone")]
[assembly: AssemblyCompany("Digital Jellyfish Design Ltd")] [assembly: AssemblyCompany("Digital Jellyfish Design Ltd")]
[assembly: AssemblyCopyright("Copyright © 1995-2010 Digital Jellyfish Design Ltd")] [assembly: AssemblyCopyright("Copyright © 1995-2010 Digital Jellyfish Design Ltd")]
[assembly: AssemblyComment("Developed by Sean Fausett & Nick Westgate")] [assembly: AssemblyComment("Developed by Sean Fausett & Nick Westgate")]
[assembly: AssemblyVersion("0.8.3.0")] [assembly: AssemblyVersion("0.8.3.0")]
[assembly: AssemblyFileVersion("0.8.3.0")] [assembly: AssemblyFileVersion("0.8.3.0")]
[assembly: AssemblyInformationalVersion("0.8.3.0")] [assembly: AssemblyInformationalVersion("0.8.3.0")]
[assembly: CLSCompliant(false)] [assembly: CLSCompliant(false)]
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
[assembly: Guid("89a50370-1ed9-4cf1-ad08-043b6e6f3c90")] [assembly: Guid("89a50370-1ed9-4cf1-ad08-043b6e6f3c90")]
[assembly: NeutralResourcesLanguage("en")] [assembly: NeutralResourcesLanguage("en")]

View File

@ -1,29 +1,29 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Deployment xmlns="http://schemas.microsoft.com/windowsphone/2009/deployment" AppPlatformVersion="7.0"> <Deployment xmlns="http://schemas.microsoft.com/windowsphone/2009/deployment" AppPlatformVersion="7.0">
<App xmlns="" ProductID="{89a50370-1ed9-4cf1-ad08-043b6e6f3c90}" Title="Virtu" RuntimeType="Silverlight" Version="1.0.0.0" Genre="Apps.Normal" Author="Sean Fausett &amp; Nick Westgate" Description="Apple IIe Emulator" Publisher="Digital Jellyfish Design Ltd"> <App xmlns="" ProductID="{89a50370-1ed9-4cf1-ad08-043b6e6f3c90}" Title="Virtu" RuntimeType="Silverlight" Version="1.0.0.0" Genre="Apps.Normal" Author="Sean Fausett &amp; Nick Westgate" Description="Apple IIe Emulator" Publisher="Digital Jellyfish Design Ltd">
<IconPath IsRelative="true" IsResource="false">AppIcon.png</IconPath> <IconPath IsRelative="true" IsResource="false">AppIcon.png</IconPath>
<Capabilities> <Capabilities>
<Capability Name="ID_CAP_NETWORKING" /> <Capability Name="ID_CAP_NETWORKING" />
<Capability Name="ID_CAP_LOCATION" /> <Capability Name="ID_CAP_LOCATION" />
<Capability Name="ID_CAP_SENSORS" /> <Capability Name="ID_CAP_SENSORS" />
<Capability Name="ID_CAP_MICROPHONE" /> <Capability Name="ID_CAP_MICROPHONE" />
<Capability Name="ID_CAP_MEDIALIB" /> <Capability Name="ID_CAP_MEDIALIB" />
<Capability Name="ID_CAP_GAMERSERVICES" /> <Capability Name="ID_CAP_GAMERSERVICES" />
<Capability Name="ID_CAP_PHONEDIALER" /> <Capability Name="ID_CAP_PHONEDIALER" />
<Capability Name="ID_CAP_PUSH_NOTIFICATION" /> <Capability Name="ID_CAP_PUSH_NOTIFICATION" />
<Capability Name="ID_CAP_WEBBROWSERCOMPONENT" /> <Capability Name="ID_CAP_WEBBROWSERCOMPONENT" />
</Capabilities> </Capabilities>
<Tasks> <Tasks>
<DefaultTask Name="_default" NavigationPage="MainPage.xaml" /> <DefaultTask Name="_default" NavigationPage="MainPage.xaml" />
</Tasks> </Tasks>
<Tokens> <Tokens>
<PrimaryToken TokenID="Jellyfish.Virtu.Silverlight.Phone.Token" TaskName="_default"> <PrimaryToken TokenID="Jellyfish.Virtu.Silverlight.Phone.Token" TaskName="_default">
<TemplateType5> <TemplateType5>
<BackgroundImageURI IsRelative="true" IsResource="false">Background.png</BackgroundImageURI> <BackgroundImageURI IsRelative="true" IsResource="false">Background.png</BackgroundImageURI>
<Count>0</Count> <Count>0</Count>
<Title>Virtu</Title> <Title>Virtu</Title>
</TemplateType5> </TemplateType5>
</PrimaryToken> </PrimaryToken>
</Tokens> </Tokens>
</App> </App>
</Deployment> </Deployment>

View File

@ -1,5 +1,5 @@
<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment" <Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Deployment.Parts> <Deployment.Parts>
</Deployment.Parts> </Deployment.Parts>
</Deployment> </Deployment>

View File

@ -1,22 +1,22 @@
using System; using System;
using System.Reflection; using System.Reflection;
using System.Resources; using System.Resources;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Jellyfish.Library; using Jellyfish.Library;
[assembly: AssemblyTitle("Virtu")] [assembly: AssemblyTitle("Virtu")]
[assembly: AssemblyDescription("Apple IIe Emulator")] [assembly: AssemblyDescription("Apple IIe Emulator")]
[assembly: AssemblyProduct("Jellyfish.Virtu.Silverlight")] [assembly: AssemblyProduct("Jellyfish.Virtu.Silverlight")]
[assembly: AssemblyCompany("Digital Jellyfish Design Ltd")] [assembly: AssemblyCompany("Digital Jellyfish Design Ltd")]
[assembly: AssemblyCopyright("Copyright © 1995-2010 Digital Jellyfish Design Ltd")] [assembly: AssemblyCopyright("Copyright © 1995-2010 Digital Jellyfish Design Ltd")]
[assembly: AssemblyComment("Developed by Sean Fausett & Nick Westgate")] [assembly: AssemblyComment("Developed by Sean Fausett & Nick Westgate")]
[assembly: AssemblyVersion("0.8.3.0")] [assembly: AssemblyVersion("0.8.3.0")]
[assembly: AssemblyFileVersion("0.8.3.0")] [assembly: AssemblyFileVersion("0.8.3.0")]
[assembly: AssemblyInformationalVersion("0.8.3.0")] [assembly: AssemblyInformationalVersion("0.8.3.0")]
[assembly: CLSCompliant(false)] [assembly: CLSCompliant(false)]
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
[assembly: Guid("89a50370-1ed9-4cf1-ad08-043b6e6f3c90")] [assembly: Guid("89a50370-1ed9-4cf1-ad08-043b6e6f3c90")]
[assembly: NeutralResourcesLanguage("en")] [assembly: NeutralResourcesLanguage("en")]

View File

@ -1,15 +1,15 @@
<OutOfBrowserSettings ShortName="Virtu" EnableGPUAcceleration="False" ShowInstallMenuItem="True"> <OutOfBrowserSettings ShortName="Virtu" EnableGPUAcceleration="False" ShowInstallMenuItem="True">
<OutOfBrowserSettings.Blurb>Apple IIe Emulator</OutOfBrowserSettings.Blurb> <OutOfBrowserSettings.Blurb>Apple IIe Emulator</OutOfBrowserSettings.Blurb>
<OutOfBrowserSettings.WindowSettings> <OutOfBrowserSettings.WindowSettings>
<WindowSettings Title="Virtu" /> <WindowSettings Title="Virtu" />
</OutOfBrowserSettings.WindowSettings> </OutOfBrowserSettings.WindowSettings>
<OutOfBrowserSettings.SecuritySettings> <OutOfBrowserSettings.SecuritySettings>
<SecuritySettings ElevatedPermissions="Required" /> <SecuritySettings ElevatedPermissions="Required" />
</OutOfBrowserSettings.SecuritySettings> </OutOfBrowserSettings.SecuritySettings>
<OutOfBrowserSettings.Icons> <OutOfBrowserSettings.Icons>
<Icon Size="16,16">AppIcon16.png</Icon> <Icon Size="16,16">AppIcon16.png</Icon>
<Icon Size="32,32">AppIcon32.png</Icon> <Icon Size="32,32">AppIcon32.png</Icon>
<Icon Size="48,48">AppIcon48.png</Icon> <Icon Size="48,48">AppIcon48.png</Icon>
<Icon Size="128,128">AppIcon128.png</Icon> <Icon Size="128,128">AppIcon128.png</Icon>
</OutOfBrowserSettings.Icons> </OutOfBrowserSettings.Icons>
</OutOfBrowserSettings> </OutOfBrowserSettings>

View File

@ -1,60 +1,60 @@
using System; using System;
using System.Windows.Controls; using System.Windows.Controls;
using Jellyfish.Library; using Jellyfish.Library;
namespace Jellyfish.Virtu.Services namespace Jellyfish.Virtu.Services
{ {
public sealed class SilverlightAudioService : AudioService public sealed class SilverlightAudioService : AudioService
{ {
public SilverlightAudioService(Machine machine, UserControl page, MediaElement media) : public SilverlightAudioService(Machine machine, UserControl page, MediaElement media) :
base(machine) base(machine)
{ {
if (page == null) if (page == null)
{ {
throw new ArgumentNullException("page"); throw new ArgumentNullException("page");
} }
if (media == null) if (media == null)
{ {
throw new ArgumentNullException("media"); throw new ArgumentNullException("media");
} }
_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); _media.SetSource(_mediaSource);
page.Loaded += (sender, e) => _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
} }
public override void SetVolume(double volume) // machine thread public override void SetVolume(double volume) // machine thread
{ {
_media.Dispatcher.BeginInvoke(() => _media.Volume = volume); _media.Dispatcher.BeginInvoke(() => _media.Volume = volume);
} }
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing) if (disposing)
{ {
_mediaSource.Dispose(); _mediaSource.Dispose();
} }
base.Dispose(disposing); base.Dispose(disposing);
} }
private void OnMediaSourceUpdate(byte[] buffer, int bufferSize) // audio thread private void OnMediaSourceUpdate(byte[] buffer, int bufferSize) // audio thread
{ {
//if (_count++ % (1000 / SampleLatency) == 0) //if (_count++ % (1000 / SampleLatency) == 0)
//{ //{
// DebugService.WriteLine("OnMediaSourceUpdate"); // DebugService.WriteLine("OnMediaSourceUpdate");
//} //}
Update(bufferSize, (source, count) => Buffer.BlockCopy(source, 0, buffer, 0, count)); Update(bufferSize, (source, count) => Buffer.BlockCopy(source, 0, buffer, 0, count));
} }
private MediaElement _media; private MediaElement _media;
private WaveMediaStreamSource _mediaSource; private WaveMediaStreamSource _mediaSource;
//private int _count; //private int _count;
} }
} }

View File

@ -1,26 +1,26 @@
using System; using System;
using Jellyfish.Library; using Jellyfish.Library;
namespace Jellyfish.Virtu.Services namespace Jellyfish.Virtu.Services
{ {
public sealed class SilverlightDebugService : DebugService public sealed class SilverlightDebugService : DebugService
{ {
public SilverlightDebugService(Machine machine, MainPage page) : public SilverlightDebugService(Machine machine, MainPage page) :
base(machine) base(machine)
{ {
if (page == null) if (page == null)
{ {
throw new ArgumentNullException("page"); throw new ArgumentNullException("page");
} }
_page = page; _page = page;
} }
protected override void OnWriteLine(string message) protected override void OnWriteLine(string message)
{ {
_page.Dispatcher.CheckBeginInvoke(() => _page.WriteLine(message + Environment.NewLine)); _page.Dispatcher.CheckBeginInvoke(() => _page.WriteLine(message + Environment.NewLine));
} }
private MainPage _page; private MainPage _page;
} }
} }

View File

@ -1,402 +1,402 @@
using System; using System;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
namespace Jellyfish.Virtu.Services namespace Jellyfish.Virtu.Services
{ {
public sealed class SilverlightKeyboardService : KeyboardService public sealed class SilverlightKeyboardService : KeyboardService
{ {
public SilverlightKeyboardService(Machine machine, UserControl page) : public SilverlightKeyboardService(Machine machine, UserControl page) :
base(machine) base(machine)
{ {
if (page == null) if (page == null)
{ {
throw new ArgumentNullException("page"); throw new ArgumentNullException("page");
} }
page.KeyDown += OnPageKeyDown; page.KeyDown += OnPageKeyDown;
page.KeyUp += OnPageKeyUp; page.KeyUp += OnPageKeyUp;
page.LostFocus += OnPageLostFocus; page.LostFocus += OnPageLostFocus;
} }
public override bool IsKeyDown(int key) public override bool IsKeyDown(int key)
{ {
return IsKeyDown((Key)key); return IsKeyDown((Key)key);
} }
public override void Update() // main thread public override void Update() // main thread
{ {
if (_updateAnyKeyDown) // SL is missing access to keyboard state; could lose track of keyboard state after Alt+Tab if (_updateAnyKeyDown) // SL is missing access to keyboard state; could lose track of keyboard state after Alt+Tab
{ {
_updateAnyKeyDown = false; _updateAnyKeyDown = false;
IsAnyKeyDown = false; IsAnyKeyDown = false;
foreach (Key key in KeyValues) foreach (Key key in KeyValues)
{ {
if (IsKeyDown(key)) if (IsKeyDown(key))
{ {
IsAnyKeyDown = true; IsAnyKeyDown = true;
break; break;
} }
} }
} }
var modifiers = System.Windows.Input.Keyboard.Modifiers; var modifiers = System.Windows.Input.Keyboard.Modifiers;
IsControlKeyDown = ((modifiers & ModifierKeys.Control) != 0); IsControlKeyDown = ((modifiers & ModifierKeys.Control) != 0);
IsShiftKeyDown = ((modifiers & ModifierKeys.Shift) != 0); IsShiftKeyDown = ((modifiers & ModifierKeys.Shift) != 0);
IsOpenAppleKeyDown = ((modifiers & ModifierKeys.Alt) != 0) || IsKeyDown(Key.NumPad0); IsOpenAppleKeyDown = ((modifiers & ModifierKeys.Alt) != 0) || IsKeyDown(Key.NumPad0);
IsCloseAppleKeyDown = ((modifiers & ModifierKeys.Windows) != 0) || IsKeyDown(Key.Decimal); IsCloseAppleKeyDown = ((modifiers & ModifierKeys.Windows) != 0) || IsKeyDown(Key.Decimal);
IsResetKeyDown = IsControlKeyDown && IsKeyDown(Key.Back); IsResetKeyDown = IsControlKeyDown && IsKeyDown(Key.Back);
base.Update(); base.Update();
} }
private bool IsKeyDown(Key key) private bool IsKeyDown(Key key)
{ {
return _states[(int)key]; return _states[(int)key];
} }
private void OnPageKeyDown(object sender, KeyEventArgs e) private void OnPageKeyDown(object sender, KeyEventArgs e)
{ {
//DebugService.WriteLine(string.Concat("OnPageKeyDn: Key=", e.Key, " PlatformKeyCode=", e.PlatformKeyCode)); //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;
IsAnyKeyDown = true; IsAnyKeyDown = true;
int asciiKey = GetAsciiKey(e.Key, e.PlatformKeyCode); int asciiKey = GetAsciiKey(e.Key, e.PlatformKeyCode);
if (asciiKey >= 0) if (asciiKey >= 0)
{ {
Machine.Keyboard.Latch = asciiKey; Machine.Keyboard.Latch = asciiKey;
e.Handled = true; e.Handled = true;
} }
Update(); Update();
} }
private void OnPageKeyUp(object sender, KeyEventArgs e) private void OnPageKeyUp(object sender, KeyEventArgs e)
{ {
//DebugService.WriteLine(string.Concat("OnPageKeyUp: Key=", e.Key, " PlatformKeyCode=", e.PlatformKeyCode)); //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;
var modifiers = System.Windows.Input.Keyboard.Modifiers; var modifiers = System.Windows.Input.Keyboard.Modifiers;
bool control = ((modifiers & ModifierKeys.Control) != 0); bool control = ((modifiers & ModifierKeys.Control) != 0);
if (e.Key == Key.CapsLock) if (e.Key == Key.CapsLock)
{ {
_capsLock ^= true; // SL is missing caps lock support; try to track manually _capsLock ^= true; // SL is missing caps lock support; try to track manually
} }
else if (control && (e.Key == Key.Divide)) else if (control && (e.Key == Key.Divide))
{ {
Machine.Cpu.ToggleThrottle(); Machine.Cpu.ToggleThrottle();
} }
else if (control && (e.Key == Key.Multiply)) else if (control && (e.Key == Key.Multiply))
{ {
Machine.Video.ToggleMonochrome(); Machine.Video.ToggleMonochrome();
} }
else if (control && (e.Key == Key.Subtract)) else if (control && (e.Key == Key.Subtract))
{ {
Machine.Video.ToggleFullScreen(); Machine.Video.ToggleFullScreen();
} }
Update(); Update();
} }
private void OnPageLostFocus(object sender, RoutedEventArgs e) // reset keyboard state on lost focus; can't access keyboard state on got focus private void OnPageLostFocus(object sender, RoutedEventArgs e) // reset keyboard state on lost focus; can't access keyboard state on got focus
{ {
IsAnyKeyDown = false; IsAnyKeyDown = false;
foreach (Key key in KeyValues) foreach (Key key in KeyValues)
{ {
_states[(int)key] = false; _states[(int)key] = false;
} }
} }
[SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")] [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
[SuppressMessage("Microsoft.Maintainability", "CA1505:AvoidUnmaintainableCode")] [SuppressMessage("Microsoft.Maintainability", "CA1505:AvoidUnmaintainableCode")]
private int GetAsciiKey(Key key, int platformKeyCode) private int GetAsciiKey(Key key, int platformKeyCode)
{ {
var modifiers = System.Windows.Input.Keyboard.Modifiers; var modifiers = System.Windows.Input.Keyboard.Modifiers;
bool control = ((modifiers & ModifierKeys.Control) != 0); bool control = ((modifiers & ModifierKeys.Control) != 0);
bool shift = ((modifiers & ModifierKeys.Shift) != 0); bool shift = ((modifiers & ModifierKeys.Shift) != 0);
bool capsLock = shift ^ _capsLock; bool capsLock = shift ^ _capsLock;
switch (key) switch (key)
{ {
case Key.Left: case Key.Left:
return 0x08; return 0x08;
case Key.Tab: case Key.Tab:
return 0x09; return 0x09;
case Key.Down: case Key.Down:
return 0x0A; return 0x0A;
case Key.Up: case Key.Up:
return 0x0B; return 0x0B;
case Key.Enter: case Key.Enter:
return 0x0D; return 0x0D;
case Key.Right: case Key.Right:
return 0x15; return 0x15;
case Key.Escape: case Key.Escape:
return 0x1B; return 0x1B;
case Key.Back: case Key.Back:
return control ? -1 : 0x7F; return control ? -1 : 0x7F;
case Key.Space: case Key.Space:
return ' '; return ' ';
case Key.D1: case Key.D1:
return shift ? '!' : '1'; return shift ? '!' : '1';
case Key.D2: case Key.D2:
return control ? 0x00 : shift ? '@' : '2'; return control ? 0x00 : shift ? '@' : '2';
case Key.D3: case Key.D3:
return shift ? '#' : '3'; return shift ? '#' : '3';
case Key.D4: case Key.D4:
return shift ? '$' : '4'; return shift ? '$' : '4';
case Key.D5: case Key.D5:
return shift ? '%' : '5'; return shift ? '%' : '5';
case Key.D6: case Key.D6:
return control ? 0x1E : shift ? '^' : '6'; return control ? 0x1E : shift ? '^' : '6';
case Key.D7: case Key.D7:
return shift ? '&' : '7'; return shift ? '&' : '7';
case Key.D8: case Key.D8:
return shift ? '*' : '8'; return shift ? '*' : '8';
case Key.D9: case Key.D9:
return shift ? '(' : '9'; return shift ? '(' : '9';
case Key.D0: case Key.D0:
return shift ? ')' : '0'; return shift ? ')' : '0';
case Key.A: case Key.A:
return control ? 0x01 : capsLock ? 'A' : 'a'; return control ? 0x01 : capsLock ? 'A' : 'a';
case Key.B: case Key.B:
return control ? 0x02 : capsLock ? 'B' : 'b'; return control ? 0x02 : capsLock ? 'B' : 'b';
case Key.C: case Key.C:
return control ? 0x03 : capsLock ? 'C' : 'c'; return control ? 0x03 : capsLock ? 'C' : 'c';
case Key.D: case Key.D:
return control ? 0x04 : capsLock ? 'D' : 'd'; return control ? 0x04 : capsLock ? 'D' : 'd';
case Key.E: case Key.E:
return control ? 0x05 : capsLock ? 'E' : 'e'; return control ? 0x05 : capsLock ? 'E' : 'e';
case Key.F: case Key.F:
return control ? 0x06 : capsLock ? 'F' : 'f'; return control ? 0x06 : capsLock ? 'F' : 'f';
case Key.G: case Key.G:
return control ? 0x07 : capsLock ? 'G' : 'g'; return control ? 0x07 : capsLock ? 'G' : 'g';
case Key.H: case Key.H:
return control ? 0x08 : capsLock ? 'H' : 'h'; return control ? 0x08 : capsLock ? 'H' : 'h';
case Key.I: case Key.I:
return control ? 0x09 : capsLock ? 'I' : 'i'; return control ? 0x09 : capsLock ? 'I' : 'i';
case Key.J: case Key.J:
return control ? 0x0A : capsLock ? 'J' : 'j'; return control ? 0x0A : capsLock ? 'J' : 'j';
case Key.K: case Key.K:
return control ? 0x0B : capsLock ? 'K' : 'k'; return control ? 0x0B : capsLock ? 'K' : 'k';
case Key.L: case Key.L:
return control ? 0x0C : capsLock ? 'L' : 'l'; return control ? 0x0C : capsLock ? 'L' : 'l';
case Key.M: case Key.M:
return control ? 0x0D : capsLock ? 'M' : 'm'; return control ? 0x0D : capsLock ? 'M' : 'm';
case Key.N: case Key.N:
return control ? 0x0E : capsLock ? 'N' : 'n'; return control ? 0x0E : capsLock ? 'N' : 'n';
case Key.O: case Key.O:
return control ? 0x0F : capsLock ? 'O' : 'o'; return control ? 0x0F : capsLock ? 'O' : 'o';
case Key.P: case Key.P:
return control ? 0x10 : capsLock ? 'P' : 'p'; return control ? 0x10 : capsLock ? 'P' : 'p';
case Key.Q: case Key.Q:
return control ? 0x11 : capsLock ? 'Q' : 'q'; return control ? 0x11 : capsLock ? 'Q' : 'q';
case Key.R: case Key.R:
return control ? 0x12 : capsLock ? 'R' : 'r'; return control ? 0x12 : capsLock ? 'R' : 'r';
case Key.S: case Key.S:
return control ? 0x13 : capsLock ? 'S' : 's'; return control ? 0x13 : capsLock ? 'S' : 's';
case Key.T: case Key.T:
return control ? 0x14 : capsLock ? 'T' : 't'; return control ? 0x14 : capsLock ? 'T' : 't';
case Key.U: case Key.U:
return control ? 0x15 : capsLock ? 'U' : 'u'; return control ? 0x15 : capsLock ? 'U' : 'u';
case Key.V: case Key.V:
return control ? 0x16 : capsLock ? 'V' : 'v'; return control ? 0x16 : capsLock ? 'V' : 'v';
case Key.W: case Key.W:
return control ? 0x17 : capsLock ? 'W' : 'w'; return control ? 0x17 : capsLock ? 'W' : 'w';
case Key.X: case Key.X:
return control ? 0x18 : capsLock ? 'X' : 'x'; return control ? 0x18 : capsLock ? 'X' : 'x';
case Key.Y: case Key.Y:
return control ? 0x19 : capsLock ? 'Y' : 'y'; return control ? 0x19 : capsLock ? 'Y' : 'y';
case Key.Z: case Key.Z:
return control ? 0x1A : capsLock ? 'Z' : 'z'; return control ? 0x1A : capsLock ? 'Z' : 'z';
case Key.Unknown: case Key.Unknown:
switch (Environment.OSVersion.Platform) switch (Environment.OSVersion.Platform)
{ {
case PlatformID.Win32NT: case PlatformID.Win32NT:
switch (platformKeyCode) switch (platformKeyCode)
{ {
case 0xBA: // WinForms Keys.Oem1 case 0xBA: // WinForms Keys.Oem1
return shift ? ':' : ';'; return shift ? ':' : ';';
case 0xBF: // WinForms Keys.Oem2 case 0xBF: // WinForms Keys.Oem2
return shift ? '?' : '/'; return shift ? '?' : '/';
case 0xC0: // WinForms Keys.Oem3 case 0xC0: // WinForms Keys.Oem3
return shift ? '~' : '`'; return shift ? '~' : '`';
case 0xDB: // WinForms Keys.Oem4 case 0xDB: // WinForms Keys.Oem4
return shift ? '{' : '['; return shift ? '{' : '[';
case 0xDC: // WinForms Keys.Oem5 case 0xDC: // WinForms Keys.Oem5
return control ? 0x1C : shift ? '|' : '\\'; return control ? 0x1C : shift ? '|' : '\\';
case 0xDD: // WinForms Keys.Oem6 case 0xDD: // WinForms Keys.Oem6
return control ? 0x1D : shift ? '}' : ']'; return control ? 0x1D : shift ? '}' : ']';
case 0xDE: // WinForms Keys.Oem7 case 0xDE: // WinForms Keys.Oem7
return shift ? '"' : '\''; return shift ? '"' : '\'';
case 0xBD: // WinForms Keys.OemMinus case 0xBD: // WinForms Keys.OemMinus
return control ? 0x1F : shift ? '_' : '-'; return control ? 0x1F : shift ? '_' : '-';
case 0xBB: // WinForms Keys.OemPlus case 0xBB: // WinForms Keys.OemPlus
return shift ? '+' : '='; return shift ? '+' : '=';
case 0xBC: // WinForms Keys.OemComma case 0xBC: // WinForms Keys.OemComma
return shift ? '<' : ','; return shift ? '<' : ',';
case 0xBE: // WinForms Keys.OemPeriod case 0xBE: // WinForms Keys.OemPeriod
return shift ? '>' : '.'; return shift ? '>' : '.';
} }
break; break;
#if !WINDOWS_PHONE #if !WINDOWS_PHONE
case PlatformID.MacOSX: case PlatformID.MacOSX:
switch (platformKeyCode) switch (platformKeyCode)
{ {
case 0x29: case 0x29:
return shift ? ':' : ';'; return shift ? ':' : ';';
case 0x2C: case 0x2C:
return shift ? '?' : '/'; return shift ? '?' : '/';
case 0x32: case 0x32:
return shift ? '~' : '`'; return shift ? '~' : '`';
case 0x21: case 0x21:
return shift ? '{' : '['; return shift ? '{' : '[';
case 0x2A: case 0x2A:
return control ? 0x1C : shift ? '|' : '\\'; return control ? 0x1C : shift ? '|' : '\\';
case 0x1E: case 0x1E:
return control ? 0x1D : shift ? '}' : ']'; return control ? 0x1D : shift ? '}' : ']';
case 0x27: case 0x27:
return shift ? '"' : '\''; return shift ? '"' : '\'';
case 0x1B: case 0x1B:
return control ? 0x1F : shift ? '_' : '-'; return control ? 0x1F : shift ? '_' : '-';
case 0x18: case 0x18:
return shift ? '+' : '='; return shift ? '+' : '=';
case 0x2B: case 0x2B:
return shift ? '<' : ','; return shift ? '<' : ',';
case 0x2F: case 0x2F:
return shift ? '>' : '.'; return shift ? '>' : '.';
} }
break; break;
#endif #endif
case PlatformID.Unix: case PlatformID.Unix:
switch (platformKeyCode) switch (platformKeyCode)
{ {
case 0x2F: case 0x2F:
return shift ? ':' : ';'; return shift ? ':' : ';';
case 0x3D: case 0x3D:
return shift ? '?' : '/'; return shift ? '?' : '/';
case 0x31: case 0x31:
return shift ? '~' : '`'; return shift ? '~' : '`';
case 0x22: case 0x22:
return shift ? '{' : '['; return shift ? '{' : '[';
case 0x33: case 0x33:
return control ? 0x1C : shift ? '|' : '\\'; return control ? 0x1C : shift ? '|' : '\\';
case 0x23: case 0x23:
return control ? 0x1D : shift ? '}' : ']'; return control ? 0x1D : shift ? '}' : ']';
case 0x30: case 0x30:
return shift ? '"' : '\''; return shift ? '"' : '\'';
case 0x14: case 0x14:
return control ? 0x1F : shift ? '_' : '-'; return control ? 0x1F : shift ? '_' : '-';
case 0x15: case 0x15:
return shift ? '+' : '='; return shift ? '+' : '=';
case 0x3B: case 0x3B:
return shift ? '<' : ','; return shift ? '<' : ',';
case 0x3C: case 0x3C:
return shift ? '>' : '.'; return shift ? '>' : '.';
} }
break; break;
} }
break; break;
} }
return -1; return -1;
} }
private static readonly Key[] KeyValues = private static readonly Key[] KeyValues =
(from key in (from key in
(from field in typeof(Key).GetFields() // missing Enum.GetValues; use reflection (from field in typeof(Key).GetFields() // missing Enum.GetValues; use reflection
where field.IsLiteral where field.IsLiteral
select (Key)field.GetValue(typeof(Key))) select (Key)field.GetValue(typeof(Key)))
where (key != Key.None) // filter Key.None where (key != Key.None) // filter Key.None
select key).ToArray(); select key).ToArray();
private static readonly int KeyCount = (int)(KeyValues.Max()) + 1; private static readonly int KeyCount = (int)(KeyValues.Max()) + 1;
private bool[] _states = new bool[KeyCount]; private bool[] _states = new bool[KeyCount];
private bool _capsLock; private bool _capsLock;
private bool _updateAnyKeyDown; private bool _updateAnyKeyDown;
} }
} }

View File

@ -1,100 +1,100 @@
using System; using System;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
#if WINDOWS_PHONE #if WINDOWS_PHONE
using Microsoft.Phone.Controls; using Microsoft.Phone.Controls;
#endif #endif
namespace Jellyfish.Virtu.Services namespace Jellyfish.Virtu.Services
{ {
public sealed class SilverlightVideoService : VideoService public sealed class SilverlightVideoService : VideoService
{ {
public SilverlightVideoService(Machine machine, UserControl page, Image image) : public SilverlightVideoService(Machine machine, UserControl page, Image image) :
base(machine) base(machine)
{ {
if (page == null) if (page == null)
{ {
throw new ArgumentNullException("page"); throw new ArgumentNullException("page");
} }
if (image == null) if (image == null)
{ {
throw new ArgumentNullException("image"); throw new ArgumentNullException("image");
} }
_page = page; _page = page;
_image = image; _image = image;
_image.Source = _bitmap; _image.Source = _bitmap;
#if !WINDOWS_PHONE #if !WINDOWS_PHONE
_page.LayoutUpdated += (sender, e) => SetWindowSizeToContent(); _page.LayoutUpdated += (sender, e) => SetWindowSizeToContent();
#else #else
((PhoneApplicationPage)_page).OrientationChanged += (sender, e) => SetImageSize(swapOrientation: (e.Orientation & PageOrientation.Landscape) != 0); ((PhoneApplicationPage)_page).OrientationChanged += (sender, e) => SetImageSize(swapOrientation: (e.Orientation & PageOrientation.Landscape) != 0);
#endif #endif
_page.SizeChanged += (sender, e) => SetImageSize(); _page.SizeChanged += (sender, e) => SetImageSize();
} }
[SuppressMessage("Microsoft.Usage", "CA2233:OperationsShouldNotOverflow")] [SuppressMessage("Microsoft.Usage", "CA2233:OperationsShouldNotOverflow")]
public override void SetPixel(int x, int y, uint color) public override void SetPixel(int x, int y, uint color)
{ {
_pixels[y * BitmapWidth + x] = (int)color; _pixels[y * BitmapWidth + x] = (int)color;
_pixelsDirty = true; _pixelsDirty = true;
} }
public override void Update() // main thread public override void Update() // main thread
{ {
#if !WINDOWS_PHONE #if !WINDOWS_PHONE
var content = Application.Current.Host.Content; var content = Application.Current.Host.Content;
if (Application.Current.IsRunningOutOfBrowser && (content.IsFullScreen != IsFullScreen)) if (Application.Current.IsRunningOutOfBrowser && (content.IsFullScreen != IsFullScreen))
{ {
Application.Current.RootVisual.Dispatcher.BeginInvoke(() => content.IsFullScreen = IsFullScreen); // queue to dispatcher; avoids crash! Application.Current.RootVisual.Dispatcher.BeginInvoke(() => content.IsFullScreen = IsFullScreen); // queue to dispatcher; avoids crash!
} }
#endif #endif
if (_pixelsDirty) if (_pixelsDirty)
{ {
_pixelsDirty = false; _pixelsDirty = false;
for (int i = 0; i < BitmapWidth * BitmapHeight; i++) for (int i = 0; i < BitmapWidth * BitmapHeight; i++)
{ {
_bitmap.Pixels[i] = _pixels[i]; _bitmap.Pixels[i] = _pixels[i];
} }
_bitmap.Invalidate(); _bitmap.Invalidate();
} }
} }
private void SetImageSize(bool swapOrientation = false) private void SetImageSize(bool swapOrientation = false)
{ {
int uniformScale = Math.Max(1, swapOrientation ? Math.Min((int)_page.RenderSize.Height / BitmapWidth, (int)_page.RenderSize.Width / BitmapHeight) : int uniformScale = Math.Max(1, swapOrientation ? Math.Min((int)_page.RenderSize.Height / BitmapWidth, (int)_page.RenderSize.Width / BitmapHeight) :
Math.Min((int)_page.RenderSize.Width / BitmapWidth, (int)_page.RenderSize.Height / BitmapHeight)); Math.Min((int)_page.RenderSize.Width / BitmapWidth, (int)_page.RenderSize.Height / BitmapHeight));
_image.Width = uniformScale * BitmapWidth; _image.Width = uniformScale * BitmapWidth;
_image.Height = uniformScale * BitmapHeight; _image.Height = uniformScale * BitmapHeight;
Machine.Video.DirtyScreen(); Machine.Video.DirtyScreen();
} }
#if !WINDOWS_PHONE #if !WINDOWS_PHONE
private void SetWindowSizeToContent() private void SetWindowSizeToContent()
{ {
if (Application.Current.IsRunningOutOfBrowser && !_sizedToContent) if (Application.Current.IsRunningOutOfBrowser && !_sizedToContent)
{ {
_sizedToContent = true; _sizedToContent = true;
var window = Application.Current.MainWindow; var window = Application.Current.MainWindow;
var size = Application.Current.RootVisual.DesiredSize; var size = Application.Current.RootVisual.DesiredSize;
window.Width = size.Width; window.Width = size.Width;
window.Height = size.Height; window.Height = size.Height;
} }
} }
#endif #endif
private const int BitmapWidth = 560; private const int BitmapWidth = 560;
private const int BitmapHeight = 384; private const int BitmapHeight = 384;
private UserControl _page; private UserControl _page;
private Image _image; private Image _image;
private WriteableBitmap _bitmap = new WriteableBitmap(BitmapWidth, BitmapHeight); private WriteableBitmap _bitmap = new WriteableBitmap(BitmapWidth, BitmapHeight);
private int[] _pixels = new int[BitmapWidth * BitmapHeight]; private int[] _pixels = new int[BitmapWidth * BitmapHeight];
private bool _pixelsDirty; private bool _pixelsDirty;
#if !WINDOWS_PHONE #if !WINDOWS_PHONE
private bool _sizedToContent; private bool _sizedToContent;
#endif #endif
} }
} }

View File

@ -1,73 +1,73 @@
using System; using System;
using Jellyfish.Virtu.Services; using Jellyfish.Virtu.Services;
namespace Jellyfish.Virtu namespace Jellyfish.Virtu
{ {
public sealed class Speaker : MachineComponent public sealed class Speaker : MachineComponent
{ {
public Speaker(Machine machine) : public Speaker(Machine machine) :
base(machine) base(machine)
{ {
_flushOutputEvent = FlushOutputEvent; // cache delegates; avoids garbage _flushOutputEvent = FlushOutputEvent; // cache delegates; avoids garbage
} }
public override void Initialize() public override void Initialize()
{ {
_audioService = Machine.Services.GetService<AudioService>(); _audioService = Machine.Services.GetService<AudioService>();
UpdateSettings(); UpdateSettings();
Machine.Video.VSync += (sender, e) => UpdateSettings(); Machine.Video.VSync += (sender, e) => UpdateSettings();
Machine.Events.AddEvent(CyclesPerFlush * Machine.Settings.Cpu.Multiplier, _flushOutputEvent); Machine.Events.AddEvent(CyclesPerFlush * Machine.Settings.Cpu.Multiplier, _flushOutputEvent);
} }
public override void Reset() public override void Reset()
{ {
_audioService.Reset(); _audioService.Reset();
_isHigh = false; _isHigh = false;
_highCycles = _totalCycles = 0; _highCycles = _totalCycles = 0;
} }
public void ToggleOutput() public void ToggleOutput()
{ {
UpdateCycles(); UpdateCycles();
_isHigh ^= true; _isHigh ^= true;
} }
private void FlushOutputEvent() private void FlushOutputEvent()
{ {
UpdateCycles(); UpdateCycles();
_audioService.Output(_highCycles * short.MaxValue / _totalCycles); // quick and dirty decimation _audioService.Output(_highCycles * short.MaxValue / _totalCycles); // quick and dirty decimation
_highCycles = _totalCycles = 0; _highCycles = _totalCycles = 0;
Machine.Events.AddEvent(CyclesPerFlush * Machine.Settings.Cpu.Multiplier, _flushOutputEvent); Machine.Events.AddEvent(CyclesPerFlush * Machine.Settings.Cpu.Multiplier, _flushOutputEvent);
} }
private void UpdateCycles() private void UpdateCycles()
{ {
int delta = (int)(Machine.Cpu.Cycles - _lastCycles); int delta = (int)(Machine.Cpu.Cycles - _lastCycles);
if (_isHigh) if (_isHigh)
{ {
_highCycles += delta; _highCycles += delta;
} }
_totalCycles += delta; _totalCycles += delta;
_lastCycles = Machine.Cpu.Cycles; _lastCycles = Machine.Cpu.Cycles;
} }
private void UpdateSettings() private void UpdateSettings()
{ {
_audioService.SetVolume(Machine.Settings.Audio.Volume); _audioService.SetVolume(Machine.Settings.Audio.Volume);
} }
private const int CyclesPerFlush = 23; private const int CyclesPerFlush = 23;
private Action _flushOutputEvent; private Action _flushOutputEvent;
private bool _isHigh; private bool _isHigh;
private int _highCycles; private int _highCycles;
private int _totalCycles; private int _totalCycles;
private long _lastCycles; private long _lastCycles;
private AudioService _audioService; private AudioService _audioService;
} }
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,8 @@
<jl:ApplicationBase x:Class="Jellyfish.Virtu.MainApp" <jl:ApplicationBase x:Class="Jellyfish.Virtu.MainApp"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:jl="clr-namespace:Jellyfish.Library;assembly=Jellyfish.Library" xmlns:jl="clr-namespace:Jellyfish.Library;assembly=Jellyfish.Library"
StartupUri="MainWindow.xaml"> StartupUri="MainWindow.xaml">
<Application.Resources> <Application.Resources>
</Application.Resources> </Application.Resources>
</jl:ApplicationBase> </jl:ApplicationBase>

View File

@ -1,14 +1,14 @@
using System.Security.Permissions; using System.Security.Permissions;
using Jellyfish.Library; using Jellyfish.Library;
namespace Jellyfish.Virtu namespace Jellyfish.Virtu
{ {
public sealed partial class MainApp : ApplicationBase public sealed partial class MainApp : ApplicationBase
{ {
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)] [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
public MainApp() : public MainApp() :
base("Virtu") base("Virtu")
{ {
} }
} }
} }

View File

@ -1,23 +1,23 @@
<UserControl x:Class="Jellyfish.Virtu.MainPage" <UserControl x:Class="Jellyfish.Virtu.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:jl="clr-namespace:Jellyfish.Library;assembly=Jellyfish.Library" xmlns:jl="clr-namespace:Jellyfish.Library;assembly=Jellyfish.Library"
Focusable="True"> Focusable="True">
<Grid Background="Black"> <Grid Background="Black">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition /> <RowDefinition />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<Button x:Name="_disk1Button" Content="Disk 1" Focusable="False" IsTabStop="False" Margin="4,4,0,4" /> <Button x:Name="_disk1Button" Content="Disk 1" Focusable="False" IsTabStop="False" Margin="4,4,0,4" />
<Button x:Name="_disk2Button" Content="Disk 2" Focusable="False" IsTabStop="False" Margin="4,4,0,4" /> <Button x:Name="_disk2Button" Content="Disk 2" Focusable="False" IsTabStop="False" Margin="4,4,0,4" />
</StackPanel> </StackPanel>
<jl:FrameRateCounter Margin="0,0,4,0" HorizontalAlignment="Right" VerticalAlignment="Center" /> <jl:FrameRateCounter Margin="0,0,4,0" HorizontalAlignment="Right" VerticalAlignment="Center" />
<Grid Grid.Row="1"> <Grid Grid.Row="1">
<Image x:Name="_image" MinWidth="560" MinHeight="384" RenderOptions.BitmapScalingMode="NearestNeighbor" HorizontalAlignment="Center" VerticalAlignment="Center" /> <Image x:Name="_image" MinWidth="560" MinHeight="384" RenderOptions.BitmapScalingMode="NearestNeighbor" HorizontalAlignment="Center" VerticalAlignment="Center" />
<ScrollViewer x:Name="_debugScrollViewer" BorderThickness="0" Focusable="False" IsTabStop="False" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"> <ScrollViewer x:Name="_debugScrollViewer" BorderThickness="0" Focusable="False" IsTabStop="False" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<TextBlock x:Name="_debugText" FontFamily="Consolas" FontSize="12" Foreground="White" /> <TextBlock x:Name="_debugText" FontFamily="Consolas" FontSize="12" Foreground="White" />
</ScrollViewer> </ScrollViewer>
</Grid> </Grid>
</Grid> </Grid>
</UserControl> </UserControl>

View File

@ -1,106 +1,106 @@
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using System.IO; using System.IO;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media; using System.Windows.Media;
using Jellyfish.Virtu.Services; using Jellyfish.Virtu.Services;
using Microsoft.Win32; using Microsoft.Win32;
namespace Jellyfish.Virtu namespace Jellyfish.Virtu
{ {
public sealed partial class MainPage : UserControl, IDisposable public sealed partial class MainPage : UserControl, IDisposable
{ {
public MainPage() public MainPage()
{ {
InitializeComponent(); InitializeComponent();
if (!DesignerProperties.GetIsInDesignMode(this)) if (!DesignerProperties.GetIsInDesignMode(this))
{ {
_debugService = new WpfDebugService(_machine, this); _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(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);
_machine.Services.AddService(typeof(AudioService), _audioService); _machine.Services.AddService(typeof(AudioService), _audioService);
_machine.Services.AddService(typeof(VideoService), _videoService); _machine.Services.AddService(typeof(VideoService), _videoService);
Loaded += (sender, e) => _machine.Start(); Loaded += (sender, e) => _machine.Start();
CompositionTarget.Rendering += OnCompositionTargetRendering; CompositionTarget.Rendering += OnCompositionTargetRendering;
Application.Current.Exit += (sender, e) => _machine.Stop(); Application.Current.Exit += (sender, e) => _machine.Stop();
_disk1Button.Click += (sender, e) => OnDiskButtonClick(0); _disk1Button.Click += (sender, e) => OnDiskButtonClick(0);
_disk2Button.Click += (sender, e) => OnDiskButtonClick(1); _disk2Button.Click += (sender, e) => OnDiskButtonClick(1);
} }
} }
public void Dispose() public void Dispose()
{ {
_machine.Dispose(); _machine.Dispose();
_debugService.Dispose(); _debugService.Dispose();
_storageService.Dispose(); _storageService.Dispose();
_keyboardService.Dispose(); _keyboardService.Dispose();
_gamePortService.Dispose(); _gamePortService.Dispose();
_audioService.Dispose(); _audioService.Dispose();
_videoService.Dispose(); _videoService.Dispose();
} }
public void WriteLine(string message) public void WriteLine(string message)
{ {
_debugText.Text += message; _debugText.Text += message;
_debugScrollViewer.UpdateLayout(); _debugScrollViewer.UpdateLayout();
_debugScrollViewer.ScrollToVerticalOffset(double.MaxValue); _debugScrollViewer.ScrollToVerticalOffset(double.MaxValue);
} }
private void OnCompositionTargetRendering(object sender, EventArgs e) private void OnCompositionTargetRendering(object sender, EventArgs e)
{ {
_keyboardService.Update(); _keyboardService.Update();
_gamePortService.Update(); _gamePortService.Update();
_videoService.Update(); _videoService.Update();
} }
private void OnDiskButtonClick(int drive) private void OnDiskButtonClick(int drive)
{ {
var dialog = new OpenFileDialog() { Filter = "Disk Files (*.dsk;*.nib)|*.dsk;*.nib|All Files (*.*)|*.*" }; var dialog = new OpenFileDialog() { Filter = "Disk Files (*.dsk;*.nib)|*.dsk;*.nib|All Files (*.*)|*.*" };
bool? result = dialog.ShowDialog(); bool? result = dialog.ShowDialog();
if (result.HasValue && result.Value) if (result.HasValue && result.Value)
{ {
using (var stream = File.OpenRead(dialog.FileName)) using (var stream = File.OpenRead(dialog.FileName))
{ {
_machine.Pause(); _machine.Pause();
var diskII = _machine.FindDiskIIController(); var diskII = _machine.FindDiskIIController();
if (diskII != null) if (diskII != null)
{ {
diskII.Drives[drive].InsertDisk(dialog.FileName, stream, false); diskII.Drives[drive].InsertDisk(dialog.FileName, stream, false);
var settings = _machine.Settings.DiskII; var settings = _machine.Settings.DiskII;
if (drive == 0) if (drive == 0)
{ {
settings.Disk1.Name = dialog.FileName; settings.Disk1.Name = dialog.FileName;
} }
else else
{ {
settings.Disk2.Name = dialog.FileName; settings.Disk2.Name = dialog.FileName;
} }
} }
_machine.Unpause(); _machine.Unpause();
} }
} }
} }
private Machine _machine = new Machine(); private Machine _machine = new Machine();
private DebugService _debugService; private DebugService _debugService;
private StorageService _storageService; private StorageService _storageService;
private KeyboardService _keyboardService; private KeyboardService _keyboardService;
private GamePortService _gamePortService; private GamePortService _gamePortService;
private AudioService _audioService; private AudioService _audioService;
private VideoService _videoService; private VideoService _videoService;
} }
} }

View File

@ -1,7 +1,7 @@
<Window x:Class="Jellyfish.Virtu.MainWindow" <Window x:Class="Jellyfish.Virtu.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:jv="clr-namespace:Jellyfish.Virtu" xmlns:jv="clr-namespace:Jellyfish.Virtu"
Title="Virtu" WindowStartupLocation="CenterScreen" FocusManager.FocusedElement="{Binding ElementName=_mainPage}"> Title="Virtu" WindowStartupLocation="CenterScreen" FocusManager.FocusedElement="{Binding ElementName=_mainPage}">
<jv:MainPage x:Name="_mainPage" /> <jv:MainPage x:Name="_mainPage" />
</Window> </Window>

View File

@ -1,12 +1,12 @@
using System.Windows; using System.Windows;
namespace Jellyfish.Virtu namespace Jellyfish.Virtu
{ {
public sealed partial class MainWindow : Window public sealed partial class MainWindow : Window
{ {
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
} }
} }
} }

View File

@ -1,25 +1,25 @@
using System; using System;
using System.Reflection; using System.Reflection;
using System.Resources; using System.Resources;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Windows; using System.Windows;
using Jellyfish.Library; using Jellyfish.Library;
[assembly: AssemblyTitle("Virtu")] [assembly: AssemblyTitle("Virtu")]
[assembly: AssemblyDescription("Apple IIe Emulator")] [assembly: AssemblyDescription("Apple IIe Emulator")]
[assembly: AssemblyProduct("Jellyfish.Virtu.Wpf")] [assembly: AssemblyProduct("Jellyfish.Virtu.Wpf")]
[assembly: AssemblyCompany("Digital Jellyfish Design Ltd")] [assembly: AssemblyCompany("Digital Jellyfish Design Ltd")]
[assembly: AssemblyCopyright("Copyright © 1995-2010 Digital Jellyfish Design Ltd")] [assembly: AssemblyCopyright("Copyright © 1995-2010 Digital Jellyfish Design Ltd")]
[assembly: AssemblyComment("Developed by Sean Fausett & Nick Westgate")] [assembly: AssemblyComment("Developed by Sean Fausett & Nick Westgate")]
[assembly: AssemblyVersion("0.8.3.0")] [assembly: AssemblyVersion("0.8.3.0")]
[assembly: AssemblyFileVersion("0.8.3.0")] [assembly: AssemblyFileVersion("0.8.3.0")]
[assembly: AssemblyInformationalVersion("0.8.3.0")] [assembly: AssemblyInformationalVersion("0.8.3.0")]
[assembly: CLSCompliant(false)] [assembly: CLSCompliant(false)]
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
[assembly: Guid("89a50370-1ed9-4cf1-ad08-043b6e6f3c90")] [assembly: Guid("89a50370-1ed9-4cf1-ad08-043b6e6f3c90")]
[assembly: NeutralResourcesLanguage("en")] [assembly: NeutralResourcesLanguage("en")]
[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)] [assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]

View File

@ -1,59 +1,59 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security; using System.Security;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using Jellyfish.Library; using Jellyfish.Library;
namespace Jellyfish.Virtu.Services namespace Jellyfish.Virtu.Services
{ {
public sealed class WpfAudioService : AudioService public sealed class WpfAudioService : AudioService
{ {
[SecurityCritical] [SecurityCritical]
public WpfAudioService(Machine machine, UserControl page) : public WpfAudioService(Machine machine, UserControl page) :
base(machine) base(machine)
{ {
if (page == null) if (page == null)
{ {
throw new ArgumentNullException("page"); throw new ArgumentNullException("page");
} }
_directSound = new DirectSound(SampleRate, SampleChannels, SampleBits, SampleSize, OnDirectSoundUpdate); _directSound = new DirectSound(SampleRate, SampleChannels, SampleBits, SampleSize, OnDirectSoundUpdate);
page.Loaded += (sender, e) => page.Loaded += (sender, e) =>
{ {
var window = Window.GetWindow(page); var window = Window.GetWindow(page);
_directSound.Start(window.GetHandle()); _directSound.Start(window.GetHandle());
window.Closed += (_sender, _e) => _directSound.Stop(); window.Closed += (_sender, _e) => _directSound.Stop();
}; };
} }
public override void SetVolume(double volume) // machine thread public override void SetVolume(double volume) // machine thread
{ {
_directSound.SetVolume(volume); _directSound.SetVolume(volume);
} }
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing) if (disposing)
{ {
_directSound.Dispose(); _directSound.Dispose();
} }
base.Dispose(disposing); base.Dispose(disposing);
} }
private void OnDirectSoundUpdate(IntPtr buffer, int bufferSize) // audio thread private void OnDirectSoundUpdate(IntPtr buffer, int bufferSize) // audio thread
{ {
//if (_count++ % (1000 / SampleLatency) == 0) //if (_count++ % (1000 / SampleLatency) == 0)
//{ //{
// DebugService.WriteLine("OnDirectSoundUpdate"); // DebugService.WriteLine("OnDirectSoundUpdate");
//} //}
Update(bufferSize, (source, count) => Marshal.Copy(source, 0, buffer, count)); Update(bufferSize, (source, count) => Marshal.Copy(source, 0, buffer, count));
} }
private DirectSound _directSound; private DirectSound _directSound;
//private int _count; //private int _count;
} }
} }

View File

@ -1,26 +1,26 @@
using System; using System;
using Jellyfish.Library; using Jellyfish.Library;
namespace Jellyfish.Virtu.Services namespace Jellyfish.Virtu.Services
{ {
public sealed class WpfDebugService : DebugService public sealed class WpfDebugService : DebugService
{ {
public WpfDebugService(Machine machine, MainPage page) : public WpfDebugService(Machine machine, MainPage page) :
base(machine) base(machine)
{ {
if (page == null) if (page == null)
{ {
throw new ArgumentNullException("page"); throw new ArgumentNullException("page");
} }
_page = page; _page = page;
} }
protected override void OnWriteLine(string message) protected override void OnWriteLine(string message)
{ {
_page.Dispatcher.CheckInvoke(() => _page.WriteLine(message + Environment.NewLine)); _page.Dispatcher.CheckInvoke(() => _page.WriteLine(message + Environment.NewLine));
} }
private MainPage _page; private MainPage _page;
} }
} }

View File

@ -1,297 +1,297 @@
using System; using System;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
namespace Jellyfish.Virtu.Services namespace Jellyfish.Virtu.Services
{ {
public sealed class WpfKeyboardService : KeyboardService public sealed class WpfKeyboardService : KeyboardService
{ {
public WpfKeyboardService(Machine machine, UserControl page) : public WpfKeyboardService(Machine machine, UserControl page) :
base(machine) base(machine)
{ {
if (page == null) if (page == null)
{ {
throw new ArgumentNullException("page"); throw new ArgumentNullException("page");
} }
page.KeyDown += OnPageKeyDown; page.KeyDown += OnPageKeyDown;
page.KeyUp += OnPageKeyUp; page.KeyUp += OnPageKeyUp;
page.GotKeyboardFocus += (sender, e) => _updateAnyKeyDown = true; page.GotKeyboardFocus += (sender, e) => _updateAnyKeyDown = true;
} }
public override bool IsKeyDown(int key) public override bool IsKeyDown(int key)
{ {
return IsKeyDown((Key)key); return IsKeyDown((Key)key);
} }
public override void Update() // main thread public override void Update() // main thread
{ {
var keyboard = System.Windows.Input.Keyboard.PrimaryDevice; var keyboard = System.Windows.Input.Keyboard.PrimaryDevice;
if (_updateAnyKeyDown) if (_updateAnyKeyDown)
{ {
_updateAnyKeyDown = false; _updateAnyKeyDown = false;
IsAnyKeyDown = false; IsAnyKeyDown = false;
foreach (Key key in KeyValues) foreach (Key key in KeyValues)
{ {
bool isKeyDown = keyboard.IsKeyDown(key); bool isKeyDown = keyboard.IsKeyDown(key);
_states[(int)key] = isKeyDown; _states[(int)key] = isKeyDown;
if (isKeyDown) if (isKeyDown)
{ {
IsAnyKeyDown = true; IsAnyKeyDown = true;
} }
} }
} }
IsControlKeyDown = ((keyboard.Modifiers & ModifierKeys.Control) != 0); IsControlKeyDown = ((keyboard.Modifiers & ModifierKeys.Control) != 0);
IsShiftKeyDown = ((keyboard.Modifiers & ModifierKeys.Shift) != 0); IsShiftKeyDown = ((keyboard.Modifiers & ModifierKeys.Shift) != 0);
IsOpenAppleKeyDown = keyboard.IsKeyDown(Key.LeftAlt) || IsKeyDown(Key.NumPad0); IsOpenAppleKeyDown = keyboard.IsKeyDown(Key.LeftAlt) || IsKeyDown(Key.NumPad0);
IsCloseAppleKeyDown = keyboard.IsKeyDown(Key.RightAlt) || IsKeyDown(Key.Decimal); IsCloseAppleKeyDown = keyboard.IsKeyDown(Key.RightAlt) || IsKeyDown(Key.Decimal);
IsResetKeyDown = IsControlKeyDown && keyboard.IsKeyDown(Key.Back); IsResetKeyDown = IsControlKeyDown && keyboard.IsKeyDown(Key.Back);
base.Update(); base.Update();
} }
private bool IsKeyDown(Key key) private bool IsKeyDown(Key key)
{ {
return _states[(int)key]; return _states[(int)key];
} }
private void OnPageKeyDown(object sender, KeyEventArgs e) private void OnPageKeyDown(object sender, KeyEventArgs e)
{ {
//DebugService.WriteLine(string.Concat("OnPageKeyDn: Key=", e.Key)); //DebugService.WriteLine(string.Concat("OnPageKeyDn: 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;
IsAnyKeyDown = true; IsAnyKeyDown = true;
int asciiKey = GetAsciiKey(e.Key, e.KeyboardDevice); int asciiKey = GetAsciiKey(e.Key, e.KeyboardDevice);
if (asciiKey >= 0) if (asciiKey >= 0)
{ {
Machine.Keyboard.Latch = asciiKey; Machine.Keyboard.Latch = asciiKey;
e.Handled = true; e.Handled = true;
} }
Update(); Update();
} }
private void OnPageKeyUp(object sender, KeyEventArgs e) private void OnPageKeyUp(object sender, KeyEventArgs e)
{ {
//DebugService.WriteLine(string.Concat("OnPageKeyUp: Key=", e.Key)); //DebugService.WriteLine(string.Concat("OnPageKeyUp: 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;
bool control = ((e.KeyboardDevice.Modifiers & ModifierKeys.Control) != 0); bool control = ((e.KeyboardDevice.Modifiers & ModifierKeys.Control) != 0);
if (control && (e.Key == Key.Divide)) if (control && (e.Key == Key.Divide))
{ {
Machine.Cpu.ToggleThrottle(); Machine.Cpu.ToggleThrottle();
} }
else if (control && (e.Key == Key.Multiply)) else if (control && (e.Key == Key.Multiply))
{ {
Machine.Video.ToggleMonochrome(); Machine.Video.ToggleMonochrome();
} }
else if (control && (e.Key == Key.Subtract)) else if (control && (e.Key == Key.Subtract))
{ {
Machine.Video.ToggleFullScreen(); Machine.Video.ToggleFullScreen();
} }
Update(); Update();
} }
[SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")] [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
[SuppressMessage("Microsoft.Maintainability", "CA1505:AvoidUnmaintainableCode")] [SuppressMessage("Microsoft.Maintainability", "CA1505:AvoidUnmaintainableCode")]
private static int GetAsciiKey(Key key, KeyboardDevice keyboard) private static int GetAsciiKey(Key key, KeyboardDevice keyboard)
{ {
bool control = ((keyboard.Modifiers & ModifierKeys.Control) != 0); bool control = ((keyboard.Modifiers & ModifierKeys.Control) != 0);
bool shift = ((keyboard.Modifiers & ModifierKeys.Shift) != 0); bool shift = ((keyboard.Modifiers & ModifierKeys.Shift) != 0);
bool capsLock = shift ^ keyboard.IsKeyToggled(Key.CapsLock); bool capsLock = shift ^ keyboard.IsKeyToggled(Key.CapsLock);
switch (key) switch (key)
{ {
case Key.Left: case Key.Left:
return 0x08; return 0x08;
case Key.Tab: case Key.Tab:
return 0x09; return 0x09;
case Key.Down: case Key.Down:
return 0x0A; return 0x0A;
case Key.Up: case Key.Up:
return 0x0B; return 0x0B;
case Key.Enter: case Key.Enter:
return 0x0D; return 0x0D;
case Key.Right: case Key.Right:
return 0x15; return 0x15;
case Key.Escape: case Key.Escape:
return 0x1B; return 0x1B;
case Key.Back: case Key.Back:
return control ? -1 : 0x7F; return control ? -1 : 0x7F;
case Key.Space: case Key.Space:
return ' '; return ' ';
case Key.D1: case Key.D1:
return shift ? '!' : '1'; return shift ? '!' : '1';
case Key.D2: case Key.D2:
return control ? 0x00 : shift ? '@' : '2'; return control ? 0x00 : shift ? '@' : '2';
case Key.D3: case Key.D3:
return shift ? '#' : '3'; return shift ? '#' : '3';
case Key.D4: case Key.D4:
return shift ? '$' : '4'; return shift ? '$' : '4';
case Key.D5: case Key.D5:
return shift ? '%' : '5'; return shift ? '%' : '5';
case Key.D6: case Key.D6:
return control ? 0x1E : shift ? '^' : '6'; return control ? 0x1E : shift ? '^' : '6';
case Key.D7: case Key.D7:
return shift ? '&' : '7'; return shift ? '&' : '7';
case Key.D8: case Key.D8:
return shift ? '*' : '8'; return shift ? '*' : '8';
case Key.D9: case Key.D9:
return shift ? '(' : '9'; return shift ? '(' : '9';
case Key.D0: case Key.D0:
return shift ? ')' : '0'; return shift ? ')' : '0';
case Key.A: case Key.A:
return control ? 0x01 : capsLock ? 'A' : 'a'; return control ? 0x01 : capsLock ? 'A' : 'a';
case Key.B: case Key.B:
return control ? 0x02 : capsLock ? 'B' : 'b'; return control ? 0x02 : capsLock ? 'B' : 'b';
case Key.C: case Key.C:
return control ? 0x03 : capsLock ? 'C' : 'c'; return control ? 0x03 : capsLock ? 'C' : 'c';
case Key.D: case Key.D:
return control ? 0x04 : capsLock ? 'D' : 'd'; return control ? 0x04 : capsLock ? 'D' : 'd';
case Key.E: case Key.E:
return control ? 0x05 : capsLock ? 'E' : 'e'; return control ? 0x05 : capsLock ? 'E' : 'e';
case Key.F: case Key.F:
return control ? 0x06 : capsLock ? 'F' : 'f'; return control ? 0x06 : capsLock ? 'F' : 'f';
case Key.G: case Key.G:
return control ? 0x07 : capsLock ? 'G' : 'g'; return control ? 0x07 : capsLock ? 'G' : 'g';
case Key.H: case Key.H:
return control ? 0x08 : capsLock ? 'H' : 'h'; return control ? 0x08 : capsLock ? 'H' : 'h';
case Key.I: case Key.I:
return control ? 0x09 : capsLock ? 'I' : 'i'; return control ? 0x09 : capsLock ? 'I' : 'i';
case Key.J: case Key.J:
return control ? 0x0A : capsLock ? 'J' : 'j'; return control ? 0x0A : capsLock ? 'J' : 'j';
case Key.K: case Key.K:
return control ? 0x0B : capsLock ? 'K' : 'k'; return control ? 0x0B : capsLock ? 'K' : 'k';
case Key.L: case Key.L:
return control ? 0x0C : capsLock ? 'L' : 'l'; return control ? 0x0C : capsLock ? 'L' : 'l';
case Key.M: case Key.M:
return control ? 0x0D : capsLock ? 'M' : 'm'; return control ? 0x0D : capsLock ? 'M' : 'm';
case Key.N: case Key.N:
return control ? 0x0E : capsLock ? 'N' : 'n'; return control ? 0x0E : capsLock ? 'N' : 'n';
case Key.O: case Key.O:
return control ? 0x0F : capsLock ? 'O' : 'o'; return control ? 0x0F : capsLock ? 'O' : 'o';
case Key.P: case Key.P:
return control ? 0x10 : capsLock ? 'P' : 'p'; return control ? 0x10 : capsLock ? 'P' : 'p';
case Key.Q: case Key.Q:
return control ? 0x11 : capsLock ? 'Q' : 'q'; return control ? 0x11 : capsLock ? 'Q' : 'q';
case Key.R: case Key.R:
return control ? 0x12 : capsLock ? 'R' : 'r'; return control ? 0x12 : capsLock ? 'R' : 'r';
case Key.S: case Key.S:
return control ? 0x13 : capsLock ? 'S' : 's'; return control ? 0x13 : capsLock ? 'S' : 's';
case Key.T: case Key.T:
return control ? 0x14 : capsLock ? 'T' : 't'; return control ? 0x14 : capsLock ? 'T' : 't';
case Key.U: case Key.U:
return control ? 0x15 : capsLock ? 'U' : 'u'; return control ? 0x15 : capsLock ? 'U' : 'u';
case Key.V: case Key.V:
return control ? 0x16 : capsLock ? 'V' : 'v'; return control ? 0x16 : capsLock ? 'V' : 'v';
case Key.W: case Key.W:
return control ? 0x17 : capsLock ? 'W' : 'w'; return control ? 0x17 : capsLock ? 'W' : 'w';
case Key.X: case Key.X:
return control ? 0x18 : capsLock ? 'X' : 'x'; return control ? 0x18 : capsLock ? 'X' : 'x';
case Key.Y: case Key.Y:
return control ? 0x19 : capsLock ? 'Y' : 'y'; return control ? 0x19 : capsLock ? 'Y' : 'y';
case Key.Z: case Key.Z:
return control ? 0x1A : capsLock ? 'Z' : 'z'; return control ? 0x1A : capsLock ? 'Z' : 'z';
case Key.Oem1: case Key.Oem1:
return shift ? ':' : ';'; return shift ? ':' : ';';
case Key.Oem2: case Key.Oem2:
return shift ? '?' : '/'; return shift ? '?' : '/';
case Key.Oem3: case Key.Oem3:
return shift ? '~' : '`'; return shift ? '~' : '`';
case Key.Oem4: case Key.Oem4:
return shift ? '{' : '['; return shift ? '{' : '[';
case Key.Oem5: case Key.Oem5:
return control ? 0x1C : shift ? '|' : '\\'; return control ? 0x1C : shift ? '|' : '\\';
case Key.Oem6: case Key.Oem6:
return control ? 0x1D : shift ? '}' : ']'; return control ? 0x1D : shift ? '}' : ']';
case Key.Oem7: case Key.Oem7:
return shift ? '"' : '\''; return shift ? '"' : '\'';
case Key.OemMinus: case Key.OemMinus:
return control ? 0x1F : shift ? '_' : '-'; return control ? 0x1F : shift ? '_' : '-';
case Key.OemPlus: case Key.OemPlus:
return shift ? '+' : '='; return shift ? '+' : '=';
case Key.OemComma: case Key.OemComma:
return shift ? '<' : ','; return shift ? '<' : ',';
case Key.OemPeriod: case Key.OemPeriod:
return shift ? '>' : '.'; return shift ? '>' : '.';
} }
return -1; return -1;
} }
private static readonly Key[] KeyValues = private static readonly Key[] KeyValues =
(from key in (Key[])Enum.GetValues(typeof(Key)) (from key in (Key[])Enum.GetValues(typeof(Key))
where (key != Key.None) // filter Key.None; avoids validation exception where (key != Key.None) // filter Key.None; avoids validation exception
select key).ToArray(); select key).ToArray();
private static readonly int KeyCount = (int)(KeyValues.Max()) + 1; private static readonly int KeyCount = (int)(KeyValues.Max()) + 1;
private bool[] _states = new bool[KeyCount]; private bool[] _states = new bool[KeyCount];
private bool _updateAnyKeyDown; private bool _updateAnyKeyDown;
} }
} }

View File

@ -1,19 +1,19 @@
using System.Deployment.Application; using System.Deployment.Application;
using System.IO.IsolatedStorage; using System.IO.IsolatedStorage;
namespace Jellyfish.Virtu.Services namespace Jellyfish.Virtu.Services
{ {
public sealed class WpfStorageService : IsolatedStorageService public sealed class WpfStorageService : IsolatedStorageService
{ {
public WpfStorageService(Machine machine) : public WpfStorageService(Machine machine) :
base(machine) base(machine)
{ {
} }
protected override IsolatedStorageFile GetStore() protected override IsolatedStorageFile GetStore()
{ {
return ApplicationDeployment.IsNetworkDeployed ? // clickonce return ApplicationDeployment.IsNetworkDeployed ? // clickonce
IsolatedStorageFile.GetUserStoreForApplication() : IsolatedStorageFile.GetUserStoreForAssembly(); IsolatedStorageFile.GetUserStoreForApplication() : IsolatedStorageFile.GetUserStoreForAssembly();
} }
} }
} }

View File

@ -1,101 +1,101 @@
using System; using System;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
namespace Jellyfish.Virtu.Services namespace Jellyfish.Virtu.Services
{ {
public sealed class WpfVideoService : VideoService public sealed class WpfVideoService : VideoService
{ {
public WpfVideoService(Machine machine, UserControl page, Image image) : public WpfVideoService(Machine machine, UserControl page, Image image) :
base(machine) base(machine)
{ {
if (page == null) if (page == null)
{ {
throw new ArgumentNullException("page"); throw new ArgumentNullException("page");
} }
if (image == null) if (image == null)
{ {
throw new ArgumentNullException("image"); throw new ArgumentNullException("image");
} }
_page = page; _page = page;
_image = image; _image = image;
_image.Source = _bitmap; _image.Source = _bitmap;
_page.Loaded += (sender, e) => SetWindowSizeToContent(); _page.Loaded += (sender, e) => SetWindowSizeToContent();
_page.SizeChanged += (sender, e) => SetImageSize(); _page.SizeChanged += (sender, e) => SetImageSize();
} }
[SuppressMessage("Microsoft.Usage", "CA2233:OperationsShouldNotOverflow")] [SuppressMessage("Microsoft.Usage", "CA2233:OperationsShouldNotOverflow")]
public override void SetPixel(int x, int y, uint color) public override void SetPixel(int x, int y, uint color)
{ {
_pixels[y * BitmapWidth + x] = color; _pixels[y * BitmapWidth + x] = color;
_pixelsDirty = true; _pixelsDirty = true;
} }
public override void Update() // main thread public override void Update() // main thread
{ {
if (_isFullScreen != IsFullScreen) if (_isFullScreen != IsFullScreen)
{ {
var window = Window.GetWindow(_page); var window = Window.GetWindow(_page);
if (IsFullScreen) if (IsFullScreen)
{ {
window.ResizeMode = ResizeMode.NoResize; window.ResizeMode = ResizeMode.NoResize;
window.WindowStyle = WindowStyle.None; window.WindowStyle = WindowStyle.None;
window.WindowState = WindowState.Maximized; window.WindowState = WindowState.Maximized;
} }
else else
{ {
window.WindowState = WindowState.Normal; window.WindowState = WindowState.Normal;
window.WindowStyle = WindowStyle.SingleBorderWindow; window.WindowStyle = WindowStyle.SingleBorderWindow;
window.ResizeMode = ResizeMode.CanResize; window.ResizeMode = ResizeMode.CanResize;
} }
_isFullScreen = IsFullScreen; _isFullScreen = IsFullScreen;
} }
if (_pixelsDirty) if (_pixelsDirty)
{ {
_pixelsDirty = false; _pixelsDirty = false;
_bitmap.WritePixels(BitmapRect, _pixels, BitmapStride, 0); _bitmap.WritePixels(BitmapRect, _pixels, BitmapStride, 0);
} }
} }
private void SetImageSize() private void SetImageSize()
{ {
int uniformScale = Math.Max(1, Math.Min((int)_page.RenderSize.Width / BitmapWidth, (int)_page.RenderSize.Height / BitmapHeight)); int uniformScale = Math.Max(1, Math.Min((int)_page.RenderSize.Width / BitmapWidth, (int)_page.RenderSize.Height / BitmapHeight));
_image.Width = uniformScale * BitmapWidth; _image.Width = uniformScale * BitmapWidth;
_image.Height = uniformScale * BitmapHeight; _image.Height = uniformScale * BitmapHeight;
Machine.Video.DirtyScreen(); Machine.Video.DirtyScreen();
} }
private void SetWindowSizeToContent() private void SetWindowSizeToContent()
{ {
if (!_sizedToContent) if (!_sizedToContent)
{ {
_sizedToContent = true; _sizedToContent = true;
var window = Application.Current.MainWindow; var window = Application.Current.MainWindow;
var size = window.DesiredSize; var size = window.DesiredSize;
window.Width = size.Width; window.Width = size.Width;
window.Height = size.Height; window.Height = size.Height;
} }
} }
private const int BitmapWidth = 560; private const int BitmapWidth = 560;
private const int BitmapHeight = 384; private const int BitmapHeight = 384;
private const int BitmapDpi = 96; private const int BitmapDpi = 96;
private static readonly PixelFormat BitmapPixelFormat = PixelFormats.Bgr32; private static readonly PixelFormat BitmapPixelFormat = PixelFormats.Bgr32;
private static readonly int BitmapStride = (BitmapWidth * BitmapPixelFormat.BitsPerPixel + 7) / 8; private static readonly int BitmapStride = (BitmapWidth * BitmapPixelFormat.BitsPerPixel + 7) / 8;
private static readonly Int32Rect BitmapRect = new Int32Rect(0, 0, BitmapWidth, BitmapHeight); private static readonly Int32Rect BitmapRect = new Int32Rect(0, 0, BitmapWidth, BitmapHeight);
private UserControl _page; private UserControl _page;
private Image _image; private Image _image;
private WriteableBitmap _bitmap = new WriteableBitmap(BitmapWidth, BitmapHeight, BitmapDpi, BitmapDpi, BitmapPixelFormat, null); private WriteableBitmap _bitmap = new WriteableBitmap(BitmapWidth, BitmapHeight, BitmapDpi, BitmapDpi, BitmapPixelFormat, null);
private uint[] _pixels = new uint[BitmapWidth * BitmapHeight]; private uint[] _pixels = new uint[BitmapWidth * BitmapHeight];
private bool _pixelsDirty; private bool _pixelsDirty;
private bool _isFullScreen; private bool _isFullScreen;
private bool _sizedToContent; private bool _sizedToContent;
} }
} }

View File

@ -1,15 +1,15 @@
namespace Jellyfish.Virtu namespace Jellyfish.Virtu
{ {
#if WINDOWS || XBOX #if WINDOWS || XBOX
static class MainApp static class MainApp
{ {
static void Main() static void Main()
{ {
using (var game = new MainGame()) using (var game = new MainGame())
{ {
game.Run(); game.Run();
} }
} }
} }
#endif #endif
} }

View File

@ -1,91 +1,91 @@
using Jellyfish.Library; using Jellyfish.Library;
using Jellyfish.Virtu.Services; using Jellyfish.Virtu.Services;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
namespace Jellyfish.Virtu namespace Jellyfish.Virtu
{ {
public sealed class MainGame : GameBase public sealed class MainGame : GameBase
{ {
public MainGame() : public MainGame() :
base("Virtu") base("Virtu")
{ {
#if WINDOWS #if WINDOWS
IsMouseVisible = true; IsMouseVisible = true;
#endif #endif
var frameRateCounter = new FrameRateCounter(this); // no initializers; avoids CA2000 var frameRateCounter = new FrameRateCounter(this); // no initializers; avoids CA2000
Components.Add(frameRateCounter); Components.Add(frameRateCounter);
frameRateCounter.DrawOrder = 1; frameRateCounter.DrawOrder = 1;
frameRateCounter.FontName = "Consolas"; frameRateCounter.FontName = "Consolas";
_debugService = new DebugService(_machine); _debugService = new DebugService(_machine);
#if WINDOWS_PHONE #if WINDOWS_PHONE
_storageService = new IsolatedStorageService(_machine); _storageService = new IsolatedStorageService(_machine);
#else #else
_storageService = new XnaStorageService(_machine, this); _storageService = new XnaStorageService(_machine, this);
#endif #endif
_keyboardService = new XnaKeyboardService(_machine); _keyboardService = new XnaKeyboardService(_machine);
_gamePortService = new XnaGamePortService(_machine); _gamePortService = new XnaGamePortService(_machine);
_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(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);
_machine.Services.AddService(typeof(AudioService), _audioService); _machine.Services.AddService(typeof(AudioService), _audioService);
_machine.Services.AddService(typeof(VideoService), _videoService); _machine.Services.AddService(typeof(VideoService), _videoService);
} }
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing) if (disposing)
{ {
_machine.Dispose(); _machine.Dispose();
_debugService.Dispose(); _debugService.Dispose();
_storageService.Dispose(); _storageService.Dispose();
_keyboardService.Dispose(); _keyboardService.Dispose();
_gamePortService.Dispose(); _gamePortService.Dispose();
_audioService.Dispose(); _audioService.Dispose();
_videoService.Dispose(); _videoService.Dispose();
} }
base.Dispose(disposing); base.Dispose(disposing);
} }
protected override void BeginRun() protected override void BeginRun()
{ {
_machine.Start(); _machine.Start();
} }
protected override void Update(GameTime gameTime) protected override void Update(GameTime gameTime)
{ {
_keyboardService.Update(); _keyboardService.Update();
_gamePortService.Update(); _gamePortService.Update();
base.Update(gameTime); base.Update(gameTime);
} }
protected override void Draw(GameTime gameTime) protected override void Draw(GameTime gameTime)
{ {
GraphicsDevice.Clear(Color.Black); GraphicsDevice.Clear(Color.Black);
_videoService.Update(); _videoService.Update();
base.Draw(gameTime); base.Draw(gameTime);
} }
protected override void EndRun() protected override void EndRun()
{ {
_machine.Stop(); _machine.Stop();
} }
private Machine _machine = new Machine(); private Machine _machine = new Machine();
private DebugService _debugService; private DebugService _debugService;
private StorageService _storageService; private StorageService _storageService;
private KeyboardService _keyboardService; private KeyboardService _keyboardService;
private GamePortService _gamePortService; private GamePortService _gamePortService;
private AudioService _audioService; private AudioService _audioService;
private VideoService _videoService; private VideoService _videoService;
} }
} }

View File

@ -1,5 +1,5 @@
<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment" <Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Deployment.Parts> <Deployment.Parts>
</Deployment.Parts> </Deployment.Parts>
</Deployment> </Deployment>

View File

@ -1,28 +1,28 @@
using System; using System;
using System.Reflection; using System.Reflection;
using System.Resources; using System.Resources;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Jellyfish.Library; using Jellyfish.Library;
[assembly: AssemblyTitle("Virtu")] [assembly: AssemblyTitle("Virtu")]
[assembly: AssemblyDescription("Apple IIe Emulator")] [assembly: AssemblyDescription("Apple IIe Emulator")]
#if WINDOWS_PHONE #if WINDOWS_PHONE
[assembly: AssemblyProduct("Jellyfish.Virtu.Xna.Phone")] [assembly: AssemblyProduct("Jellyfish.Virtu.Xna.Phone")]
#elif XBOX #elif XBOX
[assembly: AssemblyProduct("Jellyfish.Virtu.Xna.Xbox")] [assembly: AssemblyProduct("Jellyfish.Virtu.Xna.Xbox")]
#else #else
[assembly: AssemblyProduct("Jellyfish.Virtu.Xna")] [assembly: AssemblyProduct("Jellyfish.Virtu.Xna")]
#endif #endif
[assembly: AssemblyCompany("Digital Jellyfish Design Ltd")] [assembly: AssemblyCompany("Digital Jellyfish Design Ltd")]
[assembly: AssemblyCopyright("Copyright © 1995-2010 Digital Jellyfish Design Ltd")] [assembly: AssemblyCopyright("Copyright © 1995-2010 Digital Jellyfish Design Ltd")]
[assembly: AssemblyComment("Developed by Sean Fausett & Nick Westgate")] [assembly: AssemblyComment("Developed by Sean Fausett & Nick Westgate")]
[assembly: AssemblyVersion("0.8.3.0")] [assembly: AssemblyVersion("0.8.3.0")]
[assembly: AssemblyFileVersion("0.8.3.0")] [assembly: AssemblyFileVersion("0.8.3.0")]
[assembly: AssemblyInformationalVersion("0.8.3.0")] [assembly: AssemblyInformationalVersion("0.8.3.0")]
[assembly: CLSCompliant(false)] [assembly: CLSCompliant(false)]
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
[assembly: Guid("89a50370-1ed9-4cf1-ad08-043b6e6f3c90")] [assembly: Guid("89a50370-1ed9-4cf1-ad08-043b6e6f3c90")]
[assembly: NeutralResourcesLanguage("en")] [assembly: NeutralResourcesLanguage("en")]

View File

@ -1,55 +1,55 @@
using System; using System;
using Jellyfish.Library; using Jellyfish.Library;
using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Audio;
namespace Jellyfish.Virtu.Services namespace Jellyfish.Virtu.Services
{ {
public sealed class XnaAudioService : AudioService public sealed class XnaAudioService : AudioService
{ {
public XnaAudioService(Machine machine, GameBase game) : public XnaAudioService(Machine machine, GameBase game) :
base(machine) base(machine)
{ {
if (game == null) if (game == null)
{ {
throw new ArgumentNullException("game"); throw new ArgumentNullException("game");
} }
_game = game; _game = game;
_dynamicSoundEffect.BufferNeeded += OnDynamicSoundEffectBufferNeeded; _dynamicSoundEffect.BufferNeeded += OnDynamicSoundEffectBufferNeeded;
_game.Exiting += (sender, e) => _dynamicSoundEffect.Stop(); _game.Exiting += (sender, e) => _dynamicSoundEffect.Stop();
_dynamicSoundEffect.SubmitBuffer(SampleZero); _dynamicSoundEffect.SubmitBuffer(SampleZero);
_dynamicSoundEffect.Play(); _dynamicSoundEffect.Play();
} }
public override void SetVolume(double volume) // machine thread public override void SetVolume(double volume) // machine thread
{ {
_dynamicSoundEffect.Volume = (float)volume; _dynamicSoundEffect.Volume = (float)volume;
} }
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing) if (disposing)
{ {
_dynamicSoundEffect.Dispose(); _dynamicSoundEffect.Dispose();
} }
base.Dispose(disposing); base.Dispose(disposing);
} }
private void OnDynamicSoundEffectBufferNeeded(object sender, EventArgs e) // audio thread private void OnDynamicSoundEffectBufferNeeded(object sender, EventArgs e) // audio thread
{ {
//if (_count++ % (1000 / SampleLatency) == 0) //if (_count++ % (1000 / SampleLatency) == 0)
//{ //{
// DebugService.WriteLine("OnDynamicSoundEffectBufferNeeded"); // 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; //private int _count;
} }
} }

View File

@ -1,64 +1,64 @@
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
namespace Jellyfish.Virtu.Services namespace Jellyfish.Virtu.Services
{ {
public sealed class XnaGamePortService : GamePortService public sealed class XnaGamePortService : GamePortService
{ {
public XnaGamePortService(Machine machine) : public XnaGamePortService(Machine machine) :
base(machine) base(machine)
{ {
} }
public override void Update() // main thread public override void Update() // main thread
{ {
_lastState = _state; _lastState = _state;
_state = GamePad.GetState(PlayerIndex.One); _state = GamePad.GetState(PlayerIndex.One);
if (_state.IsConnected && (_state != _lastState)) if (_state.IsConnected && (_state != _lastState))
{ {
var left = _state.ThumbSticks.Left; var left = _state.ThumbSticks.Left;
var right = _state.ThumbSticks.Right; var right = _state.ThumbSticks.Right;
var dpad = _state.DPad; var dpad = _state.DPad;
Paddle0 = (int)((1 + left.X) * PaddleScale); Paddle0 = (int)((1 + left.X) * PaddleScale);
Paddle1 = (int)((1 - left.Y) * PaddleScale); // invert y Paddle1 = (int)((1 - left.Y) * PaddleScale); // invert y
Paddle2 = (int)((1 + right.X) * PaddleScale); Paddle2 = (int)((1 + right.X) * PaddleScale);
Paddle3 = (int)((1 - right.Y) * PaddleScale); // invert y Paddle3 = (int)((1 - right.Y) * PaddleScale); // invert y
Joystick0 = GetJoystick(ref left, ref dpad); Joystick0 = GetJoystick(ref left, ref dpad);
Joystick1 = GetJoystick(ref right); Joystick1 = GetJoystick(ref right);
IsButton0Down = ((_state.Buttons.A == ButtonState.Pressed) || (_state.Buttons.LeftShoulder == ButtonState.Pressed)); IsButton0Down = ((_state.Buttons.A == ButtonState.Pressed) || (_state.Buttons.LeftShoulder == ButtonState.Pressed));
IsButton1Down = ((_state.Buttons.B == ButtonState.Pressed) || (_state.Buttons.RightShoulder == ButtonState.Pressed)); IsButton1Down = ((_state.Buttons.B == ButtonState.Pressed) || (_state.Buttons.RightShoulder == ButtonState.Pressed));
IsButton2Down = (_state.Buttons.X == ButtonState.Pressed); IsButton2Down = (_state.Buttons.X == ButtonState.Pressed);
} }
} }
private static Joystick GetJoystick(ref Vector2 thumbstick) private static Joystick GetJoystick(ref Vector2 thumbstick)
{ {
bool isUp = (thumbstick.Y > JoystickDeadZone); bool isUp = (thumbstick.Y > JoystickDeadZone);
bool isLeft = (thumbstick.X < -JoystickDeadZone); bool isLeft = (thumbstick.X < -JoystickDeadZone);
bool isRight = (thumbstick.X > JoystickDeadZone); bool isRight = (thumbstick.X > JoystickDeadZone);
bool isDown = (thumbstick.Y < -JoystickDeadZone); bool isDown = (thumbstick.Y < -JoystickDeadZone);
return new Joystick(isUp, isLeft, isRight, isDown); return new Joystick(isUp, isLeft, isRight, isDown);
} }
private static Joystick GetJoystick(ref Vector2 thumbstick, ref GamePadDPad dpad) private static Joystick GetJoystick(ref Vector2 thumbstick, ref GamePadDPad dpad)
{ {
bool isUp = ((thumbstick.Y > JoystickDeadZone) || (dpad.Up == ButtonState.Pressed)); bool isUp = ((thumbstick.Y > JoystickDeadZone) || (dpad.Up == ButtonState.Pressed));
bool isLeft = ((thumbstick.X < -JoystickDeadZone) || (dpad.Left == ButtonState.Pressed)); bool isLeft = ((thumbstick.X < -JoystickDeadZone) || (dpad.Left == ButtonState.Pressed));
bool isRight = ((thumbstick.X > JoystickDeadZone) || (dpad.Right == ButtonState.Pressed)); bool isRight = ((thumbstick.X > JoystickDeadZone) || (dpad.Right == ButtonState.Pressed));
bool isDown = ((thumbstick.Y < -JoystickDeadZone) || (dpad.Down == ButtonState.Pressed)); bool isDown = ((thumbstick.Y < -JoystickDeadZone) || (dpad.Down == ButtonState.Pressed));
return new Joystick(isUp, isLeft, isRight, isDown); return new Joystick(isUp, isLeft, isRight, isDown);
} }
private const int PaddleScale = 128; private const int PaddleScale = 128;
private const float JoystickDeadZone = 0.5f; private const float JoystickDeadZone = 0.5f;
private GamePadState _state; private GamePadState _state;
private GamePadState _lastState; private GamePadState _lastState;
} }
} }

View File

@ -1,330 +1,330 @@
using System; using System;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
namespace Jellyfish.Virtu.Services namespace Jellyfish.Virtu.Services
{ {
public sealed class XnaKeyboardService : KeyboardService public sealed class XnaKeyboardService : KeyboardService
{ {
public XnaKeyboardService(Machine machine) : public XnaKeyboardService(Machine machine) :
base(machine) base(machine)
{ {
} }
public override bool IsKeyDown(int key) public override bool IsKeyDown(int key)
{ {
return IsKeyDown((Keys)key); return IsKeyDown((Keys)key);
} }
public override void Update() // main thread public override void Update() // main thread
{ {
_lastState = _state; _lastState = _state;
_state = Microsoft.Xna.Framework.Input.Keyboard.GetState(); _state = Microsoft.Xna.Framework.Input.Keyboard.GetState();
var gamePadState = GamePad.GetState(PlayerIndex.One); var gamePadState = GamePad.GetState(PlayerIndex.One);
bool gamePadControl = (gamePadState.Buttons.LeftStick == ButtonState.Pressed); bool gamePadControl = (gamePadState.Buttons.LeftStick == ButtonState.Pressed);
if (_state != _lastState) if (_state != _lastState)
{ {
IsAnyKeyDown = false; IsAnyKeyDown = false;
foreach (Keys key in KeyValues) // xna doesn't support buffered input; loses input order and could lose keys between updates foreach (Keys key in KeyValues) // xna doesn't support buffered input; loses input order and could lose keys between updates
{ {
if (_state.IsKeyDown(key)) if (_state.IsKeyDown(key))
{ {
IsAnyKeyDown = true; IsAnyKeyDown = true;
if (!_lastState.IsKeyDown(key)) if (!_lastState.IsKeyDown(key))
{ {
_lastKey = key; _lastKey = key;
_lastTime = DateTime.UtcNow.Ticks; _lastTime = DateTime.UtcNow.Ticks;
_repeatTime = RepeatDelay; _repeatTime = RepeatDelay;
OnKeyDown(key, gamePadControl); OnKeyDown(key, gamePadControl);
} }
} }
else else
{ {
if (key == _lastKey) if (key == _lastKey)
{ {
_lastKey = Keys.None; _lastKey = Keys.None;
} }
if (_lastState.IsKeyDown(key)) if (_lastState.IsKeyDown(key))
{ {
OnKeyUp(key, gamePadControl); OnKeyUp(key, gamePadControl);
} }
} }
} }
} }
if (_lastKey != Keys.None) // repeat last key if (_lastKey != Keys.None) // repeat last key
{ {
long time = DateTime.UtcNow.Ticks; long time = DateTime.UtcNow.Ticks;
if (time - _lastTime >= _repeatTime) if (time - _lastTime >= _repeatTime)
{ {
_lastTime = time; _lastTime = time;
_repeatTime = RepeatSpeed; _repeatTime = RepeatSpeed;
OnKeyDown(_lastKey, gamePadControl); OnKeyDown(_lastKey, gamePadControl);
} }
} }
IsControlKeyDown = IsKeyDown(Keys.LeftControl) || IsKeyDown(Keys.RightControl); IsControlKeyDown = IsKeyDown(Keys.LeftControl) || IsKeyDown(Keys.RightControl);
IsShiftKeyDown = IsKeyDown(Keys.LeftShift) || IsKeyDown(Keys.RightShift); IsShiftKeyDown = IsKeyDown(Keys.LeftShift) || IsKeyDown(Keys.RightShift);
IsOpenAppleKeyDown = IsKeyDown(Keys.LeftAlt) || IsKeyDown(Keys.NumPad0) || (gamePadState.Buttons.LeftShoulder == ButtonState.Pressed); IsOpenAppleKeyDown = IsKeyDown(Keys.LeftAlt) || IsKeyDown(Keys.NumPad0) || (gamePadState.Buttons.LeftShoulder == ButtonState.Pressed);
IsCloseAppleKeyDown = IsKeyDown(Keys.RightAlt) || IsKeyDown(Keys.Decimal) || (gamePadState.Buttons.RightShoulder == ButtonState.Pressed); IsCloseAppleKeyDown = IsKeyDown(Keys.RightAlt) || IsKeyDown(Keys.Decimal) || (gamePadState.Buttons.RightShoulder == ButtonState.Pressed);
IsResetKeyDown = (IsControlKeyDown && IsKeyDown(Keys.Back)) || (gamePadControl && (gamePadState.Buttons.Start == ButtonState.Pressed)); IsResetKeyDown = (IsControlKeyDown && IsKeyDown(Keys.Back)) || (gamePadControl && (gamePadState.Buttons.Start == ButtonState.Pressed));
base.Update(); base.Update();
} }
private bool IsKeyDown(Keys key) private bool IsKeyDown(Keys key)
{ {
return _state.IsKeyDown(key); return _state.IsKeyDown(key);
} }
private void OnKeyDown(Keys key, bool gamePadControl) private void OnKeyDown(Keys key, bool gamePadControl)
{ {
//DebugService.WriteLine(string.Concat("OnKeyDn: Key=", key)); //DebugService.WriteLine(string.Concat("OnKeyDn: Key=", key));
int asciiKey = GetAsciiKey(key, gamePadControl); int asciiKey = GetAsciiKey(key, gamePadControl);
if (asciiKey >= 0) if (asciiKey >= 0)
{ {
Machine.Keyboard.Latch = asciiKey; Machine.Keyboard.Latch = asciiKey;
} }
} }
private void OnKeyUp(Keys key, bool gamePadControl) private void OnKeyUp(Keys key, bool gamePadControl)
{ {
//DebugService.WriteLine(string.Concat("OnKeyUp: Key=", key)); //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)
{ {
_capsLock ^= true; _capsLock ^= true;
} }
else if ((control && (key == Keys.Divide)) || (gamePadControl && (key == Keys.D8))) else if ((control && (key == Keys.Divide)) || (gamePadControl && (key == Keys.D8)))
{ {
Machine.Cpu.ToggleThrottle(); Machine.Cpu.ToggleThrottle();
} }
else if ((control && (key == Keys.Multiply)) || (gamePadControl && (key == Keys.D9))) else if ((control && (key == Keys.Multiply)) || (gamePadControl && (key == Keys.D9)))
{ {
Machine.Video.ToggleMonochrome(); Machine.Video.ToggleMonochrome();
} }
#if WINDOWS #if WINDOWS
else if ((control && (key == Keys.Subtract)) || (gamePadControl && (key == Keys.D0))) else if ((control && (key == Keys.Subtract)) || (gamePadControl && (key == Keys.D0)))
{ {
Machine.Video.ToggleFullScreen(); Machine.Video.ToggleFullScreen();
} }
#endif #endif
} }
[SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")] [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
[SuppressMessage("Microsoft.Maintainability", "CA1505:AvoidUnmaintainableCode")] [SuppressMessage("Microsoft.Maintainability", "CA1505:AvoidUnmaintainableCode")]
private int GetAsciiKey(Keys key, bool gamePadControl) private int GetAsciiKey(Keys key, bool gamePadControl)
{ {
bool control = IsKeyDown(Keys.LeftControl) || IsKeyDown(Keys.RightControl) || gamePadControl; bool control = IsKeyDown(Keys.LeftControl) || IsKeyDown(Keys.RightControl) || gamePadControl;
bool shift = IsKeyDown(Keys.LeftShift) || IsKeyDown(Keys.RightShift); bool shift = IsKeyDown(Keys.LeftShift) || IsKeyDown(Keys.RightShift);
bool capsLock = shift ^ _capsLock; bool capsLock = shift ^ _capsLock;
bool green = IsKeyDown(Keys.ChatPadGreen); bool green = IsKeyDown(Keys.ChatPadGreen);
bool orange = IsKeyDown(Keys.ChatPadOrange); bool orange = IsKeyDown(Keys.ChatPadOrange);
switch (key) switch (key)
{ {
case Keys.Left: case Keys.Left:
return 0x08; return 0x08;
case Keys.Tab: case Keys.Tab:
return 0x09; return 0x09;
case Keys.Down: case Keys.Down:
return 0x0A; return 0x0A;
case Keys.Up: case Keys.Up:
return 0x0B; return 0x0B;
case Keys.Enter: case Keys.Enter:
return 0x0D; return 0x0D;
case Keys.Right: case Keys.Right:
return 0x15; return 0x15;
case Keys.Escape: case Keys.Escape:
return 0x1B; return 0x1B;
case Keys.Back: case Keys.Back:
return control ? -1 : 0x7F; return control ? -1 : 0x7F;
case Keys.Space: case Keys.Space:
return ' '; return ' ';
case Keys.D1: case Keys.D1:
return shift ? '!' : '1'; return shift ? '!' : '1';
case Keys.D2: case Keys.D2:
return control ? 0x00 : shift ? '@' : '2'; return control ? 0x00 : shift ? '@' : '2';
case Keys.D3: case Keys.D3:
return shift ? '#' : '3'; return shift ? '#' : '3';
case Keys.D4: case Keys.D4:
return shift ? '$' : '4'; return shift ? '$' : '4';
case Keys.D5: case Keys.D5:
return shift ? '%' : '5'; return shift ? '%' : '5';
case Keys.D6: case Keys.D6:
return control ? 0x1E : shift ? '^' : '6'; return control ? 0x1E : shift ? '^' : '6';
case Keys.D7: case Keys.D7:
return shift ? '&' : '7'; return shift ? '&' : '7';
case Keys.D8: case Keys.D8:
return gamePadControl ? -1 : shift ? '*' : '8'; return gamePadControl ? -1 : shift ? '*' : '8';
case Keys.D9: case Keys.D9:
return gamePadControl ? -1 : shift ? '(' : '9'; return gamePadControl ? -1 : shift ? '(' : '9';
case Keys.D0: case Keys.D0:
return gamePadControl ? -1 : shift ? ')' : '0'; return gamePadControl ? -1 : shift ? ')' : '0';
case Keys.A: case Keys.A:
return control ? 0x01 : green ? '~' : capsLock ? 'A' : 'a'; return control ? 0x01 : green ? '~' : capsLock ? 'A' : 'a';
case Keys.B: case Keys.B:
return control ? 0x02 : green ? '|' : orange ? '+' : capsLock ? 'B' : 'b'; return control ? 0x02 : green ? '|' : orange ? '+' : capsLock ? 'B' : 'b';
case Keys.C: case Keys.C:
return control ? 0x03 : capsLock ? 'C' : 'c'; return control ? 0x03 : capsLock ? 'C' : 'c';
case Keys.D: case Keys.D:
return control ? 0x04 : green ? '{' : capsLock ? 'D' : 'd'; return control ? 0x04 : green ? '{' : capsLock ? 'D' : 'd';
case Keys.E: case Keys.E:
return control ? 0x05 : capsLock ? 'E' : 'e'; return control ? 0x05 : capsLock ? 'E' : 'e';
case Keys.F: case Keys.F:
return control ? 0x06 : green ? '}' : capsLock ? 'F' : 'f'; return control ? 0x06 : green ? '}' : capsLock ? 'F' : 'f';
case Keys.G: case Keys.G:
return control ? 0x07 : capsLock ? 'G' : 'g'; return control ? 0x07 : capsLock ? 'G' : 'g';
case Keys.H: case Keys.H:
return control ? 0x08 : green ? '/' : orange ? '\\' : capsLock ? 'H' : 'h'; return control ? 0x08 : green ? '/' : orange ? '\\' : capsLock ? 'H' : 'h';
case Keys.I: case Keys.I:
return control ? 0x09 : green ? '*' : capsLock ? 'I' : 'i'; return control ? 0x09 : green ? '*' : capsLock ? 'I' : 'i';
case Keys.J: case Keys.J:
return control ? 0x0A : green ? '\'' : orange ? '"' : capsLock ? 'J' : 'j'; return control ? 0x0A : green ? '\'' : orange ? '"' : capsLock ? 'J' : 'j';
case Keys.K: case Keys.K:
return control ? 0x0B : green ? '[' : capsLock ? 'K' : 'k'; return control ? 0x0B : green ? '[' : capsLock ? 'K' : 'k';
case Keys.L: case Keys.L:
return control ? 0x0C : green ? ']' : capsLock ? 'L' : 'l'; return control ? 0x0C : green ? ']' : capsLock ? 'L' : 'l';
case Keys.M: case Keys.M:
return control ? 0x0D : green ? '>' : capsLock ? 'M' : 'm'; return control ? 0x0D : green ? '>' : capsLock ? 'M' : 'm';
case Keys.N: case Keys.N:
return control ? 0x0E : green ? '<' : capsLock ? 'N' : 'n'; return control ? 0x0E : green ? '<' : capsLock ? 'N' : 'n';
case Keys.O: case Keys.O:
return control ? 0x0F : green ? '(' : capsLock ? 'O' : 'o'; return control ? 0x0F : green ? '(' : capsLock ? 'O' : 'o';
case Keys.P: case Keys.P:
return control ? 0x10 : green ? ')' : orange ? '=' : capsLock ? 'P' : 'p'; return control ? 0x10 : green ? ')' : orange ? '=' : capsLock ? 'P' : 'p';
case Keys.Q: case Keys.Q:
return control ? 0x11 : green ? '!' : capsLock ? 'Q' : 'q'; return control ? 0x11 : green ? '!' : capsLock ? 'Q' : 'q';
case Keys.R: case Keys.R:
return control ? 0x12 : green ? '#' : orange ? '$' : capsLock ? 'R' : 'r'; return control ? 0x12 : green ? '#' : orange ? '$' : capsLock ? 'R' : 'r';
case Keys.S: case Keys.S:
return control ? 0x13 : capsLock ? 'S' : 's'; return control ? 0x13 : capsLock ? 'S' : 's';
case Keys.T: case Keys.T:
return control ? 0x14 : green ? '%' : capsLock ? 'T' : 't'; return control ? 0x14 : green ? '%' : capsLock ? 'T' : 't';
case Keys.U: case Keys.U:
return control ? 0x15 : green ? '&' : capsLock ? 'U' : 'u'; return control ? 0x15 : green ? '&' : capsLock ? 'U' : 'u';
case Keys.V: case Keys.V:
return control ? 0x16 : green ? '-' : orange ? '_' : capsLock ? 'V' : 'v'; return control ? 0x16 : green ? '-' : orange ? '_' : capsLock ? 'V' : 'v';
case Keys.W: case Keys.W:
return control ? 0x17 : green ? '@' : capsLock ? 'W' : 'w'; return control ? 0x17 : green ? '@' : capsLock ? 'W' : 'w';
case Keys.X: case Keys.X:
return control ? 0x18 : capsLock ? 'X' : 'x'; return control ? 0x18 : capsLock ? 'X' : 'x';
case Keys.Y: case Keys.Y:
return control ? 0x19 : green ? '^' : capsLock ? 'Y' : 'y'; return control ? 0x19 : green ? '^' : capsLock ? 'Y' : 'y';
case Keys.Z: case Keys.Z:
return control ? 0x1A : green ? '`' : capsLock ? 'Z' : 'z'; return control ? 0x1A : green ? '`' : capsLock ? 'Z' : 'z';
case Keys.OemSemicolon: case Keys.OemSemicolon:
return shift ? ':' : ';'; return shift ? ':' : ';';
case Keys.OemQuestion: case Keys.OemQuestion:
return shift ? '?' : '/'; return shift ? '?' : '/';
case Keys.OemTilde: case Keys.OemTilde:
return shift ? '~' : '`'; return shift ? '~' : '`';
case Keys.OemOpenBrackets: case Keys.OemOpenBrackets:
return shift ? '{' : '['; return shift ? '{' : '[';
case Keys.OemBackslash: case Keys.OemBackslash:
case Keys.OemPipe: case Keys.OemPipe:
return control ? 0x1C : shift ? '|' : '\\'; return control ? 0x1C : shift ? '|' : '\\';
case Keys.OemCloseBrackets: case Keys.OemCloseBrackets:
return control ? 0x1D : shift ? '}' : ']'; return control ? 0x1D : shift ? '}' : ']';
case Keys.OemQuotes: case Keys.OemQuotes:
return shift ? '"' : '\''; return shift ? '"' : '\'';
case Keys.OemMinus: case Keys.OemMinus:
return control ? 0x1F : shift ? '_' : '-'; return control ? 0x1F : shift ? '_' : '-';
case Keys.OemPlus: case Keys.OemPlus:
return shift ? '+' : '='; return shift ? '+' : '=';
case Keys.OemComma: case Keys.OemComma:
return shift ? '<' : green ? ':' : orange ? ';' : ','; return shift ? '<' : green ? ':' : orange ? ';' : ',';
case Keys.OemPeriod: case Keys.OemPeriod:
return shift ? '>' : green ? '?' : '.'; return shift ? '>' : green ? '?' : '.';
} }
return -1; return -1;
} }
private static readonly Keys[] KeyValues = private static readonly Keys[] KeyValues =
#if WINDOWS_PHONE || XBOX #if WINDOWS_PHONE || XBOX
(from key in (from key in
(from field in typeof(Keys).GetFields() // missing Enum.GetValues; use reflection (from field in typeof(Keys).GetFields() // missing Enum.GetValues; use reflection
where field.IsLiteral where field.IsLiteral
select (Keys)field.GetValue(typeof(Keys))) select (Keys)field.GetValue(typeof(Keys)))
where (key != Keys.None) // filter Keys.None where (key != Keys.None) // filter Keys.None
select key).ToArray(); select key).ToArray();
#else #else
(from key in (Keys[])Enum.GetValues(typeof(Keys)) (from key in (Keys[])Enum.GetValues(typeof(Keys))
where (key != Keys.None) // filter Keys.None where (key != Keys.None) // filter Keys.None
select key).ToArray(); select key).ToArray();
#endif #endif
private static readonly long RepeatDelay = TimeSpan.FromMilliseconds(500).Ticks; private static readonly long RepeatDelay = TimeSpan.FromMilliseconds(500).Ticks;
private static readonly long RepeatSpeed = TimeSpan.FromMilliseconds(32).Ticks; private static readonly long RepeatSpeed = TimeSpan.FromMilliseconds(32).Ticks;
private KeyboardState _state; private KeyboardState _state;
private KeyboardState _lastState; private KeyboardState _lastState;
private bool _capsLock; private bool _capsLock;
private Keys _lastKey; private Keys _lastKey;
private long _lastTime; private long _lastTime;
private long _repeatTime; private long _repeatTime;
} }
} }

View File

@ -1,67 +1,67 @@
using System; using System;
using System.IO; using System.IO;
using Jellyfish.Library; using Jellyfish.Library;
using Microsoft.Xna.Framework.Storage; using Microsoft.Xna.Framework.Storage;
namespace Jellyfish.Virtu.Services namespace Jellyfish.Virtu.Services
{ {
public sealed class XnaStorageService : StorageService public sealed class XnaStorageService : StorageService
{ {
public XnaStorageService(Machine machine, GameBase game) : public XnaStorageService(Machine machine, GameBase game) :
base(machine) base(machine)
{ {
if (game == null) if (game == null)
{ {
throw new ArgumentNullException("game"); throw new ArgumentNullException("game");
} }
_game = game; _game = game;
} }
public override void Load(string path, Action<Stream> reader) public override void Load(string path, Action<Stream> reader)
{ {
if (reader == null) if (reader == null)
{ {
throw new ArgumentNullException("reader"); throw new ArgumentNullException("reader");
} }
try try
{ {
using (var storageContainer = OpenContainer()) using (var storageContainer = OpenContainer())
{ {
using (var stream = storageContainer.OpenFile(path)) using (var stream = storageContainer.OpenFile(path))
{ {
reader(stream); reader(stream);
} }
} }
} }
catch (FileNotFoundException) catch (FileNotFoundException)
{ {
} }
} }
public override void Save(string path, Action<Stream> writer) public override void Save(string path, Action<Stream> writer)
{ {
if (writer == null) if (writer == null)
{ {
throw new ArgumentNullException("writer"); throw new ArgumentNullException("writer");
} }
using (var storageContainer = OpenContainer()) using (var storageContainer = OpenContainer())
{ {
using (var stream = storageContainer.OpenFile(path)) using (var stream = storageContainer.OpenFile(path))
{ {
writer(stream); writer(stream);
} }
} }
} }
private StorageContainer OpenContainer() private StorageContainer OpenContainer()
{ {
return _storageDevice.Value.EndOpenContainer(_storageDevice.Value.BeginOpenContainer(_game.Name, null, null)); return _storageDevice.Value.EndOpenContainer(_storageDevice.Value.BeginOpenContainer(_game.Name, null, null));
} }
private GameBase _game; private GameBase _game;
private Lazy<StorageDevice> _storageDevice = new Lazy<StorageDevice>(() => StorageDevice.EndShowSelector(StorageDevice.BeginShowSelector(null, null))); private Lazy<StorageDevice> _storageDevice = new Lazy<StorageDevice>(() => StorageDevice.EndShowSelector(StorageDevice.BeginShowSelector(null, null)));
} }
} }

Some files were not shown because too many files have changed in this diff Show More