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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 838 - (show annotations) (download)
Tue Sep 16 00:57:18 2014 UTC (6 years ago) by william
File size: 15650 byte(s)
+ add an icon resource

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

  ViewVC Help
Powered by ViewVC 1.1.22