/[RomCheater]/trunk/RomCheater.EmuMMAPPlugin/EmuMEMMapDockControl.cs
ViewVC logotype

Annotation of /trunk/RomCheater.EmuMMAPPlugin/EmuMEMMapDockControl.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 684 - (hide annotations) (download)
Mon Jun 17 08:52:54 2013 UTC (7 years, 4 months ago) by william
File size: 15373 byte(s)

1 william 684 #region Logging Defines
2     // include this any class or method that required logging, and comment-out what is not needed
3    
4     #region Enabled logging levels
5     #define LOGGING_ENABLE_INFO
6     #define LOGGING_ENABLE_WARN
7     #define LOGGING_ENABLE_DEBUG
8     //#define LOGGING_ENABLE_VERBOSEDEBUG
9     #define LOGGING_ENABLE_ERROR
10     #define LOGGING_ENABLE_VERBOSEERROR
11     #define LOGGING_ENABLE_PROFILER
12     #endregion
13     #endregion
14     using System;
15 william 628 using System.Collections.Generic;
16     using System.ComponentModel;
17     using System.Data;
18     using System.Drawing;
19     using System.Linq;
20     using System.Text;
21     using System.Windows.Forms;
22     using WeifenLuo.WinFormsUI.Docking;
23 william 683 using RomCheater.PluginFramework.Core;
24 william 684 using RomCheater.Logging;
25 william 628
26     namespace RomCheater.EmuMMAPPlugin
27     {
28 william 654 #region EmuMEMMapDockControl
29 william 628 public partial class EmuMEMMapDockControl : DockContent
30     {
31 william 683 private UserControlPlugin plugin;
32 william 641 private List<DeviceMemoryMap> DeviceMemoryMaps = new List<DeviceMemoryMap>();
33 william 683 public EmuMEMMapDockControl(UserControlPlugin plugin)
34 william 628 {
35 william 683 this.plugin = plugin;
36 william 684 InitPluginFramework();
37 william 628 InitializeComponent();
38 william 641 CreateMaps();
39 william 628 }
40 william 684 private void InitPluginFramework()
41     {
42     if (this.plugin == null) { return; }
43     this.plugin.OnSelectedProcessChanged += new PluginFramework.Events.BaseEventHandler<PluginFramework.Events.ProcessChangedEventArgs>(plugin_OnSelectedProcessChanged);
44     this.plugin.OnSelectedConfigChanged += new PluginFramework.Events.BaseEventHandler<PluginFramework.Events.ConfigChangedEventArgs>(plugin_OnSelectedConfigChanged);
45     this.plugin.OnPEDataUpdated += new PluginFramework.Events.BaseEventHandler<PluginFramework.Events.PEViewerDataUpdatedEventArgs>(plugin_OnPEDataUpdated);
46     }
47     void plugin_OnPEDataUpdated(PluginFramework.Events.PEViewerDataUpdatedEventArgs e)
48     {
49     logger.Warn.WriteLine("plugin_OnPEDataUpdated::has not been implemented!");
50     }
51     void plugin_OnSelectedConfigChanged(PluginFramework.Events.ConfigChangedEventArgs e)
52     {
53     logger.Warn.WriteLine("plugin_OnSelectedConfigChanged::has not been implemented!");
54     }
55     void plugin_OnSelectedProcessChanged(PluginFramework.Events.ProcessChangedEventArgs e)
56     {
57     logger.Warn.WriteLine("plugin_OnSelectedProcessChanged::has not been implemented!");
58     }
59 william 641 private void EmuMEMMapDockControl_Shown(object sender, EventArgs e)
60     {
61     txtDeviceMap.Clear();
62     txtDeviceMap.AppendText(string.Format("Device Memory Map(s):{0}", System.Environment.NewLine));
63     foreach (var k in DeviceMemoryMaps)
64     {
65     string devicename = k.DeviceName;
66     txtDeviceMap.AppendText(string.Format("{0}:{1}", devicename, System.Environment.NewLine));
67     var map = k.MemoryMap;
68     foreach (var mapped in map)
69     {
70     var mapped_name = mapped.Key;
71     var mapped_data = mapped.Value;
72     var t = mapped_data.ToString();
73     txtDeviceMap.AppendText(string.Format("\t{0}{1}", t, System.Environment.NewLine));
74     }
75     }
76     }
77     private void CreateMaps()
78     {
79     var map = new DeviceMemoryMap();
80     #region NES
81     map = CreateNESMemMap();
82     DeviceMemoryMaps.Add(map);
83     #endregion
84     #region SNES
85     map = CreateSNESMemMap();
86     DeviceMemoryMaps.Add(map);
87     #endregion
88     #region PS1
89     map = CreatePS1MemMap();
90     DeviceMemoryMaps.Add(map);
91     #endregion
92     #region PS2
93     map = CreatePS2MemMap();
94     DeviceMemoryMaps.Add(map);
95     #endregion
96     #region N64
97     map = CreateN64MemMap();
98     DeviceMemoryMaps.Add(map);
99     #endregion
100     #region NGC
101     map = CreateNGCMemMap();
102     DeviceMemoryMaps.Add(map);
103     #endregion
104     #region WII
105     map = CreateWIIMemMap();
106     DeviceMemoryMaps.Add(map);
107     #endregion
108 william 654 map = null; // free memory
109 william 641 }
110     #region NES
111     private DeviceMemoryMap CreateNESMemMap()
112     {
113 william 650 /* http://en.wikibooks.org/wiki/NES_Programming */
114 william 641 const string name = "NES";
115 william 654 DeviceMemoryMap map = new DeviceMemoryMap();
116 william 641 List<IMemMap> maprange = new List<IMemMap>();
117     #region memory maps
118 william 648 //maprange.Add(new MemMap(string.Format("{0}_test", name), 0, 0));
119     maprange.Add(new MemMap("Zero Page", 0x0000, 0x00FF));
120     maprange.Add(new MemMap("Stack", 0x0100, 0x01FF));
121     maprange.Add(new MemMap("Ram", 0x0200, 0x07FF));
122    
123     // mirror
124     maprange.Add(new MemMap("ZeroPage/Stack/Ram Mirror1", 0x0800, 0x0FFF));
125     // mirror
126     maprange.Add(new MemMap("ZeroPage/Stack/Ram Mirror2", 0x1000, 0x17FF));
127     // mirror
128     maprange.Add(new MemMap("ZeroPage/Stack/Ram Mirror3", 0x1800, 0x1FFF));
129 william 654
130 william 648 maprange.Add(new MemMap("IO Reg1", 0x2000, 0x2007));
131     maprange.Add(new MemMap("IO reg1 mirror - repeated", 0x2000, 0x3FFF));
132     maprange.Add(new MemMap("IO Reg2", 0x4000, 0x401F));
133     maprange.Add(new MemMap("Expansion ROM", 0x4020, 0x5FFF));
134     maprange.Add(new MemMap("SRAM", 0x6000, 0x7FFF));
135     maprange.Add(new MemMap("PRG-ROM", 0x8000, 0xFFFF));
136    
137     maprange.Add(new MemMap("Address of NMI Interrupt handler", 0xFFFA, 0xFFFB));
138     maprange.Add(new MemMap("Address of Power on reset handler", 0xFFFC, 0xFFFD));
139     maprange.Add(new MemMap("Address of BRK handler routine", 0xFFFE, 0xFFFF));
140 william 641 #endregion
141     map = new DeviceMemoryMap(name, maprange);
142     return map;
143     }
144     #endregion
145     #region SNES
146     private DeviceMemoryMap CreateSNESMemMap()
147     {
148 william 650 /* http://www.emulatronia.com/doctec/consolas/snes/SNESMem.txt */
149 william 641 const string name = "SNES";
150     DeviceMemoryMap map = new DeviceMemoryMap();
151     List<IMemMap> maprange = new List<IMemMap>();
152     #region memory maps
153 william 650 //maprange.Add(new MemMap(string.Format("{0}_test", name), 0, 0));
154     maprange.Add(new MemMap("LowRAM", 0x0000, 0x1fff));
155     maprange.Add(new MemMap("HighRAM", 0x2000, 0x7fff));
156     maprange.Add(new MemMap("Expanded RAM", 0x8000, 0xffff));
157 william 641 #endregion
158     map = new DeviceMemoryMap(name, maprange);
159     return map;
160     }
161     #endregion
162     #region PS1
163     private DeviceMemoryMap CreatePS1MemMap()
164     {
165 william 650 /* http://rveach.romhack.org/PSXInfo/psx%20hardware%20info.txt */
166 william 641 const string name = "PS1";
167     DeviceMemoryMap map = new DeviceMemoryMap();
168     List<IMemMap> maprange = new List<IMemMap>();
169     #region memory maps
170 william 646 //maprange.Add(new MemMap(string.Format("{0}_test", name), 0, 0));
171 william 644 maprange.Add(new MemMap("Kernel Memory", 0x00000000, 0x0000ffff));
172 william 645 maprange.Add(new MemMap("User Memory", 0x00010000, 0x001FFFFF));
173 william 644 maprange.Add(new MemMap("Parallel Port", 0x1f000000, 0x1f00ffff));
174     maprange.Add(new MemMap("Scratch Pad", 0x1f800000, 0x1f8003ff));
175 william 654 maprange.Add(new MemMap("HW Registers", 0x1f801000, 0x1f802fff));
176 william 650 maprange.Add(new MemMap("BIOS", 0x1FC00000, 0x1FC7FFFF));
177    
178 william 644 maprange.Add(new MemMap("Kernel & User Memory (cached)", 0x80000000, 0x801fffff));
179     maprange.Add(new MemMap("Kernel & User Memory (uncached)", 0xa0000000, 0xa01fffff));
180 william 650
181 william 646 #endregion
182     map = new DeviceMemoryMap(name, maprange);
183 william 641 return map;
184     }
185     #endregion
186     #region PS2
187     private DeviceMemoryMap CreatePS2MemMap()
188     {
189 william 650 /* http://psx-scene.com/forums/attachments/f19/17285d1280158606-ps2-memory-hardware-mapped-registers-layout-ps2-memory-hardware-mapped-registers-layout.txt */
190     /* http://psx-scene.com/forums/f19/ps2-memory-hardware-mapped-registers-layout-64760/ */
191 william 641 const string name = "PS2";
192     DeviceMemoryMap map = new DeviceMemoryMap();
193     List<IMemMap> maprange = new List<IMemMap>();
194     #region memory maps
195 william 642 //maprange.Add(new MemMap(string.Format("{0}_test", name), 0, 0));
196     maprange.Add(new MemMap("EE Kernel", 0x80000000, 0x800FFFFF));
197     maprange.Add(new MemMap("EE RAM (Cached)", 0x00100000, 0x01FFFFFF));
198     maprange.Add(new MemMap("EE RAM (Uncached)", 0x20100000, 0x21FFFFFF));
199     maprange.Add(new MemMap("EE RAM (Uncached&accelerated)", 0x30100000, 0x31FFFFFF));
200     maprange.Add(new MemMap("EE Registers (uncached)", 0x10000000, 0x11FFFFFF));
201     maprange.Add(new MemMap("GS Registers (uncached)", 0x12000000, 0x13FFFFFF));
202     maprange.Add(new MemMap("Boot ROM0 (uncached)", 0x1FC00000, 0x1FFFFFFF));
203     maprange.Add(new MemMap("Boot ROM09 (cached)", 0x9FC00000, 0x9FFFFFFF));
204     maprange.Add(new MemMap("Boot ROM0b (uncached)", 0xBFC00000, 0xBFFFFFFF));
205     maprange.Add(new MemMap("Boot ROM1", 0xBE000000, 0xBE040000));
206     maprange.Add(new MemMap("Boot ROM2", 0xBE400000, 0xBE440000));
207     maprange.Add(new MemMap("IOP RAM", 0xBC000000, 0xBC1FFFFF));
208     maprange.Add(new MemMap("Scratch Pad", 0x70000000, 0x70003FFF));
209 william 641 #endregion
210     map = new DeviceMemoryMap(name, maprange);
211     return map;
212     }
213     #endregion
214     #region N64
215     private DeviceMemoryMap CreateN64MemMap()
216     {
217 william 651 /* http://n64.icequake.net/doc/n64intro/kantan/step1/1-4.html */
218 william 641 const string name = "N64";
219     DeviceMemoryMap map = new DeviceMemoryMap();
220     List<IMemMap> maprange = new List<IMemMap>();
221     #region memory maps
222 william 651 //maprange.Add(new MemMap(string.Format("{0}_test", name), 0, 0));
223     maprange.Add(new MemMap("KUSEG [TLB Map]", 0x00000000, 0x7fffffff));
224     maprange.Add(new MemMap("KSEG0 [Ram cached]", 0x80000000, 0x9fffffff));
225     maprange.Add(new MemMap("KSEG1 [Ram uncached]", 0xa0000000, 0xbfffffff));
226     maprange.Add(new MemMap("KSSEG [TLB Map]", 0xc0000000, 0xdfffffff));
227     maprange.Add(new MemMap("KSEG3 [TLB Map]", 0xe0000000, 0xffffffff));
228 william 641 #endregion
229     map = new DeviceMemoryMap(name, maprange);
230     return map;
231     }
232     #endregion
233     #region NGC
234     private DeviceMemoryMap CreateNGCMemMap()
235     {
236 william 652 /* http://hitmen.c02.at/files/yagcd/yagcd/chap4.html#sec4 */
237 william 641 const string name = "NGC";
238     DeviceMemoryMap map = new DeviceMemoryMap();
239     List<IMemMap> maprange = new List<IMemMap>();
240     #region memory maps
241 william 652 //maprange.Add(new MemMap(string.Format("{0}_test", name), 0, 0));
242     maprange.Add(new MemMap("Physical RAM", 0x00000000, 0x017fffff));
243     maprange.Add(new MemMap("Logical RAM [cached]", 0x80000000, 0x817fffff));
244     maprange.Add(new MemMap("Logical RAM [uncached]", 0xC0000000, 0xC17fffff));
245 william 641 #endregion
246     map = new DeviceMemoryMap(name, maprange);
247     return map;
248     }
249     #endregion
250     #region WII
251     private DeviceMemoryMap CreateWIIMemMap()
252     {
253 william 653 /* http://wiibrew.org/wiki/Memory_Map */
254 william 641 const string name = "WII";
255     DeviceMemoryMap map = new DeviceMemoryMap();
256     List<IMemMap> maprange = new List<IMemMap>();
257     #region memory maps
258 william 653 //maprange.Add(new MemMap(string.Format("{0}_test", name), 0, 0));
259     maprange.Add(new MemMap("MEM1 [cached]", 0x80000000, 0x817FFFFF));
260     maprange.Add(new MemMap("MEM1 [uncached]", 0xC0000000, 0xC17FFFFF));
261     maprange.Add(new MemMap("MEM2 [cached]", 0x90000000, 0x93FFFFFF));
262     maprange.Add(new MemMap("MEM2 [uncached]", 0xD0000000, 0xD3FFFFFF));
263     maprange.Add(new MemMap("Hollywood/Starlet Registers?", 0xCD000000, 0xCD008000));
264 william 641 #endregion
265     map = new DeviceMemoryMap(name, maprange);
266     return map;
267     }
268     #endregion
269 william 628 }
270 william 654 #endregion
271 william 641
272     #region Memory Map Helper Classes
273 william 654 #region IMemMap
274 william 641 internal interface IMemMap
275     {
276     string MapName { get; }
277     string MapStart { get; }
278     string MapEnd { get; }
279     string MapSize { get; }
280     string ToString();
281     }
282 william 654 #endregion
283     #region IDeviceMemoryMap
284 william 641 internal interface IDeviceMemoryMap
285     {
286     string DeviceName { get; }
287     IDictionary<string, IMemMap> MemoryMap { get; }
288     string ToString();
289     }
290 william 654 #endregion
291     #region MemMap
292 william 641 internal class MemMap : IMemMap
293     {
294     public MemMap() : this(string.Empty, 0, 0) { }
295 william 654 public MemMap(string name) { this.MapName = name; }
296     public MemMap(string name, ulong start, ulong end) : this(name, string.Format("0x{0}", start.ToString("X")), string.Format("0x{0}", end.ToString("X")), end - start) { }
297 william 643 public MemMap(string name, string start, string end, ulong size)
298 william 641 : this(name)
299     {
300     this.MapStart = start;
301     this.MapEnd = end;
302 william 649 ulong _size = size + 1;
303     double t = 1024.0 * 1024.0;
304 william 654 double __size = (double)_size / t;
305 william 649 this.MapSize = string.Format("0x{0}={1:0.000000}MB", _size.ToString("X"), __size);
306 william 641 }
307     #region IMappedMemRange Members
308     public string MapName { get; private set; }
309     public string MapStart { get; private set; }
310     public string MapEnd { get; private set; }
311     public string MapSize { get; private set; }
312 william 654 public override string ToString() { return string.Format("[{0}]==>[{1}-{2}] [{3}]", MapName, MapStart, MapEnd, MapSize); }
313 william 641 #endregion
314     }
315 william 654 #endregion
316     #region DeviceMemoryMap
317 william 641 internal class DeviceMemoryMap : IDeviceMemoryMap
318     {
319     public DeviceMemoryMap() { this.DeviceName = string.Empty; this.MemoryMap = this.MemoryMap = new Dictionary<string, IMemMap>(); }
320     public DeviceMemoryMap(string device, List<IMemMap> memorymap)
321     {
322     this.DeviceName = device;
323     this.MemoryMap = new Dictionary<string, IMemMap>();
324 william 654 foreach (var map in memorymap) { this.MemoryMap.Add(map.MapName, map); }
325 william 641 }
326     #region IDeviceMemoryMap Members
327     public string DeviceName { get; private set; }
328     public IDictionary<string, IMemMap> MemoryMap { get; private set; }
329 william 654 public override string ToString() { return string.Format("[{0}]==>{1} mapped memory range(s)", DeviceName, MemoryMap.Count); }
330 william 641 #endregion
331     }
332     #endregion
333 william 654 #endregion
334 william 628 }

  ViewVC Help
Powered by ViewVC 1.1.22