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

View File

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

View File

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

View File

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

View File

@ -68,6 +68,21 @@ namespace BizHawk.Common
return string.Format("{0:X" + numdigits + "}", n); 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 //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) public static T BinarySearch<T, TKey>(this IList<T> list, Func<T, TKey> keySelector, TKey key)
where TKey : IComparable<TKey> where TKey : IComparable<TKey>