view src/win32/GBDisassemble.cpp @ 4:5f6f2134e8ce

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