Gameboy Game Genie dialog - top most and floating window, and refactor to use ToolSettingsDialog, and some code cleanup

This commit is contained in:
adelikat 2014-01-31 02:26:09 +00:00
parent 8e2fa8a31b
commit e634d9558a
3 changed files with 861 additions and 761 deletions

View File

@ -481,10 +481,9 @@ namespace BizHawk.Client.Common
public int SNESGGWndy = -1; public int SNESGGWndy = -1;
// GB/GG Game Genie Encoder/Decoder // GB/GG Game Genie Encoder/Decoder
public ToolDialogSettings GbGGSettings = new ToolDialogSettings();
public bool GBGGAutoload = false; public bool GBGGAutoload = false;
public bool GBGGSaveWindowPosition = true;
public int GBGGWndx = -1;
public int GBGGWndy = -1;
// GEN Game Genie Encoder/Decoder // GEN Game Genie Encoder/Decoder
public bool GENGGAutoload = false; public bool GENGGAutoload = false;

View File

@ -60,11 +60,14 @@
this.label4 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label();
this.ClearButton = new System.Windows.Forms.Button(); this.ClearButton = new System.Windows.Forms.Button();
this.menuStrip1 = new MenuStripEx(); this.menuStrip1 = new MenuStripEx();
this.optionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.OptionsSubMenu = new System.Windows.Forms.ToolStripMenuItem();
this.autoloadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.AutoloadMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.saveWindowPositionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
this.SaveWindowPositionMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.AlwaysOnTopMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.FloatingWindowMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ExitMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.groupBox2 = new System.Windows.Forms.GroupBox(); this.groupBox2 = new System.Windows.Forms.GroupBox();
this.cheatname = new System.Windows.Forms.TextBox(); this.cheatname = new System.Windows.Forms.TextBox();
this.GameGenieCodeBox.SuspendLayout(); this.GameGenieCodeBox.SuspendLayout();
@ -419,51 +422,73 @@
// //
this.menuStrip1.ClickThrough = true; this.menuStrip1.ClickThrough = true;
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.optionsToolStripMenuItem}); this.OptionsSubMenu});
this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(302, 24); this.menuStrip1.Size = new System.Drawing.Size(292, 24);
this.menuStrip1.TabIndex = 8; this.menuStrip1.TabIndex = 8;
this.menuStrip1.Text = "menuStrip1"; this.menuStrip1.Text = "menuStrip1";
// //
// optionsToolStripMenuItem // OptionsSubMenu
// //
this.optionsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.OptionsSubMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.autoloadToolStripMenuItem, this.AutoloadMenuItem,
this.saveWindowPositionToolStripMenuItem, this.toolStripSeparator2,
this.SaveWindowPositionMenuItem,
this.AlwaysOnTopMenuItem,
this.FloatingWindowMenuItem,
this.toolStripSeparator1, this.toolStripSeparator1,
this.exitToolStripMenuItem}); this.ExitMenuItem});
this.optionsToolStripMenuItem.Name = "optionsToolStripMenuItem"; this.OptionsSubMenu.Name = "OptionsSubMenu";
this.optionsToolStripMenuItem.Size = new System.Drawing.Size(61, 20); this.OptionsSubMenu.Size = new System.Drawing.Size(61, 20);
this.optionsToolStripMenuItem.Text = "&Options"; this.OptionsSubMenu.Text = "&Options";
this.optionsToolStripMenuItem.DropDownOpened += new System.EventHandler(this.optionsToolStripMenuItem_DropDownOpened); this.OptionsSubMenu.DropDownOpened += new System.EventHandler(this.OptionsSubMenu_DropDownOpened);
// //
// autoloadToolStripMenuItem // AutoloadMenuItem
// //
this.autoloadToolStripMenuItem.Name = "autoloadToolStripMenuItem"; this.AutoloadMenuItem.Name = "AutoloadMenuItem";
this.autoloadToolStripMenuItem.Size = new System.Drawing.Size(191, 22); this.AutoloadMenuItem.Size = new System.Drawing.Size(191, 22);
this.autoloadToolStripMenuItem.Text = "Auto-load"; this.AutoloadMenuItem.Text = "Auto-load";
this.autoloadToolStripMenuItem.Click += new System.EventHandler(this.autoloadToolStripMenuItem_Click); this.AutoloadMenuItem.Click += new System.EventHandler(this.AutoloadMenuItem_Click);
// //
// saveWindowPositionToolStripMenuItem // toolStripSeparator2
// //
this.saveWindowPositionToolStripMenuItem.Name = "saveWindowPositionToolStripMenuItem"; this.toolStripSeparator2.Name = "toolStripSeparator2";
this.saveWindowPositionToolStripMenuItem.Size = new System.Drawing.Size(191, 22); this.toolStripSeparator2.Size = new System.Drawing.Size(188, 6);
this.saveWindowPositionToolStripMenuItem.Text = "Save Window Position"; //
this.saveWindowPositionToolStripMenuItem.Click += new System.EventHandler(this.saveWindowPositionToolStripMenuItem_Click); // SaveWindowPositionMenuItem
//
this.SaveWindowPositionMenuItem.Name = "SaveWindowPositionMenuItem";
this.SaveWindowPositionMenuItem.Size = new System.Drawing.Size(191, 22);
this.SaveWindowPositionMenuItem.Text = "Save Window Position";
this.SaveWindowPositionMenuItem.Click += new System.EventHandler(this.SaveWindowPositionMenuItem_Click);
//
// AlwaysOnTopMenuItem
//
this.AlwaysOnTopMenuItem.Name = "AlwaysOnTopMenuItem";
this.AlwaysOnTopMenuItem.Size = new System.Drawing.Size(191, 22);
this.AlwaysOnTopMenuItem.Text = "Always On Top";
this.AlwaysOnTopMenuItem.Click += new System.EventHandler(this.AlwaysOnTopMenuItem_Click);
//
// FloatingWindowMenuItem
//
this.FloatingWindowMenuItem.Name = "FloatingWindowMenuItem";
this.FloatingWindowMenuItem.Size = new System.Drawing.Size(191, 22);
this.FloatingWindowMenuItem.Text = "Floating Window";
this.FloatingWindowMenuItem.Click += new System.EventHandler(this.FloatingWindowMenuItem_Click);
// //
// toolStripSeparator1 // toolStripSeparator1
// //
this.toolStripSeparator1.Name = "toolStripSeparator1"; this.toolStripSeparator1.Name = "toolStripSeparator1";
this.toolStripSeparator1.Size = new System.Drawing.Size(188, 6); this.toolStripSeparator1.Size = new System.Drawing.Size(188, 6);
// //
// exitToolStripMenuItem // ExitMenuItem
// //
this.exitToolStripMenuItem.Name = "exitToolStripMenuItem"; this.ExitMenuItem.Name = "ExitMenuItem";
this.exitToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.F4))); this.ExitMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.F4)));
this.exitToolStripMenuItem.Size = new System.Drawing.Size(191, 22); this.ExitMenuItem.Size = new System.Drawing.Size(191, 22);
this.exitToolStripMenuItem.Text = "E&xit"; this.ExitMenuItem.Text = "E&xit";
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click); this.ExitMenuItem.Click += new System.EventHandler(this.ExitMenuItem_Click);
// //
// groupBox2 // groupBox2
// //
@ -489,7 +514,7 @@
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(302, 262); this.ClientSize = new System.Drawing.Size(292, 252);
this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox2);
this.Controls.Add(this.ClearButton); this.Controls.Add(this.ClearButton);
this.Controls.Add(this.groupBox1); this.Controls.Add(this.groupBox1);
@ -506,7 +531,7 @@
this.ShowIcon = false; this.ShowIcon = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Game Boy/Game Gear Game Genie Encoder / Decoder"; this.Text = "Game Boy/Game Gear Game Genie Encoder / Decoder";
this.Load += new System.EventHandler(this.GBGameGenie_Load_1); this.Load += new System.EventHandler(this.GBGameGenie_Load);
this.GameGenieCodeBox.ResumeLayout(false); this.GameGenieCodeBox.ResumeLayout(false);
this.GameGenieCodeBox.PerformLayout(); this.GameGenieCodeBox.PerformLayout();
this.ButtonPanel.ResumeLayout(false); this.ButtonPanel.ResumeLayout(false);
@ -551,16 +576,19 @@
private System.Windows.Forms.Label label4; private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button ClearButton; private System.Windows.Forms.Button ClearButton;
private MenuStripEx menuStrip1; private MenuStripEx menuStrip1;
private System.Windows.Forms.ToolStripMenuItem optionsToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem OptionsSubMenu;
private System.Windows.Forms.ToolStripMenuItem autoloadToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem AutoloadMenuItem;
private System.Windows.Forms.ToolStripMenuItem saveWindowPositionToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem SaveWindowPositionMenuItem;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem ExitMenuItem;
private System.Windows.Forms.MaskedTextBox GGCodeMaskBox; private System.Windows.Forms.MaskedTextBox GGCodeMaskBox;
private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.TextBox cheatname; private System.Windows.Forms.TextBox cheatname;
private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label5; private System.Windows.Forms.Label label5;
private HexTextBox CompareBox; private HexTextBox CompareBox;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
private System.Windows.Forms.ToolStripMenuItem AlwaysOnTopMenuItem;
private System.Windows.Forms.ToolStripMenuItem FloatingWindowMenuItem;
} }
} }

View File

@ -1,9 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Globalization; using System.Globalization;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Windows.Forms;
using BizHawk.Client.Common; using BizHawk.Client.Common;
@ -14,6 +13,8 @@ namespace BizHawk.Client.EmuHawk
private readonly Dictionary<char, int> _gameGenieTable = new Dictionary<char, int>(); private readonly Dictionary<char, int> _gameGenieTable = new Dictionary<char, int>();
private bool _processing; private bool _processing;
#region Public
public bool AskSave() { return true; } public bool AskSave() { return true; }
public bool UpdateBefore { get { return false; } } public bool UpdateBefore { get { return false; } }
@ -38,6 +39,7 @@ namespace BizHawk.Client.EmuHawk
{ {
InitializeComponent(); InitializeComponent();
Closing += (o, e) => SaveConfigSettings(); Closing += (o, e) => SaveConfigSettings();
TopMost = Global.Config.GbGGSettings.TopMost;
_gameGenieTable.Add('0', 0); // 0000 _gameGenieTable.Add('0', 0); // 0000
_gameGenieTable.Add('1', 1); // 0001 _gameGenieTable.Add('1', 1); // 0001
@ -65,7 +67,6 @@ namespace BizHawk.Client.EmuHawk
// 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|3|2|1|0| // 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|3|2|1|0|
// maps to| Value |A|B|C|D|E|F|G|H|I|J|K|L|XOR 0xF|a|b|c|c|NotUsed|e|f|g|h| // maps to| Value |A|B|C|D|E|F|G|H|I|J|K|L|XOR 0xF|a|b|c|c|NotUsed|e|f|g|h|
// proper | Value |XOR 0xF|A|B|C|D|E|F|G|H|I|J|K|L|g|h|a|b|Nothing|c|d|e|f| // proper | Value |XOR 0xF|A|B|C|D|E|F|G|H|I|J|K|L|g|h|a|b|Nothing|c|d|e|f|
int x; int x;
// Getting Value // Getting Value
if (code.Length > 0) if (code.Length > 0)
@ -83,15 +84,17 @@ namespace BizHawk.Client.EmuHawk
if (code.Length > 2) if (code.Length > 2)
{ {
_gameGenieTable.TryGetValue(code[2], out x); _gameGenieTable.TryGetValue(code[2], out x);
add = (x << 8); add = x << 8;
} }
else else
{
add = -1; add = -1;
}
if (code.Length > 3) if (code.Length > 3)
{ {
_gameGenieTable.TryGetValue(code[3], out x); _gameGenieTable.TryGetValue(code[3], out x);
add |= (x << 4); add |= x << 4;
} }
if (code.Length > 4) if (code.Length > 4)
@ -103,71 +106,366 @@ namespace BizHawk.Client.EmuHawk
if (code.Length > 5) if (code.Length > 5)
{ {
_gameGenieTable.TryGetValue(code[5], out x); _gameGenieTable.TryGetValue(code[5], out x);
add |= ((x ^ 0xF) << 12); add |= (x ^ 0xF) << 12;
} }
// compare need to be full // compare need to be full
if (code.Length > 8) if (code.Length > 8)
{ {
int comp = 0; int comp = 0;
_gameGenieTable.TryGetValue(code[6], out x); _gameGenieTable.TryGetValue(code[6], out x);
comp = (x << 2); comp = x << 2;
// 8th character ignored // 8th character ignored
_gameGenieTable.TryGetValue(code[8], out x); _gameGenieTable.TryGetValue(code[8], out x);
comp |= ((x & 0xC) >> 2); comp |= (x & 0xC) >> 2;
comp |= ((x & 0x3) << 6); comp |= (x & 0x3) << 6;
cmp = comp ^ 0xBA; cmp = comp ^ 0xBA;
} }
else else
{
cmp = -1; cmp = -1;
} }
}
#endregion
private string GBGGEncode(int val, int add, int cmp) private string GBGGEncode(int val, int add, int cmp)
{ {
char[] letters = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; char[] letters = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
string code = ""; string code = string.Empty;
int[] num = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int[] num = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
num[0] = (val & 0xF0) >> 4; num[0] = (val & 0xF0) >> 4;
num[1] = val & 0x0F; num[1] = val & 0x0F;
num[2] = (add & 0x0F00) >> 8; num[2] = (add & 0x0F00) >> 8;
num[3] = (add & 0x00F0) >> 4; num[3] = (add & 0x00F0) >> 4;
num[4] = (add & 0x000F); num[4] = add & 0x000F;
num[5] = (((add & 0xF000) >> 12) ^ 0xF); num[5] = ((add & 0xF000) >> 12) ^ 0xF;
if (cmp > -1) if (cmp > -1)
{ {
int xoredcomp = (cmp & 0xFF) ^ 0xBA;
num[6] = (xoredcomp & 0x30) >> 2;
num[6] |= (xoredcomp & 0x0C) >> 2;
int xoredcomp = ((cmp & 0xFF) ^ 0xBA);
num[6] = ((xoredcomp & 0x30) >> 2);
num[6] |= ((xoredcomp & 0x0C) >> 2);
// 8th char has no real use (its value is not reflected in the address:value:compare // 8th char has no real use (its value is not reflected in the address:value:compare
// probably a protection to stop people making code up, xor the 7th digit with 0x8 // probably a protection to stop people making code up, xor the 7th digit with 0x8
// to get back what the original code had (Might be more to it) // to get back what the original code had (Might be more to it)
num[7] = num[6] ^ 8; num[7] = num[6] ^ 8;
num[8] = ((xoredcomp & 0xC0) >> 6); num[8] = (xoredcomp & 0xC0) >> 6;
num[8] |= ((xoredcomp & 0x03) << 2); num[8] |= (xoredcomp & 0x03) << 2;
for (int x = 0; x < 9; x++)
code += letters[num[x]]; for (int i = 0; i < 9; i++)
{
code += letters[num[i]];
}
} }
else else
{ {
for (int x = 0; x < 6; x++) for (int i = 0; i < 6; i++)
code += letters[num[x]]; {
code += letters[num[i]];
} }
}
return code; return code;
} }
private void GBGameGenie_Load(object sender, EventArgs e) private void GBGameGenie_Load(object sender, EventArgs e)
{ {
addcheatbt.Enabled = false; addcheatbt.Enabled = false;
if (Global.Config.GBGGSaveWindowPosition && Global.Config.GBGGWndx >= 0 && Global.Config.GBGGWndy >= 0) if (Global.Config.GbGGSettings.UseWindowPosition)
Location = new Point(Global.Config.GBGGWndx, Global.Config.GBGGWndy); {
Location = Global.Config.GbGGSettings.WindowPosition;
}
} }
private void SaveConfigSettings() private void SaveConfigSettings()
{ {
Global.Config.GBGGWndx = Location.X; Global.Config.GbGGSettings.Wndx = Location.X;
Global.Config.GBGGWndy = Location.Y; Global.Config.GbGGSettings.Wndy = Location.Y;
}
private void RefreshFloatingWindowControl()
{
Owner = Global.Config.GbGGSettings.FloatingWindow ? null : GlobalWin.MainForm;
}
#region Events
#region Menu
private void OptionsSubMenu_DropDownOpened(object sender, EventArgs e)
{
AutoloadMenuItem.Checked = Global.Config.GBGGAutoload;
SaveWindowPositionMenuItem.Checked = Global.Config.GbGGSettings.SaveWindowPosition;
AlwaysOnTopMenuItem.Checked = Global.Config.GbGGSettings.TopMost;
FloatingWindowMenuItem.Checked = Global.Config.GbGGSettings.FloatingWindow;
}
private void AutoloadMenuItem_Click(object sender, EventArgs e)
{
Global.Config.GBGGAutoload ^= true;
}
private void SaveWindowPositionMenuItem_Click(object sender, EventArgs e)
{
Global.Config.GbGGSettings.SaveWindowPosition ^= true;
}
private void AlwaysOnTopMenuItem_Click(object sender, EventArgs e)
{
Global.Config.GbGGSettings.TopMost ^= true;
TopMost = Global.Config.GbGGSettings.TopMost;
}
private void FloatingWindowMenuItem_Click(object sender, EventArgs e)
{
Global.Config.GbGGSettings.FloatingWindow ^= true;
RefreshFloatingWindowControl();
}
private void ExitMenuItem_Click(object sender, EventArgs e)
{
Close();
}
#endregion
#region Dialog and Controls
private void AddCheatClick(object sender, EventArgs e)
{
if ((Global.Emulator.SystemId == "GB") || (Global.Game.System == "GG"))
{
string name;
var address = 0;
var value = 0;
int? compare = null;
if (!string.IsNullOrWhiteSpace(cheatname.Text))
{
name = cheatname.Text;
}
else
{
_processing = true;
GGCodeMaskBox.TextMaskFormat = MaskFormat.IncludeLiterals;
name = GGCodeMaskBox.Text;
GGCodeMaskBox.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals;
_processing = false;
}
if (!string.IsNullOrWhiteSpace(AddressBox.Text))
{
address = int.Parse(AddressBox.Text, NumberStyles.HexNumber);
}
if (!string.IsNullOrWhiteSpace(ValueBox.Text))
{
value = (byte)int.Parse(ValueBox.Text, NumberStyles.HexNumber);
}
if (!string.IsNullOrWhiteSpace(CompareBox.Text))
{
try
{
compare = byte.Parse(CompareBox.Text, NumberStyles.HexNumber);
}
catch
{
compare = null;
}
}
var watch = Watch.GenerateWatch(
Global.Emulator.MemoryDomains["System Bus"],
address,
Watch.WatchSize.Byte,
Watch.DisplayType.Hex,
name,
false);
Global.CheatList.Add(new Cheat(
watch,
value,
compare));
}
}
private void ClearButton_Click(object sender, EventArgs e)
{
AddressBox.Text = string.Empty;
ValueBox.Text = string.Empty;
CompareBox.Text = string.Empty;
GGCodeMaskBox.Text = string.Empty;
addcheatbt.Enabled = false;
}
private void CompareBox_TextChanged(object sender, EventArgs e)
{
if (_processing == false)
{
_processing = true;
// remove invalid character when pasted
if (Regex.IsMatch(CompareBox.Text, @"[^a-fA-F0-9]"))
{
CompareBox.Text = Regex.Replace(CompareBox.Text, @"[^a-fA-F0-9]", string.Empty);
}
if ((CompareBox.Text.Length == 2) || (CompareBox.Text.Length == 0))
{
if ((AddressBox.Text.Length > 0) || (ValueBox.Text.Length > 0))
{
int val = 0;
int add = 0;
int cmp = -1;
if (ValueBox.Text.Length > 0)
{
val = int.Parse(ValueBox.Text, NumberStyles.HexNumber);
}
if (AddressBox.Text.Length > 0)
{
add = int.Parse(AddressBox.Text, NumberStyles.HexNumber);
}
if (CompareBox.Text.Length == 2)
{
cmp = int.Parse(CompareBox.Text, NumberStyles.HexNumber);
}
GGCodeMaskBox.Text = GBGGEncode(val, add, cmp);
addcheatbt.Enabled = true;
}
else
{
GGCodeMaskBox.Text = string.Empty;
addcheatbt.Enabled = false;
}
}
_processing = false;
}
}
private void ValueBox_TextChanged(object sender, EventArgs e)
{
if (_processing == false)
{
_processing = true;
// remove invalid character when pasted
if (Regex.IsMatch(ValueBox.Text, @"[^a-fA-F0-9]"))
{
ValueBox.Text = Regex.Replace(ValueBox.Text, @"[^a-fA-F0-9]", string.Empty);
}
if ((AddressBox.Text.Length > 0) || (ValueBox.Text.Length > 0))
{
var val = 0;
var add = 0;
var cmp = -1;
if (ValueBox.Text.Length > 0)
{
val = int.Parse(ValueBox.Text, NumberStyles.HexNumber);
}
if (AddressBox.Text.Length > 0)
{
add = int.Parse(AddressBox.Text, NumberStyles.HexNumber);
}
if (CompareBox.Text.Length == 2)
{
cmp = int.Parse(CompareBox.Text, NumberStyles.HexNumber);
}
GGCodeMaskBox.Text = GBGGEncode(val, add, cmp);
addcheatbt.Enabled = true;
}
else
{
GGCodeMaskBox.Text = string.Empty;
addcheatbt.Enabled = false;
}
_processing = false;
}
}
private void AddressBox_TextChanged(object sender, EventArgs e)
{
// remove invalid character when pasted
if (_processing == false)
{
_processing = true;
if (Regex.IsMatch(AddressBox.Text, @"[^a-fA-F0-9]"))
{
AddressBox.Text = Regex.Replace(AddressBox.Text, @"[^a-fA-F0-9]", string.Empty);
}
if ((AddressBox.Text.Length > 0) || (ValueBox.Text.Length > 0))
{
var val = 0;
var add = 0;
var cmp = -1;
if (ValueBox.Text.Length > 0)
{
val = int.Parse(ValueBox.Text, NumberStyles.HexNumber);
}
if (AddressBox.Text.Length > 0)
{
add = int.Parse(AddressBox.Text, NumberStyles.HexNumber);
}
if (CompareBox.Text.Length == 2)
{
cmp = int.Parse(CompareBox.Text, NumberStyles.HexNumber);
}
GGCodeMaskBox.Text = GBGGEncode(val, add, cmp);
addcheatbt.Enabled = true;
}
else
{
GGCodeMaskBox.Text = string.Empty;
addcheatbt.Enabled = false;
}
_processing = false;
}
}
private void Keypad_Click(object sender, EventArgs e)
{
if (GGCodeMaskBox.Text.Length < 9)
{
var code = string.Empty;
if (sender == B0) { code = "0"; }
else if (sender == B1) { code = "1"; }
else if (sender == B2) { code = "2"; }
else if (sender == B3) { code = "3"; }
else if (sender == B4) { code = "4"; }
else if (sender == B5) { code = "5"; }
else if (sender == B6) { code = "6"; }
else if (sender == B7) { code = "7"; }
else if (sender == B8) { code = "8"; }
else if (sender == B9) { code = "9"; }
else if (sender == BA) { code = "A"; }
else if (sender == BB) { code = "B"; }
else if (sender == BC) { code = "C"; }
else if (sender == BD) { code = "D"; }
else if (sender == BE) { code = "E"; }
else if (sender == BF) { code = "F"; }
GGCodeMaskBox.Text += code;
}
} }
private void GGCodeMaskBox_KeyPress(object sender, KeyPressEventArgs e) private void GGCodeMaskBox_KeyPress(object sender, KeyPressEventArgs e)
@ -182,285 +480,60 @@ namespace BizHawk.Client.EmuHawk
if (_processing == false) if (_processing == false)
{ {
_processing = true; _processing = true;
// insert REGEX Remove non HEXA char // insert REGEX Remove non HEXA char
if (Regex.IsMatch(GGCodeMaskBox.Text, @"[^a-fA-F0-9]")) if (Regex.IsMatch(GGCodeMaskBox.Text, @"[^a-fA-F0-9]"))
{ {
string temp = Regex.Replace(GGCodeMaskBox.Text, @"[^a-fA-F0-9]", string.Empty); GGCodeMaskBox.Text = Regex.Replace(GGCodeMaskBox.Text, @"[^a-fA-F0-9]", string.Empty);
GGCodeMaskBox.Text = temp;
} }
if (GGCodeMaskBox.Text.Length > 0) if (GGCodeMaskBox.Text.Length > 0)
{ {
int val = -1; var val = -1;
int add = -1; var add = -1;
int cmp = -1; var cmp = -1;
GBGGDecode(GGCodeMaskBox.Text, ref val, ref add, ref cmp); GBGGDecode(GGCodeMaskBox.Text, ref val, ref add, ref cmp);
if (add > -1) if (add > -1)
AddressBox.Text = String.Format("{0:X4}", add); {
AddressBox.Text = string.Format("{0:X4}", add);
}
if (val > -1) if (val > -1)
ValueBox.Text = String.Format("{0:X2}", val); {
ValueBox.Text = string.Format("{0:X2}", val);
}
if (cmp > -1) if (cmp > -1)
CompareBox.Text = String.Format("{0:X2}", cmp); {
CompareBox.Text = string.Format("{0:X2}", cmp);
}
else else
CompareBox.Text = ""; {
CompareBox.Text = string.Empty;
}
addcheatbt.Enabled = true; addcheatbt.Enabled = true;
} }
else else
{ {
AddressBox.Text = ""; AddressBox.Text = string.Empty;
ValueBox.Text = ""; ValueBox.Text = string.Empty;
CompareBox.Text = ""; CompareBox.Text = string.Empty;
addcheatbt.Enabled = false; addcheatbt.Enabled = false;
} }
_processing = false; _processing = false;
} }
} }
private void Keypad_Click(object sender, EventArgs e) protected override void OnShown(EventArgs e)
{ {
if (GGCodeMaskBox.Text.Length < 9) RefreshFloatingWindowControl();
{ base.OnShown(e);
string code = "";
if (sender == B0) code = "0";
if (sender == B1) code = "1";
if (sender == B2) code = "2";
if (sender == B3) code = "3";
if (sender == B4) code = "4";
if (sender == B5) code = "5";
if (sender == B6) code = "6";
if (sender == B7) code = "7";
if (sender == B8) code = "8";
if (sender == B9) code = "9";
if (sender == BA) code = "A";
if (sender == BB) code = "B";
if (sender == BC) code = "C";
if (sender == BD) code = "D";
if (sender == BE) code = "E";
if (sender == BF) code = "F";
GGCodeMaskBox.Text += code;
//int x = GGCodeMaskBox.SelectionStart;
//GGCodeMaskBox.Text = GGCodeMaskBox.Text.Insert(x, code);
//GGCodeMaskBox.SelectionStart = x + 1;
}
}
private void AddressBox_TextChanged(object sender, EventArgs e)
{
//remove invalid character when pasted
if (_processing == false)
{
_processing = true;
if (Regex.IsMatch(AddressBox.Text, @"[^a-fA-F0-9]"))
{
string temp = Regex.Replace(AddressBox.Text, @"[^a-fA-F0-9]", string.Empty);
AddressBox.Text = temp;
}
if ((AddressBox.Text.Length > 0) || (ValueBox.Text.Length > 0))
{
int val = 0;
int add = 0;
int cmp = -1;
if (ValueBox.Text.Length > 0)
val = int.Parse(ValueBox.Text, NumberStyles.HexNumber);
if (AddressBox.Text.Length > 0)
add = int.Parse(AddressBox.Text, NumberStyles.HexNumber);
if (CompareBox.Text.Length == 2)
cmp = int.Parse(CompareBox.Text, NumberStyles.HexNumber);
GGCodeMaskBox.Text = GBGGEncode(val, add, cmp);
addcheatbt.Enabled = true;
}
else
{
GGCodeMaskBox.Text = "";
addcheatbt.Enabled = false;
}
_processing = false;
}
}
private void ValueBox_TextChanged(object sender, EventArgs e)
{
if (_processing == false)
{
_processing = true;
//remove invalid character when pasted
if (Regex.IsMatch(ValueBox.Text, @"[^a-fA-F0-9]"))
{
string temp = Regex.Replace(ValueBox.Text, @"[^a-fA-F0-9]", string.Empty);
ValueBox.Text = temp;
}
if ((AddressBox.Text.Length > 0) || (ValueBox.Text.Length > 0))
{
int val = 0;
int add = 0;
int cmp = -1;
if (ValueBox.Text.Length > 0)
val = int.Parse(ValueBox.Text, NumberStyles.HexNumber);
if (AddressBox.Text.Length > 0)
add = int.Parse(AddressBox.Text, NumberStyles.HexNumber);
if (CompareBox.Text.Length == 2)
cmp = int.Parse(CompareBox.Text, NumberStyles.HexNumber);
GGCodeMaskBox.Text = GBGGEncode(val, add, cmp);
addcheatbt.Enabled = true;
}
else
{
GGCodeMaskBox.Text = "";
addcheatbt.Enabled = false;
}
_processing = false;
}
}
private void CompareBox_TextChanged(object sender, EventArgs e)
{
if (_processing == false)
{
_processing = true;
//remove invalid character when pasted
if (Regex.IsMatch(CompareBox.Text, @"[^a-fA-F0-9]"))
{
string temp = Regex.Replace(CompareBox.Text, @"[^a-fA-F0-9]", string.Empty);
CompareBox.Text = temp;
}
if ((CompareBox.Text.Length == 2) || (CompareBox.Text.Length == 0))
{
if ((AddressBox.Text.Length > 0) || (ValueBox.Text.Length > 0))
{
int val = 0;
int add = 0;
int cmp = -1;
if (ValueBox.Text.Length > 0)
val = int.Parse(ValueBox.Text, NumberStyles.HexNumber);
if (AddressBox.Text.Length > 0)
add = int.Parse(AddressBox.Text, NumberStyles.HexNumber);
if (CompareBox.Text.Length == 2)
cmp = int.Parse(CompareBox.Text, NumberStyles.HexNumber);
GGCodeMaskBox.Text = GBGGEncode(val, add, cmp);
addcheatbt.Enabled = true;
}
else
{
GGCodeMaskBox.Text = "";
addcheatbt.Enabled = false;
}
}
_processing = false;
}
}
private void ClearButton_Click(object sender, EventArgs e)
{
AddressBox.Text = "";
ValueBox.Text = "";
CompareBox.Text = "";
GGCodeMaskBox.Text = "";
addcheatbt.Enabled = false;
}
private void AddCheatClick(object sender, EventArgs e)
{
if ((Global.Emulator.SystemId == "GB") || (Global.Game.System == "GG"))
{
string NAME;
int ADDRESS = 0;
int VALUE = 0;
int? COMPARE = null;
int sysBusIndex = 0;
if (!String.IsNullOrWhiteSpace(cheatname.Text))
{
NAME = cheatname.Text;
}
else
{
_processing = true;
GGCodeMaskBox.TextMaskFormat = MaskFormat.IncludeLiterals;
NAME = GGCodeMaskBox.Text;
GGCodeMaskBox.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals;
_processing = false;
}
if (!String.IsNullOrWhiteSpace(AddressBox.Text))
{
ADDRESS = int.Parse(AddressBox.Text, NumberStyles.HexNumber);
}
if (!String.IsNullOrWhiteSpace(ValueBox.Text))
{
VALUE = (byte)(int.Parse(ValueBox.Text, NumberStyles.HexNumber));
}
if (!String.IsNullOrWhiteSpace(CompareBox.Text))
{
try
{
COMPARE = byte.Parse(CompareBox.Text, NumberStyles.HexNumber);
}
catch
{
COMPARE = null;
}
}
for (int i = 0; i < Global.Emulator.MemoryDomains.Count; i++)
{
if (Global.Emulator.MemoryDomains[i].ToString() == "System Bus")
{
sysBusIndex = i;
break;
}
}
Watch watch = Watch.GenerateWatch(
Global.Emulator.MemoryDomains[sysBusIndex],
ADDRESS,
Watch.WatchSize.Byte,
Watch.DisplayType.Hex,
NAME,
false);
Global.CheatList.Add(new Cheat(
watch,
VALUE,
COMPARE));
}
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Close();
}
private void saveWindowPositionToolStripMenuItem_Click(object sender, EventArgs e)
{
Global.Config.GBGGSaveWindowPosition ^= true;
}
private void autoloadToolStripMenuItem_Click(object sender, EventArgs e)
{
Global.Config.GBGGAutoload ^= true;
}
private void optionsToolStripMenuItem_DropDownOpened(object sender, EventArgs e)
{
autoloadToolStripMenuItem.Checked = Global.Config.GBGGAutoload;
saveWindowPositionToolStripMenuItem.Checked = Global.Config.GBGGSaveWindowPosition;
}
private void GBGameGenie_Load_1(object sender, EventArgs e)
{
} }
#endregion
#endregion
} }
} }