home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / bit_blt / amiga / bits.c next >
C/C++ Source or Header  |  1987-04-24  |  2KB  |  90 lines

  1. /*
  2.  *   This routine handles the display of the bit array in BlitLab.
  3.  */
  4. #include "structures.h"
  5. /*
  6.  *   This is the address of the real bits we operate on.
  7.  */
  8. extern short int *realbits ;
  9. static int safearr[192] ;
  10. allocbitmem() {
  11.    extern void *allocmem() ;
  12.  
  13.    realbits = (short *)(allocmem(1000L, MEMF_CHIP | MEMF_CLEAR)) + 150 ;
  14. }
  15. pdot(x, y, on)
  16. int x, y, on ;
  17. {
  18.    int off = (x >> 4) + y * 6 ;
  19.    int bit = 1 << (15 - (x & 15)) ;
  20.  
  21.    if (on) {
  22.       if ((realbits[off] & bit) == 0) {
  23.          realbits[off] |= bit ;
  24.          safearr[off] |= bit ;
  25.          color(WHITE) ;
  26.          fbox(x * 6 + HBITSTART, y * 3 + VBITSTART + 1, 4, 2) ;
  27.       }
  28.    } else {
  29.       if (realbits[off] & bit) {
  30.          realbits[off] &= ~bit ;
  31.          safearr[off] &= ~bit ;
  32.          color(BLACK) ;
  33.          fbox(x * 6 + HBITSTART, y * 3 + VBITSTART + 1, 4, 2) ;
  34.       }
  35.    }
  36. }
  37. preg(x1, y1, x2, y2, on)
  38. int x1, y1, x2, y2, on ;
  39. {
  40.    int i, j ;
  41.  
  42.    for (i=x1; i<=x2; i++)
  43.       for (j=y1; j<=y2; j++)
  44.          pdot(i, j, on) ;
  45. }
  46. /*
  47.  *   This routine writes out the new position to the screen.
  48.  */
  49. updatepos(x1, y1)
  50. int x1, y1 ;
  51. {
  52.    char outbuf[4] ;
  53.  
  54.    sprintf(outbuf, "%3d", ((x1 >> 3) & ~1) + y1 * 12) ;
  55.    drawtext(HLMGSTART+28, VLMG3+6, outbuf) ;
  56.    sprintf(outbuf, "%2d", x1 & 15) ;
  57.    drawtext(HLMGSTART+12, VLMG4+6, outbuf) ;
  58. }
  59. updatebits() {
  60.    int x=HBITSTART, y=VBITSTART+1 ;
  61.    register short *p1 = realbits, *p2 = safearr ;
  62.    int i = 192 ;
  63.    int rc = 6 ;
  64.    int bit ;
  65.  
  66.    while (i-- > 0) {
  67.       if (*p1 == *p2) {
  68.          p1++ ;
  69.          p2++ ;
  70.          x += 6 * 16 ;
  71.       } else {
  72.          bit = 0x8000 ;
  73.          while (bit != 0) {
  74.             if ((*p2 & bit) != (*p1 & bit)) {
  75.                color((*p1 & bit) ? WHITE : BLACK) ;
  76.                fbox(x, y, 4, 2) ;
  77.             }
  78.             bit = (bit >> 1) & 0x7fff ;
  79.             x += 6 ;
  80.          }
  81.          *p2++ = *p1++ ;
  82.       }
  83.       if (--rc == 0) {
  84.          rc = 6 ;
  85.          x = HBITSTART ;
  86.          y += 3 ;
  87.       }
  88.    }
  89. }
  90.