Esempio n. 1
0
void LoadOpcodeTable(Table T, char *OpfileName)
  /* LoadOpcodeTable reads strings in from the opcode file (OpfileName).
       It then parses the string into an OpcodeData record and sends a
       pointer to the record, the pointer to the key, and the table to
       the table functions for placement of the record into the table.
       If the insertion fails, the reason for the failure is given. */
{
 FILE *Opfile;       /* opcode file */
 OpcodeData *record; /* record malloced to contain line */
 char monic[5];      /* mnemonic gained from sscanf of line */
 int opcde, fmt;     /* opcode and format gained from sscanf of line */
 int result;         /* result of success or failure of TInsert */
 
 if ((Opfile = fopen(OpfileName, "r")) == NULL)
   printf("Cannot open file %s \n",OpfileName);     /* bad file name */
 else
                /* good file name so process records */
    while(fscanf(Opfile,"%s %x %d",monic, &opcde, &fmt) != EOF)
     {
      record = (OpcodeData *)malloc(sizeof(OpcodeData));
      strcpy(record->mnemonic, monic);
      record->opcode = opcde;
      record->format = fmt;
 
                   /* insert the record */
      result = TInsert(T, record->mnemonic, record);
 
                /* check for error */
      if (result == DUP)
        printf ("Duplicate opcode %s.\n\n", record->mnemonic);
      else if (result == FULL)
        printf ("Table Full. %s not inserted.\n\n", record->mnemonic);
     }
}
Esempio n. 2
0
int Pass1(char *fname, Table optab, Table stab)
  /* Pass1 expects a file name (fname), opcode table (optab), and
       symbol table (stab) from the caller.  It takes the fname and
       appends the file types to it so that the MACASM and ITF files
       can be opened.  Once opened, a line is read in one at a time
       and is parsed.  If there is a symbol and it is valid, it is
       placed in the symbol table.  The opcode is then checked to see
       if it is valid.  The line with its location counter and error
       code is then written to the ITF file.  The program length is
       returned.  */
{
 char MacName[45], ITFName[45];
   /* names of the MAC file and ITF file */
 FILE *mfile, *ifile;
   /* pointers to the MAC file and ITF file */
 char line[81];
   /* line read from input */
 char *label, *operation, *operand;
   /* values determined in ParseLine */
 short loc = 0;
   /* location counter */
 ITFline ITF;
   /* line to be sent to ITF */
 SymbolData *Sym;
   /* Symbol to be added to the symbol table */
 int result, good, good2;
   /* result of TInsert and flag that label is good */
 int i;
   /* loop index */
 int val;
 unsigned err;
   /* value and err from EvalExpr */
 char typ;
   /* type from EvalExpr */
 TableRecord *tptr;
   /* used for TRetrieve */
 int ok, inc; /* opcode ok  and go ahead and increment */
 
          /* append MAC and ITF to filename and open them */
 strcpy(MacName, fname);
 strcpy(ITFName, fname);
 strcat(MacName," MACASM (TEXT RECFM F LRECL 80\0");
 strcat(ITFName," ITF (BIN RECFM F LRECL 86\0");
 if ((mfile = fopen(MacName, "r")) == NULL)
   printf("Unable to open %s\n", MacName);
 else if ((ifile = fopen(ITFName, "w")) == NULL)
   printf ("Unable to open %s\n", ITFName);
 else
 {
   operation = dummystr;
   while ((!feof(mfile)) && (strcmp(operation, endstr) != 0))
    {
                 /* get line and make a copy of it */
     fread(line, 1, 81, mfile);
                 /* initialize ITFLine for comment */
     strcpy(ITF.srcline, line);
     ITF.locctr = loc;
     ITF.error = 0;
 
                    /* check line for comment */
     if (line[0] != '*')
      {
                          /* Parse Line */
       upper(line);
       ParseLine(line, &label, &operation, &operand);
 
                    /* check for valid opcode */
       ok = inc = 1;
       if (isalnum(operation[0]) || ispunct(operation[0]))
        if(TRetrieve(optab,operation)) ok = 1;
        else
         {
          ITF.error |= ILLEGAL_OPCODE;
          ok = 0;
         }
       else inc = 0;    /* no opcode so don't increment locctr */
 
       if (ok)
        {
         if ((strcmp(operation,equstr) != 0))
          {
              /* check for label and process symbol */
           good = 1;
           if (label != NULL)
            if (strcmp(operation, extstr) == 0)
             ITF.error |= UNEXPECTED_LABEL;
              /* check to see if label is valid */
            else if (isalpha(label[0]) && strlen(label) < 9)
             {
       /* valid so far, check for other problems with label */
              for (i=1; i < strlen(label); i++)
               if (!isalnum(label[i])) good = 0;
              if (good)
               {
                       /* process label */
                Sym = (SymbolData *)malloc(sizeof(SymbolData));
                strcpy(Sym->symbol, label);
                Sym->value = loc;
                Sym->type = REL;
                result = TInsert(stab, Sym->symbol, Sym);
                if (result == DUP)
                 {
                  ITF.error |= MULT_DEF_SYM;      /* duplicate symbol */
                  free(Sym);
                 }
                if (result == FULL)              /* symbol table full */
                 {
                  ITF.error |= SYM_TAB_OF;
                  free(Sym);
                 }
               } /* end if good */
              else ITF.error |= INVALID_LABEL;
             } /* end if alpha and len < 9 */
            else ITF.error |= INVALID_LABEL;
 
            /* if DX directive,  create operand symbol */
            if (strcmp(operation,dxstr) == 0)
             {
              good2 = 1;
              if(isalpha(operand[0]) && strlen(operand) < 9)
               {
                for (i=1; i < strlen(operand); i++)
                 if(!isalnum(operand[i])) good2 = 0;
               }
              else good2 = 0;
              if (good2 != 0)
               {
                Sym = (SymbolData *)malloc(sizeof(SymbolData));
                strcpy(Sym->symbol, operand);
                Sym->value = 0;
                Sym->type = DXEXT;
                result = TInsert(stab, Sym->symbol, Sym);
                if (result == DUP)
                 {
                  ITF.error |= MULT_DEF_SYM;   /* duplicate symbol */
                  free(Sym);
                 }
                if (result == FULL)         /* symbol table full */
                 {
                  ITF.error |= SYM_TAB_OF;
                  free(Sym);
                 }
               } /* end if good2 */
              else ITF.error |= BAD_SYM_DX;
             } /* end if dxstr */
 
      /* if extstr check for operand symbol and don't increment loc */
            if(strcmp(operation, extstr) == 0)
             if (tptr = TRetrieve(stab,operand))
              {
               Sym = tptr->data;
               if (Sym->type == REL)
                Sym->type = EXT;
               else ITF.error |= ILL_EXPR;
              }
             else ITF.error |= UNDEF_SYM;
                 /* increment location counter */
            else if (inc)
             if(strcmp(operation, dsstr) != 0) loc++;
             else
              {
               EvalExpr(operand,stab,&val,&typ,&err);
               if (typ == ABS && val >= 0 && !err)
                loc += val;
               else ITF.error |= err | ILL_EXPR;
              }
          }       /* end if not =  */
         else /* operation is = directive */
          {
              /* check to see if label is valid */
           good = 1;
           if ((label!=NULL) && (isalpha(label[0])) && (strlen(label)<9))
            for (i=1; i < strlen(label); i++)
             if (!isalnum(label[i])) good = 0;
             else good = good;
           else good = 0;
           if (good)
            {
             val = err = 0;
             EvalExpr(operand,stab,&val,&typ,&err);
             if (!err)
              {
               Sym = (SymbolData *)malloc(sizeof(SymbolData));
               strcpy(Sym->symbol, label);
               Sym->value = val;
               Sym->type = typ;
               result = TInsert(stab, Sym->symbol, Sym);
               if (result == DUP)
                {
                 ITF.error |= MULT_DEF_SYM;      /* duplicate symbol */
                 free(Sym);
                }
               if (result == FULL)              /* symbol table full */
                {
                 ITF.error |= SYM_TAB_OF;
                 free(Sym);
                }
              } /* end if !err */
             else ITF.error |= err;
            } /* end if good */
           else ITF.error |= INVALID_LABEL;
          }    /* end if eqstr */
        } /* end if ok */
       else ITF.error |= ILLEGAL_OPCODE;
      } /* end if not * */
 
                     /* write ITF line */
     fwrite(&ITF, sizeof(ITFline), 1, ifile);
    } /* end while */
 
                /* close files */
  fclose(mfile);
  fclose(ifile);
 }
 
 return loc - 1;
} /* end Pass1 */
Esempio n. 3
0
void Pass1(char *fname, Table optab, Table stab)
  /* Pass1 expects a file name (fname), opcode table (optab), and
       symbol table (stab) from the caller.  It takes the fname and
       appends the file types to it so that the MACASM and ITF files
       can be opened.  Once opened, a line is read in one at a time
       and is parsed.  If there is a symbol and it is valid, it is
       placed in the symbol table.  The opcode is then checked to see
       if it is valid.  The line with its location counter and error
       code is then written to the ITF file */
{
 char MacName[45], ITFName[45];
   /* names of the MAC file and ITF file */
 FILE *mfile, *ifile;
   /* pointers to the MAC file and ITF file */
 char line[81];
   /* line read from input */
 char *label, *operation, *operand;
   /* values determined in ParseLine */
 short loc = 0;
   /* location counter */
 ITFline ITF;
   /* line to be sent to ITF */
 SymbolData *Sym;
   /* Symbol to be added to the symbol table */
 int result, good;
   /* result of TInsert and flag that label is good */
 int i;
   /* loop index */
 
 printf("Pass 1 of assembler\n\n");
 
          /* append MAC and ITF to filename and open them */
 strcpy(MacName, fname);
 strcpy(ITFName, fname);
 strcat(MacName," MACASM (TEXT RECFM F LRECL 80\0");
 strcat(ITFName," ITF (BIN RECFM F LRECL 86\0");
 if ((mfile = fopen(MacName, "r")) == NULL)
   printf("Unable to open %s\n", MacName);
 else if ((ifile = fopen(ITFName, "w")) == NULL)
   printf ("Unable to open %s\n", ITFName);
 else
 {
   operation = dummystr;
   while ((!feof(mfile)) && (strcmp(operation, endstr) != 0))
    {
                 /* get line and make a copy of it */
     fread(line, 1, 81, mfile);
                 /* initialize ITFLine for comment */
     strcpy(ITF.srcline, line);
     ITF.locctr = loc;
     ITF.error = 0;
 
                    /* check line for comment */
     if (line[0] != '*')
      {
                          /* Parse Line */
       upper(line);
       ParseLine(line, &label, &operation, &operand);
              /* check for label and process symbol */
       if ((strcmp(operation,equstr) != 0) &&
           (strcmp(operation,extstr) != 0))
        {
         good = 1;
         if (label != NULL)
              /* check to see if label is valid */
          if (isalpha(label[0]) && strlen(label) < 9)
           {
       /* valid so far, check for other problems with label */
            for (i=1; i < strlen(label); i++)
            if (!isalnum(label[i])) good = 0;
            if (good)
             {
              Sym = (SymbolData *)malloc(sizeof(SymbolData));
              strcpy(Sym->symbol, label);
              Sym->value = loc;
              Sym->type = REL;
              result = TInsert(stab, Sym->symbol, Sym);
              if (result == DUP)
               {
                ITF.error |= MULT_DEF_SYM;      /* duplicate symbol */
                free(Sym);
               }
              if (result == FULL)              /* symbol table full */
               {
                ITF.error |= SYM_TAB_OF;
                free(Sym);
               }
             }
            else ITF.error |= INVALID_LABEL;
           }
          else ITF.error |= INVALID_LABEL;
 
                 /* increment location counter */
          if(strcmp(operation, dsstr) != 0) loc++;
          else loc += atoi(operand);
        } /* end if not = or ext */
 
                /* check for valid opcode */
       if(!TRetrieve(optab, operation))
        {
         loc--;
         if(isalpha(operation[0]))
          ITF.error |= ILLEGAL_OPCODE;
        }
      } /* end if not * */
 
                     /* write ITF line */
     fwrite(&ITF, sizeof(ITFline), 1, ifile);
    } /* end while */
 
                /* close files */
  fclose(mfile);
  fclose(ifile);
 }
 printf("Pass 1 complete.\n\n");
} /* end Pass1 */
Esempio n. 4
0
LOCAL TBOOL fbp_copyarea_int(struct rfb_Display *mod, struct rfb_Window *v,
	TINT dx, TINT dy, TINT *dr)
{
	struct RectPool *pool = &mod->rfb_RectPool;

	struct Region R;

	if (!rfb_getlayermask(mod, &R, dr, v, 0, 0))
		return TFALSE;

	if (R.rg_Rects.rl_NumNodes == 0)
	{
		region_free(pool, &R);
		return TFALSE;
	}

	TINT yinc = dy < 0 ? -1 : 1;
	TINT y, i, h;

	TINT dy0 = dr[1];
	TINT dy1 = dr[3];

	h = dy1 - dy0 + 1;
	if (yinc > 0)
	{
		TINT t = dy0;

		dy0 = dy1;
		dy1 = t;
	}

	TINT bpp = TVPIXFMT_BYTES_PER_PIXEL(v->rfbw_PixBuf.tpb_Format);

	if (R.rg_Rects.rl_NumNodes == 1)
	{
		/* optimization for a single rectangle */

		struct RectNode *rn =
			(struct RectNode *) TFIRSTNODE(&R.rg_Rects.rl_List);
		TINT x0 = rn->rn_Rect[0];
		TINT y0 = rn->rn_Rect[1];
		TINT x1 = rn->rn_Rect[2];
		TINT y1 = rn->rn_Rect[3];

		h = y1 - y0 + 1;
		dy0 = y0;
		dy1 = y1;
		if (yinc > 0)
		{
			TINT t = dy0;

			dy0 = dy1;
			dy1 = t;
		}

#if defined(ENABLE_VNCSERVER)
		if (mod->rfb_VNCTask && !(v->rfbw_Flags & RFBWFL_BACKBUFFER))
			rfb_vnc_copyrect(mod, v, dx, dy, x0, y0, x1, y1, yinc);
		else
#endif
		{
			/* update own buffer */
			for (i = 0, y = dy0; i < h; ++i, y -= yinc)
				CopyLineOver(v, x0 - dx, y - dy, x0, y, (x1 - x0 + 1) * bpp);
		}

		/* update sub device */
		TINT d[4];

		d[0] = rn->rn_Rect[0];
		d[1] = rn->rn_Rect[1];
		d[2] = rn->rn_Rect[2];
		d[3] = rn->rn_Rect[3];
		if (v->rfbw_Flags & RFBWFL_BACKBUFFER)
			rfb_markdirty(mod, v, d);
		else
			rfb_copyrect_sub(mod, d, dx, dy);
	}
	else
	{
		struct TNode *n;
		struct TList r, t;

		TInitList(&r);
		TInitList(&t);

		while ((n = TRemHead(&R.rg_Rects.rl_List)))
			TAddTail(&r, n);

		for (i = 0, y = dy0; i < h; ++i, y -= yinc)
		{
			struct TNode *rnext, *rnode = r.tlh_Head.tln_Succ;

			for (; (rnext = rnode->tln_Succ); rnode = rnext)
			{
				struct RectNode *rn = (struct RectNode *) rnode;

				if (y >= rn->rn_Rect[1] && y <= rn->rn_Rect[3])
				{
					struct TNode *prednode = TNULL;
					struct TNode *tnext, *tnode = t.tlh_Head.tln_Succ;

					for (; (tnext = tnode->tln_Succ); tnode = tnext)
					{
						struct RectNode *tn = (struct RectNode *) tnode;

						if (rn->rn_Rect[2] < tn->rn_Rect[0])
							break;
						prednode = tnode;
					}
					TRemove(rnode);
					TInsert(&t, rnode, prednode);	/* insert after prednode */
				}
			}

			while (!TISLISTEMPTY(&t))
			{
				TINT x0, x1;

				if (dx < 0)
				{
					struct RectNode *E = (struct RectNode *) TRemHead(&t);

					x0 = E->rn_Rect[0];
					x1 = E->rn_Rect[2];
					TAddTail(&r, &E->rn_Node);
					while (!TISLISTEMPTY(&t))
					{
						struct RectNode *N =
							(struct RectNode *) TFIRSTNODE(&t);
						if (N->rn_Rect[0] == x1 + 1)
						{
							x1 = N->rn_Rect[2];
							TAddTail(&r, TRemHead(&t));
							continue;
						}
						break;
					}
				}
				else
				{
					struct RectNode *E = (struct RectNode *) TRemTail(&t);

					x0 = E->rn_Rect[0];
					x1 = E->rn_Rect[2];
					TAddTail(&r, &E->rn_Node);
					while (!TISLISTEMPTY(&t))
					{
						struct RectNode *N = (struct RectNode *) TLASTNODE(&t);

						if (N->rn_Rect[2] == x0 - 1)
						{
							x0 = N->rn_Rect[0];
							TAddTail(&r, TRemTail(&t));
							continue;
						}
						break;
					}
				}
				CopyLineOver(v, x0 - dx, y - dy, x0, y, (x1 - x0 + 1) * bpp);
			}
		}

		while ((n = TRemHead(&r)))
		{
			struct RectNode *rn = (struct RectNode *) n;

			/* this would be incorrect, unfortunately: */
			/* rfb_copyrect_sub(mod, rn->rn_Rect, dx, dy); */
			rfb_markdirty(mod, v, rn->rn_Rect);
			TAddTail(&R.rg_Rects.rl_List, n);
		}
	}

	region_free(pool, &R);

	return TTRUE;	/* do expose */
}