/[pcsx2_0.9.7]/branch/debug/0.X/0.9.X/0.9.7/r3795-ramdump/pcsx2/gui/Dialogs/wxRamViewDialog.cpp
ViewVC logotype

Contents of /branch/debug/0.X/0.9.X/0.9.7/r3795-ramdump/pcsx2/gui/Dialogs/wxRamViewDialog.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 255 - (show annotations) (download)
Thu Sep 30 07:23:18 2010 UTC (10 years, 2 months ago) by william
File size: 23599 byte(s)
attempt to implement memory patching -- memWrite32 seems to fail .... don't know why ....
1 ///-----------------------------------------------------------------
2 ///
3 /// @file wxRamDumpDialog.cpp
4 /// @author neoh4x0r
5 /// Created: 9/21/2010 4:00:05 AM
6 /// @section DESCRIPTION
7 /// wxRamDumpDialog class implementation
8 ///
9 ///------------------------------------------------------------------
10
11
12 #include "PrecompiledHeader.h"
13
14 #define SIMULATED_RAM_SIZE 0x1ff
15 #define DEFAULT_RAM_DUMP_FILE "dump.raw"
16
17 #include "ConfigurationDialog.h"
18 #include "System.h"
19 #include "wxRamViewDialog.h"
20 #include <wx/wx.h>
21 #include <wx/dialog.h>
22 using namespace Dialogs;
23
24 namespace Dialogs {
25 //Do not add custom headers
26 //wxDev-C++ designer will remove them
27 ////Header Include Start
28 ////Header Include End
29
30
31 //----------------------------------------------------------------------------
32 // wxRamDumpDialog
33 //----------------------------------------------------------------------------
34 //Add Custom Events only in the appropriate block.
35 //Code added in other places will be removed by wxDev-C++
36 ////Event Table Start
37 BEGIN_EVENT_TABLE(wxRamViewDialog,wxDialog)
38 ////Manual Code Start
39 ////Manual Code End
40
41 EVT_CLOSE(wxRamViewDialog::OnClose)
42 EVT_PAINT(wxRamViewDialog::wxRamViewDialogPaint)
43 EVT_TIMER(ID_RAMREFRESHTIMER,wxRamViewDialog::RamRefreshTimerTimer)
44 EVT_CHECKBOX(ID_CHKDUMPALL,wxRamViewDialog::CHKDUMPALLClick)
45 EVT_BUTTON(ID_BTNSETDUMPFILE,wxRamViewDialog::BTNSETDUMPFILEClick)
46 EVT_BUTTON(ID_BTNRAWDUMP,wxRamViewDialog::BTNRAWDUMPClick)
47 EVT_BUTTON(ID_BTNGOTOADDRESS,wxRamViewDialog::BtnGotoAddressClick)
48
49 EVT_COMMAND_SCROLL_LINEUP(ID_RAM_SCROLL,wxRamViewDialog::RAM_SCROLLScrollLineUp)
50 EVT_COMMAND_SCROLL_LINEDOWN(ID_RAM_SCROLL,wxRamViewDialog::RAM_SCROLLScrollLineDown)
51 EVT_COMMAND_SCROLL_PAGEUP(ID_RAM_SCROLL,wxRamViewDialog::RAM_SCROLLScrollPageUp)
52 EVT_COMMAND_SCROLL_PAGEDOWN(ID_RAM_SCROLL,wxRamViewDialog::RAM_SCROLLScrollPageDown)
53 EVT_CHECKBOX(ID_CHKFREEZERAM,wxRamViewDialog::ChkFreezeRamClick)
54 EVT_BUTTON(ID_BTNPATCHADDR,wxRamViewDialog::BTNPATCHADDRClick)
55 EVT_BUTTON(ID_BTNCLOSE,wxRamViewDialog::BTNCLOSEClick)
56 END_EVENT_TABLE()
57 ////Event Table End
58
59 Dialogs::wxRamViewDialog::wxRamViewDialog(wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &position, const wxSize& size, long style)
60 : wxDialog(parent, id, title, position, size, style)
61 {
62 NeedToUpdateMemoryView = false;
63 HaveExecutedFirstReadRam = false;
64 IsCurrentlyReadingRam = false;
65 CURRENT_TOP_ADDR = cpuRegs.pc;
66 CreateGUIControls();
67
68
69
70 __RAM__PROVIDER__ = new PS2RamProvider(MAX_VIEWABLE_RAM);
71 __RAM__PROVIDER__->SetRamDumpFilename(wxString::FromAscii(DEFAULT_RAM_DUMP_FILE));
72
73 char addr[255];
74 sprintf(addr,"%08x",CURRENT_TOP_ADDR);
75 this->TXTCURRENTADDR->SetValue(wxString::FromAscii(addr));
76
77 RamRefreshTimer->Start(RAM_REFRESH_INTERVAL);
78 }
79
80 Dialogs::wxRamViewDialog::~wxRamViewDialog()
81 {
82 }
83
84 void Dialogs::wxRamViewDialog::CreateGUIControls()
85 {
86
87 //Do not add custom code between
88 //GUI Items Creation Start and GUI Items Creation End.
89 //wxDev-C++ designer will remove them.
90 //Add the custom code before or after the blocks
91 ////GUI Items Creation Start
92 SetTitle(wxRamViewDialog::GetDialogName());
93 SetIcon(wxNullIcon);
94 SetSize(8,8,770,587);
95 Center();
96
97 RamRefreshTimer = new wxTimer();
98 RamRefreshTimer->SetOwner(this, ID_RAMREFRESHTIMER);
99
100 DUMPFILECHOOSER = new wxFileDialog(this, wxT("Please Choose a file to dump to"), wxT(""), wxT("dump.raw"), wxT("*.raw"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxFD_CHANGE_DIR);
101
102 CHKDUMPALL = new wxCheckBox(this, ID_CHKDUMPALL, wxT("Dump All?"), wxPoint(491, 428), wxSize(105, 17), 0, wxDefaultValidator, wxT("CHKDUMPALL"));
103 CHKDUMPALL->SetFont(wxFont(12, wxSWISS, wxNORMAL, wxNORMAL, false, wxT("Courier")));
104
105 BTNSETDUMPFILE = new wxButton(this, ID_BTNSETDUMPFILE, wxT("..."), wxPoint(695, 479), wxSize(39, 23), wxBU_TOP | wxBU_EXACTFIT, wxDefaultValidator, wxT("BTNSETDUMPFILE"));
106 BTNSETDUMPFILE->SetFont(wxFont(12, wxSWISS, wxNORMAL, wxNORMAL, false, wxT("Courier")));
107
108 TXTDUMPFILENAME = new wxTextCtrl(this, ID_TXTDUMPFILENAME, wxT("dump.raw"), wxPoint(391, 479), wxSize(298, 19), 0, wxDefaultValidator, wxT("TXTDUMPFILENAME"));
109 TXTDUMPFILENAME->SetMaxLength(65536);
110 TXTDUMPFILENAME->SetFont(wxFont(12, wxSWISS, wxNORMAL, wxNORMAL, false, wxT("Courier")));
111
112 LBLFILENAME = new wxStaticText(this, ID_LBLFILENAME, wxT("Filename"), wxPoint(312, 479), wxDefaultSize, 0, wxT("LBLFILENAME"));
113 LBLFILENAME->SetFont(wxFont(12, wxSWISS, wxNORMAL, wxNORMAL, false, wxT("Courier")));
114
115 TXTENDADDR = new wxTextCtrl(this, ID_TXTENDADDR, wxT("00000000"), wxPoint(391, 454), wxSize(90, 19), 0, wxDefaultValidator, wxT("TXTENDADDR"));
116 TXTENDADDR->SetMaxLength(8);
117 TXTENDADDR->SetFont(wxFont(12, wxSWISS, wxNORMAL, wxNORMAL, false, wxT("Courier")));
118
119 LBLENDADDR = new wxStaticText(this, ID_LBLENDADDR, wxT("End Address"), wxPoint(285, 454), wxDefaultSize, 0, wxT("LBLENDADDR"));
120 LBLENDADDR->SetFont(wxFont(12, wxSWISS, wxNORMAL, wxNORMAL, false, wxT("Courier")));
121
122 TXTSTARTADDR = new wxTextCtrl(this, ID_TXTSTARTADDR, wxT("00000000"), wxPoint(391, 427), wxSize(90, 19), 0, wxDefaultValidator, wxT("TXTSTARTADDR"));
123 TXTSTARTADDR->SetMaxLength(8);
124 TXTSTARTADDR->SetFont(wxFont(12, wxSWISS, wxNORMAL, wxNORMAL, false, wxT("Courier")));
125
126 LBLSTARTADDR = new wxStaticText(this, ID_LBLSTARTADDR, wxT("Start Address"), wxPoint(267, 427), wxDefaultSize, 0, wxT("LBLSTARTADDR"));
127 LBLSTARTADDR->SetFont(wxFont(12, wxSWISS, wxNORMAL, wxNORMAL, false, wxT("Courier")));
128
129 BTNRAWDUMP = new wxButton(this, ID_BTNRAWDUMP, wxT("Dump"), wxPoint(641, 430), wxSize(61, 25), 0, wxDefaultValidator, wxT("BTNRAWDUMP"));
130 BTNRAWDUMP->SetFont(wxFont(12, wxSWISS, wxNORMAL, wxNORMAL, false, wxT("Courier")));
131
132 GRPMEMORYDUMP = new wxStaticBox(this, ID_GRPMEMORYDUMP, wxT("Memory Dump"), wxPoint(258, 398), wxSize(487, 109));
133 GRPMEMORYDUMP->SetFont(wxFont(12, wxSWISS, wxNORMAL, wxNORMAL, false, wxT("Courier New")));
134
135 TXTCURRENTADDR = new wxTextCtrl(this, ID_TXTCURRENTADDR, wxT("00000000"), wxPoint(153, 8), wxSize(213, 19), 0, wxDefaultValidator, wxT("TXTCURRENTADDR"));
136 TXTCURRENTADDR->SetMaxLength(8);
137 TXTCURRENTADDR->SetFont(wxFont(12, wxSWISS, wxNORMAL, wxNORMAL, false, wxT("Courier")));
138
139 BtnGotoAddress = new wxButton(this, ID_BTNGOTOADDRESS, wxT("Goto"), wxPoint(376, 7), wxSize(49, 25), 0, wxDefaultValidator, wxT("BtnGotoAddress"));
140 BtnGotoAddress->SetFont(wxFont(12, wxSWISS, wxNORMAL, wxNORMAL, false, wxT("Courier")));
141
142 RAM_SCROLL = new wxScrollBar(this, ID_RAM_SCROLL, wxPoint(732, 39), wxSize(17, 348), wxSB_VERTICAL | wxVSCROLL | wxALWAYS_SHOW_SB, wxDefaultValidator, wxT("RAM_SCROLL"));
143
144 ChkFreezeRam = new wxCheckBox(this, ID_CHKFREEZERAM, wxT("Freeze Ram"), wxPoint(573, 14), wxSize(84, 17), 0, wxDefaultValidator, wxT("ChkFreezeRam"));
145
146 RAMVIEW = new wxTextCtrl(this, ID_RAMVIEW, wxEmptyString, wxPoint(12, 39), wxSize(719, 349), wxSUNKEN_BORDER | wxTE_READONLY | wxTE_DONTWRAP | wxTE_MULTILINE, wxDefaultValidator, wxT("RAMVIEW"));
147 RAMVIEW->SetMaxLength(0);
148 RAMVIEW->SetFocus();
149 RAMVIEW->SetInsertionPointEnd();
150 RAMVIEW->SetFont(wxFont(12, wxSWISS, wxNORMAL, wxNORMAL, false, wxT("Courier")));
151
152 BTNPATCHADDR = new wxButton(this, ID_BTNPATCHADDR, wxT("Patch"), wxPoint(53, 468), wxSize(75, 25), 0, wxDefaultValidator, wxT("BTNPATCHADDR"));
153 BTNPATCHADDR->SetFont(wxFont(12, wxSWISS, wxNORMAL, wxNORMAL, false, wxT("Courier")));
154
155 TXTPATCHADDR = new wxTextCtrl(this, ID_TXTPATCHADDR, wxT("00000000"), wxPoint(95, 420), wxSize(90, 19), 0, wxDefaultValidator, wxT("TXTPATCHADDR"));
156 TXTPATCHADDR->SetMaxLength(8);
157 TXTPATCHADDR->SetFont(wxFont(12, wxSWISS, wxNORMAL, wxNORMAL, false, wxT("Courier")));
158
159 TXTPATCHDATA = new wxTextCtrl(this, ID_TXTPATCHDATA, wxT("00000000"), wxPoint(95, 443), wxSize(90, 19), 0, wxDefaultValidator, wxT("TXTPATCHDATA"));
160 TXTPATCHDATA->SetMaxLength(8);
161 TXTPATCHDATA->SetFont(wxFont(12, wxSWISS, wxNORMAL, wxNORMAL, false, wxT("Courier")));
162
163 LBLPATCHDATA = new wxStaticText(this, ID_LBLPATCHDATA, wxT("Data"), wxPoint(39, 444), wxDefaultSize, 0, wxT("LBLPATCHDATA"));
164 LBLPATCHDATA->SetFont(wxFont(12, wxSWISS, wxNORMAL, wxNORMAL, false, wxT("Courier")));
165
166 LBLPATCHADDR = new wxStaticText(this, ID_LBLPATCHADDR, wxT("Address"), wxPoint(12, 420), wxDefaultSize, 0, wxT("LBLPATCHADDR"));
167 LBLPATCHADDR->SetFont(wxFont(12, wxSWISS, wxNORMAL, wxNORMAL, false, wxT("Courier")));
168
169 GRPMEMORYPATCH = new wxStaticBox(this, ID_GRPMEMORYPATCH, wxT("Memory Patch"), wxPoint(6, 392), wxSize(200, 109));
170 GRPMEMORYPATCH->SetFont(wxFont(12, wxSWISS, wxNORMAL, wxNORMAL, false, wxT("Courier New")));
171
172 BTNCLOSE = new wxButton(this, ID_BTNCLOSE, wxT("Close"), wxPoint(674, 9), wxSize(79, 25), 0, wxDefaultValidator, wxT("BTNCLOSE"));
173 BTNCLOSE->SetFont(wxFont(12, wxSWISS, wxNORMAL, wxNORMAL, false, wxT("Courier")));
174
175 LBLCURRENTADDR = new wxStaticText(this, ID_LBLCURRENTADDR, wxT("Address:"), wxPoint(71, 9), wxDefaultSize, 0, wxT("LBLCURRENTADDR"));
176 LBLCURRENTADDR->SetFont(wxFont(12, wxSWISS, wxNORMAL, wxNORMAL, false, wxT("Courier")));
177
178
179
180 ////GUI Items Creation End
181
182
183 }
184
185 int Dialogs::wxRamViewDialog::CURRENT_BOITTOM_ADDR() { return CURRENT_TOP_ADDR + MAX_VIEWABLE_RAM; }
186 void Dialogs::wxRamViewDialog::ReadRam() { ReadRam(__RAM__PROVIDER__); }
187 void Dialogs::wxRamViewDialog::ReadRam(PS2RamProvider* provider)
188 {
189 if (!this->__RAM__PROVIDER__->IsRamAvailable()) return;
190 try {
191 wxString* _ram_data = new wxString();
192 IsCurrentlyReadingRam = true;
193 provider->FreezeRam();
194 provider->CurrentMemoryAddr = CURRENT_TOP_ADDR;
195 provider->CurrentMemoryViewSize = MAX_VIEWABLE_RAM;
196 for (int i=CURRENT_TOP_ADDR;i<=(CURRENT_TOP_ADDR+MAX_VIEWABLE_RAM);i+=RAM_ADDRESS_WIDTH)
197 {
198
199 // write address in format 00000000:
200 char addr[255];
201 sprintf(addr,"%08x",i);
202 //RAMVIEW->AppendText(wxString::FromAscii(addr));
203 //RAMVIEW->AppendText(wxString::FromAscii(": "));
204 _ram_data->Append(wxString::FromAscii(addr));
205 _ram_data->Append(wxString::FromAscii(": "));
206 char current_skipped_addr_buffer[255];
207 // write the byte data for each address
208 for (int j=0;j<RAM_ADDRESS_WIDTH;j++)
209 {
210 int current_addr=i+j;
211 if (current_addr <provider->GetRamSize())
212 {
213 sprintf(current_skipped_addr_buffer,"%02x",provider->GetRam()[current_addr]);
214 // RAMVIEW->AppendText(wxString::FromAscii(current_skipped_addr_buffer));
215 // RAMVIEW->AppendText(" ");
216 _ram_data->Append(wxString::FromAscii(current_skipped_addr_buffer));
217 _ram_data->Append(wxString::FromAscii(" "));
218 if (j == 7) { _ram_data->Append(wxString::FromAscii(" ")); }
219 }
220 else { break; }
221 }
222 _ram_data->Append(wxString::FromAscii(" "));
223 // write the ascii characters for each address
224 for (int j=0;j<RAM_ADDRESS_WIDTH;j++)
225 {
226 char ascii_data[255];
227 int current_addr=i+j;
228 if (current_addr <provider->GetRamSize())
229 {
230 unsigned char ascii_value_raw = provider->GetRam()[current_addr];
231 char ascii_value = (char)(provider->GetRam()[current_addr]);
232
233 if (ascii_value_raw >= 0x20 && ascii_value_raw <= 0x7e)
234 {
235 sprintf(ascii_data,"%c",ascii_value);
236 // RAMVIEW->AppendText(wxString::FromAscii(ascii_data));
237 _ram_data->Append(wxString::FromAscii(ascii_data));
238 }
239 else
240 {
241 _ram_data->Append(wxString::FromAscii(" "));
242 }
243
244
245 }
246 else { break; }
247 }
248 if (i<(CURRENT_TOP_ADDR+MAX_VIEWABLE_RAM))
249 {
250 // RAMVIEW->AppendText(wxString::FromAscii("\n"));
251 _ram_data->Append(wxString::FromAscii("\n"));
252 }
253 //free(addr);
254
255 RAMVIEW->ChangeValue(_ram_data->c_str());
256
257 }
258 }
259 catch(...) { // catch all exceptions
260 }
261 provider->UnFreezeRam();
262 IsCurrentlyReadingRam = false;
263 }
264
265 void Dialogs::wxRamViewDialog::OnClose(wxCloseEvent& /*event*/)
266 {
267 Destroy();
268 }
269
270 /*
271 * BTNCLOSEClick
272 */
273 void Dialogs::wxRamViewDialog::BTNCLOSEClick(wxCommandEvent& event)
274 {
275 Destroy();
276 }
277
278
279 /*
280 * RamRefreshTimerTimer
281 */
282 void Dialogs::wxRamViewDialog::RamRefreshTimerTimer(wxTimerEvent& event)
283 {
284 char addr[255];
285 sprintf(addr,"%08x",CURRENT_TOP_ADDR);
286
287 if (!IsCurrentlyReadingRam)
288 {
289 if(__RAM__PROVIDER__->RefreshRam())
290 {
291 this->TXTCURRENTADDR->SetValue(wxString::FromAscii(addr));
292 ReadRam();
293 }
294 else
295 {
296 this->TXTCURRENTADDR->SetValue(wxString::FromAscii(addr));
297 if (NeedToUpdateMemoryView && !__RAM__PROVIDER__->IsRamFrozen()) ReadRam();
298 }
299 }
300 }
301
302 /*
303 * ChkFreezeRamClick
304 */
305 void Dialogs::wxRamViewDialog::ChkFreezeRamClick(wxCommandEvent& event)
306 {
307 if (ChkFreezeRam->IsChecked())
308 {
309 __RAM__PROVIDER__->FreezeRam();
310 }
311 else
312 {
313 __RAM__PROVIDER__->UnFreezeRam();
314 }
315 }
316
317
318 /*
319 * RAM_SCROLLScrollPageDown
320 */
321 void Dialogs::wxRamViewDialog::RAM_SCROLLScrollPageDown(wxScrollEvent& event)
322 {
323 if (CURRENT_BOITTOM_ADDR() < __RAM__PROVIDER__->GetRamSize())
324 {
325 CURRENT_TOP_ADDR+=RAM_SCROLL_AMOUNT_LARGE;
326 }
327 NeedToUpdateMemoryView = true;
328 }
329
330 /*
331 * RAM_SCROLLScrollPageUp
332 */
333 void Dialogs::wxRamViewDialog::RAM_SCROLLScrollPageUp(wxScrollEvent& event)
334 {
335 if ((CURRENT_TOP_ADDR <= 0))
336 {
337 CURRENT_TOP_ADDR=0;
338 }
339 else if ((CURRENT_TOP_ADDR > 0))
340 {
341 CURRENT_TOP_ADDR-=RAM_SCROLL_AMOUNT_LARGE;
342 }
343 NeedToUpdateMemoryView = true;
344 }
345
346 /*
347 * RAM_SCROLLScrollLineDown
348 */
349 void Dialogs::wxRamViewDialog::RAM_SCROLLScrollLineDown(wxScrollEvent& event)
350 {
351 if (CURRENT_BOITTOM_ADDR() < __RAM__PROVIDER__->GetRamSize())
352 {
353 CURRENT_TOP_ADDR+=RAM_SCROLL_AMOUNT_SMALL;
354 }
355 NeedToUpdateMemoryView = true;
356 }
357
358 /*
359 * RAM_SCROLLScrollLineUp
360 */
361 void Dialogs::wxRamViewDialog::RAM_SCROLLScrollLineUp(wxScrollEvent& event)
362 {
363 if ((CURRENT_TOP_ADDR <= 0))
364 {
365 CURRENT_TOP_ADDR=0;
366 }
367 else if ((CURRENT_TOP_ADDR > 0))
368 {
369 CURRENT_TOP_ADDR-=RAM_SCROLL_AMOUNT_SMALL;
370 }
371 NeedToUpdateMemoryView = true;
372 }
373
374 /*
375 * BtnGotoAddressClick
376 */
377 void Dialogs::wxRamViewDialog::BtnGotoAddressClick(wxCommandEvent& event)
378 {
379 if (!this->__RAM__PROVIDER__->IsRamAvailable()) return;
380
381 wxString straddr = TXTCURRENTADDR->GetValue();
382 wxString straddr_check = straddr.SubString(straddr.Length()-1,1);
383
384 int ORIGINAL_CURRENT_TOP_ADDR = CURRENT_TOP_ADDR;
385
386 if (!(straddr_check.MakeLower().Cmp(wxString::FromAscii("1"))|| straddr_check.MakeLower().Cmp(wxString::FromAscii("2")) || straddr_check.MakeLower().Cmp(wxString::FromAscii("3")) ||
387 straddr_check.MakeLower().Cmp(wxString::FromAscii("4")) || straddr_check.MakeLower().Cmp(wxString::FromAscii("5")) || straddr_check.MakeLower().Cmp(wxString::FromAscii("6")) ||
388 straddr_check.MakeLower().Cmp(wxString::FromAscii("7")) || straddr_check.MakeLower().Cmp(wxString::FromAscii("8")) || straddr_check.MakeLower().Cmp(wxString::FromAscii("9")) ||
389 straddr_check.MakeLower().Cmp(wxString::FromAscii("a")) || straddr_check.MakeLower().Cmp(wxString::FromAscii("b")) || straddr_check .MakeLower().Cmp(wxString::FromAscii("c")) ||
390 straddr_check.MakeLower().Cmp(wxString::FromAscii("d")) || straddr_check.MakeLower().Cmp(wxString::FromAscii("e")) || straddr_check.MakeLower().Cmp(wxString::FromAscii("f"))))
391 {
392 CURRENT_TOP_ADDR=(int)wxStringToHexInt(straddr);
393 NeedToUpdateMemoryView = true;
394 }
395 else
396 {
397 wxString addr_fix = straddr.SubString(0,straddr.Length()-2);
398 addr_fix.Append(wxString::FromAscii("0"));
399 CURRENT_TOP_ADDR=(int)wxStringToHexInt(addr_fix);
400 NeedToUpdateMemoryView = true;
401 }
402
403 if (CURRENT_TOP_ADDR < 0 || CURRENT_TOP_ADDR > __RAM__PROVIDER__->GetRamSize())
404 {
405 CURRENT_TOP_ADDR = ORIGINAL_CURRENT_TOP_ADDR;
406 NeedToUpdateMemoryView = false;
407 }
408
409 }
410
411 /*
412 * wxRamDumpDialogActivate
413 */
414
415 /*
416 * BTNPATCHADDRClick
417 */
418 void Dialogs::wxRamViewDialog::BTNPATCHADDRClick(wxCommandEvent& event)
419 {
420 if (!this->__RAM__PROVIDER__->IsRamAvailable()) return;
421 // get address to patch
422 unsigned int patch_addr = (unsigned int)wxStringToHexInt(TXTPATCHADDR->GetValue());
423 // get data to patch
424 u32 patch_data = (u32)wxStringToInt(TXTPATCHDATA->GetValue());
425 if (__RAM__PROVIDER__->UpdateRamLocation(patch_addr,patch_data))
426 {
427 NeedToUpdateMemoryView = true;
428 }
429
430 }
431
432 /*
433 * BTNRAWDUMPClick
434 */
435 void Dialogs::wxRamViewDialog::BTNRAWDUMPClick(wxCommandEvent& event)
436 {
437 if (!this->__RAM__PROVIDER__->IsRamAvailable()) return;
438 //wxMessageBox( wxString::FromAscii("This is a test"));
439
440 // freeze ram before dumping
441 __RAM__PROVIDER__->FreezeRam();
442
443 unsigned int start_addr, end_addr;
444 start_addr = (unsigned int)wxStringToHexInt(TXTSTARTADDR->GetValue());
445 end_addr = (unsigned int)wxStringToHexInt(TXTENDADDR->GetValue());
446
447 bool dump_valid = false;
448
449 __RAM__PROVIDER__->SetRamDumpFilename(TXTDUMPFILENAME->GetValue());
450
451 if (!CHKDUMPALL->IsChecked())
452 {
453 if (start_addr == end_addr)
454 {
455 dump_valid = false;
456 wxMessageBox( wxString::Format(wxString::FromAscii("Start Address: 0x%08x is equal to\nEnd Adress: 0x%08x!"),start_addr,end_addr),wxString::FromAscii("Dump Error."),wxICON_ERROR );
457 }
458 else if ( start_addr < __RAM__PROVIDER__->MinimumRamAddress())
459 {
460 dump_valid = false;
461 wxMessageBox( wxString::Format(wxString::FromAscii("Start Address: 0x%08x Cannot be less than\nMIN_RAM_ADDRESS: 0x%08x!"),start_addr,__RAM__PROVIDER__->MinimumRamAddress()),wxString::FromAscii("Dump Error."),wxICON_ERROR );
462 }
463 else if ( start_addr > end_addr)
464 {
465 dump_valid = false;
466 wxMessageBox( wxString::Format(wxString::FromAscii("Start Address: 0x%08x Cannot be greater than\nEnd Address: 0x%08x!"),start_addr,end_addr),wxString::FromAscii("Dump Error."),wxICON_ERROR );
467 }
468 else if ( start_addr > __RAM__PROVIDER__->MaxmumRamAddress())
469 {
470 dump_valid = false;
471 wxMessageBox( wxString::Format(wxString::FromAscii("Start Address: 0x%08x Cannot be greater than\nMAX_RAM_ADDRESS: 0x%08x!"),start_addr,__RAM__PROVIDER__->MaxmumRamAddress()),wxString::FromAscii("Dump Error."),wxICON_ERROR );
472 }
473 else if ( end_addr < __RAM__PROVIDER__->MinimumRamAddress())
474 {
475 dump_valid = false;
476 wxMessageBox( wxString::Format(wxString::FromAscii("End Address: 0x%08x Cannot be less than\nMIN_RAM_ADDRESS: 0x%08x!"),end_addr,__RAM__PROVIDER__->MinimumRamAddress()),wxString::FromAscii("Dump Error."),wxICON_ERROR );
477 }
478 else if ( end_addr < start_addr)
479 {
480 dump_valid = false;
481 wxMessageBox( wxString::Format(wxString::FromAscii("End Address: 0x%08x Cannot be less than\nStart Address: 0x%08x!"),end_addr,start_addr),wxString::FromAscii("Dump Error."),wxICON_ERROR );
482 }
483 else if ( end_addr > __RAM__PROVIDER__->MaxmumRamAddress())
484 {
485 dump_valid = false;
486 wxMessageBox( wxString::Format(wxString::FromAscii("End Address: 0x%08x Cannot be greater than\nMAX_RAM_ADDRESS: 0x%08x!"),end_addr,__RAM__PROVIDER__->MaxmumRamAddress()),wxString::FromAscii("Dump Error."),wxICON_ERROR );
487 }
488 else
489 {
490 dump_valid = true;
491 }
492 }
493 else
494 {
495 dump_valid = true;
496 }
497
498 if (dump_valid)
499 {
500
501 bool dump_ok = false;
502
503 if (CHKDUMPALL->IsChecked())
504 {
505 int gofordump = wxMessageBox( wxString::Format(wxString::FromAscii("Preparing to Dump Ram at\n0x%08x - 0x%08x\n to file: %s!"),MIN_RAM_ADDRESS,MAX_RAM_ADDRESS,__RAM__PROVIDER__->GetRamDumpFilename().c_str()),wxString::FromAscii("Dump Status."),wxOK|wxCANCEL );
506 if (gofordump == wxCANCEL)
507 {
508 wxMessageBox( wxString::Format(wxString::FromAscii("Ram Dump Aborted!")),wxString::FromAscii("Dump Status."),wxOK);
509 return;
510 }
511 //wxMessageBox( wxString::Format(wxString::FromAscii("Ok Dumping Ram!")),wxString::FromAscii("Dump Status."),wxOK);
512 // perform actual dump of ram
513 dump_ok = __RAM__PROVIDER__->DumpRam();
514 }
515 else
516 {
517 int gofordump = wxMessageBox( wxString::Format(wxString::FromAscii("Preparing to Dump Ram at\n0x%08x - 0x%08x\n to file: %s!"),start_addr,end_addr,__RAM__PROVIDER__->GetRamDumpFilename().c_str()),wxString::FromAscii("Dump Status."),wxOK|wxCANCEL );
518 if (gofordump == wxCANCEL)
519 {
520 wxMessageBox( wxString::Format(wxString::FromAscii("Ram Dump Aborted!")),wxString::FromAscii("Dump Status."),wxOK);
521 return;
522 }
523 //wxMessageBox( wxString::Format(wxString::FromAscii("Ok Dumping Ram!")),wxString::FromAscii("Dump Status."),wxOK);
524 // perform actual dump of ram
525
526 dump_ok = __RAM__PROVIDER__->DumpRam(start_addr,end_addr);
527 }
528 if (dump_ok)
529 {
530 wxMessageBox( wxString::Format(wxString::FromAscii("Ram Dump Succeeded!\nDump file: %s"),__RAM__PROVIDER__->GetRamDumpFilename().c_str()),wxString::FromAscii("Dump Status."),wxOK | wxICON_INFORMATION);
531 }
532 else
533 {
534 wxMessageBox( wxString::Format(wxString::FromAscii("Ram Dump Failed!\nDump file: %s"),__RAM__PROVIDER__->GetRamDumpFilename().c_str()),wxString::FromAscii("Dump Status."),wxOK | wxICON_ERROR);
535 }
536 }
537 // unfreeze ram
538 __RAM__PROVIDER__->UnFreezeRam();
539
540 }
541 }
542
543 /*
544 * BTNSETDUMPFILEClick
545 */
546 void Dialogs::wxRamViewDialog::BTNSETDUMPFILEClick(wxCommandEvent& event)
547 {
548 if (!this->__RAM__PROVIDER__->IsRamAvailable()) return;
549 DUMPFILECHOOSER->SetFilename(TXTDUMPFILENAME->GetValue());
550 int result = DUMPFILECHOOSER->ShowModal();
551
552 if ( result == wxID_CANCEL ) return;
553 wxString dump_file = wxString::FromAscii("");
554 dump_file.Append(DUMPFILECHOOSER->GetDirectory());
555 dump_file.Append(wxString::FromAscii("\\"));
556 dump_file.Append(DUMPFILECHOOSER->GetFilename().c_str());
557 TXTDUMPFILENAME->SetValue(dump_file);
558
559 __RAM__PROVIDER__->SetRamDumpFilename(dump_file);
560
561 // unfreeze ram (ugly hack) -- it seems that the ReadRam() method does not call UnFreeze because it was being blocked by DUMPFILECHOOSER->ShowModal();
562 __RAM__PROVIDER__->UnFreezeRam();
563 }
564
565 /*
566 * CHKDUMPALLClick
567 */
568 void Dialogs::wxRamViewDialog::CHKDUMPALLClick(wxCommandEvent& event)
569 {
570 if (!this->__RAM__PROVIDER__->IsRamAvailable()) return;
571 //if (CHKDUMPALL->IsChecked())
572 //{
573 // // set dump for all
574 // char start_addr[255];
575 // char end_addr[255];
576 // sprintf(start_addr,"%08x",__RAM__PROVIDER__->MIN_RAM_ADDRESS());
577 // sprintf(end_addr,"%08x",__RAM__PROVIDER__->MAX_RAM_ADDRESS());
578 // TXTSTARTADDR->SetValue( wxString::FromAscii(start_addr));
579 // TXTENDADDR->SetValue( wxString::FromAscii(end_addr));
580 // }
581 // else
582 // {
583 // // reset dump for all
584 // TXTSTARTADDR->SetValue( wxString::FromAscii("00000000"));
585 // TXTENDADDR->SetValue( wxString::FromAscii("00000000"));
586 // }
587 }
588
589 /*
590 * wxRamViewDialogPaint
591 */
592 void Dialogs::wxRamViewDialog::wxRamViewDialogPaint(wxPaintEvent& event)
593 {
594 // paint the dialog
595 wxPaintDC dc(this);
596
597 // force-read the ram -- so that we do not have to wait for the timer to fire the first time
598 if (!HaveExecutedFirstReadRam)
599 {
600 ReadRam();
601 HaveExecutedFirstReadRam = true;
602 }
603 }

  ViewVC Help
Powered by ViewVC 1.1.22