Ejemplo n.º 1
0
/****************************************
* check that ttf-gdos is loaded,
* save pointer to config info
* */
static bool is_ttf_gdos( void )
{
   /** look for ttf-gdos ... **/

   pInfo = (TTF_GDOS_INF_RECORD *)vq_vgdos();
   if( (int32)pInfo == GDOS_NONE	/* no gdos at all */
	|| ((int)pInfo&1) != 0		/* pointer to add address*/
	|| pInfo > (void *)get_sysvar(phystop)	/* points outside valid memory*/
	|| pInfo < (void *)0x800 /* bot of mem */
	|| pInfo->magic_nr != MAGIC_NR ) {	/* ttf-gdos not there */
	 return FALSE;
   } /* if */

   if( pInfo->version > MY_VERSION ) {
      form_alert( 1, "[3][please use latest version][good idea]");
      return FALSE;
   } /* if */

   if( pInfo->version < MY_VERSION ) {
      form_alert( 1, "[3][please upgrade to|latest version of ttf-gdos][OK]" );
      return FALSE;
   } /* if */

   return TRUE;

} /* is_ttf_gdos() */
Ejemplo n.º 2
0
/* ------------------------------------------------------------------- */
static bool is_ttf_gdos( void )
{
uint32 *p = (uint32 *)vq_vgdos();

   /** look for ttf-gdos ... **/

   return( p != (uint32*)GDOS_NONE
	&& ((uint8)p&1) == 0
	&& p <= (uint32 *)get_sysvar(phystop)
	&& p >= (uint32 *)0x800 /* bot of mem */
	&& *p == MAGIC_NR );
} /* is_ttf_gdos() */
Ejemplo n.º 3
0
clock_t
_clock(void)
{
	return (get_sysvar(_hz_200) - _starttime);
}
Ejemplo n.º 4
0
// main entry into parser
void encode_rpn()
{
  statement *stmt, *tempstmt = gprog->firststmt;
  struct labelset *label;
  unsigned int x = 0, y = 0;
  int channum = 0, lastfnc = 0, lastvar = 0, ifcount = 0;
  byte display = 0, watchchannel = 0, special = 0; 
  char *cont;
  symbol *sym;

begin:

  stmt = SafeMalloc(sizeof(statement));
  stmtinit(stmt);

  for (x=0; x<MAX_STMT_METAS; x++) {
    stmt->metalist[x].operation = 0;
    stmt->metalist[x].floatarg.mantisa.i = 0;
    stmt->metalist[x].floatarg.exp = 0;
    stmt->metalist[x].shortarg = 0;
    for (y=0; y<MAX_STRING_LENGTH; y++)
      stmt->metalist[x].stringarg[y] = 0;
  }

  special = 0;
  foundequals = 0;
  firstvar = 1;
  numlabels = 0;
  envinfo.stmttype = 0;
  tokenpos = 0;
  token_type = 1;
  lastopcode = 0;

  for (x=0; x<32; x++) { numargs[x] = 0; parenstack[x] = 0; }

  do {
     get_token();
     tokenpos += strlen(token);
     if(!checkoption(get_cmdindex(get_opname(stmt->opcode)), token, token_type))
       lineerror(stmt, __FILE__, __LINE__);
     // hack to avoid using runtime system
     // using runtime system would change the last executed line info.
//     if ((!strcmp(token, "PBSTEP")) && (token_type == TOK_COMMAND)) 
//       dbg_step();

     switch (token_type) {
       case TOK_ERROR:
         lineerror(stmt, __FILE__, __LINE__);
         break;

       case TOK_COMMAND:
         lastopcode = get_opcode(token);
         if (cmdtable[get_cmdindex(token)].options & IO_CHANNEL)
           watchchannel = 1;
         else watchchannel = 0;
         stmt->opcode = get_opcode(token);
         if (stmt->opcode == CMD_LET) goto loop2;
         else goto loop;

       case TOK_NUMBER:
         stmt->opcode = 0;
         stmt->linenum = atoi(token);
         break;

       default:
         buffermeta(stmt, token_type, token);
         goto loop2; 
     }

     buffermeta(stmt, token_type, token);

loop:
     get_token();
     if (checkerr == 2) checkerr = 1;
     else if (checkerr == 1) {
       if (token[0] == '=') {
         if (stmt->metalist[stmt->metapos-2].operation == 0xEC)
           stmt->metapos-=2;
         else stmt->metapos--;
         push("ERR", TOK_OPERATOR);
       } else if (token[0] == '(') {
         prog--;
         stmt->metapos--;
         strcpy(token, "ERR");
         token_type = TOK_FUNCTION;
       } 
       checkerr = 0;
     }
     if (lastopcode == CMD_SETERR) {
       if (!strcmp(token, "ON")) lastopcode = CMD_SETERRON;
       if (!strcmp(token, "OFF")) lastopcode = CMD_SETERROFF;
     }
     if (!strcmp(token, "RECORD")) {
       if (stmt->opcode == CMD_READ) lastopcode = CMD_READRECORD;
       if (stmt->opcode == CMD_WRITE) lastopcode = CMD_WRITERECORD;
       if (stmt->opcode == CMD_EXTRACT) lastopcode = CMD_EXTRACTRECORD;
       if (stmt->opcode == CMD_FIND) lastopcode = CMD_FINDRECORD;
       if (stmt->opcode == CMD_PRINT) lastopcode = CMD_PRINTRECORD;
       token_type = lasttype;
       goto loop;
     }
     if (lastopcode == CMD_REM) {
       stmt->metalist[1].operation = 0xF5;
       tokenpos -= 2;
       if (input[tokenpos] == '\"') x = tokenpos; else x = tokenpos+2;
       stmt->metalist[1].shortarg = strlen(input) - x;
       y = 0;
       for (x=x; x<strlen(input); x++)
       { stmt->metalist[1].stringarg[y] = input[x]; y++; }
       stmt->metalist[1].stringarg[y] = '\0';
       stmt->metapos++;
       if (stmt->linenum) insertstmt(gprog, stmt);
       return; 
     }
     tokenpos += strlen(token);
     if(!checkoption(get_cmdindex(get_opname(lastopcode)), token, token_type))
       lineerror(stmt, __FILE__, __LINE__);

loop2:
     switch (token_type) {
       case TOK_SEMICOLON:
         popstack(stmt, -1);
         if (!stmt->linenum) { execline(gprog, stmt); stmtinit(stmt); }
         break;

       case TOK_COLON:
         if ((stmt->metalist[stmt->metapos-1].operation == SETVAL_NUMERIC) ||
             (stmt->metalist[stmt->metapos-1].operation == GETVAL_NUMERIC) ||
             (stmt->metalist[stmt->metapos-1].operation == LABELREF)) {
           label = SafeMalloc(sizeof(struct labelset));
           sym = idx2sym(gprog, stmt->metalist[stmt->metapos-1].shortarg); 
           label->labelnum = addlabel(gprog, sym->name, stmt->linenum);
           for (x=0; x<MAX_STRING_LENGTH; x++)
             sym->name[x] = '\0';
           x = 0;
           stmt->metapos--;
           stmt->metalist[stmt->metapos].shortarg = 0;
           stmt->opcode = 0;
           stmt->labelset[stmt->numlabels] = label;
           stmt->numlabels++;
           firstvar = 1;
         } else {
           do {
             if (stmt->linenum == tempstmt->linenum) {
               for (x=0; x<strlen(input); x++) 
                 if (input[x] == ':') break;
               y = x;
               for (x=0; x<=y; x++) input[x] = ' ';
               cont = SafeMalloc(1024*64);
               *cont = 0;
               listline(cont, tempstmt, 1);
               strcat(cont, input);
               *prog = 0; 
               prog = cont;
               display = 1;
               goto begin;
             }
             tempstmt = tempstmt->nextstmt;
           } while (tempstmt != NULL);
           numlabels++;
         }
         goto loop;

       case TOK_COMMA:
         if (parencount > 0) { 
           // comma being delimiter for system functions
           popstack(stmt, -2);
           push("(", TOK_OPERATOR);
           if (chaninfo == 1) {
             if (!channum) {
               channum = 1;
               stmt->metalist[stmt->metapos].operation = 0xE1;
               stmt->metapos++;
             }
           } else { 
             if (special == 1) numargs[parencount-1]+=10;
             else numargs[parencount-1]++; 
             envinfo.stmttype = 0; 
           }
         } else {
           // comma being delimiter for verbs
           popstack(stmt, -1); 
           buffermeta(stmt, TOK_COMMA, token); 
           for (x=0; x<32; x++) numargs[x] = 0;
           envinfo.stmttype = 0;
           foundequals = 0;
           firstvar = 1;
         }
         goto loop;

       case TOK_ERROR:
         lineerror(stmt, __FILE__, __LINE__);
         return;

       case TOK_COMMAND:
         lastopcode = get_opcode(token);
         if (cmdtable[get_cmdindex(token)].options & IO_CHANNEL)
           watchchannel = 1;
         else watchchannel = 0;
         if (!strcmp(token, "IF")) ifcount++;
         if (!stmt->opcode) {
           stmt->opcode = get_opcode(token);
           envinfo.stmttype = 0;
           goto loop;
         } else {
           popstack(stmt, -1);
           envinfo.stmttype = 0;
           if (ifcount > 0) {
             stmt->metalist[stmt->metapos].operation = 0xE7;
             stmt->metalist[stmt->metapos].shortarg = 0;
             stmt->metalist[stmt->metapos].intarg = 0;
             stmt->metapos++;
             stmt->length++;
//             watchchannel = 0;
             chaninfo = 0;
             channum = 0;
             ifcount--;
           }
           if (lastopcode == CMD_ON) {
             special = 1;
             if (!strcmp(token, "GOTO")) 
               stmt->metalist[stmt->metapos].operation = 0x00F4;
             else stmt->metalist[stmt->metapos].operation = 0x01F4;
             stmt->length += 2;
             stmt->metapos++;
           } else
             buffermeta(stmt, TOK_COMMAND, token);
           goto loop;
         }
       break;
       
       case TOK_RESERVED:
         popstack(stmt, -1);
         envinfo.stmttype = 0;
         lineref = 0;
         if (!strcmp(token, "ELSE")) {
           stmt->metalist[stmt->metapos].operation = 0xE7;
           stmt->metalist[stmt->metapos].intarg = 0;
           stmt->metalist[stmt->metapos].shortarg = 0;
           stmt->metapos++;
           stmt->metalist[stmt->metapos].operation = 0xE2;
           stmt->metalist[stmt->metapos].intarg = 0;
           stmt->metalist[stmt->metapos].shortarg = 0;
           stmt->metapos++; 
           stmt->length+=2;
           envinfo.stmttype = 0;
           chaninfo = 0;
           channum = 0;
         }
         goto loop;

       case TOK_DONE:
         if ((stmt->linenum) && (!stmt->opcode)) deletestmt(gprog,stmt->linenum);
         else {
           popstack(stmt, -1);
           if (stmt->opcode == CMD_LET && foundequals == 0) lineerror(stmt, __FILE__, __LINE__);
           if (parencount > 0 || numlabels < 0) lineerror(stmt, __FILE__, __LINE__);
           if (stmt->linenum) { if (!stmt->errorflag) insertstmt(gprog, stmt); }
           else if (stmt->opcode) { if (!stmt->errorflag) 
                  { execline(gprog, stmt); } }
         }
         if (display) {
           GC_realloc(cont, strlen(cont));
           listprog(gprog, stmt->linenum, stmt->linenum);
         }
         return;

       case TOK_USERFUNCTION:
         if (lastopcode == CMD_DEFFN)
           addfunction(gprog, token, stmt->linenum, 1);
         else addfunction(gprog, token, stmt->linenum, 0);
         if (token[strlen(token)-1] == '$') parenstack[parencount] = 8;
           else parenstack[parencount] = 7;
         buffermeta(stmt, TOK_USERFUNCTION, token);
         break;

       case TOK_FUNCTION:
         lastfnc = get_fnc(token);
         numlabels++;
       case TOK_OPERATOR: 
         if (token[0] == '[') {
           special = 1;
           cont = get_symname(lastvar);
           if (cont[strlen(cont)-1] == '$') 
             parenstack[parencount] = 2;
           else parenstack[parencount] = 1;
           numlabels++;
           goto openparen;
         } else if (token[0] == ']') {  
           numargs[parencount-1] += 9;
           popstack(stmt, -2);
           envinfo.stmttype = parenstack[parencount];
           token_type = TOK_ARRAY;
           special = 0;
           goto loop;
         } else if (token[0] == '-') {
           // placeholder
           if ((lasttype == TOK_OPERATOR) || (lasttype == TOK_RESERVED))
             token[0] = '_';
           evalstack(stmt);
           goto loop;
         } else if (token[0] == '(') {
openparen:
           if (lasttype == TOK_COMMAND) {
             if (watchchannel == 1)
               chaninfo = 1;
           } else if (lasttype == TOK_ARRAY) {
             envinfo.stmttype = 0;
             numargs[parencount]++;
             push(token, token_type);
             goto loop;
           } else if (lasttype == TOK_SETVAL) { 
             push(get_symname(lastvar), TOK_SETVAL);
             stmt->metapos--;
             stmt->metalist[stmt->metapos].shortarg = 0; 
             numlabels++;
             cont = get_symname(lastvar);
             if (cont[strlen(cont)-1] == '$') 
               parenstack[parencount] = 2;
             else parenstack[parencount] = 1;
           } else if (lasttype == TOK_VARIABLE) {
             push(get_symname(lastvar), TOK_VARIABLE);
             numlabels++;
             stmt->metapos--;
             stmt->metalist[stmt->metapos].shortarg = 0; 
             cont = get_symname(lastvar);
             if (cont[strlen(cont)-1] == '$') 
               parenstack[parencount] = 2;
             else parenstack[parencount] = 1;
           } else if (lasttype == TOK_USERFUNCTION) {
             stmt->metapos--;
             stmt->metalist[stmt->metapos].operation = 0xF5;
             stmt->metapos++;
             stmt->length++;
           } else if (lasttype == TOK_FUNCTION) {
             if ((envinfo.stmttype != fnctable[lastfnc].returntype) &&
                 (envinfo.stmttype != 0))
               lineerror(stmt, __FILE__, __LINE__);
             else parenstack[parencount] = fnctable[lastfnc].returntype;
           } else parenstack[parencount] = 1;
           envinfo.stmttype = 0;
           numargs[parencount] = 1;
           push(token, token_type);
           goto loop;
         } else if (token[0] == ')') {
           if (parencount == 0) lineerror(stmt, __FILE__, __LINE__); 
           popstack(stmt, -2); 
           if (parenstack[parencount] == 7) {
             stmt->metalist[stmt->metapos].operation = 0xF8;
             stmt->metapos++;
             stmt->length++;
             envinfo.stmttype = 1;
           } else if (parenstack[parencount] == 8) {
             stmt->metalist[stmt->metapos].operation = 0xF8;
             stmt->metapos++;
             stmt->length++;
             envinfo.stmttype = 2;
           } else envinfo.stmttype = parenstack[parencount];
           if (lastopcode == CMD_DEFFN && foundequals == 0) {
             stmt->metapos--;
             stmt->metalist[stmt->metapos].operation = 0xF8;
             stmt->metapos++;
           }
           if (chaninfo == 1) {
             chaninfo = 0;
             if (!channum) {
               stmt->metalist[stmt->metapos].operation = 0xE1;
               stmt->metapos++;
             }
             stmt->metalist[stmt->metapos].operation = 0xF4F1;
             stmt->metapos++;
             numargs[parencount] = 0;
           }
           goto loop;
         } else { 
           evalstack(stmt); 
           goto loop; 
         }
         break;   

       case TOK_VARIABLE:
         if (get_sysvar(token)) { 
           buffermeta(stmt, TOK_SYSVAR, token); 
           numlabels++;
           goto loop;
         } else { addsymbol(gprog, token); lastvar = get_symref(token); }

       case TOK_NUMBER:
       default:
        if(!stmt->opcode) { envinfo.stmttype = 0; lastopcode = stmt->opcode = CMD_LET; }
        if ((firstvar == 1) && (token_type == TOK_VARIABLE) && 
            (lastopcode == CMD_LET || lastopcode == CMD_FOR ||
             lastopcode == CMD_FOR || lastopcode == CMD_NEXT ||
             lastopcode == CMD_DIM || lastopcode == CMD_INPUT)) {
           buffermeta(stmt, TOK_SETVAL, token);
           firstvar = 0;
           token_type = TOK_SETVAL;
        } else { numlabels++; buffermeta(stmt, token_type, token); }
        goto loop;
     }
  } while (1);
}
Ejemplo n.º 5
0
// sets token and token_type to reflect next occuring token
int get_token()
{
  char test[3];
  register char *temp;
  int x;

  lasttype = token_type;

  token_type = 0;
  temp = token;

  for (x=0; x<TOKEN_LEN; x++)
    token[x] = '\0';

  while(iswhite(*prog)) { tokenpos++; prog++; }

  if(*prog == '?')
  {
    prog++;
    tokenpos++;
    *temp++ = 'P'; 
    *temp++ = 'R';
    *temp++ = 'I';
    *temp++ = 'N';
    *temp++ = 'T';
    return(token_type = TOK_COMMAND);
  }

  if((*prog == '\'') && (lasttype == 1))
  {
    prog++;
    tokenpos++;
    *temp++ = 'E';
    *temp++ = 'D';
    *temp++ = 'I';
    *temp++ = 'T';
    return(token_type = TOK_COMMAND);
  }

/*  if((*prog == '.') && (lasttype == 1)) 
  {
    prog++;
    tokenpos++;
    *temp++ = 'P';
    *temp++ = 'B';
    *temp++ = 'S';
    *temp++ = 'T';
    *temp++ = 'E';
    *temp++ = 'P';
    return(token_type = TOK_COMMAND);
  }*/

  if(strchr("\n", *prog))
  {
     *temp = 0;
     return(token_type = TOK_DONE);
  }

  if(*prog == '\'')
  {
    prog++;
    tokenpos++;
    while (*prog != '\'' && *prog != '\r') {
      if (strchr("\n", *prog)) return (token_type = TOK_ERROR); 
      *temp++ = *prog++;
    }
    prog++;
    tokenpos++;
    *temp = 0;
    return (token_type = TOK_MNEMONIC);
  }

  if(*prog == '\"')
  {
    prog++;
    tokenpos++;
    while (*prog != '\"' && *prog != '\r') {
      if (strchr("\n", *prog)) return (token_type = TOK_ERROR);
      *temp++ = *prog++;
    }
    prog++;
    tokenpos++;
    *temp = 0;
    return(token_type = TOK_STRING);
  }

  if(isoper(*prog))
  {
    if (*prog == ',') { prog++; *temp = 0; return(token_type = TOK_COMMA); }
    if (*prog == ':') { prog++; *temp = 0; return(token_type = TOK_COLON); }
    if (*prog == ';') { prog++; *temp = 0; return(token_type = TOK_SEMICOLON); }
    if (strchr("*<>=", *prog)) {
      *temp = *prog; prog++; temp++;
      if (strchr("*<>=", *prog)) {
        *temp = *prog; prog++; temp++;
        if (!strcmp(token, "<<") || !strcmp(token, ">>") 
         || !strcmp(token, "*<") || !strcmp(token, "*>") 
         || !strcmp(token, "*=") || !strcmp(token, "<*") 
         || !strcmp(token, ">*") || !strcmp(token, "=*") 
         || !strcmp(token, "==")) {
          return (token_type = TOK_ERROR);
        }
      }
      *temp = 0;
    } else {
      *temp = *prog;
      prog++;
      temp++;
      *temp = 0;
    }
    return(token_type = TOK_OPERATOR);
  }

  if(isdigit(*prog) || *prog == '.')
  {
     while(!isoper(*prog) && !iswhite(*prog)) *temp++ = *prog++;
     *temp = 0;
     return(token_type = TOK_NUMBER);
  }
	
  while(!isoper(*prog) && !iswhite(*prog) && *prog != '"' && *prog != '\'') 
    *temp++ = *prog++;

  if (islongoper(token) && get_fnc(token)) {
    while (iswhite(*prog)) *temp++ = *prog++;
    if (*prog == '(') {
      while (iswhite(*prog)) *temp++ = *prog++;
      prog++;
      if (isdigit(*prog)) goto blah;
      else if ((*prog == '"') || (*prog == '$')) {
        for (x=strlen(token); x>=3; x--) prog--;
        for (x=3; x<strlen(token)+1; x++) token[x] = '\0';
        return (token_type = TOK_FUNCTION);
      } else if (isalpha(*prog)) { 
        while (isalpha(*prog)) *temp++ = *prog++;
        if (*prog == '$') {
          for (x=strlen(token); x>=3; x--) prog--;
          for (x=3; x<strlen(token)+1; x++) token[x] = '\0';
          return (token_type = TOK_FUNCTION); 
        } else if (*prog == '(') {
          // test if valid function or sysvar
          // if succeeded, test function/sysvar return type for strings
          test[0] = toupper(token[strlen(token)-3]);
          test[1] = toupper(token[strlen(token)-2]);
          test[2] = toupper(token[strlen(token)-1]);
          test[3] = '\0';
          if (get_fnc(test) || get_sysvar(test)) {
            for (x=strlen(token); x>=3; x--) prog--;
            for (x=3; x<strlen(token)+1; x++) token[x] = '\0';
            return (token_type = TOK_FUNCTION);
          } else goto blah;
        } else goto blah;
      } else goto blah;
    } else { 
blah:
      for (x=0; !iswhite(token[x]); x++) ;
      for (x=x; x<strlen(token)+1; x++) token[x] = '\0';
      return (token_type = TOK_OPERATOR);
    }
  } else {
    // !!HACK!!
    // will decide if this is a sysvar or operator the next time
    // gettoken is run.  if next token is '=' then it's an operator
    // if so it will change the metacode for this run.
    if (!strcmp(token, "ERR")) {
      checkerr = 2; 
      return(token_type = TOK_VARIABLE); //SYSVAR);
    }
    if (islongoper(token)) return(token_type = TOK_OPERATOR);
    if (isreserved(token)) return(token_type = TOK_RESERVED);
    if (((token[0] == 'F') || (token[0] == 'f')) &&
        ((token[1] == 'N') || (token[1] == 'n')))
       return (token_type = TOK_USERFUNCTION);
    if (get_opcode(token)) return(token_type = TOK_COMMAND);
    if (get_fnc(token)) return (token_type = TOK_FUNCTION);
    else return(token_type = TOK_VARIABLE);
  }
  return 0;
}