annotate src/win32/IOViewer.cpp @ 8:08a8e09ca414

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