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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 683 - (show annotations) (download)
Mon Jun 17 08:33:06 2013 UTC (7 years, 3 months ago) by william
File size: 13636 byte(s)

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

  ViewVC Help
Powered by ViewVC 1.1.22