/[RomCheater]/trunk/RomCheater/Docking/UI/UIMemoryViewer.cs
ViewVC logotype

Diff of /trunk/RomCheater/Docking/UI/UIMemoryViewer.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/RomCheater/Docking/UI/UIMemoryViewer.cs	2012/05/31 07:13:43	198
+++ trunk/RomCheater/Docking/UI/UIMemoryViewer.cs	2012/05/31 08:10:25	201
@@ -13,7 +13,7 @@
 
 namespace RomCheater.Docking.UI
 {
-    public partial class UIMemoryViewer : UserControl, IProcessConfig, IAcceptsPlugin<IConfigPlugin>, IAcceptsMemoryRange
+    public partial class UIMemoryViewer : UserControl, IProcessConfig, IAcceptsPlugin<IConfigPlugin>//, IAcceptsMemoryRange
     {
         public UIMemoryViewer()
         {
@@ -29,7 +29,7 @@
             txtData.UseFixedBytesPerLine = true;
             txtData.StringViewVisible = true;
             ramScroll.Minimum = (int)MemoryStart;
-            for (uint i = MemoryStart; i < (MemoryStart + MemorySize); i += max_address_width) { ramScroll.Maximum += (int)max_address_width; }
+            for (uint i = MemoryStart; i < (MemoryStart + max_ram_view); i += max_address_width) { ramScroll.Maximum += (int)max_address_width; }
             ramScroll.Value = ramScroll.Minimum;
             this.CanChangeUpdateInterval = false;
 
@@ -42,11 +42,25 @@
             this.AcceptedPlugin = null; this.AcceptedProcess = null;
         }
         #region IProcessConfig Members
-        public Process AcceptedProcess { get; set; }
+        private Process _AcceptedProcess;
+        public Process AcceptedProcess
+        {
+            get { return _AcceptedProcess; }
+            set
+            {
+                _AcceptedProcess = value;
+                update_timer.Enabled = (value != null);
+                UpdateEnabled = update_timer.Enabled;
+            }
+        }
         #endregion
         #region IAcceptsPlugin<IConfigPlugin> Members
         public IConfigPlugin AcceptedPlugin { get; set; }
         #endregion
+        #region IAcceptsMemoryRange members
+        private uint MemoryStart { get { return 0; } }
+        private uint MemorySize { get { return int.MaxValue; } }
+        #endregion
         public void GotoTop() { this.CURRENT_TOP_ADDR = 0; }
         public void GotoBottom() { uint size = MemorySize; this.CURRENT_TOP_ADDR = (uint)((size - 1) - max_ram_view); }
         public void GotoAddress(uint addr) { this.CURRENT_TOP_ADDR = (uint)addr & 0xFFFFFFF0; }
@@ -83,11 +97,6 @@
         static uint small_scroll_change = max_address_width * 1; // scrolls one line (when you clikc the up or down arrows)
         static uint medium_scroll_change = max_ram_view / 2; // scrolls half a page
         static uint large_scroll_change = max_ram_view; // scrolls a full page
-
-        #region IAcceptsMemoryRange members
-        public uint MemoryStart { get; set; }
-        public uint MemorySize { get; set; }
-        #endregion
         private uint _CURRENT_TOP_ADDR;
         uint CURRENT_TOP_ADDR
         {
@@ -166,14 +175,14 @@
                 reader.ReadProcess = this.AcceptedProcess;
                 reader.OpenProcess();
                 int bytesReadSize;
-                byte[] data = reader.ReadProcessMemory(MemoryStart, MemorySize, out bytesReadSize);
+                byte[] data = reader.ReadProcessMemory(CURRENT_TOP_ADDR, max_ram_view, out bytesReadSize);
                 //this.Logger.LogDebugMessage(string.Format("GetMemory() -> Memory Size: {0}0x{2:X8}{1}", "{", "}", data.Length));
                 return data;
             }
             catch (Exception ex)
             {
                 logger.Error.WriteLine("{0}.GetMemory():{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString());
-                byte[] data = new byte[MemorySize];
+                byte[] data = new byte[max_ram_view];
                 for (int i = 0; i < data.Length; i++) { data[i] = 0x0; }
                 return data;
             }
@@ -187,46 +196,48 @@
                 if (AcceptedPlugin == null) { return; }
 
                 byte[] data = GetMemory();
-
-                List<byte> ByteData = new List<byte>((int)(address + (max_ram_view - 0)));
-
                 try
                 {
-                    AddressList = "";
-                    AsciiData = "";
+                    RamData = data;
 
-                    // create a byte array holding only the bytes that we need
-                    for (uint i = address; i < (address + (max_ram_view + 1)); i += 1) { ByteData.Add(data[i]); }
 
+                    AddressList = "";
+                    AsciiData = "";
                     // write the addreses out
                     for (uint i = address; i < (address + max_ram_view); i += max_address_width)
                     {
                         AddressList = AddressList + string.Format("{0:X8}:\n", i);
                     }
-                    // write out the ascii data
+                    //// write out the ascii data
                     StringBuilder builder = new StringBuilder();
                     for (uint i = address; i < (address + max_ram_view); i += max_address_width)
                     {
-                        for (uint j = 0; j < max_address_width; j++)
+                        try
                         {
-                            uint current_addr = i + j;
-                            if (current_addr >= MemorySize) break;
-                            byte ascii_value_raw = data[current_addr];
-                            char ascii_value = (char)data[current_addr];
-                            if (ascii_value_raw >= 0x20 && ascii_value_raw <= 0x7e)
-                            {
-                                builder.Append(ascii_value.ToString());
-                            }
-                            else
+                            for (uint j = 0; j < max_address_width; j++)
                             {
-                                builder.Append(".");
+                                uint current_addr = i + j;
+                                if (current_addr >= MemorySize) break;
+                                byte ascii_value_raw = data[j];
+                                char ascii_value = (char)data[j];
+                                if (ascii_value_raw >= 0x20 && ascii_value_raw <= 0x7e)
+                                {
+                                    builder.Append(ascii_value.ToString());
+                                }
+                                else
+                                {
+                                    builder.Append(".");
+                                }
                             }
+                            builder.AppendLine();
+                        }
+                        catch (Exception ex)
+                        {
+                            logger.Error.WriteLine("{0}.UpdateMemroyView().BuildingAsciiString:{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString());
+                            return;
                         }
-                        builder.AppendLine();
                     }
                     AsciiData = builder.ToString();
-                    // write out the bytes
-                    RamData = ByteData.ToArray();
 
 
                 }
@@ -294,7 +305,7 @@
             uint ORIGINAL_ADDR = this.CURRENT_TOP_ADDR;
 
             ////if (e.Type == ScrollEventType.EndScroll) return;
-            uint size = MemorySize;
+            uint size = max_ram_view;
 
             bool haveModifier = false;
             switch (e.Modifiers)
@@ -338,7 +349,7 @@
             }
             if (this.CURRENT_TOP_ADDR < MemoryStart) this.CURRENT_TOP_ADDR = MemoryStart;
             //if (this.CURRENT_TOP_ADDR >= VTLB_VADDR_SIZE) this.CURRENT_TOP_ADDR = (size - 1) - max_ram_view;
-            if (this.CURRENT_TOP_ADDR + max_ram_view >= MemoryStart) this.CURRENT_TOP_ADDR = (size - 1) - max_ram_view;
+            if (this.CURRENT_TOP_ADDR + max_ram_view >= MemorySize) this.CURRENT_TOP_ADDR = (size - 1);
 
             //this.UpdateEnabled = reenable;
         }

 

  ViewVC Help
Powered by ViewVC 1.1.22