some code cleanup, mostly introducing C#6isms, also add a customized resharper+stylecop settings file in case anyone is using resharper

This commit is contained in:
adelikat 2017-04-10 10:29:51 -05:00
parent 16bf63ade8
commit fc59710dab
15 changed files with 346 additions and 488 deletions

View File

@ -1,7 +1,4 @@
using System;
using System.IO;
namespace BizHawk.Client.Common
namespace BizHawk.Client.Common
{
public class LuaFile
{

View File

@ -118,12 +118,9 @@ namespace BizHawk.Client.Common
ForEach(lua => Global.Config.RecentLua.Add(lua.Path));
_filename = path;
if (LoadCallback != null)
{
LoadCallback();
}
LoadCallback?.Invoke();
return true;
return true;
}
return false;

View File

@ -6,19 +6,16 @@ namespace BizHawk.Client.Common
public class NamedLuaFunction
{
private readonly LuaFunction _function;
private readonly string _name;
private readonly string _event;
private readonly Action _action;
public NamedLuaFunction(LuaFunction function, string theevent, Action<string> logCallback, Lua lua, string name = null)
public NamedLuaFunction(LuaFunction function, string theevent, Action<string> logCallback, Lua lua, string name = null)
{
_function = function;
_name = name ?? "Anonymous";
_event = theevent;
Name = name ?? "Anonymous";
Event = theevent;
Lua = lua;
Guid = Guid.NewGuid();
_action = delegate
Callback = delegate
{
try
{
@ -28,7 +25,7 @@ namespace BizHawk.Client.Common
{
logCallback(
"error running function attached by the event " +
_event +
Event +
"\nError message: " +
ex.Message);
}
@ -37,26 +34,18 @@ namespace BizHawk.Client.Common
public Guid Guid { get; private set; }
public string Name
{
get { return _name; }
}
public string Name { get; }
public Lua Lua { get; private set; }
public Lua Lua { get; }
public string Event
{
get { return _event; }
}
public string Event { get; }
public Action Callback
{
get { return _action; }
}
public Action Callback { get; }
public void Call(string name = null)
public void Call(string name = null)
{
LuaSandbox.Sandbox(Lua, () => {
LuaSandbox.Sandbox(Lua, () =>
{
_function.Call(name);
});
}

View File

@ -20,25 +20,25 @@ namespace BizHawk.Client.Common
{ "NES_PAL", 50.006977968268290849 },
{ "FDS", 60.098813897440515532 },
{ "FDS_PAL", 50.006977968268290849 },
{ "SNES", (double)21477272 / (4 * 341 * 262) }, //60.098475521
{ "SNES_PAL", (double)21281370 / (4 * 341 * 312) }, //50.0069789082
{ "SGB", (double)21477272 / (4 * 341 * 262) }, //60.098475521
{ "SGB_PAL", (double)21281370 / (4 * 341 * 312) }, //50.0069789082
{ "PCE", (7159090.90909090 / 455 / 263) }, //59.8261054535
{ "PCECD", (7159090.90909090 / 455 / 263) }, //59.8261054535
{ "SMS", (3579545 / 262.0 / 228.0) }, //59.9227434043
{ "SMS_PAL", (3546893 / 313.0 / 228.0) }, //49.7014320946
{ "GG", (3579545 / 262.0 / 228.0) }, //59.9227434043
{ "GG_PAL", (3546893 / 313.0 / 228.0) }, //49.7014320946
{ "SG", (3579545 / 262.0 / 228.0) }, //59.9227434043
{ "SG_PAL", (3546893 / 313.0 / 228.0) }, //49.7014320946
{ "NGP", (6144000.0 / (515 * 198)) }, //60.2530155928
{ "VBOY", (20000000.0 / (259 * 384 * 4)) }, //50.2734877735
{ "SNES", (double)21477272 / (4 * 341 * 262) }, // 60.098475521
{ "SNES_PAL", (double)21281370 / (4 * 341 * 312) }, // 50.0069789082
{ "SGB", (double)21477272 / (4 * 341 * 262) }, // 60.098475521
{ "SGB_PAL", (double)21281370 / (4 * 341 * 312) }, // 50.0069789082
{ "PCE", (7159090.90909090 / 455 / 263) }, // 59.8261054535
{ "PCECD", (7159090.90909090 / 455 / 263) }, // 59.8261054535
{ "SMS", (3579545 / 262.0 / 228.0) }, // 59.9227434043
{ "SMS_PAL", (3546893 / 313.0 / 228.0) }, // 49.7014320946
{ "GG", (3579545 / 262.0 / 228.0) }, // 59.9227434043
{ "GG_PAL", (3546893 / 313.0 / 228.0) }, // 49.7014320946
{ "SG", (3579545 / 262.0 / 228.0) }, // 59.9227434043
{ "SG_PAL", (3546893 / 313.0 / 228.0) }, // 49.7014320946
{ "NGP", (6144000.0 / (515 * 198)) }, // 60.2530155928
{ "VBOY", (20000000.0 / (259 * 384 * 4)) }, // 50.2734877735
{ "Lynx", 16000000.0 / ( 16 * 105 * 159 ) }, // 59.89817310572028
{ "WSWAN", (3072000.0 / (159 * 256)) }, //75.4716981132
{ "GB", 262144.0 / 4389.0 }, //59.7275005696
{ "GBC", 262144.0 / 4389.0 }, //59.7275005696
{ "GBA", 262144.0 / 4389.0 }, //59.7275005696
{ "WSWAN", (3072000.0 / (159 * 256)) }, // 75.4716981132
{ "GB", 262144.0 / 4389.0 }, // 59.7275005696
{ "GBC", 262144.0 / 4389.0 }, // 59.7275005696
{ "GBA", 262144.0 / 4389.0 }, // 59.7275005696
{ "GEN", 53693175 / (3420.0 * 262) },
{ "GEN_PAL", 53203424 / (3420.0 * 313) },
// while the number of scanlines per frame is software controlled and variable, we
@ -51,24 +51,24 @@ namespace BizHawk.Client.Common
{ "Coleco", 59.9227510135505 },
//according to http://problemkaputt.de/psx-spx.htm
{"PSX", 44100.0*768*11/7/263/3413}, //59.292862562
{"PSX_PAL", 44100.0*768*11/7/314/3406}, //49.7645593576
{ "PSX", 44100.0*768*11/7/263/3413 }, // 59.292862562
{ "PSX_PAL", 44100.0*768*11/7/314/3406 }, // 49.7645593576
{"C64_PAL", PAL_CARRIER*2/9/312/63},
{"C64_NTSC", NTSC_CARRIER*2/7/263/65},
{"C64_NTSC_OLD", NTSC_CARRIER*2/7/262/64},
{"C64_DREAN", PAL_N_CARRIER*2/7/312/65},
{"INTV", 59.92 }
{ "C64_PAL", PAL_CARRIER*2/9/312/63 },
{ "C64_NTSC", NTSC_CARRIER*2/7/263/65 },
{ "C64_NTSC_OLD", NTSC_CARRIER*2/7/262/64 },
{ "C64_DREAN", PAL_N_CARRIER*2/7/312/65 },
{ "INTV", 59.92 }
//according to ryphecha, using
//clocks[2] = { 53.693182e06, 53.203425e06 }; //ntsc console, pal console
//lpf[2][2] = { { 263, 262.5 }, { 314, 312.5 } }; //ntsc,pal; noninterlaced, interlaced
//cpl[2] = { 3412.5, 3405 }; //ntsc mode, pal mode
//PAL PS1: 0, PAL Mode: 0, Interlaced: 0 --- 59.826106 (53.693182e06/(263*3412.5))
//PAL PS1: 0, PAL Mode: 0, Interlaced: 1 --- 59.940060 (53.693182e06/(262.5*3412.5))
//PAL PS1: 1, PAL Mode: 1, Interlaced: 0 --- 49.761427 (53.203425e06/(314*3405))
//PAL PS1: 1, PAL Mode: 1, Interlaced: 1 --- 50.000282(53.203425e06/(312.5*3405))
// according to ryphecha, using
// clocks[2] = { 53.693182e06, 53.203425e06 }; //ntsc console, pal console
// lpf[2][2] = { { 263, 262.5 }, { 314, 312.5 } }; //ntsc,pal; noninterlaced, interlaced
// cpl[2] = { 3412.5, 3405 }; //ntsc mode, pal mode
// PAL PS1: 0, PAL Mode: 0, Interlaced: 0 --- 59.826106 (53.693182e06/(263*3412.5))
// PAL PS1: 0, PAL Mode: 0, Interlaced: 1 --- 59.940060 (53.693182e06/(262.5*3412.5))
// PAL PS1: 1, PAL Mode: 1, Interlaced: 0 --- 49.761427 (53.203425e06/(314*3405))
// PAL PS1: 1, PAL Mode: 1, Interlaced: 1 --- 50.000282(53.203425e06/(312.5*3405))
};
public double this[string systemId, bool pal]

View File

@ -39,50 +39,48 @@ namespace BizHawk.Client.Common
.Append(X).Append(" ")
.Append(Y).Append(" ")
.Append(Duration).Append(" ")
.Append(string.Format("{0:X8}", Color)).Append(" ")
.Append($"{Color:X8}").Append(" ")
.Append(Message);
return sb.ToString();
}
public string ToSubRip(int index, double fps, bool addcolortag)
{
var sb = new StringBuilder();
{
var sb = new StringBuilder();
sb.Append(index.ToString());
sb.Append("\r\n");
sb.Append(index.ToString());
sb.Append("\r\n");
// Frame timing
double start = (double)Frame;
double end = (double)(Frame + Duration);
// Frame timing
double start = (double)Frame;
double end = (double)(Frame + Duration);
int startTime = (int)(start * 1000 / fps);
int endTime = (int)(end * 1000 / fps);
int startTime = (int)(start * 1000 / fps);
int endTime = (int)(end * 1000 / fps);
var startString = string.Format(
"{0:d2}:{1:d2}:{2:d2},{3:d3}",
startTime / 3600000,
(startTime / 60000) % 60,
(startTime / 1000) % 60,
startTime % 1000
);
var startString = string.Format(
"{0:d2}:{1:d2}:{2:d2},{3:d3}",
startTime / 3600000,
(startTime / 60000) % 60,
(startTime / 1000) % 60,
startTime % 1000);
var endString = string.Format(
"{0:d2}:{1:d2}:{2:d2},{3:d3}",
endTime / 3600000,
(endTime / 60000) % 60,
(endTime / 1000) % 60,
endTime % 1000
);
var endString = string.Format(
"{0:d2}:{1:d2}:{2:d2},{3:d3}",
endTime / 3600000,
(endTime / 60000) % 60,
(endTime / 1000) % 60,
endTime % 1000);
sb.Append(startString);
sb.Append(" --> ");
sb.Append(endString);
sb.Append("\r\n");
sb.Append(startString);
sb.Append(" --> ");
sb.Append(endString);
sb.Append("\r\n");
// TODO: Positioning
// TODO: Positioning
// Color tag open
// Color tag open
if (addcolortag)
{
uint rgb = (Color & 0x00FFFFFF);
@ -91,20 +89,21 @@ namespace BizHawk.Client.Common
sb.Append("\">");
}
// Message text
sb.Append(Message.Trim());
// Message text
sb.Append(Message.Trim());
// Color tag closeaddcolortag
// Color tag closeaddcolortag
if (addcolortag)
{
sb.Append("</font>");
}
sb.Append("\r\n");
// Seperator
sb.Append("\r\n");
// Seperator
sb.Append("\r\n");
return sb.ToString();
return sb.ToString();
}
}
}

View File

@ -113,8 +113,8 @@ namespace BizHawk.Client.Common
subs = subs.OrderBy(s => s.Frame).ThenByDescending(s => s.Y).ToList();
}
foreach (var subtitle in subs)
sb.Append(subtitle.ToSubRip(index++, fps, AddColorTag));
foreach (var subtitle in subs)
sb.Append(subtitle.ToSubRip(index++, fps, AddColorTag));
return sb.ToString();
}

View File

@ -19,7 +19,7 @@ namespace BizHawk.Client.Common
private int? _compare;
private int _val;
private bool _enabled;
private COMPARISONTYPE _comparisonType;
private readonly COMPARISONTYPE _comparisonType;
public Cheat(Watch watch, int value, int? compare = null, bool enabled = true, COMPARISONTYPE comparisonType = COMPARISONTYPE.NONE)
@ -50,8 +50,7 @@ namespace BizHawk.Client.Common
cheat.Size,
cheat.Type,
cheat.BigEndian ?? false,
cheat.Name
);
cheat.Name);
_compare = cheat.Compare;
_val = cheat.Value ?? 0;
@ -62,77 +61,35 @@ namespace BizHawk.Client.Common
public delegate void CheatEventHandler(object sender);
public event CheatEventHandler Changed;
public static Cheat Separator
{
get { return new Cheat(SeparatorWatch.Instance, 0, null, false); }
}
public static Cheat Separator => new Cheat(SeparatorWatch.Instance, 0, null, false);
public bool IsSeparator
{
get { return _watch.IsSeparator; }
}
public bool IsSeparator => _watch.IsSeparator;
public bool Enabled
{
get { return !IsSeparator && _enabled; }
}
public bool Enabled => !IsSeparator && _enabled;
public long? Address
{
get { return _watch.Address; }
}
public long? Address => _watch.Address;
public int? Value
{
get { return IsSeparator ? (int?)null : _val; }
}
public int? Value => IsSeparator ? (int?)null : _val;
public bool? BigEndian
{
get { return IsSeparator ? (bool?)null : _watch.BigEndian; }
}
public bool? BigEndian => IsSeparator ? (bool?)null : _watch.BigEndian;
public int? Compare
{
get { return _compare.HasValue && !IsSeparator ? _compare : null; }
}
public int? Compare => _compare.HasValue && !IsSeparator ? _compare : null;
public MemoryDomain Domain
{
get { return _watch.Domain; }
}
public MemoryDomain Domain => _watch.Domain;
public WatchSize Size
{
get { return _watch.Size; }
}
public WatchSize Size => _watch.Size;
public char SizeAsChar
{
get { return _watch.SizeAsChar; }
}
public char SizeAsChar => _watch.SizeAsChar;
public DisplayType Type
{
get { return _watch.Type; }
}
public DisplayType Type => _watch.Type;
public char TypeAsChar
{
get { return _watch.TypeAsChar; }
}
public char TypeAsChar => _watch.TypeAsChar;
public string Name
{
get { return IsSeparator ? string.Empty : _watch.Notes; }
}
public string Name => IsSeparator ? string.Empty : _watch.Notes;
public string AddressStr
{
get { return _watch.AddressString; }
}
public string AddressStr => _watch.AddressString;
public string ValueStr
public string ValueStr
{
get
{
@ -175,12 +132,9 @@ namespace BizHawk.Client.Common
}
}
public COMPARISONTYPE ComparisonType
{
get { return _comparisonType; }
}
public COMPARISONTYPE ComparisonType => _comparisonType;
public void Enable(bool handleChange = true)
public void Enable(bool handleChange = true)
{
if (!IsSeparator)
{
@ -278,7 +232,7 @@ namespace BizHawk.Client.Common
}
else
{
switch(_watch.Size)
switch (_watch.Size)
{
case WatchSize.Byte:
_watch.Poke((_watch as ByteWatch).FormatValue((byte)_val));
@ -304,10 +258,10 @@ namespace BizHawk.Client.Common
case WatchSize.Byte:
return _watch.Address == addr;
case WatchSize.Word:
return (addr == _watch.Address) || (addr == (_watch.Address) + 1);
return (addr == _watch.Address) || (addr == _watch.Address + 1);
case WatchSize.DWord:
return (addr == (_watch.Address)) || (addr == (_watch.Address) + 1) ||
(addr == (_watch.Address) + 2) || (addr == (_watch.Address) + 3);
return (addr == _watch.Address) || (addr == _watch.Address + 1) ||
(addr == _watch.Address + 2) || (addr == _watch.Address + 3);
}
}
@ -325,22 +279,24 @@ namespace BizHawk.Client.Common
case WatchSize.Byte:
return (byte?)_val;
case WatchSize.Word:
if (addr == (_watch.Address))
if (addr == _watch.Address)
{
return (byte)(_val >> 8);
}
return (byte)(_val & 0xFF);
case WatchSize.DWord:
if (addr == (_watch.Address))
if (addr == _watch.Address)
{
return (byte)((_val >> 24) & 0xFF);
}
else if (addr == (_watch.Address) + 1)
if (addr == _watch.Address + 1)
{
return (byte)((_val >> 16) & 0xFF);
}
else if (addr == ((_watch.Address)) + 2)
if (addr == _watch.Address + 2)
{
return (byte)((_val >> 8) & 0xFF);
}
@ -398,10 +354,7 @@ namespace BizHawk.Client.Common
private void Changes()
{
if (Changed != null)
{
Changed(this);
}
Changed?.Invoke(this);
}
public override bool Equals(object obj)

View File

@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
@ -20,12 +21,9 @@ namespace BizHawk.Client.Common
public delegate void CheatListEventHandler(object sender, CheatListEventArgs e);
public event CheatListEventHandler Changed;
public int Count
{
get { return _cheatList.Count; }
}
public int Count => _cheatList.Count;
public int CheatCount
public int CheatCount
{
get { return _cheatList.Count(x => !x.IsSeparator); }
}
@ -52,19 +50,13 @@ namespace BizHawk.Client.Common
}
}
public string CurrentFileName
{
get { return _currentFileName; }
}
public string CurrentFileName => _currentFileName;
public bool IsReadOnly { get { return false; } }
public bool IsReadOnly => false;
public Cheat this[int index]
{
get { return _cheatList[index]; }
}
public Cheat this[int index] => _cheatList[index];
public Cheat this[MemoryDomain domain, long address]
public Cheat this[MemoryDomain domain, long address]
{
get
{
@ -77,7 +69,7 @@ namespace BizHawk.Client.Common
return _cheatList.GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
@ -116,7 +108,6 @@ namespace BizHawk.Client.Common
Save();
}
_cheatList.Clear();
_currentFileName = string.Empty;
Changes = false;
@ -154,7 +145,7 @@ namespace BizHawk.Client.Common
c.Changed += CheatChanged;
if (_cheatList.Any(x => x.Domain == c.Domain && x.Address == c.Address))
{
_cheatList.FirstOrDefault(x => x.Domain == c.Domain && x.Address == c.Address).Enable();
_cheatList.First(x => x.Domain == c.Domain && x.Address == c.Address).Enable();
}
else
{
@ -168,7 +159,9 @@ namespace BizHawk.Client.Common
{
int index = _cheatList.IndexOf(oldCheat);
if (index == -1)
{
return false;
}
_cheatList[index] = newCheat;
Changes = true;
@ -290,7 +283,7 @@ namespace BizHawk.Client.Common
/// Returns the value of a given cheat, or a partial value of a multi-byte cheat
/// Note that address + size MUST NOT exceed the range of the cheat or undefined behavior will occur
/// </summary>
/// <param name="addr">The starting address for which you will get the number of bytes
/// <param name="addr">The starting address for which you will get the number of bytes</param>
/// <param name="size">The number of bytes of the cheat to return</param>
/// <returns>The value, or null if it can't resolve the address with a given cheat</returns>
public int? GetCheatValue(MemoryDomain domain, long addr, WatchSize size)
@ -390,14 +383,14 @@ namespace BizHawk.Client.Common
sb
.Append(cheat.AddressStr).Append('\t')
.Append(cheat.ValueStr).Append('\t')
.Append(cheat.Compare.HasValue ? cheat.Compare.Value.ToString() : "N").Append('\t')
.Append(cheat.Compare?.ToString() ?? "N").Append('\t')
.Append(cheat.Domain != null ? cheat.Domain.Name : string.Empty).Append('\t')
.Append(cheat.Enabled ? '1' : '0').Append('\t')
.Append(cheat.Name).Append('\t')
.Append(cheat.SizeAsChar).Append('\t')
.Append(cheat.TypeAsChar).Append('\t')
.Append((cheat.BigEndian ?? false) ? '1' : '0').Append('\t')
.Append(cheat.ComparisonType.ToString()).Append('\t')
.Append(cheat.ComparisonType).Append('\t')
.AppendLine();
}
}
@ -488,7 +481,7 @@ namespace BizHawk.Client.Common
{
if(!Enum.TryParse<Cheat.COMPARISONTYPE>(vals[9], out comparisonType))
{
continue; //Not sure if this is the best answer, could just resort to ==
continue; // Not sure if this is the best answer, could just resort to ==
}
}
@ -498,7 +491,7 @@ namespace BizHawk.Client.Common
size,
type,
bigendian,
name);
name);
Add(new Cheat(watch, value, compare, !Global.Config.DisableCheatsOnLoad && enabled, comparisonType));
}
@ -714,11 +707,7 @@ namespace BizHawk.Client.Common
private void CheatChanged(object sender)
{
if (Changed != null)
{
Changed(this, new CheatListEventArgs(sender as Cheat));
}
Changed?.Invoke(this, new CheatListEventArgs(sender as Cheat));
_changes = true;
}

View File

@ -5,7 +5,6 @@ using System.Linq;
using BizHawk.Common;
using BizHawk.Common.CollectionExtensions;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common.IEmulatorExtensions;
namespace BizHawk.Client.Common
{
@ -509,17 +508,11 @@ namespace BizHawk.Client.Common
set { _keepHistory = value; }
}
public bool CanUndo
{
get { return _keepHistory && _history.CanUndo; }
}
public bool CanUndo => _keepHistory && _history.CanUndo;
public bool CanRedo
{
get { return _keepHistory && _history.CanRedo; }
}
public bool CanRedo => _keepHistory && _history.CanRedo;
public void ClearHistory()
public void ClearHistory()
{
_history.Clear();
}
@ -608,8 +601,7 @@ namespace BizHawk.Client.Common
long val = SignExtendAsNeeded(GetValue(x.Address));
long prev = SignExtendAsNeeded(x.Previous);
return (val + _differentBy.Value == prev) || (val - _differentBy.Value == prev);
}
);
});
}
else
{
@ -872,7 +864,11 @@ namespace BizHawk.Client.Common
private long SignExtendAsNeeded(long val)
{
if (_settings.Type != DisplayType.Signed) return val;
if (_settings.Type != DisplayType.Signed)
{
return val;
}
switch (_settings.Size)
{
default:
@ -887,7 +883,7 @@ namespace BizHawk.Client.Common
private long GetValue(long addr)
{
//do not return sign extended variables from here.
// do not return sign extended variables from here.
switch (_settings.Size)
{
default:
@ -924,7 +920,7 @@ namespace BizHawk.Client.Common
public interface IMiniWatch
{
long Address { get; }
long Previous { get; } //do not store sign extended variables in here.
long Previous { get; } // do not store sign extended variables in here.
void SetPreviousToCurrent(MemoryDomain domain, bool bigendian);
}
@ -947,12 +943,9 @@ namespace BizHawk.Client.Common
_previous = domain.PeekByte(Address % domain.Size);
}
public long Previous
{
get { return _previous; }
}
public long Previous => _previous;
public void SetPreviousToCurrent(MemoryDomain domain, bool bigendian)
public void SetPreviousToCurrent(MemoryDomain domain, bool bigendian)
{
_previous = domain.PeekByte(Address % domain.Size);
}
@ -991,12 +984,9 @@ namespace BizHawk.Client.Common
_previous = domain.PeekUint(Address % domain.Size, bigEndian);
}
public long Previous
{
get { return _previous; }
}
public long Previous => _previous;
public void SetPreviousToCurrent(MemoryDomain domain, bool bigendian)
public void SetPreviousToCurrent(MemoryDomain domain, bool bigendian)
{
_previous = domain.PeekUint(Address, bigendian);
}
@ -1021,17 +1011,11 @@ namespace BizHawk.Client.Common
_previous = _prevFrame = domain.PeekByte(Address % domain.Size);
}
public long Previous
{
get { return _previous; }
}
public long Previous => _previous;
public int ChangeCount
{
get { return _changecount; }
}
public int ChangeCount => _changecount;
public void Update(PreviousType type, MemoryDomain domain, bool bigendian)
public void Update(PreviousType type, MemoryDomain domain, bool bigendian)
{
var value = domain.PeekByte(Address % domain.Size);
@ -1082,17 +1066,11 @@ namespace BizHawk.Client.Common
_previous = _prevFrame = domain.PeekUshort(Address % domain.Size, bigendian);
}
public long Previous
{
get { return _previous; }
}
public long Previous => _previous;
public int ChangeCount
{
get { return _changecount; }
}
public int ChangeCount => _changecount;
public void Update(PreviousType type, MemoryDomain domain, bool bigendian)
public void Update(PreviousType type, MemoryDomain domain, bool bigendian)
{
var value = domain.PeekUshort(Address % domain.Size, bigendian);
if (value != Previous)
@ -1110,7 +1088,9 @@ namespace BizHawk.Client.Common
break;
case PreviousType.LastChange:
if (_prevFrame != value)
{
_previous = _prevFrame;
}
break;
}

View File

@ -40,14 +40,15 @@ namespace BizHawk.Client.Common
{
if (value == 0)
{
this._value = GetByte();
_value = GetByte();
}
else
{
this._value = value;
_value = value;
}
this._previous = previous;
this._changecount = changeCount;
_previous = previous;
_changecount = changeCount;
}
#endregion
@ -55,7 +56,7 @@ namespace BizHawk.Client.Common
#region Methods
/// <summary>
/// Enumerate wich <see cref="DisplayType"/> are valid for a <see cref="ByteWatch"/>
/// Enumerate which <see cref="DisplayType"/> are valid for a <see cref="ByteWatch"/>
/// </summary>
public static IEnumerable<DisplayType> ValidTypes
{
@ -200,7 +201,7 @@ namespace BizHawk.Client.Common
#endregion Implements
//TODO: Implements IFormattable
// TODO: Implements IFormattable
public string FormatValue(byte val)
{
switch (Type)
@ -242,77 +243,41 @@ namespace BizHawk.Client.Common
diff = "-";
}
return string.Format("{0}{1}", diff, FormatValue((byte)Math.Abs(diffVal)));
return $"{diff}{FormatValue((byte)Math.Abs(diffVal))}";
}
}
/// <summary>
/// Get the maximum possible value
/// </summary>
public override uint MaxValue
{
get
{
return byte.MaxValue;
}
}
public override uint MaxValue => byte.MaxValue;
/// <summary>
/// <summary>
/// Get the current value
/// </summary>
public override int Value
{
get
{
return GetByte();
}
}
public override int Value => GetByte();
/// <summary>
/// <summary>
/// Gets the current value
/// but with stuff I don't understand
/// </summary>
/// <remarks>zero 15-nov-2015 - bypass LIAR LOGIC, see fdc9ea2aa922876d20ba897fb76909bf75fa6c92 https://github.com/TASVideos/BizHawk/issues/326 </remarks>
public override int ValueNoFreeze
{
get
{
return GetByte(true);
}
}
public override int ValueNoFreeze => GetByte(true);
/// <summary>
/// <summary>
/// Get a string representation of the current value
/// </summary>
public override string ValueString
{
get
{
return FormatValue(GetByte());
}
}
public override string ValueString => FormatValue(GetByte());
/// <summary>
/// <summary>
/// Get the previous value
/// </summary>
public override int Previous
{
get
{
return _previous;
}
}
public override int Previous => _previous;
/// <summary>
/// <summary>
/// Get a string representation of the previous value
/// </summary>
public override string PreviousStr
{
get
{
return FormatValue(_previous);
}
}
public override string PreviousStr => FormatValue(_previous);
#endregion Implements

View File

@ -9,42 +9,50 @@
/// Separator, only used by <see cref="SeparatorWatch"/>
/// </summary>
Separator,
/// <summary>
/// Display the value as a signed integer
/// Used by <see cref="ByteWatch"/>, <see cref="WordWatch"/> and <see cref="DWordWatch"/>
/// </summary>
Signed,
/// <summary>
/// Display the value as an unsigned integer
/// Used by <see cref="ByteWatch"/>, <see cref="WordWatch"/> and <see cref="DWordWatch"/>
/// </summary>
Unsigned,
/// <summary>
/// Raw hexadecimal display
/// Used by <see cref="ByteWatch"/>, <see cref="WordWatch"/> and <see cref="DWordWatch"/>
/// </summary>
Hex,
/// <summary>
/// Raw binary display
/// Used by <see cref="ByteWatch"/>, <see cref="WordWatch"/> and <see cref="DWordWatch"/>
/// If you can read it easily, you're probably a computer
/// </summary>
Binary,
/// <summary>
/// Display the value as fractionnal number. 12 before coma and 4 after
/// Used only by <see cref="WordWatch"/> as it is 16 bits length
/// </summary>
FixedPoint_12_4,
/// <summary>
/// Display the value as fractionnal number. 20 before coma and 12 after
/// Used only by <see cref="DWordWatch"/> as it is 32 bits length
/// </summary>
FixedPoint_20_12,
/// <summary>
/// Display the value as fractionnal number. 16 before coma and 16 after
/// Used only by <see cref="DWordWatch"/> as it is 32 bits length
/// </summary>
FixedPoint_16_16,
/// <summary>
/// The traditionnal float type as in C++ <seealso cref="float"/>
/// Used only by <see cref="DWordWatch"/> as it is 32 bits length

View File

@ -1,11 +1,11 @@
using BizHawk.Common.NumberExtensions;
using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common;
using System;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using BizHawk.Common.NumberExtensions;
using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common
{
@ -40,14 +40,15 @@ namespace BizHawk.Client.Common
{
if (value == 0)
{
this._value = GetDWord();
_value = GetDWord();
}
else
{
this._value = value;
_value = value;
}
this._previous = previous;
this._changecount = changeCount;
_previous = previous;
_changecount = changeCount;
}
#endregion
@ -76,7 +77,7 @@ namespace BizHawk.Client.Common
/// <summary>
/// Get a list a <see cref="DisplayType"/> that can be used for this <see cref="DWordWatch"/>
/// </summary>
/// <returns>An enumartion that contains all valid <see cref="DisplayType"/></returns>
/// <returns>An enumeration that contains all valid <see cref="DisplayType"/></returns>
public override IEnumerable<DisplayType> AvailableTypes()
{
return ValidTypes;
@ -238,9 +239,9 @@ namespace BizHawk.Client.Common
case DisplayType.Hex:
return val.ToHexString(8);
case DisplayType.FixedPoint_20_12:
return string.Format("{0:0.######}", val / 4096.0);
return $"{val / 4096.0:0.######}";
case DisplayType.FixedPoint_16_16:
return string.Format("{0:0.######}", val / 65536.0);
return $"{val / 65536.0:0.######}";
case DisplayType.Float:
var bytes = BitConverter.GetBytes(val);
var _float = BitConverter.ToSingle(bytes, 0);
@ -259,82 +260,40 @@ namespace BizHawk.Client.Common
/// Get a string representation of difference
/// between current value and the previous one
/// </summary>
public override string Diff
{
get
{
return FormatValue(_previous - _value);
}
}
public override string Diff => FormatValue(_previous - _value);
/// <summary>
/// <summary>
/// Get the maximum possible value
/// </summary>
public override uint MaxValue
{
get
{
return uint.MaxValue;
}
}
public override uint MaxValue => uint.MaxValue;
/// <summary>
/// <summary>
/// Get the current value
/// </summary>
public override int Value
{
get
{
return (int)GetDWord();
}
}
public override int Value => (int)GetDWord();
/// <summary>
/// <summary>
/// Gets the current value
/// but with stuff I don't understand
/// </summary>
public override int ValueNoFreeze
{
get
{
return (int)GetDWord(true);
}
}
public override int ValueNoFreeze => (int)GetDWord(true);
/// <summary>
/// <summary>
/// Get a string representation of the current value
/// </summary>
public override string ValueString
{
get
{
return FormatValue(GetDWord());
}
}
public override string ValueString => FormatValue(GetDWord());
/// <summary>
/// <summary>
/// Get the previous value
/// </summary>
public override int Previous
{
get
{
return (int)_previous;
}
}
public override int Previous => (int)_previous;
/// <summary>
/// <summary>
/// Get a string representation of the previous value
/// </summary>
public override string PreviousStr
{
get
{
return FormatValue(_previous);
}
}
public override string PreviousStr => FormatValue(_previous);
#endregion Implements
#endregion Implements
#endregion
}

View File

@ -24,7 +24,7 @@ namespace BizHawk.Client.EmuHawk
private int _defaultHeight;
private string _sortedColumn = string.Empty;
private bool _sortReverse;
private bool _paused = false;
private bool _paused;
[RequiredService]
private IMemoryDomains _memoryDomains { get; set; }
@ -35,28 +35,6 @@ namespace BizHawk.Client.EmuHawk
[OptionalService]
private IDebuggable _debuggable { get; set; }
[ConfigPersist]
public RamWatchSettings Settings { get; set; }
public class RamWatchSettings : ToolDialogSettings
{
public RamWatchSettings()
{
Columns = new ColumnList
{
new Column { Name = WatchList.ADDRESS, Visible = true, Index = 0, Width = 60 },
new Column { Name = WatchList.VALUE, Visible = true, Index = 1, Width = 59 },
new Column { Name = WatchList.PREV, Visible = false, Index = 2, Width = 59 },
new Column { Name = WatchList.CHANGES, Visible = true, Index = 3, Width = 55 },
new Column { Name = WatchList.DIFF, Visible = false, Index = 4, Width = 59 },
new Column { Name = WatchList.DOMAIN, Visible = true, Index = 5, Width = 55 },
new Column { Name = WatchList.NOTES, Visible = true, Index = 6, Width = 128 },
};
}
public ColumnList Columns { get; set; }
}
public RamWatch()
{
InitializeComponent();
@ -81,6 +59,28 @@ namespace BizHawk.Client.EmuHawk
_sortReverse = false;
}
[ConfigPersist]
public RamWatchSettings Settings { get; set; }
public class RamWatchSettings : ToolDialogSettings
{
public RamWatchSettings()
{
Columns = new ColumnList
{
new Column { Name = WatchList.ADDRESS, Visible = true, Index = 0, Width = 60 },
new Column { Name = WatchList.VALUE, Visible = true, Index = 1, Width = 59 },
new Column { Name = WatchList.PREV, Visible = false, Index = 2, Width = 59 },
new Column { Name = WatchList.CHANGES, Visible = true, Index = 3, Width = 55 },
new Column { Name = WatchList.DIFF, Visible = false, Index = 4, Width = 59 },
new Column { Name = WatchList.DOMAIN, Visible = true, Index = 5, Width = 55 },
new Column { Name = WatchList.NOTES, Visible = true, Index = 6, Width = 128 },
};
}
public ColumnList Columns { get; set; }
}
private IEnumerable<int> SelectedIndices
{
get { return WatchListView.SelectedIndices.Cast<int>(); }
@ -96,8 +96,6 @@ namespace BizHawk.Client.EmuHawk
get { return SelectedItems.Where(x => !x.IsSeparator); }
}
#region Properties
public IEnumerable<Watch> Watches
{
get
@ -106,14 +104,9 @@ namespace BizHawk.Client.EmuHawk
}
}
public bool UpdateBefore
{
get { return false; }
}
public bool UpdateBefore => false;
#endregion
#region API
#region API
public void AddWatch(Watch watch)
{
@ -159,16 +152,16 @@ namespace BizHawk.Client.EmuHawk
public void LoadFileFromRecent(string path)
{
var ask_result = true;
var askResult = true;
if (_watches.Changes)
{
ask_result = AskSaveChanges();
askResult = AskSaveChanges();
}
if (ask_result)
if (askResult)
{
var load_result = _watches.Load(path, append: false);
if (!load_result)
var loadResult = _watches.Load(path, append: false);
if (!loadResult)
{
Global.Config.RecentWatches.HandleLoadError(path);
}
@ -219,8 +212,7 @@ namespace BizHawk.Client.EmuHawk
if (_watches != null
&& !string.IsNullOrWhiteSpace(_watches.CurrentFileName)
&& _watches.All(w => w.Domain == null || _memoryDomains.Select(m => m.Name).Contains(w.Domain.Name))
&& (Global.Config.RecentWatches.AutoLoad || (IsHandleCreated || !IsDisposed))
)
&& (Global.Config.RecentWatches.AutoLoad || (IsHandleCreated || !IsDisposed)))
{
_watches.RefreshDomains(_memoryDomains);
_watches.Reload();
@ -262,8 +254,7 @@ namespace BizHawk.Client.EmuHawk
Global.Config.DispRamWatchy + (i * 14),
Color.Black,
frozen ? Color.Cyan : Color.White,
0
);
0);
}
}
@ -332,8 +323,7 @@ namespace BizHawk.Client.EmuHawk
Global.Config.DispRamWatchy + (i * 14),
Color.Black,
frozen ? Color.Cyan : Color.White,
0
);
0);
}
}
}
@ -401,11 +391,15 @@ namespace BizHawk.Client.EmuHawk
if (SelectedWatches.Any())
{
foreach (var sw in SelectedWatches)
if (sw.Domain != SelectedWatches.First().Domain)
throw new InvalidOperationException("Can't edit multiple watches on varying memorydomains");
foreach (var sw in SelectedWatches)
{
if (sw.Domain != SelectedWatches.First().Domain)
{
throw new InvalidOperationException("Can't edit multiple watches on varying memorydomains");
}
}
var we = new WatchEditor
var we = new WatchEditor
{
InitialLocation = this.ChildPointToScreen(WatchListView),
MemoryDomains = _memoryDomains
@ -962,8 +956,7 @@ namespace BizHawk.Client.EmuHawk
RamWatchMenu.Items.Remove(
RamWatchMenu.Items
.OfType<ToolStripMenuItem>()
.First(x => x.Name == "GeneratedColumnsSubMenu")
);
.First(x => x.Name == "GeneratedColumnsSubMenu"));
RamWatchMenu.Items.Add(Settings.Columns.GenerateColumnsMenu(ColumnToggleCallback));
@ -1042,7 +1035,7 @@ namespace BizHawk.Client.EmuHawk
SelectedWatches.Any() &&
_debuggable != null &&
_debuggable.MemoryCallbacksAvailable() &&
SelectedWatches.All(w => w.Domain.Name == (_memoryDomains != null ? _memoryDomains.SystemBus.Name : ""));
SelectedWatches.All(w => w.Domain.Name == (_memoryDomains != null ? _memoryDomains.SystemBus.Name : string.Empty));
PokeContextMenuItem.Enabled =
FreezeContextMenuItem.Visible =
@ -1168,7 +1161,7 @@ namespace BizHawk.Client.EmuHawk
private void ErrorIconButton_Click(object sender, EventArgs e)
{
var items = _watches
.Where(watch => (watch.Address) >= watch.Domain.Size)
.Where(watch => watch.Address >= watch.Domain.Size)
.ToList();
foreach (var item in items)

29
BizHawk.sln.DotSettings Normal file
View File

@ -0,0 +1,29 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1101/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1126/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1200/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1309/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1402/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1600/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1601/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1602/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1611/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1615/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1633/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1027/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1201/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1202/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1210/@EntryIndexedValue">DO_NOT_SHOW</s:String></wpf:ResourceDictionary>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/ThisQualifier/INSTANCE_MEMBERS_QUALIFY_MEMBERS/@EntryValue">None</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CSharpUsing/AddImportsToDeepestScope/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;</s:String></wpf:ResourceDictionary>
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1027/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1201/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1202/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1210/@EntryIndexedValue">DO_NOT_SHOW</s:String></wpf:ResourceDictionary>