Cosmetic changes.

Set svn properties on files.

--HG--
extra : convert_revision : svn%3Affd33b8c-2492-42e0-bdc5-587b920b7d6d/trunk%4044493
This commit is contained in:
Sean Fausett 2010-04-04 00:12:01 +00:00
parent 21a9ba51dd
commit 7b713e6aaa
81 changed files with 13130 additions and 13141 deletions

View File

@ -1,15 +1,15 @@
using System;
namespace Jellyfish.Library
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true, Inherited = false)]
public sealed class AssemblyCommentAttribute : Attribute
{
public AssemblyCommentAttribute(string comment)
{
Comment = comment;
}
public string Comment { get; private set; }
}
}
using System;
namespace Jellyfish.Library
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true, Inherited = false)]
public sealed class AssemblyCommentAttribute : Attribute
{
public AssemblyCommentAttribute(string comment)
{
Comment = comment;
}
public string Comment { get; private set; }
}
}

View File

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

View File

@ -67,12 +67,12 @@ namespace Jellyfish.Library
GCHandleHelpers.Pin(new WaveFormat(_sampleRate, _sampleChannels, _sampleBits), waveFormat =>
{
BufferDescription 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);
});
ClearBuffer();
BufferPositionNotify[] positionEvents = new BufferPositionNotify[BlockCount]
var positionEvents = new BufferPositionNotify[BlockCount]
{
new BufferPositionNotify(0 * _sampleSize, _position1Event), new BufferPositionNotify(1 * _sampleSize, _position2Event)
};
@ -85,10 +85,7 @@ namespace Jellyfish.Library
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()
@ -106,10 +103,7 @@ namespace Jellyfish.Library
EventHandler<DirectSoundUpdateEventArgs> handler = Update;
if (handler != null)
{
UpdateBuffer(block * _sampleSize, _sampleSize, BufferLock.None, (buffer, bufferSize) =>
{
handler(this, DirectSoundUpdateEventArgs.Create(buffer, bufferSize));
});
UpdateBuffer(block * _sampleSize, _sampleSize, BufferLock.None, (buffer, bufferSize) => handler(this, DirectSoundUpdateEventArgs.Create(buffer, bufferSize)));
}
}
@ -154,7 +148,7 @@ namespace Jellyfish.Library
{
Initialize();
EventWaitHandle[] eventHandles = new EventWaitHandle[] { _position1Event, _position2Event, _stopEvent };
var eventHandles = new EventWaitHandle[] { _position1Event, _position2Event, _stopEvent };
int index = WaitHandle.WaitAny(eventHandles);
while (index < BlockCount)

View File

@ -14,7 +14,7 @@ namespace Jellyfish.Library
throw new ArgumentNullException("action");
}
GCHandle gcHandle = new GCHandle();
var gcHandle = new GCHandle();
try
{
gcHandle = GCHandle.Alloc(value, GCHandleType.Pinned);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,147 +1,147 @@
using System;
using System.ComponentModel;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using Microsoft.Win32.SafeHandles;
namespace Jellyfish.Library
{
[SecurityPermission(SecurityAction.InheritanceDemand, UnmanagedCode = true)]
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
public abstract class SafeAllocHandle : SafeHandleZeroOrMinusOneIsInvalid
{
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
protected SafeAllocHandle(bool ownsHandle) :
base(ownsHandle)
{
}
}
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
public sealed class SafeGlobalAllocHandle : SafeAllocHandle
{
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
public SafeGlobalAllocHandle() :
base(true)
{
}
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
public SafeGlobalAllocHandle(IntPtr existingHandle, bool ownsHandle) :
base(ownsHandle)
{
SetHandle(existingHandle);
}
public static SafeGlobalAllocHandle Allocate(int size)
{
return Allocate(0x0, size);
}
public static SafeGlobalAllocHandle Allocate(byte[] value)
{
if (value == null)
{
throw new ArgumentNullException("value");
}
SafeGlobalAllocHandle alloc = Allocate(value.Length);
Marshal.Copy(value, 0, alloc.DangerousGetHandle(), value.Length);
return alloc;
}
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
protected override bool ReleaseHandle()
{
return (NativeMethods.GlobalFree(handle) == IntPtr.Zero);
}
private static SafeGlobalAllocHandle Allocate(uint flags, int size)
{
SafeGlobalAllocHandle alloc = NativeMethods.GlobalAlloc(flags, (IntPtr)size);
if (alloc.IsInvalid)
{
throw new Win32Exception();
}
return alloc;
}
[SuppressUnmanagedCodeSecurity]
private static class NativeMethods
{
[DllImport("kernel32.dll", SetLastError = true)]
public static extern SafeGlobalAllocHandle GlobalAlloc(uint dwFlags, IntPtr sizetBytes);
[DllImport("kernel32.dll", SetLastError = true)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
public static extern IntPtr GlobalFree(IntPtr hMem);
}
}
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
public sealed class SafeLocalAllocHandle : SafeAllocHandle
{
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
public SafeLocalAllocHandle() :
base(true)
{
}
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
public SafeLocalAllocHandle(IntPtr existingHandle, bool ownsHandle) :
base(ownsHandle)
{
SetHandle(existingHandle);
}
public static SafeLocalAllocHandle Allocate(int size)
{
return Allocate(0x0, size);
}
public static SafeLocalAllocHandle Allocate(byte[] value)
{
if (value == null)
{
throw new ArgumentNullException("value");
}
SafeLocalAllocHandle alloc = Allocate(value.Length);
Marshal.Copy(value, 0, alloc.DangerousGetHandle(), value.Length);
return alloc;
}
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
protected override bool ReleaseHandle()
{
return (NativeMethods.LocalFree(handle) == IntPtr.Zero);
}
private static SafeLocalAllocHandle Allocate(uint flags, int size)
{
SafeLocalAllocHandle alloc = NativeMethods.LocalAlloc(flags, (IntPtr)size);
if (alloc.IsInvalid)
{
throw new Win32Exception();
}
return alloc;
}
[SuppressUnmanagedCodeSecurity]
private static class NativeMethods
{
[DllImport("kernel32.dll", SetLastError = true)]
public static extern SafeLocalAllocHandle LocalAlloc(uint dwFlags, IntPtr sizetBytes);
[DllImport("kernel32.dll", SetLastError = true)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
public static extern IntPtr LocalFree(IntPtr hMem);
}
}
}
using System;
using System.ComponentModel;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using Microsoft.Win32.SafeHandles;
namespace Jellyfish.Library
{
[SecurityPermission(SecurityAction.InheritanceDemand, UnmanagedCode = true)]
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
public abstract class SafeAllocHandle : SafeHandleZeroOrMinusOneIsInvalid
{
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
protected SafeAllocHandle(bool ownsHandle) :
base(ownsHandle)
{
}
}
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
public sealed class SafeGlobalAllocHandle : SafeAllocHandle
{
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
public SafeGlobalAllocHandle() :
base(true)
{
}
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
public SafeGlobalAllocHandle(IntPtr existingHandle, bool ownsHandle) :
base(ownsHandle)
{
SetHandle(existingHandle);
}
public static SafeGlobalAllocHandle Allocate(int size)
{
return Allocate(0x0, size);
}
public static SafeGlobalAllocHandle Allocate(byte[] value)
{
if (value == null)
{
throw new ArgumentNullException("value");
}
var alloc = Allocate(value.Length);
Marshal.Copy(value, 0, alloc.DangerousGetHandle(), value.Length);
return alloc;
}
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
protected override bool ReleaseHandle()
{
return (NativeMethods.GlobalFree(handle) == IntPtr.Zero);
}
private static SafeGlobalAllocHandle Allocate(uint flags, int size)
{
var alloc = NativeMethods.GlobalAlloc(flags, (IntPtr)size);
if (alloc.IsInvalid)
{
throw new Win32Exception();
}
return alloc;
}
[SuppressUnmanagedCodeSecurity]
private static class NativeMethods
{
[DllImport("kernel32.dll", SetLastError = true)]
public static extern SafeGlobalAllocHandle GlobalAlloc(uint dwFlags, IntPtr sizetBytes);
[DllImport("kernel32.dll", SetLastError = true)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
public static extern IntPtr GlobalFree(IntPtr hMem);
}
}
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
public sealed class SafeLocalAllocHandle : SafeAllocHandle
{
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
public SafeLocalAllocHandle() :
base(true)
{
}
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
public SafeLocalAllocHandle(IntPtr existingHandle, bool ownsHandle) :
base(ownsHandle)
{
SetHandle(existingHandle);
}
public static SafeLocalAllocHandle Allocate(int size)
{
return Allocate(0x0, size);
}
public static SafeLocalAllocHandle Allocate(byte[] value)
{
if (value == null)
{
throw new ArgumentNullException("value");
}
var alloc = Allocate(value.Length);
Marshal.Copy(value, 0, alloc.DangerousGetHandle(), value.Length);
return alloc;
}
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
protected override bool ReleaseHandle()
{
return (NativeMethods.LocalFree(handle) == IntPtr.Zero);
}
private static SafeLocalAllocHandle Allocate(uint flags, int size)
{
var alloc = NativeMethods.LocalAlloc(flags, (IntPtr)size);
if (alloc.IsInvalid)
{
throw new Win32Exception();
}
return alloc;
}
[SuppressUnmanagedCodeSecurity]
private static class NativeMethods
{
[DllImport("kernel32.dll", SetLastError = true)]
public static extern SafeLocalAllocHandle LocalAlloc(uint dwFlags, IntPtr sizetBytes);
[DllImport("kernel32.dll", SetLastError = true)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
public static extern IntPtr LocalFree(IntPtr hMem);
}
}
}

View File

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

View File

@ -1,65 +1,65 @@
using System;
using System.Text;
using System.Windows;
namespace Jellyfish.Library
{
public class ApplicationBase : Application
{
public ApplicationBase() :
this(null)
{
}
public ApplicationBase(string name)
{
Name = name;
UnhandledException += OnApplicationUnhandledException;
//AppDomain.CurrentDomain.UnhandledException += OnAppDomainUnhandledException;
}
private void OnApplicationUnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
MessageBox.Show(GetExceptionMessage(e.ExceptionObject), GetExceptionCaption("Application Exception", false), MessageBoxButton.OK);
e.Handled = true;
}
//private void OnAppDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
//{
// MessageBox.Show(GetExceptionMessage(e.ExceptionObject as Exception), GetExceptionCaption("AppDomain Exception", e.IsTerminating), MessageBoxButton.OK);
//}
private string GetExceptionCaption(string title, bool isTerminating)
{
StringBuilder caption = new StringBuilder();
if (!string.IsNullOrEmpty(Name))
{
caption.Append(Name);
caption.Append(" ");
}
caption.Append(title);
if (isTerminating)
{
caption.Append(" (Terminating)");
}
return caption.ToString();
}
private static string GetExceptionMessage(Exception exception)
{
StringBuilder message = new StringBuilder();
if (exception != null)
{
message.Append(exception.Message.ToString());
message.Append(Environment.NewLine);
message.Append(exception.StackTrace.ToString());
}
return message.ToString();
}
public string Name { get; private set; }
}
}
using System;
using System.Text;
using System.Windows;
namespace Jellyfish.Library
{
public class ApplicationBase : Application
{
public ApplicationBase() :
this(null)
{
}
public ApplicationBase(string name)
{
Name = name;
UnhandledException += OnApplicationUnhandledException;
//AppDomain.CurrentDomain.UnhandledException += OnAppDomainUnhandledException;
}
private void OnApplicationUnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
MessageBox.Show(GetExceptionMessage(e.ExceptionObject), GetExceptionCaption("Application Exception", false), MessageBoxButton.OK);
e.Handled = true;
}
//private void OnAppDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
//{
// MessageBox.Show(GetExceptionMessage(e.ExceptionObject as Exception), GetExceptionCaption("AppDomain Exception", e.IsTerminating), MessageBoxButton.OK);
//}
private string GetExceptionCaption(string title, bool isTerminating)
{
var caption = new StringBuilder();
if (!string.IsNullOrEmpty(Name))
{
caption.Append(Name);
caption.Append(" ");
}
caption.Append(title);
if (isTerminating)
{
caption.Append(" (Terminating)");
}
return caption.ToString();
}
private static string GetExceptionMessage(Exception exception)
{
var message = new StringBuilder();
if (exception != null)
{
message.Append(exception.Message.ToString());
message.Append(Environment.NewLine);
message.Append(exception.StackTrace.ToString());
}
return message.ToString();
}
public string Name { get; private set; }
}
}

View File

@ -1,13 +1,13 @@
<UserControl x:Class="Jellyfish.Library.FrameRateCounter" x:Name="frameRateControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:jl="clr-namespace:Jellyfish.Library;assembly=Jellyfish.Library">
<UserControl.Resources>
<jl:StringFormatConverter x:Key="StringFormatConverter"/>
</UserControl.Resources>
<TextBlock FontFamily="Consolas" FontSize="12" Foreground="White">
<TextBlock.Text>
<Binding Path="FrameRate" ElementName="frameRateControl" Converter="{StaticResource StringFormatConverter}" ConverterParameter="{}{0:D} fps"/>
</TextBlock.Text>
</TextBlock>
</UserControl>
<UserControl x:Class="Jellyfish.Library.FrameRateCounter" x:Name="frameRateControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:jl="clr-namespace:Jellyfish.Library;assembly=Jellyfish.Library">
<UserControl.Resources>
<jl:StringFormatConverter x:Key="StringFormatConverter"/>
</UserControl.Resources>
<TextBlock FontFamily="Consolas" FontSize="12" Foreground="White">
<TextBlock.Text>
<Binding Path="FrameRate" ElementName="frameRateControl" Converter="{StaticResource StringFormatConverter}" ConverterParameter="{}{0:D} fps"/>
</TextBlock.Text>
</TextBlock>
</UserControl>

View File

@ -1,42 +1,42 @@
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace Jellyfish.Library
{
public sealed partial class FrameRateCounter : UserControl
{
public FrameRateCounter()
{
InitializeComponent();
CompositionTarget.Rendering += OnCompositionTargetRendering;
}
private void OnCompositionTargetRendering(object sender, EventArgs e)
{
_frameCount++;
long time = DateTime.UtcNow.Ticks;
if (time - _lastTime >= TimeSpan.TicksPerSecond)
{
_lastTime = time;
FrameRate = _frameCount;
_frameCount = 0;
}
}
public static readonly DependencyProperty FrameRateProperty = DependencyProperty.Register("FrameRate", typeof(int), typeof(FrameRateCounter),
new PropertyMetadata(0));
public int FrameRate
{
get { return (int)GetValue(FrameRateProperty); }
set { SetValue(FrameRateProperty, value); }
}
private int _frameCount;
private long _lastTime;
}
}
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace Jellyfish.Library
{
public sealed partial class FrameRateCounter : UserControl
{
public FrameRateCounter()
{
InitializeComponent();
CompositionTarget.Rendering += OnCompositionTargetRendering;
}
private void OnCompositionTargetRendering(object sender, EventArgs e)
{
_frameCount++;
long time = DateTime.UtcNow.Ticks;
if (time - _lastTime >= TimeSpan.TicksPerSecond)
{
_lastTime = time;
FrameRate = _frameCount;
_frameCount = 0;
}
}
public static readonly DependencyProperty FrameRateProperty = DependencyProperty.Register("FrameRate", typeof(int), typeof(FrameRateCounter),
new PropertyMetadata(0));
public int FrameRate
{
get { return (int)GetValue(FrameRateProperty); }
set { SetValue(FrameRateProperty, value); }
}
private int _frameCount;
private long _lastTime;
}
}

View File

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

View File

@ -1,41 +1,41 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace Jellyfish.Library
{
public sealed class StringFormatConverter : IValueConverter // SL is missing Binding.StringFormat
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (targetType != typeof(string))
{
return DependencyProperty.UnsetValue;
}
if (value == null)
{
return string.Empty;
}
string format = parameter as string;
if (!string.IsNullOrEmpty(format))
{
if (format.IndexOf('{') < 0)
{
format = "{0:" + format + "}";
}
return string.Format(culture, format, value);
}
return value.ToString();
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return DependencyProperty.UnsetValue; // one way only
}
}
}
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace Jellyfish.Library
{
public sealed class StringFormatConverter : IValueConverter // SL is missing Binding.StringFormat
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (targetType != typeof(string))
{
return DependencyProperty.UnsetValue;
}
if (value == null)
{
return string.Empty;
}
string format = parameter as string;
if (!string.IsNullOrEmpty(format))
{
if (format.IndexOf('{') < 0)
{
format = "{0:" + format + "}";
}
return string.Format(culture, format, value);
}
return value.ToString();
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return DependencyProperty.UnsetValue; // one way only
}
}
}

View File

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

View File

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

View File

@ -1,38 +1,38 @@
using System.Globalization;
using System.Text;
namespace Jellyfish.Library
{
public static class StringBuilderExtensions
{
public static StringBuilder AppendHex(this StringBuilder builder, short value) // little endian
{
return builder.AppendFormat(CultureInfo.InvariantCulture, "{0:X2}{1:X2}", value & 0xFF, value >> 8);
}
public static StringBuilder AppendHex(this StringBuilder builder, int value) // little endian
{
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)
{
if (value < 0)
{
builder.Append('-');
}
int index = builder.Length;
do
{
builder.Insert(index, Digits, (value % 10) + 9, 1);
value /= 10;
}
while (value != 0);
return builder;
}
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' };
}
}
using System.Globalization;
using System.Text;
namespace Jellyfish.Library
{
public static class StringBuilderExtensions
{
public static StringBuilder AppendHex(this StringBuilder builder, short value) // little endian
{
return builder.AppendFormat(CultureInfo.InvariantCulture, "{0:X2}{1:X2}", value & 0xFF, value >> 8);
}
public static StringBuilder AppendHex(this StringBuilder builder, int value) // little endian
{
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)
{
if (value < 0)
{
builder.Append('-');
}
int index = builder.Length;
do
{
builder.Insert(index, Digits, (value % 10) + 9, 1);
value /= 10;
}
while (value != 0);
return builder;
}
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

@ -18,7 +18,7 @@ namespace Jellyfish.Library
public string ToHexString() // little endian
{
StringBuilder builder = new StringBuilder();
var builder = new StringBuilder();
builder.AppendHex(_formatTag);
builder.AppendHex(_channels);

View File

@ -1,72 +1,72 @@
using System;
using System.Diagnostics;
using System.Security.Permissions;
using System.Text;
using System.Windows;
using System.Windows.Threading;
namespace Jellyfish.Library
{
public class ApplicationBase : Application
{
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
public ApplicationBase() :
this(null)
{
}
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
public ApplicationBase(string name)
{
Name = name;
DispatcherUnhandledException += OnApplicationDispatcherUnhandledException;
AppDomain.CurrentDomain.UnhandledException += OnAppDomainUnhandledException;
}
private void OnApplicationDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
MessageBox.Show(GetExceptionMessage(e.Exception), GetExceptionCaption("Application Dispatcher Exception", true));
e.Handled = true;
Shutdown();
}
private void OnAppDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
MessageBox.Show(GetExceptionMessage(e.ExceptionObject as Exception), GetExceptionCaption("AppDomain Exception", e.IsTerminating));
}
private string GetExceptionCaption(string title, bool isTerminating)
{
StringBuilder caption = new StringBuilder();
caption.AppendFormat("[{0}] ", Process.GetCurrentProcess().Id);
if (!string.IsNullOrEmpty(Name))
{
caption.Append(Name);
caption.Append(" ");
}
caption.Append(title);
if (isTerminating)
{
caption.Append(" (Terminating)");
}
return caption.ToString();
}
private static string GetExceptionMessage(Exception exception)
{
StringBuilder message = new StringBuilder();
if (exception != null)
{
message.Append(exception.Message.ToString());
message.Append(Environment.NewLine);
message.Append(exception.StackTrace.ToString());
}
return message.ToString();
}
public string Name { get; private set; }
}
}
using System;
using System.Diagnostics;
using System.Security.Permissions;
using System.Text;
using System.Windows;
using System.Windows.Threading;
namespace Jellyfish.Library
{
public class ApplicationBase : Application
{
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
public ApplicationBase() :
this(null)
{
}
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
public ApplicationBase(string name)
{
Name = name;
DispatcherUnhandledException += OnApplicationDispatcherUnhandledException;
AppDomain.CurrentDomain.UnhandledException += OnAppDomainUnhandledException;
}
private void OnApplicationDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
MessageBox.Show(GetExceptionMessage(e.Exception), GetExceptionCaption("Application Dispatcher Exception", true));
e.Handled = true;
Shutdown();
}
private void OnAppDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
MessageBox.Show(GetExceptionMessage(e.ExceptionObject as Exception), GetExceptionCaption("AppDomain Exception", e.IsTerminating));
}
private string GetExceptionCaption(string title, bool isTerminating)
{
var caption = new StringBuilder();
caption.AppendFormat("[{0}] ", Process.GetCurrentProcess().Id);
if (!string.IsNullOrEmpty(Name))
{
caption.Append(Name);
caption.Append(" ");
}
caption.Append(title);
if (isTerminating)
{
caption.Append(" (Terminating)");
}
return caption.ToString();
}
private static string GetExceptionMessage(Exception exception)
{
var message = new StringBuilder();
if (exception != null)
{
message.Append(exception.Message.ToString());
message.Append(Environment.NewLine);
message.Append(exception.StackTrace.ToString());
}
return message.ToString();
}
public string Name { get; private set; }
}
}

View File

@ -1,9 +1,9 @@
<UserControl x:Class="Jellyfish.Library.FrameRateCounter" x:Name="frameRateControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<TextBlock FontFamily="Consolas" FontSize="12" Foreground="White">
<TextBlock.Text>
<Binding Path="FrameRate" ElementName="frameRateControl" StringFormat="{}{0:D} fps"/>
</TextBlock.Text>
</TextBlock>
</UserControl>
<UserControl x:Class="Jellyfish.Library.FrameRateCounter" x:Name="frameRateControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<TextBlock FontFamily="Consolas" FontSize="12" Foreground="White">
<TextBlock.Text>
<Binding Path="FrameRate" ElementName="frameRateControl" StringFormat="{}{0:D} fps"/>
</TextBlock.Text>
</TextBlock>
</UserControl>

View File

@ -1,42 +1,42 @@
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace Jellyfish.Library
{
public sealed partial class FrameRateCounter : UserControl
{
public FrameRateCounter()
{
InitializeComponent();
CompositionTarget.Rendering += OnCompositionTargetRendering;
}
private void OnCompositionTargetRendering(object sender, EventArgs e)
{
_frameCount++;
long time = DateTime.UtcNow.Ticks;
if (time - _lastTime >= TimeSpan.TicksPerSecond)
{
_lastTime = time;
FrameRate = _frameCount;
_frameCount = 0;
}
}
public static readonly DependencyProperty FrameRateProperty = DependencyProperty.Register("FrameRate", typeof(int), typeof(FrameRateCounter),
new PropertyMetadata(0));
public int FrameRate
{
get { return (int)GetValue(FrameRateProperty); }
set { SetValue(FrameRateProperty, value); }
}
private int _frameCount;
private long _lastTime;
}
}
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace Jellyfish.Library
{
public sealed partial class FrameRateCounter : UserControl
{
public FrameRateCounter()
{
InitializeComponent();
CompositionTarget.Rendering += OnCompositionTargetRendering;
}
private void OnCompositionTargetRendering(object sender, EventArgs e)
{
_frameCount++;
long time = DateTime.UtcNow.Ticks;
if (time - _lastTime >= TimeSpan.TicksPerSecond)
{
_lastTime = time;
FrameRate = _frameCount;
_frameCount = 0;
}
}
public static readonly DependencyProperty FrameRateProperty = DependencyProperty.Register("FrameRate", typeof(int), typeof(FrameRateCounter),
new PropertyMetadata(0));
public int FrameRate
{
get { return (int)GetValue(FrameRateProperty); }
set { SetValue(FrameRateProperty, value); }
}
private int _frameCount;
private long _lastTime;
}
}

View File

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

View File

@ -1,40 +1,40 @@
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
namespace Jellyfish.Library
{
public static class XmlSerializerHelpers
{
[SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")]
public static T Deserialize<T>(Stream stream)
{
return Deserialize<T>(stream, null);
}
[SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")]
public static T Deserialize<T>(Stream stream, string defaultNamespace)
{
using (XmlReader reader = XmlReader.Create(stream))
{
XmlSerializer serializer = new XmlSerializer(typeof(T), defaultNamespace);
return (T)serializer.Deserialize(reader);
}
}
public static void Serialize<T>(Stream stream, T instance)
{
Serialize<T>(stream, instance, null);
}
public static void Serialize<T>(Stream stream, T instance, string defaultNamespace)
{
using (XmlWriter writer = XmlWriter.Create(stream))
{
XmlSerializer serializer = new XmlSerializer(typeof(T), defaultNamespace);
serializer.Serialize(writer, instance);
}
}
}
}
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
namespace Jellyfish.Library
{
public static class XmlSerializerHelpers
{
[SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")]
public static T Deserialize<T>(Stream stream)
{
return Deserialize<T>(stream, null);
}
[SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")]
public static T Deserialize<T>(Stream stream, string defaultNamespace)
{
using (var reader = XmlReader.Create(stream))
{
var serializer = new XmlSerializer(typeof(T), defaultNamespace);
return (T)serializer.Deserialize(reader);
}
}
public static void Serialize<T>(Stream stream, T instance)
{
Serialize<T>(stream, instance, null);
}
public static void Serialize<T>(Stream stream, T instance, string defaultNamespace)
{
using (var writer = XmlWriter.Create(stream))
{
var serializer = new XmlSerializer(typeof(T), defaultNamespace);
serializer.Serialize(writer, instance);
}
}
}
}

View File

@ -1,71 +1,71 @@
using System;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Jellyfish.Library
{
public sealed class FrameRateCounter : DrawableGameComponent
{
public FrameRateCounter(GameBase game) :
base(game)
{
FontColor = Color.White;
FontName = "Default";
//game.IsFixedTimeStep = true; // fixed (default)
//game.TargetElapsedTime = TimeSpan.FromSeconds(1 / 60f);
//game.IsFixedTimeStep = false; // flatout
//game.GraphicsDeviceManager.SynchronizeWithVerticalRetrace = false;
}
protected override void LoadContent()
{
_spriteBatch = new SpriteBatch(GraphicsDevice);
_spriteFont = Game.Content.Load<SpriteFont>(FontName);
Rectangle titleSafeArea = Game.GraphicsDevice.DisplayMode.TitleSafeArea;
Position = new Vector2(titleSafeArea.X, titleSafeArea.Y);
}
public override void Draw(GameTime gameTime)
{
_frameCount++;
_frameRateBuilder.Length = 0;
_frameRateBuilder.AppendWithoutGarbage(_frameRate).Append(" fps");
_spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None);
//_spriteBatch.DrawString(_spriteFont, fps, Position - Vector2.UnitX, Color.Black); // rough outline
//_spriteBatch.DrawString(_spriteFont, fps, Position + Vector2.UnitX, Color.Black);
//_spriteBatch.DrawString(_spriteFont, fps, Position - Vector2.UnitY, Color.Black);
//_spriteBatch.DrawString(_spriteFont, fps, Position + Vector2.UnitY, Color.Black);
_spriteBatch.DrawString(_spriteFont, _frameRateBuilder, Position, FontColor);
_spriteBatch.End();
}
public override void Update(GameTime gameTime)
{
_elapsedTime += gameTime.ElapsedGameTime.Ticks;
if (_elapsedTime >= TimeSpan.TicksPerSecond)
{
_elapsedTime -= TimeSpan.TicksPerSecond;
_frameRate = _frameCount;
_frameCount = 0;
}
}
public Color FontColor { get; set; }
public string FontName { get; set; }
public Vector2 Position { get; set; }
private SpriteBatch _spriteBatch;
private SpriteFont _spriteFont;
private long _elapsedTime;
private int _frameCount;
private int _frameRate;
private StringBuilder _frameRateBuilder = new StringBuilder(); // cache builder; avoids garbage
}
}
using System;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Jellyfish.Library
{
public sealed class FrameRateCounter : DrawableGameComponent
{
public FrameRateCounter(GameBase game) :
base(game)
{
FontColor = Color.White;
FontName = "Default";
//game.IsFixedTimeStep = true; // fixed (default)
//game.TargetElapsedTime = TimeSpan.FromSeconds(1 / 60f);
//game.IsFixedTimeStep = false; // flatout
//game.GraphicsDeviceManager.SynchronizeWithVerticalRetrace = false;
}
protected override void LoadContent()
{
_spriteBatch = new SpriteBatch(GraphicsDevice);
_spriteFont = Game.Content.Load<SpriteFont>(FontName);
var titleSafeArea = Game.GraphicsDevice.DisplayMode.TitleSafeArea;
Position = new Vector2(titleSafeArea.X, titleSafeArea.Y);
}
public override void Draw(GameTime gameTime)
{
_frameCount++;
_frameRateBuilder.Length = 0;
_frameRateBuilder.AppendWithoutGarbage(_frameRate).Append(" fps");
_spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None);
//_spriteBatch.DrawString(_spriteFont, fps, Position - Vector2.UnitX, Color.Black); // rough outline
//_spriteBatch.DrawString(_spriteFont, fps, Position + Vector2.UnitX, Color.Black);
//_spriteBatch.DrawString(_spriteFont, fps, Position - Vector2.UnitY, Color.Black);
//_spriteBatch.DrawString(_spriteFont, fps, Position + Vector2.UnitY, Color.Black);
_spriteBatch.DrawString(_spriteFont, _frameRateBuilder, Position, FontColor);
_spriteBatch.End();
}
public override void Update(GameTime gameTime)
{
_elapsedTime += gameTime.ElapsedGameTime.Ticks;
if (_elapsedTime >= TimeSpan.TicksPerSecond)
{
_elapsedTime -= TimeSpan.TicksPerSecond;
_frameRate = _frameCount;
_frameCount = 0;
}
}
public Color FontColor { get; set; }
public string FontName { get; set; }
public Vector2 Position { get; set; }
private SpriteBatch _spriteBatch;
private SpriteFont _spriteFont;
private long _elapsedTime;
private int _frameCount;
private int _frameRate;
private StringBuilder _frameRateBuilder = new StringBuilder(); // cache builder; avoids garbage
}
}

View File

@ -1,45 +1,45 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace Jellyfish.Library
{
public class GameBase : Game
{
public GameBase() :
this(null)
{
}
public GameBase(string name)
{
Name = name;
GraphicsDeviceManager = new GraphicsDeviceManager(this);
GraphicsDeviceService = (IGraphicsDeviceService)Services.GetService(typeof(IGraphicsDeviceService));
Components.Add(new GamerServicesComponent(this));
Content.RootDirectory = "Content";
if (!string.IsNullOrEmpty(Name))
{
Window.Title = Name;
}
}
protected override void Update(GameTime gameTime)
{
GamePadState gamePadState = GamePad.GetState(PlayerIndex.One);
if (gamePadState.Buttons.Back == ButtonState.Pressed)
{
Exit();
}
base.Update(gameTime);
}
public string Name { get; private set; }
public GraphicsDeviceManager GraphicsDeviceManager { get; private set; }
public IGraphicsDeviceService GraphicsDeviceService { get; private set; }
}
}
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace Jellyfish.Library
{
public class GameBase : Game
{
public GameBase() :
this(null)
{
}
public GameBase(string name)
{
Name = name;
GraphicsDeviceManager = new GraphicsDeviceManager(this);
GraphicsDeviceService = (IGraphicsDeviceService)Services.GetService(typeof(IGraphicsDeviceService));
Components.Add(new GamerServicesComponent(this));
Content.RootDirectory = "Content";
if (!string.IsNullOrEmpty(Name))
{
Window.Title = Name;
}
}
protected override void Update(GameTime gameTime)
{
var gamePadState = GamePad.GetState(PlayerIndex.One);
if (gamePadState.Buttons.Back == ButtonState.Pressed)
{
Exit();
}
base.Update(gameTime);
}
public string Name { get; private set; }
public GraphicsDeviceManager GraphicsDeviceManager { get; private set; }
public IGraphicsDeviceService GraphicsDeviceService { get; private set; }
}
}

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -1,83 +1,83 @@
using System;
namespace Jellyfish.Virtu
{
public partial class Cpu
{
private const int OpcodeCount = 256;
private readonly Action[] ExecuteOpcode65N02;
private readonly Action[] ExecuteOpcode65C02;
private const int PC = 0x01;
private const int PZ = 0x02;
private const int PI = 0x04;
private const int PD = 0x08;
private const int PB = 0x10;
private const int PR = 0x20;
private const int PV = 0x40;
private const int PN = 0x80;
private const int DataCount = 256;
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,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, 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]
{
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
};
private static readonly int[] DataPNZ = new int[DataCount]
{
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,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN
};
}
}
using System;
namespace Jellyfish.Virtu
{
public partial class Cpu
{
private const int OpcodeCount = 256;
private readonly Action[] ExecuteOpcode65N02;
private readonly Action[] ExecuteOpcode65C02;
private const int PC = 0x01;
private const int PZ = 0x02;
private const int PI = 0x04;
private const int PD = 0x08;
private const int PB = 0x10;
private const int PR = 0x20;
private const int PV = 0x40;
private const int PN = 0x80;
private const int DataCount = 256;
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,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, 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]
{
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
};
private static readonly int[] DataPNZ = new int[DataCount]
{
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,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN, PN,
PN, PN, PN, PN, PN, PN, PN, PN, 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,25 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<Dictionary>
<Acronyms>
<CasingExceptions>
<Acronym>CXXX</Acronym>
<Acronym>RPC</Acronym>
</CasingExceptions>
</Acronyms>
<Words>
<Recognized>
<Word>Annunciator</Word>
<Word>Dsk</Word>
<Word>Opcode</Word>
<Word>Unpause</Word>
<Word>Virtu</Word>
<Word>Xna</Word>
<Word>x</Word>
<Word>y</Word>
</Recognized>
<Unrecognized>
<Word>DownRight</Word>
<Word>UpRight</Word>
</Unrecognized>
</Words>
<?xml version="1.0" encoding="utf-8"?>
<Dictionary>
<Acronyms>
<CasingExceptions>
<Acronym>CXXX</Acronym>
<Acronym>RPC</Acronym>
</CasingExceptions>
</Acronyms>
<Words>
<Recognized>
<Word>Annunciator</Word>
<Word>Dsk</Word>
<Word>Opcode</Word>
<Word>Unpause</Word>
<Word>Virtu</Word>
<Word>Xna</Word>
<Word>x</Word>
<Word>y</Word>
</Recognized>
<Unrecognized>
<Word>DownRight</Word>
<Word>UpRight</Word>
</Unrecognized>
</Words>
</Dictionary>

View File

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

View File

@ -1,289 +1,289 @@
using System;
namespace Jellyfish.Virtu
{
public sealed class DiskDsk : Disk525
{
public DiskDsk(string name, byte[] data, bool isWriteProtected) :
base(name, data, isWriteProtected)
{
}
public override void ReadTrack(int number, int fraction, byte[] buffer)
{
int track = number / 2;
_trackBuffer = buffer;
_trackOffset = 0;
WriteNibble(0xFF, 48); // gap 0
for (int sector = 0; sector < SectorCount; sector++)
{
WriteNibble(0xD5); // address prologue
WriteNibble(0xAA);
WriteNibble(0x96);
WriteNibble44(Volume);
WriteNibble44(track);
WriteNibble44(sector);
WriteNibble44(Volume ^ track ^ sector);
WriteNibble(0xDE); // address epilogue
WriteNibble(0xAA);
WriteNibble(0xEB);
WriteNibble(0xFF, 8);
WriteNibble(0xD5); // data prologue
WriteNibble(0xAA);
WriteNibble(0xAD);
WriteDataNibbles((track * SectorCount + DosOrderToLogicalSector[sector]) * SectorSize);
WriteNibble(0xDE); // data epilogue
WriteNibble(0xAA);
WriteNibble(0xEB);
WriteNibble(0xFF, 16);
}
}
public override void WriteTrack(int number, int fraction, byte[] buffer)
{
if (IsWriteProtected)
return;
int track = number / 2;
_trackBuffer = buffer;
_trackOffset = 0;
int sectorsDone = 0;
for (int sector = 0; sector < SectorCount; sector++)
{
if (!Read3Nibbles(0xD5, 0xAA, 0x96, 0x304))
break; // no address prologue
/*int readVolume = */ReadNibble44();
int readTrack = ReadNibble44();
if (readTrack != track)
break; // bad track number
int readSector = ReadNibble44();
if (readSector > SectorCount)
break; // bad sector number
if ((sectorsDone & (0x1 << readSector)) != 0)
break; // already done this sector
if (ReadNibble44() != (Volume ^ readTrack ^ readSector))
break; // bad address checksum
if ((ReadNibble() != 0xDE) || (ReadNibble() != 0xAA))
break; // bad address epilogue
if (!Read3Nibbles(0xD5, 0xAA, 0xAD, 0x20))
break; // no data prologue
if (!ReadDataNibbles((track * SectorCount + DosOrderToLogicalSector[sector]) * SectorSize))
break; // bad data checksum
if ((ReadNibble() != 0xDE) || (ReadNibble() != 0xAA))
break; // bad data epilogue
sectorsDone |= 0x1 << sector;
}
if (sectorsDone != 0xFFFF)
throw new InvalidOperationException("disk error"); // TODO: we should alert the user and "dump" a NIB
}
private byte ReadNibble()
{
byte data = _trackBuffer[_trackOffset];
if (_trackOffset++ == TrackSize)
{
_trackOffset = 0;
}
return data;
}
private bool Read3Nibbles(byte data1, byte data2, byte data3, int maxReads)
{
bool result = false;
while (--maxReads > 0)
{
if (ReadNibble() != data1)
continue;
if (ReadNibble() != data2)
continue;
if (ReadNibble() != data3)
continue;
result = true;
break;
}
return result;
}
private int ReadNibble44()
{
return (((ReadNibble() << 1) | 0x1) & ReadNibble());
}
private byte ReadTranslatedNibble()
{
byte data = NibbleToByte[ReadNibble()];
// TODO: check that invalid nibbles aren't used
// (put 0xFFs for invalid nibbles in the table)
//if (data == 0xFF)
//{
//throw an exception
//}
return data;
}
private bool ReadDataNibbles(int sectorOffset)
{
byte a, x, y;
y = SecondaryBufferLength;
a = 0;
do // fill and de-nibblize secondary buffer
{
a = _secondaryBuffer[--y] = (byte)(a ^ ReadTranslatedNibble());
}
while (y > 0);
do // fill and de-nibblize secondary buffer
{
a = _primaryBuffer[y++] = (byte)(a ^ ReadTranslatedNibble());
}
while (y != 0);
int checksum = a ^ ReadTranslatedNibble(); // should be 0
x = y = 0;
do // decode data
{
if (x == 0)
{
x = SecondaryBufferLength;
}
a = (byte)((_primaryBuffer[y] << 2) | SwapBits[_secondaryBuffer[--x] & 0x03]);
_secondaryBuffer[x] >>= 2;
Data[sectorOffset + y] = a;
}
while (++y != 0);
return (checksum == 0);
}
private void WriteNibble(int data)
{
_trackBuffer[_trackOffset++] = (byte)data;
}
private void WriteNibble(int data, int count)
{
while (count-- > 0)
{
WriteNibble(data);
}
}
private void WriteNibble44(int data)
{
WriteNibble((data >> 1) | 0xAA);
WriteNibble(data | 0xAA);
}
private void WriteDataNibbles(int sectorOffset)
{
byte a, x, y;
for (x = 0; x < SecondaryBufferLength; x++)
{
_secondaryBuffer[x] = 0; // zero secondary buffer
}
y = 2;
do // fill buffers
{
x = 0;
do
{
a = Data[sectorOffset + --y];
_secondaryBuffer[x] = (byte)((_secondaryBuffer[x] << 2) | SwapBits[a & 0x03]); // b1,b0 -> secondary buffer
_primaryBuffer[y] = (byte)(a >> 2); // b7-b2 -> primary buffer
}
while (++x < SecondaryBufferLength);
}
while (y != 0);
y = SecondaryBufferLength;
do // write secondary buffer
{
WriteNibble(ByteToNibble[_secondaryBuffer[y] ^ _secondaryBuffer[y - 1]]);
}
while (--y != 0);
a = _secondaryBuffer[0];
do // write primary buffer
{
WriteNibble(ByteToNibble[a ^ _primaryBuffer[y]]);
a = _primaryBuffer[y];
}
while (++y != 0);
WriteNibble(ByteToNibble[a]); // data checksum
}
private byte[] _trackBuffer;
private int _trackOffset;
private byte[] _primaryBuffer = new byte[0x100];
private const int SecondaryBufferLength = 0x56;
private byte[] _secondaryBuffer = new byte[SecondaryBufferLength + 1];
private const int Volume = 0xFE;
private static readonly byte[] SwapBits = { 0, 2, 1, 3 };
private static readonly int[] DosOrderToLogicalSector = new int[]
{
0x0, 0x7, 0xE, 0x6, 0xD, 0x5, 0xC, 0x4, 0xB, 0x3, 0xA, 0x2, 0x9, 0x1, 0x8, 0xF
};
private static readonly byte[] ByteToNibble = new byte[]
{
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,
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
};
private static readonly byte[] NibbleToByte = new byte[]
{
// padding for offset (not used)
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,
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,
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,
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,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95,
// nibble translate table
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,
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,
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,
0xF0, 0xF1, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0xF8, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F
};
}
}
using System;
namespace Jellyfish.Virtu
{
public sealed class DiskDsk : Disk525
{
public DiskDsk(string name, byte[] data, bool isWriteProtected) :
base(name, data, isWriteProtected)
{
}
public override void ReadTrack(int number, int fraction, byte[] buffer)
{
int track = number / 2;
_trackBuffer = buffer;
_trackOffset = 0;
WriteNibble(0xFF, 48); // gap 0
for (int sector = 0; sector < SectorCount; sector++)
{
WriteNibble(0xD5); // address prologue
WriteNibble(0xAA);
WriteNibble(0x96);
WriteNibble44(Volume);
WriteNibble44(track);
WriteNibble44(sector);
WriteNibble44(Volume ^ track ^ sector);
WriteNibble(0xDE); // address epilogue
WriteNibble(0xAA);
WriteNibble(0xEB);
WriteNibble(0xFF, 8);
WriteNibble(0xD5); // data prologue
WriteNibble(0xAA);
WriteNibble(0xAD);
WriteDataNibbles((track * SectorCount + DosOrderToLogicalSector[sector]) * SectorSize);
WriteNibble(0xDE); // data epilogue
WriteNibble(0xAA);
WriteNibble(0xEB);
WriteNibble(0xFF, 16);
}
}
public override void WriteTrack(int number, int fraction, byte[] buffer)
{
if (IsWriteProtected)
return;
int track = number / 2;
_trackBuffer = buffer;
_trackOffset = 0;
int sectorsDone = 0;
for (int sector = 0; sector < SectorCount; sector++)
{
if (!Read3Nibbles(0xD5, 0xAA, 0x96, 0x304))
break; // no address prologue
/*int readVolume = */ReadNibble44();
int readTrack = ReadNibble44();
if (readTrack != track)
break; // bad track number
int readSector = ReadNibble44();
if (readSector > SectorCount)
break; // bad sector number
if ((sectorsDone & (0x1 << readSector)) != 0)
break; // already done this sector
if (ReadNibble44() != (Volume ^ readTrack ^ readSector))
break; // bad address checksum
if ((ReadNibble() != 0xDE) || (ReadNibble() != 0xAA))
break; // bad address epilogue
if (!Read3Nibbles(0xD5, 0xAA, 0xAD, 0x20))
break; // no data prologue
if (!ReadDataNibbles((track * SectorCount + DosOrderToLogicalSector[sector]) * SectorSize))
break; // bad data checksum
if ((ReadNibble() != 0xDE) || (ReadNibble() != 0xAA))
break; // bad data epilogue
sectorsDone |= 0x1 << sector;
}
if (sectorsDone != 0xFFFF)
throw new InvalidOperationException("disk error"); // TODO: we should alert the user and "dump" a NIB
}
private byte ReadNibble()
{
byte data = _trackBuffer[_trackOffset];
if (_trackOffset++ == TrackSize)
{
_trackOffset = 0;
}
return data;
}
private bool Read3Nibbles(byte data1, byte data2, byte data3, int maxReads)
{
bool result = false;
while (--maxReads > 0)
{
if (ReadNibble() != data1)
continue;
if (ReadNibble() != data2)
continue;
if (ReadNibble() != data3)
continue;
result = true;
break;
}
return result;
}
private int ReadNibble44()
{
return (((ReadNibble() << 1) | 0x1) & ReadNibble());
}
private byte ReadTranslatedNibble()
{
byte data = NibbleToByte[ReadNibble()];
// TODO: check that invalid nibbles aren't used
// (put 0xFFs for invalid nibbles in the table)
//if (data == 0xFF)
//{
//throw an exception
//}
return data;
}
private bool ReadDataNibbles(int sectorOffset)
{
byte a, x, y;
y = SecondaryBufferLength;
a = 0;
do // fill and de-nibblize secondary buffer
{
a = _secondaryBuffer[--y] = (byte)(a ^ ReadTranslatedNibble());
}
while (y > 0);
do // fill and de-nibblize secondary buffer
{
a = _primaryBuffer[y++] = (byte)(a ^ ReadTranslatedNibble());
}
while (y != 0);
int checksum = a ^ ReadTranslatedNibble(); // should be 0
x = y = 0;
do // decode data
{
if (x == 0)
{
x = SecondaryBufferLength;
}
a = (byte)((_primaryBuffer[y] << 2) | SwapBits[_secondaryBuffer[--x] & 0x03]);
_secondaryBuffer[x] >>= 2;
Data[sectorOffset + y] = a;
}
while (++y != 0);
return (checksum == 0);
}
private void WriteNibble(int data)
{
_trackBuffer[_trackOffset++] = (byte)data;
}
private void WriteNibble(int data, int count)
{
while (count-- > 0)
{
WriteNibble(data);
}
}
private void WriteNibble44(int data)
{
WriteNibble((data >> 1) | 0xAA);
WriteNibble(data | 0xAA);
}
private void WriteDataNibbles(int sectorOffset)
{
byte a, x, y;
for (x = 0; x < SecondaryBufferLength; x++)
{
_secondaryBuffer[x] = 0; // zero secondary buffer
}
y = 2;
do // fill buffers
{
x = 0;
do
{
a = Data[sectorOffset + --y];
_secondaryBuffer[x] = (byte)((_secondaryBuffer[x] << 2) | SwapBits[a & 0x03]); // b1,b0 -> secondary buffer
_primaryBuffer[y] = (byte)(a >> 2); // b7-b2 -> primary buffer
}
while (++x < SecondaryBufferLength);
}
while (y != 0);
y = SecondaryBufferLength;
do // write secondary buffer
{
WriteNibble(ByteToNibble[_secondaryBuffer[y] ^ _secondaryBuffer[y - 1]]);
}
while (--y != 0);
a = _secondaryBuffer[0];
do // write primary buffer
{
WriteNibble(ByteToNibble[a ^ _primaryBuffer[y]]);
a = _primaryBuffer[y];
}
while (++y != 0);
WriteNibble(ByteToNibble[a]); // data checksum
}
private byte[] _trackBuffer;
private int _trackOffset;
private byte[] _primaryBuffer = new byte[0x100];
private const int SecondaryBufferLength = 0x56;
private byte[] _secondaryBuffer = new byte[SecondaryBufferLength + 1];
private const int Volume = 0xFE;
private static readonly byte[] SwapBits = { 0, 2, 1, 3 };
private static readonly int[] DosOrderToLogicalSector = new int[]
{
0x0, 0x7, 0xE, 0x6, 0xD, 0x5, 0xC, 0x4, 0xB, 0x3, 0xA, 0x2, 0x9, 0x1, 0x8, 0xF
};
private static readonly byte[] ByteToNibble = new byte[]
{
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,
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
};
private static readonly byte[] NibbleToByte = new byte[]
{
// padding for offset (not used)
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,
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,
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,
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,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95,
// nibble translate table
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,
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,
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,
0xF0, 0xF1, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0xF8, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F
};
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,128 +1,128 @@
using System;
using System.Collections.ObjectModel;
using System.Threading;
using Jellyfish.Library;
using Jellyfish.Virtu.Services;
using Jellyfish.Virtu.Settings;
namespace Jellyfish.Virtu
{
public enum MachineState { Stopped = 0, Starting, Running, Pausing, Paused, Stopping }
public sealed class Machine : IDisposable
{
public Machine()
{
Events = new MachineEvents();
Services = new MachineServices();
Settings = new MachineSettings();
Cpu = new Cpu(this);
Memory = new Memory(this);
DiskII = new DiskII(this);
Keyboard = new Keyboard(this);
GamePort = new GamePort(this);
Cassette = new Cassette(this);
Speaker = new Speaker(this);
Video = new Video(this);
Components = new Collection<MachineComponent> { Cpu, Memory, DiskII, Keyboard, GamePort, Cassette, Speaker, Video };
Thread = new Thread(Run) { Name = "Machine" };
}
public void Dispose()
{
_pauseEvent.Close();
_unpauseEvent.Close();
}
public void Reset()
{
Components.ForEach(component => component.Reset()); // while machine starting or paused
}
public void Start()
{
_storageService = Services.GetService<StorageService>();
_storageService.Load(MachineSettings.FileName, stream => Settings.Deserialize(stream));
State = MachineState.Starting;
Services.ForEach(service => service.Start());
Thread.Start();
}
public void Pause()
{
State = MachineState.Pausing;
_pauseEvent.WaitOne();
State = MachineState.Paused;
}
public void Unpause()
{
State = MachineState.Running;
_unpauseEvent.Set();
}
public void Stop()
{
State = MachineState.Stopping;
Services.ForEach(service => service.Stop());
_pauseEvent.Set();
_unpauseEvent.Set();
Thread.Join();
State = MachineState.Stopped;
_storageService.Save(MachineSettings.FileName, stream => Settings.Serialize(stream));
}
private void Run() // machine thread
{
Components.ForEach(component => component.Initialize());
Reset();
State = MachineState.Running;
do
{
do
{
Events.HandleEvents(Cpu.Execute());
}
while (State == MachineState.Running);
if (State == MachineState.Pausing)
{
_pauseEvent.Set();
_unpauseEvent.WaitOne();
}
}
while (State != MachineState.Stopping);
Components.ForEach(component => component.Uninitialize());
}
public MachineEvents Events { get; private set; }
public MachineServices Services { get; private set; }
public MachineSettings Settings { get; private set; }
public MachineState State { get; private set; }
public Cpu Cpu { get; private set; }
public Memory Memory { get; private set; }
public DiskII DiskII { get; private set; }
public Keyboard Keyboard { get; private set; }
public GamePort GamePort { get; private set; }
public Cassette Cassette { get; private set; }
public Speaker Speaker { get; private set; }
public Video Video { get; private set; }
public Collection<MachineComponent> Components { get; private set; }
public Thread Thread { get; private set; }
private AutoResetEvent _pauseEvent = new AutoResetEvent(false);
private AutoResetEvent _unpauseEvent = new AutoResetEvent(false);
private StorageService _storageService;
}
}
using System;
using System.Collections.ObjectModel;
using System.Threading;
using Jellyfish.Library;
using Jellyfish.Virtu.Services;
using Jellyfish.Virtu.Settings;
namespace Jellyfish.Virtu
{
public enum MachineState { Stopped = 0, Starting, Running, Pausing, Paused, Stopping }
public sealed class Machine : IDisposable
{
public Machine()
{
Events = new MachineEvents();
Services = new MachineServices();
Settings = new MachineSettings();
Cpu = new Cpu(this);
Memory = new Memory(this);
DiskII = new DiskII(this);
Keyboard = new Keyboard(this);
GamePort = new GamePort(this);
Cassette = new Cassette(this);
Speaker = new Speaker(this);
Video = new Video(this);
Components = new Collection<MachineComponent> { Cpu, Memory, DiskII, Keyboard, GamePort, Cassette, Speaker, Video };
Thread = new Thread(Run) { Name = "Machine" };
}
public void Dispose()
{
_pauseEvent.Close();
_unpauseEvent.Close();
}
public void Reset()
{
Components.ForEach(component => component.Reset()); // while machine starting or paused
}
public void Start()
{
_storageService = Services.GetService<StorageService>();
_storageService.Load(MachineSettings.FileName, stream => Settings.Deserialize(stream));
State = MachineState.Starting;
Services.ForEach(service => service.Start());
Thread.Start();
}
public void Pause()
{
State = MachineState.Pausing;
_pauseEvent.WaitOne();
State = MachineState.Paused;
}
public void Unpause()
{
State = MachineState.Running;
_unpauseEvent.Set();
}
public void Stop()
{
State = MachineState.Stopping;
Services.ForEach(service => service.Stop());
_pauseEvent.Set();
_unpauseEvent.Set();
Thread.Join();
State = MachineState.Stopped;
_storageService.Save(MachineSettings.FileName, stream => Settings.Serialize(stream));
}
private void Run() // machine thread
{
Components.ForEach(component => component.Initialize());
Reset();
State = MachineState.Running;
do
{
do
{
Events.HandleEvents(Cpu.Execute());
}
while (State == MachineState.Running);
if (State == MachineState.Pausing)
{
_pauseEvent.Set();
_unpauseEvent.WaitOne();
}
}
while (State != MachineState.Stopping);
Components.ForEach(component => component.Uninitialize());
}
public MachineEvents Events { get; private set; }
public MachineServices Services { get; private set; }
public MachineSettings Settings { get; private set; }
public MachineState State { get; private set; }
public Cpu Cpu { get; private set; }
public Memory Memory { get; private set; }
public DiskII DiskII { get; private set; }
public Keyboard Keyboard { get; private set; }
public GamePort GamePort { get; private set; }
public Cassette Cassette { get; private set; }
public Speaker Speaker { get; private set; }
public Video Video { get; private set; }
public Collection<MachineComponent> Components { get; private set; }
public Thread Thread { get; private set; }
private AutoResetEvent _pauseEvent = new AutoResetEvent(false);
private AutoResetEvent _unpauseEvent = new AutoResetEvent(false);
private StorageService _storageService;
}
}

View File

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

View File

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

View File

@ -1,393 +1,393 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Xml;
using System.Xml.Linq;
namespace Jellyfish.Virtu.Settings
{
public sealed class MachineSettings
{
public MachineSettings()
{
Cpu = new CpuSettings { Is65C02 = true, IsThrottled = true, Multiplier = 1 };
DiskII = new DiskIISettings
{
Disk1 = new DiskSettings { Name = string.Empty, IsWriteProtected = false },
Disk2 = new DiskSettings { Name = string.Empty, IsWriteProtected = false }
};
Keyboard = new KeyboardSettings
{
UseGamePort = false,
Key = new KeySettings
{
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 },
Button0 = 0, Button1 = 0, Button2 = 0
}
};
GamePort = new GamePortSettings
{
UseKeyboard = false,
Key = new KeySettings
{
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 },
Button0 = 0, Button1 = 0, Button2 = 0
}
};
Video = new VideoSettings
{
IsFullScreen = false, IsMonochrome = false, ScannerOptions = ScannerOptions.None,
Color = new ColorSettings
{
Black = 0x000000,
DarkBlue = 0x000099,
DarkGreen = 0x117722,
MediumBlue = 0x0000FF,
Brown = 0x885500,
LightGrey = 0x99AAAA,
Green = 0x00EE11,
Aquamarine = 0x55FFAA,
DeepRed = 0xFF1111,
Purple = 0xDD00DD,
DarkGrey = 0x445555,
LightBlue = 0x33AAFF,
Orange = 0xFF4411,
Pink = 0xFF9988,
Yellow = 0xFFFF11,
White = 0xFFFFFF,
Monochrome = 0x00AA00
}
};
}
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
public void Deserialize(Stream stream)
{
try
{
using (XmlReader reader = XmlReader.Create(stream))
{
XNamespace ns = Namespace;
XElement root = XElement.Load(reader);
XElement cpu = root.Element(ns + "Cpu");
Cpu = new CpuSettings
{
Is65C02 = (bool)cpu.Attribute("Is65C02"),
IsThrottled = (bool)cpu.Attribute("IsThrottled"),
Multiplier = (int)cpu.Attribute("Multiplier")
};
XElement diskII = root.Element(ns + "DiskII");
XElement disk1 = diskII.Element(ns + "Disk1");
XElement disk2 = diskII.Element(ns + "Disk2");
DiskII = new DiskIISettings
{
Disk1 = new DiskSettings
{
Name = (string)disk1.Attribute("Name") ?? string.Empty,
IsWriteProtected = (bool)disk1.Attribute("IsWriteProtected")
},
Disk2 = new DiskSettings
{
Name = (string)disk2.Attribute("Name") ?? string.Empty,
IsWriteProtected = (bool)disk2.Attribute("IsWriteProtected")
},
};
XElement keyboard = root.Element(ns + "Keyboard");
XElement key = keyboard.Element(ns + "Key");
XElement joystick0 = key.Element(ns + "Joystick0");
XElement joystick1 = key.Element(ns + "Joystick1");
XElement buttons = key.Element(ns + "Buttons");
Keyboard = new KeyboardSettings
{
UseGamePort = (bool)keyboard.Attribute("UseGamePort"),
Key = new KeySettings
{
Joystick0 = new JoystickSettings
{
UpLeft = (int)joystick0.Attribute("UpLeft"),
Up = (int)joystick0.Attribute("Up"),
UpRight = (int)joystick0.Attribute("UpRight"),
Left = (int)joystick0.Attribute("Left"),
Right = (int)joystick0.Attribute("Right"),
DownLeft = (int)joystick0.Attribute("DownLeft"),
Down = (int)joystick0.Attribute("Down"),
DownRight = (int)joystick0.Attribute("DownRight")
},
Joystick1 = new JoystickSettings
{
UpLeft = (int)joystick1.Attribute("UpLeft"),
Up = (int)joystick1.Attribute("Up"),
UpRight = (int)joystick1.Attribute("UpRight"),
Left = (int)joystick1.Attribute("Left"),
Right = (int)joystick1.Attribute("Right"),
DownLeft = (int)joystick1.Attribute("DownLeft"),
Down = (int)joystick1.Attribute("Down"),
DownRight = (int)joystick1.Attribute("DownRight")
},
Button0 = (int)buttons.Attribute("Button0"),
Button1 = (int)buttons.Attribute("Button1"),
Button2 = (int)buttons.Attribute("Button2")
}
};
XElement gamePort = root.Element(ns + "GamePort");
key = gamePort.Element(ns + "Key");
joystick0 = key.Element(ns + "Joystick0");
joystick1 = key.Element(ns + "Joystick1");
buttons = key.Element(ns + "Buttons");
GamePort = new GamePortSettings
{
UseKeyboard = (bool)gamePort.Attribute("UseKeyboard"),
Key = new KeySettings
{
Joystick0 = new JoystickSettings
{
UpLeft = (int)joystick0.Attribute("UpLeft"),
Up = (int)joystick0.Attribute("Up"),
UpRight = (int)joystick0.Attribute("UpRight"),
Left = (int)joystick0.Attribute("Left"),
Right = (int)joystick0.Attribute("Right"),
DownLeft = (int)joystick0.Attribute("DownLeft"),
Down = (int)joystick0.Attribute("Down"),
DownRight = (int)joystick0.Attribute("DownRight")
},
Joystick1 = new JoystickSettings
{
UpLeft = (int)joystick1.Attribute("UpLeft"),
Up = (int)joystick1.Attribute("Up"),
UpRight = (int)joystick1.Attribute("UpRight"),
Left = (int)joystick1.Attribute("Left"),
Right = (int)joystick1.Attribute("Right"),
DownLeft = (int)joystick1.Attribute("DownLeft"),
Down = (int)joystick1.Attribute("Down"),
DownRight = (int)joystick1.Attribute("DownRight")
},
Button0 = (int)buttons.Attribute("Button0"),
Button1 = (int)buttons.Attribute("Button1"),
Button2 = (int)buttons.Attribute("Button2")
}
};
XElement video = root.Element(ns + "Video");
XElement color = video.Element(ns + "Color");
Video = new VideoSettings
{
IsFullScreen = (bool)video.Attribute("IsFullScreen"),
IsMonochrome = (bool)video.Attribute("IsMonochrome"),
ScannerOptions = (ScannerOptions)Enum.Parse(typeof(ScannerOptions), (string)video.Attribute("ScannerOptions"), true),
Color = new ColorSettings
{
Black = (uint)color.Attribute("Black"),
DarkBlue = (uint)color.Attribute("DarkBlue"),
DarkGreen = (uint)color.Attribute("DarkGreen"),
MediumBlue = (uint)color.Attribute("MediumBlue"),
Brown = (uint)color.Attribute("Brown"),
LightGrey = (uint)color.Attribute("LightGrey"),
Green = (uint)color.Attribute("Green"),
Aquamarine = (uint)color.Attribute("Aquamarine"),
DeepRed = (uint)color.Attribute("DeepRed"),
Purple = (uint)color.Attribute("Purple"),
DarkGrey = (uint)color.Attribute("DarkGrey"),
LightBlue = (uint)color.Attribute("LightBlue"),
Orange = (uint)color.Attribute("Orange"),
Pink = (uint)color.Attribute("Pink"),
Yellow = (uint)color.Attribute("Yellow"),
White = (uint)color.Attribute("White"),
Monochrome = (uint)color.Attribute("Monochrome")
}
};
}
}
catch (Exception)
{
}
}
public void Serialize(Stream stream)
{
XNamespace ns = Namespace;
XElement xml = new XElement(ns + "MachineSettings",
new XElement(ns + "Cpu",
new XAttribute("Is65C02", Cpu.Is65C02),
new XAttribute("IsThrottled", Cpu.IsThrottled),
new XAttribute("Multiplier", Cpu.Multiplier)),
new XElement(ns + "DiskII",
new XElement(ns + "Disk1",
new XAttribute("Name", DiskII.Disk1.Name),
new XAttribute("IsWriteProtected", DiskII.Disk1.IsWriteProtected)),
new XElement(ns + "Disk2",
new XAttribute("Name", DiskII.Disk2.Name),
new XAttribute("IsWriteProtected", DiskII.Disk2.IsWriteProtected))),
new XElement(ns + "Keyboard",
new XAttribute("UseGamePort", Keyboard.UseGamePort),
new XElement(ns + "Key",
new XElement(ns + "Joystick0",
new XAttribute("UpLeft", Keyboard.Key.Joystick0.UpLeft),
new XAttribute("Up", Keyboard.Key.Joystick0.Up),
new XAttribute("UpRight", Keyboard.Key.Joystick0.UpRight),
new XAttribute("Left", Keyboard.Key.Joystick0.Left),
new XAttribute("Right", Keyboard.Key.Joystick0.Right),
new XAttribute("DownLeft", Keyboard.Key.Joystick0.DownLeft),
new XAttribute("Down", Keyboard.Key.Joystick0.Down),
new XAttribute("DownRight", Keyboard.Key.Joystick0.DownRight)),
new XElement(ns + "Joystick1",
new XAttribute("UpLeft", Keyboard.Key.Joystick1.UpLeft),
new XAttribute("Up", Keyboard.Key.Joystick1.Up),
new XAttribute("UpRight", Keyboard.Key.Joystick1.UpRight),
new XAttribute("Left", Keyboard.Key.Joystick1.Left),
new XAttribute("Right", Keyboard.Key.Joystick1.Right),
new XAttribute("DownLeft", Keyboard.Key.Joystick1.DownLeft),
new XAttribute("Down", Keyboard.Key.Joystick1.Down),
new XAttribute("DownRight", Keyboard.Key.Joystick1.DownRight)),
new XElement(ns + "Buttons",
new XAttribute("Button0", Keyboard.Key.Button0),
new XAttribute("Button1", Keyboard.Key.Button1),
new XAttribute("Button2", Keyboard.Key.Button2)))),
new XElement(ns + "GamePort",
new XAttribute("UseKeyboard", GamePort.UseKeyboard),
new XElement(ns + "Key",
new XElement(ns + "Joystick0",
new XAttribute("UpLeft", GamePort.Key.Joystick0.UpLeft),
new XAttribute("Up", GamePort.Key.Joystick0.Up),
new XAttribute("UpRight", GamePort.Key.Joystick0.UpRight),
new XAttribute("Left", GamePort.Key.Joystick0.Left),
new XAttribute("Right", GamePort.Key.Joystick0.Right),
new XAttribute("DownLeft", GamePort.Key.Joystick0.DownLeft),
new XAttribute("Down", GamePort.Key.Joystick0.Down),
new XAttribute("DownRight", GamePort.Key.Joystick0.DownRight)),
new XElement(ns + "Joystick1",
new XAttribute("UpLeft", GamePort.Key.Joystick1.UpLeft),
new XAttribute("Up", GamePort.Key.Joystick1.Up),
new XAttribute("UpRight", GamePort.Key.Joystick1.UpRight),
new XAttribute("Left", GamePort.Key.Joystick1.Left),
new XAttribute("Right", GamePort.Key.Joystick1.Right),
new XAttribute("DownLeft", GamePort.Key.Joystick1.DownLeft),
new XAttribute("Down", GamePort.Key.Joystick1.Down),
new XAttribute("DownRight", GamePort.Key.Joystick1.DownRight)),
new XElement(ns + "Buttons",
new XAttribute("Button0", Keyboard.Key.Button0),
new XAttribute("Button1", Keyboard.Key.Button1),
new XAttribute("Button2", Keyboard.Key.Button2)))),
new XElement(ns + "Video",
new XAttribute("IsFullScreen", Video.IsFullScreen),
new XAttribute("IsMonochrome", Video.IsMonochrome),
new XAttribute("ScannerOptions", Video.ScannerOptions),
new XElement(ns + "Color",
new XAttribute("Black", Video.Color.Black),
new XAttribute("DarkBlue", Video.Color.DarkBlue),
new XAttribute("DarkGreen", Video.Color.DarkGreen),
new XAttribute("MediumBlue", Video.Color.MediumBlue),
new XAttribute("Brown", Video.Color.Brown),
new XAttribute("LightGrey", Video.Color.LightGrey),
new XAttribute("Green", Video.Color.Green),
new XAttribute("Aquamarine", Video.Color.Aquamarine),
new XAttribute("DeepRed", Video.Color.DeepRed),
new XAttribute("Purple", Video.Color.Purple),
new XAttribute("DarkGrey", Video.Color.DarkGrey),
new XAttribute("LightBlue", Video.Color.LightBlue),
new XAttribute("Orange", Video.Color.Orange),
new XAttribute("Pink", Video.Color.Pink),
new XAttribute("Yellow", Video.Color.Yellow),
new XAttribute("White", Video.Color.White),
new XAttribute("Monochrome", Video.Color.Monochrome))));
using (XmlWriter writer = XmlWriter.Create(stream))
{
xml.WriteTo(writer);
}
}
public CpuSettings Cpu { get; set; }
public DiskIISettings DiskII { get; set; }
public KeyboardSettings Keyboard { get; set; }
public GamePortSettings GamePort { get; set; }
public VideoSettings Video { get; set; }
public const string FileName = "Settings.xml";
public const string Namespace = "http://schemas.jellyfish.co.nz/virtu/settings";
}
public sealed class CpuSettings
{
public bool Is65C02 { get; set; }
public bool IsThrottled { get; set; }
public int Multiplier { get; set; }
}
public sealed class DiskSettings
{
public string Name { get; set; }
public bool IsWriteProtected { get; set; }
};
public sealed class DiskIISettings
{
public DiskSettings Disk1 { get; set; }
public DiskSettings Disk2 { get; set; }
};
public sealed class JoystickSettings
{
public int UpLeft { get; set; }
public int Up { get; set; }
public int UpRight { get; set; }
public int Left { get; set; }
public int Right { get; set; }
public int DownLeft { get; set; }
public int Down { get; set; }
public int DownRight { get; set; }
};
public sealed class KeySettings
{
public JoystickSettings Joystick0 { get; set; }
public JoystickSettings Joystick1 { get; set; }
public int Button0 { get; set; }
public int Button1 { get; set; }
public int Button2 { get; set; }
};
public sealed class KeyboardSettings
{
public bool UseGamePort { get; set; }
public KeySettings Key { get; set; }
}
public sealed class GamePortSettings
{
public bool UseKeyboard { get; set; }
public KeySettings Key { get; set; }
}
public sealed class ColorSettings
{
public uint Black { get; set; }
public uint DarkBlue { get; set; }
public uint DarkGreen { get; set; }
public uint MediumBlue { get; set; }
public uint Brown { get; set; }
public uint LightGrey { get; set; }
public uint Green { get; set; }
public uint Aquamarine { get; set; }
public uint DeepRed { get; set; }
public uint Purple { get; set; }
public uint DarkGrey { get; set; }
public uint LightBlue { get; set; }
public uint Orange { get; set; }
public uint Pink { get; set; }
public uint Yellow { get; set; }
public uint White { get; set; }
public uint Monochrome { get; set; }
}
[Flags]
public enum ScannerOptions { None = 0x0, AppleII = 0x1, Pal = 0x2 } // defaults to AppleIIe, Ntsc
public sealed class VideoSettings
{
public bool IsFullScreen { get; set; }
public bool IsMonochrome { get; set; }
public ScannerOptions ScannerOptions { get; set; }
public ColorSettings Color { get; set; }
};
}
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Xml;
using System.Xml.Linq;
namespace Jellyfish.Virtu.Settings
{
public sealed class MachineSettings
{
public MachineSettings()
{
Cpu = new CpuSettings { Is65C02 = true, IsThrottled = true, Multiplier = 1 };
DiskII = new DiskIISettings
{
Disk1 = new DiskSettings { Name = string.Empty, IsWriteProtected = false },
Disk2 = new DiskSettings { Name = string.Empty, IsWriteProtected = false }
};
Keyboard = new KeyboardSettings
{
UseGamePort = false,
Key = new KeySettings
{
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 },
Button0 = 0, Button1 = 0, Button2 = 0
}
};
GamePort = new GamePortSettings
{
UseKeyboard = false,
Key = new KeySettings
{
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 },
Button0 = 0, Button1 = 0, Button2 = 0
}
};
Video = new VideoSettings
{
IsFullScreen = false, IsMonochrome = false, ScannerOptions = ScannerOptions.None,
Color = new ColorSettings
{
Black = 0x000000,
DarkBlue = 0x000099,
DarkGreen = 0x117722,
MediumBlue = 0x0000FF,
Brown = 0x885500,
LightGrey = 0x99AAAA,
Green = 0x00EE11,
Aquamarine = 0x55FFAA,
DeepRed = 0xFF1111,
Purple = 0xDD00DD,
DarkGrey = 0x445555,
LightBlue = 0x33AAFF,
Orange = 0xFF4411,
Pink = 0xFF9988,
Yellow = 0xFFFF11,
White = 0xFFFFFF,
Monochrome = 0x00AA00
}
};
}
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
public void Deserialize(Stream stream)
{
try
{
using (var reader = XmlReader.Create(stream))
{
var ns = Namespace;
var root = XElement.Load(reader);
var cpu = root.Element(ns + "Cpu");
Cpu = new CpuSettings
{
Is65C02 = (bool)cpu.Attribute("Is65C02"),
IsThrottled = (bool)cpu.Attribute("IsThrottled"),
Multiplier = (int)cpu.Attribute("Multiplier")
};
var diskII = root.Element(ns + "DiskII");
var disk1 = diskII.Element(ns + "Disk1");
var disk2 = diskII.Element(ns + "Disk2");
DiskII = new DiskIISettings
{
Disk1 = new DiskSettings
{
Name = (string)disk1.Attribute("Name") ?? string.Empty,
IsWriteProtected = (bool)disk1.Attribute("IsWriteProtected")
},
Disk2 = new DiskSettings
{
Name = (string)disk2.Attribute("Name") ?? string.Empty,
IsWriteProtected = (bool)disk2.Attribute("IsWriteProtected")
},
};
var keyboard = root.Element(ns + "Keyboard");
var key = keyboard.Element(ns + "Key");
var joystick0 = key.Element(ns + "Joystick0");
var joystick1 = key.Element(ns + "Joystick1");
var buttons = key.Element(ns + "Buttons");
Keyboard = new KeyboardSettings
{
UseGamePort = (bool)keyboard.Attribute("UseGamePort"),
Key = new KeySettings
{
Joystick0 = new JoystickSettings
{
UpLeft = (int)joystick0.Attribute("UpLeft"),
Up = (int)joystick0.Attribute("Up"),
UpRight = (int)joystick0.Attribute("UpRight"),
Left = (int)joystick0.Attribute("Left"),
Right = (int)joystick0.Attribute("Right"),
DownLeft = (int)joystick0.Attribute("DownLeft"),
Down = (int)joystick0.Attribute("Down"),
DownRight = (int)joystick0.Attribute("DownRight")
},
Joystick1 = new JoystickSettings
{
UpLeft = (int)joystick1.Attribute("UpLeft"),
Up = (int)joystick1.Attribute("Up"),
UpRight = (int)joystick1.Attribute("UpRight"),
Left = (int)joystick1.Attribute("Left"),
Right = (int)joystick1.Attribute("Right"),
DownLeft = (int)joystick1.Attribute("DownLeft"),
Down = (int)joystick1.Attribute("Down"),
DownRight = (int)joystick1.Attribute("DownRight")
},
Button0 = (int)buttons.Attribute("Button0"),
Button1 = (int)buttons.Attribute("Button1"),
Button2 = (int)buttons.Attribute("Button2")
}
};
var gamePort = root.Element(ns + "GamePort");
key = gamePort.Element(ns + "Key");
joystick0 = key.Element(ns + "Joystick0");
joystick1 = key.Element(ns + "Joystick1");
buttons = key.Element(ns + "Buttons");
GamePort = new GamePortSettings
{
UseKeyboard = (bool)gamePort.Attribute("UseKeyboard"),
Key = new KeySettings
{
Joystick0 = new JoystickSettings
{
UpLeft = (int)joystick0.Attribute("UpLeft"),
Up = (int)joystick0.Attribute("Up"),
UpRight = (int)joystick0.Attribute("UpRight"),
Left = (int)joystick0.Attribute("Left"),
Right = (int)joystick0.Attribute("Right"),
DownLeft = (int)joystick0.Attribute("DownLeft"),
Down = (int)joystick0.Attribute("Down"),
DownRight = (int)joystick0.Attribute("DownRight")
},
Joystick1 = new JoystickSettings
{
UpLeft = (int)joystick1.Attribute("UpLeft"),
Up = (int)joystick1.Attribute("Up"),
UpRight = (int)joystick1.Attribute("UpRight"),
Left = (int)joystick1.Attribute("Left"),
Right = (int)joystick1.Attribute("Right"),
DownLeft = (int)joystick1.Attribute("DownLeft"),
Down = (int)joystick1.Attribute("Down"),
DownRight = (int)joystick1.Attribute("DownRight")
},
Button0 = (int)buttons.Attribute("Button0"),
Button1 = (int)buttons.Attribute("Button1"),
Button2 = (int)buttons.Attribute("Button2")
}
};
var video = root.Element(ns + "Video");
var color = video.Element(ns + "Color");
Video = new VideoSettings
{
IsFullScreen = (bool)video.Attribute("IsFullScreen"),
IsMonochrome = (bool)video.Attribute("IsMonochrome"),
ScannerOptions = (ScannerOptions)Enum.Parse(typeof(ScannerOptions), (string)video.Attribute("ScannerOptions"), true),
Color = new ColorSettings
{
Black = (uint)color.Attribute("Black"),
DarkBlue = (uint)color.Attribute("DarkBlue"),
DarkGreen = (uint)color.Attribute("DarkGreen"),
MediumBlue = (uint)color.Attribute("MediumBlue"),
Brown = (uint)color.Attribute("Brown"),
LightGrey = (uint)color.Attribute("LightGrey"),
Green = (uint)color.Attribute("Green"),
Aquamarine = (uint)color.Attribute("Aquamarine"),
DeepRed = (uint)color.Attribute("DeepRed"),
Purple = (uint)color.Attribute("Purple"),
DarkGrey = (uint)color.Attribute("DarkGrey"),
LightBlue = (uint)color.Attribute("LightBlue"),
Orange = (uint)color.Attribute("Orange"),
Pink = (uint)color.Attribute("Pink"),
Yellow = (uint)color.Attribute("Yellow"),
White = (uint)color.Attribute("White"),
Monochrome = (uint)color.Attribute("Monochrome")
}
};
}
}
catch (Exception)
{
}
}
public void Serialize(Stream stream)
{
var ns = Namespace;
var xml = new XElement(ns + "MachineSettings",
new XElement(ns + "Cpu",
new XAttribute("Is65C02", Cpu.Is65C02),
new XAttribute("IsThrottled", Cpu.IsThrottled),
new XAttribute("Multiplier", Cpu.Multiplier)),
new XElement(ns + "DiskII",
new XElement(ns + "Disk1",
new XAttribute("Name", DiskII.Disk1.Name),
new XAttribute("IsWriteProtected", DiskII.Disk1.IsWriteProtected)),
new XElement(ns + "Disk2",
new XAttribute("Name", DiskII.Disk2.Name),
new XAttribute("IsWriteProtected", DiskII.Disk2.IsWriteProtected))),
new XElement(ns + "Keyboard",
new XAttribute("UseGamePort", Keyboard.UseGamePort),
new XElement(ns + "Key",
new XElement(ns + "Joystick0",
new XAttribute("UpLeft", Keyboard.Key.Joystick0.UpLeft),
new XAttribute("Up", Keyboard.Key.Joystick0.Up),
new XAttribute("UpRight", Keyboard.Key.Joystick0.UpRight),
new XAttribute("Left", Keyboard.Key.Joystick0.Left),
new XAttribute("Right", Keyboard.Key.Joystick0.Right),
new XAttribute("DownLeft", Keyboard.Key.Joystick0.DownLeft),
new XAttribute("Down", Keyboard.Key.Joystick0.Down),
new XAttribute("DownRight", Keyboard.Key.Joystick0.DownRight)),
new XElement(ns + "Joystick1",
new XAttribute("UpLeft", Keyboard.Key.Joystick1.UpLeft),
new XAttribute("Up", Keyboard.Key.Joystick1.Up),
new XAttribute("UpRight", Keyboard.Key.Joystick1.UpRight),
new XAttribute("Left", Keyboard.Key.Joystick1.Left),
new XAttribute("Right", Keyboard.Key.Joystick1.Right),
new XAttribute("DownLeft", Keyboard.Key.Joystick1.DownLeft),
new XAttribute("Down", Keyboard.Key.Joystick1.Down),
new XAttribute("DownRight", Keyboard.Key.Joystick1.DownRight)),
new XElement(ns + "Buttons",
new XAttribute("Button0", Keyboard.Key.Button0),
new XAttribute("Button1", Keyboard.Key.Button1),
new XAttribute("Button2", Keyboard.Key.Button2)))),
new XElement(ns + "GamePort",
new XAttribute("UseKeyboard", GamePort.UseKeyboard),
new XElement(ns + "Key",
new XElement(ns + "Joystick0",
new XAttribute("UpLeft", GamePort.Key.Joystick0.UpLeft),
new XAttribute("Up", GamePort.Key.Joystick0.Up),
new XAttribute("UpRight", GamePort.Key.Joystick0.UpRight),
new XAttribute("Left", GamePort.Key.Joystick0.Left),
new XAttribute("Right", GamePort.Key.Joystick0.Right),
new XAttribute("DownLeft", GamePort.Key.Joystick0.DownLeft),
new XAttribute("Down", GamePort.Key.Joystick0.Down),
new XAttribute("DownRight", GamePort.Key.Joystick0.DownRight)),
new XElement(ns + "Joystick1",
new XAttribute("UpLeft", GamePort.Key.Joystick1.UpLeft),
new XAttribute("Up", GamePort.Key.Joystick1.Up),
new XAttribute("UpRight", GamePort.Key.Joystick1.UpRight),
new XAttribute("Left", GamePort.Key.Joystick1.Left),
new XAttribute("Right", GamePort.Key.Joystick1.Right),
new XAttribute("DownLeft", GamePort.Key.Joystick1.DownLeft),
new XAttribute("Down", GamePort.Key.Joystick1.Down),
new XAttribute("DownRight", GamePort.Key.Joystick1.DownRight)),
new XElement(ns + "Buttons",
new XAttribute("Button0", Keyboard.Key.Button0),
new XAttribute("Button1", Keyboard.Key.Button1),
new XAttribute("Button2", Keyboard.Key.Button2)))),
new XElement(ns + "Video",
new XAttribute("IsFullScreen", Video.IsFullScreen),
new XAttribute("IsMonochrome", Video.IsMonochrome),
new XAttribute("ScannerOptions", Video.ScannerOptions),
new XElement(ns + "Color",
new XAttribute("Black", Video.Color.Black),
new XAttribute("DarkBlue", Video.Color.DarkBlue),
new XAttribute("DarkGreen", Video.Color.DarkGreen),
new XAttribute("MediumBlue", Video.Color.MediumBlue),
new XAttribute("Brown", Video.Color.Brown),
new XAttribute("LightGrey", Video.Color.LightGrey),
new XAttribute("Green", Video.Color.Green),
new XAttribute("Aquamarine", Video.Color.Aquamarine),
new XAttribute("DeepRed", Video.Color.DeepRed),
new XAttribute("Purple", Video.Color.Purple),
new XAttribute("DarkGrey", Video.Color.DarkGrey),
new XAttribute("LightBlue", Video.Color.LightBlue),
new XAttribute("Orange", Video.Color.Orange),
new XAttribute("Pink", Video.Color.Pink),
new XAttribute("Yellow", Video.Color.Yellow),
new XAttribute("White", Video.Color.White),
new XAttribute("Monochrome", Video.Color.Monochrome))));
using (var writer = XmlWriter.Create(stream))
{
xml.WriteTo(writer);
}
}
public CpuSettings Cpu { get; set; }
public DiskIISettings DiskII { get; set; }
public KeyboardSettings Keyboard { get; set; }
public GamePortSettings GamePort { get; set; }
public VideoSettings Video { get; set; }
public const string FileName = "Settings.xml";
public static readonly XNamespace Namespace = "http://schemas.jellyfish.co.nz/virtu/settings";
}
public sealed class CpuSettings
{
public bool Is65C02 { get; set; }
public bool IsThrottled { get; set; }
public int Multiplier { get; set; }
}
public sealed class DiskSettings
{
public string Name { get; set; }
public bool IsWriteProtected { get; set; }
};
public sealed class DiskIISettings
{
public DiskSettings Disk1 { get; set; }
public DiskSettings Disk2 { get; set; }
};
public sealed class JoystickSettings
{
public int UpLeft { get; set; }
public int Up { get; set; }
public int UpRight { get; set; }
public int Left { get; set; }
public int Right { get; set; }
public int DownLeft { get; set; }
public int Down { get; set; }
public int DownRight { get; set; }
};
public sealed class KeySettings
{
public JoystickSettings Joystick0 { get; set; }
public JoystickSettings Joystick1 { get; set; }
public int Button0 { get; set; }
public int Button1 { get; set; }
public int Button2 { get; set; }
};
public sealed class KeyboardSettings
{
public bool UseGamePort { get; set; }
public KeySettings Key { get; set; }
}
public sealed class GamePortSettings
{
public bool UseKeyboard { get; set; }
public KeySettings Key { get; set; }
}
public sealed class ColorSettings
{
public uint Black { get; set; }
public uint DarkBlue { get; set; }
public uint DarkGreen { get; set; }
public uint MediumBlue { get; set; }
public uint Brown { get; set; }
public uint LightGrey { get; set; }
public uint Green { get; set; }
public uint Aquamarine { get; set; }
public uint DeepRed { get; set; }
public uint Purple { get; set; }
public uint DarkGrey { get; set; }
public uint LightBlue { get; set; }
public uint Orange { get; set; }
public uint Pink { get; set; }
public uint Yellow { get; set; }
public uint White { get; set; }
public uint Monochrome { get; set; }
}
[Flags]
public enum ScannerOptions { None = 0x0, AppleII = 0x1, Pal = 0x2 } // defaults to AppleIIe, Ntsc
public sealed class VideoSettings
{
public bool IsFullScreen { get; set; }
public bool IsMonochrome { get; set; }
public ScannerOptions ScannerOptions { get; set; }
public ColorSettings Color { get; set; }
};
}

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -1,99 +1,99 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.4927
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Jellyfish.Virtu.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class SR {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal SR() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Jellyfish.Virtu.Properties.SR", typeof(SR).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to Resource &apos;{0}&apos; invalid..
/// </summary>
internal static string ResourceInvalid {
get {
return ResourceManager.GetString("ResourceInvalid", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Resource &apos;{0}&apos; not found..
/// </summary>
internal static string ResourceNotFound {
get {
return ResourceManager.GetString("ResourceNotFound", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Service type &apos;{0}&apos; already present..
/// </summary>
internal static string ServiceAlreadyPresent {
get {
return ResourceManager.GetString("ServiceAlreadyPresent", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Service type &apos;{0}&apos; must be assignable from service provider &apos;{1}&apos;..
/// </summary>
internal static string ServiceMustBeAssignable {
get {
return ResourceManager.GetString("ServiceMustBeAssignable", resourceCulture);
}
}
}
}
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.4927
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Jellyfish.Virtu.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class SR {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal SR() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Jellyfish.Virtu.Properties.SR", typeof(SR).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to Resource &apos;{0}&apos; invalid..
/// </summary>
internal static string ResourceInvalid {
get {
return ResourceManager.GetString("ResourceInvalid", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Resource &apos;{0}&apos; not found..
/// </summary>
internal static string ResourceNotFound {
get {
return ResourceManager.GetString("ResourceNotFound", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Service type &apos;{0}&apos; already present..
/// </summary>
internal static string ServiceAlreadyPresent {
get {
return ResourceManager.GetString("ServiceAlreadyPresent", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Service type &apos;{0}&apos; must be assignable from service provider &apos;{1}&apos;..
/// </summary>
internal static string ServiceMustBeAssignable {
get {
return ResourceManager.GetString("ServiceMustBeAssignable", resourceCulture);
}
}
}
}

View File

@ -1,132 +1,132 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="ResourceNotFound" xml:space="preserve">
<value>Resource '{0}' not found.</value>
</data>
<data name="ResourceInvalid" xml:space="preserve">
<value>Resource '{0}' invalid.</value>
</data>
<data name="ServiceAlreadyPresent" xml:space="preserve">
<value>Service type '{0}' already present.</value>
</data>
<data name="ServiceMustBeAssignable" xml:space="preserve">
<value>Service type '{0}' must be assignable from service provider '{1}'.</value>
</data>
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="ResourceNotFound" xml:space="preserve">
<value>Resource '{0}' not found.</value>
</data>
<data name="ResourceInvalid" xml:space="preserve">
<value>Resource '{0}' invalid.</value>
</data>
<data name="ServiceAlreadyPresent" xml:space="preserve">
<value>Service type '{0}' already present.</value>
</data>
<data name="ServiceMustBeAssignable" xml:space="preserve">
<value>Service type '{0}' must be assignable from service provider '{1}'.</value>
</data>
</root>

View File

@ -1,67 +1,67 @@
using System;
using System.Threading;
namespace Jellyfish.Virtu.Services
{
public class AudioService : MachineService
{
public AudioService(Machine machine) :
base(machine)
{
}
public void Output(int data) // machine thread
{
_buffer[_index] = (byte)data;
_index = (_index + 1) % SampleSize;
if (_index == 0)
{
_readEvent.Set();
if (Machine.Settings.Cpu.IsThrottled)
{
_writeEvent.WaitOne();
}
}
}
public void Reset()
{
Buffer.BlockCopy(SampleZero, 0, _buffer, 0, SampleSize);
}
public override void Stop() // main thread
{
_readEvent.Set(); // signal events; avoids deadlock
_writeEvent.Set();
}
protected void Update(int bufferSize, Action<byte[], int> updateBuffer) // audio thread
{
if (updateBuffer == null)
{
throw new ArgumentNullException("updateBuffer");
}
if (Machine.State == MachineState.Running)
{
_readEvent.WaitOne();
}
updateBuffer(_buffer, bufferSize);
_writeEvent.Set();
}
public const int SampleRate = 44100; // hz
public const int SampleChannels = 1;
public const int SampleBits = 8;
public const int SampleLatency = 40; // ms
public const int SampleSize = (SampleRate * SampleLatency / 1000) * SampleChannels * (SampleBits / 8);
private static readonly byte[] SampleZero = new byte[SampleSize];
private byte[] _buffer = new byte[SampleSize];
private int _index;
private AutoResetEvent _readEvent = new AutoResetEvent(false);
private AutoResetEvent _writeEvent = new AutoResetEvent(false);
}
}
using System;
using System.Threading;
namespace Jellyfish.Virtu.Services
{
public class AudioService : MachineService
{
public AudioService(Machine machine) :
base(machine)
{
}
public void Output(int data) // machine thread
{
_buffer[_index] = (byte)data;
_index = (_index + 1) % SampleSize;
if (_index == 0)
{
_readEvent.Set();
if (Machine.Settings.Cpu.IsThrottled)
{
_writeEvent.WaitOne();
}
}
}
public void Reset()
{
Buffer.BlockCopy(SampleZero, 0, _buffer, 0, SampleSize);
}
public override void Stop() // main thread
{
_readEvent.Set(); // signal events; avoids deadlock
_writeEvent.Set();
}
protected void Update(int bufferSize, Action<byte[], int> updateBuffer) // audio thread
{
if (updateBuffer == null)
{
throw new ArgumentNullException("updateBuffer");
}
if (Machine.State == MachineState.Running)
{
_readEvent.WaitOne();
}
updateBuffer(_buffer, bufferSize);
_writeEvent.Set();
}
public const int SampleRate = 44100; // hz
public const int SampleChannels = 1;
public const int SampleBits = 8;
public const int SampleLatency = 40; // ms
public const int SampleSize = (SampleRate * SampleLatency / 1000) * SampleChannels * (SampleBits / 8);
private static readonly byte[] SampleZero = new byte[SampleSize];
private byte[] _buffer = new byte[SampleSize];
private int _index;
private AutoResetEvent _readEvent = new AutoResetEvent(false);
private AutoResetEvent _writeEvent = new AutoResetEvent(false);
}
}

View File

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

View File

@ -1,70 +1,70 @@
using System;
using System.Threading;
namespace Jellyfish.Virtu.Services
{
public sealed class AsciiKeyEventArgs : EventArgs
{
private AsciiKeyEventArgs()
{
}
public static AsciiKeyEventArgs Create(int asciiKey)
{
_instance.AsciiKey = asciiKey;
return _instance; // use singleton; avoids garbage
}
public int AsciiKey { get; private set; }
private static readonly AsciiKeyEventArgs _instance = new AsciiKeyEventArgs();
}
public abstract class KeyboardService : MachineService
{
protected KeyboardService(Machine machine) :
base(machine)
{
}
public abstract bool IsKeyDown(int key);
public virtual void Update() // main thread
{
if (IsResetKeyDown)
{
if (!_resetKeyDown)
{
_resetKeyDown = true; // entering reset; pause until key released
Machine.Pause();
Machine.Reset();
}
}
else if (_resetKeyDown)
{
_resetKeyDown = false; // leaving reset
Machine.Unpause();
}
}
protected void OnAsciiKeyDown(int asciiKey)
{
EventHandler<AsciiKeyEventArgs> handler = AsciiKeyDown;
if (handler != null)
{
handler(this, AsciiKeyEventArgs.Create(asciiKey));
}
}
public event EventHandler<AsciiKeyEventArgs> AsciiKeyDown;
public bool IsAnyKeyDown { get; protected set; }
public bool IsOpenAppleKeyDown { get; protected set; }
public bool IsCloseAppleKeyDown { get; protected set; }
protected bool IsResetKeyDown { get; set; }
private bool _resetKeyDown;
}
}
using System;
using System.Threading;
namespace Jellyfish.Virtu.Services
{
public sealed class AsciiKeyEventArgs : EventArgs
{
private AsciiKeyEventArgs()
{
}
public static AsciiKeyEventArgs Create(int asciiKey)
{
_instance.AsciiKey = asciiKey;
return _instance; // use singleton; avoids garbage
}
public int AsciiKey { get; private set; }
private static readonly AsciiKeyEventArgs _instance = new AsciiKeyEventArgs();
}
public abstract class KeyboardService : MachineService
{
protected KeyboardService(Machine machine) :
base(machine)
{
}
public abstract bool IsKeyDown(int key);
public virtual void Update() // main thread
{
if (IsResetKeyDown)
{
if (!_resetKeyDown)
{
_resetKeyDown = true; // entering reset; pause until key released
Machine.Pause();
Machine.Reset();
}
}
else if (_resetKeyDown)
{
_resetKeyDown = false; // leaving reset
Machine.Unpause();
}
}
protected void OnAsciiKeyDown(int asciiKey)
{
EventHandler<AsciiKeyEventArgs> handler = AsciiKeyDown;
if (handler != null)
{
handler(this, AsciiKeyEventArgs.Create(asciiKey));
}
}
public event EventHandler<AsciiKeyEventArgs> AsciiKeyDown;
public bool IsAnyKeyDown { get; protected set; }
public bool IsOpenAppleKeyDown { get; protected set; }
public bool IsCloseAppleKeyDown { get; protected set; }
protected bool IsResetKeyDown { get; set; }
private bool _resetKeyDown;
}
}

View File

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

View File

@ -1,41 +1,41 @@
using System;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Resources;
using Jellyfish.Virtu.Properties;
namespace Jellyfish.Virtu.Services
{
public abstract class StorageService : MachineService
{
protected StorageService(Machine machine) :
base(machine)
{
}
public static Stream GetResourceStream(string resourceName)
{
return GetResourceStream(resourceName, 0);
}
public static Stream GetResourceStream(string resourceName, int resourceSize)
{
ResourceManager resourceManager = new ResourceManager("Jellyfish.Virtu.g", Assembly.GetExecutingAssembly()) { IgnoreCase = true };
Stream resourceStream = (Stream)resourceManager.GetObject(resourceName);
if (resourceStream == null)
{
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, SR.ResourceNotFound, resourceName));
}
if ((resourceSize > 0) && (resourceStream.Length != resourceSize))
{
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, SR.ResourceInvalid, resourceName));
}
return resourceStream;
}
public abstract void Load(string path, Action<Stream> reader);
public abstract void Save(string path, Action<Stream> writer);
}
}
using System;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Resources;
using Jellyfish.Virtu.Properties;
namespace Jellyfish.Virtu.Services
{
public abstract class StorageService : MachineService
{
protected StorageService(Machine machine) :
base(machine)
{
}
public static Stream GetResourceStream(string resourceName)
{
return GetResourceStream(resourceName, 0);
}
public static Stream GetResourceStream(string resourceName, int resourceSize)
{
var resourceManager = new ResourceManager("Jellyfish.Virtu.g", Assembly.GetExecutingAssembly()) { IgnoreCase = true };
var resourceStream = (Stream)resourceManager.GetObject(resourceName);
if (resourceStream == null)
{
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, SR.ResourceNotFound, resourceName));
}
if ((resourceSize > 0) && (resourceStream.Length != resourceSize))
{
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, SR.ResourceInvalid, resourceName));
}
return resourceStream;
}
public abstract void Load(string path, Action<Stream> reader);
public abstract void Save(string path, Action<Stream> writer);
}
}

View File

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

View File

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

View File

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

View File

@ -1,21 +1,21 @@
<UserControl x:Class="Jellyfish.Virtu.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:tk="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
xmlns:jl="clr-namespace:Jellyfish.Library;assembly=Jellyfish.Library"
xmlns:jv="clr-namespace:Jellyfish.Virtu;assembly=Jellyfish.Virtu">
<tk:DockPanel Background="Black">
<StackPanel Orientation="Horizontal" tk:DockPanel.Dock="Top">
<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"/>
<jl:FrameRateCounter Margin="4 4 0 4" VerticalAlignment="Center"/>
</StackPanel>
<Grid>
<Image x:Name="_image" MinWidth="560" MinHeight="384"/>
<MediaElement x:Name="_media"/>
<!--<ScrollViewer BorderThickness="0" IsTabStop="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" VerticalScrollBarVisibility="Auto">
<TextBlock x:Name="_debug" FontFamily="Consolas" FontSize="12" Foreground="White"/>
</ScrollViewer>-->
</Grid>
</tk:DockPanel>
</UserControl>
<UserControl x:Class="Jellyfish.Virtu.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:tk="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
xmlns:jl="clr-namespace:Jellyfish.Library;assembly=Jellyfish.Library"
xmlns:jv="clr-namespace:Jellyfish.Virtu;assembly=Jellyfish.Virtu">
<tk:DockPanel Background="Black">
<StackPanel Orientation="Horizontal" tk:DockPanel.Dock="Top">
<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"/>
<jl:FrameRateCounter Margin="4 4 0 4" VerticalAlignment="Center"/>
</StackPanel>
<Grid>
<Image x:Name="_image" MinWidth="560" MinHeight="384"/>
<MediaElement x:Name="_media"/>
<!--<ScrollViewer BorderThickness="0" IsTabStop="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" VerticalScrollBarVisibility="Auto">
<TextBlock x:Name="_debug" FontFamily="Consolas" FontSize="12" Foreground="White"/>
</ScrollViewer>-->
</Grid>
</tk:DockPanel>
</UserControl>

View File

@ -1,78 +1,77 @@
using System;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Jellyfish.Virtu.Services;
namespace Jellyfish.Virtu
{
public sealed partial class MainPage : UserControl, IDisposable
{
public MainPage()
{
InitializeComponent();
_storageService = new SilverlightStorageService(_machine);
_keyboardService = new SilverlightKeyboardService(_machine, this);
_gamePortService = new GamePortService(_machine); // not connected
_audioService = new SilverlightAudioService(_machine, this, _media);
_videoService = new SilverlightVideoService(_machine, _image);
_machine.Services.AddService(typeof(StorageService), _storageService);
_machine.Services.AddService(typeof(KeyboardService), _keyboardService);
_machine.Services.AddService(typeof(GamePortService), _gamePortService);
_machine.Services.AddService(typeof(AudioService), _audioService);
_machine.Services.AddService(typeof(VideoService), _videoService);
Loaded += (sender, e) => _machine.Start();
CompositionTarget.Rendering += OnCompositionTargetRendering;
Application.Current.Exit += (sender, e) => _machine.Stop();
_disk1Button.Click += (sender, e) => OnDiskButtonClick(0);
_disk2Button.Click += (sender, e) => OnDiskButtonClick(1);
}
public void Dispose()
{
_machine.Dispose();
_storageService.Dispose();
_keyboardService.Dispose();
_gamePortService.Dispose();
_audioService.Dispose();
_videoService.Dispose();
}
private void OnCompositionTargetRendering(object sender, EventArgs e)
{
_keyboardService.Update();
_gamePortService.Update();
_videoService.Update();
}
private void OnDiskButtonClick(int drive)
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "Disk Files (*.dsk;*.nib)|*.dsk;*.nib|All Files (*.*)|*.*";
bool? result = dialog.ShowDialog();
if (result.HasValue && result.Value)
{
using (FileStream stream = dialog.File.OpenRead())
{
_machine.Pause();
_machine.DiskII.Drives[drive].InsertDisk(dialog.File.Name, stream, false);
_machine.Unpause();
}
}
}
private Machine _machine = new Machine();
private StorageService _storageService;
private KeyboardService _keyboardService;
private GamePortService _gamePortService;
private AudioService _audioService;
private VideoService _videoService;
}
}
using System;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Jellyfish.Virtu.Services;
namespace Jellyfish.Virtu
{
public sealed partial class MainPage : UserControl, IDisposable
{
public MainPage()
{
InitializeComponent();
_storageService = new SilverlightStorageService(_machine);
_keyboardService = new SilverlightKeyboardService(_machine, this);
_gamePortService = new GamePortService(_machine); // not connected
_audioService = new SilverlightAudioService(_machine, this, _media);
_videoService = new SilverlightVideoService(_machine, _image);
_machine.Services.AddService(typeof(StorageService), _storageService);
_machine.Services.AddService(typeof(KeyboardService), _keyboardService);
_machine.Services.AddService(typeof(GamePortService), _gamePortService);
_machine.Services.AddService(typeof(AudioService), _audioService);
_machine.Services.AddService(typeof(VideoService), _videoService);
Loaded += (sender, e) => _machine.Start();
CompositionTarget.Rendering += OnCompositionTargetRendering;
Application.Current.Exit += (sender, e) => _machine.Stop();
_disk1Button.Click += (sender, e) => OnDiskButtonClick(0);
_disk2Button.Click += (sender, e) => OnDiskButtonClick(1);
}
public void Dispose()
{
_machine.Dispose();
_storageService.Dispose();
_keyboardService.Dispose();
_gamePortService.Dispose();
_audioService.Dispose();
_videoService.Dispose();
}
private void OnCompositionTargetRendering(object sender, EventArgs e)
{
_keyboardService.Update();
_gamePortService.Update();
_videoService.Update();
}
private void OnDiskButtonClick(int drive)
{
var dialog = new OpenFileDialog() { Filter = "Disk Files (*.dsk;*.nib)|*.dsk;*.nib|All Files (*.*)|*.*" };
bool? result = dialog.ShowDialog();
if (result.HasValue && result.Value)
{
using (var stream = dialog.File.OpenRead())
{
_machine.Pause();
_machine.DiskII.Drives[drive].InsertDisk(dialog.File.Name, stream, false);
_machine.Unpause();
}
}
}
private Machine _machine = new Machine();
private StorageService _storageService;
private KeyboardService _keyboardService;
private GamePortService _gamePortService;
private AudioService _audioService;
private VideoService _videoService;
}
}

View File

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

View File

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

View File

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

View File

@ -1,61 +1,61 @@
using System;
using System.IO;
using System.IO.IsolatedStorage;
namespace Jellyfish.Virtu.Services
{
public sealed class SilverlightStorageService : StorageService
{
public SilverlightStorageService(Machine machine) :
base(machine)
{
}
public override void Load(string path, Action<Stream> reader)
{
if (reader == null)
{
throw new ArgumentNullException("reader");
}
try
{
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, store))
{
reader(stream);
}
}
}
catch (FileNotFoundException)
{
}
catch (IsolatedStorageException)
{
}
}
public override void Save(string path, Action<Stream> writer)
{
if (writer == null)
{
throw new ArgumentNullException("writer");
}
try
{
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(path, FileMode.Create, FileAccess.Write, FileShare.None, store))
{
writer(stream);
}
}
}
catch (IsolatedStorageException)
{
}
}
}
}
using System;
using System.IO;
using System.IO.IsolatedStorage;
namespace Jellyfish.Virtu.Services
{
public sealed class SilverlightStorageService : StorageService
{
public SilverlightStorageService(Machine machine) :
base(machine)
{
}
public override void Load(string path, Action<Stream> reader)
{
if (reader == null)
{
throw new ArgumentNullException("reader");
}
try
{
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
using (var stream = new IsolatedStorageFileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, store))
{
reader(stream);
}
}
}
catch (FileNotFoundException)
{
}
catch (IsolatedStorageException)
{
}
}
public override void Save(string path, Action<Stream> writer)
{
if (writer == null)
{
throw new ArgumentNullException("writer");
}
try
{
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
using (var stream = new IsolatedStorageFileStream(path, FileMode.Create, FileAccess.Write, FileShare.None, store))
{
writer(stream);
}
}
}
catch (IsolatedStorageException)
{
}
}
}
}

View File

@ -1,84 +1,84 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interop;
using System.Windows.Media.Imaging;
namespace Jellyfish.Virtu.Services
{
public sealed class SilverlightVideoService : VideoService
{
public SilverlightVideoService(Machine machine, Image image) :
base(machine)
{
if (image == null)
{
throw new ArgumentNullException("image");
}
_image = image;
_image.Source = _bitmap;
SetImageSize();
Application.Current.Host.Content.Resized += (sender, e) => SetImageSize();
}
[SuppressMessage("Microsoft.Usage", "CA2233:OperationsShouldNotOverflow", MessageId = "y*560")]
public override void SetPixel(int x, int y, uint color)
{
_pixels[y * BitmapWidth + x] = (int)color;
_pixelsDirty = true;
}
public override void Update() // main thread
{
if (Application.Current.IsRunningOutOfBrowser && /*_window.IsActive &&*/ (_isFullScreen != IsFullScreen))
{
if (IsFullScreen) // SL is missing out of browser window control
{
//_window.SizeToContent = SizeToContent.Manual;
//_window.Topmost = true;
//_window.WindowStyle = WindowStyle.None;
//_window.WindowState = WindowState.Maximized;
}
else
{
//_window.WindowState = WindowState.Normal;
//_window.WindowStyle = WindowStyle.SingleBorderWindow;
//_window.Topmost = false;
//_window.SizeToContent = SizeToContent.WidthAndHeight;
}
_isFullScreen = IsFullScreen;
}
if (_pixelsDirty)
{
_pixelsDirty = false;
for (int i = 0; i < BitmapWidth * BitmapHeight; i++)
{
_bitmap.Pixels[i] = _pixels[i];
}
_bitmap.Invalidate();
}
}
private void SetImageSize()
{
Content content = Application.Current.Host.Content;
int uniformScale = Math.Min((int)content.ActualWidth / BitmapWidth, (int)content.ActualHeight / BitmapHeight);
_image.Width = uniformScale * BitmapWidth;
_image.Height = uniformScale * BitmapHeight;
}
private const int BitmapWidth = 560;
private const int BitmapHeight = 384;
private Image _image;
private WriteableBitmap _bitmap = new WriteableBitmap(BitmapWidth, BitmapHeight);
private int[] _pixels = new int[BitmapWidth * BitmapHeight];
private bool _pixelsDirty;
private bool _isFullScreen;
}
}
using System;
using System.Diagnostics.CodeAnalysis;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interop;
using System.Windows.Media.Imaging;
namespace Jellyfish.Virtu.Services
{
public sealed class SilverlightVideoService : VideoService
{
public SilverlightVideoService(Machine machine, Image image) :
base(machine)
{
if (image == null)
{
throw new ArgumentNullException("image");
}
_image = image;
_image.Source = _bitmap;
SetImageSize();
Application.Current.Host.Content.Resized += (sender, e) => SetImageSize();
}
[SuppressMessage("Microsoft.Usage", "CA2233:OperationsShouldNotOverflow", MessageId = "y*560")]
public override void SetPixel(int x, int y, uint color)
{
_pixels[y * BitmapWidth + x] = (int)color;
_pixelsDirty = true;
}
public override void Update() // main thread
{
if (Application.Current.IsRunningOutOfBrowser && /*_window.IsActive &&*/ (_isFullScreen != IsFullScreen))
{
if (IsFullScreen) // SL is missing out of browser window control
{
//_window.SizeToContent = SizeToContent.Manual;
//_window.Topmost = true;
//_window.WindowStyle = WindowStyle.None;
//_window.WindowState = WindowState.Maximized;
}
else
{
//_window.WindowState = WindowState.Normal;
//_window.WindowStyle = WindowStyle.SingleBorderWindow;
//_window.Topmost = false;
//_window.SizeToContent = SizeToContent.WidthAndHeight;
}
_isFullScreen = IsFullScreen;
}
if (_pixelsDirty)
{
_pixelsDirty = false;
for (int i = 0; i < BitmapWidth * BitmapHeight; i++)
{
_bitmap.Pixels[i] = _pixels[i];
}
_bitmap.Invalidate();
}
}
private void SetImageSize()
{
var content = Application.Current.Host.Content;
int uniformScale = Math.Min((int)content.ActualWidth / BitmapWidth, (int)content.ActualHeight / BitmapHeight);
_image.Width = uniformScale * BitmapWidth;
_image.Height = uniformScale * BitmapHeight;
}
private const int BitmapWidth = 560;
private const int BitmapHeight = 384;
private Image _image;
private WriteableBitmap _bitmap = new WriteableBitmap(BitmapWidth, BitmapHeight);
private int[] _pixels = new int[BitmapWidth * BitmapHeight];
private bool _pixelsDirty;
private bool _isFullScreen;
}
}

View File

@ -1,65 +1,65 @@
using System;
using Jellyfish.Virtu.Services;
namespace Jellyfish.Virtu
{
public sealed class Speaker : MachineComponent
{
public Speaker(Machine machine) :
base(machine)
{
_flushOutputEvent = FlushOutputEvent; // cache delegates; avoids garbage
}
public override void Initialize()
{
_audioService = Machine.Services.GetService<AudioService>();
Machine.Events.AddEvent(CyclesPerFlush * Machine.Settings.Cpu.Multiplier, _flushOutputEvent);
}
public override void Reset()
{
_audioService.Reset();
_isHigh = false;
_highCycles = _totalCycles = 0;
}
public void ToggleOutput()
{
UpdateCycles();
_isHigh ^= true;
}
private void FlushOutputEvent()
{
UpdateCycles();
_audioService.Output(_highCycles * 255 / _totalCycles); // quick and dirty decimation
_highCycles = _totalCycles = 0;
Machine.Events.AddEvent(CyclesPerFlush * Machine.Settings.Cpu.Multiplier, _flushOutputEvent);
}
private void UpdateCycles()
{
int delta = (int)(Machine.Cpu.Cycles - _lastCycles);
if (_isHigh)
{
_highCycles += delta;
}
_totalCycles += delta;
_lastCycles = Machine.Cpu.Cycles;
}
private const int CyclesPerFlush = 23;
private Action _flushOutputEvent;
private bool _isHigh;
private int _highCycles;
private int _totalCycles;
private long _lastCycles;
private AudioService _audioService;
}
}
using System;
using Jellyfish.Virtu.Services;
namespace Jellyfish.Virtu
{
public sealed class Speaker : MachineComponent
{
public Speaker(Machine machine) :
base(machine)
{
_flushOutputEvent = FlushOutputEvent; // cache delegates; avoids garbage
}
public override void Initialize()
{
_audioService = Machine.Services.GetService<AudioService>();
Machine.Events.AddEvent(CyclesPerFlush * Machine.Settings.Cpu.Multiplier, _flushOutputEvent);
}
public override void Reset()
{
_audioService.Reset();
_isHigh = false;
_highCycles = _totalCycles = 0;
}
public void ToggleOutput()
{
UpdateCycles();
_isHigh ^= true;
}
private void FlushOutputEvent()
{
UpdateCycles();
_audioService.Output(_highCycles * 255 / _totalCycles); // quick and dirty decimation
_highCycles = _totalCycles = 0;
Machine.Events.AddEvent(CyclesPerFlush * Machine.Settings.Cpu.Multiplier, _flushOutputEvent);
}
private void UpdateCycles()
{
int delta = (int)(Machine.Cpu.Cycles - _lastCycles);
if (_isHigh)
{
_highCycles += delta;
}
_totalCycles += delta;
_lastCycles = Machine.Cpu.Cycles;
}
private const int CyclesPerFlush = 23;
private Action _flushOutputEvent;
private bool _isHigh;
private int _highCycles;
private int _totalCycles;
private long _lastCycles;
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"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:jl="clr-namespace:Jellyfish.Library;assembly=Jellyfish.Library"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</jl:ApplicationBase>
<jl:ApplicationBase x:Class="Jellyfish.Virtu.MainApp"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:jl="clr-namespace:Jellyfish.Library;assembly=Jellyfish.Library"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</jl:ApplicationBase>

View File

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

View File

@ -1,19 +1,19 @@
<Window x:Class="Jellyfish.Virtu.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:jl="clr-namespace:Jellyfish.Library;assembly=Jellyfish.Library"
Title="Virtu" ResizeMode="CanMinimize" SizeToContent="WidthAndHeight" WindowStartupLocation="CenterScreen">
<DockPanel Background="Black">
<StackPanel Orientation="Horizontal" DockPanel.Dock="Top">
<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"/>
<jl:FrameRateCounter Margin="4 4 0 4" VerticalAlignment="Center"/>
</StackPanel>
<Grid>
<Image x:Name="_image" MinWidth="560" MinHeight="384" RenderOptions.BitmapScalingMode="NearestNeighbor"/>
<!--<ScrollViewer BorderThickness="0" Focusable="False" IsTabStop="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" VerticalScrollBarVisibility="Auto">
<TextBlock x:Name="_debug" FontFamily="Consolas" FontSize="12" Foreground="White"/>
</ScrollViewer>-->
</Grid>
</DockPanel>
</Window>
<Window x:Class="Jellyfish.Virtu.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:jl="clr-namespace:Jellyfish.Library;assembly=Jellyfish.Library"
Title="Virtu" ResizeMode="CanMinimize" SizeToContent="WidthAndHeight" WindowStartupLocation="CenterScreen">
<DockPanel Background="Black">
<StackPanel Orientation="Horizontal" DockPanel.Dock="Top">
<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"/>
<jl:FrameRateCounter Margin="4 4 0 4" VerticalAlignment="Center"/>
</StackPanel>
<Grid>
<Image x:Name="_image" MinWidth="560" MinHeight="384" RenderOptions.BitmapScalingMode="NearestNeighbor"/>
<!--<ScrollViewer BorderThickness="0" Focusable="False" IsTabStop="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" VerticalScrollBarVisibility="Auto">
<TextBlock x:Name="_debug" FontFamily="Consolas" FontSize="12" Foreground="White"/>
</ScrollViewer>-->
</Grid>
</DockPanel>
</Window>

View File

@ -1,88 +1,87 @@
using System;
using System.IO;
using System.Windows;
using System.Windows.Media;
using Jellyfish.Virtu.Services;
using Jellyfish.Virtu.Settings;
using Microsoft.Win32;
namespace Jellyfish.Virtu
{
public sealed partial class MainWindow : Window, IDisposable
{
public MainWindow()
{
InitializeComponent();
_storageService = new WpfStorageService(_machine);
_keyboardService = new WpfKeyboardService(_machine, this);
_gamePortService = new GamePortService(_machine); // not connected
_audioService = new WpfAudioService(_machine, this);
_videoService = new WpfVideoService(_machine, this, _image);
_machine.Services.AddService(typeof(StorageService), _storageService);
_machine.Services.AddService(typeof(KeyboardService), _keyboardService);
_machine.Services.AddService(typeof(GamePortService), _gamePortService);
_machine.Services.AddService(typeof(AudioService), _audioService);
_machine.Services.AddService(typeof(VideoService), _videoService);
Loaded += (sender, e) => _machine.Start();
CompositionTarget.Rendering += OnCompositionTargetRendering;
Application.Current.Exit += (sender, e) => _machine.Stop();
_disk1Button.Click += (sender, e) => OnDiskButtonClick(0);
_disk2Button.Click += (sender, e) => OnDiskButtonClick(1);
}
public void Dispose()
{
_machine.Dispose();
_storageService.Dispose();
_keyboardService.Dispose();
_gamePortService.Dispose();
_audioService.Dispose();
_videoService.Dispose();
}
private void OnCompositionTargetRendering(object sender, EventArgs e)
{
_keyboardService.Update();
_gamePortService.Update();
_videoService.Update();
}
private void OnDiskButtonClick(int drive)
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "Disk Files (*.dsk;*.nib)|*.dsk;*.nib|All Files (*.*)|*.*";
bool? result = dialog.ShowDialog();
if (result.HasValue && result.Value)
{
using (FileStream stream = File.OpenRead(dialog.FileName))
{
_machine.Pause();
_machine.DiskII.Drives[drive].InsertDisk(dialog.FileName, stream, false);
DiskIISettings settings = _machine.Settings.DiskII;
if (drive == 0)
{
settings.Disk1.Name = dialog.FileName;
}
else
{
settings.Disk2.Name = dialog.FileName;
}
_machine.Unpause();
}
}
}
private Machine _machine = new Machine();
private StorageService _storageService;
private KeyboardService _keyboardService;
private GamePortService _gamePortService;
private AudioService _audioService;
private VideoService _videoService;
}
}
using System;
using System.IO;
using System.Windows;
using System.Windows.Media;
using Jellyfish.Virtu.Services;
using Jellyfish.Virtu.Settings;
using Microsoft.Win32;
namespace Jellyfish.Virtu
{
public sealed partial class MainWindow : Window, IDisposable
{
public MainWindow()
{
InitializeComponent();
_storageService = new WpfStorageService(_machine);
_keyboardService = new WpfKeyboardService(_machine, this);
_gamePortService = new GamePortService(_machine); // not connected
_audioService = new WpfAudioService(_machine, this);
_videoService = new WpfVideoService(_machine, this, _image);
_machine.Services.AddService(typeof(StorageService), _storageService);
_machine.Services.AddService(typeof(KeyboardService), _keyboardService);
_machine.Services.AddService(typeof(GamePortService), _gamePortService);
_machine.Services.AddService(typeof(AudioService), _audioService);
_machine.Services.AddService(typeof(VideoService), _videoService);
Loaded += (sender, e) => _machine.Start();
CompositionTarget.Rendering += OnCompositionTargetRendering;
Application.Current.Exit += (sender, e) => _machine.Stop();
_disk1Button.Click += (sender, e) => OnDiskButtonClick(0);
_disk2Button.Click += (sender, e) => OnDiskButtonClick(1);
}
public void Dispose()
{
_machine.Dispose();
_storageService.Dispose();
_keyboardService.Dispose();
_gamePortService.Dispose();
_audioService.Dispose();
_videoService.Dispose();
}
private void OnCompositionTargetRendering(object sender, EventArgs e)
{
_keyboardService.Update();
_gamePortService.Update();
_videoService.Update();
}
private void OnDiskButtonClick(int drive)
{
var dialog = new OpenFileDialog() { Filter = "Disk Files (*.dsk;*.nib)|*.dsk;*.nib|All Files (*.*)|*.*" };
bool? result = dialog.ShowDialog();
if (result.HasValue && result.Value)
{
using (FileStream stream = File.OpenRead(dialog.FileName))
{
_machine.Pause();
_machine.DiskII.Drives[drive].InsertDisk(dialog.FileName, stream, false);
DiskIISettings settings = _machine.Settings.DiskII;
if (drive == 0)
{
settings.Disk1.Name = dialog.FileName;
}
else
{
settings.Disk2.Name = dialog.FileName;
}
_machine.Unpause();
}
}
}
private Machine _machine = new Machine();
private StorageService _storageService;
private KeyboardService _keyboardService;
private GamePortService _gamePortService;
private AudioService _audioService;
private VideoService _videoService;
}
}

View File

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

View File

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

View File

@ -1,68 +1,68 @@
using System;
using System.Deployment.Application;
using System.IO;
using System.IO.IsolatedStorage;
namespace Jellyfish.Virtu.Services
{
public sealed class WpfStorageService : StorageService
{
public WpfStorageService(Machine machine) :
base(machine)
{
}
public override void Load(string path, Action<Stream> reader)
{
if (reader == null)
{
throw new ArgumentNullException("reader");
}
try
{
using (IsolatedStorageFile store = GetStore())
{
using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, store))
{
reader(stream);
}
}
}
catch (FileNotFoundException)
{
}
catch (IsolatedStorageException)
{
}
}
public override void Save(string path, Action<Stream> writer)
{
if (writer == null)
{
throw new ArgumentNullException("writer");
}
try
{
using (IsolatedStorageFile store = GetStore())
{
using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(path, FileMode.Create, FileAccess.Write, FileShare.None, store))
{
writer(stream);
}
}
}
catch (IsolatedStorageException)
{
}
}
private static IsolatedStorageFile GetStore()
{
return ApplicationDeployment.IsNetworkDeployed ? // clickonce
IsolatedStorageFile.GetUserStoreForApplication() : IsolatedStorageFile.GetUserStoreForAssembly();
}
}
}
using System;
using System.Deployment.Application;
using System.IO;
using System.IO.IsolatedStorage;
namespace Jellyfish.Virtu.Services
{
public sealed class WpfStorageService : StorageService
{
public WpfStorageService(Machine machine) :
base(machine)
{
}
public override void Load(string path, Action<Stream> reader)
{
if (reader == null)
{
throw new ArgumentNullException("reader");
}
try
{
using (var store = GetStore())
{
using (var stream = new IsolatedStorageFileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, store))
{
reader(stream);
}
}
}
catch (FileNotFoundException)
{
}
catch (IsolatedStorageException)
{
}
}
public override void Save(string path, Action<Stream> writer)
{
if (writer == null)
{
throw new ArgumentNullException("writer");
}
try
{
using (var store = GetStore())
{
using (var stream = new IsolatedStorageFileStream(path, FileMode.Create, FileAccess.Write, FileShare.None, store))
{
writer(stream);
}
}
}
catch (IsolatedStorageException)
{
}
}
private static IsolatedStorageFile GetStore()
{
return ApplicationDeployment.IsNetworkDeployed ? // clickonce
IsolatedStorageFile.GetUserStoreForApplication() : IsolatedStorageFile.GetUserStoreForAssembly();
}
}
}

View File

@ -1,94 +1,94 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Security.Permissions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Microsoft.Win32;
namespace Jellyfish.Virtu.Services
{
public sealed class WpfVideoService : VideoService
{
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
public WpfVideoService(Machine machine, Window window, Image image) :
base(machine)
{
if (window == null)
{
throw new ArgumentNullException("window");
}
if (image == null)
{
throw new ArgumentNullException("image");
}
_window = window;
_image = image;
_image.Source = _bitmap;
SetImageSize();
SystemEvents.DisplaySettingsChanged += (sender, e) => SetImageSize();
}
[SuppressMessage("Microsoft.Usage", "CA2233:OperationsShouldNotOverflow", MessageId = "y*560")]
public override void SetPixel(int x, int y, uint color)
{
_pixels[y * BitmapWidth + x] = color;
_pixelsDirty = true;
}
public override void Update() // main thread
{
if (_window.IsActive && (_isFullScreen != IsFullScreen))
{
if (IsFullScreen)
{
_window.SizeToContent = SizeToContent.Manual;
_window.Topmost = true;
_window.WindowStyle = WindowStyle.None;
_window.WindowState = WindowState.Maximized;
}
else
{
_window.WindowState = WindowState.Normal;
_window.WindowStyle = WindowStyle.SingleBorderWindow;
_window.Topmost = false;
_window.SizeToContent = SizeToContent.WidthAndHeight;
}
_isFullScreen = IsFullScreen;
SetImageSize();
}
if (_pixelsDirty)
{
_pixelsDirty = false;
_bitmap.WritePixels(BitmapRect, _pixels, BitmapStride, 0);
}
}
private void SetImageSize()
{
int uniformScale = IsFullScreen ? Math.Min((int)SystemParameters.PrimaryScreenWidth / BitmapWidth, (int)SystemParameters.PrimaryScreenHeight / BitmapHeight) :
Math.Min((int)SystemParameters.FullPrimaryScreenWidth / BitmapWidth, (int)SystemParameters.FullPrimaryScreenHeight / BitmapHeight);
_image.Width = uniformScale * BitmapWidth;
_image.Height = uniformScale * BitmapHeight;
}
private const int BitmapWidth = 560;
private const int BitmapHeight = 384;
private const int BitmapDpi = 96;
private static readonly PixelFormat BitmapPixelFormat = PixelFormats.Bgr32;
private static readonly int BitmapStride = (BitmapWidth * BitmapPixelFormat.BitsPerPixel + 7) / 8;
private static readonly Int32Rect BitmapRect = new Int32Rect(0, 0, BitmapWidth, BitmapHeight);
private Window _window;
private Image _image;
private WriteableBitmap _bitmap = new WriteableBitmap(BitmapWidth, BitmapHeight, BitmapDpi, BitmapDpi, BitmapPixelFormat, null);
private uint[] _pixels = new uint[BitmapWidth * BitmapHeight];
private bool _pixelsDirty;
private bool _isFullScreen;
}
}
using System;
using System.Diagnostics.CodeAnalysis;
using System.Security.Permissions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Microsoft.Win32;
namespace Jellyfish.Virtu.Services
{
public sealed class WpfVideoService : VideoService
{
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
public WpfVideoService(Machine machine, Window window, Image image) :
base(machine)
{
if (window == null)
{
throw new ArgumentNullException("window");
}
if (image == null)
{
throw new ArgumentNullException("image");
}
_window = window;
_image = image;
_image.Source = _bitmap;
SetImageSize();
SystemEvents.DisplaySettingsChanged += (sender, e) => SetImageSize();
}
[SuppressMessage("Microsoft.Usage", "CA2233:OperationsShouldNotOverflow", MessageId = "y*560")]
public override void SetPixel(int x, int y, uint color)
{
_pixels[y * BitmapWidth + x] = color;
_pixelsDirty = true;
}
public override void Update() // main thread
{
if (_window.IsActive && (_isFullScreen != IsFullScreen))
{
if (IsFullScreen)
{
_window.SizeToContent = SizeToContent.Manual;
_window.Topmost = true;
_window.WindowStyle = WindowStyle.None;
_window.WindowState = WindowState.Maximized;
}
else
{
_window.WindowState = WindowState.Normal;
_window.WindowStyle = WindowStyle.SingleBorderWindow;
_window.Topmost = false;
_window.SizeToContent = SizeToContent.WidthAndHeight;
}
_isFullScreen = IsFullScreen;
SetImageSize();
}
if (_pixelsDirty)
{
_pixelsDirty = false;
_bitmap.WritePixels(BitmapRect, _pixels, BitmapStride, 0);
}
}
private void SetImageSize()
{
int uniformScale = IsFullScreen ? Math.Min((int)SystemParameters.PrimaryScreenWidth / BitmapWidth, (int)SystemParameters.PrimaryScreenHeight / BitmapHeight) :
Math.Min((int)SystemParameters.FullPrimaryScreenWidth / BitmapWidth, (int)SystemParameters.FullPrimaryScreenHeight / BitmapHeight);
_image.Width = uniformScale * BitmapWidth;
_image.Height = uniformScale * BitmapHeight;
}
private const int BitmapWidth = 560;
private const int BitmapHeight = 384;
private const int BitmapDpi = 96;
private static readonly PixelFormat BitmapPixelFormat = PixelFormats.Bgr32;
private static readonly int BitmapStride = (BitmapWidth * BitmapPixelFormat.BitsPerPixel + 7) / 8;
private static readonly Int32Rect BitmapRect = new Int32Rect(0, 0, BitmapWidth, BitmapHeight);
private Window _window;
private Image _image;
private WriteableBitmap _bitmap = new WriteableBitmap(BitmapWidth, BitmapHeight, BitmapDpi, BitmapDpi, BitmapPixelFormat, null);
private uint[] _pixels = new uint[BitmapWidth * BitmapHeight];
private bool _pixelsDirty;
private bool _isFullScreen;
}
}

View File

@ -1,13 +1,13 @@
namespace Jellyfish.Virtu
{
static class MainApp
{
static void Main()
{
using (MainGame game = new MainGame())
{
game.Run();
}
}
}
}
namespace Jellyfish.Virtu
{
static class MainApp
{
static void Main()
{
using (var game = new MainGame())
{
game.Run();
}
}
}
}

View File

@ -1,81 +1,81 @@
using Jellyfish.Library;
using Jellyfish.Virtu.Services;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Jellyfish.Virtu
{
public sealed class MainGame : GameBase
{
public MainGame() :
base("Virtu")
{
Components.Add(new FrameRateCounter(this) { DrawOrder = 1, FontName = "Consolas" });
_storageService = new XnaStorageService(_machine, this);
_keyboardService = new XnaKeyboardService(_machine);
_gamePortService = new XnaGamePortService(_machine);
#if XBOX
_audioService = new AudioService(_machine); // not connected
#else
_audioService = new XnaAudioService(_machine, this);
#endif
_videoService = new XnaVideoService(_machine, this);
_machine.Services.AddService(typeof(StorageService), _storageService);
_machine.Services.AddService(typeof(KeyboardService), _keyboardService);
_machine.Services.AddService(typeof(GamePortService), _gamePortService);
_machine.Services.AddService(typeof(AudioService), _audioService);
_machine.Services.AddService(typeof(VideoService), _videoService);
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
_machine.Dispose();
_storageService.Dispose();
_keyboardService.Dispose();
_gamePortService.Dispose();
_audioService.Dispose();
_videoService.Dispose();
}
base.Dispose(disposing);
}
protected override void BeginRun()
{
_machine.Start();
}
protected override void Update(GameTime gameTime)
{
_keyboardService.Update();
_gamePortService.Update();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
_videoService.Update();
base.Draw(gameTime);
}
protected override void EndRun()
{
_machine.Stop();
}
private Machine _machine = new Machine();
private StorageService _storageService;
private KeyboardService _keyboardService;
private GamePortService _gamePortService;
private AudioService _audioService;
private VideoService _videoService;
}
}
using Jellyfish.Library;
using Jellyfish.Virtu.Services;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Jellyfish.Virtu
{
public sealed class MainGame : GameBase
{
public MainGame() :
base("Virtu")
{
Components.Add(new FrameRateCounter(this) { DrawOrder = 1, FontName = "Consolas" });
_storageService = new XnaStorageService(_machine, this);
_keyboardService = new XnaKeyboardService(_machine);
_gamePortService = new XnaGamePortService(_machine);
#if XBOX
_audioService = new AudioService(_machine); // not connected
#else
_audioService = new XnaAudioService(_machine, this);
#endif
_videoService = new XnaVideoService(_machine, this);
_machine.Services.AddService(typeof(StorageService), _storageService);
_machine.Services.AddService(typeof(KeyboardService), _keyboardService);
_machine.Services.AddService(typeof(GamePortService), _gamePortService);
_machine.Services.AddService(typeof(AudioService), _audioService);
_machine.Services.AddService(typeof(VideoService), _videoService);
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
_machine.Dispose();
_storageService.Dispose();
_keyboardService.Dispose();
_gamePortService.Dispose();
_audioService.Dispose();
_videoService.Dispose();
}
base.Dispose(disposing);
}
protected override void BeginRun()
{
_machine.Start();
}
protected override void Update(GameTime gameTime)
{
_keyboardService.Update();
_gamePortService.Update();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
_videoService.Update();
base.Draw(gameTime);
}
protected override void EndRun()
{
_machine.Stop();
}
private Machine _machine = new Machine();
private StorageService _storageService;
private KeyboardService _keyboardService;
private GamePortService _gamePortService;
private AudioService _audioService;
private VideoService _videoService;
}
}

View File

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

View File

@ -32,10 +32,7 @@ namespace Jellyfish.Virtu.Services
private void OnDirectSoundUpdate(object sender, DirectSoundUpdateEventArgs e) // audio thread
{
Update(e.BufferSize, (source, count) =>
{
Marshal.Copy(source, 0, e.Buffer, count);
});
Update(e.BufferSize, (source, count) => Marshal.Copy(source, 0, e.Buffer, count));
}
private GameBase _game;

View File

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

View File

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

View File

@ -1,63 +1,63 @@
using System;
using System.IO;
using Jellyfish.Library;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Storage;
namespace Jellyfish.Virtu.Services
{
public sealed class XnaStorageService : StorageService
{
public XnaStorageService(Machine machine, GameBase game) :
base(machine)
{
if (game == null)
{
throw new ArgumentNullException("game");
}
_game = game;
}
public override void Load(string path, Action<Stream> reader)
{
if (reader == null)
{
throw new ArgumentNullException("reader");
}
try
{
using (StorageContainer storageContainer = _storageDevice.Value.OpenContainer(_game.Name))
{
using (FileStream stream = new FileStream(Path.Combine(storageContainer.Path, path), FileMode.Open, FileAccess.Read, FileShare.Read))
{
reader(stream);
}
}
}
catch (FileNotFoundException)
{
}
}
public override void Save(string path, Action<Stream> writer)
{
if (writer == null)
{
throw new ArgumentNullException("writer");
}
using (StorageContainer storageContainer = _storageDevice.Value.OpenContainer(_game.Name))
{
using (FileStream stream = new FileStream(Path.Combine(storageContainer.Path, path), FileMode.Create, FileAccess.Write, FileShare.None))
{
writer(stream);
}
}
}
private GameBase _game;
private Lazy<StorageDevice> _storageDevice = new Lazy<StorageDevice>(() => Guide.EndShowStorageDeviceSelector(Guide.BeginShowStorageDeviceSelector(null, null)));
}
}
using System;
using System.IO;
using Jellyfish.Library;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Storage;
namespace Jellyfish.Virtu.Services
{
public sealed class XnaStorageService : StorageService
{
public XnaStorageService(Machine machine, GameBase game) :
base(machine)
{
if (game == null)
{
throw new ArgumentNullException("game");
}
_game = game;
}
public override void Load(string path, Action<Stream> reader)
{
if (reader == null)
{
throw new ArgumentNullException("reader");
}
try
{
using (var storageContainer = _storageDevice.Value.OpenContainer(_game.Name))
{
using (var stream = new FileStream(Path.Combine(storageContainer.Path, path), FileMode.Open, FileAccess.Read, FileShare.Read))
{
reader(stream);
}
}
}
catch (FileNotFoundException)
{
}
}
public override void Save(string path, Action<Stream> writer)
{
if (writer == null)
{
throw new ArgumentNullException("writer");
}
using (var storageContainer = _storageDevice.Value.OpenContainer(_game.Name))
{
using (var stream = new FileStream(Path.Combine(storageContainer.Path, path), FileMode.Create, FileAccess.Write, FileShare.None))
{
writer(stream);
}
}
}
private GameBase _game;
private Lazy<StorageDevice> _storageDevice = new Lazy<StorageDevice>(() => Guide.EndShowStorageDeviceSelector(Guide.BeginShowStorageDeviceSelector(null, null)));
}
}

View File

@ -1,117 +1,117 @@
using System;
using System.Diagnostics.CodeAnalysis;
#if WINDOWS
using System.Windows;
#endif
using Jellyfish.Library;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Jellyfish.Virtu.Services
{
public sealed class XnaVideoService : VideoService
{
public XnaVideoService(Machine machine, GameBase game) :
base(machine)
{
if (game == null)
{
throw new ArgumentNullException("game");
}
_game = game;
_game.GraphicsDeviceManager.PreparingDeviceSettings += OnGraphicsDeviceManagerPreparingDeviceSettings;
_game.GraphicsDeviceService.DeviceCreated += OnGraphicsDeviceServiceDeviceCreated;
_game.GraphicsDeviceService.DeviceReset += (sender, e) => SetTexturePosition();
}
[SuppressMessage("Microsoft.Usage", "CA2233:OperationsShouldNotOverflow", MessageId = "y*560")]
public override void SetPixel(int x, int y, uint color)
{
_pixels[y * TextureWidth + x] = color;
_pixelsDirty = true;
}
public override void Update() // main thread
{
#if WINDOWS
if (_game.GraphicsDeviceManager.IsFullScreen != IsFullScreen)
{
_game.GraphicsDeviceManager.ToggleFullScreen();
}
#endif
if (_pixelsDirty)
{
_pixelsDirty = false;
_texture.SetData(_pixels);
}
_spriteBatch.Begin(SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.None);
_graphicsDevice.SamplerStates[0].MagFilter = TextureFilter.Point;
_spriteBatch.Draw(_texture, _texturePosition, null, Color.White, 0, Vector2.Zero, _textureScale, SpriteEffects.None, 0);
_spriteBatch.End();
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
_spriteBatch.Dispose();
_texture.Dispose();
}
}
private void OnGraphicsDeviceManagerPreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e)
{
DisplayMode displayMode = e.GraphicsDeviceInformation.Adapter.CurrentDisplayMode;
PresentationParameters presentationParameters = e.GraphicsDeviceInformation.PresentationParameters;
#if WINDOWS
if (presentationParameters.IsFullScreen)
{
_textureScale = Math.Min((int)SystemParameters.PrimaryScreenWidth / TextureWidth, (int)SystemParameters.PrimaryScreenHeight / TextureHeight);
presentationParameters.BackBufferWidth = displayMode.Width; // avoids changing display mode
presentationParameters.BackBufferHeight = displayMode.Height;
}
else
{
_textureScale = Math.Min((int)SystemParameters.FullPrimaryScreenWidth / TextureWidth, (int)SystemParameters.FullPrimaryScreenHeight / TextureHeight);
presentationParameters.BackBufferWidth = _textureScale * TextureWidth;
presentationParameters.BackBufferHeight = _textureScale * TextureHeight;
}
#else
_textureScale = Math.Min(displayMode.TitleSafeArea.Width / TextureWidth, displayMode.TitleSafeArea.Height / TextureHeight);
presentationParameters.BackBufferWidth = displayMode.Width; // always use display mode
presentationParameters.BackBufferHeight = displayMode.Height;
#endif
}
private void OnGraphicsDeviceServiceDeviceCreated(object sender, EventArgs e)
{
_graphicsDevice = _game.GraphicsDevice;
_spriteBatch = new SpriteBatch(_graphicsDevice);
_texture = new Texture2D(_graphicsDevice, TextureWidth, TextureHeight, 1, TextureUsage.None, SurfaceFormat.Bgr32);
_pixels = new uint[TextureWidth * TextureHeight];
SetTexturePosition();
}
private void SetTexturePosition()
{
_texturePosition.X = (_graphicsDevice.PresentationParameters.BackBufferWidth - TextureWidth * _textureScale) / 2; // centered
_texturePosition.Y = (_graphicsDevice.PresentationParameters.BackBufferHeight - TextureHeight * _textureScale) / 2;
}
private const int TextureWidth = 560;
private const int TextureHeight = 384;
private GameBase _game;
private GraphicsDevice _graphicsDevice;
private SpriteBatch _spriteBatch;
private Texture2D _texture;
private Vector2 _texturePosition;
private int _textureScale;
private uint[] _pixels;
private bool _pixelsDirty;
}
}
using System;
using System.Diagnostics.CodeAnalysis;
#if WINDOWS
using System.Windows;
#endif
using Jellyfish.Library;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Jellyfish.Virtu.Services
{
public sealed class XnaVideoService : VideoService
{
public XnaVideoService(Machine machine, GameBase game) :
base(machine)
{
if (game == null)
{
throw new ArgumentNullException("game");
}
_game = game;
_game.GraphicsDeviceManager.PreparingDeviceSettings += OnGraphicsDeviceManagerPreparingDeviceSettings;
_game.GraphicsDeviceService.DeviceCreated += OnGraphicsDeviceServiceDeviceCreated;
_game.GraphicsDeviceService.DeviceReset += (sender, e) => SetTexturePosition();
}
[SuppressMessage("Microsoft.Usage", "CA2233:OperationsShouldNotOverflow", MessageId = "y*560")]
public override void SetPixel(int x, int y, uint color)
{
_pixels[y * TextureWidth + x] = color;
_pixelsDirty = true;
}
public override void Update() // main thread
{
#if WINDOWS
if (_game.GraphicsDeviceManager.IsFullScreen != IsFullScreen)
{
_game.GraphicsDeviceManager.ToggleFullScreen();
}
#endif
if (_pixelsDirty)
{
_pixelsDirty = false;
_texture.SetData(_pixels);
}
_spriteBatch.Begin(SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.None);
_graphicsDevice.SamplerStates[0].MagFilter = TextureFilter.Point;
_spriteBatch.Draw(_texture, _texturePosition, null, Color.White, 0, Vector2.Zero, _textureScale, SpriteEffects.None, 0);
_spriteBatch.End();
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
_spriteBatch.Dispose();
_texture.Dispose();
}
}
private void OnGraphicsDeviceManagerPreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e)
{
var displayMode = e.GraphicsDeviceInformation.Adapter.CurrentDisplayMode;
var presentationParameters = e.GraphicsDeviceInformation.PresentationParameters;
#if WINDOWS
if (presentationParameters.IsFullScreen)
{
_textureScale = Math.Min((int)SystemParameters.PrimaryScreenWidth / TextureWidth, (int)SystemParameters.PrimaryScreenHeight / TextureHeight);
presentationParameters.BackBufferWidth = displayMode.Width; // avoids changing display mode
presentationParameters.BackBufferHeight = displayMode.Height;
}
else
{
_textureScale = Math.Min((int)SystemParameters.FullPrimaryScreenWidth / TextureWidth, (int)SystemParameters.FullPrimaryScreenHeight / TextureHeight);
presentationParameters.BackBufferWidth = _textureScale * TextureWidth;
presentationParameters.BackBufferHeight = _textureScale * TextureHeight;
}
#else
_textureScale = Math.Min(displayMode.TitleSafeArea.Width / TextureWidth, displayMode.TitleSafeArea.Height / TextureHeight);
presentationParameters.BackBufferWidth = displayMode.Width; // always use display mode
presentationParameters.BackBufferHeight = displayMode.Height;
#endif
}
private void OnGraphicsDeviceServiceDeviceCreated(object sender, EventArgs e)
{
_graphicsDevice = _game.GraphicsDevice;
_spriteBatch = new SpriteBatch(_graphicsDevice);
_texture = new Texture2D(_graphicsDevice, TextureWidth, TextureHeight, 1, TextureUsage.None, SurfaceFormat.Bgr32);
_pixels = new uint[TextureWidth * TextureHeight];
SetTexturePosition();
}
private void SetTexturePosition()
{
_texturePosition.X = (_graphicsDevice.PresentationParameters.BackBufferWidth - TextureWidth * _textureScale) / 2; // centered
_texturePosition.Y = (_graphicsDevice.PresentationParameters.BackBufferHeight - TextureHeight * _textureScale) / 2;
}
private const int TextureWidth = 560;
private const int TextureHeight = 384;
private GameBase _game;
private GraphicsDevice _graphicsDevice;
private SpriteBatch _spriteBatch;
private Texture2D _texture;
private Vector2 _texturePosition;
private int _textureScale;
private uint[] _pixels;
private bool _pixelsDirty;
}
}