From eaaac167f1ae3d50729a6ff9401703886f08f9dc Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 6 Sep 2015 23:23:04 -0400 Subject: [PATCH] Basic Bot - ability to set datasize and endianness of ram values --- .../tools/BasicBot/BasicBot.Designer.cs | 41 ++++++++++++ .../tools/BasicBot/BasicBot.cs | 62 +++++++++++++++++-- 2 files changed, 99 insertions(+), 4 deletions(-) diff --git a/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.Designer.cs b/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.Designer.cs index 6114384f5a..38e49ef4c6 100644 --- a/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.Designer.cs @@ -43,6 +43,10 @@ this.OptionsSubMenu = new System.Windows.Forms.ToolStripMenuItem(); this.MemoryDomainsMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator(); + this.DataSizeMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this._1ByteMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this._2ByteMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this._4ByteMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.BigEndianMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator(); this.TurboWhileBottingMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -201,6 +205,7 @@ // this.OptionsSubMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.MemoryDomainsMenuItem, + this.DataSizeMenuItem, this.BigEndianMenuItem, this.toolStripSeparator4, this.TurboWhileBottingMenuItem}); @@ -223,6 +228,38 @@ this.toolStripSeparator3.Name = "toolStripSeparator3"; this.toolStripSeparator3.Size = new System.Drawing.Size(57, 6); // + // DataSizeMenuItem + // + this.DataSizeMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this._1ByteMenuItem, + this._2ByteMenuItem, + this._4ByteMenuItem}); + this.DataSizeMenuItem.Name = "DataSizeMenuItem"; + this.DataSizeMenuItem.Size = new System.Drawing.Size(181, 22); + this.DataSizeMenuItem.Text = "Data Size"; + this.DataSizeMenuItem.DropDownOpened += new System.EventHandler(this.DataSizeMenuItem_DropDownOpened); + // + // _1ByteMenuItem + // + this._1ByteMenuItem.Name = "_1ByteMenuItem"; + this._1ByteMenuItem.Size = new System.Drawing.Size(152, 22); + this._1ByteMenuItem.Text = "1 Byte"; + this._1ByteMenuItem.Click += new System.EventHandler(this._1ByteMenuItem_Click); + // + // _2ByteMenuItem + // + this._2ByteMenuItem.Name = "_2ByteMenuItem"; + this._2ByteMenuItem.Size = new System.Drawing.Size(152, 22); + this._2ByteMenuItem.Text = "2 Bytes"; + this._2ByteMenuItem.Click += new System.EventHandler(this._2ByteMenuItem_Click); + // + // _4ByteMenuItem + // + this._4ByteMenuItem.Name = "_4ByteMenuItem"; + this._4ByteMenuItem.Size = new System.Drawing.Size(152, 22); + this._4ByteMenuItem.Text = "4 Bytes"; + this._4ByteMenuItem.Click += new System.EventHandler(this._4ByteMenuItem_Click); + // // BigEndianMenuItem // this.BigEndianMenuItem.Name = "BigEndianMenuItem"; @@ -879,5 +916,9 @@ private System.Windows.Forms.ToolStripStatusLabel BotStatusButton; private System.Windows.Forms.ToolStripMenuItem BigEndianMenuItem; private System.Windows.Forms.ToolStripSeparator toolStripSeparator4; + private System.Windows.Forms.ToolStripMenuItem DataSizeMenuItem; + private System.Windows.Forms.ToolStripMenuItem _1ByteMenuItem; + private System.Windows.Forms.ToolStripMenuItem _2ByteMenuItem; + private System.Windows.Forms.ToolStripMenuItem _4ByteMenuItem; } } \ No newline at end of file diff --git a/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs b/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs index 61ea500faf..633a1fbb79 100644 --- a/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs +++ b/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs @@ -52,6 +52,7 @@ namespace BizHawk.Client.EmuHawk private MemoryDomain _currentDomain; private bool _bigEndian; + private int _dataSize; #region Services and Settings @@ -328,6 +329,8 @@ namespace BizHawk.Client.EmuHawk MemoryDomains.Contains(_currentDomain)) { _currentDomain = MemoryDomains.MainMemory; + _bigEndian = _currentDomain.EndianType == MemoryDomain.Endian.Big; + _dataSize = 1; } if (_isBotting) @@ -457,10 +460,32 @@ namespace BizHawk.Client.EmuHawk _bigEndian ^= true; } + private void DataSizeMenuItem_DropDownOpened(object sender, EventArgs e) + { + _1ByteMenuItem.Checked = _dataSize == 1; + _2ByteMenuItem.Checked = _dataSize == 2; + _4ByteMenuItem.Checked = _dataSize == 4; + } + + private void _1ByteMenuItem_Click(object sender, EventArgs e) + { + _dataSize = 1; + } + + private void _2ByteMenuItem_Click(object sender, EventArgs e) + { + _dataSize = 2; + } + + private void _4ByteMenuItem_Click(object sender, EventArgs e) + { + _dataSize = 4; + } + private void TurboWhileBottingMenuItem_Click(object sender, EventArgs e) { Settings.TurboWhenBotting ^= true; - } + } #endregion @@ -536,6 +561,10 @@ namespace BizHawk.Client.EmuHawk public string FromSlot { get; set; } public long Attempts { get; set; } public long Frames { get; set; } + + public string MemoryDomain { get; set; } + public bool BigEndian { get; set; } + public int DataSize { get; set; } } #endregion @@ -584,6 +613,13 @@ namespace BizHawk.Client.EmuHawk Attempts = botData.Attempts; Frames = botData.Frames; + _currentDomain = !string.IsNullOrWhiteSpace(botData.MemoryDomain) + ? MemoryDomains[botData.MemoryDomain] + : MemoryDomains.MainMemory; + + _bigEndian = botData.BigEndian; + _dataSize = botData.DataSize > 0 ? botData.DataSize : 1; + UpdateBestAttempt(); if (_bestBotAttempt != null) @@ -611,7 +647,10 @@ namespace BizHawk.Client.EmuHawk FromSlot = FromSlot, FrameLength = FrameLength, Attempts = Attempts, - Frames = Frames + Frames = Frames, + MemoryDomain = _currentDomain.Name, + BigEndian = _bigEndian, + DataSize = _dataSize }; var json = ConfigService.SaveWithType(data); @@ -668,12 +707,27 @@ namespace BizHawk.Client.EmuHawk private void SetMemoryDomain(string name) { _currentDomain = MemoryDomains[name]; + _bigEndian = MemoryDomains[name].EndianType == MemoryDomain.Endian.Big; } private int GetRamvalue(int addr) { - // TODO: ability to pick byte size/display type/endian - return _currentDomain.PeekByte(addr); + int val; + switch (_dataSize) + { + default: + case 1: + val = _currentDomain.PeekByte(addr); + break; + case 2: + val = _currentDomain.PeekWord(addr, _bigEndian); + break; + case 4: + val = (int)_currentDomain.PeekDWord(addr, _bigEndian); + break; + } + + return val; } private void Update(bool fast)