⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 deasm6502view.cpp

📁 专门为65XX系列芯片设计的变异调试环境的源代码
💻 CPP
字号:
/*-----------------------------------------------------------------------------
	6502 Macroassembler and Simulator

Copyright (C) 1995-2003 Michal Kowalski

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-----------------------------------------------------------------------------*/

// Deasm6502View.cpp : implementation file
//

#include "stdafx.h"
//#include "6502.h"
#include "Deasm6502View.h"
#include "Deasm6502Doc.h"
#include "resource.h"#include "DeasmGoto.h"
#include "Deasm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


CFont CDeasm6502View::m_Font;
LOGFONT CDeasm6502View::m_LogFont;
COLORREF CDeasm6502View::m_rgbBkgnd;
COLORREF CDeasm6502View::m_rgbAddress= RGB(127,127,127);
COLORREF CDeasm6502View::m_rgbCode= RGB(191,191,191);
COLORREF CDeasm6502View::m_rgbInstr= RGB(0,0,0);
bool CDeasm6502View::m_bDrawCode= TRUE;

/////////////////////////////////////////////////////////////////////////////
// CDeasm6502View

IMPLEMENT_DYNCREATE(CDeasm6502View, CView)


CDeasm6502View::CDeasm6502View()
{
	m_nFontHeight = 0;
	m_nFontWidth = 0;
}


CDeasm6502View::~CDeasm6502View()
{
}


BEGIN_MESSAGE_MAP(CDeasm6502View, CView)
  ON_WM_CONTEXTMENU()//{{AFX_MSG_MAP(CDeasm6502View)
  ON_WM_VSCROLL()
  ON_WM_KEYDOWN()
  ON_WM_ERASEBKGND()
  ON_COMMAND(ID_DEASM_GOTO, OnDeasmGoto)
  ON_UPDATE_COMMAND_UI(ID_DEASM_GOTO, OnUpdateDeasmGoto)
  ON_WM_CONTEXTMENU()
	ON_WM_SIZE()
	//}}AFX_MSG_MAP
  ON_MESSAGE(CBroadcast::WM_USER_EXIT_DEBUGGER, OnExitDebugger)
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CDeasm6502View drawing

int CDeasm6502View::no_of_lines(RECT &rect)	// obl. ilo渃i wierszy w oknie
{
	if (m_nFontHeight == 0)
		return 1;	// not yet ready

	int h= rect.bottom - rect.top;
	if (h >= m_nFontHeight)
		return h / m_nFontHeight;		// no of rows in window
	else
		return 1;						// always at least one row
}


void CDeasm6502View::OnDraw(CDC* pDC)	// deasemblowany program - wy渨ietlanie instrukcji
{
  CDeasm6502Doc *pDoc = (CDeasm6502Doc*)GetDocument();
  if (pDoc == NULL)
    return;

  RECT rect;
  GetClientRect(&rect);
  int lines= no_of_lines(rect);

  rect.bottom = rect.top + m_nFontHeight;
  RECT mark= rect;			// miejsce na wska焠iki

  rect.left += m_nFontHeight;		// margines lewy
  if (rect.left >= rect.right)
    rect.right = rect.left;

  CDeasm deasm;
  int ptr= pDoc->m_uStartAddr;

  for (int i=0; i<=lines; i++)
  {
    if (pDC->RectVisible(&mark))	// pola wska焠ika do od渨ie縠nia?
    {
      Breakpoint bp= theApp.m_global.GetBreakpoint(UINT16(ptr));
      if (bp & BPT_MASK)		// jest miejsce przerwania?
        draw_breakpoint(*pDC,mark.left,mark.top,m_nFontHeight,bp & BPT_DISABLED ? FALSE : TRUE);
      if (pDoc->m_nPointerAddr == ptr)	// w tym wierszu strza砶a?
	draw_pointer(*pDC,mark.left,mark.top,m_nFontHeight);
    }
    const CString &str= 
      deasm.DeasmInstr(*pDoc->m_pCtx,CDeasm::DeasmFmt(CDeasm::DF_ADDRESS|CDeasm::DF_CODE_BYTES),ptr);
    if (pDC->RectVisible(&rect))	// wiersz instrukcji do od渨ie縠nia?
    {
      pDC->SetTextColor(m_rgbAddress);
      pDC->TextOut(rect.left,rect.top,LPCTSTR(str),4);
      if (m_bDrawCode)
      {
	pDC->SetTextColor(m_rgbCode);
	pDC->TextOut(rect.left+m_nFontWidth*6,rect.top,LPCTSTR(str)+6,8);
      }
      pDC->SetTextColor(m_rgbInstr);
      pDC->TextOut(rect.left+m_nFontWidth*16,rect.top,LPCTSTR(str)+16,str.GetLength()-16);
    }
    rect.top += m_nFontHeight;
    rect.bottom += m_nFontHeight;
    mark.top += m_nFontHeight;
    mark.bottom += m_nFontHeight;
  }

}

/////////////////////////////////////////////////////////////////////////////
// CDeasm6502View diagnostics

#ifdef _DEBUG
void CDeasm6502View::AssertValid() const
{
  CView::AssertValid();
}

void CDeasm6502View::Dump(CDumpContext& dc) const
{
  CView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CDeasm6502View message handlers

void CDeasm6502View::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) 
{
  if (pInfo || pDC->IsPrinting())
    return;

  pDC->SetBkMode(OPAQUE);
  pDC->SelectObject(&m_Font);
  TEXTMETRIC tm;
  pDC->GetTextMetrics(&tm);
  m_nFontHeight = (int)tm.tmHeight + (int)tm.tmExternalLeading;
  m_nFontWidth = tm.tmAveCharWidth;
  pDC->SetBkColor(m_rgbBkgnd);

  CView::OnPrepareDC(pDC, pInfo);
}


BOOL CDeasm6502View::PreCreateWindow(CREATESTRUCT& cs)
{
  bool ret= CView::PreCreateWindow(cs);
  cs.style |= WS_VSCROLL;
  return ret;
}


//=============================================================================

void CDeasm6502View::ScrollToLine(UINT16 addr)
{
  CDeasm6502Doc *pDoc= (CDeasm6502Doc *)GetDocument();

  if (pDoc == NULL)
    return;

  if (pDoc->m_uStartAddr == addr)	// 抗dany adres jest aktualnym pocz箃kiem?
    return;

  if (pDoc->m_uStartAddr > addr)	// 抗dany adres przed aktualnym pocz箃kiem
  {
    RECT rect;
    GetClientRect(&rect);
    int lines= no_of_lines(rect);
    CDeasm deasm;
    UINT16 start= addr;
    bool redraw= TRUE;
    for (int i=0; i<lines; i++)	// idziemy od 'addr' w d蟪, a

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -