📄 6502view.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.
-----------------------------------------------------------------------------*/
// 6502View.cpp : implementation of the CSrc6502View class
//
#include "stdafx.h"
#include "MainFrm.h"
#include "6502Doc.h"
#include "6502View.h"
#include "DrawMarks.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
bool CSrc6502View::m_bAutoIndent= TRUE; // sk砤dowa statyczna - automatyczne wci阠ia
int CSrc6502View::m_nTabStep= 8; // krok tabulacji
bool CSrc6502View::m_bAutoSyntax = TRUE;
bool CSrc6502View::m_bAutoUppercase = TRUE;
CFont CSrc6502View::m_Font;
LOGFONT CSrc6502View::m_LogFont;
COLORREF CSrc6502View::m_rgbTextColor;
COLORREF CSrc6502View::m_rgbBkgndColor;
COLORREF CSrc6502View::m_vrgbColorSyntax[6]=
{
RGB(0, 0, 160), // instructions
RGB(128, 0, 128), // directives
RGB(128, 128, 128), // comments
RGB(0, 0, 255), // number
RGB(0, 128, 128), // string
RGB(192, 192, 224) // selection
};
BYTE CSrc6502View::m_vbyFontStyle[6]=
{
0, 0, 0, 0, 0, 0
};
static CMarks s_LeftMarginMarker;
/////////////////////////////////////////////////////////////////////////////
// CSrc6502View
#ifdef USE_CRYSTAL_EDIT
IMPLEMENT_DYNCREATE(CSrc6502View, CCrystalEditView)
#else
IMPLEMENT_DYNCREATE(CSrc6502View, CEditView)
#endif
BEGIN_MESSAGE_MAP(CSrc6502View, CBaseView)
//{{AFX_MSG_MAP(CSrc6502View)
ON_WM_CREATE()
ON_CONTROL_REFLECT(EN_UPDATE, OnEnUpdate)
ON_WM_CONTEXTMENU()
ON_WM_CTLCOLOR_REFLECT()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CBaseView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CBaseView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CBaseView::OnFilePrintPreview)
ON_MESSAGE(CBroadcast::WM_USER_REMOVE_ERR_MARK, OnRemoveErrMark)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSrc6502View construction/destruction
CSrc6502View::CSrc6502View()
{
// TODO: add construction code here
m_nActualPointerLine = -1;
m_nActualErrMarkLine = -1;
m_pMainFrame = 0;
// m_nBrkIndex = 0;
/*
memset(&m_logfont, 0, sizeof(m_logfont));
m_logfont.lfHeight = 9;
m_logfont.lfPitchAndFamily = FIXED_PITCH;
strcpy(m_logfont.lfFaceName, "Fixedsys");
*/
// m_Font.CreateFontIndirect(&m_LogFont);
}
CSrc6502View::~CSrc6502View()
{
}
BOOL CSrc6502View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
bool bPreCreated = CBaseView::PreCreateWindow(cs);
// cs.style &= ~(ES_AUTOHSCROLL|WS_HSCROLL); // Enable word-wrapping
cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
return bPreCreated;
}
/////////////////////////////////////////////////////////////////////////////
// CSrc6502View drawing
void CSrc6502View::OnDraw(CDC* pDC) // overridden to draw this view
{
#ifdef USE_CRYSTAL_EDIT
CBaseView::OnDraw(pDC);
#endif
}
/////////////////////////////////////////////////////////////////////////////
// CSrc6502View printing
BOOL CSrc6502View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default CBaseView preparation
return CBaseView::OnPreparePrinting(pInfo);
}
void CSrc6502View::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
// Default CBaseView begin printing.
CBaseView::OnBeginPrinting(pDC, pInfo);
}
void CSrc6502View::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
// Default CBaseView end printing
CBaseView::OnEndPrinting(pDC, pInfo);
}
/////////////////////////////////////////////////////////////////////////////
// CSrc6502View diagnostics
#ifdef _DEBUG
void CSrc6502View::AssertValid() const
{
CBaseView::AssertValid();
}
void CSrc6502View::Dump(CDumpContext& dc) const
{
CBaseView::Dump(dc);
}
CSrc6502Doc* CSrc6502View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSrc6502Doc)));
return (CSrc6502Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CSrc6502View message handlers
void CSrc6502View::OnInitialUpdate()
{
CBaseView::OnInitialUpdate();
SelectEditFont();
/*
SetFont(&m_Font,FALSE);
CEdit &edit= GetEditCtrl();
DWORD margins= edit.GetMargins();
edit.SetMargins(16u,UINT(HIWORD(margins))); // ustawienie lewego marginesu
*/
SetAutoIndent(CSrc6502View::m_bAutoIndent);
}
int CSrc6502View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CBaseView::OnCreate(lpCreateStruct) == -1)
return -1;
#ifndef USE_CRYSTAL_EDIT
m_pfnOldProc = (LRESULT (CALLBACK *)(HWND,UINT,WPARAM,LPARAM)) ::SetWindowLong(m_hWnd,GWL_WNDPROC,(LONG)EditWndProc);
m_wndLeftBar.Create(CWnd::FromHandlePermanent(lpCreateStruct->hwndParent), this);
#endif
VERIFY(m_pMainFrame = dynamic_cast<CMainFrame*>(AfxGetMainWnd()));
return 0;
}
LRESULT (CALLBACK *CSrc6502View::m_pfnOldProc)(HWND,UINT,WPARAM,LPARAM) = NULL;
void CSrc6502View::check_line(const TCHAR* buf, CAsm::Stat &stat, int &start, int &fin, CString &msg)
{
CAsm6502 xasm;
xasm.bProc6502 = theApp.m_global.GetProcType();
stat= xasm.CheckLine(buf,start,fin);
if (stat)
msg = xasm.GetErrMsg(stat);
else
msg.Empty();
}
void CSrc6502View::disp_warning(int line, CString &msg)
{
SetErrMark(line); // zaznaczenie wiersza zawieraj筩ego b彻d
CMainFrame *pMain = (CMainFrame*) AfxGetApp()->m_pMainWnd;
pMain->m_wndStatusBar.SetPaneText(0,msg);
}
//-----------------------------------------------------------------------------
void CSrc6502View::set_position_info(HWND hWnd)
{
static CString strLine;
int nStart;
(*m_pfnOldProc)(hWnd,EM_GETSEL,WPARAM(&nStart),LPARAM(NULL));
int nLine= (*m_pfnOldProc)(hWnd,EM_LINEFROMCHAR,WPARAM(nStart),LPARAM(0));
nStart -= (*m_pfnOldProc)(hWnd,EM_LINEINDEX,WPARAM(nLine),LPARAM(0));
if (nLine < 0 || nStart < 0)
return;
TCHAR *pBuf= strLine.GetBuffer(1024+2);
*((WORD *)pBuf) = 1024;
int nChars = (*m_pfnOldProc)(hWnd,EM_GETLINE,WPARAM(nLine),LPARAM(pBuf));
pBuf[nChars] = 0;
int nColumn= 0;
for (int i=0; i<nChars && i<nStart; i++) // obl. numeru kolumny
{
if (pBuf[i] == _T('\t')) // tabulator?
nColumn += m_nTabStep - nColumn % m_nTabStep;
else
nColumn++;
}
strLine.ReleaseBuffer(0);
CMainFrame* pMain = (CMainFrame*) AfxGetApp()->m_pMainWnd;
pMain->SetPositionText(nLine+1,nColumn+1);
}
//-----------------------------------------------------------------------------
LRESULT CALLBACK CSrc6502View::EditWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
CWnd *pWnd= FromHandlePermanent(hWnd);
ASSERT (pWnd->IsKindOf(RUNTIME_CLASS(CSrc6502View)));
CSrc6502View *pView= (CSrc6502View *)pWnd;
bool cr= false;
switch (msg)
{
case WM_CHAR:
cr = (wParam == 0xD); // CR?
case WM_KEYUP:
case WM_PASTE:
case WM_COPY:
case WM_CUT:
case WM_UNDO:
{
LRESULT ret;
if (cr && m_bAutoIndent)
{
ret = (*m_pfnOldProc)(hWnd,msg,wParam,lParam);
pView->set_position_info(hWnd);
int line_idx= (*m_pfnOldProc)(hWnd,EM_LINEINDEX,WPARAM(-1),0);
int line= (*m_pfnOldProc)(hWnd,EM_LINEFROMCHAR,line_idx,0) - 1; // nr aktualnego wiersza - 1
line_idx= (*m_pfnOldProc)(hWnd,EM_LINEINDEX,WPARAM(line),0);
int line_len= (*m_pfnOldProc)(hWnd,EM_LINELENGTH,line_idx,0);
line= (*m_pfnOldProc)(hWnd,EM_LINEFROMCHAR,line_idx,0);
TCHAR buf[260];
const int size= sizeof(buf) / sizeof(TCHAR) - 2;
*(WORD *)(buf+2) = (WORD)size;
(*m_pfnOldProc)(hWnd,EM_GETLINE,line,(LPARAM)(buf+2));
buf[2+min(size-1,line_len)] = 0;
/*
int line_idx= (*m_pfnOldProc)(hWnd,EM_LINEINDEX,WPARAM(-1),0);
int line_len= (*m_pfnOldProc)(hWnd,EM_LINELENGTH,line_idx,0);
int line= (*m_pfnOldProc)(hWnd,EM_LINEFROMCHAR,line_idx,0); // nr aktualnego wiersza
TCHAR buf[260];
const int size= sizeof(buf) / sizeof(TCHAR) - 2;
*(WORD *)(buf+2) = (WORD)size;
(*m_pfnOldProc)(hWnd,EM_GETLINE,line,(LPARAM)(buf+2));
buf[2+min(size-1,line_len)] = 0;
*/
int start,fin;
CAsm::Stat stat= CAsm::OK;
CString strmsg;
if (m_bAutoSyntax || m_bAutoUppercase)
check_line(buf+2,stat,start,fin,strmsg);
if (m_bAutoUppercase && start>0 && fin>0) // jest instrukcja do zamiany na du縠 litery?
{
TCHAR instr[32];
ASSERT(fin-start < 32);
_tcsncpy(instr,buf+2+start,fin-start);
instr[fin-start] = 0;
_tcsupr(instr);
int c_start,c_end;
(*m_pfnOldProc)(hWnd,EM_GETSEL,WPARAM(&c_start),LPARAM(&c_end));
(*m_pfnOldProc)(hWnd,EM_SETSEL,line_idx+start,line_idx+fin);
(*m_pfnOldProc)(hWnd,EM_REPLACESEL,0,(LPARAM)instr);
(*m_pfnOldProc)(hWnd,EM_SETSEL,c_start,c_start);
// (*m_pfnOldProc)(hWnd,EM_SETSEL,line_idx+line_len,line_idx+line_len);
}
int len= _tcsspn(buf+2,_T(" \t")); // ilo滄 spacji i tabulator體 na pocz箃ku wiersza
if (!(m_bAutoSyntax && stat)) // je渓i nie ma b酬du (je渓i spr. b酬d體), to wci阠ie
{
if (len) // je渓i jest wci阠ie w wierszu powy縠j, to kopiujemy je
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -