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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 689 - (show annotations) (download)
Mon Jun 17 10:02:53 2013 UTC (7 years, 5 months ago) by william
File size: 15576 byte(s)
+ add support for plugin framework events to be fired, the first time
* Process change events would not fire, until another process was selected (ignoreing the already selected process at startup)
** same goes for the other events that rely on a process being passed in

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

  ViewVC Help
Powered by ViewVC 1.1.22