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

📄 asm.cpp

📁 模拟了tec2000的所有功能
💻 CPP
📖 第 1 页 / 共 5 页
字号:
#include "stdafx.h"
#include "Asm.h"
#include <iostream.h> 
#include <string.h>
#include <iomanip.h>
#include <math.h>
#include <stdio.h>
#include <fstream.h>
 
#include "CompileDlg.h"
#include "TEC2000.h"

#include "MainFrm.h"
 

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


//using namespace std;

Casm::Casm()
{
//	CTEC2000App *pApp;
//  pApp=(CTEC2000App *)AfxGetApp();
//	asmtemp.memory=pApp->memory;

	addressD=0x2000;addressT=0x2000;
	addressU=0x2000;addressP=0x2000;
//	for(int i=0;i<=65536;i++){memory[i]=0;}
	for(int j=0;j<16;j++){R[j]=0x0;}
	//for(int k=0;k<256;k++){stack[k]=0x0;}
	for(int p=0;p<8;p++){F[p]=0;}
	sp=0xffff;R[4]=0xffff;R[5]=0xffff;
	sign=0;
	flags=0;
	signE=0;signR=0;signA=0;signG=0;
    reg=0;
	temp=0;
    Ioport80=0x0000;Ioport82=0x0000;
    IoportFlag81=0x0000;IoportFlag83=0x0000;

    
}

void Casm::linkmicro()
{
   
   char fname[200];
   char buffer[100];
//   char inscode[20];
   int inssign=1;
   GetCurrentDirectory(200,fname);
   int len=strlen(fname);
   fname[len++]='\\';
   fname[len++]='i';
   fname[len++]='n';
   fname[len++]='s';
   fname[len++]='.';
   fname[len++]='t';
   fname[len++]='x';
   fname[len++]='t';
   fname[len++]='\0';
   
  // AfxMessageBox(fname);
				 // AfxMessageBox(fname);

   WORD temp=memory[pc]&0xff00;
   temp/=16;temp/=16;
    
   ifstream in_filemicro;
   in_filemicro.open(fname,ios::in);
   int i;char *p;
   
   while(in_filemicro.eof()==0&&inssign!=0)
   {
      in_filemicro.getline(buffer,100,'\n');
      i=0;
	  p=buffer;
     // AfxMessageBox(p);
	  while(buffer[i]!=' '){i++;p++;}
     //AfxMessageBox(p);
	  while(buffer[i]==' '){i++;p++;}
	  //AfxMessageBox(p);
	  WORD temp1=getdata(p);
	  if(temp1==temp)
	  {
		  inssign=0;
          //AfxMessageBox("aaaaaaaaaa");   
	  }
    
   }
   if(inssign==0)
   {
	   while(buffer[i]!=' '){i++;p++;}
   }
   WORD temp2=trahexdec(getdata(p));
   pEdit->microtemp.Exec(R,temp2,flags,memory);
   for(i=0;i<16;i++)
	   R[i]=pEdit->microtemp.R[i];
   flags=pEdit->microtemp.ReturnFlages();
   
   pc=R[5];

   sp=R[4];
 //  AfxMessageBox(p);
   /*CString temp3;
   temp3.Format("%d",temp2);
   int	CurrentlengthAll;
   CurrentlengthAll=pEdit->GetWindowTextLength();
   pEdit->SetSel(CurrentlengthAll,CurrentlengthAll);
   pEdit->ReplaceSel(temp3);*/

}



void Casm::traControl(char *command)
{
	CTEC2000App *pApp;
    pApp=(CTEC2000App *)AfxGetApp();
	memory=pApp->memory;

//	R=pApp->R;
//	F=pApp->F;


   // getIns();
    strcpy(buf,command);
	
	//command[0]='\0';
//	pthis->inslength=0;

	pEdit->strins[0]='\0';
	pEdit->inslength=0;

	int j=0;
	while(buf[j]!='\0')
	{
		
		if(buf[j]>='a'&&buf[j]<='z')
			buf[j]-=0x20;
        j++;
	}
	

    int i=0;
	while(buf[i]==' '){i++;}
    char firstchar=buf[i];
    now=buf+i+1;
    
    if(signE==0&&signR==0&&signA==0)
	{
    
	switch(firstchar)
	{
    case 'D':controlD();break;
	case 'd':controlD();break;
	case 'E':controlE();break;
	case 'e':controlE();break;
	case 'G':controlG();break;
	case 'g':controlG();break;
	case 'A':controlA();break;
	case 'a':controlA();break;
	case 'R':controlR();break;
	case 'r':controlR();break;
    case 'u':controlU();break;
	case 'U':controlU();break;
	case 't':controlT();break;
	case 'T':controlT();break;
	case 'p':controlP();break;
	case 'P':controlP();break;
	case '\0':{
		CString Result="\r\n>";
		int CurrentlengthAll=pEdit->GetWindowTextLength();
     	pEdit->SetSel(CurrentlengthAll,CurrentlengthAll);
    	pEdit->ReplaceSel(Result);
		break; }
	default:{CString Result="\r\nCommand Error!\r\n>";
		int CurrentlengthAll=pEdit->GetWindowTextLength();
     	pEdit->SetSel(CurrentlengthAll,CurrentlengthAll);
    	pEdit->ReplaceSel(Result);
		break;} 
	}
	}
	else
	{ 
	    if(signE==1)controlE();
		if(signR==1)controlR();
        if(signA==1)controlA();
	}

	 
}
bool Casm::checkcontrolcomd(char *checktemp)
{
    char *p=checktemp;
	while(p[0]==' ')p++;
	if(p[0]!='A'&&p[0]!='a'&&p[0]!='C'&&p[0]!='c'&&p[0]!='D'&&p[0]!='d'&&p[0]!='E'&&p[0]!='e'
		 &&p[0]!='F'&&p[0]!='f'&&p[0]!='G'&&p[0]!='g'&&p[0]!='M'&&p[0]!='m'&&p[0]!='P'&&p[0]!='p'
		 &&p[0]!='R'&&p[0]!='r'&&p[0]!='T'&&p[0]!='t'&&p[0]!='U'&&p[0]!='u')
	{Result="Unknown Control Command!";return 0;}
	else 
	{
	 return 1;
	}
	
}

void Casm::controlA()
{
	addressU=0x2000,addressD=0x2000;addressT=0x2000;addressP=0x2000;
	CString AResult,tempstr;
	AResult="\r\n";
    int	CurrentlengthAll;
	CurrentlengthAll=pEdit->GetWindowTextLength();
 	pEdit->SetSel(CurrentlengthAll,CurrentlengthAll);
	pEdit->ReplaceSel(AResult);

	WORD INSCOD[]={0x0000,0x0100,0x0200,0x0300,0x0400,0x0500,0x0600,0x0700,0x0800,0x0900,0x0a00,
		           0x0b00,0x4100,0x4400,0x4500,0x4600,0x4700,0x8000,0x8100,0x8200,0x8300,0x8400,
	               0x8500,0x8600,0x8700,0x8800,0x8c00,0x8f00,0xce00,0x2000,0x2100,0x2a00,0x2b00,
				   0x2c00,0x2d00,0x6000,0x6400,0x6500,0x6c00,0x6d00,0x6e00,0x6f00,0xe000,0xe400,
				   0xe500,0xe600,0xe700,0xef00};
    char *DEAR[]={"ADD","SUB","AND","CMP","XOR","TEST","OR","MVRR","DEC","INC","SHL","SHR",
		          "JR","JRC","JRNC","JRZ","JRNZ","JMPA","LDRR","IN","STRR","PSHF","PUSH",
				  "OUT","POP","MVRD","POPF","RET","CALA","ADC","SBB","RCL","RCR","ASR","NOT",
				  "JMPR","JRS","JRNS","CLC","STC","EI","DI","CALR","LDRA","LDRX","STRX","STRA",
				  "IRET"};
    int temptype[]={1,1,1,1,1,1,1,1,23,23,23,23,5,5,5,5,5,6,1,21,1,3,22,21,23,41,3,3,6,1,1,23,23,
		23,23,22,5,5,3,3,3,3,22,41,42,42,41,3};

	if(signA==0)
	{
    	char *CS=now;
		int errorsign=1;
		while(CS[0]==' ')CS++;
        while((CS[0]!='\0')&&(CS[0]!=' '))
		{
			  if(!((CS[0]==' ')||(CS[0]=='0')||(CS[0]=='1')||(CS[0]=='2')||(CS[0]=='3')||(CS[0]=='4')||(CS[0]=='5')||(CS[0]=='6')||(CS[0]=='7')||(CS[0]=='8')||(CS[0]=='9')||(CS[0]=='A')||(CS[0]=='B')||(CS[0]=='C')||(CS[0]=='D')||(CS[0]=='E')||(CS[0]=='F')))
		            errorsign=0;
               CS++;
		}
        while(CS[0]!='\0')
		{
            if(CS[0]!=' ')
			   {errorsign=0;}
            CS++;
		}


		if(errorsign==1)
		{
		WORD TEMPADR=getdata(now);
    	signA=1;
    	if(TEMPADR==0){temp=0x2000;}
     	else {temp=TEMPADR;}
		

		tempstr.Format("%04x",temp);
		AResult=tempstr;
		AResult+=":";
		CurrentlengthAll=pEdit->GetWindowTextLength();
     	pEdit->SetSel(CurrentlengthAll,CurrentlengthAll);
    	pEdit->ReplaceSel(AResult);

		char ch[10];
		ch[0]='\0';
		pEdit->help.MakeIHelp(ch,0);
		pEdit->ShowHelp();
		}
		else
		{
	    CString AResult,tempstr;
	    AResult="Command Error!";
        AResult+="\r\n>";
        int	CurrentlengthAll;
	    CurrentlengthAll=pEdit->GetWindowTextLength();
    	pEdit->SetSel(CurrentlengthAll,CurrentlengthAll);
	    pEdit->ReplaceSel(AResult);

        char ch[10];
		ch[0]='\0';
		pEdit->help.MakeCHelp(ch,0);
		pEdit->ShowHelp();
		}

	}
	else
	{
		char *p=buf,INS[10];
	    WORD tempID;
	    int IDtype;
        while(p[0]==' '){p++;}
        
        if(p[0]=='\0')signA=0;
	    else 
		{
		   signA=1;
		   int i=0,j=0;
           while(p[0]!=' '&&p[0]!='\0')
		   {
			  
			  INS[i]=p[0];	  
			  
			  i++;p++;
		   }
		   INS[i]='\0';
           while(j<48&&strnicmp(INS,DEAR[j],6)!=0)
		   {
			  j++;
		   }

           if(j>=0&&j<48)
		   {
              tempID=INSCOD[j];
			  IDtype=temptype[j];
		      switch(IDtype)
			  {
              case 1:asm1(temp,p,tempID);break;
		      case 21:asm21(temp,p,tempID);break;
	  	      case 22:asm22(temp,p,tempID);break;
		      case 23:asm23(temp,p,tempID);break;
		      case 3:asm3(temp,p,tempID);break;
		      case 41:asm41(temp,p,tempID);break;
		      case 42:asm42(temp,p,tempID);break;
		      case 5:asm5(temp,p,tempID);break;
		      case 6:asm6(temp,p,tempID);break;
			  }
		   }
		   else{
                  
			      char fname[200];
				  char buffer[100];
				  char inscode[20];
				  int inssign=1;
			      GetCurrentDirectory(200,fname);
                  int len=strlen(fname);
				  fname[len++]='\\';
				  fname[len++]='i';
				  fname[len++]='n';
				  fname[len++]='s';
				  fname[len++]='.';
				  fname[len++]='t';
				  fname[len++]='x';
				  fname[len++]='t';
				  fname[len++]='\0';


				 // AfxMessageBox(fname);
                  int i;
                  ifstream in_filemicro;
				  in_filemicro.open(fname,ios::in);
				  //int line=in_file.eof();
               	  while(in_filemicro.eof()==0&&inssign!=0)
				  {
    	            i=0;
					in_filemicro.getline(buffer,100,'\n');
				  //	AfxMessageBox("hello");
                    

                       
				    while(buffer[i]!=' ')
					{inscode[i]=buffer[i];i++;}
                     
					 inscode[i]='\0';
                    // AfxMessageBox(inscode);
				     inssign=stricmp(INS,inscode);

				  }   
				   //inssign=strcmp(INS,inscode);
		           
				   if(inssign==0)
				   {
					  
					   while(buffer[i]==' ')i++;
					   WORD microinsid,microinstype;
					   microinsid=getdata(buffer+i)*16*16;
                       while(buffer[i]!=' ')i++;
					   while(buffer[i]==' ')i++;
					   microinstype=trahexdec(getdata(buffer+i));
					   
					   switch(microinstype)
					   {
						   
                           case 1:asm1(temp,p,microinsid);break;
		                   case 21:asm21(temp,p,microinsid);break;
	  	                   case 22:asm22(temp,p,microinsid);break;
		                   case 23:asm23(temp,p,microinsid);break;
		                   case 3:asm3(temp,p,microinsid);break;
		                   case 41:asm41(temp,p,microinsid);break;
		                   case 42:asm42(temp,p,microinsid);break;
		                   case 5:asm5(temp,p,microinsid);break;
		                   case 6:asm6(temp,p,microinsid);break;   
					   }

				   }
				   else
				   {
					   AResult.Empty();
					   AResult+="Unknown Command!\r\n";
                       CurrentlengthAll=pEdit->GetWindowTextLength();
     	               pEdit->SetSel(CurrentlengthAll,CurrentlengthAll);
    	               pEdit->ReplaceSel(AResult);
				   }
            }//检查是否是用户添加的指令。
           tempstr.Format("%04x",temp);
		   AResult=tempstr;
		   AResult+=":";
		   CurrentlengthAll=pEdit->GetWindowTextLength();
     	   pEdit->SetSel(CurrentlengthAll,CurrentlengthAll);
    	   pEdit->ReplaceSel(AResult);
		   return;
		}
        AResult=">";
        CurrentlengthAll=pEdit->GetWindowTextLength();
     	pEdit->SetSel(CurrentlengthAll,CurrentlengthAll);
    	pEdit->ReplaceSel(AResult);

		//AfxMessageBox("hello");

		char ch[10];
		ch[0]='\0';
		pEdit->help.MakeCHelp(ch,0);
		pEdit->ShowHelp();

	}
}

WORD Casm::tradechex(WORD dear)
{
   int i1,i2,i3,i4;

⌨️ 快捷键说明

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