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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 686 - (hide annotations) (download)
Mon Jun 17 09:31:52 2013 UTC (7 years, 4 months ago) by william
File size: 15190 byte(s)
+ massive move of source files

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

  ViewVC Help
Powered by ViewVC 1.1.22