Mercurial > vba-linux
diff src/win32/IOViewer.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/IOViewer.cpp Sat Mar 03 10:31:27 2012 -0600 1.3 @@ -0,0 +1,183 @@ 1.4 +// IOViewer.cpp : implementation file 1.5 +// 1.6 + 1.7 +#include "stdafx.h" 1.8 +#include "resource.h" 1.9 +#include "IOViewer.h" 1.10 +#include "VBA.h" 1.11 + 1.12 +#include "../gba/GBA.h" // CPUWriteHalfWord 1.13 +#include "../gba/GBAGlobals.h" 1.14 + 1.15 +#include "IOViewerRegs.h" 1.16 + 1.17 +///////////////////////////////////////////////////////////////////////////// 1.18 +// IOViewer dialog 1.19 + 1.20 +IOViewer::IOViewer(CWnd*pParent /*=NULL*/) 1.21 + : ResizeDlg(IOViewer::IDD, pParent) 1.22 +{ 1.23 + //{{AFX_DATA_INIT(IOViewer) 1.24 + // NOTE: the ClassWizard will add member initialization here 1.25 + //}}AFX_DATA_INIT 1.26 + selected = 0; 1.27 + autoUpdate = false; 1.28 +} 1.29 + 1.30 +void IOViewer::DoDataExchange(CDataExchange*pDX) 1.31 +{ 1.32 + CDialog::DoDataExchange(pDX); 1.33 + //{{AFX_DATA_MAP(IOViewer) 1.34 + DDX_Control(pDX, IDC_VALUE, m_value); 1.35 + DDX_Control(pDX, IDC_ADDRESSES, m_address); 1.36 + //}}AFX_DATA_MAP 1.37 +} 1.38 + 1.39 +BEGIN_MESSAGE_MAP(IOViewer, CDialog) 1.40 +//{{AFX_MSG_MAP(IOViewer) 1.41 +ON_BN_CLICKED(IDC_CLOSE, OnClose) 1.42 +ON_BN_CLICKED(IDC_REFRESH, OnRefresh) 1.43 +ON_BN_CLICKED(IDC_AUTO_UPDATE, OnAutoUpdate) 1.44 +ON_CBN_SELCHANGE(IDC_ADDRESSES, OnSelchangeAddresses) 1.45 +ON_BN_CLICKED(IDC_APPLY, OnApply) 1.46 +//}}AFX_MSG_MAP 1.47 +END_MESSAGE_MAP() 1.48 + 1.49 +///////////////////////////////////////////////////////////////////////////// 1.50 +// IOViewer message handlers 1.51 + 1.52 +void IOViewer::OnClose() 1.53 +{ 1.54 + theApp.winRemoveUpdateListener(this); 1.55 + 1.56 + DestroyWindow(); 1.57 +} 1.58 + 1.59 +void IOViewer::OnRefresh() 1.60 +{ 1.61 + // TODO: Add your control notification handler code here 1.62 +} 1.63 + 1.64 +void IOViewer::OnAutoUpdate() 1.65 +{ 1.66 + autoUpdate = !autoUpdate; 1.67 + if (autoUpdate) 1.68 + { 1.69 + theApp.winAddUpdateListener(this); 1.70 + } 1.71 + else 1.72 + { 1.73 + theApp.winRemoveUpdateListener(this); 1.74 + } 1.75 +} 1.76 + 1.77 +void IOViewer::OnSelchangeAddresses() 1.78 +{ 1.79 + selected = m_address.GetCurSel(); 1.80 + 1.81 + update(); 1.82 +} 1.83 + 1.84 +void IOViewer::PostNcDestroy() 1.85 +{ 1.86 + delete this; 1.87 +} 1.88 + 1.89 +BOOL IOViewer::OnInitDialog() 1.90 +{ 1.91 + CDialog::OnInitDialog(); 1.92 + 1.93 + // winCenterWindow(getHandle()); 1.94 + DIALOG_SIZER_START(sz) 1.95 + DIALOG_SIZER_END() 1.96 + SetData(sz, 1.97 + TRUE, 1.98 + HKEY_CURRENT_USER, 1.99 + "Software\\Emulators\\VisualBoyAdvance\\Viewer\\IOView", 1.100 + NULL); 1.101 + 1.102 + CFont *font = CFont::FromHandle((HFONT)GetStockObject(SYSTEM_FIXED_FONT)); 1.103 + int i; 1.104 + for (i = 0; i < sizeof(ioViewRegisters)/sizeof(IOData); i++) 1.105 + { 1.106 + m_address.AddString(ioViewRegisters[i].name); 1.107 + } 1.108 + m_address.SetFont(font); 1.109 + for (i = 0; i < 16; i++) 1.110 + { 1.111 + GetDlgItem(IDC_BIT_0+i)->SetFont(font); 1.112 + } 1.113 + 1.114 + RECT cbSize; 1.115 + int Height; 1.116 + 1.117 + m_address.GetClientRect(&cbSize); 1.118 + Height = m_address.GetItemHeight(0); 1.119 + Height += m_address.GetItemHeight(0) * (10); 1.120 + 1.121 + // Note: The use of SM_CYEDGE assumes that we're using Windows '95 1.122 + // Now add on the height of the border of the edit box 1.123 + Height += GetSystemMetrics(SM_CYEDGE) * 2; // top & bottom edges 1.124 + 1.125 + // The height of the border of the drop-down box 1.126 + Height += GetSystemMetrics(SM_CYEDGE) * 2; // top & bottom edges 1.127 + 1.128 + // now set the size of the window 1.129 + m_address.SetWindowPos(NULL, 1.130 + 0, 0, 1.131 + cbSize.right, Height, 1.132 + SWP_NOMOVE | SWP_NOZORDER); 1.133 + 1.134 + m_address.SetCurSel(0); 1.135 + update(); 1.136 + 1.137 + return TRUE; // return TRUE unless you set the focus to a control 1.138 + // EXCEPTION: OCX Property Pages should return FALSE 1.139 +} 1.140 + 1.141 +void IOViewer::update() 1.142 +{ 1.143 + CString buffer; 1.144 + 1.145 + const IOData *sel = &ioViewRegisters[selected]; 1.146 + u16 data = sel->address ? *sel->address : 1.147 + (ioMem ? *((u16 *)&ioMem[sel->offset]) : 0); 1.148 + 1.149 + for (int i = 0; i < 16; i++) 1.150 + { 1.151 + CButton *pWnd = (CButton *)GetDlgItem(IDC_BIT_0 + i); 1.152 + 1.153 + if (pWnd) 1.154 + { 1.155 + if (!(sel->write & (1 << i))) 1.156 + pWnd->EnableWindow(FALSE); 1.157 + else 1.158 + pWnd->EnableWindow(TRUE); 1.159 + pWnd->SetCheck(((data & (1 << i)) >> i)); 1.160 + buffer.Format("%2d %s", i, sel->bits[i]); 1.161 + pWnd->SetWindowText(buffer); 1.162 + } 1.163 + } 1.164 + 1.165 + buffer.Format("%04X", data); 1.166 + m_value.SetWindowText(buffer); 1.167 +} 1.168 + 1.169 +void IOViewer::OnApply() 1.170 +{ 1.171 + const IOData *sel = &ioViewRegisters[selected]; 1.172 + u16 res = 0; 1.173 + for (int i = 0; i < 16; i++) 1.174 + { 1.175 + CButton *pWnd = (CButton *)GetDlgItem(IDC_BIT_0 + i); 1.176 + 1.177 + if (pWnd) 1.178 + { 1.179 + if (pWnd->GetCheck()) 1.180 + res |= (1 << i); 1.181 + } 1.182 + } 1.183 + CPUWriteHalfWord(0x4000000+sel->offset, res); 1.184 + update(); 1.185 +} 1.186 +