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

Contents of /branch/debug/0.X/0.9.X/0.9.7/r3795-ramdump/pcsx2/System/PS2RamProvider.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: 3069 byte(s)
attempt to implement memory patching -- memWrite32 seems to fail .... don't know why ....
1 // Class automatically generated by Dev-C++ New Class wizard
2
3 #include "PrecompiledHeader.h"
4 #include "PS2RamProvider.h" // class's header file
5
6 int Debug_Read8(unsigned long addr)//just for anycase..
7 {
8 #ifdef _WIN32
9 __try
10 {
11 #endif
12 s32 val8;
13 val8 = memRead8(addr);
14 return val8;
15 #ifdef _WIN32
16 }
17 __except (EXCEPTION_EXECUTE_HANDLER)
18 {
19 return -1;
20 }
21 #endif
22 }
23
24 // class constructor
25 //PS2RamProvider::PS2RamProvider() : IRamProvider() { InitializeProvider(); }
26 //PS2RamProvider::PS2RamProvider(int SizeOfRamInBytes) : IRamProvider(SizeOfRamInBytes) { InitializeProvider(); }
27 //PS2RamProvider::PS2RamProvider(unsigned char* Ram, int SizeOfRamInBytes) : IRamProvider(Ram,SizeOfRamInBytes) { InitializeProvider(); }
28
29 PS2RamProvider::PS2RamProvider() {
30 this->CurrentMemoryAddr = cpuRegs.pc;
31 this->BASE_ADDR = this->CurrentMemoryAddr;
32 this->CurrentMemoryViewSize = 0;
33 this->InitializeProvider();
34 }
35
36 PS2RamProvider::PS2RamProvider(int ADDRESS_TABLE_SIZE) {
37 this->CurrentMemoryAddr = cpuRegs.pc;
38 this->BASE_ADDR = this->CurrentMemoryAddr;
39 this->CurrentMemoryViewSize = ADDRESS_TABLE_SIZE;
40 this->InitializeProvider();
41 }
42
43 // class destructor
44 PS2RamProvider::~PS2RamProvider() { }
45
46
47 bool PS2RamProvider::RefreshRam()
48 {
49 if (IsRamAvailable())
50 {
51 // put code here to refresh ram -- for now we will just return true;
52 this->BASE_ADDR = this->CurrentMemoryAddr;
53 this->InitializeProvider();
54 if (!IsRamAvailable()) return false;
55 return true;
56 }
57 else
58 {
59 return false;
60 }
61 }
62
63 void PS2RamProvider::InitializeProvider()
64 {
65 _IsRamAvailable = false;
66 int i;
67 //int size = this->CurrentMemoryViewSize * 16;
68 int size = this->BASE_ADDR + MAX_VIEWABLE_RAM;
69 this->SetRamSize(size);
70 unsigned char* data = new unsigned char[size];for (i = 0; i < size; i++){data[i]=0;}
71 try {
72 for (i = this->BASE_ADDR; i < size; i++)
73 {
74 int ret = Debug_Read8(this->CurrentMemoryAddr++);
75 if (ret == -1)
76 {
77 _IsRamAvailable = false;
78 this->SetRam(data,size, this->BASE_ADDR);
79 return;
80 }
81 else
82 {
83 data[i] = (unsigned char)ret;
84 }
85 }
86 this->SetRam(data,size,this->BASE_ADDR);
87 _IsRamAvailable = true;
88 }
89 catch(...)
90 {
91 _IsRamAvailable = false;
92 this->SetRam(data,size,cpuRegs.pc);
93 }
94 }
95
96 bool PS2RamProvider::IsRamAvailable()
97 {
98 return _IsRamAvailable && !this->IsRamFrozen();
99 }
100
101 bool PS2RamProvider::UpdateRamLocation(u32 address, u32 data)
102 {
103 u32 memory_patch = address;
104 u32 data_patch = data;
105 try {
106 memWrite32( memory_patch, data );
107 wxMessageBox( wxString::Format(wxString::FromAscii("Successfully Patched Address: 0x%08x with Data: 0x%08x"),memory_patch,data_patch),wxString::FromAscii("Patch Success"),wxICON_EXCLAMATION );
108 return true;
109 }
110 catch(...)
111 {
112 wxMessageBox( wxString::Format(wxString::FromAscii("Failed to Patch Address: 0x%08x with Data: 0x%08x"),memory_patch,data_patch),wxString::FromAscii("Patch Failure"),wxICON_EXCLAMATION );
113 return false;
114 }
115 }

  ViewVC Help
Powered by ViewVC 1.1.22