more misc cleanup and removing some usings that should have been removed when moving things from one project to another

This commit is contained in:
adelikat 2013-11-15 01:52:03 +00:00
parent 00308de99a
commit e606429219
23 changed files with 1687 additions and 1716 deletions

View File

@ -10,7 +10,7 @@ namespace BizHawk.Emulation.Common.Components.CP1610
private bool FlagS, FlagC, FlagZ, FlagO, FlagI, FlagD, IntRM, BusRq, BusAk, Interruptible, Interrupted;
//private bool MSync;
private ushort[] Register = new ushort[8];
private readonly ushort[] Register = new ushort[8];
private ushort RegisterSP { get { return Register[6]; } set { Register[6] = value; } }
private ushort RegisterPC { get { return Register[7]; } set { Register[7] = value; } }
@ -21,7 +21,7 @@ namespace BizHawk.Emulation.Common.Components.CP1610
public Func<ushort, ushort, bool> WriteMemory;
private static bool Logging = true;
private static StreamWriter Log;
private static readonly StreamWriter Log;
static CP1610()
{

View File

@ -185,7 +185,7 @@ namespace BizHawk.Emulation.Common.Components.CP1610
// Unknown opcode.
throw new ArgumentException();
}
RegisterPC = (ushort)addr;
RegisterPC = addr;
cycles = 12;
Interruptible = true;
break;

View File

@ -277,7 +277,7 @@ namespace BizHawk.Emulation.Common.Components.H6280
{
// There exists a slight delay between when the timer counter is decremented and when
// the interrupt fires; games can detect it, so we hack it this way.
return (byte) ((TimerValue - 1) & 0x7F);
return (byte)((TimerValue - 1) & 0x7F);
}
return TimerValue;
}

View File

@ -12,8 +12,8 @@ namespace BizHawk.Emulation.Common.Components.M6502
/// </summary>
public class MOS6502XDouble
{
MOS6502X m;
MOS6502X_CPP n;
readonly MOS6502X m;
readonly MOS6502X_CPP n;
public MOS6502XDouble(Action<System.Runtime.InteropServices.GCHandle> DisposeBuilder)
{

View File

@ -7,27 +7,27 @@ namespace BizHawk.Emulation.Common.Components.M6502
{
public static class MOS6502X_DLL
{
[UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.Cdecl)]
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate byte ReadMemoryD(ushort addr);
[UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.Cdecl)]
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void WriteMemoryD(ushort addr, byte value);
[DllImport("MOS6502XNative.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr Create();
internal static extern IntPtr Create();
[DllImport("MOS6502XNative.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void Destroy(IntPtr ptr);
internal static extern void Destroy(IntPtr ptr);
[DllImport("MOS6502XNative.dll", CallingConvention = CallingConvention.ThisCall, EntryPoint = "?Reset@MOS6502X@@QAEXXZ")]
public static extern void Reset(IntPtr ptr);
internal static extern void Reset(IntPtr ptr);
[DllImport("MOS6502XNative.dll", CallingConvention = CallingConvention.ThisCall, EntryPoint = "?NESSoftReset@MOS6502X@@QAEXXZ")]
public static extern void NESSoftReset(IntPtr ptr);
internal static extern void NESSoftReset(IntPtr ptr);
[DllImport("MOS6502XNative.dll", CallingConvention = CallingConvention.ThisCall, EntryPoint = "?ExecuteOne@MOS6502X@@QAEXXZ")]
public static extern void ExecuteOne(IntPtr ptr);
internal static extern void ExecuteOne(IntPtr ptr);
[DllImport("MOS6502XNative.dll", CallingConvention = CallingConvention.ThisCall, EntryPoint = "?SetTrampolines@MOS6502X@@QAEXP6AEG@Z0P6AXGE@Z@Z")]
public static extern void SetTrampolines(IntPtr ptr, ReadMemoryD Read, ReadMemoryD DummyRead, WriteMemoryD Write);
internal static extern void SetTrampolines(IntPtr ptr, ReadMemoryD Read, ReadMemoryD DummyRead, WriteMemoryD Write);
}
/// <summary>
@ -213,8 +213,6 @@ namespace BizHawk.Emulation.Common.Components.M6502
DisposeBuilder(h2);
DisposeBuilder(h3);
}
}
}

View File

@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
namespace BizHawk.Emulation.Common
@ -123,7 +122,7 @@ namespace BizHawk.Emulation.Common
public class InputCallbackSystem
{
private List<Action> _list = new List<Action>();
private readonly List<Action> _list = new List<Action>();
public void Add(Action action)
{
@ -159,14 +158,14 @@ namespace BizHawk.Emulation.Common
public class MemoryCallbackSystem
{
private List<Action> _reads = new List<Action>();
private List<uint?> _readAddrs = new List<uint?>();
private readonly List<Action> _reads = new List<Action>();
private readonly List<uint?> _readAddrs = new List<uint?>();
private List<Action> _writes = new List<Action>();
private List<uint?> _writeAddrs = new List<uint?>();
private readonly List<Action> _writes = new List<Action>();
private readonly List<uint?> _writeAddrs = new List<uint?>();
private List<Action> _executes = new List<Action>();
private List<uint> _execAddrs = new List<uint>();
private readonly List<Action> _executes = new List<Action>();
private readonly List<uint> _execAddrs = new List<uint>();
public void AddRead(Action function, uint? addr)
{

View File

@ -105,7 +105,7 @@ namespace BizHawk.Emulation.Common
public class MemoryDomainList : ReadOnlyCollection<MemoryDomain>
{
private int _mainMemoryIndex = 0;
private readonly int _mainMemoryIndex;
public MemoryDomainList(IList<MemoryDomain> domains)
: base(domains)

View File

@ -4,7 +4,6 @@ using System.Globalization;
using System.IO;
using BizHawk.Common;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Common.Components
{
@ -30,15 +29,15 @@ namespace BizHawk.Emulation.Common.Components
public PSGChannel[] Channels = new PSGChannel[8];
public byte VoiceLatch;
byte WaveTableWriteOffset;
private byte WaveTableWriteOffset;
Queue<QueuedCommand> commands = new Queue<QueuedCommand>(256);
long frameStartTime, frameStopTime;
private readonly Queue<QueuedCommand> commands = new Queue<QueuedCommand>(256);
private long frameStartTime, frameStopTime;
const int SampleRate = 44100;
const int PsgBase = 3580000;
static byte[] LogScale = { 0, 0, 10, 10, 13, 13, 16, 16, 20, 20, 26, 26, 32, 32, 40, 40, 51, 51, 64, 64, 81, 81, 102, 102, 128, 128, 161, 161, 203, 203, 255, 255 };
static byte[] VolumeReductionTable = { 0x1F, 0x1D, 0x1B, 0x19, 0x17, 0x15, 0x13, 0x10, 0x0F, 0x0D, 0x0B, 0x09, 0x07, 0x05, 0x03, 0x00 };
static readonly byte[] LogScale = { 0, 0, 10, 10, 13, 13, 16, 16, 20, 20, 26, 26, 32, 32, 40, 40, 51, 51, 64, 64, 81, 81, 102, 102, 128, 128, 161, 161, 203, 203, 255, 255 };
static readonly byte[] VolumeReductionTable = { 0x1F, 0x1D, 0x1B, 0x19, 0x17, 0x15, 0x13, 0x10, 0x0F, 0x0D, 0x0B, 0x09, 0x07, 0x05, 0x03, 0x00 };
public byte MainVolumeLeft;
public byte MainVolumeRight;
@ -49,8 +48,10 @@ namespace BizHawk.Emulation.Common.Components
MaxVolume = short.MaxValue;
Waves.InitWaves();
for (int i = 0; i < 8; i++)
{
Channels[i] = new PSGChannel();
}
}
public void BeginFrame(long cycles)
{

View File

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BizHawk.Common;
namespace BizHawk.Emulation.Common.Components
@ -12,19 +8,19 @@ namespace BizHawk.Emulation.Common.Components
class Pulse
{
// regs
int V;
int T;
int L;
int D;
bool LenCntDisable;
bool ConstantVolume;
bool Enable;
private int V;
private int T;
private int L;
private int D;
private bool LenCntDisable;
private bool ConstantVolume;
private bool Enable;
// envelope
bool estart;
int etime;
int ecount;
private bool estart;
private int etime;
private int ecount;
// length
static int[] lenlookup =
private static readonly int[] lenlookup =
{
10,254, 20, 2, 40, 4, 80, 6, 160, 8, 60, 10, 14, 12, 26, 14,
12, 16, 24, 18, 48, 20, 96, 22, 192, 24, 72, 26, 16, 28, 32, 30
@ -32,18 +28,18 @@ namespace BizHawk.Emulation.Common.Components
int length;
// pulse
int sequence;
static int[,] sequencelookup =
private int sequence;
private static readonly int[,] sequencelookup =
{
{0,0,0,0,0,0,0,1},
{0,0,0,0,0,0,1,1},
{0,0,0,0,1,1,1,1},
{1,1,1,1,1,1,0,0}
};
int clock;
int output;
private int clock;
private int output;
public Action<int> SendDiff;
private readonly Action<int> SendDiff;
public Pulse(Action<int> SendDiff)
{
@ -165,7 +161,7 @@ namespace BizHawk.Emulation.Common.Components
}
}
Pulse[] pulse = new Pulse[2];
private readonly Pulse[] pulse = new Pulse[2];
/// <summary>
///
@ -245,15 +241,15 @@ namespace BizHawk.Emulation.Common.Components
RaiseIRQ(PCMEnableIRQ && PCMIRQTriggered);
}
Action<bool> RaiseIRQ;
private readonly Action<bool> RaiseIRQ;
const int framereload = 7458; // ???
int frame = 0;
bool PCMRead;
bool PCMEnableIRQ;
bool PCMIRQTriggered;
byte PCMVal;
byte PCMNextVal;
private int frame;
private bool PCMRead;
private bool PCMEnableIRQ;
private bool PCMIRQTriggered;
private byte PCMVal;
private byte PCMNextVal;
public void SyncState(Serializer ser)
{
@ -288,14 +284,14 @@ namespace BizHawk.Emulation.Common.Components
}
if (PCMNextVal != PCMVal)
{
enqueuer(20 * (int)(PCMVal - PCMNextVal));
enqueuer(20 * (PCMVal - PCMNextVal));
PCMVal = PCMNextVal;
}
}
Action<int> enqueuer;
private readonly Action<int> enqueuer;
void PulseAddDiff(int value)
private void PulseAddDiff(int value)
{
enqueuer(value * 370);
//Console.WriteLine(value);

View File

@ -3,8 +3,6 @@ using System.Collections.Generic;
using System.Globalization;
using System.IO;
using BizHawk.Emulation.Common;
// TODO the freq->note translation should be moved to a separate utility class.
namespace BizHawk.Emulation.Common.Components
@ -26,7 +24,7 @@ namespace BizHawk.Emulation.Common.Components
public bool Right = true;
const int SampleRate = 44100;
static byte[] LogScale = { 0, 10, 13, 16, 20, 26, 32, 40, 51, 64, 81, 102, 128, 161, 203, 255 };
private static readonly byte[] LogScale = { 0, 10, 13, 16, 20, 26, 32, 40, 51, 64, 81, 102, 128, 161, 203, 255 };
public void Mix(short[] samples, int start, int len, int maxVolume)
{
@ -52,7 +50,7 @@ namespace BizHawk.Emulation.Common.Components
public Channel[] Channels = new Channel[4];
public byte PsgLatch;
Queue<QueuedCommand> commands = new Queue<QueuedCommand>(256);
private readonly Queue<QueuedCommand> commands = new Queue<QueuedCommand>(256);
int frameStartTime, frameStopTime;
const int PsgBase = 111861;

View File

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BizHawk.Common;
namespace BizHawk.Emulation.Common.Components
@ -16,15 +12,15 @@ namespace BizHawk.Emulation.Common.Components
{
class Pulse
{
Action<int> SendDiff;
private readonly Action<int> SendDiff;
// regs
int Period;
bool Disable;
int Volume;
private int Period;
private bool Disable;
private int Volume;
// state
int clock;
int sequence;
int output;
private int clock;
private int sequence;
private int output;
public void SyncState(Serializer ser)
{
@ -45,7 +41,10 @@ namespace BizHawk.Emulation.Common.Components
{
int newout = 1;
if (!Disable)
{
newout = sequence;
}
newout *= Volume;
if (newout != output)
{
@ -87,7 +86,7 @@ namespace BizHawk.Emulation.Common.Components
}
int RegNum;
Pulse[] pulse = new Pulse[3];
readonly Pulse[] pulse = new Pulse[3];
public void RegSelect(byte val)
{
@ -132,8 +131,8 @@ namespace BizHawk.Emulation.Common.Components
ser.EndSection();
}
Action<int> enqueuer;
void PulseAddDiff(int val)
private readonly Action<int> enqueuer;
private void PulseAddDiff(int val)
{
enqueuer(val * 250);
}
@ -142,13 +141,17 @@ namespace BizHawk.Emulation.Common.Components
{
this.enqueuer = enqueuer;
for (int i = 0; i < pulse.Length; i++)
{
pulse[i] = new Pulse(PulseAddDiff);
}
}
public void Clock()
{
for (int i = 0; i < pulse.Length; i++)
pulse[i].Clock();
foreach (Pulse p in pulse)
{
p.Clock();
}
}
}
}

View File

@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace BizHawk.Emulation.Common
@ -9,7 +6,7 @@ namespace BizHawk.Emulation.Common
/// <summary>
/// wrapper around blargg's unmanaged blip_buf
/// </summary>
public class BlipBuffer : IDisposable
public sealed class BlipBuffer : IDisposable
{
// this is transitional only. if the band-limited synthesis idea works out, i'll
// make a managed MIT implementation

View File

@ -1,7 +1,5 @@
using System.Collections.Generic;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Common
{
// Generates SEMI-synchronous sound, or "buffered asynchronous" sound.
@ -34,10 +32,10 @@ namespace BizHawk.Emulation.Common
{
public ISoundProvider BaseSoundProvider;
Queue<short> buffer = new Queue<short>(4096);
readonly Queue<short> buffer = new Queue<short>(4096);
int SamplesInOneFrame = 1470;
int TargetExtraSamples = 882;
private int SamplesInOneFrame = 1470;
private int TargetExtraSamples = 882;
const int MaxExcessSamples = 4096;
/// <summary>
@ -72,11 +70,15 @@ namespace BizHawk.Emulation.Common
BaseSoundProvider.GetSamples(mySamples);
for (int i = 0; i < mySamples.Length; i++)
buffer.Enqueue(mySamples[i]);
foreach (short s in mySamples)
{
buffer.Enqueue(s);
}
for (int i = 0; i < samples.Length; i++)
{
samples[i] = buffer.Dequeue();
}
}
}
}

View File

@ -1,16 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Common
{
/// <summary>
/// implements a DC block filter on top of an ISoundProvider. rather simple.
/// </summary>
public class DCFilter : ISoundProvider, ISyncSoundProvider
sealed public class DCFilter : ISoundProvider, ISyncSoundProvider
{
/*
* A note about accuracy:
@ -78,7 +73,7 @@ namespace BizHawk.Emulation.Common
PushThroughSamples(samples, samples, length);
}
void PushThroughSamples(short[] samplesin, short[] samplesout, int length)
private void PushThroughSamples(short[] samplesin, short[] samplesout, int length)
{
for (int i = 0; i < length; i += 2)
{

View File

@ -1,9 +1,6 @@
// C# port of C-based 3-band equalizer (C) Neil C / Etanza Systems / 2006
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BizHawk.Emulation.Common
{

View File

@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Common
{
/// <summary>
@ -10,8 +8,8 @@ namespace BizHawk.Emulation.Common
/// </summary>
public class MetaspuAsync : ISoundProvider
{
ISynchronizingAudioBuffer buffer;
ISyncSoundProvider input;
private readonly ISynchronizingAudioBuffer buffer;
private readonly ISyncSoundProvider input;
public MetaspuAsync(ISyncSoundProvider input, ESynchMethod method)
{
buffer = Metaspu.metaspu_construct(method);
@ -49,7 +47,7 @@ namespace BizHawk.Emulation.Common
{
}
short[] pullBuffer = new short[1470];
private readonly short[] pullBuffer = new short[1470];
public void PullSamples(ISoundProvider source)
{
Array.Clear(pullBuffer, 0, 1470);
@ -124,7 +122,7 @@ namespace BizHawk.Emulation.Common
}
//adjustobuf(200,1000)
bool mixqueue_go = false;
bool mixqueue_go;
public void clear()
{
@ -177,7 +175,7 @@ namespace BizHawk.Emulation.Common
return done;
}
Adjustobuf adjustobuf;
private readonly Adjustobuf adjustobuf;
class Adjustobuf
{
public Adjustobuf(int _minLatency, int _maxLatency)

View File

@ -1,5 +1,4 @@
using System.Collections.Generic;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Common
{
@ -7,7 +6,7 @@ namespace BizHawk.Emulation.Common
public sealed class SoundMixer : ISoundProvider
{
List<ISoundProvider> SoundProviders;
private readonly List<ISoundProvider> SoundProviders;
public SoundMixer(params ISoundProvider[] soundProviders)
{
@ -41,8 +40,10 @@ namespace BizHawk.Emulation.Common
{
int eachVolume = short.MaxValue / SoundProviders.Count;
foreach (var source in SoundProviders)
{
source.MaxVolume = eachVolume;
}
}
// Not actually supported on mixer.
public int MaxVolume { get; set; }

View File

@ -1,11 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Common
{
/// <summary>
@ -259,29 +254,29 @@ namespace BizHawk.Emulation.Common
/// <summary>
/// opaque pointer to state
/// </summary>
IntPtr st = IntPtr.Zero;
private IntPtr st = IntPtr.Zero;
/// <summary>
/// function to call to dispatch output
/// </summary>
Action<short[], int> drainer;
private readonly Action<short[], int> drainer;
// TODO: this size is roughly based on how big you can make the buffer before the snes resampling (32040.5 -> 44100) gets screwed up
short[] inbuf = new short[512]; //[8192]; // [512];
private short[] inbuf = new short[512]; //[8192]; // [512];
short[] outbuf;
private short[] outbuf;
// for ISyncSoundProvider
short[] outbuf2 = new short[16];
int outbuf2pos = 0;
private short[] outbuf2 = new short[16];
private int outbuf2pos = 0;
// to accept an ISyncSoundProvder input
ISyncSoundProvider input;
private readonly ISyncSoundProvider input;
/// <summary>
/// in buffer position in samples (not sample pairs)
/// </summary>
int inbufpos = 0;
private int inbufpos = 0;
/// <summary>
/// throw an exception based on error state
@ -327,10 +322,7 @@ namespace BizHawk.Emulation.Common
if (drainer != null && input != null)
throw new ArgumentException("Can't autofetch without being an ISyncSoundProvider?");
if (drainer != null)
this.drainer = drainer;
else
this.drainer = InternalDrain;
this.drainer = drainer ?? InternalDrain;
this.input = input;
outbuf = new short[inbuf.Length * ratioden / rationum / 2 * 2 + 128];

View File

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BizHawk.Common;
namespace BizHawk.Emulation.Common.Components

View File

@ -7,7 +7,6 @@
using System;
using BizHawk.Common;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Common.Components
{

View File

@ -1,10 +1,7 @@
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.IO;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Common.Components
{
// ======================================================================
@ -81,7 +78,7 @@ namespace BizHawk.Emulation.Common.Components
bool DacEnable;
byte DacValue;
Queue<QueuedCommand> commands = new Queue<QueuedCommand>();
readonly Queue<QueuedCommand> commands = new Queue<QueuedCommand>();
const int Slot1 = 0;
const int Slot2 = 2;
@ -333,7 +330,7 @@ namespace BizHawk.Emulation.Common.Components
bool n3b = !f11 & f10 & f09 & f08;
bool n3 = n3a | n3b;
op.KeyCode = (op.Block << 2) | (f11 ? 2 : 0) | (n3 ? 1 :0);
op.KeyCode = (op.Block << 2) | (f11 ? 2 : 0) | (n3 ? 1 : 0);
}
static void CalcRks(Operator op)
@ -752,7 +749,9 @@ namespace BizHawk.Emulation.Common.Components
if (op.SL_SustainLevel == 0) // If Sustain Level is 0, we skip Decay and go straight to Sustain phase.
op.EnvelopeState = EnvelopeState.Sustain;
} else {
}
else
{
// Regular Key-On
op.EnvelopeState = EnvelopeState.Attack;
@ -1079,7 +1078,7 @@ namespace BizHawk.Emulation.Common.Components
{
// This is still not a good resampler. But it's better than the other one. Unsure how much difference it makes.
// The difference with this one is that all source samples will be sampled and weighted, none skipped over.
double nativeSamplesPerOutputSample = (double) input.Length / (double) output.Length;
double nativeSamplesPerOutputSample = (double)input.Length / (double)output.Length;
int outputStereoSamples = output.Length / 2;
int inputStereoSamples = input.Length / 2;
@ -1088,10 +1087,10 @@ namespace BizHawk.Emulation.Common.Components
{
double startSample = nativeSamplesPerOutputSample * i;
double endSample = nativeSamplesPerOutputSample * (i+1);
double endSample = nativeSamplesPerOutputSample * (i + 1);
int iStartSample = (int) Math.Floor(startSample);
int iEndSample = (int) Math.Floor(endSample);
int iStartSample = (int)Math.Floor(startSample);
int iEndSample = (int)Math.Floor(endSample);
double leftSample = 0;
double rightSample = 0;
for (int j = iStartSample; j <= iEndSample; j++)
@ -1106,11 +1105,11 @@ namespace BizHawk.Emulation.Common.Components
else if (j == iEndSample)
weight = Fraction(endSample);
leftSample += ((double) input[(j * 2) + 0] * weight);
rightSample += ((double) input[(j * 2) + 1] * weight);
leftSample += ((double)input[(j * 2) + 0] * weight);
rightSample += ((double)input[(j * 2) + 1] * weight);
}
output[offset++] = (short) leftSample;
output[offset++] = (short) rightSample;
output[offset++] = (short)leftSample;
output[offset++] = (short)rightSample;
}
}