Some code cleanup tinkerings in Client.Common

This commit is contained in:
adelikat 2014-02-03 20:48:01 +00:00
parent 3dfcd8b22a
commit 23f7017651
20 changed files with 247 additions and 298 deletions

View File

@ -1,13 +1,13 @@
using System;
using System.Linq;
using System.Linq;
namespace BizHawk.Client.Common
{
// TODO: these classes are worthless or need to be extensions, decide which
public static class StringHelpers
{
public static int HowMany(string str, char c)
{
return !String.IsNullOrEmpty(str) ? str.Count(t => t == c) : 0;
return !string.IsNullOrEmpty(str) ? str.Count(t => t == c) : 0;
}
public static int HowMany(string str, string s)
@ -28,27 +28,27 @@ namespace BizHawk.Client.Common
// TODO: put it in its own file
public static class IntHelpers // TODO: a less lame name
{
public static int GetNumDigits(Int32 i)
public static int GetNumDigits(int i)
{
if (i < 0x100)
{
return 2;
}
else if (i < 0x10000)
if (i < 0x10000)
{
return 4;
}
else if (i < 0x1000000)
if (i < 0x1000000)
{
return 6;
}
else
{
return 8;
}
return 8;
}
public static uint MaxHexValueFromMaxDigits(Int32 i)
public static uint MaxHexValueFromMaxDigits(int i)
{
switch (i)
{
@ -74,5 +74,5 @@ namespace BizHawk.Client.Common
return int.MaxValue;
}
}
}
}

View File

@ -111,7 +111,7 @@ namespace BizHawk.Client.Common
"byteswap_16",
"Byte swaps 'short', i.e. bit.byteswap_16(0xFF00) would return 0x00FF"
)]
public static ushort Byteswap_16(ushort val)
public static ushort Byteswap16(ushort val)
{
return (ushort)((val & 0xFFU) << 8 | (val & 0xFF00U) >> 8);
}
@ -120,7 +120,7 @@ namespace BizHawk.Client.Common
"byteswap_32",
"Byte swaps 'dword'"
)]
public static uint Byteswap_32(uint val)
public static uint Byteswap32(uint val)
{
return (val & 0x000000FFU) << 24 | (val & 0x0000FF00U) << 8 |
(val & 0x00FF0000U) >> 8 | (val & 0xFF000000U) >> 24;
@ -130,12 +130,12 @@ namespace BizHawk.Client.Common
"byteswap_64",
"Byte swaps 'long'"
)]
public static UInt64 Byteswap_64(ulong val)
public static UInt64 Byteswap64(ulong val)
{
return (val & 0x00000000000000FFUL) << 56 | (val & 0x000000000000FF00UL) << 40 |
(val & 0x0000000000FF0000UL) << 24 | (val & 0x00000000FF000000UL) << 8 |
(val & 0x000000FF00000000UL) >> 8 | (val & 0x0000FF0000000000UL) >> 24 |
(val & 0x00FF000000000000UL) >> 40 | (val & 0xFF00000000000000UL) >> 56;
(val & 0x0000000000FF0000UL) << 24 | (val & 0x00000000FF000000UL) << 8 |
(val & 0x000000FF00000000UL) >> 8 | (val & 0x0000FF0000000000UL) >> 24 |
(val & 0x00FF000000000000UL) >> 40 | (val & 0xFF00000000000000UL) >> 56;
}
}
}

View File

@ -13,6 +13,10 @@ namespace BizHawk.Client.Common
public class EmulatorLuaLibrary : LuaLibraryBase
{
private readonly Lua _lua;
private readonly Action _frameAdvanceCallback;
private readonly Action _yieldCallback;
public EmulatorLuaLibrary(Lua lua, Action frameAdvanceCallback, Action yieldCallback)
{
_lua = lua;
@ -22,10 +26,6 @@ namespace BizHawk.Client.Common
public override string Name { get { return "emu"; } }
private readonly Lua _lua;
private readonly Action _frameAdvanceCallback;
private readonly Action _yieldCallback;
private static void SetrenderplanesDo(IList<object> luaParam)
{
if (Global.Emulator is NES)

View File

@ -7,6 +7,8 @@ namespace BizHawk.Client.Common
{
public class EventLuaLibrary : LuaLibraryBase
{
private readonly LuaFunctionList _luaFunctions = new LuaFunctionList();
public EventLuaLibrary(Action<string> logOutputCallback)
{
LogOutputCallback = logOutputCallback;
@ -19,8 +21,6 @@ namespace BizHawk.Client.Common
#region Events Library Helpers
private readonly LuaFunctionList _luaFunctions = new LuaFunctionList();
public LuaFunctionList RegisteredFunctions { get { return _luaFunctions; } }
public void CallSaveStateEvent(string name)

View File

@ -7,6 +7,8 @@ namespace BizHawk.Client.Common
// TODO: this needs a major refactor, as well as MemoryLuaLibrary, and this shoudl inherit memorylua library and extend it
public class MainMemoryLuaLibrary : LuaLibraryBase
{
private readonly Lua _lua;
public MainMemoryLuaLibrary(Lua lua)
{
_lua = lua;
@ -14,8 +16,6 @@ namespace BizHawk.Client.Common
public override string Name { get { return "mainmemory"; } }
private readonly Lua _lua;
#region Main Memory Library Helpers
private static int U2S(uint u, int size)
@ -123,9 +123,9 @@ namespace BizHawk.Client.Common
var table = _lua.NewTable();
for (var i = addr; i <= lastAddr; i++)
{
var a = String.Format("{0:X2}", i);
var a = string.Format("{0:X2}", i);
var v = Global.Emulator.MemoryDomains.MainMemory.PeekByte(i);
var vs = String.Format("{0:X2}", (int)v);
var vs = string.Format("{0:X2}", (int)v);
table[a] = vs;
}
@ -162,8 +162,7 @@ namespace BizHawk.Client.Common
{
Global.Emulator.MemoryDomains.MainMemory.PokeByte(
LuaInt(address),
(byte)LuaInt(memoryblock[address])
);
(byte)LuaInt(memoryblock[address]));
}
}

View File

@ -5,10 +5,10 @@ namespace BizHawk.Client.Common
{
public class MemoryLuaLibrary : LuaLibraryBase
{
public override string Name { get { return "memory"; } }
private int _currentMemoryDomain; // Main memory by default
public override string Name { get { return "memory"; } }
#region Memory Library Helpers
private static int U2S(uint u, int size)
@ -95,7 +95,7 @@ namespace BizHawk.Client.Common
)]
public string GetMemoryDomainList()
{
return Global.Emulator.MemoryDomains.Aggregate(String.Empty, (current, t) => current + (t.Name + '\n'));
return Global.Emulator.MemoryDomains.Aggregate(string.Empty, (current, t) => current + (t.Name + '\n'));
}
[LuaMethodAttributes(

View File

@ -4,6 +4,8 @@ namespace BizHawk.Client.Common
{
public class MovieLuaLibrary : LuaLibraryBase
{
private readonly Lua _lua;
public MovieLuaLibrary(Lua lua)
{
_lua = lua;
@ -11,8 +13,6 @@ namespace BizHawk.Client.Common
public override string Name { get { return "movie"; } }
private readonly Lua _lua;
[LuaMethodAttributes(
"filename",
"Returns the file name including path of the currently loaded movie"
@ -32,8 +32,7 @@ namespace BizHawk.Client.Common
var m = new MovieControllerAdapter { Type = Global.MovieSession.MovieControllerAdapter.Type };
m.SetControllersAsMnemonic(
Global.MovieSession.Movie.GetInput(frame)
);
Global.MovieSession.Movie.GetInput(frame));
foreach (var button in m.Type.BoolButtons)
{
@ -89,18 +88,18 @@ namespace BizHawk.Client.Common
{
return "FINISHED";
}
else if (Global.MovieSession.Movie.IsPlaying)
if (Global.MovieSession.Movie.IsPlaying)
{
return "PLAY";
}
else if (Global.MovieSession.Movie.IsRecording)
if (Global.MovieSession.Movie.IsRecording)
{
return "RECORD";
}
else
{
return "INACTIVE";
}
return "INACTIVE";
}
[LuaMethodAttributes(

View File

@ -3,7 +3,7 @@ using BizHawk.Emulation.Cores.Nintendo.NES;
namespace BizHawk.Client.Common
{
public class NESLuaLibrary : LuaLibraryBase
public class NesLuaLibrary : LuaLibraryBase
{
// TODO:
// perhaps with the new core config system, one could
@ -26,13 +26,12 @@ namespace BizHawk.Client.Common
Watch.WatchSize.Byte,
Watch.DisplayType.Hex,
code,
false
);
false);
Global.CheatList.Add(new Cheat(
watch,
decoder.Value,
decoder.Compare
));
decoder.Compare));
}
}
@ -55,10 +54,8 @@ namespace BizHawk.Client.Common
{
return ((NES.NESSettings)Global.Emulator.GetSettings()).PAL_BottomLine;
}
else
{
return ((NES.NESSettings)Global.Emulator.GetSettings()).NTSC_BottomLine;
}
return ((NES.NESSettings)Global.Emulator.GetSettings()).NTSC_BottomLine;
}
[LuaMethodAttributes(
@ -98,10 +95,8 @@ namespace BizHawk.Client.Common
{
return ((NES.NESSettings)Global.Emulator.GetSettings()).PAL_TopLine;
}
else
{
return ((NES.NESSettings)Global.Emulator.GetSettings()).NTSC_TopLine;
}
return ((NES.NESSettings)Global.Emulator.GetSettings()).NTSC_TopLine;
}
[LuaMethodAttributes(
@ -114,8 +109,7 @@ namespace BizHawk.Client.Common
{
var decoder = new NESGameGenieDecoder(code);
Global.CheatList.RemoveRange(
Global.CheatList.Where(x => x.Address == decoder.Address)
);
Global.CheatList.Where(x => x.Address == decoder.Address));
}
}

View File

@ -2,7 +2,7 @@
namespace BizHawk.Client.Common
{
public class SNESLuaLibrary : LuaLibraryBase
public class SnesLuaLibrary : LuaLibraryBase
{
public override string Name { get { return "snes"; } }

View File

@ -11,7 +11,7 @@ namespace BizHawk.Client.Common
)]
public static string Hex(long num)
{
var hex = String.Format("{0:X}", num);
var hex = string.Format("{0:X}", num);
if (hex.Length == 1)
{
hex = "0" + hex;

View File

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
@ -13,18 +12,17 @@ namespace BizHawk.Client.Common
public class LuaDocumentation : ILuaDocumentation
{
public List<LibraryFunction> FunctionList { get; set; }
public LuaDocumentation()
{
FunctionList = new List<LibraryFunction>();
}
public List<LibraryFunction> FunctionList { get; set; }
public void Add(string methodLib, string methodName, MethodInfo method, string description)
{
FunctionList.Add(
new LibraryFunction(methodLib, methodName, method, description)
);
new LibraryFunction(methodLib, methodName, method, description));
}
public void Clear()
@ -51,6 +49,8 @@ namespace BizHawk.Client.Common
public class LibraryFunction
{
private readonly string _returnType = string.Empty;
public LibraryFunction(string methodLib, string methodName, MethodInfo method, string description)
{
Library = methodLib;
@ -71,7 +71,6 @@ namespace BizHawk.Client.Common
public string Library { get; set; }
public string Name { get; set; }
public List<string> Parameters { get; set; }
private readonly string _returnType = string.Empty;
public string Description { get; set; }

View File

@ -5,18 +5,9 @@ namespace BizHawk.Client.Common
{
public class LuaFile
{
public string Name { get; set; }
public string Path { get; set; }
public bool Enabled { get; set; }
public bool Paused { get; set; }
public bool IsSeparator { get; set; }
public LuaInterface.Lua Thread { get; set; }
public bool FrameWaiting { get; set; }
public string CurrentDirectory { get; set; }
public LuaFile(string path)
{
Name = String.Empty;
Name = string.Empty;
Path = path;
Enabled = true;
Paused = false;
@ -30,18 +21,18 @@ namespace BizHawk.Client.Common
IsSeparator = false;
// the current directory for the lua task will start off wherever the lua file is located
var directory_info = new FileInfo(path).Directory;
if (directory_info != null)
var directoryInfo = new FileInfo(path).Directory;
if (directoryInfo != null)
{
CurrentDirectory = directory_info.FullName;
CurrentDirectory = directoryInfo.FullName;
}
}
public LuaFile(bool isSeparator)
{
IsSeparator = isSeparator;
Name = String.Empty;
Path = String.Empty;
Name = string.Empty;
Path = string.Empty;
Enabled = false;
}
@ -55,6 +46,15 @@ namespace BizHawk.Client.Common
CurrentDirectory = file.CurrentDirectory;
}
public string Name { get; set; }
public string Path { get; set; }
public bool Enabled { get; set; }
public bool Paused { get; set; }
public bool IsSeparator { get; set; }
public LuaInterface.Lua Thread { get; set; }
public bool FrameWaiting { get; set; }
public string CurrentDirectory { get; set; }
public static LuaFile SeparatorInstance
{
get { return new LuaFile(true); }

View File

@ -7,19 +7,12 @@ namespace BizHawk.Client.Common
{
public class LuaFileList : List<LuaFile>
{
public LuaFileList() { }
private string _filename = String.Empty;
private string _filename = string.Empty;
private bool _changes;
public Action ChangedCallback { get; set; }
public Action LoadCallback { get; set; }
public void StopAllScripts()
{
ForEach(x => x.Enabled = false);
}
public bool Changes
{
get
@ -46,14 +39,19 @@ namespace BizHawk.Client.Common
set
{
_filename = value ?? String.Empty;
_filename = value ?? string.Empty;
}
}
public void StopAllScripts()
{
ForEach(x => x.Enabled = false);
}
public new void Clear()
{
StopAllScripts();
_filename = String.Empty;
_filename = string.Empty;
Changes = false;
base.Clear();
}
@ -118,15 +116,13 @@ namespace BizHawk.Client.Common
return true;
}
else
{
return false;
}
return false;
}
public void SaveSession()
{
if (!String.IsNullOrWhiteSpace(_filename))
if (!string.IsNullOrWhiteSpace(_filename))
{
SaveSession(_filename);
}

View File

@ -59,9 +59,9 @@ namespace BizHawk.Client.Common
}
}
var lua_result = new object[n - trim];
Array.Copy(luaArgs, lua_result, n - trim);
return lua_result;
var luaResult = new object[n - trim];
Array.Copy(luaArgs, luaResult, n - trim);
return luaResult;
}
}
}

View File

@ -30,19 +30,13 @@ namespace BizHawk.Client.Common
"error running function attached by the event " +
_event +
"\nError message: " +
ex.Message
);
ex.Message);
}
};
}
public Guid Guid { get; private set; }
public void Call(string name = null)
{
_function.Call(name);
}
public string Name
{
get { return _name; }
@ -59,5 +53,10 @@ namespace BizHawk.Client.Common
{
get { return _action; }
}
public void Call(string name = null)
{
_function.Call(name);
}
}
}

View File

@ -5,7 +5,10 @@ namespace BizHawk.Client.Common
{
public class Cheat
{
#region Constructors
private readonly Watch _watch;
private int? _compare;
private int _val;
private bool _enabled;
public Cheat(Watch watch, int value, int? compare = null, bool enabled = true)
{
@ -43,33 +46,13 @@ 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); }
}
#endregion
#region private parts
private readonly Watch _watch;
private int? _compare;
private int _val;
private bool _enabled;
private void Changes()
{
if (Changed != null)
{
Changed(this);
}
}
#endregion
#region Properties
public bool IsSeparator
{
get { return _watch.IsSeparator; }
@ -127,7 +110,7 @@ namespace BizHawk.Client.Common
public string Name
{
get { return IsSeparator ? String.Empty : _watch.Notes; }
get { return IsSeparator ? string.Empty : _watch.Notes; }
}
public string AddressStr
@ -143,7 +126,7 @@ namespace BizHawk.Client.Common
{
default:
case Watch.WatchSize.Separator:
return String.Empty;
return string.Empty;
case Watch.WatchSize.Byte:
return (_watch as ByteWatch).FormatValue((byte)_val);
case Watch.WatchSize.Word:
@ -164,7 +147,7 @@ namespace BizHawk.Client.Common
{
default:
case Watch.WatchSize.Separator:
return String.Empty;
return string.Empty;
case Watch.WatchSize.Byte:
return (_watch as ByteWatch).FormatValue((byte)_compare.Value);
case Watch.WatchSize.Word:
@ -173,19 +156,11 @@ namespace BizHawk.Client.Common
return (_watch as DWordWatch).FormatValue((uint)_compare.Value);
}
}
else
{
return String.Empty;
}
return string.Empty;
}
}
public event CheatEventHandler Changed;
#endregion
#region Actions
public void Enable()
{
if (!IsSeparator)
@ -285,6 +260,13 @@ namespace BizHawk.Client.Common
}
}
#endregion
private void Changes()
{
if (Changed != null)
{
Changed(this);
}
}
}
}

View File

@ -11,7 +11,29 @@ namespace BizHawk.Client.Common
{
public class CheatCollection : ICollection<Cheat>
{
private List<Cheat> _cheatList = new List<Cheat>();
private string _currentFileName = string.Empty;
private string _defaultFileName = string.Empty;
private bool _changes;
public delegate void CheatListEventHandler(object sender, CheatListEventArgs e);
public event CheatListEventHandler Changed;
public int Count
{
get { return _cheatList.Count; }
}
public int CheatCount
{
get { return _cheatList.Count(x => !x.IsSeparator); }
}
public int ActiveCount
{
get { return _cheatList.Count(x => x.Enabled); }
}
public bool Changes
{
get
@ -29,19 +51,12 @@ namespace BizHawk.Client.Common
}
}
private List<Cheat> _cheatList = new List<Cheat>();
private string _currentFileName = String.Empty;
private string _defaultFileName = String.Empty;
public IEnumerator<Cheat> GetEnumerator()
public string CurrentFileName
{
return _cheatList.GetEnumerator();
get { return _currentFileName; }
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public bool IsReadOnly { get { return false; } }
public Cheat this[int index]
{
@ -56,6 +71,16 @@ namespace BizHawk.Client.Common
}
}
public IEnumerator<Cheat> GetEnumerator()
{
return _cheatList.GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public void Pulse()
{
_cheatList.ForEach(cheat => cheat.Pulse());
@ -64,7 +89,6 @@ namespace BizHawk.Client.Common
/// <summary>
/// Looks for a .cht file that matches the ROM loaded based on the default filename for a given ROM
/// </summary>
/// <returns></returns>
public bool AttemptToLoadCheatFile()
{
var file = new FileInfo(_defaultFileName);
@ -73,32 +97,15 @@ namespace BizHawk.Client.Common
{
return Load(file.FullName, false);
}
else
{
return false;
}
}
public int Count
{
get { return _cheatList.Count; }
}
public int CheatCount
{
get { return _cheatList.Count(x => !x.IsSeparator); }
}
public int ActiveCount
{
get { return _cheatList.Count(x => x.Enabled); }
return false;
}
public void NewList(string defaultFileName)
{
_defaultFileName = defaultFileName;
_cheatList.Clear();
_currentFileName = String.Empty;
_currentFileName = string.Empty;
Changes = false;
}
@ -145,10 +152,8 @@ namespace BizHawk.Client.Common
Changes = true;
return true;
}
else
{
return false;
}
return false;
}
public bool Remove(Watch w)
@ -160,10 +165,8 @@ namespace BizHawk.Client.Common
Changes = true;
return true;
}
else
{
return false;
}
return false;
}
public bool Contains(Cheat cheat)
@ -176,8 +179,6 @@ namespace BizHawk.Client.Common
_cheatList.CopyTo(array, arrayIndex);
}
public bool IsReadOnly { get { return false; } }
public void RemoveRange(IEnumerable<Cheat> cheats)
{
foreach (var cheat in cheats)
@ -206,19 +207,11 @@ namespace BizHawk.Client.Common
public bool IsActive(MemoryDomain domain, int address)
{
foreach (var cheat in _cheatList)
{
if (cheat.IsSeparator)
{
continue;
}
else if (cheat.Domain == domain && cheat.Contains(address) && cheat.Enabled)
{
return true;
}
}
return false;
return _cheatList.Any(cheat =>
!cheat.IsSeparator &&
cheat.Enabled &&
cheat.Domain == domain
&& cheat.Contains(address));
}
public void SaveOnClose()
@ -227,14 +220,14 @@ namespace BizHawk.Client.Common
{
if (Changes && _cheatList.Any())
{
if (String.IsNullOrWhiteSpace(_currentFileName))
if (string.IsNullOrWhiteSpace(_currentFileName))
{
_currentFileName = _defaultFileName;
}
SaveFile(_currentFileName);
}
else if (!_cheatList.Any() && !String.IsNullOrWhiteSpace(_currentFileName))
else if (!_cheatList.Any() && !string.IsNullOrWhiteSpace(_currentFileName))
{
new FileInfo(_currentFileName).Delete();
}
@ -243,7 +236,7 @@ namespace BizHawk.Client.Common
public bool Save()
{
if (String.IsNullOrWhiteSpace(_currentFileName))
if (string.IsNullOrWhiteSpace(_currentFileName))
{
_currentFileName = _defaultFileName;
}
@ -346,8 +339,8 @@ namespace BizHawk.Client.Common
}
var vals = s.Split('\t');
var address = Int32.Parse(vals[0], NumberStyles.HexNumber);
var value = Int32.Parse(vals[1], NumberStyles.HexNumber);
var address = int.Parse(vals[0], NumberStyles.HexNumber);
var value = int.Parse(vals[1], NumberStyles.HexNumber);
if (vals[2] == "N")
{
@ -355,7 +348,7 @@ namespace BizHawk.Client.Common
}
else
{
compare = Int32.Parse(vals[2], NumberStyles.HexNumber);
compare = int.Parse(vals[2], NumberStyles.HexNumber);
}
var domain = Global.Emulator.MemoryDomains[vals[3]];
@ -376,8 +369,7 @@ namespace BizHawk.Client.Common
size,
type,
name,
bigendian
);
bigendian);
Add(new Cheat(watch, value, compare, !Global.Config.DisableCheatsOnLoad && enabled));
}
@ -393,11 +385,6 @@ namespace BizHawk.Client.Common
return true;
}
public string CurrentFileName
{
get { return _currentFileName; }
}
public void Sort(string column, bool reverse)
{
switch (column)
@ -572,21 +559,6 @@ namespace BizHawk.Client.Common
}
}
public class CheatListEventArgs : EventArgs
{
public CheatListEventArgs(Cheat c)
{
Cheat = c;
}
public Cheat Cheat { get; private set; }
}
public delegate void CheatListEventHandler(object sender, CheatListEventArgs e);
public event CheatListEventHandler Changed;
#region Privates
private void CheatChanged(object sender)
{
if (Changed != null)
@ -597,7 +569,15 @@ namespace BizHawk.Client.Common
_changes = true;
}
#endregion
public class CheatListEventArgs : EventArgs
{
public CheatListEventArgs(Cheat c)
{
Cheat = c;
}
public Cheat Cheat { get; private set; }
}
public const string NAME = "NamesColumn";
public const string ADDRESS = "AddressColumn";

View File

@ -44,7 +44,7 @@ namespace BizHawk.Client.Common
protected DisplayType _type;
protected bool _bigEndian;
protected int _changecount;
protected string _notes = String.Empty;
protected string _notes = string.Empty;
public abstract int? Value { get; }
public abstract string ValueString { get; }
@ -163,10 +163,8 @@ namespace BizHawk.Client.Common
{
return "X" + IntHelpers.GetNumDigits(this._domain.Size - 1);
}
else
{
return String.Empty;
}
return string.Empty;
}
}
@ -283,17 +281,17 @@ namespace BizHawk.Client.Common
public override string AddressString
{
get { return String.Empty; }
get { return string.Empty; }
}
public override string ValueString
{
get { return String.Empty; }
get { return string.Empty; }
}
public override string PreviousStr
{
get { return String.Empty; }
get { return string.Empty; }
}
public override string ToString()
@ -331,7 +329,7 @@ namespace BizHawk.Client.Common
return;
}
public override string Diff { get { return String.Empty; } }
public override string Diff { get { return string.Empty; } }
public override void Update() { return; }
}
@ -503,7 +501,7 @@ namespace BizHawk.Client.Common
{
get
{
var diff = String.Empty;
var diff = string.Empty;
var diffVal = _value - _previous;
if (diffVal > 0)
{
@ -636,7 +634,7 @@ namespace BizHawk.Client.Common
case DisplayType.Hex:
return val.ToHexString(4);
case DisplayType.FixedPoint_12_4:
return String.Format("{0:F4}", val / 16.0);
return string.Format("{0:F4}", val / 16.0);
case DisplayType.Binary:
return Convert.ToString(val, 2).PadLeft(16, '0').Insert(8, " ").Insert(4, " ").Insert(14, " ");
}
@ -841,11 +839,11 @@ 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 string.Format("{0:0.######}", val / 4096.0);
case DisplayType.Float:
var bytes = BitConverter.GetBytes(val);
var _float = BitConverter.ToSingle(bytes, 0);
return String.Format("{0:0.######}", _float);
return string.Format("{0:0.######}", _float);
}
}

View File

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
@ -11,6 +10,10 @@ namespace BizHawk.Client.Common
{
public class WatchList : IList<Watch>
{
private List<Watch> _watchList = new List<Watch>();
private MemoryDomain _domain;
private string _currentFilename = string.Empty;
public const string ADDRESS = "AddressColumn";
public const string VALUE = "ValueColumn";
public const string PREV = "PrevColumn";
@ -19,25 +22,24 @@ namespace BizHawk.Client.Common
public const string DOMAIN = "DomainColumn";
public const string NOTES = "NotesColumn";
public enum WatchPrevDef { LastSearch, Original, LastFrame, LastChange }
private List<Watch> _watchList = new List<Watch>();
private MemoryDomain _domain;
private string _currentFilename = String.Empty;
public WatchList(MemoryDomain domain)
{
_domain = domain;
}
public enum WatchPrevDef { LastSearch, Original, LastFrame, LastChange }
public IEnumerator<Watch> GetEnumerator()
public string AddressFormatStr // TODO: this is probably compensating for not using the ToHex string extension
{
return _watchList.GetEnumerator();
}
get
{
if (_domain != null)
{
return "{0:X" + IntHelpers.GetNumDigits(this._domain.Size - 1) + "}";
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
return string.Empty;
}
}
public int Count
@ -45,12 +47,6 @@ namespace BizHawk.Client.Common
get { return _watchList.Count; }
}
public Watch this[int index]
{
get { return _watchList[index]; }
set { _watchList[index] = value; }
}
public int WatchCount
{
get { return _watchList.Count(w => !w.IsSeparator); }
@ -61,6 +57,38 @@ namespace BizHawk.Client.Common
get { return _watchList.Count; }
}
public MemoryDomain Domain
{
get { return _domain; }
set { _domain = value; }
}
public bool IsReadOnly { get { return false; } }
public string CurrentFileName
{
get { return _currentFilename; }
set { _currentFilename = value; }
}
public bool Changes { get; set; }
public Watch this[int index]
{
get { return _watchList[index]; }
set { _watchList[index] = value; }
}
public IEnumerator<Watch> GetEnumerator()
{
return _watchList.GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public void OrderWatches(string column, bool reverse)
{
switch (column)
@ -221,30 +249,13 @@ namespace BizHawk.Client.Common
}
}
public string AddressFormatStr
{
get
{
if (_domain != null)
{
return "{0:X" + IntHelpers.GetNumDigits(this._domain.Size - 1) + "}";
}
else
{
return String.Empty;
}
}
}
public void Clear()
{
_watchList.Clear();
Changes = false;
_currentFilename = String.Empty;
_currentFilename = string.Empty;
}
public MemoryDomain Domain { get { return _domain; } set { _domain = value; } }
public void UpdateValues()
{
foreach (var watch in _watchList)
@ -289,8 +300,6 @@ namespace BizHawk.Client.Common
}
}
public bool IsReadOnly { get { return false; } }
public bool Contains(Watch watch)
{
return _watchList.Any(w =>
@ -298,8 +307,7 @@ namespace BizHawk.Client.Common
w.Type == watch.Type &&
w.Domain == watch.Domain &&
w.Address == watch.Address &&
w.BigEndian == watch.BigEndian
);
w.BigEndian == watch.BigEndian);
}
public void CopyTo(Watch[] array, int arrayIndex)
@ -320,9 +328,6 @@ namespace BizHawk.Client.Common
#region File handling logic - probably needs to be its own class
public string CurrentFileName { get { return _currentFilename; } set { _currentFilename = value; } }
public bool Changes { get; set; }
public bool Load(string path, bool append)
{
var result = LoadFile(path, append);
@ -345,7 +350,7 @@ namespace BizHawk.Client.Common
public void Reload()
{
if (!String.IsNullOrWhiteSpace(CurrentFileName))
if (!string.IsNullOrWhiteSpace(CurrentFileName))
{
LoadFile(CurrentFileName, append: false);
Changes = false;
@ -354,7 +359,7 @@ namespace BizHawk.Client.Common
public bool Save()
{
if (String.IsNullOrWhiteSpace(CurrentFileName))
if (string.IsNullOrWhiteSpace(CurrentFileName))
{
return false;
}
@ -369,7 +374,7 @@ namespace BizHawk.Client.Common
foreach (var watch in _watchList)
{
sb
.Append(String.Format(AddressFormatStr, watch.Address ?? 0)).Append('\t')
.Append(string.Format(AddressFormatStr, watch.Address ?? 0)).Append('\t')
.Append(watch.SizeAsChar).Append('\t')
.Append(watch.TypeAsChar).Append('\t')
.Append(watch.BigEndian ? '1' : '0').Append('\t')
@ -393,15 +398,13 @@ namespace BizHawk.Client.Common
CurrentFileName = file.FullName;
return Save();
}
else
{
return false;
}
return false;
}
private bool LoadFile(string path, bool append)
{
var domain = String.Empty;
var domain = string.Empty;
var file = new FileInfo(path);
if (file.Exists == false)
{
@ -457,9 +460,9 @@ namespace BizHawk.Client.Common
}
else if (numColumns == 4)
{
isOldBizHawkWatch = true;
isOldBizHawkWatch = true; // This supports the legacy .wch format from 1.0.5 and earlier
}
else // 4 is 1.0.5 and earlier
else
{
continue; // If not 4, something is wrong with this line, ignore it
}
@ -471,7 +474,7 @@ namespace BizHawk.Client.Common
var temp = line.Substring(0, line.IndexOf('\t'));
try
{
addr = Int32.Parse(temp, NumberStyles.HexNumber);
addr = int.Parse(temp, NumberStyles.HexNumber);
}
catch
{
@ -490,7 +493,7 @@ namespace BizHawk.Client.Common
line = line.Substring(startIndex, line.Length - startIndex); // Endian
try
{
startIndex = Int16.Parse(line[0].ToString());
startIndex = short.Parse(line[0].ToString());
}
catch
{

View File

@ -98,9 +98,9 @@ namespace BizHawk.Client.EmuHawk
new MemoryLuaLibrary().LuaRegister(lua, Docs);
new MainMemoryLuaLibrary(_lua).LuaRegister(lua, Docs);
new MovieLuaLibrary(_lua).LuaRegister(lua, Docs);
new NESLuaLibrary().LuaRegister(lua, Docs);
new NesLuaLibrary().LuaRegister(lua, Docs);
new SavestateLuaLibrary().LuaRegister(lua, Docs);
new SNESLuaLibrary().LuaRegister(lua, Docs);
new SnesLuaLibrary().LuaRegister(lua, Docs);
new StringLuaLibrary().LuaRegister(lua, Docs);
Docs.Sort();