mirror of
https://github.com/digital-jellyfish/Virtu.git
synced 2025-03-22 07:33:53 +00:00
Add git attributes file.
Normalize text files.
This commit is contained in:
parent
6d0c8e7c54
commit
27a5e3ac89
14
.gitattributes
vendored
Normal file
14
.gitattributes
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
||||
|
||||
# Visual Studio
|
||||
*.cs diff=csharp
|
||||
*.sln merge=union
|
||||
*.csproj merge=union
|
||||
|
||||
# Virtu
|
||||
*.do binary
|
||||
*.dsk binary
|
||||
*.nib binary
|
||||
*.po binary
|
||||
*.rom binary
|
12
.gitignore
vendored
12
.gitignore
vendored
@ -1,6 +1,6 @@
|
||||
bin/
|
||||
obj/
|
||||
|
||||
*.cachefile
|
||||
*.suo
|
||||
*.user
|
||||
bin/
|
||||
obj/
|
||||
|
||||
*.cachefile
|
||||
*.suo
|
||||
*.user
|
||||
|
@ -1,17 +1,17 @@
|
||||
using System;
|
||||
|
||||
namespace Jellyfish.Library
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true, Inherited = false)]
|
||||
public sealed class AssemblyMetadataAttribute : Attribute
|
||||
{
|
||||
public AssemblyMetadataAttribute(string key, string value)
|
||||
{
|
||||
Key = key;
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public string Key { get; private set; }
|
||||
public string Value { get; private set; }
|
||||
}
|
||||
}
|
||||
using System;
|
||||
|
||||
namespace Jellyfish.Library
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true, Inherited = false)]
|
||||
public sealed class AssemblyMetadataAttribute : Attribute
|
||||
{
|
||||
public AssemblyMetadataAttribute(string key, string value)
|
||||
{
|
||||
Key = key;
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public string Key { get; private set; }
|
||||
public string Value { get; private set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Dictionary>
|
||||
<Words>
|
||||
<Recognized>
|
||||
<Word>x</Word>
|
||||
<Word>y</Word>
|
||||
</Recognized>
|
||||
</Words>
|
||||
</Dictionary>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Dictionary>
|
||||
<Words>
|
||||
<Recognized>
|
||||
<Word>x</Word>
|
||||
<Word>y</Word>
|
||||
</Recognized>
|
||||
</Words>
|
||||
</Dictionary>
|
||||
|
@ -1,173 +1,173 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Threading;
|
||||
|
||||
namespace Jellyfish.Library
|
||||
{
|
||||
public sealed partial class DirectSound : IDisposable
|
||||
{
|
||||
[SecurityCritical]
|
||||
public DirectSound(int sampleRate, int sampleChannels, int sampleBits, int sampleSize, Action<IntPtr, int> updater)
|
||||
{
|
||||
_sampleRate = sampleRate;
|
||||
_sampleChannels = sampleChannels;
|
||||
_sampleBits = sampleBits;
|
||||
_sampleSize = sampleSize;
|
||||
|
||||
_thread = new Thread(Run) { Name = "DirectSound" };
|
||||
_updater = updater;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_position1Event.Close();
|
||||
_position2Event.Close();
|
||||
_stopEvent.Close();
|
||||
}
|
||||
|
||||
public void SetVolume(float volume)
|
||||
{
|
||||
int attenuation = (volume < 0.01) ? (int)BufferVolume.Min : (int)Math.Floor(100 * 20 * Math.Log10(volume)); // 100 db
|
||||
lock (_bufferLock)
|
||||
{
|
||||
if (_buffer != null)
|
||||
{
|
||||
_buffer.SetVolume(attenuation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Start(IntPtr window)
|
||||
{
|
||||
_window = window;
|
||||
_thread.Start();
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
_stopEvent.Set();
|
||||
_thread.Join();
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
private void Initialize()
|
||||
{
|
||||
int hresult = NativeMethods.DirectSoundCreate(IntPtr.Zero, out _device, IntPtr.Zero);
|
||||
if (hresult < 0)
|
||||
{
|
||||
Marshal.ThrowExceptionForHR(hresult);
|
||||
}
|
||||
|
||||
_device.SetCooperativeLevel(_window, CooperativeLevel.Normal);
|
||||
|
||||
GCHandleHelpers.Pin(new WaveFormat(_sampleRate, _sampleChannels, _sampleBits), waveFormat =>
|
||||
{
|
||||
var description = new BufferDescription(BufferCapabilities.CtrlPositionNotify | BufferCapabilities.CtrlVolume, BlockCount * _sampleSize, waveFormat);
|
||||
_device.CreateSoundBuffer(description, out _buffer, IntPtr.Zero);
|
||||
});
|
||||
ClearBuffer();
|
||||
|
||||
var positionEvents = new BufferPositionNotify[BlockCount]
|
||||
{
|
||||
new BufferPositionNotify(0 * _sampleSize, _position1Event), new BufferPositionNotify(1 * _sampleSize, _position2Event)
|
||||
};
|
||||
((IDirectSoundNotify)_buffer).SetNotificationPositions(positionEvents.Length, positionEvents);
|
||||
|
||||
_buffer.Play(0, 0, BufferPlay.Looping);
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
private void ClearBuffer()
|
||||
{
|
||||
UpdateBuffer(0, 0, BufferLock.EntireBuffer, (buffer, bufferSize) => MarshalHelpers.ZeroMemory(buffer, bufferSize));
|
||||
}
|
||||
|
||||
private void RestoreBuffer()
|
||||
{
|
||||
BufferStatus status;
|
||||
_buffer.GetStatus(out status);
|
||||
if ((status & BufferStatus.BufferLost) != 0)
|
||||
{
|
||||
_buffer.Restore();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateBuffer(int offset, int count, BufferLock flags, Action<IntPtr, int> updater)
|
||||
{
|
||||
RestoreBuffer();
|
||||
|
||||
IntPtr buffer1, buffer2;
|
||||
int buffer1Size, buffer2Size;
|
||||
_buffer.Lock(offset, count, out buffer1, out buffer1Size, out buffer2, out buffer2Size, flags);
|
||||
try
|
||||
{
|
||||
if (buffer1 != IntPtr.Zero)
|
||||
{
|
||||
updater(buffer1, buffer1Size);
|
||||
}
|
||||
if (buffer2 != IntPtr.Zero)
|
||||
{
|
||||
updater(buffer2, buffer2Size);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_buffer.Unlock(buffer1, buffer1Size, buffer2, buffer2Size);
|
||||
}
|
||||
}
|
||||
|
||||
private void Uninitialize()
|
||||
{
|
||||
lock (_bufferLock)
|
||||
{
|
||||
if (_buffer != null)
|
||||
{
|
||||
_buffer.Stop();
|
||||
Marshal.ReleaseComObject(_buffer);
|
||||
_buffer = null;
|
||||
}
|
||||
}
|
||||
if (_device != null)
|
||||
{
|
||||
Marshal.ReleaseComObject(_device);
|
||||
_device = null;
|
||||
}
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
private void Run() // com mta thread
|
||||
{
|
||||
Initialize();
|
||||
|
||||
var eventHandles = new EventWaitHandle[] { _position1Event, _position2Event, _stopEvent };
|
||||
int index = WaitHandle.WaitAny(eventHandles);
|
||||
|
||||
while (index < BlockCount)
|
||||
{
|
||||
UpdateBuffer(((index + 1) % BlockCount) * _sampleSize, _sampleSize, BufferLock.None, _updater); // update next block in circular buffer
|
||||
index = WaitHandle.WaitAny(eventHandles);
|
||||
}
|
||||
|
||||
Uninitialize();
|
||||
}
|
||||
|
||||
private const int BlockCount = 2;
|
||||
|
||||
private int _sampleRate;
|
||||
private int _sampleChannels;
|
||||
private int _sampleBits;
|
||||
private int _sampleSize;
|
||||
|
||||
private Thread _thread;
|
||||
private IntPtr _window;
|
||||
private IDirectSound _device;
|
||||
private IDirectSoundBuffer _buffer;
|
||||
private readonly object _bufferLock = new object();
|
||||
private Action<IntPtr, int> _updater;
|
||||
|
||||
private AutoResetEvent _position1Event = new AutoResetEvent(false);
|
||||
private AutoResetEvent _position2Event = new AutoResetEvent(false);
|
||||
private ManualResetEvent _stopEvent = new ManualResetEvent(false);
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Threading;
|
||||
|
||||
namespace Jellyfish.Library
|
||||
{
|
||||
public sealed partial class DirectSound : IDisposable
|
||||
{
|
||||
[SecurityCritical]
|
||||
public DirectSound(int sampleRate, int sampleChannels, int sampleBits, int sampleSize, Action<IntPtr, int> updater)
|
||||
{
|
||||
_sampleRate = sampleRate;
|
||||
_sampleChannels = sampleChannels;
|
||||
_sampleBits = sampleBits;
|
||||
_sampleSize = sampleSize;
|
||||
|
||||
_thread = new Thread(Run) { Name = "DirectSound" };
|
||||
_updater = updater;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_position1Event.Close();
|
||||
_position2Event.Close();
|
||||
_stopEvent.Close();
|
||||
}
|
||||
|
||||
public void SetVolume(float volume)
|
||||
{
|
||||
int attenuation = (volume < 0.01) ? (int)BufferVolume.Min : (int)Math.Floor(100 * 20 * Math.Log10(volume)); // 100 db
|
||||
lock (_bufferLock)
|
||||
{
|
||||
if (_buffer != null)
|
||||
{
|
||||
_buffer.SetVolume(attenuation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Start(IntPtr window)
|
||||
{
|
||||
_window = window;
|
||||
_thread.Start();
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
_stopEvent.Set();
|
||||
_thread.Join();
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
private void Initialize()
|
||||
{
|
||||
int hresult = NativeMethods.DirectSoundCreate(IntPtr.Zero, out _device, IntPtr.Zero);
|
||||
if (hresult < 0)
|
||||
{
|
||||
Marshal.ThrowExceptionForHR(hresult);
|
||||
}
|
||||
|
||||
_device.SetCooperativeLevel(_window, CooperativeLevel.Normal);
|
||||
|
||||
GCHandleHelpers.Pin(new WaveFormat(_sampleRate, _sampleChannels, _sampleBits), waveFormat =>
|
||||
{
|
||||
var description = new BufferDescription(BufferCapabilities.CtrlPositionNotify | BufferCapabilities.CtrlVolume, BlockCount * _sampleSize, waveFormat);
|
||||
_device.CreateSoundBuffer(description, out _buffer, IntPtr.Zero);
|
||||
});
|
||||
ClearBuffer();
|
||||
|
||||
var positionEvents = new BufferPositionNotify[BlockCount]
|
||||
{
|
||||
new BufferPositionNotify(0 * _sampleSize, _position1Event), new BufferPositionNotify(1 * _sampleSize, _position2Event)
|
||||
};
|
||||
((IDirectSoundNotify)_buffer).SetNotificationPositions(positionEvents.Length, positionEvents);
|
||||
|
||||
_buffer.Play(0, 0, BufferPlay.Looping);
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
private void ClearBuffer()
|
||||
{
|
||||
UpdateBuffer(0, 0, BufferLock.EntireBuffer, (buffer, bufferSize) => MarshalHelpers.ZeroMemory(buffer, bufferSize));
|
||||
}
|
||||
|
||||
private void RestoreBuffer()
|
||||
{
|
||||
BufferStatus status;
|
||||
_buffer.GetStatus(out status);
|
||||
if ((status & BufferStatus.BufferLost) != 0)
|
||||
{
|
||||
_buffer.Restore();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateBuffer(int offset, int count, BufferLock flags, Action<IntPtr, int> updater)
|
||||
{
|
||||
RestoreBuffer();
|
||||
|
||||
IntPtr buffer1, buffer2;
|
||||
int buffer1Size, buffer2Size;
|
||||
_buffer.Lock(offset, count, out buffer1, out buffer1Size, out buffer2, out buffer2Size, flags);
|
||||
try
|
||||
{
|
||||
if (buffer1 != IntPtr.Zero)
|
||||
{
|
||||
updater(buffer1, buffer1Size);
|
||||
}
|
||||
if (buffer2 != IntPtr.Zero)
|
||||
{
|
||||
updater(buffer2, buffer2Size);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_buffer.Unlock(buffer1, buffer1Size, buffer2, buffer2Size);
|
||||
}
|
||||
}
|
||||
|
||||
private void Uninitialize()
|
||||
{
|
||||
lock (_bufferLock)
|
||||
{
|
||||
if (_buffer != null)
|
||||
{
|
||||
_buffer.Stop();
|
||||
Marshal.ReleaseComObject(_buffer);
|
||||
_buffer = null;
|
||||
}
|
||||
}
|
||||
if (_device != null)
|
||||
{
|
||||
Marshal.ReleaseComObject(_device);
|
||||
_device = null;
|
||||
}
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
private void Run() // com mta thread
|
||||
{
|
||||
Initialize();
|
||||
|
||||
var eventHandles = new EventWaitHandle[] { _position1Event, _position2Event, _stopEvent };
|
||||
int index = WaitHandle.WaitAny(eventHandles);
|
||||
|
||||
while (index < BlockCount)
|
||||
{
|
||||
UpdateBuffer(((index + 1) % BlockCount) * _sampleSize, _sampleSize, BufferLock.None, _updater); // update next block in circular buffer
|
||||
index = WaitHandle.WaitAny(eventHandles);
|
||||
}
|
||||
|
||||
Uninitialize();
|
||||
}
|
||||
|
||||
private const int BlockCount = 2;
|
||||
|
||||
private int _sampleRate;
|
||||
private int _sampleChannels;
|
||||
private int _sampleBits;
|
||||
private int _sampleSize;
|
||||
|
||||
private Thread _thread;
|
||||
private IntPtr _window;
|
||||
private IDirectSound _device;
|
||||
private IDirectSoundBuffer _buffer;
|
||||
private readonly object _bufferLock = new object();
|
||||
private Action<IntPtr, int> _updater;
|
||||
|
||||
private AutoResetEvent _position1Event = new AutoResetEvent(false);
|
||||
private AutoResetEvent _position2Event = new AutoResetEvent(false);
|
||||
private ManualResetEvent _stopEvent = new ManualResetEvent(false);
|
||||
}
|
||||
}
|
||||
|
@ -1,110 +1,110 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Threading;
|
||||
|
||||
namespace Jellyfish.Library
|
||||
{
|
||||
public sealed partial class DirectSound
|
||||
{
|
||||
[Flags]
|
||||
private enum BufferCapabilities { PrimaryBuffer = 0x00000001, CtrlVolume = 0x00000080, CtrlPositionNotify = 0x00000100, StickyFocus = 0x00004000, GlobalFocus = 0x00008000 }
|
||||
|
||||
[Flags]
|
||||
private enum BufferLock { None = 0x00000000, FromWriteCursor = 0x00000001, EntireBuffer = 0x00000002 }
|
||||
|
||||
[Flags]
|
||||
private enum BufferPlay { Looping = 0x00000001 }
|
||||
|
||||
[Flags]
|
||||
private enum BufferStatus { Playing = 0x00000001, BufferLost = 0x00000002, Looping = 0x00000004, Terminated = 0x00000020 }
|
||||
|
||||
private enum BufferVolume { Min = -10000, Max = 0 }
|
||||
|
||||
private enum CooperativeLevel { Normal = 1, Priority = 2 }
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private sealed class BufferDescription
|
||||
{
|
||||
public BufferDescription(BufferCapabilities capabilities, int size, IntPtr format)
|
||||
{
|
||||
dwSize = Marshal.SizeOf(typeof(BufferDescription));
|
||||
dwFlags = capabilities;
|
||||
dwBufferBytes = size;
|
||||
lpwfxFormat = format;
|
||||
}
|
||||
|
||||
public int dwSize;
|
||||
public BufferCapabilities dwFlags;
|
||||
public int dwBufferBytes;
|
||||
public int dwReserved;
|
||||
public IntPtr lpwfxFormat;
|
||||
public Guid guid3DAlgorithm;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private struct BufferPositionNotify
|
||||
{
|
||||
[SuppressMessage("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods", MessageId = "System.Runtime.InteropServices.SafeHandle.DangerousGetHandle")]
|
||||
public BufferPositionNotify(int offset, EventWaitHandle notifyEvent)
|
||||
{
|
||||
dwOffset = offset;
|
||||
hEventNotify = notifyEvent.SafeWaitHandle.DangerousGetHandle();
|
||||
}
|
||||
|
||||
public int dwOffset;
|
||||
public IntPtr hEventNotify;
|
||||
}
|
||||
|
||||
[ComImport, Guid("279AFA83-4981-11CE-A521-0020AF0BE560"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
private interface IDirectSound
|
||||
{
|
||||
void CreateSoundBuffer(BufferDescription pcDSBufferDesc, [MarshalAs(UnmanagedType.Interface)] out IDirectSoundBuffer pDSBuffer, IntPtr pUnkOuter);
|
||||
void GetCaps(IntPtr pDSCaps);
|
||||
void DuplicateSoundBuffer([MarshalAs(UnmanagedType.Interface)] IDirectSoundBuffer pDSBufferOriginal, [MarshalAs(UnmanagedType.Interface)] out IDirectSoundBuffer pDSBufferDuplicate);
|
||||
void SetCooperativeLevel(IntPtr hwnd, CooperativeLevel dwLevel);
|
||||
void Compact();
|
||||
void GetSpeakerConfig(out int dwSpeakerConfig);
|
||||
void SetSpeakerConfig(int dwSpeakerConfig);
|
||||
void Initialize([MarshalAs(UnmanagedType.LPStruct)] Guid pcGuidDevice);
|
||||
}
|
||||
|
||||
[ComImport, Guid("279AFA85-4981-11CE-A521-0020AF0BE560"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
private interface IDirectSoundBuffer
|
||||
{
|
||||
void GetCaps(IntPtr pDSBufferCaps);
|
||||
void GetCurrentPosition(out int dwCurrentPlayCursor, out int dwCurrentWriteCursor);
|
||||
void GetFormat(IntPtr pwfxFormat, int dwSizeAllocated, out int dwSizeWritten);
|
||||
void GetVolume(out int lVolume);
|
||||
void GetPan(out int lPan);
|
||||
void GetFrequency(out int dwFrequency);
|
||||
void GetStatus(out BufferStatus dwStatus);
|
||||
void Initialize([MarshalAs(UnmanagedType.Interface)] IDirectSound pDirectSound, BufferDescription pcDSBufferDesc);
|
||||
void Lock(int dwOffset, int dwBytes, out IntPtr pvAudioPtr1, out int dwAudioBytes1, out IntPtr pvAudioPtr2, out int dwAudioBytes2, BufferLock dwFlags);
|
||||
void Play(int dwReserved1, int dwPriority, BufferPlay dwFlags);
|
||||
void SetCurrentPosition(int dwNewPosition);
|
||||
void SetFormat(WaveFormat pcfxFormat);
|
||||
void SetVolume(int lVolume);
|
||||
void SetPan(int lPan);
|
||||
void SetFrequency(int dwFrequency);
|
||||
void Stop();
|
||||
void Unlock(IntPtr pvAudioPtr1, int dwAudioBytes1, IntPtr pvAudioPtr2, int dwAudioBytes2);
|
||||
void Restore();
|
||||
}
|
||||
|
||||
[ComImport, Guid("B0210783-89CD-11D0-AF08-00A0C925CD16"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
private interface IDirectSoundNotify
|
||||
{
|
||||
void SetNotificationPositions(int dwPositionNotifies, [MarshalAs(UnmanagedType.LPArray)] BufferPositionNotify[] pcPositionNotifies);
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
private static class NativeMethods
|
||||
{
|
||||
[DllImport("dsound.dll")]
|
||||
public static extern int DirectSoundCreate(IntPtr pcGuidDevice, [MarshalAs(UnmanagedType.Interface)] out IDirectSound pDS, IntPtr pUnkOuter);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Threading;
|
||||
|
||||
namespace Jellyfish.Library
|
||||
{
|
||||
public sealed partial class DirectSound
|
||||
{
|
||||
[Flags]
|
||||
private enum BufferCapabilities { PrimaryBuffer = 0x00000001, CtrlVolume = 0x00000080, CtrlPositionNotify = 0x00000100, StickyFocus = 0x00004000, GlobalFocus = 0x00008000 }
|
||||
|
||||
[Flags]
|
||||
private enum BufferLock { None = 0x00000000, FromWriteCursor = 0x00000001, EntireBuffer = 0x00000002 }
|
||||
|
||||
[Flags]
|
||||
private enum BufferPlay { Looping = 0x00000001 }
|
||||
|
||||
[Flags]
|
||||
private enum BufferStatus { Playing = 0x00000001, BufferLost = 0x00000002, Looping = 0x00000004, Terminated = 0x00000020 }
|
||||
|
||||
private enum BufferVolume { Min = -10000, Max = 0 }
|
||||
|
||||
private enum CooperativeLevel { Normal = 1, Priority = 2 }
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private sealed class BufferDescription
|
||||
{
|
||||
public BufferDescription(BufferCapabilities capabilities, int size, IntPtr format)
|
||||
{
|
||||
dwSize = Marshal.SizeOf(typeof(BufferDescription));
|
||||
dwFlags = capabilities;
|
||||
dwBufferBytes = size;
|
||||
lpwfxFormat = format;
|
||||
}
|
||||
|
||||
public int dwSize;
|
||||
public BufferCapabilities dwFlags;
|
||||
public int dwBufferBytes;
|
||||
public int dwReserved;
|
||||
public IntPtr lpwfxFormat;
|
||||
public Guid guid3DAlgorithm;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private struct BufferPositionNotify
|
||||
{
|
||||
[SuppressMessage("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods", MessageId = "System.Runtime.InteropServices.SafeHandle.DangerousGetHandle")]
|
||||
public BufferPositionNotify(int offset, EventWaitHandle notifyEvent)
|
||||
{
|
||||
dwOffset = offset;
|
||||
hEventNotify = notifyEvent.SafeWaitHandle.DangerousGetHandle();
|
||||
}
|
||||
|
||||
public int dwOffset;
|
||||
public IntPtr hEventNotify;
|
||||
}
|
||||
|
||||
[ComImport, Guid("279AFA83-4981-11CE-A521-0020AF0BE560"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
private interface IDirectSound
|
||||
{
|
||||
void CreateSoundBuffer(BufferDescription pcDSBufferDesc, [MarshalAs(UnmanagedType.Interface)] out IDirectSoundBuffer pDSBuffer, IntPtr pUnkOuter);
|
||||
void GetCaps(IntPtr pDSCaps);
|
||||
void DuplicateSoundBuffer([MarshalAs(UnmanagedType.Interface)] IDirectSoundBuffer pDSBufferOriginal, [MarshalAs(UnmanagedType.Interface)] out IDirectSoundBuffer pDSBufferDuplicate);
|
||||
void SetCooperativeLevel(IntPtr hwnd, CooperativeLevel dwLevel);
|
||||
void Compact();
|
||||
void GetSpeakerConfig(out int dwSpeakerConfig);
|
||||
void SetSpeakerConfig(int dwSpeakerConfig);
|
||||
void Initialize([MarshalAs(UnmanagedType.LPStruct)] Guid pcGuidDevice);
|
||||
}
|
||||
|
||||
[ComImport, Guid("279AFA85-4981-11CE-A521-0020AF0BE560"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
private interface IDirectSoundBuffer
|
||||
{
|
||||
void GetCaps(IntPtr pDSBufferCaps);
|
||||
void GetCurrentPosition(out int dwCurrentPlayCursor, out int dwCurrentWriteCursor);
|
||||
void GetFormat(IntPtr pwfxFormat, int dwSizeAllocated, out int dwSizeWritten);
|
||||
void GetVolume(out int lVolume);
|
||||
void GetPan(out int lPan);
|
||||
void GetFrequency(out int dwFrequency);
|
||||
void GetStatus(out BufferStatus dwStatus);
|
||||
void Initialize([MarshalAs(UnmanagedType.Interface)] IDirectSound pDirectSound, BufferDescription pcDSBufferDesc);
|
||||
void Lock(int dwOffset, int dwBytes, out IntPtr pvAudioPtr1, out int dwAudioBytes1, out IntPtr pvAudioPtr2, out int dwAudioBytes2, BufferLock dwFlags);
|
||||
void Play(int dwReserved1, int dwPriority, BufferPlay dwFlags);
|
||||
void SetCurrentPosition(int dwNewPosition);
|
||||
void SetFormat(WaveFormat pcfxFormat);
|
||||
void SetVolume(int lVolume);
|
||||
void SetPan(int lPan);
|
||||
void SetFrequency(int dwFrequency);
|
||||
void Stop();
|
||||
void Unlock(IntPtr pvAudioPtr1, int dwAudioBytes1, IntPtr pvAudioPtr2, int dwAudioBytes2);
|
||||
void Restore();
|
||||
}
|
||||
|
||||
[ComImport, Guid("B0210783-89CD-11D0-AF08-00A0C925CD16"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
private interface IDirectSoundNotify
|
||||
{
|
||||
void SetNotificationPositions(int dwPositionNotifies, [MarshalAs(UnmanagedType.LPArray)] BufferPositionNotify[] pcPositionNotifies);
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
private static class NativeMethods
|
||||
{
|
||||
[DllImport("dsound.dll")]
|
||||
public static extern int DirectSoundCreate(IntPtr pcGuidDevice, [MarshalAs(UnmanagedType.Interface)] out IDirectSound pDS, IntPtr pUnkOuter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,36 +1,36 @@
|
||||
using System;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace Jellyfish.Library
|
||||
{
|
||||
public static class DispatcherExtensions
|
||||
{
|
||||
public static void Post(this Dispatcher dispatcher, Action action)
|
||||
{
|
||||
if (dispatcher == null)
|
||||
{
|
||||
throw new ArgumentNullException("dispatcher");
|
||||
}
|
||||
if (action == null)
|
||||
{
|
||||
throw new ArgumentNullException("action");
|
||||
}
|
||||
|
||||
new DispatcherSynchronizationContext(dispatcher).Post(state => action(), null);
|
||||
}
|
||||
|
||||
public static void Send(this Dispatcher dispatcher, Action action)
|
||||
{
|
||||
if (dispatcher == null)
|
||||
{
|
||||
throw new ArgumentNullException("dispatcher");
|
||||
}
|
||||
if (action == null)
|
||||
{
|
||||
throw new ArgumentNullException("action");
|
||||
}
|
||||
|
||||
new DispatcherSynchronizationContext(dispatcher).Send(state => action(), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace Jellyfish.Library
|
||||
{
|
||||
public static class DispatcherExtensions
|
||||
{
|
||||
public static void Post(this Dispatcher dispatcher, Action action)
|
||||
{
|
||||
if (dispatcher == null)
|
||||
{
|
||||
throw new ArgumentNullException("dispatcher");
|
||||
}
|
||||
if (action == null)
|
||||
{
|
||||
throw new ArgumentNullException("action");
|
||||
}
|
||||
|
||||
new DispatcherSynchronizationContext(dispatcher).Post(state => action(), null);
|
||||
}
|
||||
|
||||
public static void Send(this Dispatcher dispatcher, Action action)
|
||||
{
|
||||
if (dispatcher == null)
|
||||
{
|
||||
throw new ArgumentNullException("dispatcher");
|
||||
}
|
||||
if (action == null)
|
||||
{
|
||||
throw new ArgumentNullException("action");
|
||||
}
|
||||
|
||||
new DispatcherSynchronizationContext(dispatcher).Send(state => action(), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,26 +1,26 @@
|
||||
using System;
|
||||
|
||||
namespace Jellyfish.Library
|
||||
{
|
||||
public abstract class DisposableBase : IDisposable
|
||||
{
|
||||
protected DisposableBase()
|
||||
{
|
||||
}
|
||||
|
||||
~DisposableBase()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
|
||||
namespace Jellyfish.Library
|
||||
{
|
||||
public abstract class DisposableBase : IDisposable
|
||||
{
|
||||
protected DisposableBase()
|
||||
{
|
||||
}
|
||||
|
||||
~DisposableBase()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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>
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -1,32 +1,32 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace Jellyfish.Library
|
||||
{
|
||||
public static class GCHandleHelpers
|
||||
{
|
||||
[SecurityCritical]
|
||||
public static void Pin(object value, Action<IntPtr> action)
|
||||
{
|
||||
if (action == null)
|
||||
{
|
||||
throw new ArgumentNullException("action");
|
||||
}
|
||||
|
||||
var gcHandle = new GCHandle();
|
||||
try
|
||||
{
|
||||
gcHandle = GCHandle.Alloc(value, GCHandleType.Pinned);
|
||||
action(gcHandle.AddrOfPinnedObject());
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (gcHandle.IsAllocated)
|
||||
{
|
||||
gcHandle.Free();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace Jellyfish.Library
|
||||
{
|
||||
public static class GCHandleHelpers
|
||||
{
|
||||
[SecurityCritical]
|
||||
public static void Pin(object value, Action<IntPtr> action)
|
||||
{
|
||||
if (action == null)
|
||||
{
|
||||
throw new ArgumentNullException("action");
|
||||
}
|
||||
|
||||
var gcHandle = new GCHandle();
|
||||
try
|
||||
{
|
||||
gcHandle = GCHandle.Alloc(value, GCHandleType.Pinned);
|
||||
action(gcHandle.AddrOfPinnedObject());
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (gcHandle.IsAllocated)
|
||||
{
|
||||
gcHandle.Free();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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")]
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,26 +1,26 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfish.Library.Silverlight", "Silverlight\Jellyfish.Library.Silverlight.csproj", "{99CA7796-B72A-4F8C-BCDB-0D688220A331}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfish.Library.Wpf", "Wpf\Jellyfish.Library.Wpf.csproj", "{93900841-7250-4D3A-837E-43EE3FD118DC}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{93900841-7250-4D3A-837E-43EE3FD118DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{93900841-7250-4D3A-837E-43EE3FD118DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{93900841-7250-4D3A-837E-43EE3FD118DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{93900841-7250-4D3A-837E-43EE3FD118DC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{99CA7796-B72A-4F8C-BCDB-0D688220A331}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{99CA7796-B72A-4F8C-BCDB-0D688220A331}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{99CA7796-B72A-4F8C-BCDB-0D688220A331}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{99CA7796-B72A-4F8C-BCDB-0D688220A331}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfish.Library.Silverlight", "Silverlight\Jellyfish.Library.Silverlight.csproj", "{99CA7796-B72A-4F8C-BCDB-0D688220A331}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfish.Library.Wpf", "Wpf\Jellyfish.Library.Wpf.csproj", "{93900841-7250-4D3A-837E-43EE3FD118DC}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{93900841-7250-4D3A-837E-43EE3FD118DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{93900841-7250-4D3A-837E-43EE3FD118DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{93900841-7250-4D3A-837E-43EE3FD118DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{93900841-7250-4D3A-837E-43EE3FD118DC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{99CA7796-B72A-4F8C-BCDB-0D688220A331}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{99CA7796-B72A-4F8C-BCDB-0D688220A331}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{99CA7796-B72A-4F8C-BCDB-0D688220A331}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{99CA7796-B72A-4F8C-BCDB-0D688220A331}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
@ -1,35 +1,35 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace Jellyfish.Library
|
||||
{
|
||||
public static class MarshalHelpers
|
||||
{
|
||||
[SecurityCritical]
|
||||
public static void FillMemory(IntPtr buffer, int bufferSize, byte value)
|
||||
{
|
||||
NativeMethods.FillMemory(buffer, (IntPtr)bufferSize, value);
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
public static void ZeroMemory(IntPtr buffer, int bufferSize)
|
||||
{
|
||||
NativeMethods.ZeroMemory(buffer, (IntPtr)bufferSize);
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
private static class NativeMethods
|
||||
{
|
||||
[SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage")]
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
public static extern void FillMemory(IntPtr destination, IntPtr length, byte fill);
|
||||
|
||||
[SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage")]
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
public static extern void ZeroMemory(IntPtr destination, IntPtr length);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace Jellyfish.Library
|
||||
{
|
||||
public static class MarshalHelpers
|
||||
{
|
||||
[SecurityCritical]
|
||||
public static void FillMemory(IntPtr buffer, int bufferSize, byte value)
|
||||
{
|
||||
NativeMethods.FillMemory(buffer, (IntPtr)bufferSize, value);
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
public static void ZeroMemory(IntPtr buffer, int bufferSize)
|
||||
{
|
||||
NativeMethods.ZeroMemory(buffer, (IntPtr)bufferSize);
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
private static class NativeMethods
|
||||
{
|
||||
[SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage")]
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
public static extern void FillMemory(IntPtr destination, IntPtr length, byte fill);
|
||||
|
||||
[SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage")]
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
public static extern void ZeroMemory(IntPtr destination, IntPtr length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,95 +1,95 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
|
||||
namespace Jellyfish.Library
|
||||
{
|
||||
public abstract class ApplicationBase : Application
|
||||
{
|
||||
protected ApplicationBase() :
|
||||
this(null)
|
||||
{
|
||||
}
|
||||
|
||||
protected ApplicationBase(string name)
|
||||
{
|
||||
Name = name;
|
||||
|
||||
UnhandledException += OnApplicationUnhandledException;
|
||||
//AppDomain.CurrentDomain.UnhandledException += OnAppDomainUnhandledException;
|
||||
|
||||
if (Debugger.IsAttached)
|
||||
{
|
||||
var settings = Application.Current.Host.Settings;
|
||||
settings.EnableFrameRateCounter = true;
|
||||
//settings.EnableRedrawRegions = true;
|
||||
//settings.EnableCacheVisualization = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected void InitializeOutOfBrowserUpdate()
|
||||
{
|
||||
if (IsRunningOutOfBrowser)
|
||||
{
|
||||
CheckAndDownloadUpdateCompleted += OnApplicationCheckAndDownloadUpdateCompleted;
|
||||
CheckAndDownloadUpdateAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private string GetExceptionCaption(string title, bool isTerminating = false)
|
||||
{
|
||||
var caption = new StringBuilder();
|
||||
if (!string.IsNullOrEmpty(Name))
|
||||
{
|
||||
caption.Append(Name).Append(' ');
|
||||
}
|
||||
caption.Append(title);
|
||||
if (isTerminating)
|
||||
{
|
||||
caption.Append(" (Terminating)");
|
||||
}
|
||||
|
||||
return caption.ToString();
|
||||
}
|
||||
|
||||
private void OnApplicationCheckAndDownloadUpdateCompleted(object sender, CheckAndDownloadUpdateCompletedEventArgs e)
|
||||
{
|
||||
if (e.Error != null)
|
||||
{
|
||||
if (e.Error is PlatformNotSupportedException)
|
||||
{
|
||||
MessageBox.Show("An application update is available, but it requires the latest version of Silverlight.");
|
||||
}
|
||||
//else if (Debugger.IsAttached)
|
||||
//{
|
||||
// Debugger.Break();
|
||||
//}
|
||||
}
|
||||
else if (e.UpdateAvailable)
|
||||
{
|
||||
MessageBox.Show("An application update was downloaded. Restart the application to run the latest version.");
|
||||
}
|
||||
}
|
||||
|
||||
private void OnApplicationUnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
|
||||
{
|
||||
MessageBox.Show(e.ExceptionObject.ToString(), GetExceptionCaption("Application Exception"), MessageBoxButton.OK);
|
||||
if (Debugger.IsAttached)
|
||||
{
|
||||
Debugger.Break();
|
||||
}
|
||||
}
|
||||
|
||||
//private void OnAppDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
|
||||
//{
|
||||
// MessageBox.Show(e.ExceptionObject.ToString(), GetExceptionCaption("AppDomain Exception", e.IsTerminating), MessageBoxButton.OK);
|
||||
// if (Debugger.IsAttached)
|
||||
// {
|
||||
// Debugger.Break();
|
||||
// }
|
||||
//}
|
||||
|
||||
public string Name { get; private set; }
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
|
||||
namespace Jellyfish.Library
|
||||
{
|
||||
public abstract class ApplicationBase : Application
|
||||
{
|
||||
protected ApplicationBase() :
|
||||
this(null)
|
||||
{
|
||||
}
|
||||
|
||||
protected ApplicationBase(string name)
|
||||
{
|
||||
Name = name;
|
||||
|
||||
UnhandledException += OnApplicationUnhandledException;
|
||||
//AppDomain.CurrentDomain.UnhandledException += OnAppDomainUnhandledException;
|
||||
|
||||
if (Debugger.IsAttached)
|
||||
{
|
||||
var settings = Application.Current.Host.Settings;
|
||||
settings.EnableFrameRateCounter = true;
|
||||
//settings.EnableRedrawRegions = true;
|
||||
//settings.EnableCacheVisualization = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected void InitializeOutOfBrowserUpdate()
|
||||
{
|
||||
if (IsRunningOutOfBrowser)
|
||||
{
|
||||
CheckAndDownloadUpdateCompleted += OnApplicationCheckAndDownloadUpdateCompleted;
|
||||
CheckAndDownloadUpdateAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private string GetExceptionCaption(string title, bool isTerminating = false)
|
||||
{
|
||||
var caption = new StringBuilder();
|
||||
if (!string.IsNullOrEmpty(Name))
|
||||
{
|
||||
caption.Append(Name).Append(' ');
|
||||
}
|
||||
caption.Append(title);
|
||||
if (isTerminating)
|
||||
{
|
||||
caption.Append(" (Terminating)");
|
||||
}
|
||||
|
||||
return caption.ToString();
|
||||
}
|
||||
|
||||
private void OnApplicationCheckAndDownloadUpdateCompleted(object sender, CheckAndDownloadUpdateCompletedEventArgs e)
|
||||
{
|
||||
if (e.Error != null)
|
||||
{
|
||||
if (e.Error is PlatformNotSupportedException)
|
||||
{
|
||||
MessageBox.Show("An application update is available, but it requires the latest version of Silverlight.");
|
||||
}
|
||||
//else if (Debugger.IsAttached)
|
||||
//{
|
||||
// Debugger.Break();
|
||||
//}
|
||||
}
|
||||
else if (e.UpdateAvailable)
|
||||
{
|
||||
MessageBox.Show("An application update was downloaded. Restart the application to run the latest version.");
|
||||
}
|
||||
}
|
||||
|
||||
private void OnApplicationUnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
|
||||
{
|
||||
MessageBox.Show(e.ExceptionObject.ToString(), GetExceptionCaption("Application Exception"), MessageBoxButton.OK);
|
||||
if (Debugger.IsAttached)
|
||||
{
|
||||
Debugger.Break();
|
||||
}
|
||||
}
|
||||
|
||||
//private void OnAppDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
|
||||
//{
|
||||
// MessageBox.Show(e.ExceptionObject.ToString(), GetExceptionCaption("AppDomain Exception", e.IsTerminating), MessageBoxButton.OK);
|
||||
// if (Debugger.IsAttached)
|
||||
// {
|
||||
// Debugger.Break();
|
||||
// }
|
||||
//}
|
||||
|
||||
public string Name { get; private set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,133 +1,133 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.50727</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{99CA7796-B72A-4F8C-BCDB-0D688220A331}</ProjectGuid>
|
||||
<ProjectTypeGuids>{A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Jellyfish.Library</RootNamespace>
|
||||
<AssemblyName>Jellyfish.Library</AssemblyName>
|
||||
<TargetFrameworkIdentifier>Silverlight</TargetFrameworkIdentifier>
|
||||
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile />
|
||||
<SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion>
|
||||
<SilverlightApplication>false</SilverlightApplication>
|
||||
<ValidateXaml>true</ValidateXaml>
|
||||
<ThrowErrorsInValidation>true</ThrowErrorsInValidation>
|
||||
</PropertyGroup>
|
||||
<!-- This property group is only here to support building this project using the
|
||||
MSBuild 3.5 toolset. In order to work correctly with this older toolset, it needs
|
||||
to set the TargetFrameworkVersion to v3.5 -->
|
||||
<PropertyGroup Condition="'$(MSBuildToolsVersion)' == '3.5'">
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;SILVERLIGHT;CODE_ANALYSIS</DefineConstants>
|
||||
<NoStdLib>true</NoStdLib>
|
||||
<NoConfig>true</NoConfig>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<RunCodeAnalysis>false</RunCodeAnalysis>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\</OutputPath>
|
||||
<DefineConstants>TRACE;SILVERLIGHT;CODE_ANALYSIS</DefineConstants>
|
||||
<NoStdLib>true</NoStdLib>
|
||||
<NoConfig>true</NoConfig>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<RunCodeAnalysis>false</RunCodeAnalysis>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SignAssembly>false</SignAssembly>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<AssemblyOriginatorKeyFile>..\..\..\Jellyfish\StrongName.snk</AssemblyOriginatorKeyFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="mscorlib" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Net" />
|
||||
<Reference Include="System.Windows" />
|
||||
<Reference Include="System.Windows.Browser" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\AssemblyMetadataAttribute.cs">
|
||||
<Link>AssemblyMetadataAttribute.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\DispatcherExtensions.cs">
|
||||
<Link>DispatcherExtensions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\DisposableBase.cs">
|
||||
<Link>DisposableBase.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\FrameRateCounter.xaml.cs">
|
||||
<Link>FrameRateCounter.xaml.cs</Link>
|
||||
<DependentUpon>FrameRateCounter.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="..\GlobalSuppressions.cs">
|
||||
<Link>GlobalSuppressions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\IEnumerableExtensions.cs">
|
||||
<Link>IEnumerableExtensions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MathHelpers.cs">
|
||||
<Link>MathHelpers.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\StreamExtensions.cs">
|
||||
<Link>StreamExtensions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\StringBuilderExtensions.cs">
|
||||
<Link>StringBuilderExtensions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\WaveFormat.cs">
|
||||
<Link>WaveFormat.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ApplicationBase.cs" />
|
||||
<Compile Include="WaveMediaStreamSource.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Include="..\FrameRateCounter.xaml">
|
||||
<Link>FrameRateCounter.xaml</Link>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
|
||||
<Link>CustomDictionary.xml</Link>
|
||||
</CodeAnalysisDictionary>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\$(SilverlightVersion)\Microsoft.Silverlight.CSharp.targets" />
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}">
|
||||
<SilverlightProjectProperties />
|
||||
</FlavorProperties>
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.50727</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{99CA7796-B72A-4F8C-BCDB-0D688220A331}</ProjectGuid>
|
||||
<ProjectTypeGuids>{A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Jellyfish.Library</RootNamespace>
|
||||
<AssemblyName>Jellyfish.Library</AssemblyName>
|
||||
<TargetFrameworkIdentifier>Silverlight</TargetFrameworkIdentifier>
|
||||
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile />
|
||||
<SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion>
|
||||
<SilverlightApplication>false</SilverlightApplication>
|
||||
<ValidateXaml>true</ValidateXaml>
|
||||
<ThrowErrorsInValidation>true</ThrowErrorsInValidation>
|
||||
</PropertyGroup>
|
||||
<!-- This property group is only here to support building this project using the
|
||||
MSBuild 3.5 toolset. In order to work correctly with this older toolset, it needs
|
||||
to set the TargetFrameworkVersion to v3.5 -->
|
||||
<PropertyGroup Condition="'$(MSBuildToolsVersion)' == '3.5'">
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;SILVERLIGHT;CODE_ANALYSIS</DefineConstants>
|
||||
<NoStdLib>true</NoStdLib>
|
||||
<NoConfig>true</NoConfig>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<RunCodeAnalysis>false</RunCodeAnalysis>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\</OutputPath>
|
||||
<DefineConstants>TRACE;SILVERLIGHT;CODE_ANALYSIS</DefineConstants>
|
||||
<NoStdLib>true</NoStdLib>
|
||||
<NoConfig>true</NoConfig>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<RunCodeAnalysis>false</RunCodeAnalysis>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SignAssembly>false</SignAssembly>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<AssemblyOriginatorKeyFile>..\..\..\Jellyfish\StrongName.snk</AssemblyOriginatorKeyFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="mscorlib" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Net" />
|
||||
<Reference Include="System.Windows" />
|
||||
<Reference Include="System.Windows.Browser" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\AssemblyMetadataAttribute.cs">
|
||||
<Link>AssemblyMetadataAttribute.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\DispatcherExtensions.cs">
|
||||
<Link>DispatcherExtensions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\DisposableBase.cs">
|
||||
<Link>DisposableBase.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\FrameRateCounter.xaml.cs">
|
||||
<Link>FrameRateCounter.xaml.cs</Link>
|
||||
<DependentUpon>FrameRateCounter.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="..\GlobalSuppressions.cs">
|
||||
<Link>GlobalSuppressions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\IEnumerableExtensions.cs">
|
||||
<Link>IEnumerableExtensions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MathHelpers.cs">
|
||||
<Link>MathHelpers.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\StreamExtensions.cs">
|
||||
<Link>StreamExtensions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\StringBuilderExtensions.cs">
|
||||
<Link>StringBuilderExtensions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\WaveFormat.cs">
|
||||
<Link>WaveFormat.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ApplicationBase.cs" />
|
||||
<Compile Include="WaveMediaStreamSource.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Include="..\FrameRateCounter.xaml">
|
||||
<Link>FrameRateCounter.xaml</Link>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
|
||||
<Link>CustomDictionary.xml</Link>
|
||||
</CodeAnalysisDictionary>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\$(SilverlightVersion)\Microsoft.Silverlight.CSharp.targets" />
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}">
|
||||
<SilverlightProjectProperties />
|
||||
</FlavorProperties>
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
@ -1,20 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfish.Library.Silverlight", "Jellyfish.Library.Silverlight.csproj", "{99CA7796-B72A-4F8C-BCDB-0D688220A331}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{99CA7796-B72A-4F8C-BCDB-0D688220A331}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{99CA7796-B72A-4F8C-BCDB-0D688220A331}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{99CA7796-B72A-4F8C-BCDB-0D688220A331}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{99CA7796-B72A-4F8C-BCDB-0D688220A331}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfish.Library.Silverlight", "Jellyfish.Library.Silverlight.csproj", "{99CA7796-B72A-4F8C-BCDB-0D688220A331}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{99CA7796-B72A-4F8C-BCDB-0D688220A331}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{99CA7796-B72A-4F8C-BCDB-0D688220A331}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{99CA7796-B72A-4F8C-BCDB-0D688220A331}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{99CA7796-B72A-4F8C-BCDB-0D688220A331}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
@ -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-2012 Digital Jellyfish Design Ltd")]
|
||||
[assembly: AssemblyMetadata("Developer", "Sean Fausett")]
|
||||
|
||||
[assembly: AssemblyVersion("0.4.0.0")]
|
||||
[assembly: AssemblyFileVersion("0.4.0.0")]
|
||||
[assembly: AssemblyInformationalVersion("0.4.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-2012 Digital Jellyfish Design Ltd")]
|
||||
[assembly: AssemblyMetadata("Developer", "Sean Fausett")]
|
||||
|
||||
[assembly: AssemblyVersion("0.4.0.0")]
|
||||
[assembly: AssemblyFileVersion("0.4.0.0")]
|
||||
[assembly: AssemblyInformationalVersion("0.4.0.0")]
|
||||
|
||||
[assembly: CLSCompliant(false)]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: Guid("66034b9e-9f0b-47b0-aac4-cade9a748891")]
|
||||
|
||||
[assembly: NeutralResourcesLanguage("en")]
|
||||
|
@ -1,76 +1,76 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Jellyfish.Library
|
||||
{
|
||||
public sealed class WaveMediaStreamSource : MediaStreamSource, IDisposable
|
||||
{
|
||||
public WaveMediaStreamSource(int sampleRate, int sampleChannels, int sampleBits, int sampleSize, int sampleLatency, Action<byte[], int> updater)
|
||||
{
|
||||
_bufferSize = sampleSize;
|
||||
_buffer = new byte[_bufferSize];
|
||||
_bufferStream = new MemoryStream(_buffer);
|
||||
_waveFormat = new WaveFormat(sampleRate, sampleChannels, sampleBits);
|
||||
AudioBufferLength = sampleLatency; // ms; avoids audio delay
|
||||
_updater = updater;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_bufferStream.Dispose();
|
||||
}
|
||||
|
||||
protected override void CloseMedia()
|
||||
{
|
||||
_audioDescription = null;
|
||||
}
|
||||
|
||||
protected override void GetDiagnosticAsync(MediaStreamSourceDiagnosticKind diagnosticKind)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override void GetSampleAsync(MediaStreamType mediaStreamType)
|
||||
{
|
||||
_updater(_buffer, _bufferSize);
|
||||
|
||||
var sample = new MediaStreamSample(_audioDescription, _bufferStream, 0, _bufferSize, _timestamp, _emptySampleDict);
|
||||
_timestamp += _bufferSize * 10000000L / _waveFormat.AverageBytesPerSec; // 100 ns
|
||||
|
||||
ReportGetSampleCompleted(sample);
|
||||
}
|
||||
|
||||
protected override void OpenMediaAsync()
|
||||
{
|
||||
_timestamp = 0;
|
||||
|
||||
var sourceAttributes = new Dictionary<MediaSourceAttributesKeys, string>() { { MediaSourceAttributesKeys.Duration, "0" }, { MediaSourceAttributesKeys.CanSeek, "false" } };
|
||||
var streamAttributes = new Dictionary<MediaStreamAttributeKeys, string>() { { MediaStreamAttributeKeys.CodecPrivateData, _waveFormat.ToHexString() } };
|
||||
_audioDescription = new MediaStreamDescription(MediaStreamType.Audio, streamAttributes);
|
||||
var availableStreams = new List<MediaStreamDescription>() { _audioDescription };
|
||||
|
||||
ReportOpenMediaCompleted(sourceAttributes, availableStreams);
|
||||
}
|
||||
|
||||
protected override void SeekAsync(long seekToTime)
|
||||
{
|
||||
ReportSeekCompleted(seekToTime);
|
||||
}
|
||||
|
||||
protected override void SwitchMediaStreamAsync(MediaStreamDescription mediaStreamDescription)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private byte[] _buffer;
|
||||
private int _bufferSize;
|
||||
private MemoryStream _bufferStream;
|
||||
private Action<byte[], int> _updater;
|
||||
private WaveFormat _waveFormat;
|
||||
private long _timestamp;
|
||||
private MediaStreamDescription _audioDescription;
|
||||
private Dictionary<MediaSampleAttributeKeys, string> _emptySampleDict = new Dictionary<MediaSampleAttributeKeys, string>();
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Jellyfish.Library
|
||||
{
|
||||
public sealed class WaveMediaStreamSource : MediaStreamSource, IDisposable
|
||||
{
|
||||
public WaveMediaStreamSource(int sampleRate, int sampleChannels, int sampleBits, int sampleSize, int sampleLatency, Action<byte[], int> updater)
|
||||
{
|
||||
_bufferSize = sampleSize;
|
||||
_buffer = new byte[_bufferSize];
|
||||
_bufferStream = new MemoryStream(_buffer);
|
||||
_waveFormat = new WaveFormat(sampleRate, sampleChannels, sampleBits);
|
||||
AudioBufferLength = sampleLatency; // ms; avoids audio delay
|
||||
_updater = updater;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_bufferStream.Dispose();
|
||||
}
|
||||
|
||||
protected override void CloseMedia()
|
||||
{
|
||||
_audioDescription = null;
|
||||
}
|
||||
|
||||
protected override void GetDiagnosticAsync(MediaStreamSourceDiagnosticKind diagnosticKind)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override void GetSampleAsync(MediaStreamType mediaStreamType)
|
||||
{
|
||||
_updater(_buffer, _bufferSize);
|
||||
|
||||
var sample = new MediaStreamSample(_audioDescription, _bufferStream, 0, _bufferSize, _timestamp, _emptySampleDict);
|
||||
_timestamp += _bufferSize * 10000000L / _waveFormat.AverageBytesPerSec; // 100 ns
|
||||
|
||||
ReportGetSampleCompleted(sample);
|
||||
}
|
||||
|
||||
protected override void OpenMediaAsync()
|
||||
{
|
||||
_timestamp = 0;
|
||||
|
||||
var sourceAttributes = new Dictionary<MediaSourceAttributesKeys, string>() { { MediaSourceAttributesKeys.Duration, "0" }, { MediaSourceAttributesKeys.CanSeek, "false" } };
|
||||
var streamAttributes = new Dictionary<MediaStreamAttributeKeys, string>() { { MediaStreamAttributeKeys.CodecPrivateData, _waveFormat.ToHexString() } };
|
||||
_audioDescription = new MediaStreamDescription(MediaStreamType.Audio, streamAttributes);
|
||||
var availableStreams = new List<MediaStreamDescription>() { _audioDescription };
|
||||
|
||||
ReportOpenMediaCompleted(sourceAttributes, availableStreams);
|
||||
}
|
||||
|
||||
protected override void SeekAsync(long seekToTime)
|
||||
{
|
||||
ReportSeekCompleted(seekToTime);
|
||||
}
|
||||
|
||||
protected override void SwitchMediaStreamAsync(MediaStreamDescription mediaStreamDescription)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private byte[] _buffer;
|
||||
private int _bufferSize;
|
||||
private MemoryStream _bufferStream;
|
||||
private Action<byte[], int> _updater;
|
||||
private WaveFormat _waveFormat;
|
||||
private long _timestamp;
|
||||
private MediaStreamDescription _audioDescription;
|
||||
private Dictionary<MediaSampleAttributeKeys, string> _emptySampleDict = new Dictionary<MediaSampleAttributeKeys, string>();
|
||||
}
|
||||
}
|
||||
|
@ -1,94 +1,94 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
|
||||
namespace Jellyfish.Library
|
||||
{
|
||||
public static class StreamExtensions
|
||||
{
|
||||
[SuppressMessage("Microsoft.Design", "CA1045:DoNotPassTypesByReference", MessageId = "3#")]
|
||||
public static int ReadBlock(this Stream stream, byte[] buffer, int offset, ref int count)
|
||||
{
|
||||
int read = ReadBlock(stream, buffer, offset, count, count);
|
||||
count -= read;
|
||||
return read;
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
|
||||
public static int ReadBlock(this Stream stream, byte[] buffer, int offset = 0, int count = int.MaxValue, int minCount = int.MaxValue)
|
||||
{
|
||||
if (stream == null)
|
||||
{
|
||||
throw new ArgumentNullException("stream");
|
||||
}
|
||||
if (buffer == null)
|
||||
{
|
||||
throw new ArgumentNullException("buffer");
|
||||
}
|
||||
|
||||
count = Math.Min(count, buffer.Length - offset);
|
||||
minCount = Math.Min(minCount, buffer.Length - offset);
|
||||
|
||||
int total = 0;
|
||||
int read;
|
||||
do
|
||||
{
|
||||
total += read = stream.Read(buffer, offset + total, count - total);
|
||||
}
|
||||
while ((read > 0) && (total < count));
|
||||
|
||||
if (total < minCount)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
|
||||
public static int ReadWord(this Stream stream, bool optional = false)
|
||||
{
|
||||
if (stream == null)
|
||||
{
|
||||
throw new ArgumentNullException("stream");
|
||||
}
|
||||
|
||||
int lowByte = stream.ReadByte();
|
||||
int highByte = stream.ReadByte();
|
||||
int word = lowByte | (highByte << 8);
|
||||
if ((word < 0) && !optional)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
}
|
||||
|
||||
return word;
|
||||
}
|
||||
|
||||
public static void SkipBlock(this Stream stream, int count)
|
||||
{
|
||||
if (stream == null)
|
||||
{
|
||||
throw new ArgumentNullException("stream");
|
||||
}
|
||||
|
||||
if (stream.CanSeek)
|
||||
{
|
||||
stream.Seek(count, SeekOrigin.Current);
|
||||
}
|
||||
else
|
||||
{
|
||||
int total = 0;
|
||||
int read;
|
||||
do
|
||||
{
|
||||
total += read = stream.Read(_skipBuffer, 0, Math.Min(count - total, SkipBufferSize));
|
||||
}
|
||||
while ((read > 0) && (total < count));
|
||||
}
|
||||
}
|
||||
|
||||
private const int SkipBufferSize = 1024;
|
||||
|
||||
private static byte[] _skipBuffer = new byte[SkipBufferSize];
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
|
||||
namespace Jellyfish.Library
|
||||
{
|
||||
public static class StreamExtensions
|
||||
{
|
||||
[SuppressMessage("Microsoft.Design", "CA1045:DoNotPassTypesByReference", MessageId = "3#")]
|
||||
public static int ReadBlock(this Stream stream, byte[] buffer, int offset, ref int count)
|
||||
{
|
||||
int read = ReadBlock(stream, buffer, offset, count, count);
|
||||
count -= read;
|
||||
return read;
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
|
||||
public static int ReadBlock(this Stream stream, byte[] buffer, int offset = 0, int count = int.MaxValue, int minCount = int.MaxValue)
|
||||
{
|
||||
if (stream == null)
|
||||
{
|
||||
throw new ArgumentNullException("stream");
|
||||
}
|
||||
if (buffer == null)
|
||||
{
|
||||
throw new ArgumentNullException("buffer");
|
||||
}
|
||||
|
||||
count = Math.Min(count, buffer.Length - offset);
|
||||
minCount = Math.Min(minCount, buffer.Length - offset);
|
||||
|
||||
int total = 0;
|
||||
int read;
|
||||
do
|
||||
{
|
||||
total += read = stream.Read(buffer, offset + total, count - total);
|
||||
}
|
||||
while ((read > 0) && (total < count));
|
||||
|
||||
if (total < minCount)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
|
||||
public static int ReadWord(this Stream stream, bool optional = false)
|
||||
{
|
||||
if (stream == null)
|
||||
{
|
||||
throw new ArgumentNullException("stream");
|
||||
}
|
||||
|
||||
int lowByte = stream.ReadByte();
|
||||
int highByte = stream.ReadByte();
|
||||
int word = lowByte | (highByte << 8);
|
||||
if ((word < 0) && !optional)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
}
|
||||
|
||||
return word;
|
||||
}
|
||||
|
||||
public static void SkipBlock(this Stream stream, int count)
|
||||
{
|
||||
if (stream == null)
|
||||
{
|
||||
throw new ArgumentNullException("stream");
|
||||
}
|
||||
|
||||
if (stream.CanSeek)
|
||||
{
|
||||
stream.Seek(count, SeekOrigin.Current);
|
||||
}
|
||||
else
|
||||
{
|
||||
int total = 0;
|
||||
int read;
|
||||
do
|
||||
{
|
||||
total += read = stream.Read(_skipBuffer, 0, Math.Min(count - total, SkipBufferSize));
|
||||
}
|
||||
while ((read > 0) && (total < count));
|
||||
}
|
||||
}
|
||||
|
||||
private const int SkipBufferSize = 1024;
|
||||
|
||||
private static byte[] _skipBuffer = new byte[SkipBufferSize];
|
||||
}
|
||||
}
|
||||
|
@ -1,54 +1,54 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace Jellyfish.Library
|
||||
{
|
||||
public static class StringBuilderExtensions
|
||||
{
|
||||
public static StringBuilder AppendHex(this StringBuilder builder, short value) // little endian
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
throw new ArgumentNullException("builder");
|
||||
}
|
||||
|
||||
return builder.AppendFormat(CultureInfo.InvariantCulture, "{0:X2}{1:X2}", value & 0xFF, value >> 8);
|
||||
}
|
||||
|
||||
public static StringBuilder AppendHex(this StringBuilder builder, int value) // little endian
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
throw new ArgumentNullException("builder");
|
||||
}
|
||||
|
||||
return builder.AppendFormat(CultureInfo.InvariantCulture, "{0:X2}{1:X2}{2:X2}{3:X2}", value & 0xFF, (value >> 8) & 0xFF, (value >> 16) & 0xFF, value >> 24);
|
||||
}
|
||||
|
||||
public static StringBuilder AppendWithoutGarbage(this StringBuilder builder, int value)
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
throw new ArgumentNullException("builder");
|
||||
}
|
||||
|
||||
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;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace Jellyfish.Library
|
||||
{
|
||||
public static class StringBuilderExtensions
|
||||
{
|
||||
public static StringBuilder AppendHex(this StringBuilder builder, short value) // little endian
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
throw new ArgumentNullException("builder");
|
||||
}
|
||||
|
||||
return builder.AppendFormat(CultureInfo.InvariantCulture, "{0:X2}{1:X2}", value & 0xFF, value >> 8);
|
||||
}
|
||||
|
||||
public static StringBuilder AppendHex(this StringBuilder builder, int value) // little endian
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
throw new ArgumentNullException("builder");
|
||||
}
|
||||
|
||||
return builder.AppendFormat(CultureInfo.InvariantCulture, "{0:X2}{1:X2}{2:X2}{3:X2}", value & 0xFF, (value >> 8) & 0xFF, (value >> 16) & 0xFF, value >> 24);
|
||||
}
|
||||
|
||||
public static StringBuilder AppendWithoutGarbage(this StringBuilder builder, int value)
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
throw new ArgumentNullException("builder");
|
||||
}
|
||||
|
||||
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' };
|
||||
}
|
||||
}
|
||||
|
@ -1,49 +1,49 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace Jellyfish.Library
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public sealed class WaveFormat
|
||||
{
|
||||
public WaveFormat(int sampleRate, int sampleChannels, int sampleBits)
|
||||
{
|
||||
_formatTag = WaveFormatPcm;
|
||||
_samplesPerSec = sampleRate;
|
||||
_channels = (short)sampleChannels;
|
||||
_bitsPerSample = (short)sampleBits;
|
||||
_blockAlign = (short)(sampleChannels * sampleBits / 8);
|
||||
_averageBytesPerSec = sampleRate * _blockAlign;
|
||||
}
|
||||
|
||||
public string ToHexString() // little endian
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendHex(_formatTag);
|
||||
builder.AppendHex(_channels);
|
||||
builder.AppendHex(_samplesPerSec);
|
||||
builder.AppendHex(_averageBytesPerSec);
|
||||
builder.AppendHex(_blockAlign);
|
||||
builder.AppendHex(_bitsPerSample);
|
||||
builder.AppendHex(_size);
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
public int SamplesPerSec { get { return _samplesPerSec; } } // no auto props
|
||||
public int Channels { get { return _channels; } }
|
||||
public int BitsPerSample { get { return _bitsPerSample; } }
|
||||
public int AverageBytesPerSec { get { return _averageBytesPerSec; } }
|
||||
|
||||
private const int WaveFormatPcm = 1;
|
||||
|
||||
private short _formatTag;
|
||||
private short _channels;
|
||||
private int _samplesPerSec;
|
||||
private int _averageBytesPerSec;
|
||||
private short _blockAlign;
|
||||
private short _bitsPerSample;
|
||||
private short _size;
|
||||
}
|
||||
}
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace Jellyfish.Library
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public sealed class WaveFormat
|
||||
{
|
||||
public WaveFormat(int sampleRate, int sampleChannels, int sampleBits)
|
||||
{
|
||||
_formatTag = WaveFormatPcm;
|
||||
_samplesPerSec = sampleRate;
|
||||
_channels = (short)sampleChannels;
|
||||
_bitsPerSample = (short)sampleBits;
|
||||
_blockAlign = (short)(sampleChannels * sampleBits / 8);
|
||||
_averageBytesPerSec = sampleRate * _blockAlign;
|
||||
}
|
||||
|
||||
public string ToHexString() // little endian
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.AppendHex(_formatTag);
|
||||
builder.AppendHex(_channels);
|
||||
builder.AppendHex(_samplesPerSec);
|
||||
builder.AppendHex(_averageBytesPerSec);
|
||||
builder.AppendHex(_blockAlign);
|
||||
builder.AppendHex(_bitsPerSample);
|
||||
builder.AppendHex(_size);
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
public int SamplesPerSec { get { return _samplesPerSec; } } // no auto props
|
||||
public int Channels { get { return _channels; } }
|
||||
public int BitsPerSample { get { return _bitsPerSample; } }
|
||||
public int AverageBytesPerSec { get { return _averageBytesPerSec; } }
|
||||
|
||||
private const int WaveFormatPcm = 1;
|
||||
|
||||
private short _formatTag;
|
||||
private short _channels;
|
||||
private int _samplesPerSec;
|
||||
private int _averageBytesPerSec;
|
||||
private short _blockAlign;
|
||||
private short _bitsPerSample;
|
||||
private short _size;
|
||||
}
|
||||
}
|
||||
|
@ -1,65 +1,65 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace Jellyfish.Library
|
||||
{
|
||||
public abstract class ApplicationBase : Application
|
||||
{
|
||||
[SecurityCritical]
|
||||
protected ApplicationBase() :
|
||||
this(null)
|
||||
{
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
protected ApplicationBase(string name)
|
||||
{
|
||||
Name = name;
|
||||
|
||||
DispatcherUnhandledException += OnApplicationDispatcherUnhandledException;
|
||||
AppDomain.CurrentDomain.UnhandledException += OnAppDomainUnhandledException;
|
||||
}
|
||||
|
||||
private string GetExceptionCaption(string title, bool isTerminating = false)
|
||||
{
|
||||
var caption = new StringBuilder();
|
||||
if (!string.IsNullOrEmpty(Name))
|
||||
{
|
||||
caption.Append(Name).Append(' ');
|
||||
}
|
||||
caption.Append(title);
|
||||
if (isTerminating)
|
||||
{
|
||||
caption.Append(" (Terminating)");
|
||||
}
|
||||
|
||||
return caption.ToString();
|
||||
}
|
||||
|
||||
private void OnApplicationDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
|
||||
{
|
||||
MessageBox.Show(e.Exception.ToString(), GetExceptionCaption("Application Dispatcher Exception", isTerminating: true));
|
||||
if (Debugger.IsAttached)
|
||||
{
|
||||
Debugger.Break();
|
||||
}
|
||||
e.Handled = true;
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
private void OnAppDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
|
||||
{
|
||||
MessageBox.Show(e.ExceptionObject.ToString(), GetExceptionCaption("AppDomain Exception", e.IsTerminating));
|
||||
if (Debugger.IsAttached)
|
||||
{
|
||||
Debugger.Break();
|
||||
}
|
||||
}
|
||||
|
||||
public string Name { get; private set; }
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace Jellyfish.Library
|
||||
{
|
||||
public abstract class ApplicationBase : Application
|
||||
{
|
||||
[SecurityCritical]
|
||||
protected ApplicationBase() :
|
||||
this(null)
|
||||
{
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
protected ApplicationBase(string name)
|
||||
{
|
||||
Name = name;
|
||||
|
||||
DispatcherUnhandledException += OnApplicationDispatcherUnhandledException;
|
||||
AppDomain.CurrentDomain.UnhandledException += OnAppDomainUnhandledException;
|
||||
}
|
||||
|
||||
private string GetExceptionCaption(string title, bool isTerminating = false)
|
||||
{
|
||||
var caption = new StringBuilder();
|
||||
if (!string.IsNullOrEmpty(Name))
|
||||
{
|
||||
caption.Append(Name).Append(' ');
|
||||
}
|
||||
caption.Append(title);
|
||||
if (isTerminating)
|
||||
{
|
||||
caption.Append(" (Terminating)");
|
||||
}
|
||||
|
||||
return caption.ToString();
|
||||
}
|
||||
|
||||
private void OnApplicationDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
|
||||
{
|
||||
MessageBox.Show(e.Exception.ToString(), GetExceptionCaption("Application Dispatcher Exception", isTerminating: true));
|
||||
if (Debugger.IsAttached)
|
||||
{
|
||||
Debugger.Break();
|
||||
}
|
||||
e.Handled = true;
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
private void OnAppDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
|
||||
{
|
||||
MessageBox.Show(e.ExceptionObject.ToString(), GetExceptionCaption("AppDomain Exception", e.IsTerminating));
|
||||
if (Debugger.IsAttached)
|
||||
{
|
||||
Debugger.Break();
|
||||
}
|
||||
}
|
||||
|
||||
public string Name { get; private set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,120 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{93900841-7250-4D3A-837E-43EE3FD118DC}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Jellyfish.Library</RootNamespace>
|
||||
<AssemblyName>Jellyfish.Library</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;WINDOWS;CODE_ANALYSIS</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<RunCodeAnalysis>false</RunCodeAnalysis>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\</OutputPath>
|
||||
<DefineConstants>TRACE;WINDOWS;CODE_ANALYSIS</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<RunCodeAnalysis>false</RunCodeAnalysis>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SignAssembly>false</SignAssembly>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<AssemblyOriginatorKeyFile>..\..\..\Jellyfish\StrongName.snk</AssemblyOriginatorKeyFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xaml" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\DirectSound.cs">
|
||||
<Link>DirectSound.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\DirectSoundInterop.cs">
|
||||
<Link>DirectSoundInterop.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\DispatcherExtensions.cs">
|
||||
<Link>DispatcherExtensions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\DisposableBase.cs">
|
||||
<Link>DisposableBase.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\FrameRateCounter.xaml.cs">
|
||||
<Link>FrameRateCounter.xaml.cs</Link>
|
||||
<DependentUpon>FrameRateCounter.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="..\GCHandleHelpers.cs">
|
||||
<Link>GCHandleHelpers.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\GlobalSuppressions.cs">
|
||||
<Link>GlobalSuppressions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\IEnumerableExtensions.cs">
|
||||
<Link>IEnumerableExtensions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MarshalHelpers.cs">
|
||||
<Link>MarshalHelpers.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MathHelpers.cs">
|
||||
<Link>MathHelpers.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\StreamExtensions.cs">
|
||||
<Link>StreamExtensions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\StringBuilderExtensions.cs">
|
||||
<Link>StringBuilderExtensions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\WaveFormat.cs">
|
||||
<Link>WaveFormat.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ApplicationBase.cs" />
|
||||
<Compile Include="WindowExtensions.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Include="..\FrameRateCounter.xaml">
|
||||
<Link>FrameRateCounter.xaml</Link>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
|
||||
<Link>CustomDictionary.xml</Link>
|
||||
</CodeAnalysisDictionary>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{93900841-7250-4D3A-837E-43EE3FD118DC}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Jellyfish.Library</RootNamespace>
|
||||
<AssemblyName>Jellyfish.Library</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;WINDOWS;CODE_ANALYSIS</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<RunCodeAnalysis>false</RunCodeAnalysis>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\</OutputPath>
|
||||
<DefineConstants>TRACE;WINDOWS;CODE_ANALYSIS</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<RunCodeAnalysis>false</RunCodeAnalysis>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SignAssembly>false</SignAssembly>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<AssemblyOriginatorKeyFile>..\..\..\Jellyfish\StrongName.snk</AssemblyOriginatorKeyFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xaml" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\DirectSound.cs">
|
||||
<Link>DirectSound.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\DirectSoundInterop.cs">
|
||||
<Link>DirectSoundInterop.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\DispatcherExtensions.cs">
|
||||
<Link>DispatcherExtensions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\DisposableBase.cs">
|
||||
<Link>DisposableBase.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\FrameRateCounter.xaml.cs">
|
||||
<Link>FrameRateCounter.xaml.cs</Link>
|
||||
<DependentUpon>FrameRateCounter.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="..\GCHandleHelpers.cs">
|
||||
<Link>GCHandleHelpers.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\GlobalSuppressions.cs">
|
||||
<Link>GlobalSuppressions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\IEnumerableExtensions.cs">
|
||||
<Link>IEnumerableExtensions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MarshalHelpers.cs">
|
||||
<Link>MarshalHelpers.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MathHelpers.cs">
|
||||
<Link>MathHelpers.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\StreamExtensions.cs">
|
||||
<Link>StreamExtensions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\StringBuilderExtensions.cs">
|
||||
<Link>StringBuilderExtensions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\WaveFormat.cs">
|
||||
<Link>WaveFormat.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ApplicationBase.cs" />
|
||||
<Compile Include="WindowExtensions.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Include="..\FrameRateCounter.xaml">
|
||||
<Link>FrameRateCounter.xaml</Link>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
|
||||
<Link>CustomDictionary.xml</Link>
|
||||
</CodeAnalysisDictionary>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
@ -1,20 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfish.Library.Wpf", "Jellyfish.Library.Wpf.csproj", "{93900841-7250-4D3A-837E-43EE3FD118DC}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{93900841-7250-4D3A-837E-43EE3FD118DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{93900841-7250-4D3A-837E-43EE3FD118DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{93900841-7250-4D3A-837E-43EE3FD118DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{93900841-7250-4D3A-837E-43EE3FD118DC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfish.Library.Wpf", "Jellyfish.Library.Wpf.csproj", "{93900841-7250-4D3A-837E-43EE3FD118DC}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{93900841-7250-4D3A-837E-43EE3FD118DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{93900841-7250-4D3A-837E-43EE3FD118DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{93900841-7250-4D3A-837E-43EE3FD118DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{93900841-7250-4D3A-837E-43EE3FD118DC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
@ -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-2012 Digital Jellyfish Design Ltd")]
|
||||
[assembly: AssemblyMetadata("Developer", "Sean Fausett")]
|
||||
|
||||
[assembly: AssemblyVersion("0.4.0.0")]
|
||||
[assembly: AssemblyFileVersion("0.4.0.0")]
|
||||
[assembly: AssemblyInformationalVersion("0.4.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-2012 Digital Jellyfish Design Ltd")]
|
||||
[assembly: AssemblyMetadata("Developer", "Sean Fausett")]
|
||||
|
||||
[assembly: AssemblyVersion("0.4.0.0")]
|
||||
[assembly: AssemblyFileVersion("0.4.0.0")]
|
||||
[assembly: AssemblyInformationalVersion("0.4.0.0")]
|
||||
|
||||
[assembly: CLSCompliant(false)]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: Guid("66034b9e-9f0b-47b0-aac4-cade9a748891")]
|
||||
|
||||
[assembly: NeutralResourcesLanguage("en")]
|
||||
|
@ -1,14 +1,14 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Interop;
|
||||
|
||||
namespace Jellyfish.Library
|
||||
{
|
||||
public static class WindowExtensions
|
||||
{
|
||||
public static IntPtr GetHandle(this Window window)
|
||||
{
|
||||
return new WindowInteropHelper(window).Handle;
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Interop;
|
||||
|
||||
namespace Jellyfish.Library
|
||||
{
|
||||
public static class WindowExtensions
|
||||
{
|
||||
public static IntPtr GetHandle(this Window window)
|
||||
{
|
||||
return new WindowInteropHelper(window).Handle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
560
License.txt
560
License.txt
@ -1,280 +1,280 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
@ -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()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
6522
Virtu/Cpu.cs
6522
Virtu/Cpu.cs
File diff suppressed because it is too large
Load Diff
166
Virtu/CpuData.cs
166
Virtu/CpuData.cs
@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1,28 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Dictionary>
|
||||
<Acronyms>
|
||||
<CasingExceptions>
|
||||
<Acronym>Io</Acronym>
|
||||
<Acronym>RPC</Acronym>
|
||||
</CasingExceptions>
|
||||
</Acronyms>
|
||||
<Words>
|
||||
<Recognized>
|
||||
<Word>Annunciator</Word>
|
||||
<Word>Cpu</Word>
|
||||
<Word>Dsk</Word>
|
||||
<Word>Prg</Word>
|
||||
<Word>Unpause</Word>
|
||||
<Word>Virtu</Word>
|
||||
<Word>Xex</Word>
|
||||
<Word>Xna</Word>
|
||||
<Word>x</Word>
|
||||
<Word>y</Word>
|
||||
</Recognized>
|
||||
<Unrecognized>
|
||||
<Word>DownRight</Word>
|
||||
<Word>GamePad</Word>
|
||||
<Word>UpRight</Word>
|
||||
</Unrecognized>
|
||||
</Words>
|
||||
</Dictionary>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Dictionary>
|
||||
<Acronyms>
|
||||
<CasingExceptions>
|
||||
<Acronym>Io</Acronym>
|
||||
<Acronym>RPC</Acronym>
|
||||
</CasingExceptions>
|
||||
</Acronyms>
|
||||
<Words>
|
||||
<Recognized>
|
||||
<Word>Annunciator</Word>
|
||||
<Word>Cpu</Word>
|
||||
<Word>Dsk</Word>
|
||||
<Word>Prg</Word>
|
||||
<Word>Unpause</Word>
|
||||
<Word>Virtu</Word>
|
||||
<Word>Xex</Word>
|
||||
<Word>Xna</Word>
|
||||
<Word>x</Word>
|
||||
<Word>y</Word>
|
||||
</Recognized>
|
||||
<Unrecognized>
|
||||
<Word>DownRight</Word>
|
||||
<Word>GamePad</Word>
|
||||
<Word>UpRight</Word>
|
||||
</Unrecognized>
|
||||
</Words>
|
||||
</Dictionary>
|
||||
|
194
Virtu/Disk525.cs
194
Virtu/Disk525.cs
@ -1,97 +1,97 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using Jellyfish.Library;
|
||||
|
||||
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, Stream stream, bool isWriteProtected)
|
||||
{
|
||||
if (name == null)
|
||||
{
|
||||
throw new ArgumentNullException("name");
|
||||
}
|
||||
|
||||
if (name.EndsWith(".do", StringComparison.OrdinalIgnoreCase) ||
|
||||
name.EndsWith(".dsk", StringComparison.OrdinalIgnoreCase)) // assumes dos sector skew
|
||||
{
|
||||
return new DiskDsk(name, stream, isWriteProtected, SectorSkew.Dos);
|
||||
}
|
||||
else if (name.EndsWith(".nib", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return new DiskNib(name, stream, isWriteProtected);
|
||||
}
|
||||
else if (name.EndsWith(".po", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return new DiskDsk(name, stream, isWriteProtected, SectorSkew.ProDos);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "version")]
|
||||
public static Disk525 LoadState(BinaryReader reader, Version version)
|
||||
{
|
||||
if (reader == null)
|
||||
{
|
||||
throw new ArgumentNullException("reader");
|
||||
}
|
||||
|
||||
string name = reader.ReadString();
|
||||
var data = reader.ReadBytes(reader.ReadInt32());
|
||||
bool isWriteProtected = reader.ReadBoolean();
|
||||
|
||||
if (name.EndsWith(".do", StringComparison.OrdinalIgnoreCase) ||
|
||||
name.EndsWith(".dsk", StringComparison.OrdinalIgnoreCase)) // assumes dos sector skew
|
||||
{
|
||||
return new DiskDsk(name, data, isWriteProtected, SectorSkew.Dos);
|
||||
}
|
||||
else if (name.EndsWith(".nib", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return new DiskNib(name, data, isWriteProtected);
|
||||
}
|
||||
else if (name.EndsWith(".po", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return new DiskDsk(name, data, isWriteProtected, SectorSkew.ProDos);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void SaveState(BinaryWriter writer)
|
||||
{
|
||||
if (writer == null)
|
||||
{
|
||||
throw new ArgumentNullException("writer");
|
||||
}
|
||||
|
||||
writer.Write(Name);
|
||||
writer.Write(Data.Length);
|
||||
writer.Write(Data);
|
||||
writer.Write(IsWriteProtected);
|
||||
}
|
||||
|
||||
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; }
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||
public byte[] Data { get; protected set; }
|
||||
public bool IsWriteProtected { 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;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using Jellyfish.Library;
|
||||
|
||||
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, Stream stream, bool isWriteProtected)
|
||||
{
|
||||
if (name == null)
|
||||
{
|
||||
throw new ArgumentNullException("name");
|
||||
}
|
||||
|
||||
if (name.EndsWith(".do", StringComparison.OrdinalIgnoreCase) ||
|
||||
name.EndsWith(".dsk", StringComparison.OrdinalIgnoreCase)) // assumes dos sector skew
|
||||
{
|
||||
return new DiskDsk(name, stream, isWriteProtected, SectorSkew.Dos);
|
||||
}
|
||||
else if (name.EndsWith(".nib", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return new DiskNib(name, stream, isWriteProtected);
|
||||
}
|
||||
else if (name.EndsWith(".po", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return new DiskDsk(name, stream, isWriteProtected, SectorSkew.ProDos);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "version")]
|
||||
public static Disk525 LoadState(BinaryReader reader, Version version)
|
||||
{
|
||||
if (reader == null)
|
||||
{
|
||||
throw new ArgumentNullException("reader");
|
||||
}
|
||||
|
||||
string name = reader.ReadString();
|
||||
var data = reader.ReadBytes(reader.ReadInt32());
|
||||
bool isWriteProtected = reader.ReadBoolean();
|
||||
|
||||
if (name.EndsWith(".do", StringComparison.OrdinalIgnoreCase) ||
|
||||
name.EndsWith(".dsk", StringComparison.OrdinalIgnoreCase)) // assumes dos sector skew
|
||||
{
|
||||
return new DiskDsk(name, data, isWriteProtected, SectorSkew.Dos);
|
||||
}
|
||||
else if (name.EndsWith(".nib", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return new DiskNib(name, data, isWriteProtected);
|
||||
}
|
||||
else if (name.EndsWith(".po", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return new DiskDsk(name, data, isWriteProtected, SectorSkew.ProDos);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void SaveState(BinaryWriter writer)
|
||||
{
|
||||
if (writer == null)
|
||||
{
|
||||
throw new ArgumentNullException("writer");
|
||||
}
|
||||
|
||||
writer.Write(Name);
|
||||
writer.Write(Data.Length);
|
||||
writer.Write(Data);
|
||||
writer.Write(IsWriteProtected);
|
||||
}
|
||||
|
||||
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; }
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||
public byte[] Data { get; protected set; }
|
||||
public bool IsWriteProtected { get; private set; }
|
||||
|
||||
public const int SectorCount = 16;
|
||||
public const int SectorSize = 0x100;
|
||||
public const int TrackCount = 35;
|
||||
public const int TrackSize = 0x1A00;
|
||||
}
|
||||
}
|
||||
|
648
Virtu/DiskDsk.cs
648
Virtu/DiskDsk.cs
@ -1,324 +1,324 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Jellyfish.Library;
|
||||
|
||||
namespace Jellyfish.Virtu
|
||||
{
|
||||
public enum SectorSkew { None = 0, Dos, ProDos };
|
||||
|
||||
public sealed class DiskDsk : Disk525
|
||||
{
|
||||
public DiskDsk(string name, byte[] data, bool isWriteProtected, SectorSkew sectorSkew) :
|
||||
base(name, data, isWriteProtected)
|
||||
{
|
||||
_sectorSkew = SectorSkewMode[(int)sectorSkew];
|
||||
}
|
||||
|
||||
public DiskDsk(string name, Stream stream, bool isWriteProtected, SectorSkew sectorSkew) :
|
||||
base(name, new byte[TrackCount * SectorCount * SectorSize], isWriteProtected)
|
||||
{
|
||||
if (stream == null)
|
||||
{
|
||||
throw new ArgumentNullException("stream");
|
||||
}
|
||||
|
||||
stream.ReadBlock(Data);
|
||||
_sectorSkew = SectorSkewMode[(int)sectorSkew];
|
||||
}
|
||||
|
||||
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 + _sectorSkew[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 + _sectorSkew[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 int[] _sectorSkew;
|
||||
private const int Volume = 0xFE;
|
||||
|
||||
private static readonly byte[] SwapBits = { 0, 2, 1, 3 };
|
||||
|
||||
private static readonly int[] SectorSkewNone = new int[SectorCount]
|
||||
{
|
||||
0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF
|
||||
};
|
||||
|
||||
private static readonly int[] SectorSkewDos = new int[SectorCount]
|
||||
{
|
||||
0x0, 0x7, 0xE, 0x6, 0xD, 0x5, 0xC, 0x4, 0xB, 0x3, 0xA, 0x2, 0x9, 0x1, 0x8, 0xF
|
||||
};
|
||||
|
||||
private static readonly int[] SectorSkewProDos = new int[SectorCount]
|
||||
{
|
||||
0x0, 0x8, 0x1, 0x9, 0x2, 0xA, 0x3, 0xB, 0x4, 0xC, 0x5, 0xD, 0x6, 0xE, 0x7, 0xF
|
||||
};
|
||||
|
||||
private const int SectorSkewCount = 3;
|
||||
|
||||
private static readonly int[][] SectorSkewMode = new int[SectorSkewCount][]
|
||||
{
|
||||
SectorSkewNone, SectorSkewDos, SectorSkewProDos
|
||||
};
|
||||
|
||||
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;
|
||||
using System.IO;
|
||||
using Jellyfish.Library;
|
||||
|
||||
namespace Jellyfish.Virtu
|
||||
{
|
||||
public enum SectorSkew { None = 0, Dos, ProDos };
|
||||
|
||||
public sealed class DiskDsk : Disk525
|
||||
{
|
||||
public DiskDsk(string name, byte[] data, bool isWriteProtected, SectorSkew sectorSkew) :
|
||||
base(name, data, isWriteProtected)
|
||||
{
|
||||
_sectorSkew = SectorSkewMode[(int)sectorSkew];
|
||||
}
|
||||
|
||||
public DiskDsk(string name, Stream stream, bool isWriteProtected, SectorSkew sectorSkew) :
|
||||
base(name, new byte[TrackCount * SectorCount * SectorSize], isWriteProtected)
|
||||
{
|
||||
if (stream == null)
|
||||
{
|
||||
throw new ArgumentNullException("stream");
|
||||
}
|
||||
|
||||
stream.ReadBlock(Data);
|
||||
_sectorSkew = SectorSkewMode[(int)sectorSkew];
|
||||
}
|
||||
|
||||
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 + _sectorSkew[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 + _sectorSkew[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 int[] _sectorSkew;
|
||||
private const int Volume = 0xFE;
|
||||
|
||||
private static readonly byte[] SwapBits = { 0, 2, 1, 3 };
|
||||
|
||||
private static readonly int[] SectorSkewNone = new int[SectorCount]
|
||||
{
|
||||
0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF
|
||||
};
|
||||
|
||||
private static readonly int[] SectorSkewDos = new int[SectorCount]
|
||||
{
|
||||
0x0, 0x7, 0xE, 0x6, 0xD, 0x5, 0xC, 0x4, 0xB, 0x3, 0xA, 0x2, 0x9, 0x1, 0x8, 0xF
|
||||
};
|
||||
|
||||
private static readonly int[] SectorSkewProDos = new int[SectorCount]
|
||||
{
|
||||
0x0, 0x8, 0x1, 0x9, 0x2, 0xA, 0x3, 0xB, 0x4, 0xC, 0x5, 0xD, 0x6, 0xE, 0x7, 0xF
|
||||
};
|
||||
|
||||
private const int SectorSkewCount = 3;
|
||||
|
||||
private static readonly int[][] SectorSkewMode = new int[SectorSkewCount][]
|
||||
{
|
||||
SectorSkewNone, SectorSkewDos, SectorSkewProDos
|
||||
};
|
||||
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1,287 +1,287 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using Jellyfish.Library;
|
||||
using Jellyfish.Virtu.Services;
|
||||
|
||||
namespace Jellyfish.Virtu
|
||||
{
|
||||
public sealed class DiskIIController : PeripheralCard
|
||||
{
|
||||
public DiskIIController(Machine machine) :
|
||||
base(machine)
|
||||
{
|
||||
Drive1 = new DiskIIDrive(machine);
|
||||
Drive2 = new DiskIIDrive(machine);
|
||||
|
||||
Drives = new Collection<DiskIIDrive> { Drive1, Drive2 };
|
||||
|
||||
BootDrive = Drive1;
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
StorageService.LoadResource("Roms/DiskII.rom", stream => stream.ReadBlock(_romRegionC1C7));
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
_phaseStates = 0;
|
||||
SetMotorOn(false);
|
||||
SetDriveNumber(0);
|
||||
_loadMode = false;
|
||||
_writeMode = false;
|
||||
}
|
||||
|
||||
public override void LoadState(BinaryReader reader, Version version)
|
||||
{
|
||||
if (reader == null)
|
||||
{
|
||||
throw new ArgumentNullException("reader");
|
||||
}
|
||||
|
||||
_latch = reader.ReadInt32();
|
||||
_phaseStates = reader.ReadInt32();
|
||||
_motorOn = reader.ReadBoolean();
|
||||
_driveNumber = reader.ReadInt32();
|
||||
_loadMode = reader.ReadBoolean();
|
||||
_writeMode = reader.ReadBoolean();
|
||||
_driveSpin = reader.ReadBoolean();
|
||||
foreach (var drive in Drives)
|
||||
{
|
||||
DebugService.WriteMessage("Loading machine '{0}'", drive.GetType().Name);
|
||||
drive.LoadState(reader, version);
|
||||
//DebugService.WriteMessage("Loaded machine '{0}'", drive.GetType().Name);
|
||||
}
|
||||
}
|
||||
|
||||
public override void SaveState(BinaryWriter writer)
|
||||
{
|
||||
if (writer == null)
|
||||
{
|
||||
throw new ArgumentNullException("writer");
|
||||
}
|
||||
|
||||
writer.Write(_latch);
|
||||
writer.Write(_phaseStates);
|
||||
writer.Write(_motorOn);
|
||||
writer.Write(_driveNumber);
|
||||
writer.Write(_loadMode);
|
||||
writer.Write(_writeMode);
|
||||
writer.Write(_driveSpin);
|
||||
foreach (var drive in Drives)
|
||||
{
|
||||
DebugService.WriteMessage("Saving machine '{0}'", drive.GetType().Name);
|
||||
drive.SaveState(writer);
|
||||
//DebugService.WriteMessage("Saved machine '{0}'", drive.GetType().Name);
|
||||
}
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
|
||||
public override int ReadIoRegionC0C0(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 ReadFloatingBus();
|
||||
}
|
||||
|
||||
public override int ReadIoRegionC1C7(int address)
|
||||
{
|
||||
return _romRegionC1C7[address & 0xFF];
|
||||
}
|
||||
|
||||
public override void WriteIoRegionC0C0(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);
|
||||
}
|
||||
}
|
||||
|
||||
public DiskIIDrive Drive1 { get; private set; }
|
||||
public DiskIIDrive Drive2 { get; private set; }
|
||||
|
||||
public Collection<DiskIIDrive> Drives { get; private set; }
|
||||
|
||||
public DiskIIDrive BootDrive { get; private set; }
|
||||
|
||||
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 int _latch;
|
||||
private int _phaseStates;
|
||||
private bool _motorOn;
|
||||
private int _driveNumber;
|
||||
private bool _loadMode;
|
||||
private bool _writeMode;
|
||||
private bool _driveSpin;
|
||||
|
||||
private byte[] _romRegionC1C7 = new byte[0x0100];
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using Jellyfish.Library;
|
||||
using Jellyfish.Virtu.Services;
|
||||
|
||||
namespace Jellyfish.Virtu
|
||||
{
|
||||
public sealed class DiskIIController : PeripheralCard
|
||||
{
|
||||
public DiskIIController(Machine machine) :
|
||||
base(machine)
|
||||
{
|
||||
Drive1 = new DiskIIDrive(machine);
|
||||
Drive2 = new DiskIIDrive(machine);
|
||||
|
||||
Drives = new Collection<DiskIIDrive> { Drive1, Drive2 };
|
||||
|
||||
BootDrive = Drive1;
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
StorageService.LoadResource("Roms/DiskII.rom", stream => stream.ReadBlock(_romRegionC1C7));
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
_phaseStates = 0;
|
||||
SetMotorOn(false);
|
||||
SetDriveNumber(0);
|
||||
_loadMode = false;
|
||||
_writeMode = false;
|
||||
}
|
||||
|
||||
public override void LoadState(BinaryReader reader, Version version)
|
||||
{
|
||||
if (reader == null)
|
||||
{
|
||||
throw new ArgumentNullException("reader");
|
||||
}
|
||||
|
||||
_latch = reader.ReadInt32();
|
||||
_phaseStates = reader.ReadInt32();
|
||||
_motorOn = reader.ReadBoolean();
|
||||
_driveNumber = reader.ReadInt32();
|
||||
_loadMode = reader.ReadBoolean();
|
||||
_writeMode = reader.ReadBoolean();
|
||||
_driveSpin = reader.ReadBoolean();
|
||||
foreach (var drive in Drives)
|
||||
{
|
||||
DebugService.WriteMessage("Loading machine '{0}'", drive.GetType().Name);
|
||||
drive.LoadState(reader, version);
|
||||
//DebugService.WriteMessage("Loaded machine '{0}'", drive.GetType().Name);
|
||||
}
|
||||
}
|
||||
|
||||
public override void SaveState(BinaryWriter writer)
|
||||
{
|
||||
if (writer == null)
|
||||
{
|
||||
throw new ArgumentNullException("writer");
|
||||
}
|
||||
|
||||
writer.Write(_latch);
|
||||
writer.Write(_phaseStates);
|
||||
writer.Write(_motorOn);
|
||||
writer.Write(_driveNumber);
|
||||
writer.Write(_loadMode);
|
||||
writer.Write(_writeMode);
|
||||
writer.Write(_driveSpin);
|
||||
foreach (var drive in Drives)
|
||||
{
|
||||
DebugService.WriteMessage("Saving machine '{0}'", drive.GetType().Name);
|
||||
drive.SaveState(writer);
|
||||
//DebugService.WriteMessage("Saved machine '{0}'", drive.GetType().Name);
|
||||
}
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
|
||||
public override int ReadIoRegionC0C0(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 ReadFloatingBus();
|
||||
}
|
||||
|
||||
public override int ReadIoRegionC1C7(int address)
|
||||
{
|
||||
return _romRegionC1C7[address & 0xFF];
|
||||
}
|
||||
|
||||
public override void WriteIoRegionC0C0(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);
|
||||
}
|
||||
}
|
||||
|
||||
public DiskIIDrive Drive1 { get; private set; }
|
||||
public DiskIIDrive Drive2 { get; private set; }
|
||||
|
||||
public Collection<DiskIIDrive> Drives { get; private set; }
|
||||
|
||||
public DiskIIDrive BootDrive { get; private set; }
|
||||
|
||||
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 int _latch;
|
||||
private int _phaseStates;
|
||||
private bool _motorOn;
|
||||
private int _driveNumber;
|
||||
private bool _loadMode;
|
||||
private bool _writeMode;
|
||||
private bool _driveSpin;
|
||||
|
||||
private byte[] _romRegionC1C7 = new byte[0x0100];
|
||||
}
|
||||
}
|
||||
|
@ -1,172 +1,172 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Jellyfish.Library;
|
||||
using Jellyfish.Virtu.Services;
|
||||
|
||||
namespace Jellyfish.Virtu
|
||||
{
|
||||
public sealed class DiskIIDrive : MachineComponent
|
||||
{
|
||||
public DiskIIDrive(Machine machine) :
|
||||
base(machine)
|
||||
{
|
||||
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 override void LoadState(BinaryReader reader, Version version)
|
||||
{
|
||||
if (reader == null)
|
||||
{
|
||||
throw new ArgumentNullException("reader");
|
||||
}
|
||||
|
||||
_trackLoaded = reader.ReadBoolean();
|
||||
_trackChanged = reader.ReadBoolean();
|
||||
_trackNumber = reader.ReadInt32();
|
||||
_trackOffset = reader.ReadInt32();
|
||||
if (_trackLoaded)
|
||||
{
|
||||
reader.Read(_trackData, 0, _trackData.Length);
|
||||
}
|
||||
if (reader.ReadBoolean())
|
||||
{
|
||||
DebugService.WriteMessage("Loading machine '{0}'", typeof(Disk525).Name);
|
||||
_disk = Disk525.LoadState(reader, version);
|
||||
}
|
||||
else
|
||||
{
|
||||
_disk = null;
|
||||
}
|
||||
}
|
||||
|
||||
public override void SaveState(BinaryWriter writer)
|
||||
{
|
||||
if (writer == null)
|
||||
{
|
||||
throw new ArgumentNullException("writer");
|
||||
}
|
||||
|
||||
writer.Write(_trackLoaded);
|
||||
writer.Write(_trackChanged);
|
||||
writer.Write(_trackNumber);
|
||||
writer.Write(_trackOffset);
|
||||
if (_trackLoaded)
|
||||
{
|
||||
writer.Write(_trackData);
|
||||
}
|
||||
writer.Write(_disk != null);
|
||||
if (_disk != null)
|
||||
{
|
||||
DebugService.WriteMessage("Saving machine '{0}'", _disk.GetType().Name);
|
||||
_disk.SaveState(writer);
|
||||
}
|
||||
}
|
||||
|
||||
public void InsertDisk(string name, Stream stream, bool isWriteProtected)
|
||||
{
|
||||
DebugService.WriteMessage("Inserting disk '{0}'", name);
|
||||
FlushTrack();
|
||||
_disk = Disk525.CreateDisk(name, stream, isWriteProtected);
|
||||
_trackLoaded = false;
|
||||
}
|
||||
|
||||
public void RemoveDisk()
|
||||
{
|
||||
if (_disk != null)
|
||||
{
|
||||
DebugService.WriteMessage("Removing disk '{0}'", _disk.Name);
|
||||
_trackLoaded = false;
|
||||
_trackChanged = false;
|
||||
_trackNumber = 0;
|
||||
_trackOffset = 0;
|
||||
_disk = null;
|
||||
}
|
||||
}
|
||||
|
||||
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 bool _trackLoaded;
|
||||
private bool _trackChanged;
|
||||
private int _trackNumber;
|
||||
private int _trackOffset;
|
||||
private byte[] _trackData = new byte[Disk525.TrackSize];
|
||||
private Disk525 _disk;
|
||||
|
||||
private Random _random = new Random();
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.IO;
|
||||
using Jellyfish.Library;
|
||||
using Jellyfish.Virtu.Services;
|
||||
|
||||
namespace Jellyfish.Virtu
|
||||
{
|
||||
public sealed class DiskIIDrive : MachineComponent
|
||||
{
|
||||
public DiskIIDrive(Machine machine) :
|
||||
base(machine)
|
||||
{
|
||||
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 override void LoadState(BinaryReader reader, Version version)
|
||||
{
|
||||
if (reader == null)
|
||||
{
|
||||
throw new ArgumentNullException("reader");
|
||||
}
|
||||
|
||||
_trackLoaded = reader.ReadBoolean();
|
||||
_trackChanged = reader.ReadBoolean();
|
||||
_trackNumber = reader.ReadInt32();
|
||||
_trackOffset = reader.ReadInt32();
|
||||
if (_trackLoaded)
|
||||
{
|
||||
reader.Read(_trackData, 0, _trackData.Length);
|
||||
}
|
||||
if (reader.ReadBoolean())
|
||||
{
|
||||
DebugService.WriteMessage("Loading machine '{0}'", typeof(Disk525).Name);
|
||||
_disk = Disk525.LoadState(reader, version);
|
||||
}
|
||||
else
|
||||
{
|
||||
_disk = null;
|
||||
}
|
||||
}
|
||||
|
||||
public override void SaveState(BinaryWriter writer)
|
||||
{
|
||||
if (writer == null)
|
||||
{
|
||||
throw new ArgumentNullException("writer");
|
||||
}
|
||||
|
||||
writer.Write(_trackLoaded);
|
||||
writer.Write(_trackChanged);
|
||||
writer.Write(_trackNumber);
|
||||
writer.Write(_trackOffset);
|
||||
if (_trackLoaded)
|
||||
{
|
||||
writer.Write(_trackData);
|
||||
}
|
||||
writer.Write(_disk != null);
|
||||
if (_disk != null)
|
||||
{
|
||||
DebugService.WriteMessage("Saving machine '{0}'", _disk.GetType().Name);
|
||||
_disk.SaveState(writer);
|
||||
}
|
||||
}
|
||||
|
||||
public void InsertDisk(string name, Stream stream, bool isWriteProtected)
|
||||
{
|
||||
DebugService.WriteMessage("Inserting disk '{0}'", name);
|
||||
FlushTrack();
|
||||
_disk = Disk525.CreateDisk(name, stream, isWriteProtected);
|
||||
_trackLoaded = false;
|
||||
}
|
||||
|
||||
public void RemoveDisk()
|
||||
{
|
||||
if (_disk != null)
|
||||
{
|
||||
DebugService.WriteMessage("Removing disk '{0}'", _disk.Name);
|
||||
_trackLoaded = false;
|
||||
_trackChanged = false;
|
||||
_trackNumber = 0;
|
||||
_trackOffset = 0;
|
||||
_disk = null;
|
||||
}
|
||||
}
|
||||
|
||||
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 bool _trackLoaded;
|
||||
private bool _trackChanged;
|
||||
private int _trackNumber;
|
||||
private int _trackOffset;
|
||||
private byte[] _trackData = new byte[Disk525.TrackSize];
|
||||
private Disk525 _disk;
|
||||
|
||||
private Random _random = new Random();
|
||||
}
|
||||
}
|
||||
|
@ -1,35 +1,35 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Jellyfish.Library;
|
||||
|
||||
namespace Jellyfish.Virtu
|
||||
{
|
||||
public sealed class DiskNib : Disk525
|
||||
{
|
||||
public DiskNib(string name, byte[] data, bool isWriteProtected) :
|
||||
base(name, data, isWriteProtected)
|
||||
{
|
||||
}
|
||||
|
||||
public DiskNib(string name, Stream stream, bool isWriteProtected) :
|
||||
base(name, new byte[TrackCount * TrackSize], isWriteProtected)
|
||||
{
|
||||
if (stream == null)
|
||||
{
|
||||
throw new ArgumentNullException("stream");
|
||||
}
|
||||
|
||||
stream.ReadBlock(Data);
|
||||
}
|
||||
|
||||
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;
|
||||
using System.IO;
|
||||
using Jellyfish.Library;
|
||||
|
||||
namespace Jellyfish.Virtu
|
||||
{
|
||||
public sealed class DiskNib : Disk525
|
||||
{
|
||||
public DiskNib(string name, byte[] data, bool isWriteProtected) :
|
||||
base(name, data, isWriteProtected)
|
||||
{
|
||||
}
|
||||
|
||||
public DiskNib(string name, Stream stream, bool isWriteProtected) :
|
||||
base(name, new byte[TrackCount * TrackSize], isWriteProtected)
|
||||
{
|
||||
if (stream == null)
|
||||
{
|
||||
throw new ArgumentNullException("stream");
|
||||
}
|
||||
|
||||
stream.ReadBlock(Data);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,370 +1,370 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using Jellyfish.Library;
|
||||
using Jellyfish.Virtu.Services;
|
||||
|
||||
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>();
|
||||
|
||||
JoystickDeadZone = 0.4f;
|
||||
|
||||
InvertPaddles = true; // Raster Blaster
|
||||
SwapPaddles = true;
|
||||
Joystick0TouchX = 0.35f;
|
||||
Joystick0TouchY = 0.6f;
|
||||
Joystick0TouchWidth = 0.25f;
|
||||
Joystick0TouchHeight = 0.4f;
|
||||
Joystick0TouchRadius = 0.2f;
|
||||
Joystick0TouchKeepLast = true;
|
||||
Button0TouchX = 0;
|
||||
Button0TouchY = 0;
|
||||
Button0TouchWidth = 0.5f;
|
||||
Button0TouchHeight = 1;
|
||||
Button1TouchX = 0.5f;
|
||||
Button1TouchY = 0;
|
||||
Button1TouchWidth = 0.5f;
|
||||
Button1TouchHeight = 1;
|
||||
Button2TouchX = 0.75f;
|
||||
Button2TouchY = 0;
|
||||
Button2TouchWidth = 0.25f;
|
||||
Button2TouchHeight = 0.25f;
|
||||
Button2TouchOrder = 1;
|
||||
}
|
||||
|
||||
public override void LoadState(BinaryReader reader, Version version)
|
||||
{
|
||||
if (reader == null)
|
||||
{
|
||||
throw new ArgumentNullException("reader");
|
||||
}
|
||||
|
||||
InvertPaddles = reader.ReadBoolean();
|
||||
SwapPaddles = reader.ReadBoolean();
|
||||
UseShiftKeyMod = reader.ReadBoolean();
|
||||
JoystickDeadZone = reader.ReadSingle();
|
||||
|
||||
UseKeyboard = reader.ReadBoolean();
|
||||
Joystick0UpLeftKey = reader.ReadInt32();
|
||||
Joystick0UpKey = reader.ReadInt32();
|
||||
Joystick0UpRightKey = reader.ReadInt32();
|
||||
Joystick0LeftKey = reader.ReadInt32();
|
||||
Joystick0RightKey = reader.ReadInt32();
|
||||
Joystick0DownLeftKey = reader.ReadInt32();
|
||||
Joystick0DownKey = reader.ReadInt32();
|
||||
Joystick0DownRightKey = reader.ReadInt32();
|
||||
Joystick1UpLeftKey = reader.ReadInt32();
|
||||
Joystick1UpKey = reader.ReadInt32();
|
||||
Joystick1UpRightKey = reader.ReadInt32();
|
||||
Joystick1LeftKey = reader.ReadInt32();
|
||||
Joystick1RightKey = reader.ReadInt32();
|
||||
Joystick1DownLeftKey = reader.ReadInt32();
|
||||
Joystick1DownKey = reader.ReadInt32();
|
||||
Joystick1DownRightKey = reader.ReadInt32();
|
||||
Button0Key = reader.ReadInt32();
|
||||
Button1Key = reader.ReadInt32();
|
||||
Button2Key = reader.ReadInt32();
|
||||
|
||||
UseTouch = reader.ReadBoolean();
|
||||
Joystick0TouchX = reader.ReadSingle();
|
||||
Joystick0TouchY = reader.ReadSingle();
|
||||
Joystick0TouchWidth = reader.ReadSingle();
|
||||
Joystick0TouchHeight = reader.ReadSingle();
|
||||
Joystick0TouchOrder = reader.ReadInt32();
|
||||
Joystick0TouchRadius = reader.ReadSingle();
|
||||
Joystick0TouchKeepLast = reader.ReadBoolean();
|
||||
Joystick1TouchX = reader.ReadSingle();
|
||||
Joystick1TouchY = reader.ReadSingle();
|
||||
Joystick1TouchWidth = reader.ReadSingle();
|
||||
Joystick1TouchHeight = reader.ReadSingle();
|
||||
Joystick1TouchOrder = reader.ReadInt32();
|
||||
Joystick1TouchRadius = reader.ReadSingle();
|
||||
Joystick1TouchKeepLast = reader.ReadBoolean();
|
||||
Button0TouchX = reader.ReadSingle();
|
||||
Button0TouchY = reader.ReadSingle();
|
||||
Button0TouchWidth = reader.ReadSingle();
|
||||
Button0TouchHeight = reader.ReadSingle();
|
||||
Button0TouchOrder = reader.ReadInt32();
|
||||
Button1TouchX = reader.ReadSingle();
|
||||
Button1TouchY = reader.ReadSingle();
|
||||
Button1TouchWidth = reader.ReadSingle();
|
||||
Button1TouchHeight = reader.ReadSingle();
|
||||
Button1TouchOrder = reader.ReadInt32();
|
||||
Button2TouchX = reader.ReadSingle();
|
||||
Button2TouchY = reader.ReadSingle();
|
||||
Button2TouchWidth = reader.ReadSingle();
|
||||
Button2TouchHeight = reader.ReadSingle();
|
||||
Button2TouchOrder = reader.ReadInt32();
|
||||
}
|
||||
|
||||
public override void SaveState(BinaryWriter writer)
|
||||
{
|
||||
if (writer == null)
|
||||
{
|
||||
throw new ArgumentNullException("writer");
|
||||
}
|
||||
|
||||
writer.Write(InvertPaddles);
|
||||
writer.Write(SwapPaddles);
|
||||
writer.Write(UseShiftKeyMod);
|
||||
writer.Write(JoystickDeadZone);
|
||||
|
||||
writer.Write(UseKeyboard);
|
||||
writer.Write(Joystick0UpLeftKey);
|
||||
writer.Write(Joystick0UpKey);
|
||||
writer.Write(Joystick0UpRightKey);
|
||||
writer.Write(Joystick0LeftKey);
|
||||
writer.Write(Joystick0RightKey);
|
||||
writer.Write(Joystick0DownLeftKey);
|
||||
writer.Write(Joystick0DownKey);
|
||||
writer.Write(Joystick0DownRightKey);
|
||||
writer.Write(Joystick1UpLeftKey);
|
||||
writer.Write(Joystick1UpKey);
|
||||
writer.Write(Joystick1UpRightKey);
|
||||
writer.Write(Joystick1LeftKey);
|
||||
writer.Write(Joystick1RightKey);
|
||||
writer.Write(Joystick1DownLeftKey);
|
||||
writer.Write(Joystick1DownKey);
|
||||
writer.Write(Joystick1DownRightKey);
|
||||
writer.Write(Button0Key);
|
||||
writer.Write(Button1Key);
|
||||
writer.Write(Button2Key);
|
||||
|
||||
writer.Write(UseTouch);
|
||||
writer.Write(Joystick0TouchX);
|
||||
writer.Write(Joystick0TouchY);
|
||||
writer.Write(Joystick0TouchWidth);
|
||||
writer.Write(Joystick0TouchHeight);
|
||||
writer.Write(Joystick0TouchOrder);
|
||||
writer.Write(Joystick0TouchRadius);
|
||||
writer.Write(Joystick0TouchKeepLast);
|
||||
writer.Write(Joystick1TouchX);
|
||||
writer.Write(Joystick1TouchY);
|
||||
writer.Write(Joystick1TouchWidth);
|
||||
writer.Write(Joystick1TouchHeight);
|
||||
writer.Write(Joystick1TouchOrder);
|
||||
writer.Write(Joystick1TouchRadius);
|
||||
writer.Write(Joystick1TouchKeepLast);
|
||||
writer.Write(Button0TouchX);
|
||||
writer.Write(Button0TouchY);
|
||||
writer.Write(Button0TouchWidth);
|
||||
writer.Write(Button0TouchHeight);
|
||||
writer.Write(Button0TouchOrder);
|
||||
writer.Write(Button1TouchX);
|
||||
writer.Write(Button1TouchY);
|
||||
writer.Write(Button1TouchWidth);
|
||||
writer.Write(Button1TouchHeight);
|
||||
writer.Write(Button1TouchOrder);
|
||||
writer.Write(Button2TouchX);
|
||||
writer.Write(Button2TouchY);
|
||||
writer.Write(Button2TouchWidth);
|
||||
writer.Write(Button2TouchHeight);
|
||||
writer.Write(Button2TouchOrder);
|
||||
}
|
||||
|
||||
public bool ReadButton0()
|
||||
{
|
||||
return (_gamePortService.IsButton0Down || _keyboardService.IsOpenAppleKeyDown ||
|
||||
(UseKeyboard && (Button0Key > 0) && _keyboardService.IsKeyDown(Button0Key)));
|
||||
}
|
||||
|
||||
public bool ReadButton1()
|
||||
{
|
||||
return (_gamePortService.IsButton1Down || _keyboardService.IsCloseAppleKeyDown ||
|
||||
(UseKeyboard && (Button1Key > 0) && _keyboardService.IsKeyDown(Button1Key)));
|
||||
}
|
||||
|
||||
public bool ReadButton2()
|
||||
{
|
||||
return (_gamePortService.IsButton2Down || (UseShiftKeyMod && !_keyboardService.IsShiftKeyDown) || // Shift' [TN9]
|
||||
(UseKeyboard && (Button2Key > 0) && _keyboardService.IsKeyDown(Button2Key)));
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
|
||||
public void TriggerTimers()
|
||||
{
|
||||
int paddle0 = _gamePortService.Paddle0;
|
||||
int paddle1 = _gamePortService.Paddle1;
|
||||
int paddle2 = _gamePortService.Paddle2;
|
||||
int paddle3 = _gamePortService.Paddle3;
|
||||
|
||||
if (UseKeyboard) // override
|
||||
{
|
||||
if (((Joystick0UpLeftKey > 0) && _keyboardService.IsKeyDown(Joystick0UpLeftKey)) ||
|
||||
((Joystick0LeftKey > 0) && _keyboardService.IsKeyDown(Joystick0LeftKey)) ||
|
||||
((Joystick0DownLeftKey > 0) && _keyboardService.IsKeyDown(Joystick0DownLeftKey)))
|
||||
{
|
||||
paddle0 -= PaddleScale;
|
||||
}
|
||||
if (((Joystick0UpRightKey > 0) && _keyboardService.IsKeyDown(Joystick0UpRightKey)) ||
|
||||
((Joystick0RightKey > 0) && _keyboardService.IsKeyDown(Joystick0RightKey)) ||
|
||||
((Joystick0DownRightKey > 0) && _keyboardService.IsKeyDown(Joystick0DownRightKey)))
|
||||
{
|
||||
paddle0 += PaddleScale;
|
||||
}
|
||||
if (((Joystick0UpLeftKey > 0) && _keyboardService.IsKeyDown(Joystick0UpLeftKey)) ||
|
||||
((Joystick0UpKey > 0) && _keyboardService.IsKeyDown(Joystick0UpKey)) ||
|
||||
((Joystick0UpRightKey > 0) && _keyboardService.IsKeyDown(Joystick0UpRightKey)))
|
||||
{
|
||||
paddle1 -= PaddleScale;
|
||||
}
|
||||
if (((Joystick0DownLeftKey > 0) && _keyboardService.IsKeyDown(Joystick0DownLeftKey)) ||
|
||||
((Joystick0DownKey > 0) && _keyboardService.IsKeyDown(Joystick0DownKey)) ||
|
||||
((Joystick0DownRightKey > 0) && _keyboardService.IsKeyDown(Joystick0DownRightKey)))
|
||||
{
|
||||
paddle1 += PaddleScale;
|
||||
}
|
||||
if (((Joystick1UpLeftKey > 0) && _keyboardService.IsKeyDown(Joystick1UpLeftKey)) ||
|
||||
((Joystick1LeftKey > 0) && _keyboardService.IsKeyDown(Joystick1LeftKey)) ||
|
||||
((Joystick1DownLeftKey > 0) && _keyboardService.IsKeyDown(Joystick1DownLeftKey)))
|
||||
{
|
||||
paddle2 -= PaddleScale;
|
||||
}
|
||||
if (((Joystick1UpRightKey > 0) && _keyboardService.IsKeyDown(Joystick1UpRightKey)) ||
|
||||
((Joystick1RightKey > 0) && _keyboardService.IsKeyDown(Joystick1RightKey)) ||
|
||||
((Joystick1DownRightKey > 0) && _keyboardService.IsKeyDown(Joystick1DownRightKey)))
|
||||
{
|
||||
paddle2 += PaddleScale;
|
||||
}
|
||||
if (((Joystick1UpLeftKey > 0) && _keyboardService.IsKeyDown(Joystick1UpLeftKey)) ||
|
||||
((Joystick1UpKey > 0) && _keyboardService.IsKeyDown(Joystick1UpKey)) ||
|
||||
((Joystick1UpRightKey > 0) && _keyboardService.IsKeyDown(Joystick1UpRightKey)))
|
||||
{
|
||||
paddle3 -= PaddleScale;
|
||||
}
|
||||
if (((Joystick1DownLeftKey > 0) && _keyboardService.IsKeyDown(Joystick1DownLeftKey)) ||
|
||||
((Joystick1DownKey > 0) && _keyboardService.IsKeyDown(Joystick1DownKey)) ||
|
||||
((Joystick1DownRightKey > 0) && _keyboardService.IsKeyDown(Joystick1DownRightKey)))
|
||||
{
|
||||
paddle3 += PaddleScale;
|
||||
}
|
||||
}
|
||||
if (InvertPaddles)
|
||||
{
|
||||
paddle0 = 2 * PaddleScale - paddle0;
|
||||
paddle1 = 2 * PaddleScale - paddle1;
|
||||
paddle2 = 2 * PaddleScale - paddle2;
|
||||
paddle3 = 2 * PaddleScale - paddle3;
|
||||
}
|
||||
|
||||
Paddle0Strobe = true;
|
||||
Paddle1Strobe = true;
|
||||
Paddle2Strobe = true;
|
||||
Paddle3Strobe = true;
|
||||
|
||||
Machine.Events.AddEvent(MathHelpers.ClampByte(SwapPaddles ? paddle1 : paddle0) * CyclesPerValue, _resetPaddle0StrobeEvent); // [7-29]
|
||||
Machine.Events.AddEvent(MathHelpers.ClampByte(SwapPaddles ? paddle0 : paddle1) * CyclesPerValue, _resetPaddle1StrobeEvent);
|
||||
Machine.Events.AddEvent(MathHelpers.ClampByte(SwapPaddles ? paddle3 : paddle2) * CyclesPerValue, _resetPaddle2StrobeEvent);
|
||||
Machine.Events.AddEvent(MathHelpers.ClampByte(SwapPaddles ? paddle2 : paddle3) * CyclesPerValue, _resetPaddle3StrobeEvent);
|
||||
}
|
||||
|
||||
private void ResetPaddle0StrobeEvent()
|
||||
{
|
||||
Paddle0Strobe = false;
|
||||
}
|
||||
|
||||
private void ResetPaddle1StrobeEvent()
|
||||
{
|
||||
Paddle1Strobe = false;
|
||||
}
|
||||
|
||||
private void ResetPaddle2StrobeEvent()
|
||||
{
|
||||
Paddle2Strobe = false;
|
||||
}
|
||||
|
||||
private void ResetPaddle3StrobeEvent()
|
||||
{
|
||||
Paddle3Strobe = false;
|
||||
}
|
||||
|
||||
public const int PaddleScale = 128;
|
||||
|
||||
public bool InvertPaddles { get; set; }
|
||||
public bool SwapPaddles { get; set; }
|
||||
public bool UseShiftKeyMod { get; set; }
|
||||
public float JoystickDeadZone { get; set; }
|
||||
|
||||
public bool UseKeyboard { get; set; }
|
||||
public int Joystick0UpLeftKey { get; set; }
|
||||
public int Joystick0UpKey { get; set; }
|
||||
public int Joystick0UpRightKey { get; set; }
|
||||
public int Joystick0LeftKey { get; set; }
|
||||
public int Joystick0RightKey { get; set; }
|
||||
public int Joystick0DownLeftKey { get; set; }
|
||||
public int Joystick0DownKey { get; set; }
|
||||
public int Joystick0DownRightKey { get; set; }
|
||||
public int Joystick1UpLeftKey { get; set; }
|
||||
public int Joystick1UpKey { get; set; }
|
||||
public int Joystick1UpRightKey { get; set; }
|
||||
public int Joystick1LeftKey { get; set; }
|
||||
public int Joystick1RightKey { get; set; }
|
||||
public int Joystick1DownLeftKey { get; set; }
|
||||
public int Joystick1DownKey { get; set; }
|
||||
public int Joystick1DownRightKey { get; set; }
|
||||
public int Button0Key { get; set; }
|
||||
public int Button1Key { get; set; }
|
||||
public int Button2Key { get; set; }
|
||||
|
||||
public bool UseTouch { get; set; }
|
||||
public float Joystick0TouchX { get; set; }
|
||||
public float Joystick0TouchY { get; set; }
|
||||
public float Joystick0TouchWidth { get; set; }
|
||||
public float Joystick0TouchHeight { get; set; }
|
||||
public int Joystick0TouchOrder { get; set; }
|
||||
public float Joystick0TouchRadius { get; set; }
|
||||
public bool Joystick0TouchKeepLast { get; set; }
|
||||
public float Joystick1TouchX { get; set; }
|
||||
public float Joystick1TouchY { get; set; }
|
||||
public float Joystick1TouchWidth { get; set; }
|
||||
public float Joystick1TouchHeight { get; set; }
|
||||
public int Joystick1TouchOrder { get; set; }
|
||||
public float Joystick1TouchRadius { get; set; }
|
||||
public bool Joystick1TouchKeepLast { get; set; }
|
||||
public float Button0TouchX { get; set; }
|
||||
public float Button0TouchY { get; set; }
|
||||
public float Button0TouchWidth { get; set; }
|
||||
public float Button0TouchHeight { get; set; }
|
||||
public int Button0TouchOrder { get; set; }
|
||||
public float Button1TouchX { get; set; }
|
||||
public float Button1TouchY { get; set; }
|
||||
public float Button1TouchWidth { get; set; }
|
||||
public float Button1TouchHeight { get; set; }
|
||||
public int Button1TouchOrder { get; set; }
|
||||
public float Button2TouchX { get; set; }
|
||||
public float Button2TouchY { get; set; }
|
||||
public float Button2TouchWidth { get; set; }
|
||||
public float Button2TouchHeight { get; set; }
|
||||
public int Button2TouchOrder { get; set; }
|
||||
|
||||
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 System.IO;
|
||||
using Jellyfish.Library;
|
||||
using Jellyfish.Virtu.Services;
|
||||
|
||||
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>();
|
||||
|
||||
JoystickDeadZone = 0.4f;
|
||||
|
||||
InvertPaddles = true; // Raster Blaster
|
||||
SwapPaddles = true;
|
||||
Joystick0TouchX = 0.35f;
|
||||
Joystick0TouchY = 0.6f;
|
||||
Joystick0TouchWidth = 0.25f;
|
||||
Joystick0TouchHeight = 0.4f;
|
||||
Joystick0TouchRadius = 0.2f;
|
||||
Joystick0TouchKeepLast = true;
|
||||
Button0TouchX = 0;
|
||||
Button0TouchY = 0;
|
||||
Button0TouchWidth = 0.5f;
|
||||
Button0TouchHeight = 1;
|
||||
Button1TouchX = 0.5f;
|
||||
Button1TouchY = 0;
|
||||
Button1TouchWidth = 0.5f;
|
||||
Button1TouchHeight = 1;
|
||||
Button2TouchX = 0.75f;
|
||||
Button2TouchY = 0;
|
||||
Button2TouchWidth = 0.25f;
|
||||
Button2TouchHeight = 0.25f;
|
||||
Button2TouchOrder = 1;
|
||||
}
|
||||
|
||||
public override void LoadState(BinaryReader reader, Version version)
|
||||
{
|
||||
if (reader == null)
|
||||
{
|
||||
throw new ArgumentNullException("reader");
|
||||
}
|
||||
|
||||
InvertPaddles = reader.ReadBoolean();
|
||||
SwapPaddles = reader.ReadBoolean();
|
||||
UseShiftKeyMod = reader.ReadBoolean();
|
||||
JoystickDeadZone = reader.ReadSingle();
|
||||
|
||||
UseKeyboard = reader.ReadBoolean();
|
||||
Joystick0UpLeftKey = reader.ReadInt32();
|
||||
Joystick0UpKey = reader.ReadInt32();
|
||||
Joystick0UpRightKey = reader.ReadInt32();
|
||||
Joystick0LeftKey = reader.ReadInt32();
|
||||
Joystick0RightKey = reader.ReadInt32();
|
||||
Joystick0DownLeftKey = reader.ReadInt32();
|
||||
Joystick0DownKey = reader.ReadInt32();
|
||||
Joystick0DownRightKey = reader.ReadInt32();
|
||||
Joystick1UpLeftKey = reader.ReadInt32();
|
||||
Joystick1UpKey = reader.ReadInt32();
|
||||
Joystick1UpRightKey = reader.ReadInt32();
|
||||
Joystick1LeftKey = reader.ReadInt32();
|
||||
Joystick1RightKey = reader.ReadInt32();
|
||||
Joystick1DownLeftKey = reader.ReadInt32();
|
||||
Joystick1DownKey = reader.ReadInt32();
|
||||
Joystick1DownRightKey = reader.ReadInt32();
|
||||
Button0Key = reader.ReadInt32();
|
||||
Button1Key = reader.ReadInt32();
|
||||
Button2Key = reader.ReadInt32();
|
||||
|
||||
UseTouch = reader.ReadBoolean();
|
||||
Joystick0TouchX = reader.ReadSingle();
|
||||
Joystick0TouchY = reader.ReadSingle();
|
||||
Joystick0TouchWidth = reader.ReadSingle();
|
||||
Joystick0TouchHeight = reader.ReadSingle();
|
||||
Joystick0TouchOrder = reader.ReadInt32();
|
||||
Joystick0TouchRadius = reader.ReadSingle();
|
||||
Joystick0TouchKeepLast = reader.ReadBoolean();
|
||||
Joystick1TouchX = reader.ReadSingle();
|
||||
Joystick1TouchY = reader.ReadSingle();
|
||||
Joystick1TouchWidth = reader.ReadSingle();
|
||||
Joystick1TouchHeight = reader.ReadSingle();
|
||||
Joystick1TouchOrder = reader.ReadInt32();
|
||||
Joystick1TouchRadius = reader.ReadSingle();
|
||||
Joystick1TouchKeepLast = reader.ReadBoolean();
|
||||
Button0TouchX = reader.ReadSingle();
|
||||
Button0TouchY = reader.ReadSingle();
|
||||
Button0TouchWidth = reader.ReadSingle();
|
||||
Button0TouchHeight = reader.ReadSingle();
|
||||
Button0TouchOrder = reader.ReadInt32();
|
||||
Button1TouchX = reader.ReadSingle();
|
||||
Button1TouchY = reader.ReadSingle();
|
||||
Button1TouchWidth = reader.ReadSingle();
|
||||
Button1TouchHeight = reader.ReadSingle();
|
||||
Button1TouchOrder = reader.ReadInt32();
|
||||
Button2TouchX = reader.ReadSingle();
|
||||
Button2TouchY = reader.ReadSingle();
|
||||
Button2TouchWidth = reader.ReadSingle();
|
||||
Button2TouchHeight = reader.ReadSingle();
|
||||
Button2TouchOrder = reader.ReadInt32();
|
||||
}
|
||||
|
||||
public override void SaveState(BinaryWriter writer)
|
||||
{
|
||||
if (writer == null)
|
||||
{
|
||||
throw new ArgumentNullException("writer");
|
||||
}
|
||||
|
||||
writer.Write(InvertPaddles);
|
||||
writer.Write(SwapPaddles);
|
||||
writer.Write(UseShiftKeyMod);
|
||||
writer.Write(JoystickDeadZone);
|
||||
|
||||
writer.Write(UseKeyboard);
|
||||
writer.Write(Joystick0UpLeftKey);
|
||||
writer.Write(Joystick0UpKey);
|
||||
writer.Write(Joystick0UpRightKey);
|
||||
writer.Write(Joystick0LeftKey);
|
||||
writer.Write(Joystick0RightKey);
|
||||
writer.Write(Joystick0DownLeftKey);
|
||||
writer.Write(Joystick0DownKey);
|
||||
writer.Write(Joystick0DownRightKey);
|
||||
writer.Write(Joystick1UpLeftKey);
|
||||
writer.Write(Joystick1UpKey);
|
||||
writer.Write(Joystick1UpRightKey);
|
||||
writer.Write(Joystick1LeftKey);
|
||||
writer.Write(Joystick1RightKey);
|
||||
writer.Write(Joystick1DownLeftKey);
|
||||
writer.Write(Joystick1DownKey);
|
||||
writer.Write(Joystick1DownRightKey);
|
||||
writer.Write(Button0Key);
|
||||
writer.Write(Button1Key);
|
||||
writer.Write(Button2Key);
|
||||
|
||||
writer.Write(UseTouch);
|
||||
writer.Write(Joystick0TouchX);
|
||||
writer.Write(Joystick0TouchY);
|
||||
writer.Write(Joystick0TouchWidth);
|
||||
writer.Write(Joystick0TouchHeight);
|
||||
writer.Write(Joystick0TouchOrder);
|
||||
writer.Write(Joystick0TouchRadius);
|
||||
writer.Write(Joystick0TouchKeepLast);
|
||||
writer.Write(Joystick1TouchX);
|
||||
writer.Write(Joystick1TouchY);
|
||||
writer.Write(Joystick1TouchWidth);
|
||||
writer.Write(Joystick1TouchHeight);
|
||||
writer.Write(Joystick1TouchOrder);
|
||||
writer.Write(Joystick1TouchRadius);
|
||||
writer.Write(Joystick1TouchKeepLast);
|
||||
writer.Write(Button0TouchX);
|
||||
writer.Write(Button0TouchY);
|
||||
writer.Write(Button0TouchWidth);
|
||||
writer.Write(Button0TouchHeight);
|
||||
writer.Write(Button0TouchOrder);
|
||||
writer.Write(Button1TouchX);
|
||||
writer.Write(Button1TouchY);
|
||||
writer.Write(Button1TouchWidth);
|
||||
writer.Write(Button1TouchHeight);
|
||||
writer.Write(Button1TouchOrder);
|
||||
writer.Write(Button2TouchX);
|
||||
writer.Write(Button2TouchY);
|
||||
writer.Write(Button2TouchWidth);
|
||||
writer.Write(Button2TouchHeight);
|
||||
writer.Write(Button2TouchOrder);
|
||||
}
|
||||
|
||||
public bool ReadButton0()
|
||||
{
|
||||
return (_gamePortService.IsButton0Down || _keyboardService.IsOpenAppleKeyDown ||
|
||||
(UseKeyboard && (Button0Key > 0) && _keyboardService.IsKeyDown(Button0Key)));
|
||||
}
|
||||
|
||||
public bool ReadButton1()
|
||||
{
|
||||
return (_gamePortService.IsButton1Down || _keyboardService.IsCloseAppleKeyDown ||
|
||||
(UseKeyboard && (Button1Key > 0) && _keyboardService.IsKeyDown(Button1Key)));
|
||||
}
|
||||
|
||||
public bool ReadButton2()
|
||||
{
|
||||
return (_gamePortService.IsButton2Down || (UseShiftKeyMod && !_keyboardService.IsShiftKeyDown) || // Shift' [TN9]
|
||||
(UseKeyboard && (Button2Key > 0) && _keyboardService.IsKeyDown(Button2Key)));
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
|
||||
public void TriggerTimers()
|
||||
{
|
||||
int paddle0 = _gamePortService.Paddle0;
|
||||
int paddle1 = _gamePortService.Paddle1;
|
||||
int paddle2 = _gamePortService.Paddle2;
|
||||
int paddle3 = _gamePortService.Paddle3;
|
||||
|
||||
if (UseKeyboard) // override
|
||||
{
|
||||
if (((Joystick0UpLeftKey > 0) && _keyboardService.IsKeyDown(Joystick0UpLeftKey)) ||
|
||||
((Joystick0LeftKey > 0) && _keyboardService.IsKeyDown(Joystick0LeftKey)) ||
|
||||
((Joystick0DownLeftKey > 0) && _keyboardService.IsKeyDown(Joystick0DownLeftKey)))
|
||||
{
|
||||
paddle0 -= PaddleScale;
|
||||
}
|
||||
if (((Joystick0UpRightKey > 0) && _keyboardService.IsKeyDown(Joystick0UpRightKey)) ||
|
||||
((Joystick0RightKey > 0) && _keyboardService.IsKeyDown(Joystick0RightKey)) ||
|
||||
((Joystick0DownRightKey > 0) && _keyboardService.IsKeyDown(Joystick0DownRightKey)))
|
||||
{
|
||||
paddle0 += PaddleScale;
|
||||
}
|
||||
if (((Joystick0UpLeftKey > 0) && _keyboardService.IsKeyDown(Joystick0UpLeftKey)) ||
|
||||
((Joystick0UpKey > 0) && _keyboardService.IsKeyDown(Joystick0UpKey)) ||
|
||||
((Joystick0UpRightKey > 0) && _keyboardService.IsKeyDown(Joystick0UpRightKey)))
|
||||
{
|
||||
paddle1 -= PaddleScale;
|
||||
}
|
||||
if (((Joystick0DownLeftKey > 0) && _keyboardService.IsKeyDown(Joystick0DownLeftKey)) ||
|
||||
((Joystick0DownKey > 0) && _keyboardService.IsKeyDown(Joystick0DownKey)) ||
|
||||
((Joystick0DownRightKey > 0) && _keyboardService.IsKeyDown(Joystick0DownRightKey)))
|
||||
{
|
||||
paddle1 += PaddleScale;
|
||||
}
|
||||
if (((Joystick1UpLeftKey > 0) && _keyboardService.IsKeyDown(Joystick1UpLeftKey)) ||
|
||||
((Joystick1LeftKey > 0) && _keyboardService.IsKeyDown(Joystick1LeftKey)) ||
|
||||
((Joystick1DownLeftKey > 0) && _keyboardService.IsKeyDown(Joystick1DownLeftKey)))
|
||||
{
|
||||
paddle2 -= PaddleScale;
|
||||
}
|
||||
if (((Joystick1UpRightKey > 0) && _keyboardService.IsKeyDown(Joystick1UpRightKey)) ||
|
||||
((Joystick1RightKey > 0) && _keyboardService.IsKeyDown(Joystick1RightKey)) ||
|
||||
((Joystick1DownRightKey > 0) && _keyboardService.IsKeyDown(Joystick1DownRightKey)))
|
||||
{
|
||||
paddle2 += PaddleScale;
|
||||
}
|
||||
if (((Joystick1UpLeftKey > 0) && _keyboardService.IsKeyDown(Joystick1UpLeftKey)) ||
|
||||
((Joystick1UpKey > 0) && _keyboardService.IsKeyDown(Joystick1UpKey)) ||
|
||||
((Joystick1UpRightKey > 0) && _keyboardService.IsKeyDown(Joystick1UpRightKey)))
|
||||
{
|
||||
paddle3 -= PaddleScale;
|
||||
}
|
||||
if (((Joystick1DownLeftKey > 0) && _keyboardService.IsKeyDown(Joystick1DownLeftKey)) ||
|
||||
((Joystick1DownKey > 0) && _keyboardService.IsKeyDown(Joystick1DownKey)) ||
|
||||
((Joystick1DownRightKey > 0) && _keyboardService.IsKeyDown(Joystick1DownRightKey)))
|
||||
{
|
||||
paddle3 += PaddleScale;
|
||||
}
|
||||
}
|
||||
if (InvertPaddles)
|
||||
{
|
||||
paddle0 = 2 * PaddleScale - paddle0;
|
||||
paddle1 = 2 * PaddleScale - paddle1;
|
||||
paddle2 = 2 * PaddleScale - paddle2;
|
||||
paddle3 = 2 * PaddleScale - paddle3;
|
||||
}
|
||||
|
||||
Paddle0Strobe = true;
|
||||
Paddle1Strobe = true;
|
||||
Paddle2Strobe = true;
|
||||
Paddle3Strobe = true;
|
||||
|
||||
Machine.Events.AddEvent(MathHelpers.ClampByte(SwapPaddles ? paddle1 : paddle0) * CyclesPerValue, _resetPaddle0StrobeEvent); // [7-29]
|
||||
Machine.Events.AddEvent(MathHelpers.ClampByte(SwapPaddles ? paddle0 : paddle1) * CyclesPerValue, _resetPaddle1StrobeEvent);
|
||||
Machine.Events.AddEvent(MathHelpers.ClampByte(SwapPaddles ? paddle3 : paddle2) * CyclesPerValue, _resetPaddle2StrobeEvent);
|
||||
Machine.Events.AddEvent(MathHelpers.ClampByte(SwapPaddles ? paddle2 : paddle3) * CyclesPerValue, _resetPaddle3StrobeEvent);
|
||||
}
|
||||
|
||||
private void ResetPaddle0StrobeEvent()
|
||||
{
|
||||
Paddle0Strobe = false;
|
||||
}
|
||||
|
||||
private void ResetPaddle1StrobeEvent()
|
||||
{
|
||||
Paddle1Strobe = false;
|
||||
}
|
||||
|
||||
private void ResetPaddle2StrobeEvent()
|
||||
{
|
||||
Paddle2Strobe = false;
|
||||
}
|
||||
|
||||
private void ResetPaddle3StrobeEvent()
|
||||
{
|
||||
Paddle3Strobe = false;
|
||||
}
|
||||
|
||||
public const int PaddleScale = 128;
|
||||
|
||||
public bool InvertPaddles { get; set; }
|
||||
public bool SwapPaddles { get; set; }
|
||||
public bool UseShiftKeyMod { get; set; }
|
||||
public float JoystickDeadZone { get; set; }
|
||||
|
||||
public bool UseKeyboard { get; set; }
|
||||
public int Joystick0UpLeftKey { get; set; }
|
||||
public int Joystick0UpKey { get; set; }
|
||||
public int Joystick0UpRightKey { get; set; }
|
||||
public int Joystick0LeftKey { get; set; }
|
||||
public int Joystick0RightKey { get; set; }
|
||||
public int Joystick0DownLeftKey { get; set; }
|
||||
public int Joystick0DownKey { get; set; }
|
||||
public int Joystick0DownRightKey { get; set; }
|
||||
public int Joystick1UpLeftKey { get; set; }
|
||||
public int Joystick1UpKey { get; set; }
|
||||
public int Joystick1UpRightKey { get; set; }
|
||||
public int Joystick1LeftKey { get; set; }
|
||||
public int Joystick1RightKey { get; set; }
|
||||
public int Joystick1DownLeftKey { get; set; }
|
||||
public int Joystick1DownKey { get; set; }
|
||||
public int Joystick1DownRightKey { get; set; }
|
||||
public int Button0Key { get; set; }
|
||||
public int Button1Key { get; set; }
|
||||
public int Button2Key { get; set; }
|
||||
|
||||
public bool UseTouch { get; set; }
|
||||
public float Joystick0TouchX { get; set; }
|
||||
public float Joystick0TouchY { get; set; }
|
||||
public float Joystick0TouchWidth { get; set; }
|
||||
public float Joystick0TouchHeight { get; set; }
|
||||
public int Joystick0TouchOrder { get; set; }
|
||||
public float Joystick0TouchRadius { get; set; }
|
||||
public bool Joystick0TouchKeepLast { get; set; }
|
||||
public float Joystick1TouchX { get; set; }
|
||||
public float Joystick1TouchY { get; set; }
|
||||
public float Joystick1TouchWidth { get; set; }
|
||||
public float Joystick1TouchHeight { get; set; }
|
||||
public int Joystick1TouchOrder { get; set; }
|
||||
public float Joystick1TouchRadius { get; set; }
|
||||
public bool Joystick1TouchKeepLast { get; set; }
|
||||
public float Button0TouchX { get; set; }
|
||||
public float Button0TouchY { get; set; }
|
||||
public float Button0TouchWidth { get; set; }
|
||||
public float Button0TouchHeight { get; set; }
|
||||
public int Button0TouchOrder { get; set; }
|
||||
public float Button1TouchX { get; set; }
|
||||
public float Button1TouchY { get; set; }
|
||||
public float Button1TouchWidth { get; set; }
|
||||
public float Button1TouchHeight { get; set; }
|
||||
public int Button1TouchOrder { get; set; }
|
||||
public float Button2TouchX { get; set; }
|
||||
public float Button2TouchY { get; set; }
|
||||
public float Button2TouchWidth { get; set; }
|
||||
public float Button2TouchHeight { get; set; }
|
||||
public int Button2TouchOrder { get; set; }
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
[assembly: SuppressMessage("Microsoft.Design", "CA2210:AssembliesShouldHaveValidStrongNames")]
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
[assembly: SuppressMessage("Microsoft.Design", "CA2210:AssembliesShouldHaveValidStrongNames")]
|
||||
|
@ -1,38 +1,38 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfish.Library.Silverlight", "..\Library\Silverlight\Jellyfish.Library.Silverlight.csproj", "{99CA7796-B72A-4F8C-BCDB-0D688220A331}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfish.Library.Wpf", "..\Library\Wpf\Jellyfish.Library.Wpf.csproj", "{93900841-7250-4D3A-837E-43EE3FD118DC}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfish.Virtu.Silverlight", "Silverlight\Jellyfish.Virtu.Silverlight.csproj", "{F8DB6D3A-807D-4E2D-92D5-469273E088DA}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfish.Virtu.Wpf", "Wpf\Jellyfish.Virtu.Wpf.csproj", "{C152D47E-BBC1-4C35-8646-465180720A72}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{93900841-7250-4D3A-837E-43EE3FD118DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{93900841-7250-4D3A-837E-43EE3FD118DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{93900841-7250-4D3A-837E-43EE3FD118DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{93900841-7250-4D3A-837E-43EE3FD118DC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{99CA7796-B72A-4F8C-BCDB-0D688220A331}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{99CA7796-B72A-4F8C-BCDB-0D688220A331}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{99CA7796-B72A-4F8C-BCDB-0D688220A331}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{99CA7796-B72A-4F8C-BCDB-0D688220A331}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C152D47E-BBC1-4C35-8646-465180720A72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C152D47E-BBC1-4C35-8646-465180720A72}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C152D47E-BBC1-4C35-8646-465180720A72}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C152D47E-BBC1-4C35-8646-465180720A72}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F8DB6D3A-807D-4E2D-92D5-469273E088DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F8DB6D3A-807D-4E2D-92D5-469273E088DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F8DB6D3A-807D-4E2D-92D5-469273E088DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F8DB6D3A-807D-4E2D-92D5-469273E088DA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfish.Library.Silverlight", "..\Library\Silverlight\Jellyfish.Library.Silverlight.csproj", "{99CA7796-B72A-4F8C-BCDB-0D688220A331}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfish.Library.Wpf", "..\Library\Wpf\Jellyfish.Library.Wpf.csproj", "{93900841-7250-4D3A-837E-43EE3FD118DC}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfish.Virtu.Silverlight", "Silverlight\Jellyfish.Virtu.Silverlight.csproj", "{F8DB6D3A-807D-4E2D-92D5-469273E088DA}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfish.Virtu.Wpf", "Wpf\Jellyfish.Virtu.Wpf.csproj", "{C152D47E-BBC1-4C35-8646-465180720A72}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{93900841-7250-4D3A-837E-43EE3FD118DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{93900841-7250-4D3A-837E-43EE3FD118DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{93900841-7250-4D3A-837E-43EE3FD118DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{93900841-7250-4D3A-837E-43EE3FD118DC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{99CA7796-B72A-4F8C-BCDB-0D688220A331}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{99CA7796-B72A-4F8C-BCDB-0D688220A331}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{99CA7796-B72A-4F8C-BCDB-0D688220A331}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{99CA7796-B72A-4F8C-BCDB-0D688220A331}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C152D47E-BBC1-4C35-8646-465180720A72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C152D47E-BBC1-4C35-8646-465180720A72}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C152D47E-BBC1-4C35-8646-465180720A72}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C152D47E-BBC1-4C35-8646-465180720A72}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F8DB6D3A-807D-4E2D-92D5-469273E088DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F8DB6D3A-807D-4E2D-92D5-469273E088DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F8DB6D3A-807D-4E2D-92D5-469273E088DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F8DB6D3A-807D-4E2D-92D5-469273E088DA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
@ -1,120 +1,120 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Jellyfish.Virtu.Services;
|
||||
|
||||
namespace Jellyfish.Virtu
|
||||
{
|
||||
public sealed class Keyboard : MachineComponent
|
||||
{
|
||||
public Keyboard(Machine machine) :
|
||||
base(machine)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
_keyboardService = Machine.Services.GetService<KeyboardService>();
|
||||
|
||||
UseGamePort = true; // Raster Blaster
|
||||
Button2Key = ' ';
|
||||
}
|
||||
|
||||
public override void LoadState(BinaryReader reader, Version version)
|
||||
{
|
||||
if (reader == null)
|
||||
{
|
||||
throw new ArgumentNullException("reader");
|
||||
}
|
||||
|
||||
DisableResetKey = reader.ReadBoolean();
|
||||
|
||||
UseGamePort = reader.ReadBoolean();
|
||||
Joystick0UpLeftKey = reader.ReadInt32();
|
||||
Joystick0UpKey = reader.ReadInt32();
|
||||
Joystick0UpRightKey = reader.ReadInt32();
|
||||
Joystick0LeftKey = reader.ReadInt32();
|
||||
Joystick0RightKey = reader.ReadInt32();
|
||||
Joystick0DownLeftKey = reader.ReadInt32();
|
||||
Joystick0DownKey = reader.ReadInt32();
|
||||
Joystick0DownRightKey = reader.ReadInt32();
|
||||
Joystick1UpLeftKey = reader.ReadInt32();
|
||||
Joystick1UpKey = reader.ReadInt32();
|
||||
Joystick1UpRightKey = reader.ReadInt32();
|
||||
Joystick1LeftKey = reader.ReadInt32();
|
||||
Joystick1RightKey = reader.ReadInt32();
|
||||
Joystick1DownLeftKey = reader.ReadInt32();
|
||||
Joystick1DownKey = reader.ReadInt32();
|
||||
Joystick1DownRightKey = reader.ReadInt32();
|
||||
Button0Key = reader.ReadInt32();
|
||||
Button1Key = reader.ReadInt32();
|
||||
Button2Key = reader.ReadInt32();
|
||||
}
|
||||
|
||||
public override void SaveState(BinaryWriter writer)
|
||||
{
|
||||
if (writer == null)
|
||||
{
|
||||
throw new ArgumentNullException("writer");
|
||||
}
|
||||
|
||||
writer.Write(DisableResetKey);
|
||||
|
||||
writer.Write(UseGamePort);
|
||||
writer.Write(Joystick0UpLeftKey);
|
||||
writer.Write(Joystick0UpKey);
|
||||
writer.Write(Joystick0UpRightKey);
|
||||
writer.Write(Joystick0LeftKey);
|
||||
writer.Write(Joystick0RightKey);
|
||||
writer.Write(Joystick0DownLeftKey);
|
||||
writer.Write(Joystick0DownKey);
|
||||
writer.Write(Joystick0DownRightKey);
|
||||
writer.Write(Joystick1UpLeftKey);
|
||||
writer.Write(Joystick1UpKey);
|
||||
writer.Write(Joystick1UpRightKey);
|
||||
writer.Write(Joystick1LeftKey);
|
||||
writer.Write(Joystick1RightKey);
|
||||
writer.Write(Joystick1DownLeftKey);
|
||||
writer.Write(Joystick1DownKey);
|
||||
writer.Write(Joystick1DownRightKey);
|
||||
writer.Write(Button0Key);
|
||||
writer.Write(Button1Key);
|
||||
writer.Write(Button2Key);
|
||||
}
|
||||
|
||||
public void ResetStrobe()
|
||||
{
|
||||
Strobe = false;
|
||||
}
|
||||
|
||||
public bool DisableResetKey { get; set; }
|
||||
|
||||
public bool UseGamePort { get; set; }
|
||||
public int Joystick0UpLeftKey { get; set; }
|
||||
public int Joystick0UpKey { get; set; }
|
||||
public int Joystick0UpRightKey { get; set; }
|
||||
public int Joystick0LeftKey { get; set; }
|
||||
public int Joystick0RightKey { get; set; }
|
||||
public int Joystick0DownLeftKey { get; set; }
|
||||
public int Joystick0DownKey { get; set; }
|
||||
public int Joystick0DownRightKey { get; set; }
|
||||
public int Joystick1UpLeftKey { get; set; }
|
||||
public int Joystick1UpKey { get; set; }
|
||||
public int Joystick1UpRightKey { get; set; }
|
||||
public int Joystick1LeftKey { get; set; }
|
||||
public int Joystick1RightKey { get; set; }
|
||||
public int Joystick1DownLeftKey { get; set; }
|
||||
public int Joystick1DownKey { get; set; }
|
||||
public int Joystick1DownRightKey { get; set; }
|
||||
public int Button0Key { get; set; }
|
||||
public int Button1Key { get; set; }
|
||||
public int Button2Key { get; set; }
|
||||
|
||||
public bool IsAnyKeyDown { get { return _keyboardService.IsAnyKeyDown; } }
|
||||
public int Latch { get { return _latch; } set { _latch = value; Strobe = true; } }
|
||||
public bool Strobe { get; private set; }
|
||||
|
||||
private KeyboardService _keyboardService;
|
||||
|
||||
private int _latch;
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.IO;
|
||||
using Jellyfish.Virtu.Services;
|
||||
|
||||
namespace Jellyfish.Virtu
|
||||
{
|
||||
public sealed class Keyboard : MachineComponent
|
||||
{
|
||||
public Keyboard(Machine machine) :
|
||||
base(machine)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
_keyboardService = Machine.Services.GetService<KeyboardService>();
|
||||
|
||||
UseGamePort = true; // Raster Blaster
|
||||
Button2Key = ' ';
|
||||
}
|
||||
|
||||
public override void LoadState(BinaryReader reader, Version version)
|
||||
{
|
||||
if (reader == null)
|
||||
{
|
||||
throw new ArgumentNullException("reader");
|
||||
}
|
||||
|
||||
DisableResetKey = reader.ReadBoolean();
|
||||
|
||||
UseGamePort = reader.ReadBoolean();
|
||||
Joystick0UpLeftKey = reader.ReadInt32();
|
||||
Joystick0UpKey = reader.ReadInt32();
|
||||
Joystick0UpRightKey = reader.ReadInt32();
|
||||
Joystick0LeftKey = reader.ReadInt32();
|
||||
Joystick0RightKey = reader.ReadInt32();
|
||||
Joystick0DownLeftKey = reader.ReadInt32();
|
||||
Joystick0DownKey = reader.ReadInt32();
|
||||
Joystick0DownRightKey = reader.ReadInt32();
|
||||
Joystick1UpLeftKey = reader.ReadInt32();
|
||||
Joystick1UpKey = reader.ReadInt32();
|
||||
Joystick1UpRightKey = reader.ReadInt32();
|
||||
Joystick1LeftKey = reader.ReadInt32();
|
||||
Joystick1RightKey = reader.ReadInt32();
|
||||
Joystick1DownLeftKey = reader.ReadInt32();
|
||||
Joystick1DownKey = reader.ReadInt32();
|
||||
Joystick1DownRightKey = reader.ReadInt32();
|
||||
Button0Key = reader.ReadInt32();
|
||||
Button1Key = reader.ReadInt32();
|
||||
Button2Key = reader.ReadInt32();
|
||||
}
|
||||
|
||||
public override void SaveState(BinaryWriter writer)
|
||||
{
|
||||
if (writer == null)
|
||||
{
|
||||
throw new ArgumentNullException("writer");
|
||||
}
|
||||
|
||||
writer.Write(DisableResetKey);
|
||||
|
||||
writer.Write(UseGamePort);
|
||||
writer.Write(Joystick0UpLeftKey);
|
||||
writer.Write(Joystick0UpKey);
|
||||
writer.Write(Joystick0UpRightKey);
|
||||
writer.Write(Joystick0LeftKey);
|
||||
writer.Write(Joystick0RightKey);
|
||||
writer.Write(Joystick0DownLeftKey);
|
||||
writer.Write(Joystick0DownKey);
|
||||
writer.Write(Joystick0DownRightKey);
|
||||
writer.Write(Joystick1UpLeftKey);
|
||||
writer.Write(Joystick1UpKey);
|
||||
writer.Write(Joystick1UpRightKey);
|
||||
writer.Write(Joystick1LeftKey);
|
||||
writer.Write(Joystick1RightKey);
|
||||
writer.Write(Joystick1DownLeftKey);
|
||||
writer.Write(Joystick1DownKey);
|
||||
writer.Write(Joystick1DownRightKey);
|
||||
writer.Write(Button0Key);
|
||||
writer.Write(Button1Key);
|
||||
writer.Write(Button2Key);
|
||||
}
|
||||
|
||||
public void ResetStrobe()
|
||||
{
|
||||
Strobe = false;
|
||||
}
|
||||
|
||||
public bool DisableResetKey { get; set; }
|
||||
|
||||
public bool UseGamePort { get; set; }
|
||||
public int Joystick0UpLeftKey { get; set; }
|
||||
public int Joystick0UpKey { get; set; }
|
||||
public int Joystick0UpRightKey { get; set; }
|
||||
public int Joystick0LeftKey { get; set; }
|
||||
public int Joystick0RightKey { get; set; }
|
||||
public int Joystick0DownLeftKey { get; set; }
|
||||
public int Joystick0DownKey { get; set; }
|
||||
public int Joystick0DownRightKey { get; set; }
|
||||
public int Joystick1UpLeftKey { get; set; }
|
||||
public int Joystick1UpKey { get; set; }
|
||||
public int Joystick1UpRightKey { get; set; }
|
||||
public int Joystick1LeftKey { get; set; }
|
||||
public int Joystick1RightKey { get; set; }
|
||||
public int Joystick1DownLeftKey { get; set; }
|
||||
public int Joystick1DownKey { get; set; }
|
||||
public int Joystick1DownRightKey { get; set; }
|
||||
public int Button0Key { get; set; }
|
||||
public int Button1Key { get; set; }
|
||||
public int Button2Key { get; set; }
|
||||
|
||||
public bool IsAnyKeyDown { get { return _keyboardService.IsAnyKeyDown; } }
|
||||
public int Latch { get { return _latch; } set { _latch = value; Strobe = true; } }
|
||||
public bool Strobe { get; private set; }
|
||||
|
||||
private KeyboardService _keyboardService;
|
||||
|
||||
private int _latch;
|
||||
}
|
||||
}
|
||||
|
546
Virtu/Machine.cs
546
Virtu/Machine.cs
@ -1,273 +1,273 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Jellyfish.Virtu.Services;
|
||||
|
||||
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();
|
||||
|
||||
Cpu = new Cpu(this);
|
||||
Memory = new Memory(this);
|
||||
Keyboard = new Keyboard(this);
|
||||
GamePort = new GamePort(this);
|
||||
Cassette = new Cassette(this);
|
||||
Speaker = new Speaker(this);
|
||||
Video = new Video(this);
|
||||
NoSlotClock = new NoSlotClock(this);
|
||||
|
||||
var emptySlot = new PeripheralCard(this);
|
||||
Slot1 = emptySlot;
|
||||
Slot2 = emptySlot;
|
||||
Slot3 = emptySlot;
|
||||
Slot4 = emptySlot;
|
||||
Slot5 = emptySlot;
|
||||
Slot6 = new DiskIIController(this);
|
||||
Slot7 = emptySlot;
|
||||
|
||||
Slots = new Collection<PeripheralCard> { null, Slot1, Slot2, Slot3, Slot4, Slot5, Slot6, Slot7 };
|
||||
Components = new Collection<MachineComponent> { Cpu, Memory, Keyboard, GamePort, Cassette, Speaker, Video, NoSlotClock, Slot1, Slot2, Slot3, Slot4, Slot5, Slot6, Slot7 };
|
||||
|
||||
BootDiskII = Slots.OfType<DiskIIController>().Last();
|
||||
|
||||
Thread = new Thread(Run) { Name = "Machine" };
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_pauseEvent.Close();
|
||||
_unpauseEvent.Close();
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
foreach (var component in Components)
|
||||
{
|
||||
_debugService.WriteMessage("Resetting machine '{0}'", component.GetType().Name);
|
||||
component.Reset();
|
||||
//_debugService.WriteMessage("Reset machine '{0}'", component.GetType().Name);
|
||||
}
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Jellyfish.Virtu.Services.DebugService.WriteMessage(System.String)")]
|
||||
public void Start()
|
||||
{
|
||||
_debugService = Services.GetService<DebugService>();
|
||||
_storageService = Services.GetService<StorageService>();
|
||||
|
||||
_debugService.WriteMessage("Starting machine");
|
||||
State = MachineState.Starting;
|
||||
Thread.Start();
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Jellyfish.Virtu.Services.DebugService.WriteMessage(System.String)")]
|
||||
public void Pause()
|
||||
{
|
||||
_debugService.WriteMessage("Pausing machine");
|
||||
State = MachineState.Pausing;
|
||||
_pauseEvent.WaitOne();
|
||||
State = MachineState.Paused;
|
||||
_debugService.WriteMessage("Paused machine");
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Jellyfish.Virtu.Services.DebugService.WriteMessage(System.String)")]
|
||||
public void Unpause()
|
||||
{
|
||||
_debugService.WriteMessage("Running machine");
|
||||
State = MachineState.Running;
|
||||
_unpauseEvent.Set();
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Jellyfish.Virtu.Services.DebugService.WriteMessage(System.String)")]
|
||||
public void Stop()
|
||||
{
|
||||
_debugService.WriteMessage("Stopping machine");
|
||||
State = MachineState.Stopping;
|
||||
_unpauseEvent.Set();
|
||||
if (Thread.IsAlive)
|
||||
{
|
||||
Thread.Join();
|
||||
}
|
||||
State = MachineState.Stopped;
|
||||
_debugService.WriteMessage("Stopped machine");
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
foreach (var component in Components)
|
||||
{
|
||||
_debugService.WriteMessage("Initializing machine '{0}'", component.GetType().Name);
|
||||
component.Initialize();
|
||||
//_debugService.WriteMessage("Initialized machine '{0}'", component.GetType().Name);
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadState()
|
||||
{
|
||||
#if WINDOWS
|
||||
var args = Environment.GetCommandLineArgs();
|
||||
if (args.Length > 1)
|
||||
{
|
||||
string name = args[1];
|
||||
Func<string, Action<Stream>, bool> loader = StorageService.LoadFile;
|
||||
|
||||
if (name.StartsWith("res://", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
name = name.Substring(6);
|
||||
loader = StorageService.LoadResource;
|
||||
}
|
||||
|
||||
if (name.EndsWith(".bin", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
loader(name, stream => LoadState(stream));
|
||||
}
|
||||
else if (name.EndsWith(".prg", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
loader(name, stream => Memory.LoadPrg(stream));
|
||||
}
|
||||
else if (name.EndsWith(".xex", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
loader(name, stream => Memory.LoadXex(stream));
|
||||
}
|
||||
else
|
||||
{
|
||||
loader(name, stream => BootDiskII.BootDrive.InsertDisk(name, stream, false));
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if (!_storageService.Load(Machine.StateFileName, stream => LoadState(stream)))
|
||||
{
|
||||
StorageService.LoadResource("Disks/Default.dsk", stream => BootDiskII.BootDrive.InsertDisk("Default.dsk", stream, false));
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadState(Stream stream)
|
||||
{
|
||||
using (var reader = new BinaryReader(stream))
|
||||
{
|
||||
string signature = reader.ReadString();
|
||||
var version = new Version(reader.ReadString());
|
||||
if ((signature != StateSignature) || (version != new Version(Machine.Version))) // avoid state version mismatch (for now)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
foreach (var component in Components)
|
||||
{
|
||||
_debugService.WriteMessage("Loading machine '{0}'", component.GetType().Name);
|
||||
component.LoadState(reader, version);
|
||||
//_debugService.WriteMessage("Loaded machine '{0}'", component.GetType().Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveState()
|
||||
{
|
||||
_storageService.Save(Machine.StateFileName, stream => SaveState(stream));
|
||||
}
|
||||
|
||||
private void SaveState(Stream stream)
|
||||
{
|
||||
using (var writer = new BinaryWriter(stream))
|
||||
{
|
||||
writer.Write(StateSignature);
|
||||
writer.Write(Machine.Version);
|
||||
foreach (var component in Components)
|
||||
{
|
||||
_debugService.WriteMessage("Saving machine '{0}'", component.GetType().Name);
|
||||
component.SaveState(writer);
|
||||
//_debugService.WriteMessage("Saved machine '{0}'", component.GetType().Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Uninitialize()
|
||||
{
|
||||
foreach (var component in Components)
|
||||
{
|
||||
_debugService.WriteMessage("Uninitializing machine '{0}'", component.GetType().Name);
|
||||
component.Uninitialize();
|
||||
//_debugService.WriteMessage("Uninitialized machine '{0}'", component.GetType().Name);
|
||||
}
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Jellyfish.Virtu.Services.DebugService.WriteMessage(System.String)")]
|
||||
private void Run() // machine thread
|
||||
{
|
||||
Initialize();
|
||||
Reset();
|
||||
LoadState();
|
||||
|
||||
_debugService.WriteMessage("Running machine");
|
||||
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);
|
||||
|
||||
SaveState();
|
||||
Uninitialize();
|
||||
}
|
||||
|
||||
public const string Version = "0.9.4.0";
|
||||
|
||||
public MachineEvents Events { get; private set; }
|
||||
public MachineServices Services { get; private set; }
|
||||
public MachineState State { get { return _state; } private set { _state = value; } }
|
||||
|
||||
public Cpu Cpu { get; private set; }
|
||||
public Memory Memory { 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 NoSlotClock NoSlotClock { get; private set; }
|
||||
|
||||
public PeripheralCard Slot1 { get; private set; }
|
||||
public PeripheralCard Slot2 { get; private set; }
|
||||
public PeripheralCard Slot3 { get; private set; }
|
||||
public PeripheralCard Slot4 { get; private set; }
|
||||
public PeripheralCard Slot5 { get; private set; }
|
||||
public PeripheralCard Slot6 { get; private set; }
|
||||
public PeripheralCard Slot7 { get; private set; }
|
||||
|
||||
public Collection<PeripheralCard> Slots { get; private set; }
|
||||
public Collection<MachineComponent> Components { get; private set; }
|
||||
|
||||
public DiskIIController BootDiskII { get; private set; }
|
||||
|
||||
public Thread Thread { get; private set; }
|
||||
|
||||
private const string StateFileName = "State.bin";
|
||||
private const string StateSignature = "Virtu";
|
||||
|
||||
private DebugService _debugService;
|
||||
private StorageService _storageService;
|
||||
private volatile MachineState _state;
|
||||
|
||||
private AutoResetEvent _pauseEvent = new AutoResetEvent(false);
|
||||
private AutoResetEvent _unpauseEvent = new AutoResetEvent(false);
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Jellyfish.Virtu.Services;
|
||||
|
||||
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();
|
||||
|
||||
Cpu = new Cpu(this);
|
||||
Memory = new Memory(this);
|
||||
Keyboard = new Keyboard(this);
|
||||
GamePort = new GamePort(this);
|
||||
Cassette = new Cassette(this);
|
||||
Speaker = new Speaker(this);
|
||||
Video = new Video(this);
|
||||
NoSlotClock = new NoSlotClock(this);
|
||||
|
||||
var emptySlot = new PeripheralCard(this);
|
||||
Slot1 = emptySlot;
|
||||
Slot2 = emptySlot;
|
||||
Slot3 = emptySlot;
|
||||
Slot4 = emptySlot;
|
||||
Slot5 = emptySlot;
|
||||
Slot6 = new DiskIIController(this);
|
||||
Slot7 = emptySlot;
|
||||
|
||||
Slots = new Collection<PeripheralCard> { null, Slot1, Slot2, Slot3, Slot4, Slot5, Slot6, Slot7 };
|
||||
Components = new Collection<MachineComponent> { Cpu, Memory, Keyboard, GamePort, Cassette, Speaker, Video, NoSlotClock, Slot1, Slot2, Slot3, Slot4, Slot5, Slot6, Slot7 };
|
||||
|
||||
BootDiskII = Slots.OfType<DiskIIController>().Last();
|
||||
|
||||
Thread = new Thread(Run) { Name = "Machine" };
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_pauseEvent.Close();
|
||||
_unpauseEvent.Close();
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
foreach (var component in Components)
|
||||
{
|
||||
_debugService.WriteMessage("Resetting machine '{0}'", component.GetType().Name);
|
||||
component.Reset();
|
||||
//_debugService.WriteMessage("Reset machine '{0}'", component.GetType().Name);
|
||||
}
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Jellyfish.Virtu.Services.DebugService.WriteMessage(System.String)")]
|
||||
public void Start()
|
||||
{
|
||||
_debugService = Services.GetService<DebugService>();
|
||||
_storageService = Services.GetService<StorageService>();
|
||||
|
||||
_debugService.WriteMessage("Starting machine");
|
||||
State = MachineState.Starting;
|
||||
Thread.Start();
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Jellyfish.Virtu.Services.DebugService.WriteMessage(System.String)")]
|
||||
public void Pause()
|
||||
{
|
||||
_debugService.WriteMessage("Pausing machine");
|
||||
State = MachineState.Pausing;
|
||||
_pauseEvent.WaitOne();
|
||||
State = MachineState.Paused;
|
||||
_debugService.WriteMessage("Paused machine");
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Jellyfish.Virtu.Services.DebugService.WriteMessage(System.String)")]
|
||||
public void Unpause()
|
||||
{
|
||||
_debugService.WriteMessage("Running machine");
|
||||
State = MachineState.Running;
|
||||
_unpauseEvent.Set();
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Jellyfish.Virtu.Services.DebugService.WriteMessage(System.String)")]
|
||||
public void Stop()
|
||||
{
|
||||
_debugService.WriteMessage("Stopping machine");
|
||||
State = MachineState.Stopping;
|
||||
_unpauseEvent.Set();
|
||||
if (Thread.IsAlive)
|
||||
{
|
||||
Thread.Join();
|
||||
}
|
||||
State = MachineState.Stopped;
|
||||
_debugService.WriteMessage("Stopped machine");
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
foreach (var component in Components)
|
||||
{
|
||||
_debugService.WriteMessage("Initializing machine '{0}'", component.GetType().Name);
|
||||
component.Initialize();
|
||||
//_debugService.WriteMessage("Initialized machine '{0}'", component.GetType().Name);
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadState()
|
||||
{
|
||||
#if WINDOWS
|
||||
var args = Environment.GetCommandLineArgs();
|
||||
if (args.Length > 1)
|
||||
{
|
||||
string name = args[1];
|
||||
Func<string, Action<Stream>, bool> loader = StorageService.LoadFile;
|
||||
|
||||
if (name.StartsWith("res://", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
name = name.Substring(6);
|
||||
loader = StorageService.LoadResource;
|
||||
}
|
||||
|
||||
if (name.EndsWith(".bin", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
loader(name, stream => LoadState(stream));
|
||||
}
|
||||
else if (name.EndsWith(".prg", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
loader(name, stream => Memory.LoadPrg(stream));
|
||||
}
|
||||
else if (name.EndsWith(".xex", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
loader(name, stream => Memory.LoadXex(stream));
|
||||
}
|
||||
else
|
||||
{
|
||||
loader(name, stream => BootDiskII.BootDrive.InsertDisk(name, stream, false));
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if (!_storageService.Load(Machine.StateFileName, stream => LoadState(stream)))
|
||||
{
|
||||
StorageService.LoadResource("Disks/Default.dsk", stream => BootDiskII.BootDrive.InsertDisk("Default.dsk", stream, false));
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadState(Stream stream)
|
||||
{
|
||||
using (var reader = new BinaryReader(stream))
|
||||
{
|
||||
string signature = reader.ReadString();
|
||||
var version = new Version(reader.ReadString());
|
||||
if ((signature != StateSignature) || (version != new Version(Machine.Version))) // avoid state version mismatch (for now)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
foreach (var component in Components)
|
||||
{
|
||||
_debugService.WriteMessage("Loading machine '{0}'", component.GetType().Name);
|
||||
component.LoadState(reader, version);
|
||||
//_debugService.WriteMessage("Loaded machine '{0}'", component.GetType().Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveState()
|
||||
{
|
||||
_storageService.Save(Machine.StateFileName, stream => SaveState(stream));
|
||||
}
|
||||
|
||||
private void SaveState(Stream stream)
|
||||
{
|
||||
using (var writer = new BinaryWriter(stream))
|
||||
{
|
||||
writer.Write(StateSignature);
|
||||
writer.Write(Machine.Version);
|
||||
foreach (var component in Components)
|
||||
{
|
||||
_debugService.WriteMessage("Saving machine '{0}'", component.GetType().Name);
|
||||
component.SaveState(writer);
|
||||
//_debugService.WriteMessage("Saved machine '{0}'", component.GetType().Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Uninitialize()
|
||||
{
|
||||
foreach (var component in Components)
|
||||
{
|
||||
_debugService.WriteMessage("Uninitializing machine '{0}'", component.GetType().Name);
|
||||
component.Uninitialize();
|
||||
//_debugService.WriteMessage("Uninitialized machine '{0}'", component.GetType().Name);
|
||||
}
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Jellyfish.Virtu.Services.DebugService.WriteMessage(System.String)")]
|
||||
private void Run() // machine thread
|
||||
{
|
||||
Initialize();
|
||||
Reset();
|
||||
LoadState();
|
||||
|
||||
_debugService.WriteMessage("Running machine");
|
||||
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);
|
||||
|
||||
SaveState();
|
||||
Uninitialize();
|
||||
}
|
||||
|
||||
public const string Version = "0.9.4.0";
|
||||
|
||||
public MachineEvents Events { get; private set; }
|
||||
public MachineServices Services { get; private set; }
|
||||
public MachineState State { get { return _state; } private set { _state = value; } }
|
||||
|
||||
public Cpu Cpu { get; private set; }
|
||||
public Memory Memory { 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 NoSlotClock NoSlotClock { get; private set; }
|
||||
|
||||
public PeripheralCard Slot1 { get; private set; }
|
||||
public PeripheralCard Slot2 { get; private set; }
|
||||
public PeripheralCard Slot3 { get; private set; }
|
||||
public PeripheralCard Slot4 { get; private set; }
|
||||
public PeripheralCard Slot5 { get; private set; }
|
||||
public PeripheralCard Slot6 { get; private set; }
|
||||
public PeripheralCard Slot7 { get; private set; }
|
||||
|
||||
public Collection<PeripheralCard> Slots { get; private set; }
|
||||
public Collection<MachineComponent> Components { get; private set; }
|
||||
|
||||
public DiskIIController BootDiskII { get; private set; }
|
||||
|
||||
public Thread Thread { get; private set; }
|
||||
|
||||
private const string StateFileName = "State.bin";
|
||||
private const string StateSignature = "Virtu";
|
||||
|
||||
private DebugService _debugService;
|
||||
private StorageService _storageService;
|
||||
private volatile MachineState _state;
|
||||
|
||||
private AutoResetEvent _pauseEvent = new AutoResetEvent(false);
|
||||
private AutoResetEvent _unpauseEvent = new AutoResetEvent(false);
|
||||
}
|
||||
}
|
||||
|
@ -1,42 +1,42 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Jellyfish.Library;
|
||||
using Jellyfish.Virtu.Services;
|
||||
|
||||
namespace Jellyfish.Virtu
|
||||
{
|
||||
public abstract class MachineComponent
|
||||
{
|
||||
protected MachineComponent(Machine machine)
|
||||
{
|
||||
Machine = machine;
|
||||
|
||||
_debugService = new Lazy<DebugService>(() => Machine.Services.GetService<DebugService>());
|
||||
}
|
||||
|
||||
public virtual void Initialize()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void Reset()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void LoadState(BinaryReader reader, Version version)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void Uninitialize()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void SaveState(BinaryWriter writer)
|
||||
{
|
||||
}
|
||||
|
||||
protected Machine Machine { get; private set; }
|
||||
protected DebugService DebugService { get { return _debugService.Value; } }
|
||||
|
||||
private Lazy<DebugService> _debugService;
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.IO;
|
||||
using Jellyfish.Library;
|
||||
using Jellyfish.Virtu.Services;
|
||||
|
||||
namespace Jellyfish.Virtu
|
||||
{
|
||||
public abstract class MachineComponent
|
||||
{
|
||||
protected MachineComponent(Machine machine)
|
||||
{
|
||||
Machine = machine;
|
||||
|
||||
_debugService = new Lazy<DebugService>(() => Machine.Services.GetService<DebugService>());
|
||||
}
|
||||
|
||||
public virtual void Initialize()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void Reset()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void LoadState(BinaryReader reader, Version version)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void Uninitialize()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void SaveState(BinaryWriter writer)
|
||||
{
|
||||
}
|
||||
|
||||
protected Machine Machine { get; private set; }
|
||||
protected DebugService DebugService { get { return _debugService.Value; } }
|
||||
|
||||
private Lazy<DebugService> _debugService;
|
||||
}
|
||||
}
|
||||
|
@ -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.InvariantCulture, "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)
|
||||
{
|
||||
var 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;
|
||||
}
|
||||
}
|
||||
|
||||
var 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 (var 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)
|
||||
{
|
||||
var 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.InvariantCulture, "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)
|
||||
{
|
||||
var 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;
|
||||
}
|
||||
}
|
||||
|
||||
var 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 (var 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)
|
||||
{
|
||||
var 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>();
|
||||
}
|
||||
}
|
||||
|
3476
Virtu/Memory.cs
3476
Virtu/Memory.cs
File diff suppressed because it is too large
Load Diff
@ -1,106 +1,106 @@
|
||||
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 StateIntC8Rom = 0x010000; // [5-28]
|
||||
private const int StateIntCXRom = 0x020000;
|
||||
private const int StateAn0 = 0x040000;
|
||||
private const int StateAn1 = 0x080000;
|
||||
private const int StateAn2 = 0x100000;
|
||||
private const int StateAn3 = 0x200000;
|
||||
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 StateIntC8Rom = 0x010000; // [5-28]
|
||||
private const int StateIntCXRom = 0x020000;
|
||||
private const int StateAn0 = 0x040000;
|
||||
private const int StateAn1 = 0x080000;
|
||||
private const int StateAn2 = 0x100000;
|
||||
private const int StateAn3 = 0x200000;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -1,228 +1,228 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Jellyfish.Virtu
|
||||