home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / xplatfrm / motxas / do1.c < prev    next >
Text File  |  1990-07-14  |  3KB  |  172 lines

  1. /*
  2.  *      MC6801 specific processing
  3.  */
  4.  
  5. /* addressing modes */
  6. #define IMMED   0       /* immediate */
  7. #define IND     1       /* indexed */
  8. #define OTHER   2       /* NOTA */
  9.  
  10. /*
  11.  *      localinit --- machine specific initialization
  12.  */
  13. localinit()
  14. {
  15. }
  16.  
  17. /*
  18.  *      do_op --- process mnemonic
  19.  *
  20.  *    Called with the base opcode and it's class. Optr points to
  21.  *    the beginning of the operand field.
  22.  */
  23. do_op(opcode,class)
  24. int opcode;    /* base opcode */
  25. int class;    /* mnemonic class */
  26. {
  27.     int     dist;   /* relative branch distance */
  28.     int     amode;  /* indicated addressing mode */
  29.     char    *peek;
  30.  
  31.     /* guess at addressing mode */
  32.     peek = Optr;
  33.     amode = OTHER;
  34.     if( head(Operand,"X") || head(Operand,"x") ) {
  35.         if( delim(*(Operand+1)) )
  36.             amode = IND;
  37.         }
  38.     else while( !delim(*peek) ) { /* check for comma in operand field */
  39.         if( *peek++ == ',' ){
  40.             amode = IND;
  41.             break;
  42.             }
  43.         }
  44.     if( *Optr == '#' ) amode = IMMED;
  45.  
  46.     switch(class){
  47.         case INH:                       /* inherent addressing */
  48.             emit(opcode);
  49.             return;
  50.         case GEN:                       /* general addressing */
  51.             do_gen(opcode,amode);
  52.             return;
  53.         case REL:                       /* relative branches */
  54.             if( eval() )
  55.                 dist = Result - (Pc+2);
  56.             else dist = -2;
  57.             emit(opcode);
  58.             if( (dist >127 || dist <-128) && Pass==2){
  59.                 error("Branch out of Range");
  60.                 dist = -2;
  61.                 }
  62.             emit(lobyte(dist));
  63.             return;
  64.         case NOIMM:
  65.             if( amode == IMMED){
  66.                 error("Immediate Addressing Illegal");
  67.                 return;
  68.                 }
  69.             do_gen(opcode,amode);
  70.             return;
  71.         case LONGIMM:
  72.             if( amode == IMMED ){
  73.                 emit(opcode);
  74.                 Optr++;
  75.                 eval();
  76.                 eword(Result);
  77.                 return;
  78.                 }
  79.             do_gen(opcode,amode);
  80.             return;
  81.         case GRP2:
  82.             if( amode == IND ){
  83.                 do_indexed(opcode);
  84.                 return;
  85.                 }
  86.             /* extended addressing */
  87.             eval();
  88.             emit(opcode+0x10);
  89.             eword(Result);
  90.             return;
  91.         default:
  92.             fatal("Error in Mnemonic table");
  93.         }
  94. }
  95.  
  96. /*
  97.  *      do_gen --- process general addressing modes
  98.  */
  99. do_gen(op,mode)
  100. int     op;
  101. int     mode;
  102. {
  103.     if( mode == IMMED){
  104.         Optr++;
  105.         emit(op);
  106.         eval();
  107.         emit(lobyte(Result));
  108.         return;
  109.         }
  110.     else if( mode == IND ){
  111.         Cycles+=2;
  112.         do_indexed(op+0x20);
  113.         return;
  114.         }
  115.     else if( mode == OTHER){
  116.         eval();
  117.         if(Force_word){
  118.             emit(op+0x30);
  119.             eword(Result);
  120.             Cycles+=2;
  121.             return;
  122.             }
  123.         if(Force_byte){
  124.             emit(op+0x10);
  125.             emit(lobyte(Result));
  126.             Cycles++;
  127.             return;
  128.             }
  129.         if(Result>=0 && Result <=0xFF){
  130.             emit(op+0x10);
  131.             emit(lobyte(Result));
  132.             Cycles++;
  133.             return;
  134.             }
  135.         else {
  136.             emit(op+0x30);
  137.             eword(Result);
  138.             Cycles+=2;
  139.             return;
  140.             }
  141.         }
  142.     else {
  143.         error("Unknown Addressing Mode");
  144.         return;
  145.         }
  146. }
  147.  
  148. /*
  149.  *      do_indexed --- handle all weird stuff for indexed addressing
  150.  */
  151. do_indexed(op)
  152. int op;
  153. {
  154.     emit(op);
  155.     if( *Optr != ',' && !head(Operand,"X") && !head(Operand,"x") ) {
  156.         eval();
  157.             if( !( *Optr++ == ',' && ( mapdn(*Optr) == 'x') ) )
  158.             warn("Indexed Addressing Assumed");
  159.         }
  160.         else {            /* if no expression, fake it */
  161.                 Force_word = NO;
  162.                 Force_byte = NO;
  163.                 Result = 0;
  164.         if( *Optr == ',' ) Optr++;
  165.         if( mapdn(*Optr) != 'x' )
  166.             warn("Indexed Addressing Assumed");
  167.                 }
  168.     if( Result < 0 || Result > 255)
  169.         warn("Value Truncated");
  170.     emit(lobyte(Result));
  171. }
  172.