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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 649 - (show annotations) (download)
Sat Jun 8 22:45:25 2013 UTC (6 years, 8 months ago) by william
File size: 11431 byte(s)
+ fix memory map size being off by 1

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
11 namespace RomCheater.EmuMMAPPlugin
12 {
13 public partial class EmuMEMMapDockControl : DockContent
14 {
15 private List<DeviceMemoryMap> DeviceMemoryMaps = new List<DeviceMemoryMap>();
16 public EmuMEMMapDockControl()
17 {
18 InitializeComponent();
19 CreateMaps();
20 }
21 private void EmuMEMMapDockControl_Shown(object sender, EventArgs e)
22 {
23 txtDeviceMap.Clear();
24 txtDeviceMap.AppendText(string.Format("Device Memory Map(s):{0}", System.Environment.NewLine));
25 foreach (var k in DeviceMemoryMaps)
26 {
27 string devicename = k.DeviceName;
28 txtDeviceMap.AppendText(string.Format("{0}:{1}", devicename, System.Environment.NewLine));
29 var map = k.MemoryMap;
30 foreach (var mapped in map)
31 {
32 var mapped_name = mapped.Key;
33 var mapped_data = mapped.Value;
34 var t = mapped_data.ToString();
35 txtDeviceMap.AppendText(string.Format("\t{0}{1}", t, System.Environment.NewLine));
36 }
37 }
38 }
39 private void CreateMaps()
40 {
41 var map = new DeviceMemoryMap();
42
43 #region NES
44 map = CreateNESMemMap();
45 DeviceMemoryMaps.Add(map);
46 #endregion
47 #region SNES
48 map = CreateSNESMemMap();
49 DeviceMemoryMaps.Add(map);
50 #endregion
51 #region PS1
52 map = CreatePS1MemMap();
53 DeviceMemoryMaps.Add(map);
54 #endregion
55 #region PS2
56 map = CreatePS2MemMap();
57 DeviceMemoryMaps.Add(map);
58 #endregion
59 #region N64
60 map = CreateN64MemMap();
61 DeviceMemoryMaps.Add(map);
62 #endregion
63 #region NGC
64 map = CreateNGCMemMap();
65 DeviceMemoryMaps.Add(map);
66 #endregion
67 #region WII
68 map = CreateWIIMemMap();
69 DeviceMemoryMaps.Add(map);
70 #endregion
71 map = null;
72 }
73
74 #region NES
75 private DeviceMemoryMap CreateNESMemMap()
76 {
77 const string name = "NES";
78 DeviceMemoryMap map = new DeviceMemoryMap();
79 List<IMemMap> maprange = new List<IMemMap>();
80 #region memory maps
81 //maprange.Add(new MemMap(string.Format("{0}_test", name), 0, 0));
82 maprange.Add(new MemMap("Zero Page", 0x0000, 0x00FF));
83 maprange.Add(new MemMap("Stack", 0x0100, 0x01FF));
84 maprange.Add(new MemMap("Ram", 0x0200, 0x07FF));
85
86 // mirror
87 maprange.Add(new MemMap("ZeroPage/Stack/Ram Mirror1", 0x0800, 0x0FFF));
88 // mirror
89 maprange.Add(new MemMap("ZeroPage/Stack/Ram Mirror2", 0x1000, 0x17FF));
90 // mirror
91 maprange.Add(new MemMap("ZeroPage/Stack/Ram Mirror3", 0x1800, 0x1FFF));
92
93 maprange.Add(new MemMap("IO Reg1", 0x2000, 0x2007));
94 maprange.Add(new MemMap("IO reg1 mirror - repeated", 0x2000, 0x3FFF));
95 maprange.Add(new MemMap("IO Reg2", 0x4000, 0x401F));
96 maprange.Add(new MemMap("Expansion ROM", 0x4020, 0x5FFF));
97 maprange.Add(new MemMap("SRAM", 0x6000, 0x7FFF));
98 maprange.Add(new MemMap("PRG-ROM", 0x8000, 0xFFFF));
99
100 maprange.Add(new MemMap("Address of NMI Interrupt handler", 0xFFFA, 0xFFFB));
101 maprange.Add(new MemMap("Address of Power on reset handler", 0xFFFC, 0xFFFD));
102 maprange.Add(new MemMap("Address of BRK handler routine", 0xFFFE, 0xFFFF));
103 #endregion
104 map = new DeviceMemoryMap(name, maprange);
105 return map;
106 }
107 #endregion
108 #region SNES
109 private DeviceMemoryMap CreateSNESMemMap()
110 {
111 const string name = "SNES";
112 DeviceMemoryMap map = new DeviceMemoryMap();
113 List<IMemMap> maprange = new List<IMemMap>();
114 #region memory maps
115 maprange.Add(new MemMap(string.Format("{0}_test", name), 0, 0));
116 #endregion
117 map = new DeviceMemoryMap(name, maprange);
118 return map;
119 }
120 #endregion
121 #region PS1
122 private DeviceMemoryMap CreatePS1MemMap()
123 {
124 const string name = "PS1";
125 DeviceMemoryMap map = new DeviceMemoryMap();
126 List<IMemMap> maprange = new List<IMemMap>();
127 #region memory maps
128 //maprange.Add(new MemMap(string.Format("{0}_test", name), 0, 0));
129 maprange.Add(new MemMap("Kernel Memory", 0x00000000, 0x0000ffff));
130 maprange.Add(new MemMap("User Memory", 0x00010000, 0x001FFFFF));
131 maprange.Add(new MemMap("Parallel Port", 0x1f000000, 0x1f00ffff));
132 maprange.Add(new MemMap("Scratch Pad", 0x1f800000, 0x1f8003ff));
133 maprange.Add(new MemMap("HW Registers", 0x1f801000, 0x1f802fff));
134 maprange.Add(new MemMap("Kernel & User Memory (cached)", 0x80000000, 0x801fffff));
135 maprange.Add(new MemMap("Kernel & User Memory (uncached)", 0xa0000000, 0xa01fffff));
136 maprange.Add(new MemMap("BIOS", 0x1FC00000, 0x1FC7FFFF));
137 #endregion
138 map = new DeviceMemoryMap(name, maprange);
139 return map;
140 }
141 #endregion
142 #region PS2
143 private DeviceMemoryMap CreatePS2MemMap()
144 {
145 const string name = "PS2";
146 DeviceMemoryMap map = new DeviceMemoryMap();
147 List<IMemMap> maprange = new List<IMemMap>();
148 #region memory maps
149 //maprange.Add(new MemMap(string.Format("{0}_test", name), 0, 0));
150 maprange.Add(new MemMap("EE Kernel", 0x80000000, 0x800FFFFF));
151 maprange.Add(new MemMap("EE RAM (Cached)", 0x00100000, 0x01FFFFFF));
152 maprange.Add(new MemMap("EE RAM (Uncached)", 0x20100000, 0x21FFFFFF));
153 maprange.Add(new MemMap("EE RAM (Uncached&accelerated)", 0x30100000, 0x31FFFFFF));
154 maprange.Add(new MemMap("EE Registers (uncached)", 0x10000000, 0x11FFFFFF));
155 maprange.Add(new MemMap("GS Registers (uncached)", 0x12000000, 0x13FFFFFF));
156 maprange.Add(new MemMap("Boot ROM0 (uncached)", 0x1FC00000, 0x1FFFFFFF));
157 maprange.Add(new MemMap("Boot ROM09 (cached)", 0x9FC00000, 0x9FFFFFFF));
158 maprange.Add(new MemMap("Boot ROM0b (uncached)", 0xBFC00000, 0xBFFFFFFF));
159 maprange.Add(new MemMap("Boot ROM1", 0xBE000000, 0xBE040000));
160 maprange.Add(new MemMap("Boot ROM2", 0xBE400000, 0xBE440000));
161 maprange.Add(new MemMap("IOP RAM", 0xBC000000, 0xBC1FFFFF));
162 maprange.Add(new MemMap("Scratch Pad", 0x70000000, 0x70003FFF));
163 #endregion
164 map = new DeviceMemoryMap(name, maprange);
165 return map;
166 }
167 #endregion
168 #region N64
169 private DeviceMemoryMap CreateN64MemMap()
170 {
171 const string name = "N64";
172 DeviceMemoryMap map = new DeviceMemoryMap();
173 List<IMemMap> maprange = new List<IMemMap>();
174 #region memory maps
175 maprange.Add(new MemMap(string.Format("{0}_test", name), 0, 0));
176 #endregion
177 map = new DeviceMemoryMap(name, maprange);
178 return map;
179 }
180 #endregion
181 #region NGC
182 private DeviceMemoryMap CreateNGCMemMap()
183 {
184 const string name = "NGC";
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 #endregion
190 map = new DeviceMemoryMap(name, maprange);
191 return map;
192 }
193 #endregion
194 #region WII
195 private DeviceMemoryMap CreateWIIMemMap()
196 {
197 const string name = "WII";
198 DeviceMemoryMap map = new DeviceMemoryMap();
199 List<IMemMap> maprange = new List<IMemMap>();
200 #region memory maps
201 maprange.Add(new MemMap(string.Format("{0}_test", name), 0, 0));
202 #endregion
203 map = new DeviceMemoryMap(name, maprange);
204 return map;
205 }
206 #endregion
207 }
208
209 #region Memory Map Helper Classes
210 internal interface IMemMap
211 {
212 string MapName { get; }
213 string MapStart { get; }
214 string MapEnd { get; }
215 string MapSize { get; }
216 string ToString();
217 }
218 internal interface IDeviceMemoryMap
219 {
220 string DeviceName { get; }
221 IDictionary<string, IMemMap> MemoryMap { get; }
222 string ToString();
223 }
224
225 internal class MemMap : IMemMap
226 {
227 public MemMap() : this(string.Empty, 0, 0) { }
228 public MemMap(string name)
229 {
230 this.MapName = name;
231 }
232 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) { }
233 public MemMap(string name, string start, string end, ulong size)
234 : this(name)
235 {
236 this.MapStart = start;
237 this.MapEnd = end;
238
239 ulong _size = size + 1;
240 double t = 1024.0 * 1024.0;
241 double __size = (double)_size/t;
242 this.MapSize = string.Format("0x{0}={1:0.000000}MB", _size.ToString("X"), __size);
243 }
244 #region IMappedMemRange Members
245 public string MapName { get; private set; }
246 public string MapStart { get; private set; }
247 public string MapEnd { get; private set; }
248 public string MapSize { get; private set; }
249 public override string ToString()
250 {
251 return string.Format("[{0}]==>[{1}-{2}] [{3}]", MapName, MapStart, MapEnd, MapSize);
252 }
253 #endregion
254 }
255
256 internal class DeviceMemoryMap : IDeviceMemoryMap
257 {
258 public DeviceMemoryMap() { this.DeviceName = string.Empty; this.MemoryMap = this.MemoryMap = new Dictionary<string, IMemMap>(); }
259 public DeviceMemoryMap(string device, List<IMemMap> memorymap)
260 {
261 this.DeviceName = device;
262 this.MemoryMap = new Dictionary<string, IMemMap>();
263
264 foreach (var map in memorymap)
265 {
266 this.MemoryMap.Add(map.MapName, map);
267 }
268
269 }
270
271 #region IDeviceMemoryMap Members
272 public string DeviceName { get; private set; }
273 public IDictionary<string, IMemMap> MemoryMap { get; private set; }
274 public override string ToString()
275 {
276 return string.Format("[{0}]==>{1} mapped memory range(s)", DeviceName, MemoryMap.Count);
277 }
278 #endregion
279 }
280
281 #endregion
282 }
283

  ViewVC Help
Powered by ViewVC 1.1.22