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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

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 686 using RomCheater.Core;
26 william 628
27     namespace RomCheater.EmuMMAPPlugin
28     {
29 william 654 #region EmuMEMMapDockControl
30 william 628 public partial class EmuMEMMapDockControl : DockContent
31     {
32 william 683 private UserControlPlugin plugin;
33 william 641 private List<DeviceMemoryMap> DeviceMemoryMaps = new List<DeviceMemoryMap>();
34 william 683 public EmuMEMMapDockControl(UserControlPlugin plugin)
35 william 628 {
36 william 683 this.plugin = plugin;
37 william 684 InitPluginFramework();
38 william 628 InitializeComponent();
39 william 838 this.Icon = Core.Properties.Resources.romcheater_icon;
40 william 641 CreateMaps();
41 william 628 }
42 william 684 private void InitPluginFramework()
43     {
44     if (this.plugin == null) { return; }
45 william 686 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 william 689 RaisePluginFrameworkEvents();
49 william 684 }
50 william 689
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 william 686 void plugin_OnPEDataUpdated(PEViewerDataUpdatedEventArgs e)
63 william 684 {
64 william 691 //logger.Warn.WriteLine("plugin_OnPEDataUpdated::has not been implemented!");
65 william 684 }
66 william 686 void plugin_OnSelectedConfigChanged(ConfigChangedEventArgs e)
67 william 684 {
68 william 691 //logger.Warn.WriteLine("plugin_OnSelectedConfigChanged::has not been implemented!");
69 william 684 }
70 william 686 void plugin_OnSelectedProcessChanged(ProcessChangedEventArgs e)
71 william 684 {
72 william 691 //logger.Warn.WriteLine("plugin_OnSelectedProcessChanged::has not been implemented!");
73 william 684 }
74 william 641 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 william 654 map = null; // free memory
124 william 641 }
125     #region NES
126     private DeviceMemoryMap CreateNESMemMap()
127     {
128 william 650 /* http://en.wikibooks.org/wiki/NES_Programming */
129 william 641 const string name = "NES";
130 william 654 DeviceMemoryMap map = new DeviceMemoryMap();
131 william 641 List<IMemMap> maprange = new List<IMemMap>();
132     #region memory maps
133 william 648 //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 william 654
145 william 648 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 william 641 #endregion
156     map = new DeviceMemoryMap(name, maprange);
157     return map;
158     }
159     #endregion
160     #region SNES
161     private DeviceMemoryMap CreateSNESMemMap()
162     {
163 william 650 /* http://www.emulatronia.com/doctec/consolas/snes/SNESMem.txt */
164 william 641 const string name = "SNES";
165     DeviceMemoryMap map = new DeviceMemoryMap();
166     List<IMemMap> maprange = new List<IMemMap>();
167     #region memory maps
168 william 650 //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 william 641 #endregion
173     map = new DeviceMemoryMap(name, maprange);
174     return map;
175     }
176     #endregion
177     #region PS1
178     private DeviceMemoryMap CreatePS1MemMap()
179     {
180 william 650 /* http://rveach.romhack.org/PSXInfo/psx%20hardware%20info.txt */
181 william 641 const string name = "PS1";
182     DeviceMemoryMap map = new DeviceMemoryMap();
183     List<IMemMap> maprange = new List<IMemMap>();
184     #region memory maps
185 william 646 //maprange.Add(new MemMap(string.Format("{0}_test", name), 0, 0));
186 william 644 maprange.Add(new MemMap("Kernel Memory", 0x00000000, 0x0000ffff));
187 william 645 maprange.Add(new MemMap("User Memory", 0x00010000, 0x001FFFFF));
188 william 644 maprange.Add(new MemMap("Parallel Port", 0x1f000000, 0x1f00ffff));
189     maprange.Add(new MemMap("Scratch Pad", 0x1f800000, 0x1f8003ff));
190 william 654 maprange.Add(new MemMap("HW Registers", 0x1f801000, 0x1f802fff));
191 william 650 maprange.Add(new MemMap("BIOS", 0x1FC00000, 0x1FC7FFFF));
192    
193 william 644 maprange.Add(new MemMap("Kernel & User Memory (cached)", 0x80000000, 0x801fffff));
194     maprange.Add(new MemMap("Kernel & User Memory (uncached)", 0xa0000000, 0xa01fffff));
195 william 650
196 william 646 #endregion
197     map = new DeviceMemoryMap(name, maprange);
198 william 641 return map;
199     }
200     #endregion
201     #region PS2
202     private DeviceMemoryMap CreatePS2MemMap()
203     {
204 william 650 /* 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 william 641 const string name = "PS2";
207     DeviceMemoryMap map = new DeviceMemoryMap();
208     List<IMemMap> maprange = new List<IMemMap>();
209     #region memory maps
210 william 642 //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 william 641 #endregion
225     map = new DeviceMemoryMap(name, maprange);
226     return map;
227     }
228     #endregion
229     #region N64
230     private DeviceMemoryMap CreateN64MemMap()
231     {
232 william 651 /* http://n64.icequake.net/doc/n64intro/kantan/step1/1-4.html */
233 william 641 const string name = "N64";
234     DeviceMemoryMap map = new DeviceMemoryMap();
235     List<IMemMap> maprange = new List<IMemMap>();
236     #region memory maps
237 william 651 //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 william 641 #endregion
244     map = new DeviceMemoryMap(name, maprange);
245     return map;
246     }
247     #endregion
248     #region NGC
249     private DeviceMemoryMap CreateNGCMemMap()
250     {
251 william 652 /* http://hitmen.c02.at/files/yagcd/yagcd/chap4.html#sec4 */
252 william 641 const string name = "NGC";
253     DeviceMemoryMap map = new DeviceMemoryMap();
254     List<IMemMap> maprange = new List<IMemMap>();
255     #region memory maps
256 william 652 //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 william 641 #endregion
261     map = new DeviceMemoryMap(name, maprange);
262     return map;
263     }
264     #endregion
265     #region WII
266     private DeviceMemoryMap CreateWIIMemMap()
267     {
268 william 653 /* http://wiibrew.org/wiki/Memory_Map */
269 william 641 const string name = "WII";
270     DeviceMemoryMap map = new DeviceMemoryMap();
271     List<IMemMap> maprange = new List<IMemMap>();
272     #region memory maps
273 william 653 //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 william 641 #endregion
280     map = new DeviceMemoryMap(name, maprange);
281     return map;
282     }
283     #endregion
284 william 628 }
285 william 654 #endregion
286 william 641
287     #region Memory Map Helper Classes
288 william 654 #region IMemMap
289 william 641 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 william 654 #endregion
298     #region IDeviceMemoryMap
299 william 641 internal interface IDeviceMemoryMap
300     {
301     string DeviceName { get; }
302     IDictionary<string, IMemMap> MemoryMap { get; }
303     string ToString();
304     }
305 william 654 #endregion
306     #region MemMap
307 william 641 internal class MemMap : IMemMap
308     {
309     public MemMap() : this(string.Empty, 0, 0) { }
310 william 654 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 william 643 public MemMap(string name, string start, string end, ulong size)
313 william 641 : this(name)
314     {
315     this.MapStart = start;
316     this.MapEnd = end;
317 william 649 ulong _size = size + 1;
318     double t = 1024.0 * 1024.0;
319 william 654 double __size = (double)_size / t;
320 william 649 this.MapSize = string.Format("0x{0}={1:0.000000}MB", _size.ToString("X"), __size);
321 william 641 }
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 william 654 public override string ToString() { return string.Format("[{0}]==>[{1}-{2}] [{3}]", MapName, MapStart, MapEnd, MapSize); }
328 william 641 #endregion
329     }
330 william 654 #endregion
331     #region DeviceMemoryMap
332 william 641 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 william 654 foreach (var map in memorymap) { this.MemoryMap.Add(map.MapName, map); }
340 william 641 }
341     #region IDeviceMemoryMap Members
342     public string DeviceName { get; private set; }
343     public IDictionary<string, IMemMap> MemoryMap { get; private set; }
344 william 654 public override string ToString() { return string.Format("[{0}]==>{1} mapped memory range(s)", DeviceName, MemoryMap.Count); }
345 william 641 #endregion
346     }
347     #endregion
348 william 654 #endregion
349 william 628 }

  ViewVC Help
Powered by ViewVC 1.1.22