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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 652 - (hide annotations) (download)
Sun Jun 9 00:30:55 2013 UTC (7 years, 4 months ago) by william
File size: 12976 byte(s)
+ add NGC (gamecube) memory map

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     public partial class EmuMEMMapDockControl : DockContent
14     {
15 william 641 private List<DeviceMemoryMap> DeviceMemoryMaps = new List<DeviceMemoryMap>();
16 william 628 public EmuMEMMapDockControl()
17     {
18     InitializeComponent();
19 william 641 CreateMaps();
20 william 628 }
21 william 641 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 william 650 /* http://en.wikibooks.org/wiki/NES_Programming */
78 william 641 const string name = "NES";
79     DeviceMemoryMap map = new DeviceMemoryMap();
80     List<IMemMap> maprange = new List<IMemMap>();
81     #region memory maps
82 william 648 //maprange.Add(new MemMap(string.Format("{0}_test", name), 0, 0));
83     maprange.Add(new MemMap("Zero Page", 0x0000, 0x00FF));
84     maprange.Add(new MemMap("Stack", 0x0100, 0x01FF));
85     maprange.Add(new MemMap("Ram", 0x0200, 0x07FF));
86    
87     // mirror
88     maprange.Add(new MemMap("ZeroPage/Stack/Ram Mirror1", 0x0800, 0x0FFF));
89     // mirror
90     maprange.Add(new MemMap("ZeroPage/Stack/Ram Mirror2", 0x1000, 0x17FF));
91     // mirror
92     maprange.Add(new MemMap("ZeroPage/Stack/Ram Mirror3", 0x1800, 0x1FFF));
93    
94     maprange.Add(new MemMap("IO Reg1", 0x2000, 0x2007));
95     maprange.Add(new MemMap("IO reg1 mirror - repeated", 0x2000, 0x3FFF));
96     maprange.Add(new MemMap("IO Reg2", 0x4000, 0x401F));
97     maprange.Add(new MemMap("Expansion ROM", 0x4020, 0x5FFF));
98     maprange.Add(new MemMap("SRAM", 0x6000, 0x7FFF));
99     maprange.Add(new MemMap("PRG-ROM", 0x8000, 0xFFFF));
100    
101     maprange.Add(new MemMap("Address of NMI Interrupt handler", 0xFFFA, 0xFFFB));
102     maprange.Add(new MemMap("Address of Power on reset handler", 0xFFFC, 0xFFFD));
103     maprange.Add(new MemMap("Address of BRK handler routine", 0xFFFE, 0xFFFF));
104 william 641 #endregion
105     map = new DeviceMemoryMap(name, maprange);
106     return map;
107     }
108     #endregion
109     #region SNES
110     private DeviceMemoryMap CreateSNESMemMap()
111     {
112 william 650 /* http://www.emulatronia.com/doctec/consolas/snes/SNESMem.txt */
113 william 641 const string name = "SNES";
114     DeviceMemoryMap map = new DeviceMemoryMap();
115     List<IMemMap> maprange = new List<IMemMap>();
116     #region memory maps
117 william 650 //maprange.Add(new MemMap(string.Format("{0}_test", name), 0, 0));
118     maprange.Add(new MemMap("LowRAM", 0x0000, 0x1fff));
119     maprange.Add(new MemMap("HighRAM", 0x2000, 0x7fff));
120     maprange.Add(new MemMap("Expanded RAM", 0x8000, 0xffff));
121 william 641 #endregion
122     map = new DeviceMemoryMap(name, maprange);
123     return map;
124     }
125     #endregion
126     #region PS1
127     private DeviceMemoryMap CreatePS1MemMap()
128     {
129 william 650 /* http://rveach.romhack.org/PSXInfo/psx%20hardware%20info.txt */
130 william 641 const string name = "PS1";
131     DeviceMemoryMap map = new DeviceMemoryMap();
132     List<IMemMap> maprange = new List<IMemMap>();
133     #region memory maps
134 william 646 //maprange.Add(new MemMap(string.Format("{0}_test", name), 0, 0));
135 william 644 maprange.Add(new MemMap("Kernel Memory", 0x00000000, 0x0000ffff));
136 william 645 maprange.Add(new MemMap("User Memory", 0x00010000, 0x001FFFFF));
137 william 644 maprange.Add(new MemMap("Parallel Port", 0x1f000000, 0x1f00ffff));
138     maprange.Add(new MemMap("Scratch Pad", 0x1f800000, 0x1f8003ff));
139 william 650 maprange.Add(new MemMap("HW Registers", 0x1f801000, 0x1f802fff));
140     maprange.Add(new MemMap("BIOS", 0x1FC00000, 0x1FC7FFFF));
141    
142 william 644 maprange.Add(new MemMap("Kernel & User Memory (cached)", 0x80000000, 0x801fffff));
143     maprange.Add(new MemMap("Kernel & User Memory (uncached)", 0xa0000000, 0xa01fffff));
144 william 650
145 william 646 #endregion
146     map = new DeviceMemoryMap(name, maprange);
147 william 641 return map;
148     }
149     #endregion
150     #region PS2
151     private DeviceMemoryMap CreatePS2MemMap()
152     {
153 william 650 /* http://psx-scene.com/forums/attachments/f19/17285d1280158606-ps2-memory-hardware-mapped-registers-layout-ps2-memory-hardware-mapped-registers-layout.txt */
154     /* http://psx-scene.com/forums/f19/ps2-memory-hardware-mapped-registers-layout-64760/ */
155 william 641 const string name = "PS2";
156     DeviceMemoryMap map = new DeviceMemoryMap();
157     List<IMemMap> maprange = new List<IMemMap>();
158     #region memory maps
159 william 642 //maprange.Add(new MemMap(string.Format("{0}_test", name), 0, 0));
160     maprange.Add(new MemMap("EE Kernel", 0x80000000, 0x800FFFFF));
161     maprange.Add(new MemMap("EE RAM (Cached)", 0x00100000, 0x01FFFFFF));
162     maprange.Add(new MemMap("EE RAM (Uncached)", 0x20100000, 0x21FFFFFF));
163     maprange.Add(new MemMap("EE RAM (Uncached&accelerated)", 0x30100000, 0x31FFFFFF));
164     maprange.Add(new MemMap("EE Registers (uncached)", 0x10000000, 0x11FFFFFF));
165     maprange.Add(new MemMap("GS Registers (uncached)", 0x12000000, 0x13FFFFFF));
166     maprange.Add(new MemMap("Boot ROM0 (uncached)", 0x1FC00000, 0x1FFFFFFF));
167     maprange.Add(new MemMap("Boot ROM09 (cached)", 0x9FC00000, 0x9FFFFFFF));
168     maprange.Add(new MemMap("Boot ROM0b (uncached)", 0xBFC00000, 0xBFFFFFFF));
169     maprange.Add(new MemMap("Boot ROM1", 0xBE000000, 0xBE040000));
170     maprange.Add(new MemMap("Boot ROM2", 0xBE400000, 0xBE440000));
171     maprange.Add(new MemMap("IOP RAM", 0xBC000000, 0xBC1FFFFF));
172     maprange.Add(new MemMap("Scratch Pad", 0x70000000, 0x70003FFF));
173 william 641 #endregion
174     map = new DeviceMemoryMap(name, maprange);
175     return map;
176     }
177     #endregion
178     #region N64
179     private DeviceMemoryMap CreateN64MemMap()
180     {
181 william 651 /* http://n64.icequake.net/doc/n64intro/kantan/step1/1-4.html */
182 william 641 const string name = "N64";
183     DeviceMemoryMap map = new DeviceMemoryMap();
184     List<IMemMap> maprange = new List<IMemMap>();
185     #region memory maps
186 william 651 //maprange.Add(new MemMap(string.Format("{0}_test", name), 0, 0));
187     maprange.Add(new MemMap("KUSEG [TLB Map]", 0x00000000, 0x7fffffff));
188     maprange.Add(new MemMap("KSEG0 [Ram cached]", 0x80000000, 0x9fffffff));
189     maprange.Add(new MemMap("KSEG1 [Ram uncached]", 0xa0000000, 0xbfffffff));
190     maprange.Add(new MemMap("KSSEG [TLB Map]", 0xc0000000, 0xdfffffff));
191     maprange.Add(new MemMap("KSEG3 [TLB Map]", 0xe0000000, 0xffffffff));
192 william 641 #endregion
193     map = new DeviceMemoryMap(name, maprange);
194     return map;
195     }
196     #endregion
197     #region NGC
198     private DeviceMemoryMap CreateNGCMemMap()
199     {
200 william 652 /* http://hitmen.c02.at/files/yagcd/yagcd/chap4.html#sec4 */
201 william 641 const string name = "NGC";
202     DeviceMemoryMap map = new DeviceMemoryMap();
203     List<IMemMap> maprange = new List<IMemMap>();
204     #region memory maps
205 william 652 //maprange.Add(new MemMap(string.Format("{0}_test", name), 0, 0));
206     maprange.Add(new MemMap("Physical RAM", 0x00000000, 0x017fffff));
207     maprange.Add(new MemMap("Logical RAM [cached]", 0x80000000, 0x817fffff));
208     maprange.Add(new MemMap("Logical RAM [uncached]", 0xC0000000, 0xC17fffff));
209 william 641 #endregion
210     map = new DeviceMemoryMap(name, maprange);
211     return map;
212     }
213     #endregion
214     #region WII
215     private DeviceMemoryMap CreateWIIMemMap()
216     {
217     const string name = "WII";
218     DeviceMemoryMap map = new DeviceMemoryMap();
219     List<IMemMap> maprange = new List<IMemMap>();
220     #region memory maps
221     maprange.Add(new MemMap(string.Format("{0}_test", name), 0, 0));
222     #endregion
223     map = new DeviceMemoryMap(name, maprange);
224     return map;
225     }
226     #endregion
227 william 628 }
228 william 641
229     #region Memory Map Helper Classes
230     internal interface IMemMap
231     {
232     string MapName { get; }
233     string MapStart { get; }
234     string MapEnd { get; }
235     string MapSize { get; }
236     string ToString();
237     }
238     internal interface IDeviceMemoryMap
239     {
240     string DeviceName { get; }
241     IDictionary<string, IMemMap> MemoryMap { get; }
242     string ToString();
243     }
244    
245     internal class MemMap : IMemMap
246     {
247     public MemMap() : this(string.Empty, 0, 0) { }
248     public MemMap(string name)
249     {
250     this.MapName = name;
251     }
252 william 643 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) { }
253     public MemMap(string name, string start, string end, ulong size)
254 william 641 : this(name)
255     {
256     this.MapStart = start;
257     this.MapEnd = end;
258 william 649
259     ulong _size = size + 1;
260     double t = 1024.0 * 1024.0;
261     double __size = (double)_size/t;
262     this.MapSize = string.Format("0x{0}={1:0.000000}MB", _size.ToString("X"), __size);
263 william 641 }
264     #region IMappedMemRange Members
265     public string MapName { get; private set; }
266     public string MapStart { get; private set; }
267     public string MapEnd { get; private set; }
268     public string MapSize { get; private set; }
269     public override string ToString()
270     {
271     return string.Format("[{0}]==>[{1}-{2}] [{3}]", MapName, MapStart, MapEnd, MapSize);
272     }
273     #endregion
274     }
275    
276     internal class DeviceMemoryMap : IDeviceMemoryMap
277     {
278     public DeviceMemoryMap() { this.DeviceName = string.Empty; this.MemoryMap = this.MemoryMap = new Dictionary<string, IMemMap>(); }
279     public DeviceMemoryMap(string device, List<IMemMap> memorymap)
280     {
281     this.DeviceName = device;
282     this.MemoryMap = new Dictionary<string, IMemMap>();
283    
284     foreach (var map in memorymap)
285     {
286     this.MemoryMap.Add(map.MapName, map);
287     }
288    
289     }
290    
291     #region IDeviceMemoryMap Members
292     public string DeviceName { get; private set; }
293     public IDictionary<string, IMemMap> MemoryMap { get; private set; }
294     public override string ToString()
295     {
296     return string.Format("[{0}]==>{1} mapped memory range(s)", DeviceName, MemoryMap.Count);
297     }
298     #endregion
299     }
300    
301     #endregion
302 william 628 }
303 william 641

  ViewVC Help
Powered by ViewVC 1.1.22