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