view src/win32/IOViewer.cpp @ 2:3549bbe597ed

adding makefile.am
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:47 -0600
parents f9f4f1b99eed
children
line wrap: on
line source
1 // IOViewer.cpp : implementation file
2 //
4 #include "stdafx.h"
5 #include "resource.h"
6 #include "IOViewer.h"
7 #include "VBA.h"
9 #include "../gba/GBA.h" // CPUWriteHalfWord
10 #include "../gba/GBAGlobals.h"
12 #include "IOViewerRegs.h"
14 /////////////////////////////////////////////////////////////////////////////
15 // IOViewer dialog
17 IOViewer::IOViewer(CWnd*pParent /*=NULL*/)
18 : ResizeDlg(IOViewer::IDD, pParent)
19 {
20 //{{AFX_DATA_INIT(IOViewer)
21 // NOTE: the ClassWizard will add member initialization here
22 //}}AFX_DATA_INIT
23 selected = 0;
24 autoUpdate = false;
25 }
27 void IOViewer::DoDataExchange(CDataExchange*pDX)
28 {
29 CDialog::DoDataExchange(pDX);
30 //{{AFX_DATA_MAP(IOViewer)
31 DDX_Control(pDX, IDC_VALUE, m_value);
32 DDX_Control(pDX, IDC_ADDRESSES, m_address);
33 //}}AFX_DATA_MAP
34 }
36 BEGIN_MESSAGE_MAP(IOViewer, CDialog)
37 //{{AFX_MSG_MAP(IOViewer)
38 ON_BN_CLICKED(IDC_CLOSE, OnClose)
39 ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
40 ON_BN_CLICKED(IDC_AUTO_UPDATE, OnAutoUpdate)
41 ON_CBN_SELCHANGE(IDC_ADDRESSES, OnSelchangeAddresses)
42 ON_BN_CLICKED(IDC_APPLY, OnApply)
43 //}}AFX_MSG_MAP
44 END_MESSAGE_MAP()
46 /////////////////////////////////////////////////////////////////////////////
47 // IOViewer message handlers
49 void IOViewer::OnClose()
50 {
51 theApp.winRemoveUpdateListener(this);
53 DestroyWindow();
54 }
56 void IOViewer::OnRefresh()
57 {
58 // TODO: Add your control notification handler code here
59 }
61 void IOViewer::OnAutoUpdate()
62 {
63 autoUpdate = !autoUpdate;
64 if (autoUpdate)
65 {
66 theApp.winAddUpdateListener(this);
67 }
68 else
69 {
70 theApp.winRemoveUpdateListener(this);
71 }
72 }
74 void IOViewer::OnSelchangeAddresses()
75 {
76 selected = m_address.GetCurSel();
78 update();
79 }
81 void IOViewer::PostNcDestroy()
82 {
83 delete this;
84 }
86 BOOL IOViewer::OnInitDialog()
87 {
88 CDialog::OnInitDialog();
90 // winCenterWindow(getHandle());
91 DIALOG_SIZER_START(sz)
92 DIALOG_SIZER_END()
93 SetData(sz,
94 TRUE,
95 HKEY_CURRENT_USER,
96 "Software\\Emulators\\VisualBoyAdvance\\Viewer\\IOView",
97 NULL);
99 CFont *font = CFont::FromHandle((HFONT)GetStockObject(SYSTEM_FIXED_FONT));
100 int i;
101 for (i = 0; i < sizeof(ioViewRegisters)/sizeof(IOData); i++)
102 {
103 m_address.AddString(ioViewRegisters[i].name);
104 }
105 m_address.SetFont(font);
106 for (i = 0; i < 16; i++)
107 {
108 GetDlgItem(IDC_BIT_0+i)->SetFont(font);
109 }
111 RECT cbSize;
112 int Height;
114 m_address.GetClientRect(&cbSize);
115 Height = m_address.GetItemHeight(0);
116 Height += m_address.GetItemHeight(0) * (10);
118 // Note: The use of SM_CYEDGE assumes that we're using Windows '95
119 // Now add on the height of the border of the edit box
120 Height += GetSystemMetrics(SM_CYEDGE) * 2; // top & bottom edges
122 // The height of the border of the drop-down box
123 Height += GetSystemMetrics(SM_CYEDGE) * 2; // top & bottom edges
125 // now set the size of the window
126 m_address.SetWindowPos(NULL,
127 0, 0,
128 cbSize.right, Height,
129 SWP_NOMOVE | SWP_NOZORDER);
131 m_address.SetCurSel(0);
132 update();
134 return TRUE; // return TRUE unless you set the focus to a control
135 // EXCEPTION: OCX Property Pages should return FALSE
136 }
138 void IOViewer::update()
139 {
140 CString buffer;
142 const IOData *sel = &ioViewRegisters[selected];
143 u16 data = sel->address ? *sel->address :
144 (ioMem ? *((u16 *)&ioMem[sel->offset]) : 0);
146 for (int i = 0; i < 16; i++)
147 {
148 CButton *pWnd = (CButton *)GetDlgItem(IDC_BIT_0 + i);
150 if (pWnd)
151 {
152 if (!(sel->write & (1 << i)))
153 pWnd->EnableWindow(FALSE);
154 else
155 pWnd->EnableWindow(TRUE);
156 pWnd->SetCheck(((data & (1 << i)) >> i));
157 buffer.Format("%2d %s", i, sel->bits[i]);
158 pWnd->SetWindowText(buffer);
159 }
160 }
162 buffer.Format("%04X", data);
163 m_value.SetWindowText(buffer);
164 }
166 void IOViewer::OnApply()
167 {
168 const IOData *sel = &ioViewRegisters[selected];
169 u16 res = 0;
170 for (int i = 0; i < 16; i++)
171 {
172 CButton *pWnd = (CButton *)GetDlgItem(IDC_BIT_0 + i);
174 if (pWnd)
175 {
176 if (pWnd->GetCheck())
177 res |= (1 << i);
178 }
179 }
180 CPUWriteHalfWord(0x4000000+sel->offset, res);
181 update();
182 }