home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CMCD0704.ISO / Software / Freeware / Utilitare / VisualBoyAdvance-1.7.2 / src / win32 / IOViewer.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-05-13  |  5.0 KB  |  202 lines

  1. // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
  2. // Copyright (C) 1999-2003 Forgotten
  3. // Copyright (C) 2004 Forgotten and the VBA development team
  4.  
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2, or(at your option)
  8. // any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software Foundation,
  17. // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18.  
  19. // IOViewer.cpp : implementation file
  20. //
  21.  
  22. #include "stdafx.h"
  23. #include "vba.h"
  24. #include "IOViewer.h"
  25.  
  26. #include "../System.h"
  27. #include "../GBA.h"
  28. #include "../Globals.h"
  29.  
  30. #include "IOViewerRegs.h"
  31.  
  32. #ifdef _DEBUG
  33. #define new DEBUG_NEW
  34. #undef THIS_FILE
  35. static char THIS_FILE[] = __FILE__;
  36. #endif
  37.  
  38. /////////////////////////////////////////////////////////////////////////////
  39. // IOViewer dialog
  40.  
  41.  
  42. IOViewer::IOViewer(CWnd* pParent /*=NULL*/)
  43.   : ResizeDlg(IOViewer::IDD, pParent)
  44. {
  45.   //{{AFX_DATA_INIT(IOViewer)
  46.   // NOTE: the ClassWizard will add member initialization here
  47.   //}}AFX_DATA_INIT
  48.   selected = 0;
  49.   autoUpdate = false;
  50. }
  51.  
  52.  
  53. void IOViewer::DoDataExchange(CDataExchange* pDX)
  54. {
  55.   CDialog::DoDataExchange(pDX);
  56.   //{{AFX_DATA_MAP(IOViewer)
  57.     DDX_Control(pDX, IDC_VALUE, m_value);
  58.   DDX_Control(pDX, IDC_ADDRESSES, m_address);
  59.     //}}AFX_DATA_MAP
  60. }
  61.  
  62.  
  63. BEGIN_MESSAGE_MAP(IOViewer, CDialog)
  64.   //{{AFX_MSG_MAP(IOViewer)
  65.   ON_BN_CLICKED(IDC_CLOSE, OnClose)
  66.   ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
  67.   ON_BN_CLICKED(IDC_AUTO_UPDATE, OnAutoUpdate)
  68.   ON_CBN_SELCHANGE(IDC_ADDRESSES, OnSelchangeAddresses)
  69.     ON_BN_CLICKED(IDC_APPLY, OnApply)
  70.     //}}AFX_MSG_MAP
  71.   END_MESSAGE_MAP()
  72.  
  73.   /////////////////////////////////////////////////////////////////////////////
  74. // IOViewer message handlers
  75.  
  76. void IOViewer::OnClose() 
  77. {
  78.   theApp.winRemoveUpdateListener(this);
  79.   
  80.   DestroyWindow();
  81. }
  82.  
  83. void IOViewer::OnRefresh() 
  84. {
  85.   // TODO: Add your control notification handler code here
  86.   
  87. }
  88.  
  89. void IOViewer::OnAutoUpdate() 
  90. {
  91.   autoUpdate = !autoUpdate;
  92.   if(autoUpdate) {
  93.     theApp.winAddUpdateListener(this);
  94.   } else {
  95.     theApp.winRemoveUpdateListener(this);    
  96.   }  
  97. }
  98.  
  99. void IOViewer::OnSelchangeAddresses() 
  100. {
  101.   selected = m_address.GetCurSel();
  102.  
  103.   update();
  104. }
  105.  
  106. void IOViewer::PostNcDestroy() 
  107. {
  108.   delete this;
  109. }
  110.  
  111. BOOL IOViewer::OnInitDialog() 
  112. {
  113.   CDialog::OnInitDialog();
  114.   
  115.   // winCenterWindow(getHandle());
  116.   DIALOG_SIZER_START( sz )
  117.     DIALOG_SIZER_END()
  118.     SetData(sz,
  119.             TRUE,
  120.             HKEY_CURRENT_USER,
  121.             "Software\\Emulators\\VisualBoyAdvance\\Viewer\\IOView",
  122.             NULL);
  123.  
  124.   CFont *font = CFont::FromHandle((HFONT)GetStockObject(SYSTEM_FIXED_FONT));
  125.   int i;
  126.   for(i = 0; i < sizeof(ioViewRegisters)/sizeof(IOData); i++) {
  127.     m_address.AddString(ioViewRegisters[i].name);
  128.   }
  129.   m_address.SetFont(font);
  130.   for(i = 0; i < 16; i++) {
  131.     GetDlgItem(IDC_BIT_0+i)->SetFont(font);
  132.   }
  133.  
  134.   RECT cbSize;
  135.   int Height;
  136.   
  137.   m_address.GetClientRect(&cbSize);
  138.   Height = m_address.GetItemHeight(0);
  139.   Height += m_address.GetItemHeight(0) * (10);
  140.   
  141.   // Note: The use of SM_CYEDGE assumes that we're using Windows '95
  142.   // Now add on the height of the border of the edit box
  143.   Height += GetSystemMetrics(SM_CYEDGE) * 2;  // top & bottom edges
  144.   
  145.   // The height of the border of the drop-down box
  146.   Height += GetSystemMetrics(SM_CYEDGE) * 2;  // top & bottom edges
  147.   
  148.   // now set the size of the window
  149.   m_address.SetWindowPos(NULL,
  150.                          0, 0,
  151.                          cbSize.right, Height,
  152.                          SWP_NOMOVE | SWP_NOZORDER);
  153.  
  154.   m_address.SetCurSel(0);
  155.   update();
  156.   
  157.   return TRUE;  // return TRUE unless you set the focus to a control
  158.                 // EXCEPTION: OCX Property Pages should return FALSE
  159. }
  160.  
  161. void IOViewer::update()
  162. {
  163.   CString buffer;
  164.  
  165.   const IOData *sel = &ioViewRegisters[selected];
  166.   u16 data = sel->address ? *sel->address : 
  167.     (ioMem ? *((u16 *)&ioMem[sel->offset]) : 0);
  168.  
  169.   for(int i = 0; i < 16; i++) {
  170.     CButton *pWnd = (CButton *)GetDlgItem(IDC_BIT_0 + i);
  171.  
  172.     if(pWnd) {
  173.       if(!(sel->write & (1 << i)))
  174.         pWnd->EnableWindow(FALSE);
  175.       else
  176.         pWnd->EnableWindow(TRUE);
  177.       pWnd->SetCheck(((data & (1 << i)) >> i));
  178.       buffer.Format("%2d %s", i, sel->bits[i]);
  179.       pWnd->SetWindowText(buffer);
  180.     }
  181.   }
  182.  
  183.   buffer.Format("%04X", data);
  184.   m_value.SetWindowText(buffer);
  185. }
  186.  
  187. void IOViewer::OnApply() 
  188. {
  189.   const IOData *sel = &ioViewRegisters[selected];
  190.   u16 res = 0;
  191.   for(int i = 0; i < 16; i++) {
  192.     CButton *pWnd = (CButton *)GetDlgItem(IDC_BIT_0 + i);
  193.       
  194.     if(pWnd) {
  195.       if(pWnd->GetCheck())
  196.         res |= (1 << i);
  197.     }
  198.   }
  199.   CPUWriteHalfWord(0x4000000+sel->offset, res);
  200.   update();
  201. }
  202.