home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CMCD0704.ISO / Software / Freeware / Utilitare / VisualBoyAdvance-1.7.2 / src / win32 / GBDisassemble.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-05-13  |  6.1 KB  |  263 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. // GBDisassemble.cpp : implementation file
  20. //
  21.  
  22. #include "stdafx.h"
  23. #include "vba.h"
  24. #include "GBDisassemble.h"
  25.  
  26. #include "../System.h"
  27. #include "../gb/GB.h"
  28. #include "../gb/gbGlobals.h"
  29.  
  30. #ifdef _DEBUG
  31. #define new DEBUG_NEW
  32. #undef THIS_FILE
  33. static char THIS_FILE[] = __FILE__;
  34. #endif
  35.  
  36. extern gbRegister AF;
  37. extern gbRegister BC;
  38. extern gbRegister DE;
  39. extern gbRegister HL;
  40. extern gbRegister SP;
  41. extern gbRegister PC;
  42. extern u16 IFF;
  43. extern int gbDis(char *, u16);
  44.  
  45. /////////////////////////////////////////////////////////////////////////////
  46. // GBDisassemble dialog
  47.  
  48.  
  49. GBDisassemble::GBDisassemble(CWnd* pParent /*=NULL*/)
  50.   : ResizeDlg(GBDisassemble::IDD, pParent)
  51. {
  52.   //{{AFX_DATA_INIT(GBDisassemble)
  53.   m_c = FALSE;
  54.   m_h = FALSE;
  55.   m_n = FALSE;
  56.   m_z = FALSE;
  57.   //}}AFX_DATA_INIT
  58.   address = 0;
  59.   autoUpdate = false;
  60.   count = 1;
  61.   lastAddress = 0;
  62. }
  63.  
  64.  
  65. void GBDisassemble::DoDataExchange(CDataExchange* pDX)
  66. {
  67.   CDialog::DoDataExchange(pDX);
  68.   //{{AFX_DATA_MAP(GBDisassemble)
  69.   DDX_Control(pDX, IDC_ADDRESS, m_address);
  70.   DDX_Control(pDX, IDC_DISASSEMBLE, m_list);
  71.   DDX_Check(pDX, IDC_C, m_c);
  72.   DDX_Check(pDX, IDC_H, m_h);
  73.   DDX_Check(pDX, IDC_N, m_n);
  74.   DDX_Check(pDX, IDC_Z, m_z);
  75.   //}}AFX_DATA_MAP
  76. }
  77.  
  78.  
  79. BEGIN_MESSAGE_MAP(GBDisassemble, CDialog)
  80.   //{{AFX_MSG_MAP(GBDisassemble)
  81.   ON_BN_CLICKED(IDC_CLOSE, OnClose)
  82.   ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
  83.   ON_BN_CLICKED(IDC_NEXT, OnNext)
  84.   ON_BN_CLICKED(IDC_GO, OnGo)
  85.   ON_BN_CLICKED(IDC_GOPC, OnGopc)
  86.   ON_BN_CLICKED(IDC_AUTO_UPDATE, OnAutoUpdate)
  87.   ON_WM_VSCROLL()
  88.   //}}AFX_MSG_MAP
  89.   END_MESSAGE_MAP()
  90.  
  91.   /////////////////////////////////////////////////////////////////////////////
  92. // GBDisassemble message handlers
  93.  
  94. void GBDisassemble::OnClose() 
  95. {
  96.   theApp.winRemoveUpdateListener(this);
  97.   
  98.   DestroyWindow();
  99. }
  100.  
  101. void GBDisassemble::OnRefresh() 
  102. {
  103.   refresh();
  104. }
  105.  
  106. void GBDisassemble::OnNext() 
  107. {
  108.   gbEmulate(1);
  109.   if(PC.W < address || PC.W >= lastAddress)
  110.     OnGopc();
  111.   refresh();
  112. }
  113.  
  114. void GBDisassemble::OnGo() 
  115. {
  116.   CString buffer;
  117.   m_address.GetWindowText(buffer);
  118.   sscanf(buffer, "%x", &address);
  119.   refresh();
  120. }
  121.  
  122. void GBDisassemble::OnGopc() 
  123. {
  124.   address = PC.W;
  125.  
  126.   refresh();
  127. }
  128.  
  129. void GBDisassemble::OnAutoUpdate() 
  130. {
  131.   autoUpdate = !autoUpdate;
  132.   if(autoUpdate) {
  133.     theApp.winAddUpdateListener(this);
  134.   } else {
  135.     theApp.winRemoveUpdateListener(this);    
  136.   }  
  137. }
  138.  
  139. BOOL GBDisassemble::OnInitDialog() 
  140. {
  141.   CDialog::OnInitDialog();
  142.   
  143.   DIALOG_SIZER_START( sz )
  144.     DIALOG_SIZER_ENTRY( IDC_DISASSEMBLE, DS_SizeY)
  145.     DIALOG_SIZER_ENTRY( IDC_REFRESH, DS_MoveY)
  146.     DIALOG_SIZER_ENTRY( IDC_CLOSE, DS_MoveY)
  147.     DIALOG_SIZER_ENTRY( IDC_NEXT,  DS_MoveY)
  148.     DIALOG_SIZER_ENTRY( IDC_AUTO_UPDATE, DS_MoveY)
  149.     DIALOG_SIZER_ENTRY( IDC_GOPC, DS_MoveY)
  150.     DIALOG_SIZER_ENTRY( IDC_VSCROLL, DS_SizeY)
  151.     DIALOG_SIZER_END()
  152.     SetData(sz,
  153.             TRUE,
  154.             HKEY_CURRENT_USER,
  155.             "Software\\Emulators\\VisualBoyAdvance\\Viewer\\GBDisassembleView",
  156.             NULL);
  157.  
  158.   SCROLLINFO si;
  159.   ZeroMemory(&si, sizeof(si));
  160.   si.cbSize = sizeof(si);
  161.   si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS;
  162.   si.nMin = 0;
  163.   si.nMax = 100;
  164.   si.nPos = 50;
  165.   si.nPage = 0;
  166.   GetDlgItem(IDC_VSCROLL)->SetScrollInfo(SB_CTL, &si, TRUE);
  167.   CFont *font = CFont::FromHandle((HFONT)GetStockObject(SYSTEM_FIXED_FONT));
  168.   m_list.SetFont(font);
  169.   
  170.   for(int i = 0; i < 6; i++)
  171.     GetDlgItem(IDC_R0+i)->SetFont(font);
  172.  
  173.   m_address.LimitText(4);
  174.   refresh();
  175.   
  176.   return TRUE;  // return TRUE unless you set the focus to a control
  177.                 // EXCEPTION: OCX Property Pages should return FALSE
  178. }
  179.  
  180. void GBDisassemble::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  181. {
  182.   char buffer[80];
  183.   
  184.   switch(nSBCode) {
  185.   case SB_LINEDOWN:
  186.     address += gbDis(buffer, address);
  187.     break;
  188.   case SB_LINEUP:
  189.     address--;
  190.     break;
  191.   case SB_PAGEDOWN:
  192.     address = lastAddress;
  193.     break;
  194.   case SB_PAGEUP:
  195.     address -= count;
  196.     break;
  197.   }
  198.   refresh();
  199.   
  200.   CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
  201. }
  202.  
  203. void GBDisassemble::refresh()
  204. {
  205.   if(gbRom == NULL)
  206.     return;
  207.   
  208.   int h = m_list.GetItemHeight(0);
  209.   RECT r;
  210.   m_list.GetClientRect(&r);
  211.   count = (r.bottom - r.top+1)/h;
  212.  
  213.   m_list.ResetContent();
  214.   if(!emulating || theApp.cartridgeType != 1)
  215.     return;
  216.   
  217.   char buffer[80];
  218.   u16 addr = address;
  219.   int i;
  220.   int sel = -1;
  221.   for(i = 0; i < count; i++) {
  222.     if(addr == PC.W)
  223.       sel = i;
  224.     addr += gbDis(buffer, addr);
  225.     m_list.InsertString(-1, buffer);
  226.   }
  227.   lastAddress = addr-1;
  228.   if(sel != -1)
  229.     m_list.SetCurSel(sel);
  230.  
  231.   sprintf(buffer, "%04x", AF.W);
  232.   GetDlgItem(IDC_R0)->SetWindowText(buffer);
  233.   sprintf(buffer, "%04x", BC.W);
  234.   GetDlgItem(IDC_R1)->SetWindowText(buffer);  
  235.   sprintf(buffer, "%04x", DE.W);
  236.   GetDlgItem(IDC_R2)->SetWindowText(buffer);  
  237.   sprintf(buffer, "%04x", HL.W);
  238.   GetDlgItem(IDC_R3)->SetWindowText(buffer);  
  239.   sprintf(buffer, "%04x", SP.W);
  240.   GetDlgItem(IDC_R4)->SetWindowText(buffer);  
  241.   sprintf(buffer, "%04x", PC.W);
  242.   GetDlgItem(IDC_R5)->SetWindowText(buffer);  
  243.   sprintf(buffer, "%04x", IFF);
  244.   GetDlgItem(IDC_R6)->SetWindowText(buffer);  
  245.  
  246.   m_z = (AF.B.B0 & 0x80) != 0;
  247.   m_n = (AF.B.B0 & 0x40) != 0;
  248.   m_h = (AF.B.B0 & 0x20) != 0;
  249.   m_c = (AF.B.B0 & 0x10) != 0;
  250.   UpdateData(FALSE);
  251. }
  252.  
  253. void GBDisassemble::update()
  254. {
  255.   OnGopc();
  256.   refresh();
  257. }
  258.  
  259. void GBDisassemble::PostNcDestroy() 
  260. {
  261.   delete this;
  262. }
  263.