some code cleanup
This commit is contained in:
parent
a907d3ce7b
commit
02ea7d360f
|
@ -1,23 +1,12 @@
|
||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace BizHawk.Client.Common
|
namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
public class NESGameGenieDecoder
|
public class NESGameGenieDecoder
|
||||||
{
|
{
|
||||||
public int Address { get; private set; }
|
private readonly string _code = string.Empty;
|
||||||
public int Value { get; private set; }
|
|
||||||
public int? Compare { get; private set; }
|
|
||||||
|
|
||||||
private readonly string _code = String.Empty;
|
private readonly Dictionary<char, int> _gameGenieTable = new Dictionary<char, int>
|
||||||
|
|
||||||
public NESGameGenieDecoder(string code)
|
|
||||||
{
|
|
||||||
_code = code;
|
|
||||||
Decode();
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly Dictionary<char, int> GameGenieTable = new Dictionary<char, int>
|
|
||||||
{
|
{
|
||||||
{ 'A', 0 }, // 0000
|
{ 'A', 0 }, // 0000
|
||||||
{ 'P', 1 }, // 0001
|
{ 'P', 1 }, // 0001
|
||||||
|
@ -37,6 +26,16 @@ namespace BizHawk.Client.Common
|
||||||
{ 'N', 15 }, // 1111
|
{ 'N', 15 }, // 1111
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public NESGameGenieDecoder(string code)
|
||||||
|
{
|
||||||
|
_code = code;
|
||||||
|
Decode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Address { get; private set; }
|
||||||
|
public int Value { get; private set; }
|
||||||
|
public int? Compare { get; private set; }
|
||||||
|
|
||||||
public void Decode()
|
public void Decode()
|
||||||
{
|
{
|
||||||
// char 3 bit 3 denotes the code length.
|
// char 3 bit 3 denotes the code length.
|
||||||
|
@ -49,28 +48,28 @@ namespace BizHawk.Client.Common
|
||||||
Address = 0x8000;
|
Address = 0x8000;
|
||||||
int x;
|
int x;
|
||||||
|
|
||||||
GameGenieTable.TryGetValue(_code[0], out x);
|
_gameGenieTable.TryGetValue(_code[0], out x);
|
||||||
Value |= (x & 0x07);
|
Value |= x & 0x07;
|
||||||
Value |= (x & 0x08) << 4;
|
Value |= (x & 0x08) << 4;
|
||||||
|
|
||||||
GameGenieTable.TryGetValue(_code[1], out x);
|
_gameGenieTable.TryGetValue(_code[1], out x);
|
||||||
Value |= (x & 0x07) << 4;
|
Value |= (x & 0x07) << 4;
|
||||||
Address |= (x & 0x08) << 4;
|
Address |= (x & 0x08) << 4;
|
||||||
|
|
||||||
GameGenieTable.TryGetValue(_code[2], out x);
|
_gameGenieTable.TryGetValue(_code[2], out x);
|
||||||
Address |= (x & 0x07) << 4;
|
Address |= (x & 0x07) << 4;
|
||||||
|
|
||||||
GameGenieTable.TryGetValue(_code[3], out x);
|
_gameGenieTable.TryGetValue(_code[3], out x);
|
||||||
Address |= (x & 0x07) << 12;
|
Address |= (x & 0x07) << 12;
|
||||||
Address |= (x & 0x08);
|
Address |= x & 0x08;
|
||||||
|
|
||||||
GameGenieTable.TryGetValue(_code[4], out x);
|
_gameGenieTable.TryGetValue(_code[4], out x);
|
||||||
Address |= (x & 0x07);
|
Address |= x & 0x07;
|
||||||
Address |= (x & 0x08) << 8;
|
Address |= (x & 0x08) << 8;
|
||||||
|
|
||||||
GameGenieTable.TryGetValue(_code[5], out x);
|
_gameGenieTable.TryGetValue(_code[5], out x);
|
||||||
Address |= (x & 0x07) << 8;
|
Address |= (x & 0x07) << 8;
|
||||||
Value |= (x & 0x08);
|
Value |= x & 0x08;
|
||||||
}
|
}
|
||||||
else if (_code.Length == 8)
|
else if (_code.Length == 8)
|
||||||
{
|
{
|
||||||
|
@ -82,50 +81,48 @@ namespace BizHawk.Client.Common
|
||||||
Compare = 0;
|
Compare = 0;
|
||||||
int x;
|
int x;
|
||||||
|
|
||||||
GameGenieTable.TryGetValue(_code[0], out x);
|
_gameGenieTable.TryGetValue(_code[0], out x);
|
||||||
Value |= (x & 0x07);
|
Value |= x & 0x07;
|
||||||
Value |= (x & 0x08) << 4;
|
Value |= (x & 0x08) << 4;
|
||||||
|
|
||||||
GameGenieTable.TryGetValue(_code[1], out x);
|
_gameGenieTable.TryGetValue(_code[1], out x);
|
||||||
Value |= (x & 0x07) << 4;
|
Value |= (x & 0x07) << 4;
|
||||||
Address |= (x & 0x08) << 4;
|
Address |= (x & 0x08) << 4;
|
||||||
|
|
||||||
GameGenieTable.TryGetValue(_code[2], out x);
|
_gameGenieTable.TryGetValue(_code[2], out x);
|
||||||
Address |= (x & 0x07) << 4;
|
Address |= (x & 0x07) << 4;
|
||||||
|
|
||||||
GameGenieTable.TryGetValue(_code[3], out x);
|
_gameGenieTable.TryGetValue(_code[3], out x);
|
||||||
Address |= (x & 0x07) << 12;
|
Address |= (x & 0x07) << 12;
|
||||||
Address |= (x & 0x08);
|
Address |= x & 0x08;
|
||||||
|
|
||||||
GameGenieTable.TryGetValue(_code[4], out x);
|
_gameGenieTable.TryGetValue(_code[4], out x);
|
||||||
Address |= (x & 0x07);
|
Address |= x & 0x07;
|
||||||
Address |= (x & 0x08) << 8;
|
Address |= (x & 0x08) << 8;
|
||||||
|
|
||||||
GameGenieTable.TryGetValue(_code[5], out x);
|
_gameGenieTable.TryGetValue(_code[5], out x);
|
||||||
Address |= (x & 0x07) << 8;
|
Address |= (x & 0x07) << 8;
|
||||||
Compare |= (x & 0x08);
|
Compare |= x & 0x08;
|
||||||
|
|
||||||
GameGenieTable.TryGetValue(_code[6], out x);
|
_gameGenieTable.TryGetValue(_code[6], out x);
|
||||||
Compare |= (x & 0x07);
|
Compare |= x & 0x07;
|
||||||
Compare |= (x & 0x08) << 4;
|
Compare |= (x & 0x08) << 4;
|
||||||
|
|
||||||
GameGenieTable.TryGetValue(_code[7], out x);
|
_gameGenieTable.TryGetValue(_code[7], out x);
|
||||||
Compare |= (x & 0x07) << 4;
|
Compare |= (x & 0x07) << 4;
|
||||||
Value |= (x & 0x08);
|
Value |= x & 0x08;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class NESGameGenieEncoder
|
public class NESGameGenieEncoder
|
||||||
{
|
{
|
||||||
private readonly char[] letters = { 'A', 'P', 'Z', 'L', 'G', 'I', 'T', 'Y', 'E', 'O', 'X', 'U', 'K', 'S', 'V', 'N' };
|
private readonly char[] _letters = { 'A', 'P', 'Z', 'L', 'G', 'I', 'T', 'Y', 'E', 'O', 'X', 'U', 'K', 'S', 'V', 'N' };
|
||||||
|
|
||||||
private int _address;
|
private readonly int _address;
|
||||||
private int _value;
|
private readonly int _value;
|
||||||
private int? _compare;
|
private int? _compare;
|
||||||
|
|
||||||
public string GameGenieCode { get; private set; }
|
|
||||||
|
|
||||||
public NESGameGenieEncoder(int address, int value, int? compare)
|
public NESGameGenieEncoder(int address, int value, int? compare)
|
||||||
{
|
{
|
||||||
_address = address;
|
_address = address;
|
||||||
|
@ -133,21 +130,24 @@ namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
_address -= 0x8000;
|
_address -= 0x8000;
|
||||||
}
|
}
|
||||||
|
|
||||||
_value = value;
|
_value = value;
|
||||||
_compare = compare;
|
_compare = compare;
|
||||||
|
|
||||||
GameGenieCode = String.Empty;
|
GameGenieCode = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string GameGenieCode { get; private set; }
|
||||||
|
|
||||||
public string Encode()
|
public string Encode()
|
||||||
{
|
{
|
||||||
byte[] num = { 0, 0, 0, 0, 0, 0, 0, 0 };
|
byte[] num = { 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||||
num[0] = (byte)((_value & 7) + ((_value >> 4) & 8));
|
num[0] = (byte)((_value & 7) + ((_value >> 4) & 8));
|
||||||
num[1] = (byte)(((_value >> 4) & 7) + ((_address >> 4) & 8));
|
num[1] = (byte)(((_value >> 4) & 7) + ((_address >> 4) & 8));
|
||||||
num[2] = (byte)(((_address >> 4) & 7));
|
num[2] = (byte)((_address >> 4) & 7);
|
||||||
num[3] = (byte)((_address >> 12) + (_address & 8));
|
num[3] = (byte)((_address >> 12) + (_address & 8));
|
||||||
num[4] = (byte)((_address & 7) + ((_address >> 8) & 8));
|
num[4] = (byte)((_address & 7) + ((_address >> 8) & 8));
|
||||||
num[5] = (byte)(((_address >> 8) & 7));
|
num[5] = (byte)((_address >> 8) & 7);
|
||||||
|
|
||||||
if (_compare.HasValue)
|
if (_compare.HasValue)
|
||||||
{
|
{
|
||||||
|
@ -155,17 +155,17 @@ namespace BizHawk.Client.Common
|
||||||
num[5] += (byte)(_compare & 8);
|
num[5] += (byte)(_compare & 8);
|
||||||
num[6] = (byte)((_compare & 7) + ((_compare >> 4) & 8));
|
num[6] = (byte)((_compare & 7) + ((_compare >> 4) & 8));
|
||||||
num[7] = (byte)(((_compare >> 4) & 7) + (_value & 8));
|
num[7] = (byte)(((_compare >> 4) & 7) + (_value & 8));
|
||||||
for (int i = 0; i < 8; i++)
|
for (var i = 0; i < 8; i++)
|
||||||
{
|
{
|
||||||
GameGenieCode += letters[num[i]];
|
GameGenieCode += _letters[num[i]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
num[5] += (byte)(_value & 8);
|
num[5] += (byte)(_value & 8);
|
||||||
for (int i = 0; i < 6; i++)
|
for (var i = 0; i < 6; i++)
|
||||||
{
|
{
|
||||||
GameGenieCode += letters[num[i]];
|
GameGenieCode += _letters[num[i]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -115,7 +115,7 @@ namespace BizHawk.Client.Common
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (str.Trim() == String.Empty)
|
if (str.Trim() == string.Empty)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using BizHawk.Emulation.Common;
|
||||||
using BizHawk.Emulation.Common;
|
|
||||||
|
|
||||||
namespace BizHawk.Client.Common
|
namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
|
@ -196,11 +195,14 @@ namespace BizHawk.Client.Common
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string GetStringForPulse(int val)
|
private string GetStringForPulse(int val)
|
||||||
{
|
{
|
||||||
if (_watch.Type == Watch.DisplayType.Hex)
|
if (_watch.Type == Watch.DisplayType.Hex)
|
||||||
|
{
|
||||||
return val.ToString("X8");
|
return val.ToString("X8");
|
||||||
else return val.ToString();
|
}
|
||||||
|
|
||||||
|
return val.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Pulse()
|
public void Pulse()
|
||||||
|
@ -274,6 +276,5 @@ namespace BizHawk.Client.Common
|
||||||
Changed(this);
|
Changed(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -273,7 +273,7 @@ namespace BizHawk.Client.Common
|
||||||
.Append(cheat.AddressStr).Append('\t')
|
.Append(cheat.AddressStr).Append('\t')
|
||||||
.Append(cheat.ValueStr).Append('\t')
|
.Append(cheat.ValueStr).Append('\t')
|
||||||
.Append(cheat.Compare.HasValue ? cheat.Compare.Value.ToString() : "N").Append('\t')
|
.Append(cheat.Compare.HasValue ? cheat.Compare.Value.ToString() : "N").Append('\t')
|
||||||
.Append(cheat.Domain != null ? cheat.Domain.Name : String.Empty).Append('\t')
|
.Append(cheat.Domain != null ? cheat.Domain.Name : string.Empty).Append('\t')
|
||||||
.Append(cheat.Enabled ? '1' : '0').Append('\t')
|
.Append(cheat.Enabled ? '1' : '0').Append('\t')
|
||||||
.Append(cheat.Name).Append('\t')
|
.Append(cheat.Name).Append('\t')
|
||||||
.Append(cheat.SizeAsChar).Append('\t')
|
.Append(cheat.SizeAsChar).Append('\t')
|
||||||
|
|
|
@ -372,28 +372,30 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
else if (SpecificValueRadio.Checked)
|
|
||||||
|
if (SpecificValueRadio.Checked)
|
||||||
{
|
{
|
||||||
return SpecificValueBox.ToRawInt();
|
return SpecificValueBox.ToRawInt();
|
||||||
}
|
}
|
||||||
else if (SpecificAddressRadio.Checked)
|
|
||||||
|
if (SpecificAddressRadio.Checked)
|
||||||
{
|
{
|
||||||
return SpecificAddressBox.ToRawInt();
|
return SpecificAddressBox.ToRawInt();
|
||||||
}
|
}
|
||||||
else if (NumberOfChangesRadio.Checked)
|
|
||||||
|
if (NumberOfChangesRadio.Checked)
|
||||||
{
|
{
|
||||||
return NumberOfChangesBox.ToRawInt();
|
return NumberOfChangesBox.ToRawInt();
|
||||||
}
|
}
|
||||||
else if (DifferenceRadio.Checked)
|
|
||||||
|
if (DifferenceRadio.Checked)
|
||||||
{
|
{
|
||||||
return DifferenceBox.ToRawInt();
|
return DifferenceBox.ToRawInt();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private int? DifferentByValue
|
private int? DifferentByValue
|
||||||
{
|
{
|
||||||
|
@ -407,13 +409,37 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (NotEqualToRadio.Checked) return RamSearchEngine.ComparisonOperator.NotEqual;
|
if (NotEqualToRadio.Checked)
|
||||||
else if (LessThanRadio.Checked) return RamSearchEngine.ComparisonOperator.LessThan;
|
{
|
||||||
else if (GreaterThanRadio.Checked) return RamSearchEngine.ComparisonOperator.GreaterThan;
|
return RamSearchEngine.ComparisonOperator.NotEqual;
|
||||||
else if (LessThanOrEqualToRadio.Checked) return RamSearchEngine.ComparisonOperator.LessThanEqual;
|
}
|
||||||
else if (GreaterThanOrEqualToRadio.Checked) return RamSearchEngine.ComparisonOperator.GreaterThanEqual;
|
|
||||||
else if (DifferentByRadio.Checked) return RamSearchEngine.ComparisonOperator.DifferentBy;
|
if (LessThanRadio.Checked)
|
||||||
else return RamSearchEngine.ComparisonOperator.Equal;
|
{
|
||||||
|
return RamSearchEngine.ComparisonOperator.LessThan;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GreaterThanRadio.Checked)
|
||||||
|
{
|
||||||
|
return RamSearchEngine.ComparisonOperator.GreaterThan;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (LessThanOrEqualToRadio.Checked)
|
||||||
|
{
|
||||||
|
return RamSearchEngine.ComparisonOperator.LessThanEqual;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GreaterThanOrEqualToRadio.Checked)
|
||||||
|
{
|
||||||
|
return RamSearchEngine.ComparisonOperator.GreaterThanEqual;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DifferentByRadio.Checked)
|
||||||
|
{
|
||||||
|
return RamSearchEngine.ComparisonOperator.DifferentBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
return RamSearchEngine.ComparisonOperator.Equal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,11 +447,27 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (SpecificValueRadio.Checked) return RamSearchEngine.Compare.SpecificValue;
|
if (SpecificValueRadio.Checked)
|
||||||
else if (SpecificAddressRadio.Checked) return RamSearchEngine.Compare.SpecificAddress;
|
{
|
||||||
else if (NumberOfChangesRadio.Checked) return RamSearchEngine.Compare.Changes;
|
return RamSearchEngine.Compare.SpecificValue;
|
||||||
else if (DifferenceRadio.Checked) return RamSearchEngine.Compare.Difference;
|
}
|
||||||
else return RamSearchEngine.Compare.Previous;
|
|
||||||
|
if (SpecificAddressRadio.Checked)
|
||||||
|
{
|
||||||
|
return RamSearchEngine.Compare.SpecificAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NumberOfChangesRadio.Checked)
|
||||||
|
{
|
||||||
|
return RamSearchEngine.Compare.Changes;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DifferenceRadio.Checked)
|
||||||
|
{
|
||||||
|
return RamSearchEngine.Compare.Difference;
|
||||||
|
}
|
||||||
|
|
||||||
|
return RamSearchEngine.Compare.Previous;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue