1 /* Copyright 2012 Theo Berkau <cwx@cyberwarriorx.com>
2
3 This file is part of Yabause.
4
5 Yabause is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 Yabause is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with Yabause; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 #include "UIDebugSCUDSP.h"
20 #include "../CommonDialogs.h"
21 #include "UIYabause.h"
22
SCUDSPDis(void * context,u32 addr,char * string)23 int SCUDSPDis(void *context, u32 addr, char *string)
24 {
25 ScuDspDisasm((u8)addr, string);
26 return 1;
27 }
28
SCUDSPBreakpointHandler(u32 addr)29 void SCUDSPBreakpointHandler (u32 addr)
30 {
31 UIYabause* ui = QtYabause::mainWindow( false );
32
33 emit ui->breakpointHandlerSCUDSP();
34 }
35
UIDebugSCUDSP(YabauseThread * mYabauseThread,QWidget * p)36 UIDebugSCUDSP::UIDebugSCUDSP( YabauseThread *mYabauseThread, QWidget* p )
37 : UIDebugCPU( PROC_SCUDSP, mYabauseThread, p )
38 {
39 this->setWindowTitle(QtYabause::translate("Debug SCU DSP"));
40 gbRegisters->setTitle(QtYabause::translate("DSP Registers"));
41 pbMemoryTransfer->setVisible( false );
42 gbMemoryBreakpoints->setVisible( false );
43
44 pbReserved1->setText(QtYabause::translate("Save Program"));
45 pbReserved2->setText(QtYabause::translate("Save MD0"));
46 pbReserved3->setText(QtYabause::translate("Save MD1"));
47 pbReserved4->setText(QtYabause::translate("Save MD2"));
48 pbReserved5->setText(QtYabause::translate("Save MD3"));
49
50 pbReserved1->setVisible( true );
51 pbReserved2->setVisible( true );
52 pbReserved3->setVisible( true );
53 pbReserved4->setVisible( true );
54 pbReserved5->setVisible( true );
55
56 QSize size = lwRegisters->minimumSize();
57 size.setWidth(size.width() + lwRegisters->fontMetrics().averageCharWidth());
58 lwRegisters->setMinimumSize(size);
59
60 size = lwDisassembledCode->minimumSize();
61 size.setWidth(lwRegisters->fontMetrics().averageCharWidth() * 80);
62 lwDisassembledCode->setMinimumSize(size);
63
64 if (ScuRegs)
65 {
66 const scucodebreakpoint_struct *cbp;
67 int i;
68
69 cbp = ScuDspGetBreakpointList();
70
71 for (i = 0; i < MAX_BREAKPOINTS; i++)
72 {
73 QString text;
74 if (cbp[i].addr != 0xFFFFFFFF)
75 {
76 text.sprintf("%08X", (int)cbp[i].addr);
77 lwCodeBreakpoints->addItem(text);
78 }
79 }
80
81 lwDisassembledCode->setDisassembleFunction(SCUDSPDis);
82 lwDisassembledCode->setEndAddress(0x100);
83 lwDisassembledCode->setMinimumInstructionSize(1);
84 ScuDspSetBreakpointCallBack(SCUDSPBreakpointHandler);
85 }
86
87 updateAll();
88 }
89
updateRegList()90 void UIDebugSCUDSP::updateRegList()
91 {
92 scudspregs_struct regs;
93 QString str;
94
95 if (ScuRegs == NULL)
96 return;
97
98 memset(®s, 0, sizeof(regs));
99 ScuDspGetRegisters(®s);
100 lwRegisters->clear();
101
102 str.sprintf("PR = %d EP = %d", regs.ProgControlPort.part.PR, regs.ProgControlPort.part.EP);
103 lwRegisters->addItem(str);
104
105 str.sprintf("T0 = %d S = %d", regs.ProgControlPort.part.T0, regs.ProgControlPort.part.S);
106 lwRegisters->addItem(str);
107
108 str.sprintf("Z = %d C = %d", regs.ProgControlPort.part.Z, regs.ProgControlPort.part.C);
109 lwRegisters->addItem(str);
110
111 str.sprintf("V = %d E = %d", regs.ProgControlPort.part.V, regs.ProgControlPort.part.E);
112 lwRegisters->addItem(str);
113
114 str.sprintf("ES = %d EX = %d", regs.ProgControlPort.part.ES, regs.ProgControlPort.part.EX);
115 lwRegisters->addItem(str);
116
117 str.sprintf("LE = %d", regs.ProgControlPort.part.LE);
118 lwRegisters->addItem(str);
119
120 str.sprintf("P = %02X", regs.ProgControlPort.part.P);
121 lwRegisters->addItem(str);
122
123 str.sprintf("TOP = %02X", regs.TOP);
124 lwRegisters->addItem(str);
125
126 str.sprintf("LOP = %02X", regs.LOP);
127 lwRegisters->addItem(str);
128
129 str.sprintf("CT = %02X:%02X:%02X:%02X", regs.CT[0], regs.CT[1], regs.CT[2], regs.CT[3]);
130 lwRegisters->addItem(str);
131
132 str.sprintf("RA = %08X", regs.RA0);
133 lwRegisters->addItem(str);
134
135 str.sprintf("WA = %08X", regs.WA0);
136 lwRegisters->addItem(str);
137
138 str.sprintf("RX = %08X", regs.RX);
139 lwRegisters->addItem(str);
140
141 str.sprintf("RY = %08X", regs.RX);
142 lwRegisters->addItem(str);
143
144 str.sprintf("PH = %04X", regs.P.part.H & 0xFFFF);
145 lwRegisters->addItem(str);
146
147 str.sprintf("PL = %08X", (int)(regs.P.part.L & 0xFFFFFFFF));
148 lwRegisters->addItem(str);
149
150 str.sprintf("ACH = %04X", regs.AC.part.H & 0xFFFF);
151 lwRegisters->addItem(str);
152
153 str.sprintf("ACL = %08X", (int)(regs.AC.part.L & 0xFFFFFFFF));
154 lwRegisters->addItem(str);
155 }
156
updateCodeList(u32 addr)157 void UIDebugSCUDSP::updateCodeList(u32 addr)
158 {
159 lwDisassembledCode->goToAddress(addr);
160 lwDisassembledCode->setPC(addr);
161 }
162
updateAll()163 void UIDebugSCUDSP::updateAll()
164 {
165 updateRegList();
166 if (ScuRegs)
167 {
168 scudspregs_struct regs;
169 ScuDspGetRegisters(®s);
170 updateCodeList(regs.PC);
171 }
172 }
173
getRegister(int index,int * size)174 u32 UIDebugSCUDSP::getRegister(int index, int *size)
175 {
176 *size = 0;
177 return 0;
178 }
179
setRegister(int index,u32 value)180 void UIDebugSCUDSP::setRegister(int index, u32 value)
181 {
182 }
183
addCodeBreakpoint(u32 addr)184 bool UIDebugSCUDSP::addCodeBreakpoint(u32 addr)
185 {
186 if (!ScuRegs)
187 return false;
188 return ScuDspAddCodeBreakpoint(addr) == 0;
189 }
190
delCodeBreakpoint(u32 addr)191 bool UIDebugSCUDSP::delCodeBreakpoint(u32 addr)
192 {
193 if (!ScuRegs)
194 return false;
195 return ScuDspDelCodeBreakpoint(addr) == 0;
196 }
197
stepInto()198 void UIDebugSCUDSP::stepInto()
199 {
200 ScuDspStep();
201 updateAll();
202 }
203
reserved1()204 void UIDebugSCUDSP::reserved1()
205 {
206 const QString s = CommonDialogs::getSaveFileName( QString(), QtYabause::translate( "Choose a location for binary file" ), QtYabause::translate( "Binary Files (*.bin)" ) );
207 if (!ScuRegs)
208 return;
209 if ( !s.isNull() )
210 ScuDspSaveProgram(QFile::encodeName(s));
211 }
212
reserved2()213 void UIDebugSCUDSP::reserved2()
214 {
215 const QString s = CommonDialogs::getSaveFileName( QString(), QtYabause::translate( "Choose a location for binary file" ), QtYabause::translate( "Binary Files (*.bin)" ) );
216 if (!ScuRegs)
217 return;
218 if ( !s.isNull() )
219 ScuDspSaveMD(QFile::encodeName(s), 0);
220 }
221
reserved3()222 void UIDebugSCUDSP::reserved3()
223 {
224 const QString s = CommonDialogs::getSaveFileName( QString(), QtYabause::translate( "Choose a location for binary file" ), QtYabause::translate( "Binary Files (*.bin)" ) );
225 if (!ScuRegs)
226 return;
227 if ( !s.isNull() )
228 ScuDspSaveMD(QFile::encodeName(s), 1);
229 }
230
reserved4()231 void UIDebugSCUDSP::reserved4()
232 {
233 const QString s = CommonDialogs::getSaveFileName( QString(), QtYabause::translate( "Choose a location for binary file" ), QtYabause::translate( "Binary Files (*.bin)" ) );
234 if (!ScuRegs)
235 return;
236 if ( !s.isNull() )
237 ScuDspSaveMD(QFile::encodeName(s), 2);
238 }
239
reserved5()240 void UIDebugSCUDSP::reserved5()
241 {
242 const QString s = CommonDialogs::getSaveFileName( QString(), QtYabause::translate( "Choose a location for binary file" ), QtYabause::translate( "Binary Files (*.bin)" ) );
243 if (!ScuRegs)
244 return;
245 if ( !s.isNull() )
246 ScuDspSaveMD(QFile::encodeName(s), 3);
247 }
248
249