home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / xplatfrm / motxas / do0.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-14  |  3.3 KB  |  176 lines

  1. /*
  2.  *    MC6800/02 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.             if((opcode == 0x8D) && (amode == IND)){
  70.                 Cycles-=2;
  71.                 }
  72.             do_gen(opcode,amode);
  73.             return;
  74.         case LONGIMM:
  75.             if( amode == IMMED ){
  76.                 emit(opcode);
  77.                 Optr++;
  78.                 eval();
  79.                 eword(Result);
  80.                 return;
  81.                 }
  82.             do_gen(opcode,amode);
  83.             return;
  84.         case GRP2:
  85.             if( amode == IND ){
  86.                 Cycles++;
  87.                 do_indexed(opcode);
  88.                 return;
  89.                 }
  90.             /* extended addressing */
  91.             eval();
  92.             emit(opcode+0x10);
  93.             eword(Result);
  94.             return;
  95.         default:
  96.             fatal("Error in Mnemonic table");
  97.         }
  98. }
  99.  
  100. /*
  101.  *    do_gen --- process general addressing modes
  102.  */
  103. do_gen(op,mode)
  104. int    op;
  105. int    mode;
  106. {
  107.     if( mode == IMMED){
  108.         Optr++;
  109.         emit(op);
  110.         eval();
  111.         emit(lobyte(Result));
  112.         return;
  113.         }
  114.     else if( mode == IND ){
  115.         Cycles+=3;
  116.         do_indexed(op+0x20);
  117.         return;
  118.         }
  119.     else if( mode == OTHER){
  120.         eval();
  121.         if(Force_word){
  122.             emit(op+0x30);
  123.             eword(Result);
  124.             Cycles+=2;
  125.             return;
  126.             }
  127.         if(Force_byte){
  128.             emit(op+0x10);
  129.             emit(lobyte(Result));
  130.             Cycles++;
  131.             return;
  132.             }
  133.         if(Result>=0 && Result <=0xFF){
  134.             emit(op+0x10);
  135.             emit(lobyte(Result));
  136.             Cycles++;
  137.             return;
  138.             }
  139.         else {
  140.             emit(op+0x30);
  141.             eword(Result);
  142.             Cycles+=2;
  143.             return;
  144.             }
  145.         }
  146.     else {
  147.         error("Unknown Addressing Mode");
  148.         return;
  149.         }
  150. }
  151.  
  152. /*
  153.  *    do_indexed --- handle all weird stuff for indexed addressing
  154.  */
  155. do_indexed(op)
  156. int op;
  157. {
  158.     emit(op);
  159.     if( *Optr != ',' && !head(Operand,"X") && !head(Operand,"x") ) {
  160.         eval();
  161.             if( !( *Optr++ == ',' && ( mapdn(*Optr) == 'x') ) )
  162.             warn("Indexed Addressing Assumed");
  163.         }
  164.     else {            /* if no expression, fake it */
  165.         Force_word = NO;
  166.         Force_byte = NO;
  167.         Result = 0;
  168.         if( *Optr == ',' ) Optr++;
  169.         if( mapdn(*Optr) != 'x' )
  170.             warn("Indexed Addressing Assumed");
  171.         }
  172.     if( Result < 0 || Result > 255)
  173.         warn("Value Truncated");
  174.     emit(lobyte(Result));
  175. }
  176.