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

📄 crosasmdlg.cpp

📁 模拟了tec2000的所有功能
💻 CPP
字号:
// CrosAsmDlg.cpp : implementation file
//

#include "stdafx.h"
#include "TEC2000.h"
#include "CrosAsmDlg.h"
#include<string.h>

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

#include "CAcroComp.h"

/////////////////////////////////////////////////////////////////////////////
// CCrosAsmDlg dialog


CCrosAsmDlg::CCrosAsmDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCrosAsmDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCrosAsmDlg)
	m_strAsm = _T("");
	m_strCod = _T("");
	m_strAddress = _T("");
	//}}AFX_DATA_INIT
}


void CCrosAsmDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCrosAsmDlg)
	DDX_Control(pDX, IDC_ASM, m_ctrlAsm);
	DDX_Control(pDX, IDC_ADDRESS, m_ctrlAddress);
	DDX_Control(pDX, IDC_COD, m_ctrlCod);
	DDX_Text(pDX, IDC_ASM, m_strAsm);
	DDX_Text(pDX, IDC_COD, m_strCod);
	DDX_Text(pDX, IDC_ADDRESS, m_strAddress);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CCrosAsmDlg, CDialog)
	//{{AFX_MSG_MAP(CCrosAsmDlg)
	ON_BN_CLICKED(IDC_CROSASM_OPEN, OnCrosasmOpen)
	ON_BN_CLICKED(IDC_CROSCOMP, OnCroscomp)
	ON_BN_CLICKED(IDC_LOADASM, OnLoadasm)
	ON_BN_CLICKED(IDC_CROLOAD, OnCroload)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCrosAsmDlg message handlers



BOOL CCrosAsmDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(pMsg->message==WM_KEYDOWN){
		if(pMsg->wParam==VK_RETURN)
			return TRUE;
		if(pMsg->wParam==VK_ESCAPE)
			return TRUE;
	}
	return CDialog::PreTranslateMessage(pMsg);
}

void CCrosAsmDlg::OnCrosasmOpen() 
{
	char *FilterStr = "COD Files (*.asm)|*.asm; *.asm|All Files (*.*)|*.*||";
	CFileDialog OpenFile(TRUE, ".asm", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,FilterStr, NULL); 
	
	if (OpenFile.DoModal() == IDOK)
		OpenFileName = OpenFile.GetPathName();
	else return;
	m_strAddress=OpenFileName;
	m_ctrlAddress.SetWindowText(OpenFileName);
	CString context;
	m_ctrlAsm.SetWindowText(context);
	char buffer[256];
    ifstream in_file(OpenFileName,ios::in);
	while(in_file.eof()==0){
    	in_file.getline(buffer,256,'\n');
    	context+=buffer;
		context+="\r\n";
	}
	m_ctrlAsm.SetWindowText(context);
}

void CCrosAsmDlg::OnCroscomp() 
{
	int length=OpenFileName.GetLength();
	if(length!=0){
	char *temp;
	temp=new char[length];
	strcpy(temp,OpenFileName);

	CAcroComp as;
	bool sign;
	sign=as.Handle(temp);

	ErrorReport *pp;
	pp=as.GetErrorReport();
	Error * error1=pp->GetHead();
	int line1;
    while(error1!=NULL){
		  line1=error1->GetLineNum();
		  SetClolor(line1);
	      error1=error1->GetNext();
		 
	}

	CString add=OpenFileName;
	UINT lengthadd=add.GetLength();
	CString a;
	a.Format("%d",lengthadd);
	add.SetAt(lengthadd-4,'+');
	add.SetAt(lengthadd-3,'.');
	add.SetAt(lengthadd-2,'A');
	add.SetAt(lengthadd-1,'S');
	add+="M";
    CString context;
	char buffer[256];
    ifstream in_file(add,ios::in);
	int line=0;
	while(in_file.eof()==0){
    	in_file.getline(buffer,256,'\n');
		if(line==0){
			buffer[10]=as.Getchg()[0];
			buffer[11]=as.Getchg()[1];
		}
    	context+=buffer;
		context+="\r\n";
		line++;
	}
	m_ctrlCod.SetWindowText(context);
	}
	else{
		AfxMessageBox(" 没有载入.ASM文件");
	}
	FileName=OpenFileName;
	OpenFileName="";
}

void CCrosAsmDlg::OnLoadasm() 
{
	this->m_ctrlAddress.GetWindowText(m_strAddress);
	int length1=m_strAddress.GetLength();
	if(length1!=0){
		OpenFileName=m_strAddress;
		CString context;
    	char buffer[256];
        ifstream in_file(OpenFileName,ios::in);
    	while(in_file.eof()==0){
        	in_file.getline(buffer,256,'\n');
        	context+=buffer;
	    	context+="\r\n";
		}
    	m_ctrlAsm.SetWindowText(context);
	}
	else{
		AfxMessageBox("没有选择.ASM文件");
	}	
}


void CCrosAsmDlg::SetClolor(int line){
	char buffer[256];
	m_ctrlAsm.GetLine(line,buffer,256);
	int length=strlen(buffer);
	long nEnd;
	long nStart = m_ctrlAsm.LineIndex(line);
	nEnd = nStart+length;
	long len=m_ctrlAsm.GetWindowTextLength();
	COLORREF clr=RGB(0,0,255);
	m_ctrlAsm.SetSel(nStart, nEnd);//选择这个范围

	DWORD dwEffects = true?CFE_BOLD:0;

	CHARFORMAT cfm;
	cfm.cbSize = sizeof(cfm);
    m_ctrlAsm.GetSelectionCharFormat(cfm); //选中内容中的第一个字符的属性
	
	if ((cfm.dwMask & CFM_COLOR)  && cfm.crTextColor == clr && 
		(cfm.dwMask & CFM_BOLD) && (cfm.dwEffects & CFE_BOLD) == dwEffects)
		return;

	cfm.dwEffects = dwEffects;
	cfm.crTextColor = clr;
	cfm.dwMask = CFM_BOLD | CFM_COLOR;

	m_ctrlAsm.SetSelectionCharFormat(cfm);//改变所有选中的字符属性
}


void CCrosAsmDlg::OnCroload() 
{
	if(FileName==""){
		AfxMessageBox("没有编译文件,请先编译文件!");
    	return ;
	}
	CString add=FileName;
	UINT lengthadd=add.GetLength();
	CString a;
	a.Format("%d",lengthadd);
	add.SetAt(lengthadd-4,'.');
	add.SetAt(lengthadd-3,'C');
	add.SetAt(lengthadd-2,'O');
	add.SetAt(lengthadd-1,'D');
	char file[100];
	strcpy(file,add);
	CAcroComp Cacrocomp;

	CTEC2000App *pApp;
    pApp=(CTEC2000App *)AfxGetApp();
    CMainFrame *pFrm;
    pFrm=(CMainFrame *)pApp->GetMainWnd();
    CWnd *pStatusDlg=pFrm->m_wndCStatusDlg.GetDlgItem(IDC_STATUSEDIT);
    CEdit * ph=(CEdit *)pStatusDlg;
    CString temp;
	if(Cacrocomp.WriteToMem(file)){
		temp=add;
		temp+="\r\n";
		temp+="导入内存成功!";
		ph->SetWindowText(temp);
	}
	else{
		temp=add;
		temp+="\r\n";
		temp+="导入内存失败!";
		ph->SetWindowText(temp);
	}
}

⌨️ 快捷键说明

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