annotate src/win32/Disassemble.cpp @ 8:08a8e09ca414

add files required by automake
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:54:39 -0600
parents f9f4f1b99eed
children
rev   line source
rlm@1 1 // Disassemble.cpp : implementation file
rlm@1 2 //
rlm@1 3
rlm@1 4 #include "stdafx.h"
rlm@1 5 #include "resource.h"
rlm@1 6 #include "Disassemble.h"
rlm@1 7 #include "VBA.h"
rlm@1 8
rlm@1 9 #include "../gba/armdis.h"
rlm@1 10 #include "../gba/GBA.h"
rlm@1 11 #include "../gba/GBAGlobals.h"
rlm@1 12
rlm@1 13 extern void CPUUpdateCPSR();
rlm@1 14
rlm@1 15 /////////////////////////////////////////////////////////////////////////////
rlm@1 16 // Disassemble dialog
rlm@1 17
rlm@1 18 Disassemble::Disassemble(CWnd*pParent /*=NULL*/)
rlm@1 19 : ResizeDlg(Disassemble::IDD, pParent)
rlm@1 20 {
rlm@1 21 //{{AFX_DATA_INIT(Disassemble)
rlm@1 22 m_c = FALSE;
rlm@1 23 m_f = FALSE;
rlm@1 24 m_i = FALSE;
rlm@1 25 m_n = FALSE;
rlm@1 26 m_t = FALSE;
rlm@1 27 m_v = FALSE;
rlm@1 28 m_z = FALSE;
rlm@1 29 //}}AFX_DATA_INIT
rlm@1 30 autoUpdate = false;
rlm@1 31 address = 0;
rlm@1 32 count = 1;
rlm@1 33 mode = 0;
rlm@1 34 }
rlm@1 35
rlm@1 36 void Disassemble::DoDataExchange(CDataExchange*pDX)
rlm@1 37 {
rlm@1 38 CDialog::DoDataExchange(pDX);
rlm@1 39 //{{AFX_DATA_MAP(Disassemble)
rlm@1 40 DDX_Control(pDX, IDC_ADDRESS, m_address);
rlm@1 41 DDX_Control(pDX, IDC_DISASSEMBLE, m_list);
rlm@1 42 DDX_Check(pDX, IDC_C, m_c);
rlm@1 43 DDX_Check(pDX, IDC_F, m_f);
rlm@1 44 DDX_Check(pDX, IDC_I, m_i);
rlm@1 45 DDX_Check(pDX, IDC_N, m_n);
rlm@1 46 DDX_Check(pDX, IDC_T, m_t);
rlm@1 47 DDX_Check(pDX, IDC_V, m_v);
rlm@1 48 DDX_Check(pDX, IDC_Z, m_z);
rlm@1 49 DDX_Radio(pDX, IDC_AUTOMATIC, mode);
rlm@1 50 //}}AFX_DATA_MAP
rlm@1 51 }
rlm@1 52
rlm@1 53 BEGIN_MESSAGE_MAP(Disassemble, CDialog)
rlm@1 54 //{{AFX_MSG_MAP(Disassemble)
rlm@1 55 ON_BN_CLICKED(IDC_AUTO_UPDATE, OnAutoUpdate)
rlm@1 56 ON_BN_CLICKED(IDC_AUTOMATIC, OnAutomatic)
rlm@1 57 ON_BN_CLICKED(IDC_ARM, OnArm)
rlm@1 58 ON_BN_CLICKED(IDC_CLOSE, OnClose)
rlm@1 59 ON_BN_CLICKED(IDC_GO, OnGo)
rlm@1 60 ON_BN_CLICKED(IDC_GOPC, OnGopc)
rlm@1 61 ON_BN_CLICKED(IDC_NEXT, OnNext)
rlm@1 62 ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
rlm@1 63 ON_BN_CLICKED(IDC_THUMB, OnThumb)
rlm@1 64 ON_WM_VSCROLL()
rlm@1 65 //}}AFX_MSG_MAP
rlm@1 66 END_MESSAGE_MAP()
rlm@1 67
rlm@1 68 /////////////////////////////////////////////////////////////////////////////
rlm@1 69 // Disassemble message handlers
rlm@1 70
rlm@1 71 void Disassemble::OnAutoUpdate()
rlm@1 72 {
rlm@1 73 autoUpdate = !autoUpdate;
rlm@1 74 if (autoUpdate)
rlm@1 75 {
rlm@1 76 theApp.winAddUpdateListener(this);
rlm@1 77 }
rlm@1 78 else
rlm@1 79 {
rlm@1 80 theApp.winRemoveUpdateListener(this);
rlm@1 81 }
rlm@1 82 }
rlm@1 83
rlm@1 84 void Disassemble::OnAutomatic()
rlm@1 85 {
rlm@1 86 mode = 0;
rlm@1 87 refresh();
rlm@1 88 }
rlm@1 89
rlm@1 90 void Disassemble::OnArm()
rlm@1 91 {
rlm@1 92 mode = 1;
rlm@1 93 refresh();
rlm@1 94 }
rlm@1 95
rlm@1 96 void Disassemble::OnClose()
rlm@1 97 {
rlm@1 98 theApp.winRemoveUpdateListener(this);
rlm@1 99
rlm@1 100 DestroyWindow();
rlm@1 101 }
rlm@1 102
rlm@1 103 void Disassemble::OnGo()
rlm@1 104 {
rlm@1 105 CString buffer;
rlm@1 106 m_address.GetWindowText(buffer);
rlm@1 107 sscanf(buffer, "%x", &address);
rlm@1 108 refresh();
rlm@1 109 }
rlm@1 110
rlm@1 111 void Disassemble::OnGopc()
rlm@1 112 {
rlm@1 113 if (armState)
rlm@1 114 address = armNextPC - 16;
rlm@1 115 else
rlm@1 116 address = armNextPC - 8;
rlm@1 117
rlm@1 118 refresh();
rlm@1 119 }
rlm@1 120
rlm@1 121 void Disassemble::OnNext()
rlm@1 122 {
rlm@1 123 CPULoop(1);
rlm@1 124 if (armState)
rlm@1 125 {
rlm@1 126 u32 total = address+count*4;
rlm@1 127 if (armNextPC >= address && armNextPC < total)
rlm@1 128 {}
rlm@1 129 else
rlm@1 130 {
rlm@1 131 OnGopc();
rlm@1 132 }
rlm@1 133 }
rlm@1 134 else
rlm@1 135 {
rlm@1 136 u32 total = address+count*2;
rlm@1 137 if (armNextPC >= address && armNextPC < total)
rlm@1 138 {}
rlm@1 139 else
rlm@1 140 {
rlm@1 141 OnGopc();
rlm@1 142 }
rlm@1 143 }
rlm@1 144 refresh();
rlm@1 145 }
rlm@1 146
rlm@1 147 void Disassemble::OnRefresh()
rlm@1 148 {
rlm@1 149 refresh();
rlm@1 150 }
rlm@1 151
rlm@1 152 void Disassemble::OnThumb()
rlm@1 153 {
rlm@1 154 mode = 2;
rlm@1 155 refresh();
rlm@1 156 }
rlm@1 157
rlm@1 158 BOOL Disassemble::OnInitDialog()
rlm@1 159 {
rlm@1 160 CDialog::OnInitDialog();
rlm@1 161
rlm@1 162 DIALOG_SIZER_START(sz)
rlm@1 163 DIALOG_SIZER_ENTRY(IDC_DISASSEMBLE, DS_SizeY)
rlm@1 164 DIALOG_SIZER_ENTRY(IDC_REFRESH, DS_MoveY)
rlm@1 165 DIALOG_SIZER_ENTRY(IDC_CLOSE, DS_MoveY)
rlm@1 166 DIALOG_SIZER_ENTRY(IDC_NEXT, DS_MoveY)
rlm@1 167 DIALOG_SIZER_ENTRY(IDC_AUTO_UPDATE, DS_MoveY)
rlm@1 168 DIALOG_SIZER_ENTRY(IDC_GOPC, DS_MoveY)
rlm@1 169 DIALOG_SIZER_ENTRY(IDC_VSCROLL, DS_SizeY)
rlm@1 170 DIALOG_SIZER_END()
rlm@1 171 SetData(sz,
rlm@1 172 TRUE,
rlm@1 173 HKEY_CURRENT_USER,
rlm@1 174 "Software\\Emulators\\VisualBoyAdvance\\Viewer\\DisassembleView",
rlm@1 175 NULL);
rlm@1 176
rlm@1 177 SCROLLINFO si;
rlm@1 178 ZeroMemory(&si, sizeof(si));
rlm@1 179 si.cbSize = sizeof(si);
rlm@1 180 si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS;
rlm@1 181 si.nMin = 0;
rlm@1 182 si.nMax = 100;
rlm@1 183 si.nPos = 50;
rlm@1 184 si.nPage = 0;
rlm@1 185 GetDlgItem(IDC_VSCROLL)->SetScrollInfo(SB_CTL, &si, TRUE);
rlm@1 186
rlm@1 187 CFont *font = CFont::FromHandle((HFONT)GetStockObject(SYSTEM_FIXED_FONT));
rlm@1 188 m_list.SetFont(font, FALSE);
rlm@1 189 for (int i = 0; i < 17; i++)
rlm@1 190 GetDlgItem(IDC_R0+i)->SetFont(font, FALSE);
rlm@1 191
rlm@1 192 GetDlgItem(IDC_MODE)->SetFont(font, FALSE);
rlm@1 193
rlm@1 194 m_address.LimitText(8);
rlm@1 195 refresh();
rlm@1 196
rlm@1 197 return TRUE; // return TRUE unless you set the focus to a control
rlm@1 198 // EXCEPTION: OCX Property Pages should return FALSE
rlm@1 199 }
rlm@1 200
rlm@1 201 void Disassemble::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar*pScrollBar)
rlm@1 202 {
rlm@1 203 switch (nSBCode)
rlm@1 204 {
rlm@1 205 case SB_LINEDOWN:
rlm@1 206 if (mode == 0)
rlm@1 207 {
rlm@1 208 if (armState)
rlm@1 209 address += 4;
rlm@1 210 else
rlm@1 211 address += 2;
rlm@1 212 }
rlm@1 213 else if (mode == 1)
rlm@1 214 address += 4;
rlm@1 215 else
rlm@1 216 address += 2;
rlm@1 217 break;
rlm@1 218 case SB_LINEUP:
rlm@1 219 if (mode == 0)
rlm@1 220 {
rlm@1 221 if (armState)
rlm@1 222 address -= 4;
rlm@1 223 else
rlm@1 224 address -= 2;
rlm@1 225 }
rlm@1 226 else if (mode == 1)
rlm@1 227 address -= 4;
rlm@1 228 else
rlm@1 229 address -= 2;
rlm@1 230 break;
rlm@1 231 case SB_PAGEDOWN:
rlm@1 232 if (mode == 0)
rlm@1 233 {
rlm@1 234 if (armState)
rlm@1 235 address += count*4;
rlm@1 236 else
rlm@1 237 address += count*2;
rlm@1 238 }
rlm@1 239 else if (mode == 1)
rlm@1 240 address += count*4;
rlm@1 241 else
rlm@1 242 address += count*2;
rlm@1 243 break;
rlm@1 244 case SB_PAGEUP:
rlm@1 245 if (mode == 0)
rlm@1 246 {
rlm@1 247 if (armState)
rlm@1 248 address -= count*4;
rlm@1 249 else
rlm@1 250 address -= count*2;
rlm@1 251 }
rlm@1 252 else if (mode == 1)
rlm@1 253 address -= count*4;
rlm@1 254 else
rlm@1 255 address -= count*2;
rlm@1 256 break;
rlm@1 257 }
rlm@1 258 refresh();
rlm@1 259
rlm@1 260 CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
rlm@1 261 }
rlm@1 262
rlm@1 263 void Disassemble::refresh()
rlm@1 264 {
rlm@1 265 if (rom == NULL)
rlm@1 266 return;
rlm@1 267
rlm@1 268 bool8 arm = armState;
rlm@1 269
rlm@1 270 if (mode != 0)
rlm@1 271 {
rlm@1 272 if (mode == 1)
rlm@1 273 arm = true;
rlm@1 274 else
rlm@1 275 arm = false;
rlm@1 276 }
rlm@1 277
rlm@1 278 int h = m_list.GetItemHeight(0);
rlm@1 279 RECT r;
rlm@1 280 m_list.GetClientRect(&r);
rlm@1 281 count = (r.bottom - r.top+1)/h;
rlm@1 282
rlm@1 283 m_list.ResetContent();
rlm@1 284 if (!systemIsEmulating() && systemCartridgeType == 0)
rlm@1 285 return;
rlm@1 286
rlm@1 287 char buffer[80];
rlm@1 288 u32 addr = address;
rlm@1 289 int i;
rlm@1 290 int sel = -1;
rlm@1 291 for (i = 0; i < count; i++)
rlm@1 292 {
rlm@1 293 if (addr == armNextPC)
rlm@1 294 sel = i;
rlm@1 295 if (arm)
rlm@1 296 {
rlm@1 297 addr += disArm(addr, buffer, 3);
rlm@1 298 }
rlm@1 299 else
rlm@1 300 {
rlm@1 301 addr += disThumb(addr, buffer, 3);
rlm@1 302 }
rlm@1 303 m_list.InsertString(-1, buffer);
rlm@1 304 }
rlm@1 305
rlm@1 306 if (sel != -1)
rlm@1 307 m_list.SetCurSel(sel);
rlm@1 308
rlm@1 309 CPUUpdateCPSR();
rlm@1 310
rlm@1 311 for (i = 0; i < 17; i++)
rlm@1 312 {
rlm@1 313 sprintf(buffer, "%08x", reg[i].I);
rlm@1 314 GetDlgItem(IDC_R0+i)->SetWindowText(buffer);
rlm@1 315 }
rlm@1 316
rlm@1 317 m_n = (reg[16].I & 0x80000000) != 0;
rlm@1 318 m_z = (reg[16].I & 0x40000000) != 0;
rlm@1 319 m_c = (reg[16].I & 0x20000000) != 0;
rlm@1 320 m_v = (reg[16].I & 0x10000000) != 0;
rlm@1 321 m_i = (reg[16].I & 0x80) != 0;
rlm@1 322 m_f = (reg[16].I & 0x40) != 0;
rlm@1 323 m_t = (reg[16].I & 0x20) != 0;
rlm@1 324
rlm@1 325 UpdateData(FALSE);
rlm@1 326
rlm@1 327 int v = reg[16].I & 0x1f;
rlm@1 328 sprintf(buffer, "%02x", v);
rlm@1 329 GetDlgItem(IDC_MODE)->SetWindowText(buffer);
rlm@1 330 }
rlm@1 331
rlm@1 332 void Disassemble::update()
rlm@1 333 {
rlm@1 334 OnGopc();
rlm@1 335 refresh();
rlm@1 336 }
rlm@1 337
rlm@1 338 void Disassemble::PostNcDestroy()
rlm@1 339 {
rlm@1 340 delete this;
rlm@1 341 }
rlm@1 342