Diff for /np2/generic/cmndraw.c between versions 1.6 and 1.8

version 1.6, 2004/03/25 10:41:13 version 1.8, 2004/04/06 18:41:00
Line 457  void cmddraw_fill(CMNVRAM *vram, int x,  Line 457  void cmddraw_fill(CMNVRAM *vram, int x, 
         }          }
 }  }
   
 void cmddraw_text8(CMNVRAM *vram, int x, int y, const char *str, CMNPALS *pal) {  
   
         UINT    s;  // ---- new
 const BYTE      *ptr;  
         BYTE    src[10];  void cmndraw_fill2(const CMNVRAM *vram, int x, int y,
                                                                                   int cx, int cy, CMNPAL fg) {
   
           BYTE    *p;
           int             dalign;
           int             r;
   
         if ((vram == NULL) || (str == NULL) || (pal == NULL)) {          if (vram == NULL) {
                 return;                  return;
         }          }
         src[0] = 0;          p = vram->ptr + (x * vram->xalign) + (y * vram->yalign);
         src[1] = 7;          dalign = vram->yalign - (vram->xalign * cx);
         while(*str) {          switch(vram->bpp) {
                 s = (UINT)(*str++);  #if defined(SUPPORT_8BPP)
                 ptr = NULL;                  case 8:
                 if ((s >= 0x20) && (s < 0x80)) {                          do {
                         ptr = minifont + (s - 0x20) * 8;                                  r = cx;
                 }                                  do {
                 else if ((s >= 0xa0) && (s < 0xe0)) {                                          *p = fg.pal8;
                         ptr = minifont + (s - 0xa0 + 0x60) * 8;                                          p += vram->xalign;
                 }                                  } while(--r);
                 if (ptr == NULL) {                                  p += dalign;
                         continue;                          } while(--cy);
                           break;
   #endif
   #if defined(SUPPORT_16BPP)
                   case 16:
                           do {
                                   r = cx;
                                   do {
                                           *(UINT16 *)p = fg.pal16;
                                           p += vram->xalign;
                                   } while(--r);
                                   p += dalign;
                           } while(--cy);
                           break;
   #endif
   #if defined(SUPPORT_24BPP)
                   case 24:
                           do {
                                   r = cx;
                                   do {
                                           p[RGB24_R] = fg.pal32.p.r;
                                           p[RGB24_G] = fg.pal32.p.g;
                                           p[RGB24_B] = fg.pal32.p.b;
                                           p += vram->xalign;
                                   } while(--r);
                                   p += dalign;
                           } while(--cy);
                           break;
   #endif
   #if defined(SUPPORT_32BPP)
                   case 32:
                           do {
                                   r = cx;
                                   do {
                                           *(UINT32 *)p = fg.pal32.d;
                                           p += vram->xalign;
                                   } while(--r);
                                   p += dalign;
                           } while(--cy);
                           break;
   #endif
           }
   }
   
   void cmndraw_setfg2(const CMNVRAM *vram, const BYTE *src,
                                                                                   int x, int y, CMNPAL fg) {
   
   const BYTE      *p;
           BYTE    *q;
           BYTE    cy;
           int             dalign;
           BYTE    c;
           BYTE    bit;
           BYTE    cx;
   
           if (vram == NULL) {
                   return;
           }
           p = src + 2;
           q = vram->ptr + (x * vram->xalign) + (y * vram->yalign);
           dalign = vram->yalign - (vram->xalign * src[0]);
           cy = src[1];
           do {
                   cx = src[0];
                   bit = 0;
                   c = 0;
                   switch(vram->bpp) {
   #if defined(SUPPORT_8BPP)
                           case 8:
                                   do {
                                           if (!bit) {
                                                   bit = 0x80;
                                                   c = *p++;
                                           }
                                           if (c & bit) {
                                                   *q = fg.pal8;
                                           }
                                           bit >>= 1;
                                           q += vram->xalign;
                                   } while(--cx);
                                   break;
   #endif
   #if defined(SUPPORT_16BPP)
                           case 16:
                                   do {
                                           if (!bit) {
                                                   bit = 0x80;
                                                   c = *p++;
                                           }
                                           if (c & bit) {
                                                   *(UINT16 *)q = fg.pal16;
                                           }
                                           bit >>= 1;
                                           q += vram->xalign;
                                   } while(--cx);
                                   break;
   #endif
   #if defined(SUPPORT_24BPP)
                           case 24:
                                   do {
                                           if (!bit) {
                                                   bit = 0x80;
                                                   c = *p++;
                                           }
                                           if (c & bit) {
                                                   q[RGB24_R] = fg.pal32.p.r;
                                                   q[RGB24_G] = fg.pal32.p.g;
                                                   q[RGB24_B] = fg.pal32.p.b;
                                           }
                                           bit >>= 1;
                                           q += vram->xalign;
                                   } while(--cx);
                                   break;
   #endif
   #if defined(SUPPORT_32BPP)
                           case 32:
                                   do {
                                           if (!bit) {
                                                   bit = 0x80;
                                                   c = *p++;
                                           }
                                           if (c & bit) {
                                                   *(UINT32 *)q = fg.pal32.d;
                                           }
                                           bit >>= 1;
                                           q += vram->xalign;
                                   } while(--cx);
                                   break;
   #endif
                 }                  }
                 src[0] = ptr[0];                  q += dalign;
                 CopyMemory(src + 2, ptr + 1, 7);          } while(--cy);
   }
   
   void cmndraw_setpat2(const CMNVRAM *vram, const BYTE *src,
                                                                                   int x, int y, CMNPAL bg, CMNPAL fg) {
   
   const BYTE      *p;
           BYTE    *q;
           BYTE    cy;
           int             dalign;
           BYTE    c;
           BYTE    bit;
           BYTE    cx;
   
           p = src + 2;
           q = vram->ptr + (x * vram->xalign) + (y * vram->yalign);
           dalign = vram->yalign - (vram->xalign * src[0]);
           cy = src[1];
           do {
                   cx = src[0];
                   bit = 0;
                   c = 0;
                 switch(vram->bpp) {                  switch(vram->bpp) {
 #if defined(SUPPORT_8BPP)  #if defined(SUPPORT_8BPP)
                         case 8:                          case 8:
                                 cmndraw8_setfg(vram, src, x, y, pal->pal8);                                  do {
                                           if (!bit) {
                                                   bit = 0x80;
                                                   c = *p++;
                                           }
                                           if (c & bit) {
                                                   *q = fg.pal8;
                                           }
                                           else {
                                                   *q = bg.pal8;
                                           }
                                           bit >>= 1;
                                           q += vram->xalign;
                                   } while(--cx);
                                 break;                                  break;
 #endif  #endif
 #if defined(SUPPORT_16BPP)  #if defined(SUPPORT_16BPP)
                         case 16:                          case 16:
                                 cmndraw16_setfg(vram, src, x, y, pal->pal16);                                  do {
                                           if (!bit) {
                                                   bit = 0x80;
                                                   c = *p++;
                                           }
                                           if (c & bit) {
                                                   *(UINT16 *)q = fg.pal16;
                                           }
                                           else {
                                                   *(UINT16 *)q = bg.pal16;
                                           }
                                           bit >>= 1;
                                           q += vram->xalign;
                                   } while(--cx);
                                 break;                                  break;
 #endif  #endif
 #if defined(SUPPORT_24BPP)  #if defined(SUPPORT_24BPP)
                         case 24:                          case 24:
                                 cmndraw24_setfg(vram, src, x, y, pal->pal32);                                  do {
                                           if (!bit) {
                                                   bit = 0x80;
                                                   c = *p++;
                                           }
                                           if (c & bit) {
                                                   q[RGB24_R] = fg.pal32.p.r;
                                                   q[RGB24_G] = fg.pal32.p.g;
                                                   q[RGB24_B] = fg.pal32.p.b;
                                           }
                                           else {
                                                   q[RGB24_R] = bg.pal32.p.r;
                                                   q[RGB24_G] = bg.pal32.p.g;
                                                   q[RGB24_B] = bg.pal32.p.b;
                                           }
                                           bit >>= 1;
                                           q += vram->xalign;
                                   } while(--cx);
                                 break;                                  break;
 #endif  #endif
 #if defined(SUPPORT_32BPP)  #if defined(SUPPORT_32BPP)
                         case 32:                          case 32:
                                 cmndraw32_setfg(vram, src, x, y, pal->pal32);                                  do {
                                           if (!bit) {
                                                   bit = 0x80;
                                                   c = *p++;
                                           }
                                           if (c & bit) {
                                                   *(UINT32 *)q = fg.pal32.d;
                                           }
                                           else {
                                                   *(UINT32 *)q = bg.pal32.d;
                                           }
                                           bit >>= 1;
                                           q += vram->xalign;
                                   } while(--cx);
                                 break;                                  break;
 #endif  #endif
                 }                  }
                   q += dalign;
           } while(--cy);
   }
   
   
   
   
   
   
   
   
   
   
   
   
   // ----
   
   void cmddraw_text8(CMNVRAM *vram, int x, int y, const char *str, CMNPAL fg) {
   
           UINT    s;
   const BYTE      *ptr;
           BYTE    src[10];
   
           if ((vram == NULL) || (str == NULL)) {
                   return;
           }
           src[0] = 0;
           src[1] = 7;
           while(*str) {
                   s = (UINT)(*str++);
                   ptr = NULL;
                   if ((s >= 0x20) && (s < 0x80)) {
                           ptr = minifont + (s - 0x20) * 8;
                   }
                   else if ((s >= 0xa0) && (s < 0xe0)) {
                           ptr = minifont + (s - 0xa0 + 0x60) * 8;
                   }
                   if (ptr == NULL) {
                           continue;
                   }
                   src[0] = ptr[0];
                   CopyMemory(src + 2, ptr + 1, 7);
                   cmndraw_setfg2(vram, src, x, y, fg);
                 x += ptr[0] + 1;                  x += ptr[0] + 1;
         }          }
 }  }
Line 511  const BYTE *ptr; Line 763  const BYTE *ptr;
   
 // ---- bmp  // ---- bmp
   
 void cmddraw_bmp16(CMNVRAM *vram, const void *bmp, CMNPALCNV cnv, UINT flag) {  BOOL cmndraw_bmp4inf(CMNBMP *bmp, const void *ptr) {
   
 const BMPFILE   *bf;  const BMPFILE   *bf;
 const BMPINFO   *bi;  const BMPINFO   *bi;
Line 521  const BYTE  *palptr; Line 773  const BYTE  *palptr;
         int                     bmpalign;          int                     bmpalign;
         UINT            pals;          UINT            pals;
         UINT            c;          UINT            c;
         RGB32           paltbl[16];  
         CMNPAL          pal[16];  
         BYTE            *dst;  
         int                     yalign;  
         int                     x;  
         int                     y;  
   
         if ((vram == NULL) || (bmp == NULL) || (cnv == NULL)) {          if ((bmp == NULL) || (ptr == NULL)) {
                 return;                  return(FAILURE);
         }          }
         bf = (BMPFILE *)bmp;          bf = (BMPFILE *)ptr;
         bi = (BMPINFO *)(bf + 1);          bi = (BMPINFO *)(bf + 1);
         palptr = (BYTE *)(bi + 1);          palptr = (BYTE *)(bi + 1);
         if (((bf->bfType[0] != 'B') && (bf->bfType[1] != 'M')) ||          if (((bf->bfType[0] != 'B') && (bf->bfType[1] != 'M')) ||
                 (bmpdata_getinfo(bi, &inf) != SUCCESS) || (inf.bpp != 4)) {                  (bmpdata_getinfo(bi, &inf) != SUCCESS) || (inf.bpp != 4)) {
                 return;                  return(FAILURE);
         }          }
           pals = min(LOADINTELDWORD(bi->biClrUsed), 16);
   
         src = (BYTE *)bf + (LOADINTELDWORD(bf->bfOffBits));          src = (BYTE *)bf + (LOADINTELDWORD(bf->bfOffBits));
         bmpalign = bmpdata_getalign(bi);          bmpalign = bmpdata_getalign(bi);
         if (inf.height > 0) {          if (inf.height > 0) {
                 src += (inf.height - 1) * bmpalign;                  bmp->ptr = src + ((inf.height - 1) * bmpalign);
                 bmpalign *= -1;                  bmp->width = inf.width;
                   bmp->height = inf.height;
                   bmp->align = bmpalign * -1;
         }          }
         else {          else {
                 inf.height *= -1;                  bmp->ptr = src;
                   bmp->width = inf.width;
                   bmp->height = inf.height * -1;
                   bmp->align = bmpalign;
         }          }
         if ((vram->width < inf.width) || (vram->height < inf.height)) {          bmp->pals = pals;
                 return;          ZeroMemory(bmp->paltbl, sizeof(bmp->paltbl));
         }  
         pals = LOADINTELDWORD(bi->biClrUsed);  
         pals = min(pals, 16);  
         ZeroMemory(paltbl, sizeof(paltbl));  
         for (c=0; c<pals; c++) {          for (c=0; c<pals; c++) {
                 paltbl[c].p.b = palptr[c*4+0];                  bmp->paltbl[c].p.b = palptr[c*4+0];
                 paltbl[c].p.g = palptr[c*4+1];                  bmp->paltbl[c].p.g = palptr[c*4+1];
                 paltbl[c].p.r = palptr[c*4+2];                  bmp->paltbl[c].p.r = palptr[c*4+2];
           }
           return(SUCCESS);
   }
   
   void cmndraw_bmp16(CMNVRAM *vram, const void *ptr, CMNPALCNV cnv, UINT flag) {
   
           CMNBMP  bmp;
           CMNPAL  pal[16];
           BYTE    *src;
           BYTE    *dst;
           int             yalign;
           int             x;
           int             y;
           UINT    c;
   
           if ((vram == NULL) || (cnv == NULL) ||
                   (cmndraw_bmp4inf(&bmp, ptr) != SUCCESS) ||
                   (vram->width < bmp.width) || (vram->height < bmp.height)) {
                   return;
         }          }
         (*cnv)(pal, paltbl, pals, vram->bpp);          (*cnv)(pal, bmp.paltbl, bmp.pals, vram->bpp);
           src = bmp.ptr;
         dst = vram->ptr;          dst = vram->ptr;
         switch(flag & 0x03) {          switch(flag & 0x03) {
                 case CMNBMP_CENTER:                  case CMNBMP_CENTER:
                         dst += ((vram->width - inf.width) / 2) * vram->xalign;                          dst += ((vram->width - bmp.width) / 2) * vram->xalign;
                         break;                          break;
   
                 case CMNBMP_RIGHT:                  case CMNBMP_RIGHT:
                         dst += (vram->width - inf.width) * vram->xalign;                          dst += (vram->width - bmp.width) * vram->xalign;
                         break;                          break;
         }          }
         switch(flag & 0x0c) {          switch(flag & 0x0c) {
                 case CMNBMP_MIDDLE:                  case CMNBMP_MIDDLE:
                         dst += ((vram->height - inf.height) / 2) * vram->yalign;                          dst += ((vram->height - bmp.height) / 2) * vram->yalign;
                         break;                          break;
   
                 case CMNBMP_BOTTOM:                  case CMNBMP_BOTTOM:
                         dst += (vram->height - inf.height) * vram->yalign;                          dst += (vram->height - bmp.height) * vram->yalign;
                         break;                          break;
         }          }
         yalign = vram->yalign - (inf.width * vram->xalign);          yalign = vram->yalign - (bmp.width * vram->xalign);
         switch(vram->bpp) {          for (y=0; y<bmp.height; y++) {
                   switch(vram->bpp) {
 #if defined(SUPPORT_8BPP)  #if defined(SUPPORT_8BPP)
                 case 8:                          case 8:
                         for (y=0; y<inf.height; y++) {                                  for (x=0; x<bmp.width; x++) {
                                 for (x=0; x<inf.width; x++) {  
                                         if (!(x & 1)) {                                          if (!(x & 1)) {
                                                 c = src[x >> 1] >> 4;                                                  c = src[x >> 1] >> 4;
                                         }                                          }
Line 593  const BYTE  *palptr; Line 862  const BYTE  *palptr;
                                         *dst = pal[c].pal8;                                          *dst = pal[c].pal8;
                                         dst += vram->xalign;                                          dst += vram->xalign;
                                 }                                  }
                                 src += bmpalign;                                  break;
                                 dst += yalign;  
                         }  
                         break;  
 #endif  #endif
 #if defined(SUPPORT_16BPP)  #if defined(SUPPORT_16BPP)
                 case 16:                          case 16:
                         for (y=0; y<inf.height; y++) {                                  for (x=0; x<bmp.width; x++) {
                                 for (x=0; x<inf.width; x++) {  
                                         if (!(x & 1)) {                                          if (!(x & 1)) {
                                                 c = src[x >> 1] >> 4;                                                  c = src[x >> 1] >> 4;
                                         }                                          }
Line 611  const BYTE  *palptr; Line 876  const BYTE  *palptr;
                                         *(UINT16 *)dst = pal[c].pal16;                                          *(UINT16 *)dst = pal[c].pal16;
                                         dst += vram->xalign;                                          dst += vram->xalign;
                                 }                                  }
                                 src += bmpalign;                                  break;
                                 dst += yalign;  
                         }  
                         break;  
 #endif  #endif
 #if defined(SUPPORT_24BPP)  #if defined(SUPPORT_24BPP)
                 case 24:                          case 24:
                         for (y=0; y<inf.height; y++) {                                  for (x=0; x<bmp.width; x++) {
                                 for (x=0; x<inf.width; x++) {  
                                         if (!(x & 1)) {                                          if (!(x & 1)) {
                                                 c = src[x >> 1] >> 4;                                                  c = src[x >> 1] >> 4;
                                         }                                          }
Line 631  const BYTE  *palptr; Line 892  const BYTE  *palptr;
                                         dst[RGB24_B] = pal[c].pal32.p.b;                                          dst[RGB24_B] = pal[c].pal32.p.b;
                                         dst += vram->xalign;                                          dst += vram->xalign;
                                 }                                  }
                                 src += bmpalign;                                  break;
                                 dst += yalign;  
                         }  
                         break;  
 #endif  #endif
 #if defined(SUPPORT_32BPP)  #if defined(SUPPORT_32BPP)
                 case 32:                          case 32:
                         for (y=0; y<inf.height; y++) {                                  for (x=0; x<bmp.width; x++) {
                                 for (x=0; x<inf.width; x++) {  
                                         if (!(x & 1)) {                                          if (!(x & 1)) {
                                                 c = src[x >> 1] >> 4;                                                  c = src[x >> 1] >> 4;
                                         }                                          }
Line 649  const BYTE  *palptr; Line 906  const BYTE  *palptr;
                                         *(UINT32 *)dst = pal[c].pal32.d;                                          *(UINT32 *)dst = pal[c].pal32.d;
                                         dst += vram->xalign;                                          dst += vram->xalign;
                                 }                                  }
                                 src += bmpalign;                                  break;
                                 dst += yalign;  
                         }  
                         break;  
 #endif  #endif
                   }
                   src += bmp.align;
                   dst += yalign;
         }          }
 }  }
   

Removed from v.1.6  
changed lines
  Added in v.1.8


RetroPC.NET-CVS <cvs@retropc.net>