diff --git a/BizHawk.Client.Common/NESGameGenieEncoderDecoder.cs b/BizHawk.Client.Common/NESGameGenieEncoderDecoder.cs index 338396f4a2..2ea1c02854 100644 --- a/BizHawk.Client.Common/NESGameGenieEncoderDecoder.cs +++ b/BizHawk.Client.Common/NESGameGenieEncoderDecoder.cs @@ -1,15 +1,30 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; namespace BizHawk.Client.Common { public class NESGameGenieDecoder { - public int Address { get; private set; } - public int Value { get; private set; } - public int? Compare { get; private set; } + private readonly string _code = string.Empty; - private readonly string _code = String.Empty; + private readonly Dictionary _gameGenieTable = new Dictionary + { + { 'A', 0 }, // 0000 + { 'P', 1 }, // 0001 + { 'Z', 2 }, // 0010 + { 'L', 3 }, // 0011 + { 'G', 4 }, // 0100 + { 'I', 5 }, // 0101 + { 'T', 6 }, // 0110 + { 'Y', 7 }, // 0111 + { 'E', 8 }, // 1000 + { 'O', 9 }, // 1001 + { 'X', 10 }, // 1010 + { 'U', 11 }, // 1011 + { 'K', 12 }, // 1100 + { 'S', 13 }, // 1101 + { 'V', 14 }, // 1110 + { 'N', 15 }, // 1111 + }; public NESGameGenieDecoder(string code) { @@ -17,115 +32,97 @@ namespace BizHawk.Client.Common Decode(); } - private readonly Dictionary GameGenieTable = new Dictionary - { - { 'A', 0 }, //0000 - { 'P', 1 }, //0001 - { 'Z', 2 }, //0010 - { 'L', 3 }, //0011 - { 'G', 4 }, //0100 - { 'I', 5 }, //0101 - { 'T', 6 }, //0110 - { 'Y', 7 }, //0111 - { 'E', 8 }, //1000 - { 'O', 9 }, //1001 - { 'X', 10}, //1010 - { 'U', 11}, //1011 - { 'K', 12}, //1100 - { 'S', 13}, //1101 - { 'V', 14}, //1110 - { 'N', 15}, //1111 - }; + public int Address { get; private set; } + public int Value { get; private set; } + public int? Compare { get; private set; } public void Decode() { - //char 3 bit 3 denotes the code length. + // char 3 bit 3 denotes the code length. if (_code.Length == 6) { - //Char # | 1 | 2 | 3 | 4 | 5 | 6 | - //Bit # |3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0| - //maps to|1|6|7|8|H|2|3|4|-|I|J|K|L|A|B|C|D|M|N|O|5|E|F|G| + // Char # | 1 | 2 | 3 | 4 | 5 | 6 | + // Bit # |3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0| + // maps to|1|6|7|8|H|2|3|4|-|I|J|K|L|A|B|C|D|M|N|O|5|E|F|G| Value = 0; Address = 0x8000; int x; - GameGenieTable.TryGetValue(_code[0], out x); - Value |= (x & 0x07); + _gameGenieTable.TryGetValue(_code[0], out x); + Value |= x & 0x07; Value |= (x & 0x08) << 4; - GameGenieTable.TryGetValue(_code[1], out x); + _gameGenieTable.TryGetValue(_code[1], out x); Value |= (x & 0x07) << 4; Address |= (x & 0x08) << 4; - GameGenieTable.TryGetValue(_code[2], out x); + _gameGenieTable.TryGetValue(_code[2], out x); Address |= (x & 0x07) << 4; - GameGenieTable.TryGetValue(_code[3], out x); + _gameGenieTable.TryGetValue(_code[3], out x); Address |= (x & 0x07) << 12; - Address |= (x & 0x08); + Address |= x & 0x08; - GameGenieTable.TryGetValue(_code[4], out x); - Address |= (x & 0x07); + _gameGenieTable.TryGetValue(_code[4], out x); + Address |= x & 0x07; Address |= (x & 0x08) << 8; - GameGenieTable.TryGetValue(_code[5], out x); + _gameGenieTable.TryGetValue(_code[5], out x); Address |= (x & 0x07) << 8; - Value |= (x & 0x08); + Value |= x & 0x08; } else if (_code.Length == 8) { - //Char # | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | - //Bit # |3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0| - //maps to|1|6|7|8|H|2|3|4|-|I|J|K|L|A|B|C|D|M|N|O|%|E|F|G|!|^|&|*|5|@|#|$| + // Char # | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | + // Bit # |3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0| + // maps to|1|6|7|8|H|2|3|4|-|I|J|K|L|A|B|C|D|M|N|O|%|E|F|G|!|^|&|*|5|@|#|$| Value = 0; Address = 0x8000; Compare = 0; int x; - GameGenieTable.TryGetValue(_code[0], out x); - Value |= (x & 0x07); + _gameGenieTable.TryGetValue(_code[0], out x); + Value |= x & 0x07; Value |= (x & 0x08) << 4; - GameGenieTable.TryGetValue(_code[1], out x); + _gameGenieTable.TryGetValue(_code[1], out x); Value |= (x & 0x07) << 4; Address |= (x & 0x08) << 4; - GameGenieTable.TryGetValue(_code[2], out x); + _gameGenieTable.TryGetValue(_code[2], out x); Address |= (x & 0x07) << 4; - GameGenieTable.TryGetValue(_code[3], out x); + _gameGenieTable.TryGetValue(_code[3], out x); Address |= (x & 0x07) << 12; - Address |= (x & 0x08); + Address |= x & 0x08; - GameGenieTable.TryGetValue(_code[4], out x); - Address |= (x & 0x07); + _gameGenieTable.TryGetValue(_code[4], out x); + Address |= x & 0x07; Address |= (x & 0x08) << 8; - GameGenieTable.TryGetValue(_code[5], out x); + _gameGenieTable.TryGetValue(_code[5], out x); Address |= (x & 0x07) << 8; - Compare |= (x & 0x08); + Compare |= x & 0x08; - GameGenieTable.TryGetValue(_code[6], out x); - Compare |= (x & 0x07); + _gameGenieTable.TryGetValue(_code[6], out x); + Compare |= x & 0x07; Compare |= (x & 0x08) << 4; - GameGenieTable.TryGetValue(_code[7], out x); + _gameGenieTable.TryGetValue(_code[7], out x); Compare |= (x & 0x07) << 4; - Value |= (x & 0x08); + Value |= x & 0x08; } } } 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 int _value; + private readonly int _address; + private readonly int _value; private int? _compare; - public string GameGenieCode { get; private set; } - public NESGameGenieEncoder(int address, int value, int? compare) { _address = address; @@ -133,21 +130,24 @@ namespace BizHawk.Client.Common { _address -= 0x8000; } + _value = value; _compare = compare; - GameGenieCode = String.Empty; + GameGenieCode = string.Empty; } + public string GameGenieCode { get; private set; } + public string Encode() { byte[] num = { 0, 0, 0, 0, 0, 0, 0, 0 }; num[0] = (byte)((_value & 7) + ((_value >> 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[4] = (byte)((_address & 7) + ((_address >> 8) & 8)); - num[5] = (byte)(((_address >> 8) & 7)); + num[5] = (byte)((_address >> 8) & 7); if (_compare.HasValue) { @@ -155,17 +155,17 @@ namespace BizHawk.Client.Common num[5] += (byte)(_compare & 8); num[6] = (byte)((_compare & 7) + ((_compare >> 4) & 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 { 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]]; } } diff --git a/BizHawk.Client.Common/SavestateManager.cs b/BizHawk.Client.Common/SavestateManager.cs index 70fb0d6380..3a8ea7b298 100644 --- a/BizHawk.Client.Common/SavestateManager.cs +++ b/BizHawk.Client.Common/SavestateManager.cs @@ -115,7 +115,7 @@ namespace BizHawk.Client.Common break; } - if (str.Trim() == String.Empty) + if (str.Trim() == string.Empty) { continue; } diff --git a/BizHawk.Client.Common/tools/Cheat.cs b/BizHawk.Client.Common/tools/Cheat.cs index 826805b7f0..9a2f325478 100644 --- a/BizHawk.Client.Common/tools/Cheat.cs +++ b/BizHawk.Client.Common/tools/Cheat.cs @@ -1,5 +1,4 @@ -using System; -using BizHawk.Emulation.Common; +using BizHawk.Emulation.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) + { return val.ToString("X8"); - else return val.ToString(); + } + + return val.ToString(); } public void Pulse() @@ -274,6 +276,5 @@ namespace BizHawk.Client.Common Changed(this); } } - } } diff --git a/BizHawk.Client.Common/tools/CheatList.cs b/BizHawk.Client.Common/tools/CheatList.cs index f7acbb63f1..e97711e3e9 100644 --- a/BizHawk.Client.Common/tools/CheatList.cs +++ b/BizHawk.Client.Common/tools/CheatList.cs @@ -273,7 +273,7 @@ namespace BizHawk.Client.Common .Append(cheat.AddressStr).Append('\t') .Append(cheat.ValueStr).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.Name).Append('\t') .Append(cheat.SizeAsChar).Append('\t') diff --git a/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs b/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs index ed9c5375df..464a5de215 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs @@ -372,26 +372,28 @@ namespace BizHawk.Client.EmuHawk { return null; } - else if (SpecificValueRadio.Checked) + + if (SpecificValueRadio.Checked) { return SpecificValueBox.ToRawInt(); } - else if (SpecificAddressRadio.Checked) + + if (SpecificAddressRadio.Checked) { return SpecificAddressBox.ToRawInt(); } - else if (NumberOfChangesRadio.Checked) + + if (NumberOfChangesRadio.Checked) { return NumberOfChangesBox.ToRawInt(); } - else if (DifferenceRadio.Checked) + + if (DifferenceRadio.Checked) { return DifferenceBox.ToRawInt(); } - else - { - return null; - } + + return null; } } @@ -407,13 +409,37 @@ namespace BizHawk.Client.EmuHawk { get { - if (NotEqualToRadio.Checked) return RamSearchEngine.ComparisonOperator.NotEqual; - else if (LessThanRadio.Checked) return RamSearchEngine.ComparisonOperator.LessThan; - else if (GreaterThanRadio.Checked) return RamSearchEngine.ComparisonOperator.GreaterThan; - else if (LessThanOrEqualToRadio.Checked) return RamSearchEngine.ComparisonOperator.LessThanEqual; - else if (GreaterThanOrEqualToRadio.Checked) return RamSearchEngine.ComparisonOperator.GreaterThanEqual; - else if (DifferentByRadio.Checked) return RamSearchEngine.ComparisonOperator.DifferentBy; - else return RamSearchEngine.ComparisonOperator.Equal; + if (NotEqualToRadio.Checked) + { + return RamSearchEngine.ComparisonOperator.NotEqual; + } + + if (LessThanRadio.Checked) + { + 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 { - if (SpecificValueRadio.Checked) return RamSearchEngine.Compare.SpecificValue; - else if (SpecificAddressRadio.Checked) return RamSearchEngine.Compare.SpecificAddress; - else if (NumberOfChangesRadio.Checked) return RamSearchEngine.Compare.Changes; - else if (DifferenceRadio.Checked) return RamSearchEngine.Compare.Difference; - else return RamSearchEngine.Compare.Previous; + if (SpecificValueRadio.Checked) + { + return RamSearchEngine.Compare.SpecificValue; + } + + 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; } }