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

📄 copia de cps1.c

📁 这个是延伸mame的在wince平台下的游戏模拟器的代码
💻 C
📖 第 1 页 / 共 4 页
字号:
	sy=dest->height-temp-size;
		temp=flipx;
		flipx=flipy;
	flipy=!temp;
	}

	if (cps1_flip_screen)
	{
		/* Handle flipped screen */
		flipx=!flipx;
		flipy=!flipy;
		sx=dest->width-sx-size;
		sy=dest->height-sy-size;
	}

	if (sx<0 || sx > dest->width-size || sy<0 || sy>dest->height-size )
	{
		return;
	}


	src = cps1_gfx+code*delta;
	paldata = &gfx->colortable[gfx->color_granularity * color];

	if (Machine->orientation & ORIENTATION_SWAP_XY)
	{
		if (flipy)
		{
		      sy+=size;
		      if (flipx)
		      {
				sx+=size;
				for (i=0; i<size; i++)
				{
					unsigned char *bm;
					int ny=sy;
					for (j=0; j<size/8; j++)
					{
					      dwval=*src;
					      n=(dwval>>28)&0x0f;
					      bm=dest->line[ny-1]+sx;
					      if (tpens & (0x01 << n)) bm[-1]=paldata[n];
					      n=(dwval>>24)&0x0f;
					      bm=dest->line[ny-2]+sx;
					      if (tpens & (0x01 << n)) bm[-1]=paldata[n];
					      n=(dwval>>20)&0x0f;
					      bm=dest->line[ny-3]+sx;
					      if (tpens & (0x01 << n)) bm[-1]=paldata[n];
					      n=(dwval>>16)&0x0f;
					      bm=dest->line[ny-4]+sx;
					      if (tpens & (0x01 << n)) bm[-1]=paldata[n];
					      n=(dwval>>12)&0x0f;
					      bm=dest->line[ny-5]+sx;
					      if (tpens & (0x01 << n)) bm[-1]=paldata[n];
					      n=(dwval>>8)&0x0f;
					      bm=dest->line[ny-6]+sx;
					      if (tpens & (0x01 << n)) bm[-1]=paldata[n];
					      n=(dwval>>4)&0x0f;
					      bm=dest->line[ny-7]+sx;
					      if (tpens & (0x01 << n)) bm[-1]=paldata[n];
					      n=dwval&0x0f;
					      bm=dest->line[ny-8]+sx;
					      if (tpens & (0x01 << n)) bm[-1]=paldata[n];
					      ny-=8;
					      src++;
					}
					sx--;
					src+=srcdelta;
				}
		      }
		      else
		      {
				for (i=0; i<size; i++)
				{
					unsigned char *bm;
					int ny=sy;
					for (j=0; j<size/8; j++)
					{
					      dwval=*src;
					      n=(dwval>>28)&0x0f;
					      bm=dest->line[ny-1]+sx;
					      if (tpens & (0x01 << n)) bm[0]=paldata[n];
					      n=(dwval>>24)&0x0f;
					      bm=dest->line[ny-2]+sx;
					      if (tpens & (0x01 << n)) bm[0]=paldata[n];
					      n=(dwval>>20)&0x0f;
					      bm=dest->line[ny-3]+sx;
					      if (tpens & (0x01 << n)) bm[0]=paldata[n];
					      n=(dwval>>16)&0x0f;
					      bm=dest->line[ny-4]+sx;
					      if (tpens & (0x01 << n)) bm[0]=paldata[n];
					      n=(dwval>>12)&0x0f;
					      bm=dest->line[ny-5]+sx;
					      if (tpens & (0x01 << n)) bm[0]=paldata[n];
					      n=(dwval>>8)&0x0f;
					      bm=dest->line[ny-6]+sx;
					      if (tpens & (0x01 << n)) bm[0]=paldata[n];
					      n=(dwval>>4)&0x0f;
					      bm=dest->line[ny-7]+sx;
					      if (tpens & (0x01 << n)) bm[0]=paldata[n];
					      n=dwval&0x0f;
					      bm=dest->line[ny-8]+sx;
					      if (tpens & (0x01 << n)) bm[0]=paldata[n];
					      ny-=8;
					      src++;
					}
					sx++;
					src+=srcdelta;
				}
		       }
		}
		else
		{
		       if (flipx)
		       {
				sx+=size;
				for (i=0; i<size; i++)
				{
					unsigned char *bm;
					int ny=sy;
					for (j=0; j<size/8; j++)
					{
					      dwval=*src;
					      n=(dwval>>28)&0x0f;
					      bm=dest->line[ny+0]+sx;
					      if (tpens & (0x01 << n)) bm[-1]=paldata[n];
					      n=(dwval>>24)&0x0f;
					      bm=dest->line[ny+1]+sx;
					      if (tpens & (0x01 << n)) bm[-1]=paldata[n];
					      n=(dwval>>20)&0x0f;
					      bm=dest->line[ny+2]+sx;
					      if (tpens & (0x01 << n)) bm[-1]=paldata[n];
					      n=(dwval>>16)&0x0f;
					      bm=dest->line[ny+3]+sx;
					      if (tpens & (0x01 << n)) bm[-1]=paldata[n];
					      n=(dwval>>12)&0x0f;
					      bm=dest->line[ny+4]+sx;
					      if (tpens & (0x01 << n)) bm[-1]=paldata[n];
					      n=(dwval>>8)&0x0f;
					      bm=dest->line[ny+5]+sx;
					      if (tpens & (0x01 << n)) bm[-1]=paldata[n];
					      n=(dwval>>4)&0x0f;
					      bm=dest->line[ny+6]+sx;
					      if (tpens & (0x01 << n)) bm[-1]=paldata[n];
					      n=dwval&0x0f;
					      bm=dest->line[ny+7]+sx;
					      if (tpens & (0x01 << n)) bm[-1]=paldata[n];
					      ny+=8;
					      src++;
					}
					sx--;
					src+=srcdelta;
				}
			}
			else
			{
				for (i=0; i<size; i++)
				{
					unsigned char *bm;
					int ny=sy;
					for (j=0; j<size/8; j++)
					{
					      dwval=*src;
					      n=(dwval>>28)&0x0f;
					      bm=dest->line[ny+0]+sx;
					      if (tpens & (0x01 << n)) bm[0]=paldata[n];
					      n=(dwval>>24)&0x0f;
					      bm=dest->line[ny+1]+sx;
					      if (tpens & (0x01 << n)) bm[0]=paldata[n];
					      n=(dwval>>20)&0x0f;
					      bm=dest->line[ny+2]+sx;
					      if (tpens & (0x01 << n)) bm[0]=paldata[n];
					      n=(dwval>>16)&0x0f;
					      bm=dest->line[ny+3]+sx;
					      if (tpens & (0x01 << n)) bm[0]=paldata[n];
					      n=(dwval>>12)&0x0f;
					      bm=dest->line[ny+4]+sx;
					      if (tpens & (0x01 << n)) bm[0]=paldata[n];
					      n=(dwval>>8)&0x0f;
					      bm=dest->line[ny+5]+sx;
					      if (tpens & (0x01 << n)) bm[0]=paldata[n];
					      n=(dwval>>4)&0x0f;
					      bm=dest->line[ny+6]+sx;
					      if (tpens & (0x01 << n)) bm[0]=paldata[n];
					      n=dwval&0x0f;
					      bm=dest->line[ny+7]+sx;
					      if (tpens & (0x01 << n)) bm[0]=paldata[n];
					      src++;
					      ny+=8;
					}
					sx++;
					src+=srcdelta;
				 }
			}
		}

	}
	else
	{
		if (flipy)
		{
		      sy+=size-1;
		      if (flipx)
		      {
				sx+=size;
				for (i=0; i<size; i++)
				{
					unsigned char *bm=dest->line[sy-i]+sx;
					for (j=0; j<size/8; j++)
					{
					      dwval=*src;
					      n=(dwval>>28)&0x0f;
					      if (tpens & (0x01 << n)) bm[-1]=paldata[n];
					      n=(dwval>>24)&0x0f;
					      if (tpens & (0x01 << n)) bm[-2]=paldata[n];
					      n=(dwval>>20)&0x0f;
					      if (tpens & (0x01 << n)) bm[-3]=paldata[n];
					      n=(dwval>>16)&0x0f;
					      if (tpens & (0x01 << n)) bm[-4]=paldata[n];
					      n=(dwval>>12)&0x0f;
					      if (tpens & (0x01 << n)) bm[-5]=paldata[n];
					      n=(dwval>>8)&0x0f;
					      if (tpens & (0x01 << n)) bm[-6]=paldata[n];
					      n=(dwval>>4)&0x0f;
					      if (tpens & (0x01 << n)) bm[-7]=paldata[n];
					      n=dwval&0x0f;
					      if (tpens & (0x01 << n)) bm[-8]=paldata[n];
					      src++;
					      bm-=8;
					}
					src+=srcdelta;
				}
		      }
		      else
		      {
				for (i=0; i<size; i++)
				{
					unsigned char *bm=dest->line[sy-i]+sx;
					for (j=0; j<size/8; j++)
					{
					      dwval=*src;
					      n=(dwval>>28)&0x0f;
					      if (tpens & (0x01 << n)) bm[0]=paldata[n];
					      n=(dwval>>24)&0x0f;
					      if (tpens & (0x01 << n)) bm[1]=paldata[n];
					      n=(dwval>>20)&0x0f;
					      if (tpens & (0x01 << n)) bm[2]=paldata[n];
					      n=(dwval>>16)&0x0f;
					      if (tpens & (0x01 << n)) bm[3]=paldata[n];
					      n=(dwval>>12)&0x0f;
					      if (tpens & (0x01 << n)) bm[4]=paldata[n];
					      n=(dwval>>8)&0x0f;
					      if (tpens & (0x01 << n)) bm[5]=paldata[n];
					      n=(dwval>>4)&0x0f;
					      if (tpens & (0x01 << n)) bm[6]=paldata[n];
					      n=dwval&0x0f;
					      if (tpens & (0x01 << n)) bm[7]=paldata[n];
					      bm+=8;
					      src++;
					}
					src+=srcdelta;
				}
		       }
		}
		else
		{
		       if (flipx)
		       {
				sx+=size;
				for (i=0; i<size; i++)
				{
					unsigned char *bm=dest->line[sy+i]+sx;
					for (j=0; j<size/8; j++)
					{
					      dwval=*src;
					      n=(dwval>>28)&0x0f;
					      if (tpens & (0x01 << n)) bm[-1]=paldata[n];
					      n=(dwval>>24)&0x0f;
					      if (tpens & (0x01 << n)) bm[-2]=paldata[n];
					      n=(dwval>>20)&0x0f;
					      if (tpens & (0x01 << n)) bm[-3]=paldata[n];
					      n=(dwval>>16)&0x0f;
					      if (tpens & (0x01 << n)) bm[-4]=paldata[n];
					      n=(dwval>>12)&0x0f;
					      if (tpens & (0x01 << n)) bm[-5]=paldata[n];
					      n=(dwval>>8)&0x0f;
					      if (tpens & (0x01 << n)) bm[-6]=paldata[n];
					      n=(dwval>>4)&0x0f;
					      if (tpens & (0x01 << n)) bm[-7]=paldata[n];
					      n=dwval&0x0f;
					      if (tpens & (0x01 << n)) bm[-8]=paldata[n];
					      bm-=8;
					      src++;
					}
					src+=srcdelta;
				}
			}
			else
			{
				for (i=0; i<size; i++)
				{
					unsigned char *bm=dest->line[sy+i]+sx;
					for (j=0; j<size/8; j++)
					{
					      dwval=*src;
					      n=(dwval>>28)&0x0f;
					      if (tpens & (0x01 << n)) bm[0]=paldata[n];
					      n=(dwval>>24)&0x0f;
					      if (tpens & (0x01 << n)) bm[1]=paldata[n];
					      n=(dwval>>20)&0x0f;
					      if (tpens & (0x01 << n)) bm[2]=paldata[n];
					      n=(dwval>>16)&0x0f;
					      if (tpens & (0x01 << n)) bm[3]=paldata[n];
					      n=(dwval>>12)&0x0f;
					      if (tpens & (0x01 << n)) bm[4]=paldata[n];
					      n=(dwval>>8)&0x0f;
					      if (tpens & (0x01 << n)) bm[5]=paldata[n];
					      n=(dwval>>4)&0x0f;
					      if (tpens & (0x01 << n)) bm[6]=paldata[n];
					      n=dwval&0x0f;
					      if (tpens & (0x01 << n)) bm[7]=paldata[n];
					      src++;
					      bm+=8;
					}
					src+=srcdelta;
				 }
			}
		}
       }
}

INLINE void cps1_draw_scroll1(
	struct osd_bitmap *dest,
	unsigned int code, int color,
	int flipx, int flipy,int sx, int sy)
{
	cps1_draw_gfx(dest,
		Machine->gfx[0],
		code,color,flipx,flipy,sx,sy,
		0x8000,cps1_char_pen_usage,8, cps1_max_char, 16, 1);
}


INLINE void cps1_draw_tile16(struct osd_bitmap *dest,
	const struct GfxElement *gfx,
	unsigned int code, int color,
	int flipx, int flipy,int sx, int sy, int tpens)
{
	cps1_draw_gfx(dest,
		gfx,
		code,color,flipx,flipy,sx,sy,
		tpens,cps1_tile16_pen_usage,16, cps1_max_tile16, 16*2,0);
}

INLINE void cps1_draw_tile32(struct osd_bitmap *dest,
	const struct GfxElement *gfx,
	unsigned int code, int color,
	int flipx, int flipy,int sx, int sy, int tpens)
{
	cps1_draw_gfx(dest,
		gfx,
		code,color,flipx,flipy,sx,sy,
		tpens,cps1_tile32_pen_usage,32, cps1_max_tile32, 16*2*4,0);
}





static int cps1_transparency_scroll[4];



#ifdef MAME_DEBUG
void cps1_dump_video(void)
{
	FILE *fp;
	fp=fopen("SCROLL1.DMP", "w+b");
	if (fp)
	{
		fwrite(cps1_scroll1, cps1_scroll1_size, 1, fp);
		fclose(fp);
	}
	fp=fopen("SCROLL2.DMP", "w+b");
	if (fp)
	{
		fwrite(cps1_scroll2, cps1_scroll2_size, 1, fp);
		fclose(fp);
	}
	fp=fopen("SCROLL3.DMP", "w+b");
	if (fp)
	{
		fwrite(cps1_scroll3, cps1_scroll3_size, 1, fp);
		fclose(fp);
	}
	fp=fopen("OBJ.DMP", "w+b");
	if (fp)
	{
		fwrite(cps1_obj, cps1_obj_size, 1, fp);
		fclose(fp);
	}

	fp=fopen("OTHER.DMP", "w+b");
	if (fp)
	{
		fwrite(cps1_other, cps1_other_size, 1, fp);
		fclose(fp);
	}

	fp=fopen("PALETTE.DMP", "w+b");
	if (fp)
	{
		fwrite(cps1_palette, cps1_palette_size, 1, fp);
		fclose(fp);
	}

	fp=fopen("OUTPUT.DMP", "w+b");
	if (fp)
	{
		fwrite(cps1_output, cps1_output_size, 1, fp);
		fclose(fp);
	}
	fp=fopen("VIDEO.DMP", "w+b");
	if (fp)
	{
		fwrite(cps1_gfxram, cps1_gfxram_size, 1, fp);
		fclose(fp);
	}

}
#endif


INLINE void cps1_get_video_base(void )
{
	struct CPS1VIDCFG *pCFG=&cps1_vid_cfg[cps1_game_config->alternative];
	int layercontrol;


	/* Re-calculate the VIDEO RAM base */
	cps1_scroll1=cps1_base(CPS1_SCROLL1_BASE);
	cps1_scroll2=cps1_base(CPS1_SCROLL2_BASE);
	cps1_scroll3=cps1_base(CPS1_SCROLL3_BASE);
	cps1_obj=cps1_base(CPS1_OBJ_BASE);
	cps1_palette=cps1_base(CPS1_PALETTE_BASE);
	cps1_other=cps1_base(CPS1_OTHER_BASE);

	/* Get scroll values */
	scroll1x=cps1_port(CPS1_SCROLL1_SCROLLX);
	scroll1y=cps1_port(CPS1_SCROLL1_SCROLLY);
	scroll2x=cps1_port(CPS1_SCROLL2_SCROLLX);
	scroll2y=cps1_port(CPS1_SCROLL2_SCROLLY);
	scroll3x=cps1_port(CPS1_SCROLL3_SCROLLX);
	scroll3y=cps1_port(CPS1_SCROLL3_SCROLLY);

	/* Get transparency registers */
	if (pCFG->priority1)
	{
		cps1_transparency_scroll[0]=~cps1_port(pCFG->priority0);
		cps1_transparency_scroll[1]=~cps1_port(pCFG->priority1);
		cps1_transparency_scroll[2]=~cps1_port(pCFG->priority2);
		cps1_transparency_scroll[3]=~cps1_port(pCFG->priority3);
	 }

	/* Get layer enable bits */
	layercontrol=READ_WORD(&cps1_output[cps1_layer_control]);
	cps1_layer_enabled[0]=1;
	cps1_layer_enabled[1]=layercontrol & pCFG->scrl1_enable_mask;
	cps1_layer_enabled[2]=layercontrol & pCFG->scrl2_enable_mask;
	cps1_layer_enabled[3]=layercontrol & pCFG->scrl3_enable_mask;
#ifdef MAME_DEBUG
{
	char baf[40];
	int enablemask;

if (osd_key_pressed(OSD_KEY_Z))
{
	if (osd_key_pressed(OSD_KEY_Q)) cps1_layer_enabled[3]=0;
	if (osd_key_pressed(OSD_KEY_W)) cps1_layer_enabled[2]=0;
	if (osd_key_pressed(OSD_KEY_E)) cps1_layer_enabled[1]=0;
	if (osd_key_pressed(OSD_KEY_R)) cps1_layer_enabled[0]=0;
	if (osd_key_pressed(OSD_KEY_T))
	{
		sprintf(baf,"layer %02x",layercontrol&0xc03f);
		usrintf_showmessage(baf);
	}
}

	enablemask = pCFG->scrl1_enable_mask | pCFG->scrl2_enable_mask | pCFG->scrl3_enable_mask;

	if (pCFG->scrl1_enable_mask == pCFG->scrl2_enable_mask ||
			pCFG->scrl1_enable_mask == pCFG->scrl3_enable_mask ||
			pCFG->scrl2_enable_mask == pCFG->scrl3_enable_mask)
	{
		if (((layercontrol & enablemask) && (layercontrol & enablemask) != enablemask))
		{
			sprintf(baf,"layer %02x",layercontrol&0xc03f);
			usrintf_showmessage(baf);
		}
	}

	if (((layercontrol & ~enablemask) & 0xc03f) != 0)
	{
		sprintf(baf,"layer %02x",layercontrol&0xc03f);
		usrintf_showmessage(baf);
	}
}
#endif
}


int cps1_gfxram_r(int offset)
{
   return READ_WORD(&cps1_gfxram[offset]);
}

void cps1_gfxram_w(int offset, int data)
{
	COMBINE_WORD_MEM(&cps1_gfxram[offset],data);
}



/***************************************************************************

⌨️ 快捷键说明

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