diff --git a/BizHawk.MultiClient/NEStools/NESGameGenie.Designer.cs b/BizHawk.MultiClient/NEStools/NESGameGenie.Designer.cs index c23c68eafb..f7e99bef47 100644 --- a/BizHawk.MultiClient/NEStools/NESGameGenie.Designer.cs +++ b/BizHawk.MultiClient/NEStools/NESGameGenie.Designer.cs @@ -55,6 +55,11 @@ this.P = new System.Windows.Forms.Button(); this.A = new System.Windows.Forms.Button(); this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.label6 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.Encoding = new System.Windows.Forms.CheckBox(); + this.ClearButton = new System.Windows.Forms.Button(); this.GameGenieCodeBox.SuspendLayout(); this.ButtonPanel.SuspendLayout(); this.groupBox1.SuspendLayout(); @@ -74,7 +79,7 @@ // GameGenieCodeBox // this.GameGenieCodeBox.Controls.Add(this.GameGenieCode); - this.GameGenieCodeBox.Location = new System.Drawing.Point(12, 85); + this.GameGenieCodeBox.Location = new System.Drawing.Point(31, 85); this.GameGenieCodeBox.Name = "GameGenieCodeBox"; this.GameGenieCodeBox.Size = new System.Drawing.Size(115, 54); this.GameGenieCodeBox.TabIndex = 1; @@ -84,7 +89,7 @@ // label3 // this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(15, 68); + this.label3.Location = new System.Drawing.Point(8, 68); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(34, 13); this.label3.TabIndex = 5; @@ -93,7 +98,7 @@ // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(15, 42); + this.label2.Location = new System.Drawing.Point(8, 42); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(49, 13); this.label2.TabIndex = 4; @@ -102,7 +107,7 @@ // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(15, 16); + this.label1.Location = new System.Drawing.Point(8, 16); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(45, 13); this.label1.TabIndex = 3; @@ -135,11 +140,11 @@ // AddressBox // this.AddressBox.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper; - this.AddressBox.Location = new System.Drawing.Point(68, 13); + this.AddressBox.Location = new System.Drawing.Point(75, 13); this.AddressBox.MaxLength = 4; this.AddressBox.Name = "AddressBox"; this.AddressBox.RightToLeft = System.Windows.Forms.RightToLeft.Yes; - this.AddressBox.Size = new System.Drawing.Size(46, 20); + this.AddressBox.Size = new System.Drawing.Size(39, 20); this.AddressBox.TabIndex = 0; this.AddressBox.TextChanged += new System.EventHandler(this.AddressBox_TextChanged); this.AddressBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.AddressBox_KeyPress); @@ -147,9 +152,9 @@ // AddCheat // this.AddCheat.Enabled = false; - this.AddCheat.Location = new System.Drawing.Point(177, 217); + this.AddCheat.Location = new System.Drawing.Point(202, 217); this.AddCheat.Name = "AddCheat"; - this.AddCheat.Size = new System.Drawing.Size(75, 21); + this.AddCheat.Size = new System.Drawing.Size(69, 21); this.AddCheat.TabIndex = 3; this.AddCheat.Text = "Add Cheat"; this.AddCheat.UseVisualStyleBackColor = true; @@ -173,7 +178,7 @@ this.ButtonPanel.Controls.Add(this.Z); this.ButtonPanel.Controls.Add(this.P); this.ButtonPanel.Controls.Add(this.A); - this.ButtonPanel.Location = new System.Drawing.Point(12, 12); + this.ButtonPanel.Location = new System.Drawing.Point(31, 12); this.ButtonPanel.Name = "ButtonPanel"; this.ButtonPanel.Size = new System.Drawing.Size(240, 67); this.ButtonPanel.TabIndex = 4; @@ -340,28 +345,84 @@ // // groupBox1 // + this.groupBox1.Controls.Add(this.label6); + this.groupBox1.Controls.Add(this.label5); + this.groupBox1.Controls.Add(this.label4); this.groupBox1.Controls.Add(this.label3); this.groupBox1.Controls.Add(this.label1); this.groupBox1.Controls.Add(this.label2); this.groupBox1.Controls.Add(this.AddressBox); this.groupBox1.Controls.Add(this.ValueBox); this.groupBox1.Controls.Add(this.CompareBox); - this.groupBox1.Location = new System.Drawing.Point(12, 145); + this.groupBox1.Location = new System.Drawing.Point(31, 145); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(126, 93); this.groupBox1.TabIndex = 5; this.groupBox1.TabStop = false; // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(69, 69); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(18, 13); + this.label6.TabIndex = 9; + this.label6.Text = "0x"; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(69, 42); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(18, 13); + this.label5.TabIndex = 8; + this.label5.Text = "0x"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(57, 16); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(18, 13); + this.label4.TabIndex = 7; + this.label4.Text = "0x"; + // + // Encoding + // + this.Encoding.Appearance = System.Windows.Forms.Appearance.Button; + this.Encoding.AutoSize = true; + this.Encoding.Location = new System.Drawing.Point(217, 101); + this.Encoding.Name = "Encoding"; + this.Encoding.Size = new System.Drawing.Size(54, 23); + this.Encoding.TabIndex = 6; + this.Encoding.Text = "Encode"; + this.Encoding.UseVisualStyleBackColor = true; + // + // ClearButton + // + this.ClearButton.Location = new System.Drawing.Point(217, 130); + this.ClearButton.Name = "ClearButton"; + this.ClearButton.Size = new System.Drawing.Size(54, 23); + this.ClearButton.TabIndex = 7; + this.ClearButton.Text = "&Clear"; + this.ClearButton.UseVisualStyleBackColor = true; + this.ClearButton.Click += new System.EventHandler(this.ClearButton_Click); + // // NESGameGenie // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(290, 266); + this.ClientSize = new System.Drawing.Size(302, 266); + this.Controls.Add(this.ClearButton); + this.Controls.Add(this.Encoding); this.Controls.Add(this.groupBox1); this.Controls.Add(this.ButtonPanel); this.Controls.Add(this.AddCheat); this.Controls.Add(this.GameGenieCodeBox); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D; + this.MaximizeBox = false; this.Name = "NESGameGenie"; + this.ShowIcon = false; this.Text = "Game Genie Encoder / Decoder"; this.Load += new System.EventHandler(this.NESGameGenie_Load); this.GameGenieCodeBox.ResumeLayout(false); @@ -370,6 +431,7 @@ this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); this.ResumeLayout(false); + this.PerformLayout(); } @@ -402,5 +464,10 @@ private System.Windows.Forms.Button O; private System.Windows.Forms.Button E; private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.CheckBox Encoding; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.Button ClearButton; } } \ No newline at end of file diff --git a/BizHawk.MultiClient/NEStools/NESGameGenie.cs b/BizHawk.MultiClient/NEStools/NESGameGenie.cs index 58c2fea5e0..7df32f377b 100644 --- a/BizHawk.MultiClient/NEStools/NESGameGenie.cs +++ b/BizHawk.MultiClient/NEStools/NESGameGenie.cs @@ -6,11 +6,14 @@ using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; +using System.Globalization; +using BizHawk; namespace BizHawk.MultiClient { public partial class NESGameGenie : Form { + //TODO: Encoding: Backspace on textboxes should trigger encoding int address = -1; int value = -1; int compare = -1; @@ -47,8 +50,15 @@ namespace BizHawk.MultiClient if (e.KeyChar > 97 && e.KeyChar < 123) e.KeyChar -= (char)32; - if (!(GameGenieTable.ContainsKey(e.KeyChar))) - e.Handled = true; + if (!(GameGenieTable.ContainsKey(e.KeyChar))) + { + if (!(e.KeyChar == (char)Keys.Back)) //Allow backspace + e.Handled = true; + } + else + { + Encoding.Checked = false; + } } private int GetBit(int value, int bit) @@ -167,10 +177,13 @@ namespace BizHawk.MultiClient private void GameGenieCode_TextChanged(object sender, EventArgs e) { - if (GameGenieCode.Text.Length == 6 || GameGenieCode.Text.Length == 8) - DecodeGameGenieCode(GameGenieCode.Text); - else - ClearProperties(); + if (Encoding.Checked == false) + { + if (GameGenieCode.Text.Length == 6 || GameGenieCode.Text.Length == 8) + DecodeGameGenieCode(GameGenieCode.Text); + else + ClearProperties(); + } } private void Keypad_Click(object sender, EventArgs e) @@ -193,53 +206,147 @@ namespace BizHawk.MultiClient if (sender == S) GameGenieCode.Text += "S"; if (sender == V) GameGenieCode.Text += "V"; if (sender == N) GameGenieCode.Text += "N"; + Encoding.Checked = false; } } private void AddressBox_KeyPress(object sender, KeyPressEventArgs e) { - //TODO: IsValidHex - //if not ignore input + if (!(e.KeyChar == (char)Keys.Back)) //Allow backspace + { + if (InputValidate.IsValidHexNumber(e.KeyChar)) + { + Encoding.Checked = true; + } + else + e.Handled = true; + } + else + Encoding.Checked = true; } private void CompareBox_KeyPress(object sender, KeyPressEventArgs e) { - //TODO: IsValidHex + if (!(e.KeyChar == (char)Keys.Back)) //Allow backspace + { + if (InputValidate.IsValidHexNumber(e.KeyChar)) + { + + Encoding.Checked = true; + } + else + e.Handled = true; + } + else + Encoding.Checked = true; } private void ValueBox_KeyPress(object sender, KeyPressEventArgs e) { - //TODO: IsValidHex + if (!(e.KeyChar == (char)Keys.Back)) //Allow backspace + { + if (InputValidate.IsValidHexNumber(e.KeyChar)) + { + + Encoding.Checked = true; + } + else + e.Handled = true; + } + else + Encoding.Checked = true; } private void AddressBox_TextChanged(object sender, EventArgs e) { - /* - int a = int.Parse(AddressBox.Text); //TODO: try/catch just in case? - if (a >= 0x8000) + if (Encoding.Checked && AddressBox.Text.Length > 0) { - if (ValueBox.Text.Length > 0 && CompareBox.Text.Length > 0) + int a = int.Parse(AddressBox.Text, NumberStyles.HexNumber); //TODO: try/catch just in case? + if (ValueBox.Text.Length > 0) { address = a; - EncodeGameGenie(); //TODO: check to make sure value & compare are set + EncodeGameGenie(); } } - */ //TODO: decoder will change the text and trigger this event, find a way around it } private void CompareBox_TextChanged(object sender, EventArgs e) { - + if (Encoding.Checked) + { + if (CompareBox.Text.Length > 0) + { + int c = int.Parse(CompareBox.Text, NumberStyles.HexNumber); + if (c > 0 && c < 0x100) + { + if (ValueBox.Text.Length > 0 && AddressBox.Text.Length > 0) + { + compare = c; + EncodeGameGenie(); + } + } + } + else + { + compare = -1; + EncodeGameGenie(); + } + } } private void ValueBox_TextChanged(object sender, EventArgs e) { - + if (Encoding.Checked && ValueBox.Text.Length > 0) + { + int v = int.Parse(ValueBox.Text, NumberStyles.HexNumber); + if (v > 0 && v < 0x100) + { + if (AddressBox.Text.Length > 0) + { + value = v; + EncodeGameGenie(); + } + } + } } private void EncodeGameGenie() { + char[] letters = {'A','P','Z','L','G','I','T','Y','E','O','X','U','K','S','V','N'}; + if (address >= 0x8000) + address -= 0x8000; + GameGenieCode.Text = ""; + 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[3] = (byte)((address >> 12) + (address & 8)); + num[4] = (byte)((address & 7) + ((address >> 8) & 8)); + num[5] = (byte)(((address >> 8) & 7)); + if (compare < 0 || CompareBox.Text.Length == 0) + { + num[5] += (byte)(value & 8); + for (int x = 0; x < 6; x++) + GameGenieCode.Text += letters[num[x]]; + } + else + { + num[2] += 8; + num[5] += (byte)(compare & 8); + num[6] = (byte)((compare & 7) + ((compare >> 4) & 8)); + num[7] = (byte)(((compare >> 4) & 7) + (value & 8)); + for (int x = 0; x < 8; x++) + GameGenieCode.Text += letters[num[x]]; + } + + } + + private void ClearButton_Click(object sender, EventArgs e) + { + ClearProperties(); + GameGenieCode.Text = ""; + Encoding.Checked = false; } } }