home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_06_08 / v6n8050b.txt < prev    next >
Text File  |  1989-09-28  |  4KB  |  133 lines

  1. /* hr_pixel.c - Set the color of the pixel at column x, row y according
  2.  * to color c.  sop is the starting address of the display page. eop is the
  3.  * ending address.  Note:  If the color is not possible at the
  4.  * specified position, it is shifted left.  If the color is other than
  5.  * BLACK or WHITE, the adjacent bits are both turned off.  If the color
  6.  * is WHITE, the bit to the left is also turned on. This shifting is not
  7.  * performed when the adjacent pixel is in a different row.  Returns void.
  8.  *
  9.  * Environment:    Apple II, Aztec c65 V1.05B
  10.  * Programmer:    Don Strayer
  11.  * Date:        15-Jun-88
  12.  */
  13.  
  14. #include <math.h,d1>
  15. #include <hr_apple2.h>
  16.  
  17. hr_pixel( x, y, c, sop , eop )
  18.     int x;                                        /* column */
  19.     int y;                                        /* row */
  20.     int c;                                        /* color */
  21.     int sop;                                    /* start of page */
  22.     int eop;                                    /* end of page */
  23.  
  24. {    static char *pa;                            /* pixel address */
  25.  
  26.     /* convert row number y to its equivalent blocking in display memory */
  27.  
  28.     y = ( ( y / 8 ) * 3 ) + ( ( y % 8 ) * 24 ) - ( ( y / 64 ) * 24 )
  29.             + ( y / 64 );
  30.  
  31.     /* adjust offset for the 8 byte padding every 3rd row */
  32.  
  33.     sop += ( y / 3 ) * 8;
  34.  
  35.     /* set the pixel to the specified color, adjusting as necessary */
  36.  
  37.     switch ( c )
  38.  
  39.     {    case HR_BLACK:
  40.         {    pa = sop + ( y * HR_BPR ) + ( x / HR_PPB );        /* pixel address */
  41.             *pa = *pa & ( ( 1 << ( x % HR_PPB ) ) ^ 255 );    /* set pixel off */
  42.             break;
  43.         }
  44.  
  45.         case HR_PURPLE:
  46.         {    if ( x & 1 )                    /* decrement column if odd */
  47.                 --x;
  48.  
  49.             pa = sop + ( y * HR_BPR ) + ( x / HR_PPB );    /* pixel address */
  50.             *pa = *pa | ( 1 << ( x % HR_PPB ) );        /* set pixel on */
  51.             *pa = *pa & 127;                            /* high order off */
  52.  
  53.             break;
  54.         }
  55.         
  56.         case HR_BLUE:
  57.         {    if ( x & 1 )                    /* decrement column if odd */
  58.                 --x;
  59.  
  60.             pa = sop + ( y * HR_BPR ) + ( x / HR_PPB );    /* pixel address */
  61.             *pa = *pa | ( 1 << ( x % HR_PPB ) );        /* set pixel on */
  62.             *pa = *pa | 128;                            /* high order on */
  63.  
  64.             break;
  65.         }
  66.  
  67.         case HR_GREEN:
  68.         {    if ( x == 0 )                        /* exit if column zero */
  69.                 break;                            /* (can't decrment) */
  70.  
  71.             if ( ! ( x & 1 ) )                    /* decrement column if even */
  72.                 --x;
  73.  
  74.             pa = sop + ( y * HR_BPR ) + ( x / HR_PPB );    /* pixel address */
  75.             *pa = *pa | ( 1 << ( x % HR_PPB ) );        /* set pixel on */
  76.             *pa = *pa & 127;                            /* high order off */
  77.  
  78.             break;
  79.         }
  80.  
  81.         case HR_ORANGE:
  82.         {    if ( x == 0 )                    /* exit if column zero */
  83.             break;                            /* (can't decrement) */
  84.  
  85.             if ( ! ( x & 1 ) )                /* decrement column if even */
  86.                 --x;
  87.  
  88.             pa = sop + ( y * HR_BPR ) + ( x / HR_PPB );    /* pixel address */
  89.             *pa = *pa | ( 1 << ( x % HR_PPB ) );        /* set pixel on */
  90.             *pa = *pa | 128;                            /* high order off */
  91.  
  92.             break;
  93.         }
  94.  
  95.         case HR_WHITE:
  96.         {    pa = sop + ( y * HR_BPR ) + ( x / HR_PPB );    /* pixel address */
  97.             *pa = *pa | ( 1 << ( x % HR_PPB ) );        /* set pixel on */
  98.  
  99.             /* set pixel on left on if within current row */
  100.  
  101.             if ( x )
  102.             {    pa = sop + ( y * HR_BPR ) + ( --x / HR_PPB );
  103.                 *pa = *pa | ( 1 << ( x % HR_PPB ) );
  104.                 ++x;
  105.             }
  106.  
  107.         break;
  108.         }
  109.  
  110.         default:                            /* invalid color */
  111.             break;
  112.     }
  113.  
  114.     /* if the pixel is colored, set the adjacent positions off,
  115.        provided within the current row */
  116.  
  117.     if ( ( c != HR_BLACK ) && ( c != HR_WHITE ) )
  118.     {    if ( x )
  119.         {    pa = sop + ( y * HR_BPR ) + ( --x / HR_PPB );
  120.             *pa = *pa & ( ( 1 << ( x % HR_PPB ) ) ^ 255 );
  121.             ++x;
  122.         }
  123.         if ( x < 278 )
  124.         {    pa = sop + ( y * HR_BPR ) + ( ++x / HR_PPB );
  125.             *pa = *pa & ( ( 1 << ( x % HR_PPB ) ) ^ 255 );
  126.             --x;
  127.         }
  128.     }
  129.  
  130.     return();
  131. }
  132.  
  133.