Mercurial > vba-clojure
diff src/win32/Disassemble.cpp @ 1:f9f4f1b99eed
importing src directory
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:31:27 -0600 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/win32/Disassemble.cpp Sat Mar 03 10:31:27 2012 -0600 1.3 @@ -0,0 +1,342 @@ 1.4 +// Disassemble.cpp : implementation file 1.5 +// 1.6 + 1.7 +#include "stdafx.h" 1.8 +#include "resource.h" 1.9 +#include "Disassemble.h" 1.10 +#include "VBA.h" 1.11 + 1.12 +#include "../gba/armdis.h" 1.13 +#include "../gba/GBA.h" 1.14 +#include "../gba/GBAGlobals.h" 1.15 + 1.16 +extern void CPUUpdateCPSR(); 1.17 + 1.18 +///////////////////////////////////////////////////////////////////////////// 1.19 +// Disassemble dialog 1.20 + 1.21 +Disassemble::Disassemble(CWnd*pParent /*=NULL*/) 1.22 + : ResizeDlg(Disassemble::IDD, pParent) 1.23 +{ 1.24 + //{{AFX_DATA_INIT(Disassemble) 1.25 + m_c = FALSE; 1.26 + m_f = FALSE; 1.27 + m_i = FALSE; 1.28 + m_n = FALSE; 1.29 + m_t = FALSE; 1.30 + m_v = FALSE; 1.31 + m_z = FALSE; 1.32 + //}}AFX_DATA_INIT 1.33 + autoUpdate = false; 1.34 + address = 0; 1.35 + count = 1; 1.36 + mode = 0; 1.37 +} 1.38 + 1.39 +void Disassemble::DoDataExchange(CDataExchange*pDX) 1.40 +{ 1.41 + CDialog::DoDataExchange(pDX); 1.42 + //{{AFX_DATA_MAP(Disassemble) 1.43 + DDX_Control(pDX, IDC_ADDRESS, m_address); 1.44 + DDX_Control(pDX, IDC_DISASSEMBLE, m_list); 1.45 + DDX_Check(pDX, IDC_C, m_c); 1.46 + DDX_Check(pDX, IDC_F, m_f); 1.47 + DDX_Check(pDX, IDC_I, m_i); 1.48 + DDX_Check(pDX, IDC_N, m_n); 1.49 + DDX_Check(pDX, IDC_T, m_t); 1.50 + DDX_Check(pDX, IDC_V, m_v); 1.51 + DDX_Check(pDX, IDC_Z, m_z); 1.52 + DDX_Radio(pDX, IDC_AUTOMATIC, mode); 1.53 + //}}AFX_DATA_MAP 1.54 +} 1.55 + 1.56 +BEGIN_MESSAGE_MAP(Disassemble, CDialog) 1.57 +//{{AFX_MSG_MAP(Disassemble) 1.58 +ON_BN_CLICKED(IDC_AUTO_UPDATE, OnAutoUpdate) 1.59 +ON_BN_CLICKED(IDC_AUTOMATIC, OnAutomatic) 1.60 +ON_BN_CLICKED(IDC_ARM, OnArm) 1.61 +ON_BN_CLICKED(IDC_CLOSE, OnClose) 1.62 +ON_BN_CLICKED(IDC_GO, OnGo) 1.63 +ON_BN_CLICKED(IDC_GOPC, OnGopc) 1.64 +ON_BN_CLICKED(IDC_NEXT, OnNext) 1.65 +ON_BN_CLICKED(IDC_REFRESH, OnRefresh) 1.66 +ON_BN_CLICKED(IDC_THUMB, OnThumb) 1.67 +ON_WM_VSCROLL() 1.68 +//}}AFX_MSG_MAP 1.69 +END_MESSAGE_MAP() 1.70 + 1.71 +///////////////////////////////////////////////////////////////////////////// 1.72 +// Disassemble message handlers 1.73 + 1.74 +void Disassemble::OnAutoUpdate() 1.75 +{ 1.76 + autoUpdate = !autoUpdate; 1.77 + if (autoUpdate) 1.78 + { 1.79 + theApp.winAddUpdateListener(this); 1.80 + } 1.81 + else 1.82 + { 1.83 + theApp.winRemoveUpdateListener(this); 1.84 + } 1.85 +} 1.86 + 1.87 +void Disassemble::OnAutomatic() 1.88 +{ 1.89 + mode = 0; 1.90 + refresh(); 1.91 +} 1.92 + 1.93 +void Disassemble::OnArm() 1.94 +{ 1.95 + mode = 1; 1.96 + refresh(); 1.97 +} 1.98 + 1.99 +void Disassemble::OnClose() 1.100 +{ 1.101 + theApp.winRemoveUpdateListener(this); 1.102 + 1.103 + DestroyWindow(); 1.104 +} 1.105 + 1.106 +void Disassemble::OnGo() 1.107 +{ 1.108 + CString buffer; 1.109 + m_address.GetWindowText(buffer); 1.110 + sscanf(buffer, "%x", &address); 1.111 + refresh(); 1.112 +} 1.113 + 1.114 +void Disassemble::OnGopc() 1.115 +{ 1.116 + if (armState) 1.117 + address = armNextPC - 16; 1.118 + else 1.119 + address = armNextPC - 8; 1.120 + 1.121 + refresh(); 1.122 +} 1.123 + 1.124 +void Disassemble::OnNext() 1.125 +{ 1.126 + CPULoop(1); 1.127 + if (armState) 1.128 + { 1.129 + u32 total = address+count*4; 1.130 + if (armNextPC >= address && armNextPC < total) 1.131 + {} 1.132 + else 1.133 + { 1.134 + OnGopc(); 1.135 + } 1.136 + } 1.137 + else 1.138 + { 1.139 + u32 total = address+count*2; 1.140 + if (armNextPC >= address && armNextPC < total) 1.141 + {} 1.142 + else 1.143 + { 1.144 + OnGopc(); 1.145 + } 1.146 + } 1.147 + refresh(); 1.148 +} 1.149 + 1.150 +void Disassemble::OnRefresh() 1.151 +{ 1.152 + refresh(); 1.153 +} 1.154 + 1.155 +void Disassemble::OnThumb() 1.156 +{ 1.157 + mode = 2; 1.158 + refresh(); 1.159 +} 1.160 + 1.161 +BOOL Disassemble::OnInitDialog() 1.162 +{ 1.163 + CDialog::OnInitDialog(); 1.164 + 1.165 + DIALOG_SIZER_START(sz) 1.166 + DIALOG_SIZER_ENTRY(IDC_DISASSEMBLE, DS_SizeY) 1.167 + DIALOG_SIZER_ENTRY(IDC_REFRESH, DS_MoveY) 1.168 + DIALOG_SIZER_ENTRY(IDC_CLOSE, DS_MoveY) 1.169 + DIALOG_SIZER_ENTRY(IDC_NEXT, DS_MoveY) 1.170 + DIALOG_SIZER_ENTRY(IDC_AUTO_UPDATE, DS_MoveY) 1.171 + DIALOG_SIZER_ENTRY(IDC_GOPC, DS_MoveY) 1.172 + DIALOG_SIZER_ENTRY(IDC_VSCROLL, DS_SizeY) 1.173 + DIALOG_SIZER_END() 1.174 + SetData(sz, 1.175 + TRUE, 1.176 + HKEY_CURRENT_USER, 1.177 + "Software\\Emulators\\VisualBoyAdvance\\Viewer\\DisassembleView", 1.178 + NULL); 1.179 + 1.180 + SCROLLINFO si; 1.181 + ZeroMemory(&si, sizeof(si)); 1.182 + si.cbSize = sizeof(si); 1.183 + si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS; 1.184 + si.nMin = 0; 1.185 + si.nMax = 100; 1.186 + si.nPos = 50; 1.187 + si.nPage = 0; 1.188 + GetDlgItem(IDC_VSCROLL)->SetScrollInfo(SB_CTL, &si, TRUE); 1.189 + 1.190 + CFont *font = CFont::FromHandle((HFONT)GetStockObject(SYSTEM_FIXED_FONT)); 1.191 + m_list.SetFont(font, FALSE); 1.192 + for (int i = 0; i < 17; i++) 1.193 + GetDlgItem(IDC_R0+i)->SetFont(font, FALSE); 1.194 + 1.195 + GetDlgItem(IDC_MODE)->SetFont(font, FALSE); 1.196 + 1.197 + m_address.LimitText(8); 1.198 + refresh(); 1.199 + 1.200 + return TRUE; // return TRUE unless you set the focus to a control 1.201 + // EXCEPTION: OCX Property Pages should return FALSE 1.202 +} 1.203 + 1.204 +void Disassemble::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar*pScrollBar) 1.205 +{ 1.206 + switch (nSBCode) 1.207 + { 1.208 + case SB_LINEDOWN: 1.209 + if (mode == 0) 1.210 + { 1.211 + if (armState) 1.212 + address += 4; 1.213 + else 1.214 + address += 2; 1.215 + } 1.216 + else if (mode == 1) 1.217 + address += 4; 1.218 + else 1.219 + address += 2; 1.220 + break; 1.221 + case SB_LINEUP: 1.222 + if (mode == 0) 1.223 + { 1.224 + if (armState) 1.225 + address -= 4; 1.226 + else 1.227 + address -= 2; 1.228 + } 1.229 + else if (mode == 1) 1.230 + address -= 4; 1.231 + else 1.232 + address -= 2; 1.233 + break; 1.234 + case SB_PAGEDOWN: 1.235 + if (mode == 0) 1.236 + { 1.237 + if (armState) 1.238 + address += count*4; 1.239 + else 1.240 + address += count*2; 1.241 + } 1.242 + else if (mode == 1) 1.243 + address += count*4; 1.244 + else 1.245 + address += count*2; 1.246 + break; 1.247 + case SB_PAGEUP: 1.248 + if (mode == 0) 1.249 + { 1.250 + if (armState) 1.251 + address -= count*4; 1.252 + else 1.253 + address -= count*2; 1.254 + } 1.255 + else if (mode == 1) 1.256 + address -= count*4; 1.257 + else 1.258 + address -= count*2; 1.259 + break; 1.260 + } 1.261 + refresh(); 1.262 + 1.263 + CDialog::OnVScroll(nSBCode, nPos, pScrollBar); 1.264 +} 1.265 + 1.266 +void Disassemble::refresh() 1.267 +{ 1.268 + if (rom == NULL) 1.269 + return; 1.270 + 1.271 + bool8 arm = armState; 1.272 + 1.273 + if (mode != 0) 1.274 + { 1.275 + if (mode == 1) 1.276 + arm = true; 1.277 + else 1.278 + arm = false; 1.279 + } 1.280 + 1.281 + int h = m_list.GetItemHeight(0); 1.282 + RECT r; 1.283 + m_list.GetClientRect(&r); 1.284 + count = (r.bottom - r.top+1)/h; 1.285 + 1.286 + m_list.ResetContent(); 1.287 + if (!systemIsEmulating() && systemCartridgeType == 0) 1.288 + return; 1.289 + 1.290 + char buffer[80]; 1.291 + u32 addr = address; 1.292 + int i; 1.293 + int sel = -1; 1.294 + for (i = 0; i < count; i++) 1.295 + { 1.296 + if (addr == armNextPC) 1.297 + sel = i; 1.298 + if (arm) 1.299 + { 1.300 + addr += disArm(addr, buffer, 3); 1.301 + } 1.302 + else 1.303 + { 1.304 + addr += disThumb(addr, buffer, 3); 1.305 + } 1.306 + m_list.InsertString(-1, buffer); 1.307 + } 1.308 + 1.309 + if (sel != -1) 1.310 + m_list.SetCurSel(sel); 1.311 + 1.312 + CPUUpdateCPSR(); 1.313 + 1.314 + for (i = 0; i < 17; i++) 1.315 + { 1.316 + sprintf(buffer, "%08x", reg[i].I); 1.317 + GetDlgItem(IDC_R0+i)->SetWindowText(buffer); 1.318 + } 1.319 + 1.320 + m_n = (reg[16].I & 0x80000000) != 0; 1.321 + m_z = (reg[16].I & 0x40000000) != 0; 1.322 + m_c = (reg[16].I & 0x20000000) != 0; 1.323 + m_v = (reg[16].I & 0x10000000) != 0; 1.324 + m_i = (reg[16].I & 0x80) != 0; 1.325 + m_f = (reg[16].I & 0x40) != 0; 1.326 + m_t = (reg[16].I & 0x20) != 0; 1.327 + 1.328 + UpdateData(FALSE); 1.329 + 1.330 + int v = reg[16].I & 0x1f; 1.331 + sprintf(buffer, "%02x", v); 1.332 + GetDlgItem(IDC_MODE)->SetWindowText(buffer); 1.333 +} 1.334 + 1.335 +void Disassemble::update() 1.336 +{ 1.337 + OnGopc(); 1.338 + refresh(); 1.339 +} 1.340 + 1.341 +void Disassemble::PostNcDestroy() 1.342 +{ 1.343 + delete this; 1.344 +} 1.345 +