home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / mesa-1.2.8 / mondello / linetemp.h < prev    next >
C/C++ Source or Header  |  1996-05-27  |  4KB  |  161 lines

  1. /* linetemp.h - line drawing template (see graphics.c)
  2.  
  3.    #define's
  4.    
  5.    THREED    - use z-values, otherwise z=0
  6.    OPCODE       - the opcode for the given line
  7.    FLAT_INDEX   - line is flat shaded (single color), 8bpp
  8.    INTERP_INDEX - line is gouraud shaded (multi color), 8bpp
  9.    FLAT_COLOR   - line is flat shaded (single color), 24bpp
  10.    INTERP_COLOR - line is gouraud shaded (multi color) ,24bpp
  11.    
  12.  */
  13.  
  14. {
  15.  
  16.   int adx, ady; 
  17.   int dx,dy; 
  18.   uint reg1; 
  19.   uint reg2; 
  20.   uint reg3; 
  21.   uint reg4;
  22.   uint mlen;
  23.   
  24. #ifdef THREED
  25.   uint reg5, reg6;
  26.   z1=FN(z1);
  27.   z2=FN(z2);
  28. #endif
  29.   
  30.   y2+=yoffs;
  31.   y1+=yoffs;
  32.   
  33.   dx = x2-x1;                                   
  34.   dy = y2-y1;                                   
  35.   adx=abs(dx);                                      /* TODO - opt */
  36.   ady=abs(dy);                                      /* TODO - opt */
  37.   reg3=(dx & 0x80000000) | ((dy & 0x80000000) >> 1) | (x1 << 12); 
  38.   if (adx > ady) {
  39.     reg1=(adx>>8)<<24 | y1 << 12;                 
  40.     if (!dx) {            /* TODO - this case never happens! */
  41.       reg2=adx<<24 | ((dy<<12)&0x00ffffff);
  42.       mlen=1;
  43.     }
  44.     else {
  45.       reg2=adx<<24 | (((dy<<12)/adx)&0x00ffffff);
  46.       mlen=adx;
  47.     }
  48.     if(adx!=dx)                                 
  49.       reg4=0x00fff000;                            
  50.     else                                        
  51.       reg4=0x00001000;                            
  52.   } else {
  53.     reg1=(ady>>8)<<24 | y1 << 12;                 
  54.     if(ady!=dy)                                 
  55.       reg2=ady<<24 | 0x00fff000;                  
  56.     else                                        
  57.       reg2=ady<<24 | 0x00001000;                  
  58.     if (!dy) {
  59.       reg4=dx<<12;
  60.       mlen=1;
  61.     }
  62.     else {
  63.       reg4=(dx<<12)/ady;
  64.       mlen=ady;
  65.     }
  66.   } 
  67. #ifdef THREED
  68.   reg5=z1<<12;
  69.   reg6=(z2-z1)<<12;
  70. #endif
  71.  
  72. /* setup for first of possible several draws */
  73.  
  74. #ifdef FLAT_INDEX
  75.   *listPtr++=load_short_ro(BANK_MASK_REG,BLUE_BANK);
  76. #endif
  77.  
  78. #ifdef INTERP_INDEX
  79.   *listPtr++=load_short_ro(BANK_MASK_REG,BLUE_BANK);
  80. #endif
  81.  
  82. #ifdef FLAT_COLOR
  83.   *listPtr++=load_short_ro(BANK_MASK_REG,RED_BANK);
  84. #endif
  85.  
  86. #ifdef INTERP_COLOR
  87.   *listPtr++=load_short_ro(BANK_MASK_REG,RED_BANK);
  88. #endif
  89.  
  90. /* draw first line */
  91.  
  92.   *listPtr++ = OPCODE;                    /* instruction     */
  93.   *listPtr++ = reg1;                     /* y-start, y-count */
  94.   *listPtr++ = reg2;                     /* y-delta, y-count */
  95.   *listPtr++ = reg3;                     /* x-start     */
  96.   *listPtr++ = reg4;                    /* x-delta     */
  97.  
  98. /* do vars for tail end of 1st line (dz, di, etc) and following lines */
  99.  
  100. #ifdef THREED
  101.   *listPtr++ = reg5;                    /* z-start */
  102.   *listPtr++ = reg6;                    /* z-delta */
  103. #else   
  104.   *listPtr++ = 0;                       /* z-start */
  105.   *listPtr++ = 0;                    /* z-delta */
  106. #endif
  107.  
  108. #ifdef FLAT_INDEX
  109.   *listPtr++ = cindex << 12;                /* i-start */
  110.   *listPtr++ = 0;                    /* i-delta */
  111. #endif
  112.  
  113. #ifdef INTERP_INDEX
  114.   *listPtr++ = i1 << 12;                /* i-start */
  115.   *listPtr++ = ((i2-i1+1) << 12)/mlen & 0x000fffff;    /* i-delta */
  116. #endif
  117.  
  118. #ifdef FLAT_COLOR
  119.   *listPtr++ = r << 12;                    /* i-start */
  120.   *listPtr++ = 0;                    /* i-delta */
  121.   
  122.   *listPtr++ = load_short_ro(BANK_MASK_REG, GREEN_BANK);/* bank select     */
  123.   *listPtr++ = load_long_ro(IMAIN_REG,1);        /* load i-start */
  124.   *listPtr++ = g << 12;                    /* i-start (r7)    */  
  125.   *listPtr++ = OPCODE & ~0x7f;                /* strip loads     */
  126.  
  127.   *listPtr++ = load_short_ro(BANK_MASK_REG, BLUE_BANK);    /* bank select     */
  128.   *listPtr++ = load_long_ro(IMAIN_REG,1);        /* load i-start */
  129.   *listPtr++ = b << 12;                    /* i-start (r7)    */  
  130.   *listPtr++ = OPCODE & ~0x7f;                /* strip loads     */
  131. #endif
  132.  
  133. #ifdef INTERP_COLOR
  134.   *listPtr++ = r1 << 12;                /* i-start (r7)    */
  135.   *listPtr++ = ((r2-r1+1) << 12)/mlen;            /* i-delta (r8)    */
  136.  
  137.   *listPtr++ = load_short_ro(BANK_MASK_REG, GREEN_BANK);/* bank select    */
  138.   *listPtr++ = load_long_ro(IMAIN_REG,2);        /* load i's     */
  139.   *listPtr++ = g1 << 12;                /* i-start (r7)    */
  140.   *listPtr++ = ((g2-g1+1) << 12)/mlen;            /* i-delta (r8)    */
  141.   *listPtr++ = OPCODE & ~0x7f;                /* strip loads     */  
  142.   
  143.   *listPtr++ = load_short_ro(BANK_MASK_REG, BLUE_BANK);    /* bank select     */
  144.   *listPtr++ = load_long_ro(IMAIN_REG,2);        /* load i's    */
  145.   *listPtr++ = b1 << 12;                /* i-start (r7)    */
  146.   *listPtr++ = ((b2-b1+1) << 12)/mlen;            /* i-delta (r8)     */
  147.   *listPtr++ = OPCODE & ~0x7f;                /* strip loads     */
  148. #endif
  149.   
  150.   CHKEXEC;                        /* execute    */
  151. }
  152.  
  153. #undef FLAT_INDEX
  154. #undef INTERP_INDEX
  155. #undef FLAT_COLOR
  156. #undef INTERP_COLOR
  157. #undef THREED
  158. #undef OPCODE
  159.  
  160.  
  161.