Point Seclusion
Tuesday April 16, 2024, 04:49:51 am
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Welcome Member
 
  Home Help Search Arcade Gallery Links Staff List Calendar Members Login Register  

This keeps giving me errors, and I don't know why.. PLEASE HELP!!

Pages: [1]   Go Down
  Print  
Author Topic: This keeps giving me errors, and I don't know why.. PLEASE HELP!!  (Read 357 times)
0 Members and 1 Guest are viewing this topic.
f4Gg0t
Member
***
Offline Offline

Posts: 83



View Profile
« on: Monday November 10, 2008, 03:09:33 am »

Code:
#include<fstream.h>
#include<graphics.h>
#include<stdlib.h>
#include<dos.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include"gui.h"

class InstructionSet
{
      char Instruction[5];
      int  NoOfBits;
      int  NoOfCodes;
      char TheCodes[8][3];
      char Remark[50];
   public:
      friend void Clear(InstructionSet);
      void Write();
      void GiveInstruction(char []);
      void GiveCode(int,char []);
      int  GiveBytes();
      int  GiveNoOfCodes();
};

int  MemStat=0,     MemScroll=0;
int  MessageStat=0, MessageScroll=0;
int  ComStat=0,     ComScroll=0;
int  ERR;
char MemVal[7937][3];
char Message[100][36];
char COM[100][20];
char RegDetails[14][30];
char RegScroll=0;
InstructionSet INS[86];

Registers Register;
Flags     Flag;
int M[8],MSet=0;

char Move[8][8][3]={
    "40","41","42","43","44","45","46","47",
    "48","49","4A","4B","4C","4D","4E","4F",
    "50","51","52","53","54","55","56","57",
    "58","59","5A","5B","5C","5D","5E","5F",
    "60","61","62","63","64","65","66","67",
    "68","69","6A","6B","6C","6D","6E","6F",
    "70","71","72","73","74","75","XX","77",
    "78","79","7A","7B","7C","7D","7E","7F",
   };

void CopyToArray();
void CheckCode();
void ClearMessages();
void ClearMemory();
void ResetData();
void CreateMemoryAddress();
void CreateCommandList();
void CreateMessageList();
void CreateRegisterList();
void SaveFile();
void OpenFile();
void Compile();
void Execute();
void SetParity();
void SetSign();
void SetZero(int []);
void ConditionalJump(int,int,int&);
void CALL(int,int,int&);
void RET(int,int,int&);
void PUSH(int [],int [],int &);
void POP(int [],int [],int &);
void COMPARE(int [],int &);
void ADD(int [],int &);
void ADD_CY(int [],int &);
void SUB(int [],int &);
void SUB_B(int [],int &);
void AND(int [],int &);
void OR(int [],int &);
void XOR(int [],int &);
void MOVE(int [],int [],int &i);
void DAA(int &);
void DAD(int [],int [],int &);
void DCR(int [],int &);
void INR(int [],int &);
void INX(int [],int [],int &);
void DCX(int [],int [],int &);
void RAL(int &);
void RAR(int &);
void RLC(int &);
void RRC(int &);

void main()
{
  InitGraph();
  DrawDialog();
  setbkcolor(BLACK);
  CopyToArray();
  int  n;
  char Temp[20],T[5];

  ResetData();
  CreateMemoryAddress();
  CreateCommandList();
  CreateMessageList();
  CreateRegisterList();
  CommandButton COMPILE     (8,448,72,461,"COMPILE");
  CommandButton EXECUTE     (76,448,140,461,"EXECUTE");
  CommandButton RESET       (144,448,208,461," RESET ");
  CommandButton EXIT        (594,448,633,461,"EXIT");
  CommandButton SAVE        (551,448,590,461,"SAVE");
  CommandButton OPEN        (508,448,547,461,"OPEN");
  CommandButton ScrollUP    (175,10,191,24,"");
  CommandButton ScrollDown  (175,358,191,372,"");
  CommandButton MemUP       (288,10,304,24,"");
  CommandButton MemDown     (288,358,304,372,"");
  CommandButton MessageUP   (599,10,615,24,"");
  CommandButton MessageDown (599,166,615,180,"");
  CommandButton RegUp       (599,362,615,376,"");
  CommandButton RegDown     (599,393,615,407,"");
  CommandButton GetCom      (8,407,174,420,"  ADD NEW COMMAND");
  CommandButton EditCom     (8,422,174,436,"   ALTER COMMAND ");
  CommandButton EditMem     (208,376,305,390,"EDIT MEMORY");
  CommandButton ViewMem     (208,393,305,407,"VIEW MEMORY");
  Text3D(404,469,"8085 Simulator - By Sandeep.G");
  InitMouse();
  ShowMouse();
  int Stat=0;
  while(1)
  {
//    GetStatus(&BUTTON,&X,&Y);
//    gotoxy(28,27); printf("X:%3d Y:%3d",X,Y);

    Stat=EXIT.IsBtnClicked();
    if(Stat==1)        break;

    Stat=MemUP.IsBtnClicked();
    if(Stat==1&&MemScroll!=0)
    {
      MemScroll--;
      CreateMemoryAddress();
    }

    Stat=MemDown.IsBtnClicked();
    if(Stat==1&&MemScroll!=7915)
    {
      MemScroll++;
      CreateMemoryAddress();
    }

    Stat=GetCom.IsBtnClicked();
    if(Stat==1&&ComStat!=99)
    {
      gotoxy(3,25); cout<<"                   ";
      gotoxy(3,25);
      gets(Temp);
      ToSentence(ComStat+1,T);
      strcpy(COM[ComStat],T);
      strcat(COM[ComStat],". ");
      strupr(Temp);
      strcat(COM[ComStat],Temp);
      gotoxy(3,25); cout<<"                   ";
      ComStat++;
      CreateCommandList();
    }

    Stat=ScrollUP.IsBtnClicked();
    if(Stat==1&&ComScroll!=0)
    {
      ComScroll--;
      CreateCommandList();
    }

    Stat=ScrollDown.IsBtnClicked();
    if(Stat==1&&ComScroll!=78&&ComStat>=23)
    {
      ComScroll++;
      CreateCommandList();
    }

    Stat=MessageUP.IsBtnClicked();
    if(Stat==1&&MessageScroll!=0)
    {
      MessageScroll--;
      CreateMessageList();
    }

    Stat=MessageDown.IsBtnClicked();
    if(Stat==1&&MessageScroll!=89&&MessageStat>=11)
    {
      MessageScroll++;
      CreateMessageList();
    }

    Stat=RegUp.IsBtnClicked();
    if(Stat==1&&RegScroll!=0)
    {
      RegScroll--;
      CreateRegisterList();
    }

    Stat=RegDown.IsBtnClicked();
    if(Stat==1&&RegScroll!=12)
    {
      RegScroll++;
      CreateRegisterList();
    }

    Stat=COMPILE.IsBtnClicked();
    if(Stat==1)      { CheckCode();   Compile(); }

    Stat=EXECUTE.IsBtnClicked();
    if(Stat==1)      { Execute(); }

    Stat=RESET.IsBtnClicked();
    if(Stat==1)
    {
      ResetData();
      CreateMemoryAddress();      CreateCommandList();
      CreateMessageList();        CreateRegisterList();
    }

    Stat=OPEN.IsBtnClicked();
    if(Stat==1)      OpenFile();

    Stat=SAVE.IsBtnClicked();
    if(Stat==1)      SaveFile();

    Stat=EditCom.IsBtnClicked();
    if(Stat==1)
    {
      InputBox(T,"ALTER COMMAND","Enter The Line Number"," ");
      n=atol(T);
      if(n<=0||n>(ComStat))
MessageBox("ERROR","Invalid Line Number","Operation Terminated");
      else
      {
       InputBox(Temp,"ALTER COMMAND",COM[n-1],"Enter New Line");
       strupr(Temp);
       strcpy(COM[n-1],T);
       strcat(COM[n-1],". ");
       strcat(COM[n-1],Temp);
      }
      CreateCommandList();
    }

    Stat=EditMem.IsBtnClicked();
    if(Stat==1)
    {
      InputBox(Temp,"EDIT MEMORY","Enter The Memory Address"," ");
      strupr(Temp);
      if(!IsInLimit(2,Temp))
MessageBox("ERROR","Value Out Of Range","Operation Terminated");
      else
      {
InputBox(T,"EDIT MEMORY","Enter Value"," ");
strupr(T);
if(!IsInLimit(1,T))
    MessageBox("ERROR","Value Out Of Range","Operation Terminated");
else
{
   n=ToDec(Temp);
   n-=16639;
   strcpy(MemVal[n],T);
   CreateMemoryAddress();
}
      }
    }

    Stat=ViewMem.IsBtnClicked();
    if(Stat==1)
    {
      InputBox(T,"VIEW MEMORY","Enter The Memory Address"," ");
      strupr(T);
      if(!IsInLimit(2,T))
MessageBox("ERROR","Value Out Of Range","Operation Terminated");
      else
      {
strcpy(Temp,T);
strcat(Temp," Contains: ");
n=ToDec(T);
n-=16639;
MessageBox("MEMORY VIEWER",Temp,MemVal[n]);
      }
    }

  }
  closegraph();
}

void Clear(InstructionSet Inst)
{
  int i;
  strcpy(Inst.Instruction," ");
  Inst.NoOfBits=0;
  Inst.NoOfCodes=0;
  for(i=0;i<8;i++)
    strcpy(Inst.TheCodes[i]," ");
  strcpy(Inst.Remark," ");
}

void InstructionSet::Write()
{
  cout<<"\nInstruction       : "<<Instruction;
  cout<<"\nNo Of Bits        : "<<NoOfBits;
  cout<<"\nTotal No Of Codes : "<<NoOfCodes;
  cout<<"\nThe Codes...";
  for(int i=0;i<NoOfCodes;i++)
  {
    cout<<"\n\tCode "<<i<<": "<<TheCodes[i];
  }
  cout<<"\nRemark...\n";
  puts(Remark);
}

void InstructionSet::GiveInstruction(char V[])
{         strcpy(V,Instruction);             }

void InstructionSet::GiveCode(int N, char V[])
{         strcpy(V,TheCodes[N]);             }

int InstructionSet::GiveBytes()
{         return NoOfBits;    }

int  InstructionSet::GiveNoOfCodes()
{         return NoOfCodes;        }

void CopyToArray()
{
  int CH;
  fstream FIO;
  FIO.open("INST.dat",ios::in);
  FIO.seekg(0);
  int Count=-1;
  while(Count!=85)
  {
    Count++;
    Clear(INS[Count]);
    FIO.read((char *)&INS[Count],sizeof(INS[Count]));
  }
  FIO.close();
}

void SaveFile()
{
  char CH[20];
  fstream FIO;
  if(ComStat==0)
    MessageBox("ERROR","Can't Save Empty File","Aborting..");
  else
  {
    InputBox(CH,"SAVE FILE","Enter The File Name:"," ");
    strcat(CH,".MNE");
    FIO.open(CH,ios::out|ios::binary);
    if(!FIO)
      MessageBox("ERROR","The File Can't Be Opened.","Aborting..");
    else
    {
      for(int i=0;i<ComStat;i++)
FIO.write((char *)&COM[i],sizeof(COM[i]));
      FIO.close();
      MessageBox("8085 Simulator","File Operation Complete"," ");
    }
  }
}

void OpenFile()
{
  char CH[20];
  fstream FIO;
  if(ComStat>0)
  {
    InputBox(CH,"8085 Simulator","Save Current File ?","Enter y/n");
    strupr(CH);
    if(strcmp(CH,"Y")==0)
      SaveFile();
  }
  ResetData();
  CreateMemoryAddress();      CreateCommandList();
  CreateMessageList();        CreateRegisterList();
  InputBox(CH,"OPEN FILE","Enter The File Name:"," ");
  strcat(CH,".MNE");
  FIO.open(CH,ios::in|ios::nocreate|ios::binary);
  if(!FIO)
     MessageBox("ERROR","The File Can't Be Opened.","Aborting..");
  else
  {
    while(FIO)
    {
      FIO.read((char *)&COM[ComStat],sizeof(COM[ComStat]));
      ComStat++;
    }
    CreateCommandList();
    MessageBox("8085 Simulator","File Operation Complete"," ");
    FIO.close();
  }
  ComStat--;
}

void ClearMessages()
{
  for(int i=0;i<100;i++)
    strcpy(Message[i]," ");
    MessageStat=MessageScroll=0;
}

void ClearMemory()
{
  for(int i=0;i<7937;i++)
    strcpy(MemVal[i],"00");
  MemStat=MemScroll=0;
}

void ResetData()
{
  MSet=0;
  for(int i=0;i<100;i++)
    strcpy(COM[i],"                   ");
    ComStat=ComScroll=0;
  ClearMemory();
  ClearMessages();

  for(i=0;i<8;i++)
  {
    Register.A[i]=Register.B[i]=Register.C[i]=Register.D[i]=Register.E[i]=0;
    Register.H[i]=Register.L[i]=0;
  }
  strcpy(Register.SP,"50FF");
  strcpy(Register.PC,"XXXX");
  Flag.CY=Flag.Z=Flag.S=Flag.AC=Flag.P=0;
  RegScroll=0;
}

void CreateMemoryAddress()
{
  char Val[5];
  for(int i=MemScroll,j=2;i<=MemScroll+21;i++,j++)
  {
    ToHex(i+16639,Val);
   gotoxy(28,j); cout<<Val<<"  "<<MemVal[i];
  }
}

void CreateCommandList()
{
  for(int i=ComScroll,j=2;i<=ComScroll+21;i++,j++)
  {
    gotoxy(3,j);  cout<<"                   ";
    gotoxy(3,j);  cout<<COM[i];
  }
}

void CreateRegisterList()
{
  char Val[6];
  strcpy(RegDetails[0], "ACCUMULATOR           : ");
  ToBCD(1,Register.A,Val);
  strcat(RegDetails[0],Val);
  strcpy(RegDetails[1], "REGISTER B            : ");
  ToBCD(1,Register.B,Val);
  strcat(RegDetails[1],Val);
  strcpy(RegDetails[2], "REGISTER C            : ");
  ToBCD(1,Register.C,Val);
  strcat(RegDetails[2],Val);
  strcpy(RegDetails[3], "REGISTER D            : ");
  ToBCD(1,Register.D,Val);
  strcat(RegDetails[3],Val);
  strcpy(RegDetails[4], "REGISTER E            : ");
  ToBCD(1,Register.E,Val);
  strcat(RegDetails[4],Val);
  strcpy(RegDetails[5], "REGISTER H            : ");
  ToBCD(1,Register.H,Val);
  strcat(RegDetails[5],Val);
  strcpy(RegDetails[6], "REGISTER L            : ");
  ToBCD(1,Register.L,Val);
  strcat(RegDetails[6],Val);
  strcpy(RegDetails[7], "STACK POINTER         : ");
  strcat(RegDetails[7],Register.SP);
  strcpy(RegDetails[8], "PROGRAM COUNTER       : ");
  strcat(RegDetails[8],Register.PC);
  strcpy(RegDetails[9], "CARRY FLAG            : ");
  ToSentence(Flag.CY,Val);
  strcat(RegDetails[9],Val);
  strcpy(RegDetails[10],"ZERO FLAG             : ");
  ToSentence(Flag.Z,Val);
  strcat(RegDetails[10],Val);
  strcpy(RegDetails[11],"SIGN FLAG             : ");
  ToSentence(Flag.S,Val);
  strcat(RegDetails[11],Val);
  strcpy(RegDetails[12],"PARITY FLAG           : ");
  ToSentence(Flag.P,Val);
  strcat(RegDetails[12],Val);
  strcpy(RegDetails[13],"AUXILLIARY CARRY FLAG : ");
  ToSentence(Flag.AC,Val);
  strcat(RegDetails[13],Val);
  for(int i=RegScroll,j=24;i<=RegScroll+1;i++,j++)
  {
    gotoxy(41,j);  cout<<"                            ";
    gotoxy(41,j);  cout<<RegDetails[i];
  }
}

void CreateMessageList()
{
  for(int i=MessageScroll,j=2;i<=MessageScroll+9;i++,j++)
  {
    gotoxy(41,j);  cout<<"                           ";
    gotoxy(41,j);  cout<<Message[i];
  }
}

void CheckCode()
{
  char Val[5],CurLine[10][10];
  int i,j,Len;
  int Found;
  ERR=0;
  ClearMessages();
  ClearMemory();
  for(i=0;i<ComStat;i++)
  {
    Found=0;
    Seperate(CurLine,COM[i],Len);
    if(Len>5) goto Err;
    if(strcmp(CurLine[1],"MOV")==0)
    {  Found=1;  goto DET;   }
    for(j=0;j<=85;j++)
    {
      INS[j].GiveInstruction(Val);
      if(strcmp(CurLine[1],Val)==0)
      { Found=3;    goto DET;     }
    }
    if(Found==0)
    {
      if(strcmp(CurLine[2],"MOV")==0)
      { Found=2;    goto DET;     }
      for(j=0;j<=85;j++)
      {
INS[j].GiveInstruction(Val);
if(strcmp(CurLine[2],Val)==0)
{ Found=2;    goto DET;     }
      }
    }
Err:
    ERR++;
    strcpy(Message[MessageStat],"ERROR: ");
    strcat(Message[MessageStat],COM[i]);
    MessageStat++;
    CreateMessageList();
DET:
  }
}

void Compile()
{
  char Val[5],CurLine[10][10];
  int  i,j,Len;
  int  Val1,Val2;
  while(1)
  {
    InputBox(Val,"COMPILER","Enter The Starting Address"," ");
    strupr(Val);
    i=IsInLimit(2,Val);
    if(i==1)
      break;
    else
     MessageBox("COMPILER","INVALID ADDRESS","Value Must Be 40FF-50FF");
  }
  i=ToDec(Val);
  i-=16639;
  int  Mode;
  int  StAdd=i;
  char HA[3],LA[3];
  LABELStack Source[100];        int TopS=-1;
  LABELStack Destination[100];   int TopD=-1;
  for(i=0;i<ComStat;i++)
  {
    Mode=0;
    for(j=0;j<10;j++)  strcpy(CurLine[i]," ");
    Seperate(CurLine,COM[i],Len);
    if(strcmp(CurLine[1],"MOV")==0)
    {  Mode=1;  goto DET;   }
    for(j=0;j<=85;j++)
    {
      INS[j].GiveInstruction(Val);
      if(strcmp(CurLine[1],Val)==0)
      { Mode=3;    goto DET;     }
    }
    if(Mode==0)
    {
      if(strcmp(CurLine[2],"MOV")==0)
      { Mode=2;    goto DET;     }
      for(j=0;j<=85;j++)
      {
INS[j].GiveInstruction(Val);
if(strcmp(CurLine[2],Val)==0)
{ Mode=2;    goto DET;     }
      }
    }
DET:
    switch(Mode)
    {
      case 1: // MOV INSTRUCTION
      if((
   strcmp(CurLine[2],"B")==0||strcmp(CurLine[2],"C")==0||
   strcmp(CurLine[2],"D")==0||strcmp(CurLine[2],"E")==0||
   strcmp(CurLine[2],"H")==0||strcmp(CurLine[2],"L")==0||
   strcmp(CurLine[2],"M")==0||strcmp(CurLine[2],"A")==0
  )&&(
   strcmp(CurLine[3],"B")==0||strcmp(CurLine[3],"C")==0||
   strcmp(CurLine[3],"D")==0||strcmp(CurLine[3],"E")==0||
   strcmp(CurLine[3],"H")==0||strcmp(CurLine[3],"L")==0||
   strcmp(CurLine[3],"M")==0||strcmp(CurLine[3],"A")==0
  )&&(
   strcmp(CurLine[2],"M")!=0||strcmp(CurLine[3],"M")!=0
))
{
   Val1=GetIndex(8,CurLine[2]);
   Val2=GetIndex(8,CurLine[3]);
   strcpy(MemVal[StAdd],Move[Val1][Val2]);
   StAdd++;
}
else
{
   ERR++;
   ToSentence(i+1,Val);
   strcpy(Message[MessageStat],"ERROR(");
   strcat(Message[MessageStat],Val);
   strcat(Message[MessageStat],"): MOV Is Invalid");
   MessageStat++;
}
      break;
      case 2: //HERE THE CASE 1&3 ARE REPEATED WITH THE EXPECTION THAT THERE
      //IS AN INCREMENT IN THE INDEX OF CURLINE[]
      // MOV INSTRUCTION
      TopD++;
      strcpy(Destination[TopD].LABEL,CurLine[1]);
      Destination[TopD].ADD=StAdd;
      if(strcmp(CurLine[2],"MOV")==0)
      {
if((
     strcmp(CurLine[3],"B")==0||strcmp(CurLine[3],"C")==0||
     strcmp(CurLine[3],"D")==0||strcmp(CurLine[3],"E")==0||
     strcmp(CurLine[3],"H")==0||strcmp(CurLine[3],"L")==0||
     strcmp(CurLine[3],"M")==0||strcmp(CurLine[3],"A")==0
    )&&(
     strcmp(CurLine[4],"B")==0||strcmp(CurLine[4],"C")==0||
     strcmp(CurLine[4],"D")==0||strcmp(CurLine[4],"E")==0||
     strcmp(CurLine[4],"H")==0||strcmp(CurLine[4],"L")==0||
     strcmp(CurLine[4],"M")==0||strcmp(CurLine[4],"A")==0
    )&&(
     strcmp(CurLine[3],"M")!=0||strcmp(CurLine[4],"M")!=0
  ))
  {
     Val1=GetIndex(8,CurLine[3]);
     Val2=GetIndex(8,CurLine[4]);
     strcpy(MemVal[StAdd],Move[Val1][Val2]);
     StAdd++;     goto END2;
  }
  else
  {
   ERR++;
   ToSentence(i+1,Val);
   strcpy(Message[MessageStat],"ERROR(");
   strcat(Message[MessageStat],Val);
   strcat(Message[MessageStat],"): MOV Is Invalid");
   MessageStat++;  goto END2;
  }
      }
      //MVI INSTRUCTION
      if(strcmp(CurLine[2],"MVI")==0)
      {
if(IsInLimit(1,CurLine[4])==0)
{
   ERR++;
   ToSentence(i+1,Val);
   strcpy(Message[MessageStat],"ERROR(");
   strcat(Message[MessageStat],Val);
   strcat(Message[MessageStat],"): Value Out Of Range");
   MessageStat++;  goto END2;
}
Val1=GetIndex(8,CurLine[3]);
switch(Val1)
{
  case 0: strcpy(MemVal[StAdd],"06");  break;
  case 1: strcpy(MemVal[StAdd],"0E");  break;
  case 2: strcpy(MemVal[StAdd],"16");  break;
  case 3: strcpy(MemVal[StAdd],"1E");  break;
  case 4: strcpy(MemVal[StAdd],"26");  break;
  case 5: strcpy(MemVal[StAdd],"2E");  break;
  case 6: strcpy(MemVal[StAdd],"36");  break;
  case 7: strcpy(MemVal[StAdd],"3E");  break;
  default:
   ERR++;
   ToSentence(i+1,Val);
   strcpy(Message[MessageStat],"ERROR(");
   strcat(Message[MessageStat],Val);
   strcat(Message[MessageStat],"): Invalid Register");
   MessageStat++;  goto END2;
}
StAdd++;  strcpy(MemVal[StAdd],CurLine[4]);
StAdd++;  goto END2;
      }
      //INSTRUCTION FOR PUSH AND POP
      if(strcmp(CurLine[2],"PUSH")==0)
      {
if(strcmp(CurLine[3],"PSW")==0)
{ strcpy(MemVal[StAdd],"F5"); goto SUCC3; }
Val1=GetIndex(4,CurLine[3]);
switch(Val1)
{
  case 0: strcpy(MemVal[StAdd],"C5");  break;
  case 1: strcpy(MemVal[StAdd],"D5");  break;
  case 2: strcpy(MemVal[StAdd],"E5");  break;
  default:
   ERR++;
   ToSentence(i+1,Val);
   strcpy(Message[MessageStat],"ERROR(");
   strcat(Message[MessageStat],Val);
   strcat(Message[MessageStat],"): Invalid Register");
   MessageStat++;  goto END2;
}
SUCC3:    StAdd++;  goto END2;
      }
      if(strcmp(CurLine[2],"POP")==0)
      {
if(strcmp(CurLine[3],"PSW")==0)
{ strcpy(MemVal[StAdd],"F1"); goto SUCC4; }
Val1=GetIndex(4,CurLine[3]);
switch(Val1)
{
  case 0: strcpy(MemVal[StAdd],"C1");  break;
  case 1: strcpy(MemVal[StAdd],"D1");  break;
  case 2: strcpy(MemVal[StAdd],"E1");  break;
  default:
   ERR++;
   ToSentence(i+1,Val);
   strcpy(Message[MessageStat],"ERROR(");
   strcat(Message[MessageStat],Val);
   strcat(Message[MessageStat],"): Invalid Register");
   MessageStat++;  goto END2;
}
SUCC4:    StAdd++;  goto END2;
      }
Report Spam   Report to moderator   Logged

z

Share on Facebook Share on Twitter

f4Gg0t
Member
***
Offline Offline

Posts: 83



View Profile
« Reply #1 on: Monday November 10, 2008, 03:10:41 am »

Okay its to long to post, so I'll have to split it up

Code:
      //LXI INSTRUCTION
      if(strcmp(CurLine[2],"LXI")==0)
      {
Val1=GetIndex(4,CurLine[3]);
switch(Val1)
{
  case 0: strcpy(MemVal[StAdd],"01");  break;
  case 1: strcpy(MemVal[StAdd],"11");  break;
  case 2: strcpy(MemVal[StAdd],"21");  break;
  case 3: strcpy(MemVal[StAdd],"31");  break;
  default:
   ERR++;
   ToSentence(i+1,Val);
   strcpy(Message[MessageStat],"ERROR(");
   strcat(Message[MessageStat],Val);
   strcat(Message[MessageStat],"): Invalid Register");
   MessageStat++;  goto END2;

}
StAdd++;
CutString(CurLine[4],HA,LA);
strcpy(MemVal[StAdd],LA); StAdd++;
strcpy(MemVal[StAdd],HA); StAdd++;
goto END2;
      }
      //JUMP AND CALL INSTRUCTIONS
      if(strcmp(CurLine[2],"CALL")==0||strcmp(CurLine[2],"CC")==0||
strcmp(CurLine[2],"CNC")==0||strcmp(CurLine[2],"CP")==0 ||
strcmp(CurLine[2],"CM")==0||strcmp(CurLine[2],"CPE")==0 ||
strcmp(CurLine[2],"CPO")==0||strcmp(CurLine[2],"CZ")==0 ||
strcmp(CurLine[2],"CNZ")==0||strcmp(CurLine[2],"JMP")==0||
strcmp(CurLine[2],"JC")==0||strcmp(CurLine[2],"JNC")==0 ||
strcmp(CurLine[2],"JP")==0||strcmp(CurLine[2],"JM")==0  ||
strcmp(CurLine[2],"JPE")==0||strcmp(CurLine[2],"JPO")==0||
strcmp(CurLine[2],"JZ")==0||strcmp(CurLine[2],"JNZ")==0   )
      {
if(strcmp(CurLine[3]," ")==0)
{
   ERR++;
   ToSentence(i+1,Val);
   strcpy(Message[MessageStat],"ERROR(");
   strcat(Message[MessageStat],Val);
   strcat(Message[MessageStat],"): LABEL Missing");
   MessageStat++;  goto END2;
}
for(j=0;j<=85;j++)
{
  if((INS[j].GiveBytes()==3)&&(INS[j].GiveNoOfCodes()==1))
  {
    INS[j].GiveInstruction(Val);
    if(strcmp(CurLine[2],Val)==0)
    {
      INS[j].GiveCode(0,Val);
      strcpy(MemVal[StAdd],Val);  StAdd++;
      TopS++;   Source[TopS].ADD=StAdd;
      strcpy(Source[TopS].LABEL,CurLine[3]);
      StAdd+=2;
      goto END2;
    }
  }
}
      }
      //INSTRUCTIONS FOR REGISTER PAIR
      for(j=0;j<=85;j++)
      {
if((INS[j].GiveBytes()==1)&&(INS[j].GiveNoOfCodes()==4))
{
  INS[j].GiveInstruction(Val);
  if(strcmp(CurLine[2],Val)==0)
  {
    Val1=GetIndex(4,CurLine[3]);
    if(!(Val1>=0)&&(Val1<=3))
    {
   ERR++;
   ToSentence(i+1,Val);
   strcpy(Message[MessageStat],"ERROR(");
   strcat(Message[MessageStat],Val);
   strcat(Message[MessageStat],"): Invalid Register");
   MessageStat++;  goto END2;
    }
    INS[j].GiveCode(Val1,Val);
    strcpy(MemVal[StAdd],Val);        StAdd++;
    goto END2;
  }
}
      }
      //INSTRUCTIONS WITH NO OPERANDS
      for(j=0;j<=85;j++)
      {
if(INS[j].GiveBytes()==0)
{
  INS[j].GiveInstruction(Val);
  if(strcmp(CurLine[2],Val)==0)
  {
    INS[j].GiveCode(0,Val);
    strcpy(MemVal[StAdd],Val);
    StAdd++;   goto END2;
  }
}
      }
      //INSTRUCTIONS WITH 8-BIT OPERAND.
      for(j=0;j<=85;j++)
      {
if((INS[j].GiveBytes()==2)&&(INS[j].GiveNoOfCodes()==1))
{
  INS[j].GiveInstruction(Val);
  if(strcmp(CurLine[2],Val)==0)
  {
    if(IsInLimit(1,CurLine[3])==0)
    {
      ERR++;
      ToSentence(i+1,Val);
      strcpy(Message[MessageStat],"ERROR(");
      strcat(Message[MessageStat],Val);
      strcat(Message[MessageStat],"): Value Out Of Range");
      MessageStat++;  goto END2;
    }
    INS[j].GiveCode(0,Val);
    strcpy(MemVal[StAdd],Val);        StAdd++;
    strcpy(MemVal[StAdd],CurLine[3]); StAdd++;
    goto END2;
  }
}
      }
      //INSTRUCTIONS WITH 16-BIT OPERAND.
      for(j=0;j<=85;j++)
      {
if((INS[j].GiveBytes()==3)&&(INS[j].GiveNoOfCodes()==1))
{
  INS[j].GiveInstruction(Val);
  if(strcmp(CurLine[2],Val)==0)
  {
    if(IsInLimit(2,CurLine[3])==0)
    {
      ERR++;
      ToSentence(i+1,Val);
      strcpy(Message[MessageStat],"ERROR(");
      strcat(Message[MessageStat],Val);
      strcat(Message[MessageStat],"): Value Out Of Range");
      MessageStat++;  goto END2;
    }
    INS[j].GiveCode(0,Val);
    strcpy(MemVal[StAdd],Val);        StAdd++;
    CutString(CurLine[3],HA,LA);
    strcpy(MemVal[StAdd],LA); StAdd++;
    strcpy(MemVal[StAdd],HA); StAdd++;
    goto END2;
  }
}
      }
      //1-BYTE INSTRUCTIONS WITH OPERANDS AS REGISTERS
      for(j=0;j<=85;j++)
      {
if((INS[j].GiveBytes()==1)&&(INS[j].GiveNoOfCodes()==8))
{
  INS[j].GiveInstruction(Val);
  if(strcmp(CurLine[2],Val)==0)
  {
    Val1=GetIndex(8,CurLine[3]);
    if(!(Val1>=0)&&(Val1<=7))
    {
      ERR++;
      ToSentence(i+1,Val);
      strcpy(Message[MessageStat],"ERROR(");
      strcat(Message[MessageStat],Val);
      strcat(Message[MessageStat],"): Invalid Register");
      MessageStat++;  goto END2;
    }
    INS[j].GiveCode(Val1,Val);
    strcpy(MemVal[StAdd],Val);        StAdd++;
    goto END2;
  }
}
      }
      //STAX AND LDAX INSTRUCTIONS.
      for(j=0;j<=85;j++)
      {
if((INS[j].GiveBytes()==1)&&(INS[j].GiveNoOfCodes()==2))
{
  INS[j].GiveInstruction(Val);
  if(strcmp(CurLine[2],Val)==0)
  {
    Val1=GetIndex(2,CurLine[3]);
    if(!(Val1>=0)&&(Val1<=1))
    {
      ERR++;
      ToSentence(i+1,Val);
      strcpy(Message[MessageStat],"ERROR(");
      strcat(Message[MessageStat],Val);
      strcat(Message[MessageStat],"): Invalid Register");
      MessageStat++;  goto END2;
    }
    INS[j].GiveCode(Val1,Val);
    strcpy(MemVal[StAdd],Val);        StAdd++;
    goto END2;
  }
}
      }

END2:       break;
      case 3:
      //MVI INSTRUCTION
      if(strcmp(CurLine[1],"MVI")==0)
      {
if(IsInLimit(1,CurLine[3])==0)
{
  ERR++
  ToSentence(i+1,Val);
  strcpy(Message[MessageStat],"ERROR(");
  strcat(Message[MessageStat],Val);
  strcat(Message[MessageStat],"): Value Out Of Range");
  MessageStat++;  goto END1;
}
Val1=GetIndex(8,CurLine[2]);
switch(Val1)
{
  case 0: strcpy(MemVal[StAdd],"06");  break;
  case 1: strcpy(MemVal[StAdd],"0E");  break;
  case 2: strcpy(MemVal[StAdd],"16");  break;
  case 3: strcpy(MemVal[StAdd],"1E");  break;
  case 4: strcpy(MemVal[StAdd],"26");  break;
  case 5: strcpy(MemVal[StAdd],"2E");  break;
  case 6: strcpy(MemVal[StAdd],"36");  break;
  case 7: strcpy(MemVal[StAdd],"3E");  break;
  default:
ERR++;
ToSentence(i+1,Val);
strcpy(Message[MessageStat],"ERROR(");
strcat(Message[MessageStat],Val);
strcat(Message[MessageStat],"): Invalid Register");
MessageStat++;  goto END1;
}
StAdd++;  strcpy(MemVal[StAdd],CurLine[3]);
StAdd++;  goto END1;
      }
      //INSTRUCTION FOR PUSH AND POP
      if(strcmp(CurLine[1],"PUSH")==0)
      {
if(strcmp(CurLine[2],"PSW")==0)
{ strcpy(MemVal[StAdd],"F5"); goto SUCC1; }
Val1=GetIndex(4,CurLine[2]);
switch(Val1)
{
  case 0: strcpy(MemVal[StAdd],"C5");  break;
  case 1: strcpy(MemVal[StAdd],"D5");  break;
  case 2: strcpy(MemVal[StAdd],"E5");  break;
  default:
ERR++;
ToSentence(i+1,Val);
strcpy(Message[MessageStat],"ERROR(");
strcat(Message[MessageStat],Val);
strcat(Message[MessageStat],"): Invalid Register");
MessageStat++;  goto END1;
}
SUCC1:    StAdd++;  goto END1;
      }
      if(strcmp(CurLine[1],"POP")==0)
      {
if(strcmp(CurLine[2],"PSW")==0)
{ strcpy(MemVal[StAdd],"F1"); goto SUCC2; }
Val1=GetIndex(4,CurLine[2]);
switch(Val1)
{
  case 0: strcpy(MemVal[StAdd],"C1");  break;
  case 1: strcpy(MemVal[StAdd],"D1");  break;
  case 2: strcpy(MemVal[StAdd],"E1");  break;
  default:
ERR++;
ToSentence(i+1,Val);
strcpy(Message[MessageStat],"ERROR(");
strcat(Message[MessageStat],Val);
strcat(Message[MessageStat],"): Invalid Register");
MessageStat++;  goto END1;
}
SUCC2:    StAdd++;  goto END1;
      }
      //LXI INSTRUCTION
      if(strcmp(CurLine[1],"LXI")==0)
      {
Val1=GetIndex(4,CurLine[2]);
switch(Val1)
{
  case 0: strcpy(MemVal[StAdd],"01");  break;
  case 1: strcpy(MemVal[StAdd],"11");  break;
  case 2: strcpy(MemVal[StAdd],"21");  break;
  case 3: strcpy(MemVal[StAdd],"31");  break;
  default:
ERR++;
ToSentence(i+1,Val);
strcpy(Message[MessageStat],"ERROR(");
strcat(Message[MessageStat],Val);
strcat(Message[MessageStat],"): Invalid Register");
MessageStat++;  goto END1;
}
StAdd++;
CutString(CurLine[3],HA,LA);
strcpy(MemVal[StAdd],LA); StAdd++;
strcpy(MemVal[StAdd],HA); StAdd++;
goto END1;
      }
      //JUMP AND CALL INSTRUCTIONS
      if(strcmp(CurLine[1],"CALL")==0||strcmp(CurLine[1],"CC")==0||
strcmp(CurLine[1],"CNC")==0||strcmp(CurLine[1],"CP")==0 ||
strcmp(CurLine[1],"CM")==0||strcmp(CurLine[1],"CPE")==0 ||
strcmp(CurLine[1],"CPO")==0||strcmp(CurLine[1],"CZ")==0 ||
strcmp(CurLine[1],"CNZ")==0||strcmp(CurLine[1],"JMP")==0||
strcmp(CurLine[1],"JC")==0||strcmp(CurLine[1],"JNC")==0 ||
strcmp(CurLine[1],"JP")==0||strcmp(CurLine[1],"JM")==0  ||
strcmp(CurLine[1],"JPE")==0||strcmp(CurLine[1],"JPO")==0||
strcmp(CurLine[1],"JZ")==0||strcmp(CurLine[1],"JNZ")==0   )
      {
if(strcmp(CurLine[2]," ")==0)
{
   ERR++;
   ToSentence(i+1,Val);
   strcpy(Message[MessageStat],"ERROR(");
   strcat(Message[MessageStat],Val);
   strcat(Message[MessageStat],"): LABEL Missing");
   MessageStat++;  goto END1;
}
for(j=0;j<=85;j++)
{
  if((INS[j].GiveBytes()==3)&&(INS[j].GiveNoOfCodes()==1))
  {
    INS[j].GiveInstruction(Val);
    if(strcmp(CurLine[1],Val)==0)
    {
      INS[j].GiveCode(0,Val);
      strcpy(MemVal[StAdd],Val);  StAdd++;
      TopS++;   Source[TopS].ADD=StAdd;
      strcpy(Source[TopS].LABEL,CurLine[2]);
      StAdd+=2;
      goto END1;
    }
  }
}
      }
      //INSTRUCTIONS FOR REGISTER PAIR
      for(j=0;j<=85;j++)
      {
if((INS[j].GiveBytes()==1)&&(INS[j].GiveNoOfCodes()==4))
{
  INS[j].GiveInstruction(Val);
  if(strcmp(CurLine[1],Val)==0)
  {
    Val1=GetIndex(4,CurLine[2]);
    if(!(Val1>=0)&&(Val1<=3))
    {
      ERR++;
      ToSentence(i+1,Val);
      strcpy(Message[MessageStat],"ERROR(");
      strcat(Message[MessageStat],Val);
      strcat(Message[MessageStat],"): Invalid Register");
      MessageStat++;  goto END1;
    }
    INS[j].GiveCode(Val1,Val);
    strcpy(MemVal[StAdd],Val);        StAdd++;
    goto END1;
  }
}
      }
      //INSTRUCTIONS WITH NO OPERANDS
      for(j=0;j<=85;j++)
      {
if(INS[j].GiveBytes()==0)
{
  INS[j].GiveInstruction(Val);
  if(strcmp(CurLine[1],Val)==0)
  {
    INS[j].GiveCode(0,Val);
    strcpy(MemVal[StAdd],Val);
    StAdd++;   goto END1;
  }
}
      }
      //INSTRUCTIONS WITH 8-BIT OPERAND.
      for(j=0;j<=85;j++)
      {
if((INS[j].GiveBytes()==2)&&(INS[j].GiveNoOfCodes()==1))
{
  INS[j].GiveInstruction(Val);
  if(strcmp(CurLine[1],Val)==0)
  {
    if(IsInLimit(1,CurLine[2])==0)
    {
      ERR++;
      ToSentence(i+1,Val);
      strcpy(Message[MessageStat],"ERROR(");
      strcat(Message[MessageStat],Val);
      strcat(Message[MessageStat],"): Value Out Of Range");
      MessageStat++;  goto END1;
    }
    INS[j].GiveCode(0,Val);
    strcpy(MemVal[StAdd],Val);        StAdd++;
    strcpy(MemVal[StAdd],CurLine[2]); StAdd++;
    goto END1;
  }
}
      }
      //INSTRUCTIONS WITH 16-BIT OPERAND.
      for(j=0;j<=85;j++)
      {
if((INS[j].GiveBytes()==3)&&(INS[j].GiveNoOfCodes()==1))
{
  INS[j].GiveInstruction(Val);
  if(strcmp(CurLine[1],Val)==0)
  {
    if(IsInLimit(2,CurLine[2])==0)
    {
      ERR++;
      ToSentence(i+1,Val);
      strcpy(Message[MessageStat],"ERROR(");
      strcat(Message[MessageStat],Val);
      strcat(Message[MessageStat],"): Value Out Of Range");
      MessageStat++;  goto END1;
    }
    INS[j].GiveCode(0,Val);
    strcpy(MemVal[StAdd],Val);        StAdd++;
    CutString(CurLine[2],HA,LA);
    strcpy(MemVal[StAdd],LA); StAdd++;
    strcpy(MemVal[StAdd],HA); StAdd++;
    goto END1;
  }
}
      }
      //1-BYTE INSTRUCTIONS WITH OPERANDS AS REGISTERS
      for(j=0;j<=85;j++)
      {
if((INS[j].GiveBytes()==1)&&(INS[j].GiveNoOfCodes()==8))
{
  INS[j].GiveInstruction(Val);
  if(strcmp(CurLine[1],Val)==0)
  {
    Val1=GetIndex(8,CurLine[2]);
    if(!(Val1>=0)&&(Val1<=7))
    {
      ERR++;
      ToSentence(i+1,Val);
      strcpy(Message[MessageStat],"ERROR(");
      strcat(Message[MessageStat],Val);
      strcat(Message[MessageStat],"): Invalid Register");
      MessageStat++;  goto END1;
    }
    INS[j].GiveCode(Val1,Val);
    strcpy(MemVal[StAdd],Val);        StAdd++;
    goto END1;
  }
}
      }
      //STAX AND LDAX INSTRUCTIONS.
      for(j=0;j<=85;j++)
      {
if((INS[j].GiveBytes()==1)&&(INS[j].GiveNoOfCodes()==2))
{
  INS[j].GiveInstruction(Val);
  if(strcmp(CurLine[1],Val)==0)
  {
    Val1=GetIndex(2,CurLine[2]);
    if(!(Val1>=0)&&(Val1<=1))
    {
      ERR++;
      ToSentence(i+1,Val);
      strcpy(Message[MessageStat],"ERROR(");
      strcat(Message[MessageStat],Val);
      strcat(Message[MessageStat],"): Invalid Register");
      MessageStat++;  goto END1;
    }
    INS[j].GiveCode(Val1,Val);
    strcpy(MemVal[StAdd],Val);        StAdd++;
    goto END1;
  }
}
      }
END1:
      break;
    }
  }
  if((TopS!=-1&&TopD==-1)||(TopS==-1&&TopD!=-1))
  {
    ERR++;
    strcpy(Message[MessageStat],"ERROR(*): Labels Mismatch");
    MessageStat++;
  }
  else if(TopS!=-1&&TopD!=-1) //Assigning Labels Starts Here
  {
/*    for(i=0;i<=TopD;i++)  //Checking For Ambiguous Labels Starts.
    {
      for(j=0;j<=TopD;j++)
      {
if(i!=j)
{
  if(strcmp(Destination[i].LABEL,Destination[j].LABEL)==0)
  {
    gotoxy(40,n);
    ERR++;
    strcpy(Message[MessageStat],"ERROR(*): Label ");
    strcat(Message[MessageStat],Destination[i].LABEL);
    strcat(Message[MessageStat]," have repeated");
    MessageStat++;
  }
}
      }
    }                   //Check For Ambiguous Labels Ends.*/
    for(i=0;i<=TopS;i++)
    {
      for(j=0;j<=TopD;j++)
      {
if(strcmp(Source[i].LABEL,Destination[j].LABEL)==0)
{
  ToHex(16639+Destination[j].ADD,Val);
  CutString(Val,HA,LA);
  strcpy(MemVal[Source[i].ADD],LA);
  strcpy(MemVal[Source[i].ADD+1],HA);
}
      }
    }
  }  //Assigning Labels Ends Here.
  END3:
  if(ERR==0)
  {
    CreateMemoryAddress();
    MessageBox("COMPILER","NO ERRORS FOUND","Compilation Successful");
    strcpy(Message[MessageStat],"NO ERRORS FOUND");
    MessageStat++;
    strcpy(Message[MessageStat],"Compilation Successful.");
    MessageStat++;
  }
« Last Edit: Tuesday November 11, 2008, 11:07:26 pm by f4Gg0t » Report Spam   Report to moderator   Logged

z
f4Gg0t
Member
***
Offline Offline

Posts: 83



View Profile
« Reply #2 on: Monday November 10, 2008, 03:11:22 am »

PART 3 lol

Code:
  else
  {
    ClearMemory();
    CreateMemoryAddress();
    ToSentence(ERR,Val);
    strcpy(Message[MessageStat],Val);
    strcat(Message[MessageStat]," ERROR(S) FOUND!");
    MessageStat++;
    strcpy(Message[MessageStat],"Cant't Create HEX Code.");
    MessageBox("COMPILER",Message[MessageStat-1],Message[MessageStat]);
    MessageStat++;
  }
  CreateMessageList();
  MemStat=StAdd;
}

//This function executes the hex code created by the compiler.
//I  have used many if's instead of if..else, as if we use a big
//if..else if..else ladder, C++ compiler shows an error
//'Out Of Memory'

void Execute()
{
  int i,SADD,Temp,TempAr[8];
  int FLAG=1;
  char TempC[10],T[3];
  InputBox(Register.PC,"EXECUTION","Enter The Starting Address"," ");
  strupr(Register.PC);
  i=IsInLimit(2,Register.PC);
  if(i!=1)
  {
    MessageBox("EXECUTION","ADDRESS OUT OF RANGE","Valid: 40FF-50FF");
    return;
  }
  CreateRegisterList();
  SADD=ToDec(Register.PC);
  SADD-=16639;
  i=SADD;
  while(FLAG)  //EXECUTION OF THE HEX CODE BEGINS HERE.
  {
    if(IsInLimit(2,Register.PC)!=1)
    {
      MessageBox("RUNTIME ERROR","Program Counter Misdirected","Program Reset");
      i=SADD;
      goto ExeEND;
    }
    if(IsInLimit(2,Register.SP)!=1)
    {
      MessageBox("RUNTIME ERROR","Invalid Stack Pointer","Program Reset");
      i=SADD;
      goto ExeEND;
    }

    ToBCD(1,Register.H,TempC);
    ToBCD(1,Register.L,T);
    strcat(TempC,T);
    if(IsInLimit(2,TempC)==1)
    {
      ToBCD(1,M,T);
      Temp=ToDec(TempC);
      Temp-=16639;
      strcpy(MemVal[Temp],T);
      CreateMemoryAddress();
      MSet=1;
    }
    else  MSet=0;

    if(strcmp(MemVal[i],"76")==0)        // HLT
    {  FLAG=0; goto End1Loop; }
    if(strcmp(MemVal[i],"00")==0)   // NOP
    {
     i++;
     ToHex(i+16639,Register.PC);
     goto End1Loop;
    }
    if(strcmp(MemVal[i],"DB")==0||strcmp(MemVal[i],"D3")==0) //IN & OUT
    {
      i+=2;
      ToHex(i+16639,Register.PC);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"3F")==0)   // CMC
    {
     if(Flag.CY==0)
Flag.CY=1;
     else
Flag.CY=0;
     i++;
     ToHex(i+16639,Register.PC);
     goto End1Loop;
    }
    if(strcmp(MemVal[i],"37")==0)   // STC
    {
     Flag.CY=1;
     i++;
     ToHex(i+16639,Register.PC);
     goto End1Loop;
    }
    if(strcmp(MemVal[i],"EB")==0)   // XCHG
    {
     for(int j=0;j<8;j++)
     {
       Temp=Register.H[j];
       Register.H[j]=Register.D[j];
       Register.D[j]=Temp;
       Temp=Register.L[j];
       Register.L[j]=Register.E[j];
       Register.E[j]=Temp;
     }
     i++;
     ToHex(i+16639,Register.PC);
     goto End1Loop;
    }
    if(strcmp(MemVal[i],"C3")==0)    //JMP
    {  ConditionalJump(1,1,i); goto End1Loop; }
    if(strcmp(MemVal[i],"DA")==0)    //JC
    {   ConditionalJump(Flag.CY,1,i);goto End1Loop; }
    if(strcmp(MemVal[i],"D2")==0)    //JNC
    {   ConditionalJump(Flag.CY,0,i);goto End1Loop; }
    if(strcmp(MemVal[i],"F2")==0)    //JP
    {   ConditionalJump(Flag.S,0,i); goto End1Loop; }
    if(strcmp(MemVal[i],"FA")==0)    //JM
    {   ConditionalJump(Flag.S,1,i); goto End1Loop; }
    if(strcmp(MemVal[i],"EA")==0)    //JPE
    {   ConditionalJump(Flag.P,1,i); goto End1Loop; }
    if(strcmp(MemVal[i],"E2")==0)    //JPO
    {   ConditionalJump(Flag.P,0,i); goto End1Loop; }
    if(strcmp(MemVal[i],"CA")==0)    //JZ
    {   ConditionalJump(Flag.Z,1,i); goto End1Loop; }
    if(strcmp(MemVal[i],"C2")==0)    //JNZ
    {   ConditionalJump(Flag.Z,0,i); goto End1Loop; }
    if(strcmp(MemVal[i],"CD")==0)    //CALL
    {  CALL(1,1,i); goto End1Loop; }
    if(strcmp(MemVal[i],"DC")==0)    //CC
    {   CALL(Flag.CY,1,i);goto End1Loop; }
    if(strcmp(MemVal[i],"D4")==0)    //CNC
    {   CALL(Flag.CY,0,i);goto End1Loop; }
    if(strcmp(MemVal[i],"F4")==0)    //CP
    {   CALL(Flag.S,0,i); goto End1Loop; }
    if(strcmp(MemVal[i],"FC")==0)    //CM
    {   CALL(Flag.S,1,i); goto End1Loop; }
    if(strcmp(MemVal[i],"EC")==0)    //CPE
    {   CALL(Flag.P,1,i); goto End1Loop; }
    if(strcmp(MemVal[i],"E4")==0)    //CPO
    {   CALL(Flag.P,0,i); goto End1Loop; }
    if(strcmp(MemVal[i],"CC")==0)    //CZ
    {   CALL(Flag.Z,1,i); goto End1Loop; }
    if(strcmp(MemVal[i],"C4")==0)    //JNZ
    {   CALL(Flag.Z,0,i); goto End1Loop; }
    if(strcmp(MemVal[i],"C9")==0)    //RET
    {   RET(1,1,i); goto End1Loop; }
    if(strcmp(MemVal[i],"D8")==0)    //RC
    {   RET(Flag.CY,1,i);goto End1Loop; }
    if(strcmp(MemVal[i],"D0")==0)    //RNC
    {   RET(Flag.CY,0,i);goto End1Loop; }
    if(strcmp(MemVal[i],"F0")==0)    //RP
    {   RET(Flag.S,0,i); goto End1Loop; }
    if(strcmp(MemVal[i],"F8")==0)    //RM
    {   RET(Flag.S,1,i); goto End1Loop; }
    if(strcmp(MemVal[i],"E8")==0)    //RPE
    {   RET(Flag.P,1,i); goto End1Loop; }
    if(strcmp(MemVal[i],"E0")==0)    //RPO
    {   RET(Flag.P,0,i); goto End1Loop; }
    if(strcmp(MemVal[i],"C8")==0)    //RZ
    {   RET(Flag.Z,1,i); goto End1Loop; }
    if(strcmp(MemVal[i],"C0")==0)    //RNZ
    {   RET(Flag.Z,0,i); goto End1Loop; }
    if(strcmp(MemVal[i],"C5")==0)   //PUSH B
    {   PUSH(Register.B,Register.C,i); goto End1Loop;  }
    if(strcmp(MemVal[i],"D5")==0)   //PUSH D
    {   PUSH(Register.D,Register.E,i); goto End1Loop;  }
    if(strcmp(MemVal[i],"E5")==0)   //PUSH H
    {   PUSH(Register.H,Register.L,i); goto End1Loop;  }
    if(strcmp(MemVal[i],"F5")==0)   //PUSH PSW
    {
       int PSW[8]={Flag.S,Flag.Z,0,Flag.AC,0,Flag.P,0,Flag.CY};
       PUSH(Register.A,PSW,i);
       goto End1Loop;
    }
    if(strcmp(MemVal[i],"2F")==0)  //CMA
    {
     for(int j=0;j<8;j++)
     {
       if(Register.A[j]==0)
Register.A[j]=1;
       else
Register.A[j]=0;
     }
     i++;
     ToHex(i+16639,Register.PC);
     goto End1Loop;
    }
    if(strcmp(MemVal[i],"B8")==0)  //CMP B
    { COMPARE(Register.B,i); goto End1Loop; }
    if(strcmp(MemVal[i],"B9")==0)  //CMP C
    { COMPARE(Register.C,i); goto End1Loop; }
    if(strcmp(MemVal[i],"BA")==0)  //CMP D
    { COMPARE(Register.D,i); goto End1Loop; }
    if(strcmp(MemVal[i],"BB")==0)  //CMP E
    { COMPARE(Register.E,i); goto End1Loop; }
    if(strcmp(MemVal[i],"BC")==0)  //CMP H
    { COMPARE(Register.H,i); goto End1Loop; }
    if(strcmp(MemVal[i],"BD")==0)  //CMP L
    { COMPARE(Register.L,i); goto End1Loop; }
    if(strcmp(MemVal[i],"BE")==0)  //CMP M
    {
      if(MSet==0)
      {
       MessageBox("RUNTIME ERROR","M Not Set","Execution terminated");
       goto ExeEND;
      }
      else
COMPARE(M,i);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"BF")==0)  //CMP A
    { COMPARE(Register.A,i); goto End1Loop; }
    if(strcmp(MemVal[i],"FE")==0)  //CPI
    {
      i++;
      ToBin(TempAr,MemVal[i]);
      COMPARE(TempAr,i);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"C6")==0)  //ADI
    {
      i++;
      ToBin(TempAr,MemVal[i]);
      ADD(TempAr,i);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"CE")==0)  //ACI
    {
      i++;
      ToBin(TempAr,MemVal[i]);
      ADD_CY(TempAr,i);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"88")==0)    //ADC B
    { ADD_CY(Register.B,i);  goto End1Loop; }
    if(strcmp(MemVal[i],"89")==0)    //ADC C
    { ADD_CY(Register.C,i);  goto End1Loop; }
    if(strcmp(MemVal[i],"8A")==0)    //ADC D
    { ADD_CY(Register.D,i);  goto End1Loop; }
    if(strcmp(MemVal[i],"8B")==0)    //ADC E
    { ADD_CY(Register.E,i);  goto End1Loop; }
    if(strcmp(MemVal[i],"8C")==0)    //ADC H
    { ADD_CY(Register.H,i);  goto End1Loop; }
    if(strcmp(MemVal[i],"8D")==0)    //ADC L
    { ADD_CY(Register.L,i);  goto End1Loop; }
    if(strcmp(MemVal[i],"8E")==0)    //ADC M
    {
      if(MSet==0)
      {
       MessageBox("RUNTIME ERROR","M Not Set","Execution terminated");
       goto ExeEND;
      }
      else
ADD_CY(M,i);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"8F")==0)    //ADC A
    { ADD_CY(Register.A,i); goto End1Loop; }
    if(strcmp(MemVal[i],"80")==0)    //ADD B
    { ADD(Register.B,i);    goto End1Loop; }
    if(strcmp(MemVal[i],"81")==0)    //ADD C
    { ADD(Register.C,i);    goto End1Loop; }
    if(strcmp(MemVal[i],"82")==0)    //ADD D
    { ADD(Register.D,i);    goto End1Loop; }
    if(strcmp(MemVal[i],"83")==0)    //ADD E
    { ADD(Register.E,i);    goto End1Loop; }
    if(strcmp(MemVal[i],"84")==0)    //ADD H
    { ADD(Register.H,i);    goto End1Loop; }
    if(strcmp(MemVal[i],"85")==0)    //ADD L
    { ADD(Register.L,i);    goto End1Loop; }
    if(strcmp(MemVal[i],"86")==0)    //ADD M
    {
      if(MSet==0)
      {
       MessageBox("RUNTIME ERROR","M Not Set","Execution terminated");
       goto ExeEND;
      }
      else
ADD(M,i);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"87")==0)    //ADD A
    { ADD(Register.A,i);  goto End1Loop;  }
    if(strcmp(MemVal[i],"E6")==0)    //ANI
    {
      i++;
      ToBin(TempAr,MemVal[i]);
      AND(TempAr,i);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"A0")==0)    //ANA B
    {  AND(Register.B,i);  goto End1Loop;  }
    if(strcmp(MemVal[i],"A1")==0)    //ANA C
    {  AND(Register.C,i);  goto End1Loop;  }
    if(strcmp(MemVal[i],"A2")==0)    //ANA D
    {  AND(Register.D,i);  goto End1Loop;  }
    if(strcmp(MemVal[i],"A3")==0)    //ANA E
    {  AND(Register.E,i);  goto End1Loop;  }
    if(strcmp(MemVal[i],"A4")==0)    //ANA H
    {  AND(Register.H,i);  goto End1Loop;  }
    if(strcmp(MemVal[i],"A5")==0)    //ANA L
    {  AND(Register.L,i);  goto End1Loop;  }
    if(strcmp(MemVal[i],"A6")==0)    //ANA M
    {
      if(MSet==0)
      {
       MessageBox("RUNTIME ERROR","M Not Set","Execution terminated");
       goto ExeEND;
      }
      else
AND(M,i);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"A7")==0)    //ANA A
    {  AND(Register.A,i);  goto End1Loop; }
    if(strcmp(MemVal[i],"EE")==0)    //XRI
    {
      i++;
      ToBin(TempAr,MemVal[i]);
      XOR(TempAr,i);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"A8")==0)    //XRA B
    {  XOR(Register.B,i);  goto End1Loop;  }
    if(strcmp(MemVal[i],"A9")==0)    //XRA C
    {  XOR(Register.C,i);  goto End1Loop;  }
    if(strcmp(MemVal[i],"AA")==0)    //XRA D
    {  XOR(Register.D,i);  goto End1Loop;  }
    if(strcmp(MemVal[i],"AB")==0)    //XRA E
    {  XOR(Register.E,i);  goto End1Loop;  }
    if(strcmp(MemVal[i],"AC")==0)    //XRA H
    {  XOR(Register.H,i);  goto End1Loop;  }
    if(strcmp(MemVal[i],"AD")==0)    //XRA L
    {  XOR(Register.L,i);  goto End1Loop;  }
    if(strcmp(MemVal[i],"AE")==0)    //XRA M
    {
      if(MSet==0)
      {
       MessageBox("RUNTIME ERROR","M Not Set","Execution terminated");
       goto ExeEND;
      }
      else
       XOR(M,i);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"AF")==0)    //XRA A
    {  XOR(Register.A,i);  goto End1Loop; }
    if(strcmp(MemVal[i],"F6")==0)    //ORI
    {
      i++;
      ToBin(TempAr,MemVal[i]);
      OR(TempAr,i);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"B0")==0)    //ORA B
    {  OR(Register.B,i);  goto End1Loop;  }
    if(strcmp(MemVal[i],"B1")==0)    //ORA C
    {  OR(Register.C,i);  goto End1Loop;  }
    if(strcmp(MemVal[i],"B2")==0)    //ORA D
    {  OR(Register.D,i);  goto End1Loop;  }
    if(strcmp(MemVal[i],"B3")==0)    //ORA E
    {  OR(Register.E,i);  goto End1Loop;  }
    if(strcmp(MemVal[i],"B4")==0)    //ORA H
    {  OR(Register.H,i);  goto End1Loop;  }
    if(strcmp(MemVal[i],"B5")==0)    //ORA L
    {  OR(Register.L,i);  goto End1Loop;  }
    if(strcmp(MemVal[i],"B6")==0)    //ORA M
    {
      if(MSet==0)
      {
       MessageBox("RUNTIME ERROR","M Not Set","Execution terminated");
       goto ExeEND;
      }
      else
OR(M,i);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"B7")==0)    //ORA A
    {  OR(Register.A,i);  goto End1Loop; }
    if(strcmp(MemVal[i],"D6")==0)  //SUI
    {
      i++;
      ToBin(TempAr,MemVal[i]);
      SUB(TempAr,i);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"DE")==0)  //SBI
    {
      i++;
      ToBin(TempAr,MemVal[i]);
      SUB_B(TempAr,i);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"98")==0)    //SBB B
    {  SUB_B(Register.B,i);  goto End1Loop;  }
    if(strcmp(MemVal[i],"99")==0)    //SBB C
    {  SUB_B(Register.C,i);  goto End1Loop;  }
    if(strcmp(MemVal[i],"9A")==0)    //SBB D
    {  SUB_B(Register.D,i);  goto End1Loop;  }
    if(strcmp(MemVal[i],"9B")==0)    //SBB E
    {  SUB_B(Register.E,i);  goto End1Loop;  }
    if(strcmp(MemVal[i],"9C")==0)    //SBB H
    {  SUB_B(Register.H,i);  goto End1Loop;  }
    if(strcmp(MemVal[i],"9D")==0)    //SBB L
    {  SUB_B(Register.L,i);  goto End1Loop;  }
    if(strcmp(MemVal[i],"9E")==0)    //SBB M
    {
      if(MSet==0)
      {
       MessageBox("RUNTIME ERROR","M Not Set","Execution terminated");
       goto ExeEND;
      }
      else
SUB_B(M,i);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"9F")==0)    //SBB A
    {  SUB_B(Register.A,i);  goto End1Loop; }
    if(strcmp(MemVal[i],"90")==0)    //SUB B
    {  SUB(Register.B,i);  goto End1Loop; }
    if(strcmp(MemVal[i],"91")==0)    //SUB C
    {  SUB(Register.C,i);  goto End1Loop; }
    if(strcmp(MemVal[i],"92")==0)    //SUB D
    {  SUB(Register.D,i);  goto End1Loop; }
    if(strcmp(MemVal[i],"93")==0)    //SUB E
    {  SUB(Register.E,i);  goto End1Loop; }
    if(strcmp(MemVal[i],"94")==0)    //SUB H
    {  SUB(Register.H,i);  goto End1Loop; }
    if(strcmp(MemVal[i],"95")==0)    //SUB L
    {  SUB(Register.L,i);  goto End1Loop; }
    if(strcmp(MemVal[i],"96")==0)    //SUB M
    {
      if(MSet==0)
      {
       MessageBox("RUNTIME ERROR","M Not Set","Execution terminated");
       goto ExeEND;
      }
      else
SUB(M,i);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"97")==0)    //SUB A
    {  SUB(Register.A,i); goto End1Loop;  }
    if(strcmp(MemVal[i],"C1")==0)   //POP B
    {  POP(Register.B,Register.C,i);  goto End1Loop; }
    if(strcmp(MemVal[i],"D1")==0)   //POP D
    {  POP(Register.D,Register.E,i);  goto End1Loop; }
    if(strcmp(MemVal[i],"E1")==0)   //POP H
    {  POP(Register.H,Register.L,i);  goto End1Loop; }
    if(strcmp(MemVal[i],"F1")==0)   //POP B
    {
      int PSW[8];
      POP(Register.A,PSW,i);
      PSW[0]=Flag.S; PSW[1]=Flag.Z;
      PSW[5]=Flag.P; PSW[7]=Flag.CY;
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"E9")==0)  //PCHL
    {
      char T[3];
      ToBCD(1,Register.H,T);      strcpy(TempC,T);
      ToBCD(1,Register.L,T);      strcpy(TempC,T);
      strcpy(Register.PC,TempC);
      i=ToDec(Register.PC);       i-=16639;
      ToHex(i+16639,Register.PC);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"F9")==0)  //SPHL
    {
      char T[3];
      ToBCD(1,Register.H,T);      strcpy(TempC,T);
      ToBCD(1,Register.L,T);      strcpy(TempC,T);
      strcpy(Register.SP,TempC);
      i++;
      ToHex(i+16639,Register.PC);
      goto End1Loop;
    }
    Temp=ToDec(MemVal[i]);
    if(Temp>=64&&Temp<=127)
    {
      if(Temp>=64&&Temp<=71)   //MOV B X
      {
switch(Temp-64)
{
  case 0: MOVE(Register.B,Register.B,i); break;
  case 1: MOVE(Register.B,Register.C,i); break;
  case 2: MOVE(Register.B,Register.D,i); break;
  case 3: MOVE(Register.B,Register.E,i); break;
  case 4: MOVE(Register.B,Register.H,i); break;
  case 5: MOVE(Register.B,Register.L,i); break;
  case 6: if(MSet==0)
  {
    MessageBox("RUNTIME ERROR","M Not Set","Execution terminated");
    goto ExeEND;
  }
  MOVE(Register.B,M,i); break;
  case 7: MOVE(Register.B,Register.A,i); break;
}
      }
      else if(Temp>=72&&Temp<=79)   //MOV C X
      {
switch(Temp-72)
{
  case 0: MOVE(Register.C,Register.B,i); break;
  case 1: MOVE(Register.C,Register.C,i); break;
  case 2: MOVE(Register.C,Register.D,i); break;
  case 3: MOVE(Register.C,Register.E,i); break;
  case 4: MOVE(Register.C,Register.H,i); break;
  case 5: MOVE(Register.C,Register.L,i); break;
  case 6: if(MSet==0)
  {
    MessageBox("RUNTIME ERROR","M Not Set","Execution terminated");
    goto ExeEND;
  }
  MOVE(Register.C,M,i); break;
  case 7: MOVE(Register.C,Register.A,i); break;
}
      }
      else if(Temp>=80&&Temp<=87)  //MOV D X
      {
switch(Temp-80)
{
  case 0: MOVE(Register.D,Register.B,i); break;
  case 1: MOVE(Register.D,Register.C,i); break;
  case 2: MOVE(Register.D,Register.D,i); break;
  case 3: MOVE(Register.D,Register.E,i); break;
  case 4: MOVE(Register.D,Register.H,i); break;
  case 5: MOVE(Register.D,Register.L,i); break;
  case 6: if(MSet==0)
  {
    MessageBox("RUNTIME ERROR","M Not Set","Execution terminated");
    goto ExeEND;
  }
  MOVE(Register.D,M,i); break;
  case 7: MOVE(Register.D,Register.A,i); break;
}
      }
      else if(Temp>=88&&Temp<=95)   //MOV E X
      {
switch(Temp-88)
{
  case 0: MOVE(Register.E,Register.B,i); break;
  case 1: MOVE(Register.E,Register.C,i); break;
  case 2: MOVE(Register.E,Register.D,i); break;
  case 3: MOVE(Register.E,Register.E,i); break;
  case 4: MOVE(Register.E,Register.H,i); break;
  case 5: MOVE(Register.E,Register.L,i); break;
  case 6: if(MSet==0)
  {
    MessageBox("RUNTIME ERROR","M Not Set","Execution terminated");
    goto ExeEND;
  }
  MOVE(Register.E,M,i); break;
  case 7: MOVE(Register.E,Register.A,i); break;
}
Report Spam   Report to moderator   Logged

z
f4Gg0t
Member
***
Offline Offline

Posts: 83



View Profile
« Reply #3 on: Monday November 10, 2008, 03:12:19 am »

last part lol

Code:
      }
      else if(Temp>=96&&Temp<=103)    //MOV H X
      {
switch(Temp-96)
{
  case 0: MOVE(Register.H,Register.B,i); break;
  case 1: MOVE(Register.H,Register.C,i); break;
  case 2: MOVE(Register.H,Register.D,i); break;
  case 3: MOVE(Register.H,Register.E,i); break;
  case 4: MOVE(Register.H,Register.H,i); break;
  case 5: MOVE(Register.H,Register.L,i); break;
  case 6: if(MSet==0)
  {
    MessageBox("RUNTIME ERROR","M Not Set","Execution terminated");
    goto ExeEND;
  }
  MOVE(Register.H,M,i); break;
  case 7: MOVE(Register.H,Register.A,i); break;
}
      }
      else if(Temp>=104&&Temp<=111)  //MOV L X
      {
switch(Temp-104)
{
  case 0: MOVE(Register.L,Register.B,i); break;
  case 1: MOVE(Register.L,Register.C,i); break;
  case 2: MOVE(Register.L,Register.D,i); break;
  case 3: MOVE(Register.L,Register.E,i); break;
  case 4: MOVE(Register.L,Register.H,i); break;
  case 5: MOVE(Register.L,Register.L,i); break;
  case 6: if(MSet==0)
  {
    MessageBox("RUNTIME ERROR","M Not Set","Execution terminated");
    goto ExeEND;
  }
  MOVE(Register.L,M,i); break;
  case 7: MOVE(Register.L,Register.A,i); break;
}
      }
      else if(Temp>=112&&Temp<=119)       //MOV M X
      {
if(MSet==1)
{
  switch(Temp-112)
  {
    case 0: MOVE(M,Register.B,i); break;
    case 1: MOVE(M,Register.C,i); break;
    case 2: MOVE(M,Register.D,i); break;
    case 3: MOVE(M,Register.E,i); break;
    case 4: MOVE(M,Register.H,i); break;
    case 5: MOVE(M,Register.L,i); break;
    case 7: MOVE(M,Register.A,i); break;
  }
}
else
{
  MessageBox("RUNTIME ERROR","M Not Set","Execution terminated");
  goto ExeEND;
}
      }
      else if(Temp>=120&&Temp<=127)         //MOV A X
      {
switch(Temp-120)
{
  case 0: MOVE(Register.A,Register.B,i); break;
  case 1: MOVE(Register.A,Register.C,i); break;
  case 2: MOVE(Register.A,Register.D,i); break;
  case 3: MOVE(Register.A,Register.E,i); break;
  case 4: MOVE(Register.A,Register.H,i); break;
  case 5: MOVE(Register.A,Register.L,i); break;
  case 6: if(MSet==0)
  {
    MessageBox("RUNTIME ERROR","M Not Set","Execution terminated");
    goto ExeEND;
  }
  MOVE(Register.A,M,i); break;
  case 7: MOVE(Register.A,Register.A,i); break;
}
      }
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"06")==0)   //MVI B
    {
i++;
ToBin(TempAr,MemVal[i]);
MOVE(Register.B,TempAr,i);
goto End1Loop;
    }
    if(strcmp(MemVal[i],"0E")==0)   //MVI C
    {
i++;
ToBin(TempAr,MemVal[i]);
MOVE(Register.C,TempAr,i);
goto End1Loop;
    }
    if(strcmp(MemVal[i],"16")==0)  //MVI D
    {
i++;
ToBin(TempAr,MemVal[i]);
MOVE(Register.D,TempAr,i);
goto End1Loop;
    }
    if(strcmp(MemVal[i],"1E")==0)  //MVI E
    {
i++;
ToBin(TempAr,MemVal[i]);
MOVE(Register.E,TempAr,i);
goto End1Loop;
    }
    if(strcmp(MemVal[i],"26")==0)  //MVI H
    {
i++;
ToBin(TempAr,MemVal[i]);
MOVE(Register.H,TempAr,i);
goto End1Loop;
    }
    if(strcmp(MemVal[i],"2E")==0)  //MVI L
    {
i++;
ToBin(TempAr,MemVal[i]);
MOVE(Register.L,TempAr,i);
goto End1Loop;
    }
    if(strcmp(MemVal[i],"3E")==0)  //MVI A
    {
i++;
ToBin(TempAr,MemVal[i]);
MOVE(Register.A,TempAr,i);
goto End1Loop;
    }
    if(strcmp(MemVal[i],"36")==0)  //MVI M
    {
if(MSet==1)
{
  i++;
  ToBin(TempAr,MemVal[i]);
  MOVE(M,TempAr,i);
  goto End1Loop;
}
else
{
  MessageBox("RUNTIME ERROR","M Not Set","Execution terminated");
  goto ExeEND;
}
    }
    if(strcmp(MemVal[i],"3A")==0)  //LDA
    {
      strcpy(TempC,MemVal[i+2]);
      strcat(TempC,MemVal[i+1]);
      Temp=ToDec(TempC)-16639;
      ToBin(Register.A,MemVal[Temp]);
      i+=3;
      ToHex(i+16639,Register.PC);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"0A")==0)  //LDAX B
    {
      ToBCD(1,Register.B,TempC);
      ToBCD(1,Register.C,T);
      strcat(TempC,T);
      Temp=ToDec(TempC)-16639;
      ToBin(Register.A,MemVal[Temp]);
      i++;
      ToHex(i+16639,Register.PC);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"1A")==0)  //LDAX D
    {
      ToBCD(1,Register.D,TempC);
      ToBCD(1,Register.E,T);
      strcat(TempC,T);
      Temp=ToDec(TempC)-16639;
      ToBin(Register.A,MemVal[Temp]);
      i++;
      ToHex(i+16639,Register.PC);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"02")==0)  //STAX B
    {
      ToBCD(1,Register.B,TempC);
      ToBCD(1,Register.C,T);
      strcat(TempC,T);
      Temp=ToDec(TempC)-16639;
      ToBCD(1,Register.A,MemVal[Temp]);
      i++;
      ToHex(i+16639,Register.PC);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"12")==0)  //STAX D
    {
      ToBCD(1,Register.D,TempC);
      ToBCD(1,Register.E,T);
      strcat(TempC,T);
      Temp=ToDec(TempC)-16639;
      ToBCD(1,Register.A,MemVal[Temp]);
      i++;
      ToHex(i+16639,Register.PC);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"32")==0)  //STA
    {
      strcpy(TempC,MemVal[i+2]);
      strcat(TempC,MemVal[i+1]);
      Temp=ToDec(TempC)-16639;
      ToBCD(1,Register.A,MemVal[Temp]);
      i+=3;
      ToHex(i+16639,Register.PC);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"2A")==0)  //LHLD
    {
      strcpy(TempC,MemVal[i+2]);
      strcat(TempC,MemVal[i+1]);
      Temp=ToDec(TempC)-16639;
      ToBin(Register.L,MemVal[Temp]);
      ToBin(Register.H,MemVal[Temp+1]);
      i+=3;
      ToHex(i+16639,Register.PC);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"22")==0)  //SHLD
    {
      strcpy(TempC,MemVal[i+2]);
      strcat(TempC,MemVal[i+1]);
      Temp=ToDec(TempC)-16639;
      ToBCD(1,Register.L,MemVal[Temp]);
      ToBCD(1,Register.H,MemVal[Temp+1]);
      i+=3;
      ToHex(i+16639,Register.PC);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"01")==0)  //LXI B
    {
      ToBin(Register.B,MemVal[i+2]);
      ToBin(Register.C,MemVal[i+1]);
      i+=3;
      ToHex(i+16639,Register.PC);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"11")==0)  //LXI D
    {
      ToBin(Register.D,MemVal[i+2]);
      ToBin(Register.E,MemVal[i+1]);
      i+=3;
      ToHex(i+16639,Register.PC);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"21")==0)  //LXI H
    {
      ToBin(Register.H,MemVal[i+2]);
      ToBin(Register.L,MemVal[i+1]);
      i+=3;
      ToHex(i+16639,Register.PC);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"31")==0)  //LXI SP
    {
      strcpy(Register.SP,MemVal[i+2]);
      strcat(Register.SP,MemVal[i+1]);
      i+=3;
      ToHex(i+16639,Register.PC);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"E3")==0)  //XTHL
    {
      Temp=ToDec(Register.SP)-16639;
      strcpy(TempC,MemVal[Temp]);
      strcpy(T,MemVal[Temp+1]);
      ToBCD(1,Register.L,MemVal[Temp]);
      ToBCD(1,Register.H,MemVal[Temp+1]);
      ToBin(Register.L,TempC);
      ToBin(Register.H,T);
      i++;
      ToHex(i+16639,Register.PC);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"27")==0)  //DAA
    { DAA(i); goto End1Loop;    }
    if(strcmp(MemVal[i],"09")==0)
    { DAD(Register.B,Register.C,i);  goto End1Loop;  }  //DAD B
    if(strcmp(MemVal[i],"19")==0)
    { DAD(Register.D,Register.E,i);  goto End1Loop;  }  //DAD D
    if(strcmp(MemVal[i],"29")==0)
    { DAD(Register.H,Register.L,i);  goto End1Loop;  }  //DAD H
    if(strcmp(MemVal[i],"39")==0)
    {
      CutString(Register.SP,TempC,T);                   //DAD SP
      int A[8];
      ToBin(TempAr,TempC);
      ToBin(A,T);
      DAD(TempAr,A,i);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"05")==0)         //DCR B
    { DCR(Register.B,i); goto End1Loop; }
    if(strcmp(MemVal[i],"0D")==0)         //DCR C
    { DCR(Register.C,i); goto End1Loop; }
    if(strcmp(MemVal[i],"15")==0)         //DCR D
    { DCR(Register.D,i); goto End1Loop; }
    if(strcmp(MemVal[i],"1D")==0)         //DCR E
    { DCR(Register.E,i); goto End1Loop; }
    if(strcmp(MemVal[i],"25")==0)         //DCR H
    { DCR(Register.H,i); goto End1Loop; }
    if(strcmp(MemVal[i],"2D")==0)         //DCR L
    { DCR(Register.L,i); goto End1Loop; }
    if(strcmp(MemVal[i],"35")==0)         //DCR M
    {
      if(MSet==1)
      {
DCR(M,i);
goto End1Loop;
      }
      else
      {
MessageBox("RUNTIME ERROR","M Not Set","Execution terminated");
goto ExeEND;
      }
    }
    if(strcmp(MemVal[i],"3D")==0)         //DCR A
    { DCR(Register.A,i); goto End1Loop; }

    if(strcmp(MemVal[i],"04")==0)         //INR B
    { INR(Register.B,i); goto End1Loop; }
    if(strcmp(MemVal[i],"0C")==0)         //INR C
    { INR(Register.C,i); goto End1Loop; }
    if(strcmp(MemVal[i],"14")==0)         //INR D
    { INR(Register.D,i); goto End1Loop; }
    if(strcmp(MemVal[i],"1C")==0)         //INR E
    { INR(Register.E,i); goto End1Loop; }
    if(strcmp(MemVal[i],"24")==0)         //INR H
    { INR(Register.H,i); goto End1Loop; }
    if(strcmp(MemVal[i],"2C")==0)         //INR L
    { INR(Register.L,i); goto End1Loop; }
    if(strcmp(MemVal[i],"34")==0)         //INR M
    {
      if(MSet==1)
      {
INR(M,i);
goto End1Loop;
      }
      else
      {
MessageBox("RUNTIME ERROR","M Not Set","Execution terminated");
goto ExeEND;
      }
    }
    if(strcmp(MemVal[i],"3C")==0)         //INR A
    { INR(Register.A,i); goto End1Loop; }
    if(strcmp(MemVal[i],"03")==0)
    { INX(Register.B,Register.C,i);  goto End1Loop;  }  //INX B
    if(strcmp(MemVal[i],"13")==0)
    { INX(Register.D,Register.E,i);  goto End1Loop;  }  //INX D
    if(strcmp(MemVal[i],"23")==0)
    { INX(Register.H,Register.L,i);  goto End1Loop;  }  //INX H
    if(strcmp(MemVal[i],"33")==0)
    {
      CutString(Register.SP,TempC,T);                   //INX SP
      int A[8];
      ToBin(TempAr,TempC);
      ToBin(A,T);
      INX(TempAr,A,i);
      ToBCD(1,TempAr,Register.SP);
      ToBCD(1,A,TempC);
      strcat(Register.SP,TempC);
      goto End1Loop;
    }
    if(strcmp(MemVal[i],"0B")==0)
    { DCX(Register.B,Register.C,i);  goto End1Loop;  }  //DCX B
    if(strcmp(MemVal[i],"1B")==0)
    { DCX(Register.D,Register.E,i);  goto End1Loop;  }  //DCX D
    if(strcmp(MemVal[i],"2B")==0)
    { DCX(Register.H,Register.L,i);  goto End1Loop;  }  //DCX H
    if(strcmp(MemVal[i],"3B")==0)
    {
      CutString(Register.SP,TempC,T);                   //DCX SP
      int A[8];
      ToBin(TempAr,TempC);
      ToBin(A,T);
      DCX(TempAr,A,i);
      ToBCD(1,TempAr,Register.SP);
      ToBCD(1,A,TempC);
      strcat(Register.SP,TempC);
      goto End1Loop;
    }

    if(strcmp(MemVal[i],"17")==0)  //RAL
    { RAL(i); goto End1Loop;    }
    if(strcmp(MemVal[i],"1F")==0)  //RAR
    { RAR(i); goto End1Loop;    }
    if(strcmp(MemVal[i],"07")==0)  //RLC
    { RLC(i); goto End1Loop;    }
    if(strcmp(MemVal[i],"0F")==0)  //RRC
    { RRC(i); goto End1Loop;    }

    i++;
    ToHex(i+16639,Register.PC);
End1Loop:
    CreateMemoryAddress();
  }
ExeEND:   CreateRegisterList();
}

void RAL(int &i)
{
  int Temp,j;
  Temp=Flag.CY;
  Flag.CY=Register.A[0];
  for(j=0;j<=6;j++)
    Register.A[j]=Register.A[j+1];
  Register.A[7]=Temp;
  i++;
  ToHex(i+16639,Register.PC);
}

void RAR(int &i)
{
  int Temp,j;
  Temp=Flag.CY;
  Flag.CY=Register.A[7];
  for(j=7;j>=1;j--)
    Register.A[j]=Register.A[j-1];
  Register.A[0]=Temp;
  i++;
  ToHex(i+16639,Register.PC);
}

void RLC(int &i)
{
  int Temp=Register.A[0];
  for(int j=0;j<=6;j++)
    Register.A[j]=Register.A[j+1];
  Flag.CY=Register.A[7]=Temp;
  i++;
  ToHex(i+16639,Register.PC);
}

void RRC(int &i)
{
  int Temp=Register.A[7];
  for(int j=7;j>=1;j--)
    Register.A[j]=Register.A[j-1];
  Flag.CY=Register.A[0]=Temp;
  i++;
  ToHex(i+16639,Register.PC);
}

void ConditionalJump(int CON,int ChkVal,int &Count)
{
  char TempC[10];
  int Temp;
  if(CON==ChkVal)
  {
    strcpy(TempC,MemVal[Count+2]);
    strcat(TempC,MemVal[Count+1]);
    Temp=ToDec(TempC);
    Count=Temp-16639;
    ToHex(Count+16639,Register.PC);
  }
}

void PUSH(int R1[],int R2[],int &i)
{
  int Temp;
  char V[3];
  Temp=ToDec(Register.SP);
  Temp-=16639;
  Temp--;
  ToBCD(1,R1,V);
  strcpy(MemVal[Temp],V);
  Temp--;
  ToBCD(1,R2,V);
  strcpy(MemVal[Temp],V);
  ToHex(Temp+16639,Register.SP);
  i++;
  ToHex(i+16639,Register.PC);
}

void POP(int R1[],int R2[],int &i)
{
 int Temp=ToDec(Register.SP);
 Temp-=16639;
 ToBin(R2,MemVal[Temp]);
 Temp++;
 ToBin(R1,MemVal[Temp]);
 Temp++;
 Temp+=16639;
 ToHex(Temp,Register.SP);
 i++;
 ToHex(i+16639,Register.PC);
}

void COMPARE(int Ar[],int &i)
{
  char A[3],R[3];
  int Val1,Val2;
  ToBCD(1,Register.A,A); Val1=ToDec(A);
  ToBCD(1,Ar,R);         Val2=ToDec(R);
  if(Val1<Val2)
  { Flag.CY=1;  Flag.Z=0; SetSign(); SetParity();  }
  else if(Val1>Val2)
  { Flag.Z=1;   Flag.CY=0; SetSign(); SetParity(); }
  else if(Val1==Val2)
  {  Flag.Z=Flag.CY=0; SetSign(); SetParity();     }
  i++;
  ToHex(i+16639,Register.PC);
}

void SetSign()
{ Flag.S=Register.A[0]; }

void SetZero(int R[])
{
  Flag.Z=1;
  for(int i=0;i<8;i++)
  {
    if(R[i]==1)
      Flag.Z=0;
  }
}

void SetParity()
{
  int Count=0,i;
  for(i=0;i<8;i++)
  {
    if(Register.A[i]==1)
      Count++;
  }
  if(Count%2==0)  Flag.P=1;
  else            Flag.P=0;
}

void ADD(int R[],int &i)
{
  Flag.CY=0;
  BINADD(Register.A,R,Flag.CY);
  SetParity();
  SetSign();
  SetZero(Register.A);
  i++;
  ToHex(i+16639,Register.PC);
}

void ADD_CY(int R[],int &i)
{
  int Ar[8]={0,0,0,0,0,0,0,Flag.CY};
  int T;
  Flag.CY=0;
  BINADD(Register.A,R,Flag.CY);
  T=Flag.CY;
  Flag.CY=0;
  BINADD(Register.A,Ar,Flag.CY);
  if(T==1) Flag.CY=1;
  SetParity();
  SetSign();
  SetZero(Register.A);
  i++;
  ToHex(i+16639,Register.PC);
}

void AND(int R[],int &i)
{
  for(int k=0;k<8;k++)
  {
    if(Register.A[k]==1&&R[k]==1)  Register.A[k]=1;
    else                           Register.A[k]=0;
  }
  Flag.CY=0;
  SetParity();
  SetZero(Register.A);
  SetSign();
  i++;
  ToHex(i+16639,Register.PC);
}

void OR(int R[],int &i)
{
  for(int k=0;k<8;k++)
  {
    if(Register.A[k]==0&&R[k]==0)  Register.A[k]=0;
    else                           Register.A[k]=1;
  }
  Flag.CY=0;
  SetParity();
  SetZero(Register.A);
  SetSign();
  i++;
  ToHex(i+16639,Register.PC);
}

void XOR(int R[],int &i)
{
  for(int k=0;k<8;k++)
  {
    if((Register.A[k]==1&&R[k]==1)||(Register.A[k]==0&&R[k]==0))
       Register.A[k]=0;
    else
       Register.A[k]=1;
  }
  Flag.CY=0;
  SetParity();
  SetZero(Register.A);
  SetSign();
  i++;
  ToHex(i+16639,Register.PC);
}

void SUB(int R[],int &i)
{
  Flag.CY=0;
  BINSUB(Register.A,R,Flag.CY);
  SetParity();
  SetZero(Register.A);
  SetSign();
  i++;
  ToHex(i+16639,Register.PC);
}

void DCR(int R[],int &i)
{
  int Ar[8]={0,0,0,0,0,0,0,1};
  int T=0;
  BINSUB(R,Ar,T);
  SetParity();
  SetSign();
  SetZero(R);
  i++;
  ToHex(i+16639,Register.PC);
}

void INX(int R1[],int R2[],int&i)
{
  int Ar1[8]={0,0,0,0,0,0,0,0};
  int Ar2[8]={0,0,0,0,0,0,0,1};
  int T=0;
  BINADD(R2,Ar2,T);
  BINADD(R1,Ar1,T);
  i++;
  ToHex(i+16639,Register.PC);
}

void DCX(int R1[],int R2[],int&i)
{
  int Ar1[8]={0,0,0,0,0,0,0,0};
  int Ar2[8]={0,0,0,0,0,0,0,1};
  int T=0;
  BINSUB(R2,Ar2,T);
  BINSUB(R1,Ar1,T);
  i++;
  ToHex(i+16639,Register.PC);
}

void INR(int R[],int &i)
{
  int Ar[8]={0,0,0,0,0,0,0,1};
  int T=0;
  BINADD(R,Ar,T);
  SetParity();
  SetSign();
  SetZero(R);
  i++;
  ToHex(i+16639,Register.PC);
}

void SUB_B(int R[],int &i)
{
  int Ar[8]={0,0,0,0,0,0,0,Flag.CY};
  BINADD(R,Ar,Flag.CY);
  Flag.CY=0;
  BINSUB(Register.A,R,Flag.CY);
  SetParity();
  SetSign();
  SetZero(Register.A);
  i++;
  ToHex(i+16639,Register.PC);
}

void MOVE(int Des[],int Sou[],int &i)
{
  int j;
  for(j=0;j<8;j++)
    Des[j]=Sou[j];
  i++;
  ToHex(i+16639,Register.PC);
}

void CALL(int CON,int ChkVal,int &Count)
{
  char HA[3],LA[3],TempC[5];
  int Ar1[8],Ar2[8];
  int Temp;
  if(CON==ChkVal)
  {
    ToHex(Count+3+16639,Register.PC);
    CutString(Register.PC,HA,LA);
    ToBin(Ar1,HA);
    ToBin(Ar2,LA);
    PUSH(Ar1,Ar2,Temp);
    strcpy(TempC,MemVal[Count+2]);
    strcat(TempC,MemVal[Count+1]);
    Temp=ToDec(TempC);
    Count=Temp-16639;
    ToHex(Count+16639,Register.PC);
  }
}

void RET(int CON,int ChkVal,int &Count)
{
  int Ar1[8],Ar2[8];
  char HA[3],LA[3];
  if(CON==ChkVal)
  {
    POP(Ar1,Ar2,Count);
    ToBCD(1,Ar1,HA);
    ToBCD(1,Ar2,LA);
    strcat(HA,LA);
    Count=ToDec(HA)-16639;
    ToHex(Count+16639,Register.PC);
  }
}

void DAA(int &i)
{
  char T[3],T1[2],T2[3];
  int V1,V2;
  Flag.CY=0;
  ToBCD(1,Register.A,T);
  T1[0]=T[0];  T2[0]=T[1];
  T1[1]=T2[1]='\0';
  V1=ToDec(T1); V2=ToDec(T2);
  if(V2>9)
  {
    int Ar[8]={0,0,0,0,0,1,1,0};
    BINADD(Register.A,Ar,Flag.CY);
  }
  if(V1>9||Flag.CY==1)
  {
    int Ar[8]={0,1,1,0,0,0,0,0};
    BINADD(Register.A,Ar,Flag.CY);
  }
  SetParity();
  SetZero(Register.A);
  SetSign();
  i++;
  ToHex(i+16639,Register.PC);
}

void DAD(int R1[],int R2[],int &i)
{
  Flag.CY=0;
  BINADD(Register.L,R2,Flag.CY);
  BINADD(Register.H,R1,Flag.CY);
  i++;
  ToHex(i+16639,Register.PC);
}
Report Spam   Report to moderator   Logged

z
Johnny5678
Newbie
*
Offline Offline

Posts: 18


View Profile
« Reply #4 on: Monday November 10, 2008, 03:22:37 am »

oh this reminds me of this one time my friend Adrian ( the one who has funny jokes) he like didn't copy this one part of the script, I think all it was was a semi colon or something, and the whole website wouldn't work., it took him ages to figure it out.
Report Spam   Report to moderator   Logged
f4Gg0t
Member
***
Offline Offline

Posts: 83



View Profile
« Reply #5 on: Monday November 10, 2008, 03:29:36 am »

oh this reminds me of this one time my friend Adrian ( the one who has funny jokes) he like didn't copy this one part of the script, I think all it was was a semi colon or something, and the whole website wouldn't work., it took him ages to figure it out.
hehe what a noob
Report Spam   Report to moderator   Logged

z
raider00321
Moderator
King
*****
Offline Offline

Newgrounds Alias: raider00321
Posts: 969


Mood:Not a happy chappy


View Profile
« Reply #6 on: Monday November 10, 2008, 03:55:16 am »

ooo quite large. But what are the errors?? lol
Report Spam   Report to moderator   Logged

V BEST FREE WEBHOST FOUND BY FAR V http://www.000webhost.com/89919.html
§ Skylinegodzilla ♪
Speedy Sky Mod
Moderator
King
*****
Offline Offline

Newgrounds Alias: skylinegodzilla
Posts: 1043


The Sky is the limit


View Profile WWW
« Reply #7 on: Tuesday November 11, 2008, 09:35:45 pm »

so what is that code suppose to do?

Note: have you tryed to brake down the code n to different flash files? you can then find the arers that work and find the problem using the process of elimination

the flas file that wont work will be the part  with the erra
it will simplify it alot
Report Spam   Report to moderator   Logged

himm... i seam to mist place my signature
f4Gg0t
Member
***
Offline Offline

Posts: 83



View Profile
« Reply #8 on: Tuesday November 11, 2008, 10:09:47 pm »

This is C++ .....
Report Spam   Report to moderator   Logged

z
raider00321
Moderator
King
*****
Offline Offline

Newgrounds Alias: raider00321
Posts: 969


Mood:Not a happy chappy


View Profile
« Reply #9 on: Tuesday November 11, 2008, 10:40:51 pm »

This is C++ .....

ive noticed that. Once again, what are the errors?
Report Spam   Report to moderator   Logged

V BEST FREE WEBHOST FOUND BY FAR V http://www.000webhost.com/89919.html
raider00321
Moderator
King
*****
Offline Offline

Newgrounds Alias: raider00321
Posts: 969


Mood:Not a happy chappy


View Profile
« Reply #10 on: Tuesday November 11, 2008, 10:42:23 pm »

This is C++ .....

ive noticed that. Once again, what are the errors?
oh, and highlight in your script where it says the errors are cos to hell am i counting line by line XD
Report Spam   Report to moderator   Logged

V BEST FREE WEBHOST FOUND BY FAR V http://www.000webhost.com/89919.html
f4Gg0t
Member
***
Offline Offline

Posts: 83



View Profile
« Reply #11 on: Tuesday November 11, 2008, 11:12:18 pm »

This is C++ .....

ive noticed that. Once again, what are the errors?
oh, and highlight in your script where it says the errors are cos to hell am i counting line by line XD
It was saying error on line 955, and I was looking forever. But the error was actually a line before, guess I'm to stupid to realize. Fixed now, thanks for the help though.
Report Spam   Report to moderator   Logged

z
§ Skylinegodzilla ♪
Speedy Sky Mod
Moderator
King
*****
Offline Offline

Newgrounds Alias: skylinegodzilla
Posts: 1043


The Sky is the limit


View Profile WWW
« Reply #12 on: Wednesday November 12, 2008, 04:06:38 am »

This is C++ .....

ive noticed that. Once again, what are the errors?
oh, and highlight in your script where it says the errors are cos to hell am i counting line by line XD
It was saying error on line 955, and I was looking forever. But the error was actually a line before, guess I'm to stupid to realize. Fixed now, thanks for the help though.

i havwe never used c++ b4
the closeist i have been to that is vb
Report Spam   Report to moderator   Logged

himm... i seam to mist place my signature


Pages: [1]   Go Up
  Print  
 
Jump to:  

Bookmark this site! | Upgrade This Forum
SMF For Free - Create your own Forum

Powered by SMF | SMF © 2016, Simple Machines
Privacy Policy