Use ToHexString() extension is more places

This commit is contained in:
adelikat 2013-11-07 18:15:17 +00:00
parent 085719bf44
commit 0adffa65c1
5 changed files with 45 additions and 35 deletions

View File

@ -2,6 +2,7 @@
using System.Globalization;
using System.Collections.Generic;
using BizHawk.Common;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common
@ -429,7 +430,7 @@ namespace BizHawk.Client.Common
case DisplayType.Signed:
return ((sbyte)val).ToString();
case DisplayType.Hex:
return String.Format("{0:X2}", val);
return val.ToHexString(2);
case DisplayType.Binary:
return Convert.ToString(val, 2).PadLeft(8, '0').Insert(4, " ");
}
@ -624,7 +625,7 @@ namespace BizHawk.Client.Common
case DisplayType.Signed:
return ((short)val).ToString();
case DisplayType.Hex:
return String.Format("{0:X4}", val);
return val.ToHexString(4);
case DisplayType.FixedPoint_12_4:
return String.Format("{0:F4}", (val / 16.0));
case DisplayType.Binary:
@ -820,7 +821,7 @@ namespace BizHawk.Client.Common
case DisplayType.Signed:
return ((int)val).ToString();
case DisplayType.Hex:
return String.Format("{0:X8}", val);
return val.ToHexString(8);
case DisplayType.FixedPoint_20_12:
return String.Format("{0:0.######}", (val / 4096.0));
case DisplayType.Float:

View File

@ -164,9 +164,7 @@ namespace BizHawk.Client.EmuHawk
{
addrStr.Append(" ");
}
addrStr.Append(String.Format("{0:X" + NumDigits + "}", addr));
addrStr.Append('\n');
addrStr.AppendLine(addr.ToHexString(NumDigits));
}
return addrStr.ToString();

View File

@ -35,12 +35,12 @@ namespace BizHawk.Client.EmuHawk
private RamSearchEngine Searches;
private RamSearchEngine.Settings Settings;
private int defaultWidth; //For saving the default size of the dialog, so the user can restore if desired
private int defaultHeight;
private string _sortedColumn = "";
private int _defaultWidth; //For saving the default size of the dialog, so the user can restore if desired
private int _defaultHeight;
private string _sortedColumn = String.Empty;
private bool _sortReverse = false;
private bool forcePreviewClear = false;
private bool autoSearch = false;
private bool _forcePreviewClear = false;
private bool _autoSearch = false;
private bool dropdown_dontfire = false; //Used as a hack to get around lame .net dropdowns, there's no way to set their index without firing the selectedindexchanged event!
@ -63,7 +63,7 @@ namespace BizHawk.Client.EmuHawk
WatchListView.VirtualMode = true;
Closing += (o, e) => SaveConfigSettings();
_sortedColumn = "";
_sortedColumn = String.Empty;
_sortReverse = false;
Settings = new RamSearchEngine.Settings();
@ -133,7 +133,7 @@ namespace BizHawk.Client.EmuHawk
Color nextColor = Color.White;
bool isCheat = Global.CheatList.IsActive(Settings.Domain, Searches[index].Address.Value);
bool isWeeded = Global.Config.RamSearchPreviewMode && !forcePreviewClear && Searches.Preview(Searches[index].Address.Value);
bool isWeeded = Global.Config.RamSearchPreviewMode && !_forcePreviewClear && Searches.Preview(Searches[index].Address.Value);
if (isCheat)
{
@ -194,8 +194,8 @@ namespace BizHawk.Client.EmuHawk
private void LoadConfigSettings()
{
//Size and Positioning
defaultWidth = Size.Width; //Save these first so that the user can restore to its original size
defaultHeight = Size.Height;
_defaultWidth = Size.Width; //Save these first so that the user can restore to its original size
_defaultHeight = Size.Height;
if (Global.Config.RamSearchSaveWindowPosition && Global.Config.RamSearchWndx >= 0 && Global.Config.RamSearchWndy >= 0)
{
@ -222,12 +222,12 @@ namespace BizHawk.Client.EmuHawk
{
Searches.Update();
if (autoSearch)
if (_autoSearch)
{
DoSearch();
}
forcePreviewClear = false;
_forcePreviewClear = false;
WatchListView.Refresh();
}
}
@ -450,7 +450,7 @@ namespace BizHawk.Client.EmuHawk
WatchListView.ItemCount = Searches.Count;
SetRemovedMessage(removed);
ToggleSearchDependentToolBarItems();
forcePreviewClear = true;
_forcePreviewClear = true;
}
private List<int> SelectedIndices
@ -892,11 +892,11 @@ namespace BizHawk.Client.EmuHawk
private void ToggleAutoSearch()
{
autoSearch ^= true;
AutoSearchCheckBox.Checked = autoSearch;
_autoSearch ^= true;
AutoSearchCheckBox.Checked = _autoSearch;
DoSearchToolButton.Enabled =
SearchButton.Enabled =
!autoSearch;
!_autoSearch;
}
private void GoToSpecifiedAddress()
@ -1169,7 +1169,7 @@ namespace BizHawk.Client.EmuHawk
SetTotal();
WatchListView.ItemCount = Searches.Count;
ToggleSearchDependentToolBarItems();
forcePreviewClear = true;
_forcePreviewClear = true;
UpdateUndoToolBarButtons();
}
}
@ -1182,7 +1182,7 @@ namespace BizHawk.Client.EmuHawk
SetTotal();
WatchListView.ItemCount = Searches.Count;
ToggleSearchDependentToolBarItems();
forcePreviewClear = true;
_forcePreviewClear = true;
UpdateUndoToolBarButtons();
}
}
@ -1261,7 +1261,7 @@ namespace BizHawk.Client.EmuHawk
UseUndoHistoryMenuItem.Checked = Searches.UndoEnabled;
PreviewModeMenuItem.Checked = Global.Config.RamSearchPreviewMode;
AlwaysOnTopMenuItem.Checked = Global.Config.RamSearchAlwaysOnTop;
AutoSearchMenuItem.Checked = autoSearch;
AutoSearchMenuItem.Checked = _autoSearch;
}
private void PreviewModeMenuItem_Click(object sender, EventArgs e)
@ -1306,7 +1306,7 @@ namespace BizHawk.Client.EmuHawk
private void RestoreDefaultsMenuItem_Click(object sender, EventArgs e)
{
Size = new Size(defaultWidth, defaultHeight);
Size = new Size(_defaultWidth, _defaultHeight);
Global.Config.RamSearchColumnIndexes = new Dictionary<string, int>
{
@ -1426,7 +1426,7 @@ namespace BizHawk.Client.EmuHawk
private void ClearPreviewContextMenuItem_Click(object sender, EventArgs e)
{
forcePreviewClear = true;
_forcePreviewClear = true;
WatchListView.Refresh();
}

View File

@ -2,6 +2,7 @@
using System.Globalization;
using System.Windows.Forms;
using BizHawk.Common;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
@ -35,8 +36,7 @@ namespace BizHawk.Client.EmuHawk
Text = "0";
break;
case Watch.DisplayType.Hex:
string formatstr = "{0:X" + MaxLength.ToString() + "}";
Text = String.Format(formatstr, 0);
Text = ((int)0).ToHexString(MaxLength);
break;
case Watch.DisplayType.FixedPoint_12_4:
case Watch.DisplayType.FixedPoint_20_12:
@ -279,8 +279,7 @@ namespace BizHawk.Client.EmuHawk
{
hexVal++;
}
string formatstr = "{0:X" + MaxLength.ToString() + "}";
Text = String.Format(formatstr, hexVal);
Text = hexVal.ToHexString(MaxLength);
break;
case Watch.DisplayType.FixedPoint_12_4:
double f12val = double.Parse(Text);
@ -372,8 +371,7 @@ namespace BizHawk.Client.EmuHawk
{
hexVal--;
}
string formatstr = "{0:X" + MaxLength.ToString() + "}";
Text = String.Format(formatstr, hexVal);
Text = hexVal.ToHexString(MaxLength);
break;
case Watch.DisplayType.FixedPoint_12_4:
double f12val = double.Parse(Text);
@ -529,9 +527,7 @@ namespace BizHawk.Client.EmuHawk
Text = Convert.ToString(bval, 2).PadLeft(numBits, '0');
break;
case Watch.DisplayType.Hex:
uint hexVal = (uint)val;
string formatstr = "{0:X" + MaxLength.ToString() + "}";
Text = String.Format(formatstr, hexVal);
Text = val.ToHexString(MaxLength);
break;
case Watch.DisplayType.FixedPoint_12_4:
Text = String.Format("{0:F5}", (val / 16.0));

View File

@ -68,6 +68,21 @@ namespace BizHawk.Common
return string.Format("{0:X" + numdigits + "}", n);
}
public static string ToHexString(this uint n, int numdigits)
{
return string.Format("{0:X" + numdigits + "}", n);
}
public static string ToHexString(this byte n, int numdigits)
{
return string.Format("{0:X" + numdigits + "}", n);
}
public static string ToHexString(this ushort n, int numdigits)
{
return string.Format("{0:X" + numdigits + "}", n);
}
//http://stackoverflow.com/questions/1766328/can-linq-use-binary-search-when-the-collection-is-ordered
public static T BinarySearch<T, TKey>(this IList<T> list, Func<T, TKey> keySelector, TKey key)
where TKey : IComparable<TKey>