annotate src/win32/GBDisassemble.cpp @ 2:3549bbe597ed

adding makefile.am
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:47 -0600
parents f9f4f1b99eed
children
rev   line source
rlm@1 1 // GBDisassemble.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 "GBDisassemble.h"
rlm@1 7 #include "VBA.h"
rlm@1 8
rlm@1 9 #include "../gb/GB.h"
rlm@1 10 #include "../gb/gbGlobals.h"
rlm@1 11
rlm@1 12 extern gbRegister AF;
rlm@1 13 extern gbRegister BC;
rlm@1 14 extern gbRegister DE;
rlm@1 15 extern gbRegister HL;
rlm@1 16 extern gbRegister SP;
rlm@1 17 extern gbRegister PC;
rlm@1 18 extern u16 IFF;
rlm@1 19 extern int gbDis(char *, u16);
rlm@1 20
rlm@1 21 /////////////////////////////////////////////////////////////////////////////
rlm@1 22 // GBDisassemble dialog
rlm@1 23
rlm@1 24 GBDisassemble::GBDisassemble(CWnd*pParent /*=NULL*/)
rlm@1 25 : ResizeDlg(GBDisassemble::IDD, pParent)
rlm@1 26 {
rlm@1 27 //{{AFX_DATA_INIT(GBDisassemble)
rlm@1 28 m_c = FALSE;
rlm@1 29 m_h = FALSE;
rlm@1 30 m_n = FALSE;
rlm@1 31 m_z = FALSE;
rlm@1 32 //}}AFX_DATA_INIT
rlm@1 33 address = 0;
rlm@1 34 autoUpdate = false;
rlm@1 35 count = 1;
rlm@1 36 lastAddress = 0;
rlm@1 37 }
rlm@1 38
rlm@1 39 void GBDisassemble::DoDataExchange(CDataExchange*pDX)
rlm@1 40 {
rlm@1 41 CDialog::DoDataExchange(pDX);
rlm@1 42 //{{AFX_DATA_MAP(GBDisassemble)
rlm@1 43 DDX_Control(pDX, IDC_ADDRESS, m_address);
rlm@1 44 DDX_Control(pDX, IDC_DISASSEMBLE, m_list);
rlm@1 45 DDX_Check(pDX, IDC_C, m_c);
rlm@1 46 DDX_Check(pDX, IDC_H, m_h);
rlm@1 47 DDX_Check(pDX, IDC_N, m_n);
rlm@1 48 DDX_Check(pDX, IDC_Z, m_z);
rlm@1 49 //}}AFX_DATA_MAP
rlm@1 50 }
rlm@1 51
rlm@1 52 BEGIN_MESSAGE_MAP(GBDisassemble, CDialog)
rlm@1 53 //{{AFX_MSG_MAP(GBDisassemble)
rlm@1 54 ON_BN_CLICKED(IDC_CLOSE, OnClose)
rlm@1 55 ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
rlm@1 56 ON_BN_CLICKED(IDC_NEXT, OnNext)
rlm@1 57 ON_BN_CLICKED(IDC_GO, OnGo)
rlm@1 58 ON_BN_CLICKED(IDC_GOPC, OnGopc)
rlm@1 59 ON_BN_CLICKED(IDC_AUTO_UPDATE, OnAutoUpdate)
rlm@1 60 ON_WM_VSCROLL()
rlm@1 61 //}}AFX_MSG_MAP
rlm@1 62 END_MESSAGE_MAP()
rlm@1 63
rlm@1 64 /////////////////////////////////////////////////////////////////////////////
rlm@1 65 // GBDisassemble message handlers
rlm@1 66
rlm@1 67 void GBDisassemble::OnClose()
rlm@1 68 {
rlm@1 69 theApp.winRemoveUpdateListener(this);
rlm@1 70
rlm@1 71 DestroyWindow();
rlm@1 72 }
rlm@1 73
rlm@1 74 void GBDisassemble::OnRefresh()
rlm@1 75 {
rlm@1 76 refresh();
rlm@1 77 }
rlm@1 78
rlm@1 79 void GBDisassemble::OnNext()
rlm@1 80 {
rlm@1 81 gbEmulate(1);
rlm@1 82 if (PC.W < address || PC.W >= lastAddress)
rlm@1 83 OnGopc();
rlm@1 84 refresh();
rlm@1 85 }
rlm@1 86
rlm@1 87 void GBDisassemble::OnGo()
rlm@1 88 {
rlm@1 89 CString buffer;
rlm@1 90 m_address.GetWindowText(buffer);
rlm@1 91 sscanf(buffer, "%x", &address);
rlm@1 92 refresh();
rlm@1 93 }
rlm@1 94
rlm@1 95 void GBDisassemble::OnGopc()
rlm@1 96 {
rlm@1 97 address = PC.W;
rlm@1 98
rlm@1 99 refresh();
rlm@1 100 }
rlm@1 101
rlm@1 102 void GBDisassemble::OnAutoUpdate()
rlm@1 103 {
rlm@1 104 autoUpdate = !autoUpdate;
rlm@1 105 if (autoUpdate)
rlm@1 106 {
rlm@1 107 theApp.winAddUpdateListener(this);
rlm@1 108 }
rlm@1 109 else
rlm@1 110 {
rlm@1 111 theApp.winRemoveUpdateListener(this);
rlm@1 112 }
rlm@1 113 }
rlm@1 114
rlm@1 115 BOOL GBDisassemble::OnInitDialog()
rlm@1 116 {
rlm@1 117 CDialog::OnInitDialog();
rlm@1 118
rlm@1 119 DIALOG_SIZER_START(sz)
rlm@1 120 DIALOG_SIZER_ENTRY(IDC_DISASSEMBLE, DS_SizeY)
rlm@1 121 DIALOG_SIZER_ENTRY(IDC_REFRESH, DS_MoveY)
rlm@1 122 DIALOG_SIZER_ENTRY(IDC_CLOSE, DS_MoveY)
rlm@1 123 DIALOG_SIZER_ENTRY(IDC_NEXT, DS_MoveY)
rlm@1 124 DIALOG_SIZER_ENTRY(IDC_AUTO_UPDATE, DS_MoveY)
rlm@1 125 DIALOG_SIZER_ENTRY(IDC_GOPC, DS_MoveY)
rlm@1 126 DIALOG_SIZER_ENTRY(IDC_VSCROLL, DS_SizeY)
rlm@1 127 DIALOG_SIZER_END()
rlm@1 128 SetData(sz,
rlm@1 129 TRUE,
rlm@1 130 HKEY_CURRENT_USER,
rlm@1 131 "Software\\Emulators\\VisualBoyAdvance\\Viewer\\GBDisassembleView",
rlm@1 132 NULL);
rlm@1 133
rlm@1 134 SCROLLINFO si;
rlm@1 135 ZeroMemory(&si, sizeof(si));
rlm@1 136 si.cbSize = sizeof(si);
rlm@1 137 si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS;
rlm@1 138 si.nMin = 0;
rlm@1 139 si.nMax = 100;
rlm@1 140 si.nPos = 50;
rlm@1 141 si.nPage = 0;
rlm@1 142 GetDlgItem(IDC_VSCROLL)->SetScrollInfo(SB_CTL, &si, TRUE);
rlm@1 143 CFont *font = CFont::FromHandle((HFONT)GetStockObject(SYSTEM_FIXED_FONT));
rlm@1 144 m_list.SetFont(font);
rlm@1 145
rlm@1 146 for (int i = 0; i < 7; i++)
rlm@1 147 GetDlgItem(IDC_R0+i)->SetFont(font);
rlm@1 148
rlm@1 149 m_address.LimitText(4);
rlm@1 150 refresh();
rlm@1 151
rlm@1 152 return TRUE; // return TRUE unless you set the focus to a control
rlm@1 153 // EXCEPTION: OCX Property Pages should return FALSE
rlm@1 154 }
rlm@1 155
rlm@1 156 void GBDisassemble::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar*pScrollBar)
rlm@1 157 {
rlm@1 158 char buffer[80];
rlm@1 159
rlm@1 160 switch (nSBCode)
rlm@1 161 {
rlm@1 162 case SB_LINEDOWN:
rlm@1 163 address += gbDis(buffer, address);
rlm@1 164 break;
rlm@1 165 case SB_LINEUP:
rlm@1 166 address--;
rlm@1 167 break;
rlm@1 168 case SB_PAGEDOWN:
rlm@1 169 address = lastAddress;
rlm@1 170 break;
rlm@1 171 case SB_PAGEUP:
rlm@1 172 address -= count;
rlm@1 173 break;
rlm@1 174 }
rlm@1 175 refresh();
rlm@1 176
rlm@1 177 CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
rlm@1 178 }
rlm@1 179
rlm@1 180 void GBDisassemble::refresh()
rlm@1 181 {
rlm@1 182 if (gbRom == NULL)
rlm@1 183 return;
rlm@1 184
rlm@1 185 int h = m_list.GetItemHeight(0);
rlm@1 186 RECT r;
rlm@1 187 m_list.GetClientRect(&r);
rlm@1 188 count = (r.bottom - r.top+1)/h;
rlm@1 189
rlm@1 190 m_list.ResetContent();
rlm@1 191 if (!systemIsEmulating() || systemCartridgeType != 1)
rlm@1 192 return;
rlm@1 193
rlm@1 194 char buffer[80];
rlm@1 195 u16 addr = address;
rlm@1 196 int i;
rlm@1 197 int sel = -1;
rlm@1 198 for (i = 0; i < count; i++)
rlm@1 199 {
rlm@1 200 if (addr == PC.W)
rlm@1 201 sel = i;
rlm@1 202 addr += gbDis(buffer, addr);
rlm@1 203 m_list.InsertString(-1, buffer);
rlm@1 204 }
rlm@1 205 lastAddress = addr-1;
rlm@1 206 if (sel != -1)
rlm@1 207 m_list.SetCurSel(sel);
rlm@1 208
rlm@1 209 sprintf(buffer, "%04x", AF.W);
rlm@1 210 GetDlgItem(IDC_R0)->SetWindowText(buffer);
rlm@1 211 sprintf(buffer, "%04x", BC.W);
rlm@1 212 GetDlgItem(IDC_R1)->SetWindowText(buffer);
rlm@1 213 sprintf(buffer, "%04x", DE.W);
rlm@1 214 GetDlgItem(IDC_R2)->SetWindowText(buffer);
rlm@1 215 sprintf(buffer, "%04x", HL.W);
rlm@1 216 GetDlgItem(IDC_R3)->SetWindowText(buffer);
rlm@1 217 sprintf(buffer, "%04x", SP.W);
rlm@1 218 GetDlgItem(IDC_R4)->SetWindowText(buffer);
rlm@1 219 sprintf(buffer, "%04x", PC.W);
rlm@1 220 GetDlgItem(IDC_R5)->SetWindowText(buffer);
rlm@1 221 sprintf(buffer, "%04x", IFF);
rlm@1 222 GetDlgItem(IDC_R6)->SetWindowText(buffer);
rlm@1 223
rlm@1 224 m_z = (AF.B.B0 & 0x80) != 0;
rlm@1 225 m_n = (AF.B.B0 & 0x40) != 0;
rlm@1 226 m_h = (AF.B.B0 & 0x20) != 0;
rlm@1 227 m_c = (AF.B.B0 & 0x10) != 0;
rlm@1 228 UpdateData(FALSE);
rlm@1 229 }
rlm@1 230
rlm@1 231 void GBDisassemble::update()
rlm@1 232 {
rlm@1 233 OnGopc();
rlm@1 234 refresh();
rlm@1 235 }
rlm@1 236
rlm@1 237 void GBDisassemble::PostNcDestroy()
rlm@1 238 {
rlm@1 239 delete this;
rlm@1 240 }
rlm@1 241