⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tilemod.c

📁 十七种模拟器源代码 非常有用的作课程设计不可缺少的
💻 C
📖 第 1 页 / 共 2 页
字号:
   rotate and flip all tile_list tiles   */   for( i = 0; i < tile_list_count; i ++){      j  = display_cfg.rotate;      j -= tile_list[i].rotate;      j &= 3;      k  = display_cfg.flip;      k -= tile_list[i].flip;      k &= 3;      if(j || k){         do_flip(&tile_list[i], tile_list[i].flip);         do_rotate(&tile_list[i], j);         do_flip(&tile_list[i], display_cfg.flip);         tile_list[i].rotate = display_cfg.rotate;         tile_list[i].flip   = display_cfg.flip;      }   }   /*   rotate and flip the template tiles (used for building correctly   rotated GFX RAM tiles)   */   for(i = 0; i < (8 * 8); i++)       tile_8x8_map[i] = i;   tile_8x8_template.rotate = 0;   tile_8x8_template.flip = 0;   do_rotate(&tile_8x8_template, (0 - display_cfg.rotate) & 3);   do_flip(&tile_8x8_template, display_cfg.flip);   tile_8x8_template.rotate = display_cfg.rotate;   tile_8x8_template.flip = display_cfg.flip;   for(i = 0; i < (16 * 16); i++)       tile_16x16_map[i] = i;   tile_16x16_template.rotate = 0;   tile_16x16_template.flip = 0;   do_rotate(&tile_16x16_template, (0 - display_cfg.rotate) & 3);   do_flip(&tile_16x16_template, display_cfg.flip);   tile_16x16_template.rotate = display_cfg.rotate;   tile_16x16_template.flip = display_cfg.flip;   for(i = 0; i < (32 * 32); i++)       tile_32x32_map[i] = i;   tile_32x32_template.rotate = 0;   tile_32x32_template.flip = 0;   do_rotate(&tile_32x32_template, (0 - display_cfg.rotate) & 3);   do_flip(&tile_32x32_template, display_cfg.flip);   tile_32x32_template.rotate = display_cfg.rotate;   tile_32x32_template.flip = display_cfg.flip;}UINT8 *MakeSolidTileMap16x16(UINT8 *source, UINT32 count){   return MakeSolidTileMap(source,count,16*16);}UINT8 *MakeSolidTileMap32x32(UINT8 *source, UINT32 count){   return MakeSolidTileMap(source,count,32*32);}UINT8 *MakeSolidTileMap64x64(UINT8 *source, UINT32 count){   return MakeSolidTileMap(source,count,64*64);}UINT32 get_pad_size(UINT32 count){   UINT32 pad_size;   pad_size = 0x010000;   if(count>0x10000) pad_size = 0x020000;   if(count>0x20000) pad_size = 0x040000;   if(count>0x40000) pad_size = 0x080000;   if(count>0x80000) pad_size = 0x100000;   return pad_size;}UINT8 *make_solid_mask(UINT8 *source, UINT32 count, UINT32 size, UINT32 pad_size){   UINT32 ta,tb,tc,td,te;   UINT8 *map;   if(pad_size<count)      pad_size = get_pad_size(count);   if(!(map=AllocateMem(pad_size))) return NULL;   memset(map,0x00,pad_size);   tb=0;   for(ta=0;ta<count;ta++){      td=0;      te=0;      for(tc=0;tc<size;tc++,tb++){         if(source[tb])            td=1;         else            te=1;      }      if((td==0)&&(te==1)) map[ta]=0;      // All pixels are 0: Don't Draw      if((td==1)&&(te==1)) map[ta]=1;      // Mixed: Draw Trans      if((td==1)&&(te==0)) map[ta]=2;      // All pixels are !0: Draw Solid   }   return map;}UINT8 *make_solid_mask_8x8(UINT8 *source, UINT32 count){   UINT8 *map;   map = make_solid_mask(source, count, 8*8, 0);   tile_list[tile_list_count].count  = count;   tile_list[tile_list_count].type   = TILE_TYPE_8x8;   tile_list[tile_list_count].width  = 8;   tile_list[tile_list_count].height = 8;   tile_list[tile_list_count].data   = source;   tile_list[tile_list_count].mask   = map;   tile_list[tile_list_count].rotate = 0;   tile_list[tile_list_count].flip   = 0;   tile_list_count++;   return map;}UINT8 *make_solid_mask_16x8(UINT8 *source, UINT32 count){   return make_solid_mask(source, count, 16*8, 0);}UINT8 *make_solid_mask_16x16(UINT8 *source, UINT32 count){   UINT8 *map;   map = make_solid_mask(source, count, 16*16, 0);   tile_list[tile_list_count].count  = count;   tile_list[tile_list_count].type   = TILE_TYPE_16x16;   tile_list[tile_list_count].width  = 16;   tile_list[tile_list_count].height = 16;   tile_list[tile_list_count].data   = source;   tile_list[tile_list_count].mask   = map;   tile_list[tile_list_count].rotate = 0;   tile_list[tile_list_count].flip   = 0;   tile_list_count++;   return map;}UINT8 *make_solid_mask_32x32(UINT8 *source, UINT32 count){   UINT8 *map;   map = make_solid_mask(source, count, 32*32, 0);   tile_list[tile_list_count].count  = count;   tile_list[tile_list_count].type   = TILE_TYPE_32x32;   tile_list[tile_list_count].width  = 32;   tile_list[tile_list_count].height = 32;   tile_list[tile_list_count].data   = source;   tile_list[tile_list_count].mask   = map;   tile_list[tile_list_count].rotate = 0;   tile_list[tile_list_count].flip   = 0;   tile_list_count++;   return map;}UINT8 *make_solid_mask_64x64(UINT8 *source, UINT32 count){   return make_solid_mask(source, count, 64*64, 0);}UINT8 *make_solid_mask_pad_8x8(UINT8 *source, UINT32 count, UINT32 pad_size){   UINT8 *map;   map = make_solid_mask(source, count, 8*8, pad_size);   tile_list[tile_list_count].count  = count;   tile_list[tile_list_count].type   = TILE_TYPE_8x8;   tile_list[tile_list_count].width  = 8;   tile_list[tile_list_count].height = 8;   tile_list[tile_list_count].data   = source;   tile_list[tile_list_count].mask   = map;   tile_list[tile_list_count].rotate = 0;   tile_list[tile_list_count].flip   = 0;   tile_list_count++;   return map;}UINT8 *make_solid_mask_pad_16x16(UINT8 *source, UINT32 count, UINT32 pad_size){   UINT8 *map;   map = make_solid_mask(source, count, 16*16, pad_size);   tile_list[tile_list_count].count  = count;   tile_list[tile_list_count].type   = TILE_TYPE_16x16;   tile_list[tile_list_count].width  = 16;   tile_list[tile_list_count].height = 16;   tile_list[tile_list_count].data   = source;   tile_list[tile_list_count].mask   = map;   tile_list[tile_list_count].rotate = 0;   tile_list[tile_list_count].flip   = 0;   tile_list_count++;   return map;}UINT8 *make_solid_mask_4bpp(UINT8 *source, UINT32 count, UINT32 size){   UINT32 ta,tb,tc,td,te;   UINT8 *map;   ta = get_pad_size(count);   if(!(map=AllocateMem(ta))) return NULL;   memset(map,0x00,ta);   tb=0;   for(ta=0;ta<count;ta++){      td=0;      te=0;      for(tc=0;tc<size;tc+=2,tb++){         if((source[tb]&0xF0)!=0) td=1;         else te=1;         if((source[tb]&0x0F)!=0) td=1;         else te=1;      }      if((td==0)&&(te==1)) map[ta]=0;      // All pixels are 0: Don't Draw      if((td==1)&&(te==1)) map[ta]=1;      // Mixed: Draw Trans      if((td==1)&&(te==0)) map[ta]=2;      // All pixels are !0: Draw Solid   }   return(map);}UINT8 *make_solid_mask_8x8_4bpp(UINT8 *source, UINT32 count){   return make_solid_mask_4bpp(source,count,8*8);}UINT8 *make_solid_mask_16x16_4bpp(UINT8 *source, UINT32 count){   return make_solid_mask_4bpp(source,count,16*16);}UINT8 *make_solid_mask_64x64_4bpp(UINT8 *source, UINT32 count){   return make_solid_mask_4bpp(source,count,64*64);}UINT8 *make_colour_count(UINT8 *source, UINT32 count, UINT32 size){   UINT32 ta,tb,tc,td,te;   UINT8 *map;   ta = get_pad_size(count);   if(!(map=AllocateMem(ta))) return NULL;   memset(map,0x00,ta);   tb=0;   for(ta=0;ta<count;ta++){      td = 0;      for(tc=0;tc<size;tc++,tb++){         if(source[tb] > td) td = source[tb];      }      te = 0;      if(td>0x00) te=0x01;      if(td>0x01) te=0x02;      if(td>0x02) te=0x04;      if(td>0x04) te=0x08;      if(td>0x08) te=0x10;      if(td>0x10) te=0x20;      if(td>0x20) te=0x40;      if(td>0x40) te=0x80;      if(td>0x80) te=0xFF;      map[ta] = te;   }   return map;}UINT8 *make_colour_count_16x16(UINT8 *source, UINT32 count){   return make_colour_count(source,count,16*16);}/*GFX ROM decoding (mame style)*/#define readbit(src, bitnum)                       \   (src[(bitnum) >> 3] & (0x80 >> ((bitnum) & 7))) \typedef struct GFX_ELEMENT{   int width, height;   unsigned char *gfxdata; /* pixel data */   int line_modulo;        /* amount to add to get to the next line (usually = width) */   int char_modulo;        /* = line_modulo * height */} GFX_ELEMENT;static void decodechar(GFX_ELEMENT *gfx, int num, const UINT8 *src, const GFX_LAYOUT *gl){   int plane,x,y;   UINT8 *dp;   int baseoffs;   const UINT32 *xoffset,*yoffset;   xoffset = gl->xoffset;   yoffset = gl->yoffset;   dp = gfx->gfxdata + num * gfx->char_modulo;   memset(dp,0,gfx->height * gfx->line_modulo);   baseoffs = num * gl->charincrement;   for (plane = 0;plane < gl->planes;plane++)   {      int shiftedbit = 1 << (gl->planes-1-plane);      int offs = baseoffs + gl->planeoffset[plane];      dp = gfx->gfxdata + num * gfx->char_modulo + (gfx->height-1) * gfx->line_modulo;      y = gfx->height;      while (--y >= 0)      {         int offs2 = offs + yoffset[y];         x = gfx->width;         while (--x >= 0)         {            if (readbit(src,offs2 + xoffset[x]))               dp[x] |= shiftedbit;         }         dp -= gfx->line_modulo;      }   }}UINT8 *decode_gfx(const UINT8 *src, const UINT32 src_size, const GFX_LAYOUT *gfx_layout){   GFX_ELEMENT gfx;   GFX_LAYOUT gl;   UINT8 *gfx_data;   UINT32 c, j, reglen;   /*   some weirdness   */   reglen = 8 * src_size;   memcpy(&gl, gfx_layout, sizeof(gl));   if (IS_FRAC(gl.total))      gl.total = reglen / gl.charincrement * FRAC_NUM(gl.total) / FRAC_DEN(gl.total);   for (j = 0;j < MAX_GFX_PLANES;j++)   {      if (IS_FRAC(gl.planeoffset[j]))      {         gl.planeoffset[j] = FRAC_OFFSET(gl.planeoffset[j]) +               reglen * FRAC_NUM(gl.planeoffset[j]) / FRAC_DEN(gl.planeoffset[j]);      }   }   for (j = 0;j < MAX_GFX_SIZE;j++)   {      if (IS_FRAC(gl.xoffset[j]))      {         gl.xoffset[j] = FRAC_OFFSET(gl.xoffset[j]) +               reglen * FRAC_NUM(gl.xoffset[j]) / FRAC_DEN(gl.xoffset[j]);      }      if (IS_FRAC(gl.yoffset[j]))      {         gl.yoffset[j] = FRAC_OFFSET(gl.yoffset[j]) +               reglen * FRAC_NUM(gl.yoffset[j]) / FRAC_DEN(gl.yoffset[j]);      }   }   /*   some setup then decode   */   memset(&gfx, 0, sizeof(gfx));   gfx.width = gl.width;   gfx.height = gl.height;   gfx.line_modulo = gfx.width;   gfx.char_modulo = gfx.line_modulo * gfx.height;   gfx_data = AllocateMem(gl.total * gfx.char_modulo * sizeof(UINT8));   if(!gfx_data)   {      return 0;   }   gfx.gfxdata = gfx_data;   for (c = 0;c < gl.total;c++)      decodechar(&gfx, c, src, &gl);   return gfx_data;}/*convert real bpp -> internal bpp 8 ->  815 -> 1616 -> 1624 -> 3232 -> 32*/UINT32 internal_bpp(UINT32 source){   static const UINT32 dest[4] =   {      8, 16, 32, 32,   };   return dest[((source - 1) >> 3) & 3];}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -