📄 memoryview.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.
-----------------------------------------------------------------------------*/
// MemoryView.cpp : implementation file
//
#include "stdafx.h"
#include "resource.h"
#include "MemoryView.h"
#include "MemoryGoto.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CFont CMemoryView::m_Font;
LOGFONT CMemoryView::m_LogFont;
COLORREF CMemoryView::m_rgbTextColor;
COLORREF CMemoryView::m_rgbBkgndColor;
/////////////////////////////////////////////////////////////////////////////
// CMemoryView
IMPLEMENT_DYNCREATE(CMemoryView, CView)
CMemoryView::CMemoryView()
{
m_eDump = FULL;
}
CMemoryView::~CMemoryView()
{
}
BEGIN_MESSAGE_MAP(CMemoryView, CView)
//{{AFX_MSG_MAP(CMemoryView)
ON_WM_VSCROLL()
ON_WM_KEYDOWN()
ON_WM_SIZE()
ON_WM_ERASEBKGND()
ON_WM_CONTEXTMENU()
ON_UPDATE_COMMAND_UI(ID_MEMORY_GOTO, OnUpdateMemoryGoto)
ON_COMMAND(ID_MEMORY_GOTO, OnMemoryGoto)
ON_UPDATE_COMMAND_UI(ID_MEMORY_CHG, OnUpdateMemoryChg)
ON_COMMAND(ID_MEMORY_CHG, OnMemoryChg)
ON_COMMAND(ID_MEMORY_FULL, OnMemoryFull)
ON_COMMAND(ID_MEMORY_HEX, OnMemoryHex)
ON_COMMAND(ID_MEMORY_TEXT, OnMemoryText)
ON_UPDATE_COMMAND_UI(ID_MEMORY_FULL, OnUpdateMemoryFull)
ON_UPDATE_COMMAND_UI(ID_MEMORY_HEX, OnUpdateMemoryHex)
ON_UPDATE_COMMAND_UI(ID_MEMORY_TEXT, OnUpdateMemoryText)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
int CMemoryView::bytes_in_line()
{
int lim= 0;
switch (m_eDump)
{
case FULL: // hex i tekst
lim = (m_nCx - 9) / 4; // ilo滄 wy渨ietlanych w jednym wierszu bajt體
break;
case HEX: // tylko hex
lim = (m_nCx - 5) / 3; // ilo滄 wy渨ietlanych w jednym wierszu bajt體
break;
case TEXT: // tylko tekst
lim = (m_nCx - 8) / 1; // ilo滄 wy渨ietlanych w jednym wierszu bajt體
break;
default:
ASSERT(false);
}
return lim <= 0 ? 1 : lim;
}
/////////////////////////////////////////////////////////////////////////////
// CMemoryView drawing
void CMemoryView::OnDraw(CDC* pDC)
{
CMemoryDoc *pDoc = (CMemoryDoc *)GetDocument();
ASSERT(pDoc->IsKindOf(RUNTIME_CLASS(CMemoryDoc)));
const COutputMem& mem= *pDoc->m_pMem;
CString line(_T(' '), 1 + max(m_nCx, 8));
UINT16 addr= pDoc->m_uAddress;
TCHAR hex[8];
int lim= bytes_in_line(); // ilo滄 wy渨ietlanych w jednym wierszu bajt體
for (int i= 0, y= 0; i <= m_nCy; i++, y += m_nChrH)
{
line.Format(_T("%04X "), int(addr));
int j= 0;
switch (m_eDump)
{
case FULL: // hex i tekst -----------------------------
{
for (j = 0; j < lim && addr + j < 0x10000; j++)
{
wsprintf(hex, _T(" %02X"), int(mem[addr + j]));
line += hex;
}
line += _T(" >");
for (j = 0; j < lim && addr + j < 0x10000; j++)
line += TCHAR(mem[addr + j]);
line += _T("<");
}
break;
case HEX: // hex ---------------------------------
{
for (j = 0; j < lim && addr + j < 0x10000; j++)
{
wsprintf(hex, _T(" %02X"), int(mem[addr + j]));
line += hex;
}
}
break;
case TEXT: // tekst -------------------------------
{
line += _T(" >");
for (j = 0; j < lim && addr + j < 0x10000; j++)
line += TCHAR(mem[addr + j]);
line += _T("<");
}
break;
}
addr += UINT16(j);
pDC->TextOut(1, y, line);
if (addr == 0) // doszli渕y do ko馽a pami阠i?
break;
}
}
/////////////////////////////////////////////////////////////////////////////
// CMemoryView diagnostics
#ifdef _DEBUG
void CMemoryView::AssertValid() const
{
CView::AssertValid();
}
void CMemoryView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// obliczenia pomocnicze
void CMemoryView::calc(CDC *pDC)
{
RECT rect;
GetClientRect(&rect);
pDC->SelectObject(&m_Font);
TEXTMETRIC tm;
pDC->GetTextMetrics(&tm);
m_nChrH = (int)tm.tmHeight + (int)tm.tmExternalLeading;
m_nChrW = tm.tmAveCharWidth;
m_nCx = (rect.right-1) / m_nChrW; // ilo滄 kolumn
m_nCy = rect.bottom / m_nChrH; // ilo滄 wierszy
// if (rect.bottom % m_nCharH) // na dole wystaje kawa砮k wiersza?
if (m_nCy == 0)
m_nCy++;
}
//-----------------------------------------------------------------------------
void CMemoryView::scroll(UINT nSBCode, int nPos, int nRepeat)
{
CMemoryDoc *pDoc = (CMemoryDoc *)GetDocument();
if (pDoc == NULL)
return;
switch (nSBCode)
{
case SB_ENDSCROLL: // End scroll
break;
case SB_LINEDOWN: // Scroll one line down
switch (find_next_addr(pDoc->m_uAddress,*pDoc->m_pMem))
{
case 0:
break; // dalej ju
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -