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

📄 march.cpp

📁 eC++编译器源码
💻 CPP
字号:
#pragma march
#include <Graphics.h>
#include <stdio.h>
#include <cstring.h>

void Open(Micro &m)
{
  int i;
  Open(m.w, 480, 480);
  SetFill(m.w, LoadFillPattern("solid"));
  m.regular = LoadFont("screen.r.12");
  SetDrawingColor(m.w, SetNearestColor(0xff0000L));
  m.from = LoadFont("screen.bc.12");
  SetDrawingColor(m.w, SetNearestColor(0xff00L));
  m.to = LoadFont("screen.bc.14");
  Control(m.w1, m.w, 50, 30, "type=\"button\" title=\"step\"");
  Display(m.w, 0, 0, "Sample Architecture");
  Display(m.w1, 250, 240, " ");
  m.width = 480;
  m.height = 480;
  for (i=0; i<=HIGH(m.r); i=i+1) {
    m.r[i].value = 0;
    m.r[i].highlight = false;
  };
  m.mir = 0L;
  m.r[0].name = "PC";
  m.r[1].name = "AC";
  m.r[2].name = "SP";
  m.r[3].name = "IR";
  m.r[4].name = "TIR";
  m.r[5].name = "+0";
  m.r[6].name = "+1";
  m.r[7].name = "-1";
  m.r[8].name = "0xfff";
  m.r[9].name = "0xff";
  m.r[10].name = "A";
  m.r[11].name = "B";
  m.r[12].name = "C";
  m.r[13].name = "D";
  m.r[14].name = "E";
  m.r[15].name = "F";
};

void Step(Micro &m)
{   char s[40];
    for ( ;; ) {
      GetAttributes(m.w1,s);
      if (strstr(s, "click=0")==-1) break;
      GetAttributes(m.w,s);
      if (s[6]=='1') Paint(m);
    };
};

void disAssem(unsigned int ir, char &s[])
{ unsigned int temp;
  temp = ir&0xfff;
  switch (ir/0x1000) {
  case 0: if (sprintf(s, "LOD %3x", temp)==0) HALT;
          break;
  case 1: if (sprintf(s, "STO %3x", temp)==0) HALT;
          break;
  case 2: if (sprintf(s, "ADD %3x", temp)==0) HALT;
          break;
  case 3: if (sprintf(s, "SUB %3x", temp)==0) HALT;
          break;
  case 4: if (sprintf(s, "JA+ %3x", temp)==0) HALT;
          break;
  case 5: if (sprintf(s, "JA0 %3x", temp)==0) HALT;
          break;
  case 6: if (sprintf(s, "JMP %3x", temp)==0) HALT;
          break;
  case 7: if (sprintf(s, "LOC %3x", temp)==0) HALT;
          break;
  case 8: if (sprintf(s, "JA- %3x", temp)==0) HALT;
          break;
  case 9: if (sprintf(s, "JNZ %3x", temp)==0) HALT;
          break;
  case 10:s = "PUSH AC";
          break;
  case 11:s = "POP  AC";
          break;
  case 12:s = "SWAP AC,SP";
          break;
  case 13:case 15:s = "ILLEGAL";
          break;
  case 14:s = "STOP";
          break;
  default:if (ir==0xf000) {
            s = "PUSH [AC]";
          } else if (ir==0xf100) {
            s = "HALT";
          } else if (ir==0xf200) {
            s = "POP [AC]";
          } else if (ir==0xf400) {
            s = "POP AC";
          } else if (ir==0xf600) {
            s = "PUSH AC";
          } else if (ir==0xf800) {
            s = "RETURN";
          } else if (ir==0xfa00) {
            s = "SWAP";
          } else {
            if ((ir&0xff00)==0xfc00) {
              if (sprintf(s, "SP+ %3x", temp)==0) HALT;
            } else if ((ir&0xff00)==0xfe00) {
              if (sprintf(s, "SP- %3x", temp)==0) HALT;
            } else s = "ILLEGAL";
          };
          break;
  }; //switch
};

void Paint(Micro &m)
{
unsigned int i,j,k,x,y;  
Coordinate c[4];
char s[64];
long mir;
  mir = m.mir;
  GetSize(m.w, m.width, m.height);
  SetDrawingColor(m.w, SetNearestColor(0L));
  SetFont(m.w, m.to);
  SetFill(m.w, LoadFillPattern("skeleton"));
  y = m.height/16;
  x = m.width/2-10;
    c[0].x = 0;
    c[0].y = 0;
    c[1].x = x;
    c[1].y = 0;
    c[2].x = x;
    c[2].y = y-4;
    c[3].x = 0;
    c[3].y = y-4;
  for (i=ORD(PC); i<=ORD(F); i=i+1) {
    Polygon(m.w, 5,i*y, 4, c);
    WriteText(m.w, 7, i*y+1, m.r[i].name);
    if (sprintf(s, "%4x  ", m.r[i].value)==0) HALT;
    if (i==ORD(IR)) {
      WriteText(m.w, 22, i*y+4, s);
      disAssem(m.r[i].value, s);
      strcat(s, "       ");
      WriteText(m.w, x/2-4, i*y+4, s);
    } else WriteText(m.w, x/2, i*y+4, s);
  };
  Polygon(m.w, x+12,0, 4, c);
  WriteText(m.w, x+14, 1, "MAR   ");
  if (sprintf(s, "%4x  ", m.mar)==0) HALT;
  WriteText(m.w, x+x/2, 4, s);
  Polygon(m.w, x+12,y, 4, c);
  WriteText(m.w, x+14, y+1, "MBR   ");
  if (sprintf(s, "%4x  ", m.mbr)==0) HALT;
  WriteText(m.w, x+x/2, y+4, s);
  j = 4;
  if (sprintf(s, "clocks: %5ld  ", m.clock)==0) HALT;
  WriteText(m.w, x+12, (2)*y+j, s);
  INC(j,14);
  if (sprintf(s, "mic: %4x  ", m.mic)==0) HALT;
  WriteText(m.w, x+12, (2)*y+j, s);
  INC(j,14);
  if (sprintf(s, "mir: %X  ", mir)==0) HALT;
  WriteText(m.w, x+12, (2)*y+j, s);
  INC(j,28);
  if ((mir&0x80000000L)==0L) {
    mir = m.mir & 0xf00L;
    s = "0: ";
    strcat(s, m.r[TRUNC(mir/0x100L)].name);
    strcat(s, "->AMUX ");
    mir = m.mir & 0xf000L;
    strcat(s, m.r[TRUNC(mir/0x1000L)].name);
    strcat(s, "->BLATCH            ");
    WriteText(m.w, x+12, (2)*y+j, s);
    mir = m.mir;
  } else {
    s = "1: MBR->AMUX ";
    mir = m.mir & 0xf000L;
    strcat(s, m.r[TRUNC(mir/0x1000L)].name);
    strcat(s, "->BLATCH                      ");

    WriteText(m.w, x+12, (2)*y+j, s);
    mir = m.mir&0x7fffffffL;
  };
  INC(j,14);
  k = TRUNC(mir&0xffL);
  switch (TRUNC(mir/0x20000000L)) { 
  case 0: WriteText(m.w, x+12, (2)*y+j, "00:                                          ");
          break;
  case 1: if (sprintf(s, "01: JUMP %2x IF ALU<0         ", k)==0) HALT;
          WriteText(m.w, x+12, (2)*y+j, s);
          break;
  case 2: if (sprintf(s, "10: JUMP %2x IF ALU==0         ", k)==0) HALT;
          WriteText(m.w, x+12, (2)*y+j, s);
          break;
  case 3: if (sprintf(s, "11: JUMP %2x                                                  ", k)==0) HALT;
          WriteText(m.w, x+12, (2)*y+j, s);
          break;
  };
  INC(j,14);
  mir = mir & 0x1fffffffL;
  switch (TRUNC(mir/0x8000000L)) { 
  case 0: WriteText(m.w, x+12, (2)*y+j, "00: ALU=AMUX+BLATCH    ");
          break;
  case 1: WriteText(m.w, x+12, (2)*y+j, "01: ALU=AMUX&BLATCH    ");
          break;
  case 2: WriteText(m.w, x+12, (2)*y+j, "10: ALU=AMUX                        ");
          break;
  case 3: WriteText(m.w, x+12, (2)*y+j, "11: ALU=~AMUX                       ");
          break;
  };
  INC(j,14);
  mir = mir & 0x7ffffffL;
  switch (TRUNC(mir/0x2000000L)) { 
  case 0: WriteText(m.w, x+12, (2)*y+j, "00:                                ");
          break;
  case 1: WriteText(m.w, x+12, (2)*y+j, "01: Shift right 1 ");
          break;
  case 2: WriteText(m.w, x+12, (2)*y+j, "10: Shift left 1 ");
          break;
  case 3: WriteText(m.w, x+12, (2)*y+j, "11:                                ");
          break;
  };
  INC(j,14);
  mir = mir & 0x1ffffffL;
  switch (TRUNC(mir/0x800000L)) { 
  case 0: WriteText(m.w, x+12, (2)*y+j, "00:                               ");
          break;
  case 1: WriteText(m.w, x+12, (2)*y+j, "01: BLATCH->MAR                 ");
          break;
  case 2: WriteText(m.w, x+12, (2)*y+j, "10: Shifter->MBR           ");
          break;
  case 3: WriteText(m.w, x+12, (2)*y+j, "11: MAR&MBR                ");
          break;
  };
  INC(j,14);
  mir = mir & 0x7fffffL;
  switch (TRUNC(mir/0x200000L)) { 
  case 0: WriteText(m.w, x+12, (2)*y+j, "00:                                               ");
          break;
  case 1: WriteText(m.w, x+12, (2)*y+j, "01: write MBR->mem[MAR]           ");
          break;
  case 2: WriteText(m.w, x+12, (2)*y+j, "10: read mem[MAR]->MBR           ");
          break;
  case 3: WriteText(m.w, x+12, (2)*y+j, "11: MBR<>memory           ");
          break;
  };
  INC(j,14);
  WriteText(m.w, x+12, (2)*y+j, "                               ");
  if ((mir&0x100000L)!=0L) {
    mir = mir & 0xf0000L;
    s = "ALU->";
    strcat(s, m.r[TRUNC(mir/0x10000L)].name);
    WriteText(m.w, x+12, (2)*y+j, s);
    INC(j, 14);
  };
};

void Close(Micro &m)
{
  Close(m.w1);
  Close(m.w);
};

⌨️ 快捷键说明

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