1 // NOTE: Apologies for the quality of this code, this is really from pre-opensource Dolphin - that is, 2003.
2
3 #include "Common/CommonWindows.h"
4 #include <windowsx.h>
5 #include <commctrl.h>
6 #include "Windows/resource.h"
7 #include "Common/Data/Encoding/Utf8.h"
8
9 #include "Core/Debugger/SymbolMap.h"
10 #include "Windows/Debugger/Debugger_VFPUDlg.h"
11
12 #include "Windows/Debugger/CtrlMemView.h"
13
14 #include "Core/MIPS/MIPS.h" // BAD
15
16 CVFPUDlg *vfpudlg;
17
CVFPUDlg(HINSTANCE _hInstance,HWND _hParent,DebugInterface * cpu_)18 CVFPUDlg::CVFPUDlg(HINSTANCE _hInstance, HWND _hParent, DebugInterface *cpu_) : Dialog((LPCSTR)IDD_VFPU, _hInstance,_hParent)
19 {
20 cpu = cpu_;
21 wchar_t temp[256];
22 wsprintf(temp, L"VFPU - %S", cpu->GetName());
23 SetWindowText(m_hDlg,temp);
24
25 ShowWindow(m_hDlg,SW_HIDE);
26 font = CreateFont(12,0,0,0,FW_DONTCARE,FALSE,FALSE,FALSE,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,
27 L"Lucida Console");
28
29 HWND tabs = GetDlgItem(m_hDlg, IDC_TABDATATYPE);
30
31 TCITEM tcItem;
32 ZeroMemory (&tcItem,sizeof (tcItem));
33 tcItem.mask = TCIF_TEXT;
34 tcItem.dwState = 0;
35 tcItem.pszText = (LPTSTR)L"Float";
36 tcItem.cchTextMax = (int)wcslen(tcItem.pszText)+1;
37 tcItem.iImage = 0;
38 TabCtrl_InsertItem(tabs, TabCtrl_GetItemCount(tabs),&tcItem);
39 tcItem.pszText = (LPTSTR)L"HalfFloat";
40 tcItem.cchTextMax = (int)wcslen(tcItem.pszText)+1;
41 TabCtrl_InsertItem(tabs, TabCtrl_GetItemCount(tabs),&tcItem);
42 tcItem.pszText = (LPTSTR)L"Hex";
43 tcItem.cchTextMax = (int)wcslen(tcItem.pszText)+1;
44 TabCtrl_InsertItem(tabs, TabCtrl_GetItemCount(tabs),&tcItem);
45 tcItem.pszText = (LPTSTR)L"Bytes";
46 tcItem.cchTextMax = (int)wcslen(tcItem.pszText)+1;
47 TabCtrl_InsertItem(tabs, TabCtrl_GetItemCount(tabs),&tcItem);
48 tcItem.pszText = (LPTSTR)L"Shorts";
49 tcItem.cchTextMax = (int)wcslen(tcItem.pszText)+1;
50 TabCtrl_InsertItem(tabs, TabCtrl_GetItemCount(tabs),&tcItem);
51 tcItem.pszText = (LPTSTR)L"Ints";
52 tcItem.cchTextMax = (int)wcslen(tcItem.pszText)+1;
53 TabCtrl_InsertItem(tabs, TabCtrl_GetItemCount(tabs),&tcItem);
54 mode=0;
55 Size();
56 }
57
58
~CVFPUDlg(void)59 CVFPUDlg::~CVFPUDlg(void)
60 {
61 DeleteObject(font);
62 }
63
Update(void)64 void CVFPUDlg::Update(void)
65 {
66 if (m_hDlg != NULL)
67 {
68 InvalidateRect(m_hDlg, 0,0);
69 /*
70 CtrlMemView *mv = CtrlMemView::getFrom(GetDlgItem(m_hDlg,IDC_MEMVIEW));
71 if (mv != NULL)
72 mv->redraw();*/
73 }
74 }
75
76
77
DlgProc(UINT message,WPARAM wParam,LPARAM lParam)78 BOOL CVFPUDlg::DlgProc(UINT message, WPARAM wParam, LPARAM lParam)
79 {
80 switch(message)
81 {
82 case WM_INITDIALOG:
83 {
84 return TRUE;
85 }
86 break;
87 case WM_COMMAND:
88 {
89 // CtrlMemView *mv = CtrlMemView::getFrom(GetDlgItem(m_hDlg,IDC_MEMVIEW));
90 //switch (LOWORD(wParam))
91 //{
92 //}
93 }
94 break;
95
96 case WM_NOTIFY:
97 {
98 HWND tabs = GetDlgItem(m_hDlg, IDC_TABDATATYPE);
99 NMHDR* pNotifyMessage = NULL;
100 pNotifyMessage = (LPNMHDR)lParam;
101 if (pNotifyMessage->hwndFrom == tabs)
102 {
103 mode = TabCtrl_GetCurSel (tabs);
104 InvalidateRect(m_hDlg,0,0);
105 }
106 break;
107 }
108
109 case WM_SIZE:
110 Size();
111 break;
112
113 case WM_PAINT:
114 {
115 HWND wnd = m_hDlg;
116 RECT rect;
117 GetClientRect(wnd, &rect);
118 PAINTSTRUCT p;
119 HDC hdc = BeginPaint(wnd, &p);
120 SetBkMode(hdc, TRANSPARENT);
121 DWORD bgColor = 0xffffff;
122 HPEN nullPen=CreatePen(0,0,bgColor);
123 HPEN currentPen=CreatePen(0,0,0);
124 HPEN selPen=CreatePen(0,0,0x808080);
125 LOGBRUSH lbr;
126 lbr.lbHatch=0; lbr.lbStyle=0;
127 lbr.lbColor=bgColor;
128 HBRUSH nullBrush=CreateBrushIndirect(&lbr);
129 lbr.lbColor=0xFFEfE8;
130 HBRUSH currentBrush=CreateBrushIndirect(&lbr);
131 lbr.lbColor=0x70FF70;
132 HBRUSH pcBrush=CreateBrushIndirect(&lbr);
133 HPEN oldPen=(HPEN)SelectObject(hdc,currentPen);
134 HBRUSH oldBrush=(HBRUSH)SelectObject(hdc,nullBrush);
135 HFONT oldFont = (HFONT)SelectObject(hdc,(HGDIOBJ)font);
136
137 enum
138 {
139 rowHeight = 15,
140 columnWidth = 80,
141 xStart = columnWidth/2,
142 yStart = 30,
143 };
144
145 for (int matrix = 0; matrix<8; matrix++)
146 {
147 int my = (int)(yStart + matrix * rowHeight * 5.5f);
148 Rectangle(hdc, 0, my, xStart, my+rowHeight);
149 char temp[256];
150 int temp_len = sprintf_s(temp, "M%i00", matrix);
151 TextOutA(hdc,3,my+2,temp,temp_len);
152 Rectangle(hdc,xStart,my+rowHeight,xStart+columnWidth*4,my+5*rowHeight);
153
154 for (int column = 0; column<4; column++)
155 {
156 int y = my;
157 int x = column * columnWidth + xStart;
158
159 Rectangle(hdc, x, y, x + columnWidth, y+rowHeight);
160 temp_len = sprintf_s(temp, "R%i0%i", matrix, column);
161 TextOutA(hdc,x+3,y+2,temp,temp_len);
162
163 Rectangle(hdc, 0, y+rowHeight*(column+1), xStart, y+rowHeight*(column+2));
164 temp_len = sprintf_s(temp, "C%i%i0", matrix, column);
165 TextOutA(hdc,3,y+rowHeight*(column+1)+1,temp,temp_len);
166
167 y+=rowHeight;
168
169 for (int row = 0; row<4; row++)
170 {
171 float val = mipsr4k.v[voffset[column*32+row+matrix*4]];
172 u32 hex = mipsr4k.vi[voffset[column*32+row+matrix*4]];
173 switch (mode)
174 {
175 case 0: temp_len = sprintf_s(temp,"%f",val); break;
176 // case 1: temp_len = sprintf_s(temp,"??"); break;
177 case 2: temp_len = sprintf_s(temp,"0x%08x",hex); break;
178 default:temp_len = sprintf_s(temp,"%f",val); break;
179 }
180
181 TextOutA(hdc,x+3,y+2,temp,temp_len);
182 y+=rowHeight;
183 }
184 }
185 }
186
187 SelectObject(hdc,oldFont);
188 SelectObject(hdc,oldPen);
189 SelectObject(hdc,oldBrush);
190
191 DeleteObject(nullPen);
192 DeleteObject(currentPen);
193 DeleteObject(selPen);
194
195 DeleteObject(nullBrush);
196 DeleteObject(pcBrush);
197 DeleteObject(currentBrush);
198
199 EndPaint(m_hDlg, &p);
200 }
201 break;
202
203 case WM_CLOSE:
204 Show(false);
205 break;
206 }
207
208 return 0;
209 }
210
Goto(u32 addr)211 void CVFPUDlg::Goto(u32 addr)
212 {
213 Show(true);
214 CtrlMemView *mv = CtrlMemView::getFrom(GetDlgItem(CVFPUDlg::m_hDlg,IDC_MEMVIEW));
215 mv->gotoAddr(addr & ~3);
216 }
217
218
Size()219 void CVFPUDlg::Size()
220 {
221 RECT rc;
222 GetClientRect(m_hDlg,&rc);
223 }
224