1 // Copyright (C) 2003 Dolphin Project.
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, version 2.0.
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU General Public License 2.0 for more details.
12 // A copy of the GPL 2.0 should have been included with the program.
13 // If not, see http://www.gnu.org/licenses/
15 // Official SVN repository and contact information can be found at
16 // http://code.google.com/p/dolphin-emu/
19 #include "BreakpointView.h"
20 #include "CodeWindow.h"
21 #include "HW/Memmap.h"
22 #include "BreakpointDlg.h"
23 #include "MemoryCheckDlg.h"
25 #include "PowerPC/PowerPC.h"
28 BEGIN_EVENT_TABLE(CBreakPointWindow
, wxPanel
)
29 EVT_LIST_ITEM_ACTIVATED(ID_BPS
, CBreakPointWindow::OnActivated
)
30 EVT_LIST_ITEM_SELECTED(ID_TOOLBAR
, CBreakPointWindow::OnSelectItem
)
33 CBreakPointWindow::CBreakPointWindow(CCodeWindow
* _pCodeWindow
, wxWindow
* parent
,
34 wxWindowID id
, const wxString
& title
, const wxPoint
& position
,
35 const wxSize
& size
, long style
)
36 : wxPanel(parent
, id
, position
, size
, style
, title
)
37 , m_BreakPointListView(NULL
)
38 , m_pCodeWindow(_pCodeWindow
)
43 void CBreakPointWindow::CreateGUIControls()
45 SetSize(8, 8, 400, 370);
48 m_BreakPointBar
= new CBreakPointBar(this, ID_TOOLBAR
, wxDefaultPosition
, wxSize(0, 55),
49 wxLC_ICON
| wxSUNKEN_BORDER
| wxLC_SINGLE_SEL
);
50 m_BreakPointListView
= new CBreakPointView(this, ID_BPS
, wxDefaultPosition
, wxDefaultSize
,
51 wxLC_REPORT
| wxSUNKEN_BORDER
| wxLC_ALIGN_LEFT
| wxLC_SINGLE_SEL
| wxLC_SORT_ASCENDING
);
53 wxBoxSizer
* sizerH
= new wxBoxSizer(wxVERTICAL
);
54 sizerH
->Add(m_BreakPointBar
, 0, wxALL
| wxEXPAND
);
55 sizerH
->Add((wxListCtrl
*)m_BreakPointListView
, 1, wxEXPAND
);
61 void CBreakPointWindow::OnSelectItem(wxListEvent
& event
)
63 switch(event
.GetItem().GetId())
67 m_BreakPointBar
->SetItemState(event
.GetItem().GetId(), 0, wxLIST_STATE_FOCUSED
);
71 m_BreakPointBar
->SetItemState(event
.GetItem().GetId(), 0, wxLIST_STATE_FOCUSED
);
73 case IDM_ADD_BREAKPOINT
:
76 case IDM_ADD_BREAKPOINTMANY
:
77 OnAddBreakPointMany();
79 case IDM_ADD_MEMORYCHECK
:
82 case IDM_ADD_MEMORYCHECKMANY
:
83 OnAddMemoryCheckMany();
88 void CBreakPointWindow::NotifyUpdate()
90 if (m_BreakPointListView
!= NULL
) m_BreakPointListView
->Update();
93 void CBreakPointWindow::OnDelete()
95 if (m_BreakPointListView
)
97 m_BreakPointListView
->DeleteCurrentSelection();
101 void CBreakPointWindow::OnActivated(wxListEvent
& event
)
103 long Index
= event
.GetIndex();
106 u32 Address
= (u32
)m_BreakPointListView
->GetItemData(Index
);
107 if (m_pCodeWindow
!= NULL
)
109 m_pCodeWindow
->JumpToAddress(Address
);
114 // Breakpoint actions
115 // ---------------------
117 // Clear all breakpoints
118 void CBreakPointWindow::OnClear()
120 PowerPC::breakpoints
.Clear();
121 PowerPC::memchecks
.Clear();
125 // Add one breakpoint
126 void CBreakPointWindow::OnAddBreakPoint()
128 BreakPointDlg
bpDlg(this, this);
132 // Load breakpoints from file
133 void CBreakPointWindow::OnAddBreakPointMany()
137 std::string filename
= std::string(File::GetUserPath(D_GAMECONFIG_IDX
)) + "BreakPoints.ini";
139 if (ini
.Load(filename
.c_str())) // check if there is any file there
141 // get lines from a certain section
142 std::vector
<std::string
> lines
;
143 if (!ini
.GetLines("BreakPoints", lines
))
145 wxMessageBox(_T("You have no [BreakPoints] line in your file"));
149 for (std::vector
<std::string
>::const_iterator iter
= lines
.begin(); iter
!= lines
.end(); ++iter
)
151 std::string line
= StripSpaces(*iter
);
153 if (AsciiToHex(line
.c_str(), Address
))
155 PowerPC::breakpoints
.Add(Address
);
158 // Only update after we are done with the loop
163 wxMessageBox(_T("Couldn't find GameConfig/BreakPoints.ini file"));
168 // Memory check actions
169 // ---------------------
171 CBreakPointWindow::OnAddMemoryCheck()
173 MemoryCheckDlg
memDlg(this);
177 // Load memory checks from file
178 void CBreakPointWindow::OnAddMemoryCheckMany()
182 std::string filename
= std::string(File::GetUserPath(D_GAMECONFIG_IDX
)) + "MemoryChecks.ini";
184 if (ini
.Load(filename
.c_str()))
186 // get lines from a certain section
187 std::vector
<std::string
> lines
;
188 if (!ini
.GetLines("MemoryChecks", lines
))
190 wxMessageBox(_T("You have no [MemoryChecks] line in your file"));
194 for (std::vector
<std::string
>::const_iterator iter
= lines
.begin(); iter
!= lines
.end(); ++iter
)
196 std::string line
= StripSpaces(*iter
);
197 std::vector
<std::string
> pieces
;
198 SplitString(line
, ' ', pieces
); // split string
203 bool doCommon
= false;
205 // ------------------------------------------------------------------------------------------
206 // Decide if we have a range or just one address, and if we should break or not
210 && AsciiToHex(pieces
[0].c_str(), sAddress
)
211 && pieces
[0].size() == 8
215 MemCheck
.StartAddress
= sAddress
;
216 MemCheck
.EndAddress
= sAddress
;
218 MemCheck
.Break
= false;
222 && AsciiToHex(pieces
[0].c_str(), sAddress
) && AsciiToHex(pieces
[1].c_str(), eAddress
)
223 && pieces
[0].size() == 8 && pieces
[1].size() == 8
227 MemCheck
.StartAddress
= sAddress
;
228 MemCheck
.EndAddress
= eAddress
;
230 MemCheck
.Break
= false;
234 && AsciiToHex(pieces
[0].c_str(), sAddress
) && AsciiToHex(pieces
[1].c_str(), eAddress
)
235 && pieces
[0].size() == 8 && pieces
[1].size() == 8 && pieces
[2].size() == 1
239 MemCheck
.StartAddress
= sAddress
;
240 MemCheck
.EndAddress
= eAddress
;
242 MemCheck
.Break
= true;
247 // settings for the memory check
248 MemCheck
.OnRead
= true;
249 MemCheck
.OnWrite
= true;
251 //MemCheck.Break = false; // this is also what sets Active "on" in the breakpoint window
252 // so don't think it's off because we are only writing this to the log
253 PowerPC::memchecks
.Add(MemCheck
);
256 // Update after we are done with the loop
261 wxMessageBox(_T("You have no ") + wxString::FromAscii(File::GetUserPath(D_GAMECONFIG_IDX
)) + _T("MemoryChecks.ini file"));