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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 654 - (hide annotations) (download)
Sun Jun 9 00:40:20 2013 UTC (7 years, 4 months ago) by william
File size: 13494 byte(s)
+ cleanup code

1 william 628 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 william 654 #region EmuMEMMapDockControl
14 william 628 public partial class EmuMEMMapDockControl : DockContent
15     {
16 william 641 private List<DeviceMemoryMap> DeviceMemoryMaps = new List<DeviceMemoryMap>();
17 william 628 public EmuMEMMapDockControl()
18     {
19     InitializeComponent();
20 william 641 CreateMaps();
21 william 628 }
22 william 641 private void EmuMEMMapDockControl_Shown(object sender, EventArgs e)
23     {
24     txtDeviceMap.Clear();
25     txtDeviceMap.AppendText(string.Format("Device Memory Map(s):{0}", System.Environment.NewLine));
26     foreach (var k in DeviceMemoryMaps)
27     {
28     string devicename = k.DeviceName;
29     txtDeviceMap.AppendText(string.Format("{0}:{1}", devicename, System.Environment.NewLine));
30     var map = k.MemoryMap;
31     foreach (var mapped in map)
32     {
33     var mapped_name = mapped.Key;
34     var mapped_data = mapped.Value;
35     var t = mapped_data.ToString();
36     txtDeviceMap.AppendText(string.Format("\t{0}{1}", t, System.Environment.NewLine));
37     }
38     }
39     }
40     private void CreateMaps()
41     {
42     var map = new DeviceMemoryMap();
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 william 654 map = null; // free memory
72 william 641 }
73     #region NES
74     private DeviceMemoryMap CreateNESMemMap()
75     {
76 william 650 /* http://en.wikibooks.org/wiki/NES_Programming */
77 william 641 const string name = "NES";
78 william 654 DeviceMemoryMap map = new DeviceMemoryMap();
79 william 641 List<IMemMap> maprange = new List<IMemMap>();
80     #region memory maps
81 william 648 //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 william 654
93 william 648 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 william 641 #endregion
104     map = new DeviceMemoryMap(name, maprange);
105     return map;
106     }
107     #endregion
108     #region SNES
109     private DeviceMemoryMap CreateSNESMemMap()
110     {
111 william 650 /* http://www.emulatronia.com/doctec/consolas/snes/SNESMem.txt */
112 william 641 const string name = "SNES";
113     DeviceMemoryMap map = new DeviceMemoryMap();
114     List<IMemMap> maprange = new List<IMemMap>();
115     #region memory maps
116 william 650 //maprange.Add(new MemMap(string.Format("{0}_test", name), 0, 0));
117     maprange.Add(new MemMap("LowRAM", 0x0000, 0x1fff));
118     maprange.Add(new MemMap("HighRAM", 0x2000, 0x7fff));
119     maprange.Add(new MemMap("Expanded RAM", 0x8000, 0xffff));
120 william 641 #endregion
121     map = new DeviceMemoryMap(name, maprange);
122     return map;
123     }
124     #endregion
125     #region PS1
126     private DeviceMemoryMap CreatePS1MemMap()
127     {
128 william 650 /* http://rveach.romhack.org/PSXInfo/psx%20hardware%20info.txt */
129 william 641 const string name = "PS1";
130     DeviceMemoryMap map = new DeviceMemoryMap();
131     List<IMemMap> maprange = new List<IMemMap>();
132     #region memory maps
133 william 646 //maprange.Add(new MemMap(string.Format("{0}_test", name), 0, 0));
134 william 644 maprange.Add(new MemMap("Kernel Memory", 0x00000000, 0x0000ffff));
135 william 645 maprange.Add(new MemMap("User Memory", 0x00010000, 0x001FFFFF));
136 william 644 maprange.Add(new MemMap("Parallel Port", 0x1f000000, 0x1f00ffff));
137     maprange.Add(new MemMap("Scratch Pad", 0x1f800000, 0x1f8003ff));
138 william 654 maprange.Add(new MemMap("HW Registers", 0x1f801000, 0x1f802fff));
139 william 650 maprange.Add(new MemMap("BIOS", 0x1FC00000, 0x1FC7FFFF));
140    
141 william 644 maprange.Add(new MemMap("Kernel & User Memory (cached)", 0x80000000, 0x801fffff));
142     maprange.Add(new MemMap("Kernel & User Memory (uncached)", 0xa0000000, 0xa01fffff));
143 william 650
144 william 646 #endregion
145     map = new DeviceMemoryMap(name, maprange);
146 william 641 return map;
147     }
148     #endregion
149     #region PS2
150     private DeviceMemoryMap CreatePS2MemMap()
151     {
152 william 650 /* http://psx-scene.com/forums/attachments/f19/17285d1280158606-ps2-memory-hardware-mapped-registers-layout-ps2-memory-hardware-mapped-registers-layout.txt */
153     /* http://psx-scene.com/forums/f19/ps2-memory-hardware-mapped-registers-layout-64760/ */
154 william 641 const string name = "PS2";
155     DeviceMemoryMap map = new DeviceMemoryMap();
156     List<IMemMap> maprange = new List<IMemMap>();
157     #region memory maps
158 william 642 //maprange.Add(new MemMap(string.Format("{0}_test", name), 0, 0));
159     maprange.Add(new MemMap("EE Kernel", 0x80000000, 0x800FFFFF));
160     maprange.Add(new MemMap("EE RAM (Cached)", 0x00100000, 0x01FFFFFF));
161     maprange.Add(new MemMap("EE RAM (Uncached)", 0x20100000, 0x21FFFFFF));
162     maprange.Add(new MemMap("EE RAM (Uncached&accelerated)", 0x30100000, 0x31FFFFFF));
163     maprange.Add(new MemMap("EE Registers (uncached)", 0x10000000, 0x11FFFFFF));
164     maprange.Add(new MemMap("GS Registers (uncached)", 0x12000000, 0x13FFFFFF));
165     maprange.Add(new MemMap("Boot ROM0 (uncached)", 0x1FC00000, 0x1FFFFFFF));
166     maprange.Add(new MemMap("Boot ROM09 (cached)", 0x9FC00000, 0x9FFFFFFF));
167     maprange.Add(new MemMap("Boot ROM0b (uncached)", 0xBFC00000, 0xBFFFFFFF));
168     maprange.Add(new MemMap("Boot ROM1", 0xBE000000, 0xBE040000));
169     maprange.Add(new MemMap("Boot ROM2", 0xBE400000, 0xBE440000));
170     maprange.Add(new MemMap("IOP RAM", 0xBC000000, 0xBC1FFFFF));
171     maprange.Add(new MemMap("Scratch Pad", 0x70000000, 0x70003FFF));
172 william 641 #endregion
173     map = new DeviceMemoryMap(name, maprange);
174     return map;
175     }
176     #endregion
177     #region N64
178     private DeviceMemoryMap CreateN64MemMap()
179     {
180 william 651 /* http://n64.icequake.net/doc/n64intro/kantan/step1/1-4.html */
181 william 641 const string name = "N64";
182     DeviceMemoryMap map = new DeviceMemoryMap();
183     List<IMemMap> maprange = new List<IMemMap>();
184     #region memory maps
185 william 651 //maprange.Add(new MemMap(string.Format("{0}_test", name), 0, 0));
186     maprange.Add(new MemMap("KUSEG [TLB Map]", 0x00000000, 0x7fffffff));
187     maprange.Add(new MemMap("KSEG0 [Ram cached]", 0x80000000, 0x9fffffff));
188     maprange.Add(new MemMap("KSEG1 [Ram uncached]", 0xa0000000, 0xbfffffff));
189     maprange.Add(new MemMap("KSSEG [TLB Map]", 0xc0000000, 0xdfffffff));
190     maprange.Add(new MemMap("KSEG3 [TLB Map]", 0xe0000000, 0xffffffff));
191 william 641 #endregion
192     map = new DeviceMemoryMap(name, maprange);
193     return map;
194     }
195     #endregion
196     #region NGC
197     private DeviceMemoryMap CreateNGCMemMap()
198     {
199 william 652 /* http://hitmen.c02.at/files/yagcd/yagcd/chap4.html#sec4 */
200 william 641 const string name = "NGC";
201     DeviceMemoryMap map = new DeviceMemoryMap();
202     List<IMemMap> maprange = new List<IMemMap>();
203     #region memory maps
204 william 652 //maprange.Add(new MemMap(string.Format("{0}_test", name), 0, 0));
205     maprange.Add(new MemMap("Physical RAM", 0x00000000, 0x017fffff));
206     maprange.Add(new MemMap("Logical RAM [cached]", 0x80000000, 0x817fffff));
207     maprange.Add(new MemMap("Logical RAM [uncached]", 0xC0000000, 0xC17fffff));
208 william 641 #endregion
209     map = new DeviceMemoryMap(name, maprange);
210     return map;
211     }
212     #endregion
213     #region WII
214     private DeviceMemoryMap CreateWIIMemMap()
215     {
216 william 653 /* http://wiibrew.org/wiki/Memory_Map */
217 william 641 const string name = "WII";
218     DeviceMemoryMap map = new DeviceMemoryMap();
219     List<IMemMap> maprange = new List<IMemMap>();
220     #region memory maps
221 william 653 //maprange.Add(new MemMap(string.Format("{0}_test", name), 0, 0));
222     maprange.Add(new MemMap("MEM1 [cached]", 0x80000000, 0x817FFFFF));
223     maprange.Add(new MemMap("MEM1 [uncached]", 0xC0000000, 0xC17FFFFF));
224     maprange.Add(new MemMap("MEM2 [cached]", 0x90000000, 0x93FFFFFF));
225     maprange.Add(new MemMap("MEM2 [uncached]", 0xD0000000, 0xD3FFFFFF));
226     maprange.Add(new MemMap("Hollywood/Starlet Registers?", 0xCD000000, 0xCD008000));
227 william 641 #endregion
228     map = new DeviceMemoryMap(name, maprange);
229     return map;
230     }
231     #endregion
232 william 628 }
233 william 654 #endregion
234 william 641
235     #region Memory Map Helper Classes
236 william 654 #region IMemMap
237 william 641 internal interface IMemMap
238     {
239     string MapName { get; }
240     string MapStart { get; }
241     string MapEnd { get; }
242     string MapSize { get; }
243     string ToString();
244     }
245 william 654 #endregion
246     #region IDeviceMemoryMap
247 william 641 internal interface IDeviceMemoryMap
248     {
249     string DeviceName { get; }
250     IDictionary<string, IMemMap> MemoryMap { get; }
251     string ToString();
252     }
253 william 654 #endregion
254     #region MemMap
255 william 641 internal class MemMap : IMemMap
256     {
257     public MemMap() : this(string.Empty, 0, 0) { }
258 william 654 public MemMap(string name) { this.MapName = name; }
259     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) { }
260 william 643 public MemMap(string name, string start, string end, ulong size)
261 william 641 : this(name)
262     {
263     this.MapStart = start;
264     this.MapEnd = end;
265 william 649 ulong _size = size + 1;
266     double t = 1024.0 * 1024.0;
267 william 654 double __size = (double)_size / t;
268 william 649 this.MapSize = string.Format("0x{0}={1:0.000000}MB", _size.ToString("X"), __size);
269 william 641 }
270     #region IMappedMemRange Members
271     public string MapName { get; private set; }
272     public string MapStart { get; private set; }
273     public string MapEnd { get; private set; }
274     public string MapSize { get; private set; }
275 william 654 public override string ToString() { return string.Format("[{0}]==>[{1}-{2}] [{3}]", MapName, MapStart, MapEnd, MapSize); }
276 william 641 #endregion
277     }
278 william 654 #endregion
279     #region DeviceMemoryMap
280 william 641 internal class DeviceMemoryMap : IDeviceMemoryMap
281     {
282     public DeviceMemoryMap() { this.DeviceName = string.Empty; this.MemoryMap = this.MemoryMap = new Dictionary<string, IMemMap>(); }
283     public DeviceMemoryMap(string device, List<IMemMap> memorymap)
284     {
285     this.DeviceName = device;
286     this.MemoryMap = new Dictionary<string, IMemMap>();
287 william 654 foreach (var map in memorymap) { this.MemoryMap.Add(map.MapName, map); }
288 william 641 }
289     #region IDeviceMemoryMap Members
290     public string DeviceName { get; private set; }
291     public IDictionary<string, IMemMap> MemoryMap { get; private set; }
292 william 654 public override string ToString() { return string.Format("[{0}]==>{1} mapped memory range(s)", DeviceName, MemoryMap.Count); }
293 william 641 #endregion
294     }
295     #endregion
296 william 654 #endregion
297 william 628 }

  ViewVC Help
Powered by ViewVC 1.1.22