move Gb GameShark decoding to its own class
This commit is contained in:
parent
5b781f568f
commit
57c19d9db4
|
@ -0,0 +1,37 @@
|
|||
using System.Globalization;
|
||||
|
||||
namespace BizHawk.Client.Common.cheats
|
||||
{
|
||||
public class GbGameSharkDecoder
|
||||
{
|
||||
private readonly string _code;
|
||||
|
||||
public GbGameSharkDecoder(string code)
|
||||
{
|
||||
_code = code;
|
||||
Decode();
|
||||
}
|
||||
|
||||
public int Address { get; private set; }
|
||||
public int Value { get; private set; }
|
||||
|
||||
// Sample Input for GB/GBC:
|
||||
// 010FF6C1
|
||||
// Becomes:
|
||||
// Address C1F6
|
||||
// Value 0F
|
||||
public void Decode()
|
||||
{
|
||||
string code = _code.Remove(0, 2);
|
||||
|
||||
var valueStr = code.Remove(2, 4);
|
||||
code = code.Remove(0, 2);
|
||||
|
||||
var addrStr = code.Remove(0, 2);
|
||||
addrStr = addrStr + code.Remove(2, 2);
|
||||
|
||||
Value = int.Parse(valueStr, NumberStyles.HexNumber);
|
||||
Address = int.Parse(addrStr, NumberStyles.HexNumber);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -118,8 +118,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private void GameBoy()
|
||||
{
|
||||
string ramCompare = null;
|
||||
|
||||
// Game Genie
|
||||
if (_singleCheat.LastIndexOf("-") == 7 && _singleCheat.IndexOf("-") == 3)
|
||||
{
|
||||
|
@ -155,33 +153,9 @@ namespace BizHawk.Client.EmuHawk
|
|||
return;
|
||||
}
|
||||
|
||||
// Sample Input for GB/GBC:
|
||||
// 010FF6C1
|
||||
// Becomes:
|
||||
// Address C1F6
|
||||
// Value 0F
|
||||
_parseString = _singleCheat.Remove(0, 2);
|
||||
|
||||
// Now we need to break it down a little more.
|
||||
_ramValue = _parseString.Remove(2, 4);
|
||||
_parseString = _parseString.Remove(0, 2);
|
||||
|
||||
// The issue is Endian... Time to get ultra clever. And Regret it.
|
||||
// First Half
|
||||
_ramAddress = _parseString.Remove(0, 2);
|
||||
_ramAddress = _ramAddress + _parseString.Remove(2, 2);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var watch = Watch.GenerateWatch(MemoryDomains["System Bus"], long.Parse(_ramAddress, NumberStyles.HexNumber), WatchSize.Word, Common.DisplayType.Hex, false, txtDescription.Text);
|
||||
Global.CheatList.Add(ramCompare == null
|
||||
? new Cheat(watch, int.Parse(_ramValue, NumberStyles.HexNumber))
|
||||
: new Cheat(watch, int.Parse(_ramValue, NumberStyles.HexNumber), int.Parse(ramCompare, NumberStyles.HexNumber)));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"An Error occured: {ex.GetType()}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
var decoder = new GbGameSharkDecoder(_singleCheat);
|
||||
var watch = Watch.GenerateWatch(MemoryDomains["System Bus"], decoder.Address, WatchSize.Word, Common.DisplayType.Hex, false, txtDescription.Text);
|
||||
Global.CheatList.Add(new Cheat(watch, decoder.Value));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue