/[pcsx2_0.9.7]/branch/debug/0.X/0.9.X/0.9.7/r3795-ramdump/pcsx2/System/IRamProvider.h
ViewVC logotype

Contents of /branch/debug/0.X/0.9.X/0.9.7/r3795-ramdump/pcsx2/System/IRamProvider.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 259 - (show annotations) (download)
Thu Oct 14 09:38:29 2010 UTC (10 years, 1 month ago) by william
File MIME type: text/plain
File size: 6667 byte(s)
Turn on: HAVE_MEMORY_DUMP_TESTING

1 // Class automatically generated by Dev-C++ New Class wizard
2
3 #ifndef IRAMPROVIDER_H
4 #define IRAMPROVIDER_H
5
6 //#define wxUSE_UNICODE 0
7
8 #include <wx/wx.h>
9 #include <fstream>
10 #include <sstream>
11 #include "Common.h"
12
13 #define RAM_ADDRESS_WIDTH 0x10
14 #define RAM_ADDRESS_WIDTH_PADDING 0xf
15
16 #ifndef MAX_VIEWABLE_RAM
17 #define MAX_VIEWABLE_RAM 0x140
18 #endif
19
20 #define PS2_ELF_ENTRYPOINT 0x00100000
21 #define MIN_RAM_ADDRESS PS2_ELF_ENTRYPOINT
22 #define MAX_RAM_ADDRESS Ps2MemSize::Base
23
24 // BEGIN - RAM DUMP CONTROL ENABLE DEFINES
25 static const bool HAVE_MEMORY_DUMP_TESTING = true;
26 inline bool ENABLE_MEMORY_DUMP_CONTROL(bool _default_enable_state_) { if (HAVE_MEMORY_DUMP_TESTING) return true; return _default_enable_state_; }
27 inline bool ENABLE_MEMORY_DUMP_CONTROL() { if (HAVE_MEMORY_DUMP_TESTING) return true; return false; }
28 static const bool HAVE_MEMORY_DUMP = ENABLE_MEMORY_DUMP_CONTROL(true); /* Enable/Disable Memory Dump */
29 static const bool HAVE_MEMORY_PATCH = ENABLE_MEMORY_DUMP_CONTROL(false);/* Enable/Disable Memory Patch */
30 static const bool HAVE_MEMORY_AUTO_FREEZE = ENABLE_MEMORY_DUMP_CONTROL(false);/* Enable/Disable Memory Auto Freeze */
31 static const bool HAVE_MEMORY_MANUAL_FREEZE = ENABLE_MEMORY_DUMP_CONTROL(false); /* Enable/Disable Manual Memory Freezeing */
32 static const bool HAVE_MEMORY_GOTOADDRESS = ENABLE_MEMORY_DUMP_CONTROL(true); /* Enable/Disable Memory Goto Address */
33 static const bool HAVE_MEMORY_VIEW_SCROLL = ENABLE_MEMORY_DUMP_CONTROL(true); /* Enable/Disable Scrolling The Memory View */
34 static const bool HAVE_MEMORY_VIEW_REFRESH = ENABLE_MEMORY_DUMP_CONTROL(true); /* Enable/Disable Memory Refreshing*/
35 // END - RAM DUMP CONTROL ENABLE DEFINES
36
37
38
39 #define HEX_BASE 16
40 #define DuoDEC_BASE 12
41 #define DEC_BASE 10
42 #define OCT_BASE 8
43 #define BIN_BASE 2
44
45 inline void* wxStringToInt(wxString x) {
46 long pLong;
47 x.ToLong(&pLong,DEC_BASE);
48 void *pVoid;
49 memcpy(&pVoid, &pLong, sizeof(pLong));
50 return pVoid;
51 }
52
53
54 inline void* wxStringToHexInt(wxString x) {
55 long pLong;
56 x.ToLong(&pLong,HEX_BASE);
57 void *pVoid;
58 memcpy(&pVoid, &pLong, sizeof(pLong));
59 return pVoid;
60 }
61
62 inline int IntToHex(std::ostringstream& ss) { return strtol(ss.str().c_str(), NULL, HEX_BASE); }
63 inline int IntToHex(int x) { std::ostringstream ss; ss << x; return strtol(ss.str().c_str(), NULL, HEX_BASE); }
64 inline int HexToInt(int x) { std::ostringstream ss; ss << x; return strtol(ss.str().c_str(), NULL, DEC_BASE); }
65 inline int HexToInt(std::ostringstream& ss) { return strtol(ss.str().c_str(), NULL, DEC_BASE); }
66
67
68 inline bool NumberToByteArray(const wxChar* data, unsigned char*& patch_data, int& size)
69 {
70 //wxMessageBox( wxString::Format(wxString::FromAscii("NumberToByteArray() data: %s"),data),wxString::FromAscii("Debug Message"),wxICON_EXCLAMATION );
71
72 bool conversion_success = false;
73 char data_to_patch[256];
74 size = 0;
75 patch_data = new unsigned char[size];
76
77
78 if ( wcslen(data) == 1 || wcslen(data) == 3 || wcslen(data) == 5 || wcslen(data) == 7 ) { sprintf(data_to_patch,"0%s", data); size = wcslen(data) + 1; }
79 else if ( wcslen(data) == 2 || wcslen(data) == 4 || wcslen(data) == 6 || wcslen(data) == 8 ) { sprintf(data_to_patch,"%s", data); size = wcslen(data); }
80 else { sprintf(data_to_patch,"%s", ""); size = 0; }
81
82 if (size <= 0 ) return false;
83
84 //wxMessageBox( wxString::Format(wxString::FromAscii("NumberToByteArray() data_to_patch: %s"),data_to_patch),wxString::FromAscii("Debug Message"),wxICON_EXCLAMATION );
85
86 patch_data = new unsigned char[size/2]; for(int i=0;i<size/2;i++){patch_data[i]=0;}
87
88 for (int i=0;i<size;i+=2)
89 {
90 char fint = (char)data_to_patch[i]; // first number of byte
91 char sint = (char)data_to_patch[i+1]; // seccond number of byte
92
93 std::ostringstream ss;
94 ss << fint << sint;
95
96 int nint = IntToHex(ss);
97
98 //wxMessageBox( wxString::Format(wxString::FromAscii("NumberToByteArray() ss->strtol: %x"),nint),wxString::FromAscii("Debug Message"),wxICON_EXCLAMATION );
99
100 switch(i)
101 {
102 case 2:
103 case 4:
104 case 6:
105 patch_data[i/2] = nint;
106 break;
107 default:
108 patch_data[i] = nint;
109 break;
110 }
111
112 }
113 // fix size
114 size = size/2;
115 conversion_success = true;
116 return conversion_success;
117 }
118 inline bool CreateByteArrayFromIntegral(const wxChar* patch_value, int& patch_length, unsigned char*& patch_data) {
119 bool patch_valid = false;
120 patch_valid = NumberToByteArray(patch_value,patch_data,patch_length);
121 if (!patch_valid)
122 {
123 wxMessageBox( wxString::FromAscii("Patch data's length is invalid...please check your data."),wxString::FromAscii("Patch Data is Invalid."),wxICON_ERROR );
124 }
125 return patch_valid;
126 }
127
128 /*
129 * No description
130 */
131 class IRamProvider
132 {
133 public:
134 // class constructor
135 IRamProvider();
136 //IRamProvider(int SizeOfRamInBytes);
137 IRamProvider(unsigned char* Ram, int SizeOfRamInBytes);
138 // class destructor
139 virtual ~IRamProvider();
140
141 unsigned int MinimumRamAddress();
142 unsigned int MaxmumRamAddress();
143
144 // Gets the size of the ram
145 virtual unsigned char* GetRam();
146 virtual void SetRam(unsigned char* Ram, int SizeOfRamInBytes, unsigned int BASE_ADDR);
147 virtual bool RefreshRam();
148 virtual bool ClearRam();
149 virtual int GetRamSize();
150 virtual void SetRamSize(int size);
151 virtual void FreezeRam();
152 virtual void UnFreezeRam();
153 virtual bool IsRamFrozen();
154
155 virtual bool IsRamAvailable();
156 virtual bool UpdateRamLocation(unsigned int address, wxString data);
157
158 virtual wxString GetRamDumpFilename();
159 virtual void SetRamDumpFilename(wxString filename);
160
161 virtual bool DumpRam(const char* filename);
162 virtual bool DumpRam(unsigned int start_address, unsigned int end_address, const char* filename);
163 virtual bool DumpRam();
164 virtual bool DumpRam(unsigned int start_address, unsigned int end_address);
165
166 unsigned int BASE_ADDR;
167 private:
168 int _RamSize;
169 bool _FreezeRam;
170 bool _UpdateRamLocation(unsigned int address, unsigned char* data, int size);
171 wxString RAM_DUMP_FILE;
172 bool _IsRamAvailable;
173 protected:
174 unsigned char* _Ram;
175 virtual void InitializeProvider();
176 void MakeRamAvailable();
177 void MakeRamUnAvailable();
178 };
179
180 #endif // IRAMPROVIDER_H

  ViewVC Help
Powered by ViewVC 1.1.22