diff src/win32/GBDisassemble.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/GBDisassemble.cpp	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,241 @@
     1.4 +// GBDisassemble.cpp : implementation file
     1.5 +//
     1.6 +
     1.7 +#include "stdafx.h"
     1.8 +#include "resource.h"
     1.9 +#include "GBDisassemble.h"
    1.10 +#include "VBA.h"
    1.11 +
    1.12 +#include "../gb/GB.h"
    1.13 +#include "../gb/gbGlobals.h"
    1.14 +
    1.15 +extern gbRegister AF;
    1.16 +extern gbRegister BC;
    1.17 +extern gbRegister DE;
    1.18 +extern gbRegister HL;
    1.19 +extern gbRegister SP;
    1.20 +extern gbRegister PC;
    1.21 +extern u16        IFF;
    1.22 +extern int        gbDis(char *, u16);
    1.23 +
    1.24 +/////////////////////////////////////////////////////////////////////////////
    1.25 +// GBDisassemble dialog
    1.26 +
    1.27 +GBDisassemble::GBDisassemble(CWnd*pParent /*=NULL*/)
    1.28 +	: ResizeDlg(GBDisassemble::IDD, pParent)
    1.29 +{
    1.30 +	//{{AFX_DATA_INIT(GBDisassemble)
    1.31 +	m_c = FALSE;
    1.32 +	m_h = FALSE;
    1.33 +	m_n = FALSE;
    1.34 +	m_z = FALSE;
    1.35 +	//}}AFX_DATA_INIT
    1.36 +	address     = 0;
    1.37 +	autoUpdate  = false;
    1.38 +	count       = 1;
    1.39 +	lastAddress = 0;
    1.40 +}
    1.41 +
    1.42 +void GBDisassemble::DoDataExchange(CDataExchange*pDX)
    1.43 +{
    1.44 +	CDialog::DoDataExchange(pDX);
    1.45 +	//{{AFX_DATA_MAP(GBDisassemble)
    1.46 +	DDX_Control(pDX, IDC_ADDRESS, m_address);
    1.47 +	DDX_Control(pDX, IDC_DISASSEMBLE, m_list);
    1.48 +	DDX_Check(pDX, IDC_C, m_c);
    1.49 +	DDX_Check(pDX, IDC_H, m_h);
    1.50 +	DDX_Check(pDX, IDC_N, m_n);
    1.51 +	DDX_Check(pDX, IDC_Z, m_z);
    1.52 +	//}}AFX_DATA_MAP
    1.53 +}
    1.54 +
    1.55 +BEGIN_MESSAGE_MAP(GBDisassemble, CDialog)
    1.56 +//{{AFX_MSG_MAP(GBDisassemble)
    1.57 +ON_BN_CLICKED(IDC_CLOSE, OnClose)
    1.58 +ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
    1.59 +ON_BN_CLICKED(IDC_NEXT, OnNext)
    1.60 +ON_BN_CLICKED(IDC_GO, OnGo)
    1.61 +ON_BN_CLICKED(IDC_GOPC, OnGopc)
    1.62 +ON_BN_CLICKED(IDC_AUTO_UPDATE, OnAutoUpdate)
    1.63 +ON_WM_VSCROLL()
    1.64 +//}}AFX_MSG_MAP
    1.65 +END_MESSAGE_MAP()
    1.66 +
    1.67 +/////////////////////////////////////////////////////////////////////////////
    1.68 +// GBDisassemble message handlers
    1.69 +
    1.70 +void GBDisassemble::OnClose()
    1.71 +{
    1.72 +	theApp.winRemoveUpdateListener(this);
    1.73 +
    1.74 +	DestroyWindow();
    1.75 +}
    1.76 +
    1.77 +void GBDisassemble::OnRefresh()
    1.78 +{
    1.79 +	refresh();
    1.80 +}
    1.81 +
    1.82 +void GBDisassemble::OnNext()
    1.83 +{
    1.84 +	gbEmulate(1);
    1.85 +	if (PC.W < address || PC.W >= lastAddress)
    1.86 +		OnGopc();
    1.87 +	refresh();
    1.88 +}
    1.89 +
    1.90 +void GBDisassemble::OnGo()
    1.91 +{
    1.92 +	CString buffer;
    1.93 +	m_address.GetWindowText(buffer);
    1.94 +	sscanf(buffer, "%x", &address);
    1.95 +	refresh();
    1.96 +}
    1.97 +
    1.98 +void GBDisassemble::OnGopc()
    1.99 +{
   1.100 +	address = PC.W;
   1.101 +
   1.102 +	refresh();
   1.103 +}
   1.104 +
   1.105 +void GBDisassemble::OnAutoUpdate()
   1.106 +{
   1.107 +	autoUpdate = !autoUpdate;
   1.108 +	if (autoUpdate)
   1.109 +	{
   1.110 +		theApp.winAddUpdateListener(this);
   1.111 +	}
   1.112 +	else
   1.113 +	{
   1.114 +		theApp.winRemoveUpdateListener(this);
   1.115 +	}
   1.116 +}
   1.117 +
   1.118 +BOOL GBDisassemble::OnInitDialog()
   1.119 +{
   1.120 +	CDialog::OnInitDialog();
   1.121 +
   1.122 +	DIALOG_SIZER_START(sz)
   1.123 +	DIALOG_SIZER_ENTRY(IDC_DISASSEMBLE, DS_SizeY)
   1.124 +	DIALOG_SIZER_ENTRY(IDC_REFRESH, DS_MoveY)
   1.125 +	DIALOG_SIZER_ENTRY(IDC_CLOSE, DS_MoveY)
   1.126 +	DIALOG_SIZER_ENTRY(IDC_NEXT,  DS_MoveY)
   1.127 +	DIALOG_SIZER_ENTRY(IDC_AUTO_UPDATE, DS_MoveY)
   1.128 +	DIALOG_SIZER_ENTRY(IDC_GOPC, DS_MoveY)
   1.129 +	DIALOG_SIZER_ENTRY(IDC_VSCROLL, DS_SizeY)
   1.130 +	DIALOG_SIZER_END()
   1.131 +	SetData(sz,
   1.132 +	        TRUE,
   1.133 +	        HKEY_CURRENT_USER,
   1.134 +	        "Software\\Emulators\\VisualBoyAdvance\\Viewer\\GBDisassembleView",
   1.135 +	        NULL);
   1.136 +
   1.137 +	SCROLLINFO si;
   1.138 +	ZeroMemory(&si, sizeof(si));
   1.139 +	si.cbSize = sizeof(si);
   1.140 +	si.fMask  = SIF_PAGE | SIF_RANGE | SIF_POS;
   1.141 +	si.nMin   = 0;
   1.142 +	si.nMax   = 100;
   1.143 +	si.nPos   = 50;
   1.144 +	si.nPage  = 0;
   1.145 +	GetDlgItem(IDC_VSCROLL)->SetScrollInfo(SB_CTL, &si, TRUE);
   1.146 +	CFont *font = CFont::FromHandle((HFONT)GetStockObject(SYSTEM_FIXED_FONT));
   1.147 +	m_list.SetFont(font);
   1.148 +
   1.149 +	for (int i = 0; i < 7; i++)
   1.150 +		GetDlgItem(IDC_R0+i)->SetFont(font);
   1.151 +
   1.152 +	m_address.LimitText(4);
   1.153 +	refresh();
   1.154 +
   1.155 +	return TRUE; // return TRUE unless you set the focus to a control
   1.156 +	             // EXCEPTION: OCX Property Pages should return FALSE
   1.157 +}
   1.158 +
   1.159 +void GBDisassemble::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar*pScrollBar)
   1.160 +{
   1.161 +	char buffer[80];
   1.162 +
   1.163 +	switch (nSBCode)
   1.164 +	{
   1.165 +	case SB_LINEDOWN:
   1.166 +		address += gbDis(buffer, address);
   1.167 +		break;
   1.168 +	case SB_LINEUP:
   1.169 +		address--;
   1.170 +		break;
   1.171 +	case SB_PAGEDOWN:
   1.172 +		address = lastAddress;
   1.173 +		break;
   1.174 +	case SB_PAGEUP:
   1.175 +		address -= count;
   1.176 +		break;
   1.177 +	}
   1.178 +	refresh();
   1.179 +
   1.180 +	CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
   1.181 +}
   1.182 +
   1.183 +void GBDisassemble::refresh()
   1.184 +{
   1.185 +	if (gbRom == NULL)
   1.186 +		return;
   1.187 +
   1.188 +	int  h = m_list.GetItemHeight(0);
   1.189 +	RECT r;
   1.190 +	m_list.GetClientRect(&r);
   1.191 +	count = (r.bottom - r.top+1)/h;
   1.192 +
   1.193 +	m_list.ResetContent();
   1.194 +	if (!systemIsEmulating() || systemCartridgeType != 1)
   1.195 +		return;
   1.196 +
   1.197 +	char buffer[80];
   1.198 +	u16  addr = address;
   1.199 +	int  i;
   1.200 +	int  sel = -1;
   1.201 +	for (i = 0; i < count; i++)
   1.202 +	{
   1.203 +		if (addr == PC.W)
   1.204 +			sel = i;
   1.205 +		addr += gbDis(buffer, addr);
   1.206 +		m_list.InsertString(-1, buffer);
   1.207 +	}
   1.208 +	lastAddress = addr-1;
   1.209 +	if (sel != -1)
   1.210 +		m_list.SetCurSel(sel);
   1.211 +
   1.212 +	sprintf(buffer, "%04x", AF.W);
   1.213 +	GetDlgItem(IDC_R0)->SetWindowText(buffer);
   1.214 +	sprintf(buffer, "%04x", BC.W);
   1.215 +	GetDlgItem(IDC_R1)->SetWindowText(buffer);
   1.216 +	sprintf(buffer, "%04x", DE.W);
   1.217 +	GetDlgItem(IDC_R2)->SetWindowText(buffer);
   1.218 +	sprintf(buffer, "%04x", HL.W);
   1.219 +	GetDlgItem(IDC_R3)->SetWindowText(buffer);
   1.220 +	sprintf(buffer, "%04x", SP.W);
   1.221 +	GetDlgItem(IDC_R4)->SetWindowText(buffer);
   1.222 +	sprintf(buffer, "%04x", PC.W);
   1.223 +	GetDlgItem(IDC_R5)->SetWindowText(buffer);
   1.224 +	sprintf(buffer, "%04x", IFF);
   1.225 +	GetDlgItem(IDC_R6)->SetWindowText(buffer);
   1.226 +
   1.227 +	m_z = (AF.B.B0 & 0x80) != 0;
   1.228 +	m_n = (AF.B.B0 & 0x40) != 0;
   1.229 +	m_h = (AF.B.B0 & 0x20) != 0;
   1.230 +	m_c = (AF.B.B0 & 0x10) != 0;
   1.231 +	UpdateData(FALSE);
   1.232 +}
   1.233 +
   1.234 +void GBDisassemble::update()
   1.235 +{
   1.236 +	OnGopc();
   1.237 +	refresh();
   1.238 +}
   1.239 +
   1.240 +void GBDisassemble::PostNcDestroy()
   1.241 +{
   1.242 +	delete this;
   1.243 +}
   1.244 +