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

📄 tmnt.c

📁 这个是延伸mame的在wince平台下的游戏模拟器的代码
💻 C
📖 第 1 页 / 共 2 页
字号:

						/* pick the correct entry in the PROM (top 8 bits of the code) */
						entry = (c & 0x3fc00) >> 10;

						/* the bits to scramble are the low 9 ones */
						for (i = 0;i < 9;i++)
							bits[i] = (c >> i) & 0x01;

						/* rearrange the bits basing on the table */
						for (i = 0;i < 9;i++)
							newbits[i] = bits[bit_pick_table[i][code_conv_table[entry]]];

						/* build the converted sprite line address */
						c &= 0xffe00;
						for (i = 0;i < 9;i++)
							c |= newbits[i] << i;

						/* and finally draw this line */
						drawgfx(bitmap,Machine->gfx[1 + ((c & 0x3c000) >> 14)],
								c & 0x03fff,
								col,
								flipx,flipy,
								sx + 16 * x * (flipx ? -1 : 1),sy + (16 * y + subcount) * (flipy ? -1 : 1),
								&Machine->drv->visible_area,TRANSPARENCY_PEN,0);
					}
				}
			}
		}
	}
}


static void punkshot_drawsprites(struct osd_bitmap *bitmap,int pri)
{
	int offs;
	int pri_code;


	for (pri_code = 0x8000;pri_code < 0x10000;pri_code += 0x100)
	{
		for (offs = spriteram_size - 8;offs >= 0;offs -= 8)
		{
			int sx,sy,col,code,size,w,h,x,y,flipx,flipy;
			/* sprites can be grouped up to 8x8. The draw order is
				 0  1  4  5 16 17 20 21
				 2  3  6  7 18 19 22 23
				 8  9 12 13 24 25 28 29
				10 11 14 15 26 27 30 31
				32 33 36 37 48 49 52 53
				34 35 38 39 50 51 54 55
				40 41 44 45 56 57 60 61
				42 43 46 47 58 59 62 63
			*/
			static int xoffset[8] = { 0, 1, 4, 5, 16, 17, 20, 21 };
			static int yoffset[8] = { 0, 2, 8, 10, 32, 34, 40, 42 };
			static int width[8] =  { 1, 2, 1, 2, 4, 2, 4, 8 };
			static int height[8] = { 1, 1, 2, 2, 2, 4, 4, 8 };


			if ((READ_WORD(&spriteram[offs]) & 0xff00) != pri_code) continue;

			if (pri == 0)
			{
				if ((READ_WORD(&spriteram[offs+2]) & 0x20) == 0)
					continue;
			}
			else if (pri == 1)
			{
				if ((READ_WORD(&spriteram[offs+2]) & 0x20) != 0)
					continue;
			}

			size = (READ_WORD(&spriteram[offs]) & 0xe0) >> 5;
			w = width[size];
			h = height[size];

			code = (READ_WORD(&spriteram[offs+2]) >> 8) +
					((READ_WORD(&spriteram[offs]) & 0x1f) << 8) +
					(((READ_WORD(&spriteram[offs+2]) & 0x10) >> 4) << 13);

			/* I'm not sure the following is correct, but some sort of alignment */
			/* is certainly needed to fix the score table. */
			if (w == 2) code &= ~1;
			if (w == 4) code &= ~7;
			if (w == 8) code &= ~31;

			col = sprite_colorbase + (READ_WORD(&spriteram[offs+2]) & 0x0f);

			sx = READ_WORD(&spriteram[offs+6]) & 0x01ff;
			sy = 256 - (READ_WORD(&spriteram[offs+4]) & 0x01ff);
			flipx = READ_WORD(&spriteram[offs+6]) & 0x0200;
			flipy = READ_WORD(&spriteram[offs+4]) & 0x0200;

			if (flipx) sx += 16 * (w - 1);
			if (flipy) sy += 16 * (h - 1);

			for (y = 0;y < h;y++)
			{
				for (x = 0;x < w;x++)
				{
					drawgfx(bitmap,Machine->gfx[1],
							code + xoffset[x] + yoffset[y],
							col,
							flipx,flipy,
							sx + 16 * x * (flipx ? -1 : 1),sy + 16 * y * (flipy ? -1 : 1),
							&Machine->drv->visible_area,TRANSPARENCY_PEN,0);
				}
			}
		}
	}
}


void tmnt_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
	int offs,i;


	/* palette remapping first */
	{
		unsigned short palette_map[64];
		int tile,code,color;

		memset (palette_map, 0, sizeof (palette_map));

		/* foreground */
		for (offs = 0x3000 - 2;offs >= 0x2000;offs -= 2)
		{
			tile = READ_WORD(&punkshot_vidram[offs]);
			color = fg_colorbase + ((tile & 0xe000) >> 13);
			code = (tile & 0x03ff) + ((tile & 0x1000) >> 2) +
					0x800 * charrombank[(tile & 0x0c00) >> 10];
			palette_map[color] |= Machine->gfx[0]->pen_usage[code];
		}

		/* background */
		for (offs = 0x5000 - 2;offs >= 0x4000;offs -= 2)
		{
			tile = READ_WORD(&punkshot_vidram[offs]);
			color = bg_colorbase + ((tile & 0xe000) >> 13);
			code = (tile & 0x03ff) + ((tile & 0x1000) >> 2) +
					0x800 * charrombank[(tile & 0x0c00) >> 10];
			palette_map[color] |= Machine->gfx[0]->pen_usage[code];
		}

		/* characters */
		for (offs = 0x1000 - 2;offs >= 0;offs -= 2)
		{
			tile = READ_WORD(&punkshot_vidram[offs]);
			color = text_colorbase + ((tile & 0xe000) >> 13);
			code = (tile & 0x03ff) + ((tile & 0x1000) >> 2) +
					0x800 * charrombank[(tile & 0x0c00) >> 10];
			palette_map[color] |= Machine->gfx[0]->pen_usage[code];
		}

		/* sprites */
		for (offs = spriteram_size - 8;offs >= 0;offs -= 8)
		{
			color = sprite_colorbase + (READ_WORD(&spriteram[offs+2]) & 0x0f);
			palette_map[color] |= 0xffff;
		}

		/* now build the final table */
		for (i = 0; i < 64; i++)
		{
			int usage = palette_map[i], j;
			if (usage)
			{
				palette_used_colors[i * 16 + 0] = PALETTE_COLOR_TRANSPARENT;
				for (j = 1; j < 16; j++)
					if (usage & (1 << j))
						palette_used_colors[i * 16 + j] = PALETTE_COLOR_USED;
					else
						palette_used_colors[i * 16 + j] = PALETTE_COLOR_UNUSED;
			}
			else
				memset (&palette_used_colors[i * 16 + 0], PALETTE_COLOR_UNUSED, 16);
		}

		/* recalc */
		if (palette_recalc ())
			memset(dirtybuffer,1,punkshot_vidram_size / 2);
	}


	/* for every character in the Video RAM, check if it has been modified */
	/* since last time and update it accordingly. */
	for (offs = 0x3000 - 2;offs >= 0x2000;offs -= 2)
	{
		int sx,sy,tile,code,color;

		if (dirtybuffer[offs / 2])
		{
			tile = READ_WORD(&punkshot_vidram[offs]);
			color = fg_colorbase + ((tile & 0xe000) >> 13);

			dirtybuffer[offs / 2] = 0;

			sx = (offs/2) % 64;
			sy = (offs/2) / 64 - 64;

			code = (tile & 0x03ff) + ((tile & 0x1000) >> 2) +
					0x800 * charrombank[(tile & 0x0c00) >> 10];

			drawgfx(tmpbitmap,Machine->gfx[0],
					code,
					color,
					0,0,
					8*sx,8*sy,
					0,TRANSPARENCY_NONE,0);
		}
	}

	for (offs = 0x5000 - 2;offs >= 0x4000;offs -= 2)
	{
		int sx,sy,tile,code,color;

		if (dirtybuffer[offs / 2])
		{
			tile = READ_WORD(&punkshot_vidram[offs]);
			color = bg_colorbase + ((tile & 0xe000) >> 13);

			dirtybuffer[offs / 2] = 0;

			sx = (offs/2) % 64;
			sy = (offs/2) / 64 - 128;

			code = (tile & 0x03ff) + ((tile & 0x1000) >> 2) +
					0x800 * charrombank[(tile & 0x0c00) >> 10];

			drawgfx(tmpbitmap1,Machine->gfx[0],
					code,
					color,
					0,0,
					8*sx,8*sy,
					0,TRANSPARENCY_NONE,0);
		}
	}


	/* copy the temporary bitmap to the screen */
	{
		int xscroll,yscroll;


		yscroll = -(READ_WORD(punkshot_yscroll) & 0xff);
		xscroll = -((READ_WORD(&punkshot_scrollram[0]) & 0xff) + 256 * (READ_WORD(&punkshot_scrollram[2]) & 0xff));
		xscroll += 6;
		copyscrollbitmap(bitmap,tmpbitmap1,1,&xscroll,1,&yscroll,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
	}


	/* draw the sprites if they don't have priosity over the foreground */
	if ((priority & 1) == 1) tmnt_drawsprites(bitmap);


	/* draw the foreground */
	{
		int xscroll,yscroll;


		xscroll = -((READ_WORD(&punkshot_scrollram[0]) >> 8) + 256 * (READ_WORD(&punkshot_scrollram[2]) >> 8));
		xscroll += 6;
		yscroll = -(READ_WORD(punkshot_yscroll) >> 8);
		copyscrollbitmap(bitmap,tmpbitmap,1,&xscroll,1,&yscroll,&Machine->drv->visible_area,TRANSPARENCY_PEN,palette_transparent_pen);
	}


	/* draw the sprites if they have priosity over the foreground */
	if ((priority & 1) == 0) tmnt_drawsprites(bitmap);


	/* draw the foreground characters */
	for (offs = 0x1000 - 2;offs >= 0;offs -= 2)
	{
		int sx,sy,tile,code,color;


		sx = (offs/2) % 64;
		sy = (offs/2) / 64;
		tile = READ_WORD(&punkshot_vidram[offs]);
		color = text_colorbase + ((tile & 0xe000) >> 13);

		code = (tile & 0x03ff) + ((tile & 0x1000) >> 2) +
				0x800 * charrombank[(tile & 0x0c00) >> 10];

		drawgfx(bitmap,Machine->gfx[0],
				code,
				color,
				0,0,
				8*sx,8*sy,
				&Machine->drv->visible_area,TRANSPARENCY_PEN,0);
	}
}

void punkshot_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
	int offs,i;


	/* palette remapping first */
	{
		unsigned short palette_map[128];
		int tile,code,color;

		memset (palette_map, 0, sizeof (palette_map));

		/* foreground */
		for (offs = 0x3000 - 2;offs >= 0x2000;offs -= 2)
		{
			tile = READ_WORD(&punkshot_vidram[offs]);
			color = fg_colorbase + ((tile & 0xe000) >> 13);
			code = (tile & 0x03ff) + ((tile & 0x1000) >> 2) +
					0x800 * charrombank[(tile & 0x0c00) >> 10];
			palette_map[color] |= Machine->gfx[0]->pen_usage[code];
		}

		/* background */
		for (offs = 0x5000 - 2;offs >= 0x4000;offs -= 2)
		{
			tile = READ_WORD(&punkshot_vidram[offs]);
			color = bg_colorbase + ((tile & 0xe000) >> 13);
			code = (tile & 0x03ff) + ((tile & 0x1000) >> 2) +
					0x800 * charrombank[(tile & 0x0c00) >> 10];
			palette_map[color] |= Machine->gfx[0]->pen_usage[code];
		}

		/* characters */
		for (offs = 0x1000 - 2;offs >= 0;offs -= 2)
		{
			tile = READ_WORD(&punkshot_vidram[offs]);
			color = text_colorbase + ((tile & 0xe000) >> 13);
			code = (tile & 0x03ff) + ((tile & 0x1000) >> 2) +
					0x800 * charrombank[(tile & 0x0c00) >> 10];
			palette_map[color] |= Machine->gfx[0]->pen_usage[code];
		}

		/* sprites */
		for (offs = spriteram_size - 8;offs >= 0;offs -= 8)
		{
			color = sprite_colorbase + (READ_WORD(&spriteram[offs+2]) & 0x0f);
			palette_map[color] |= 0xffff;
		}

		/* now build the final table */
		for (i = 0; i < 128; i++)
		{
			int usage = palette_map[i], j;
			if (usage)
			{
				palette_used_colors[i * 16 + 0] = PALETTE_COLOR_TRANSPARENT;
				for (j = 1; j < 16; j++)
					if (usage & (1 << j))
						palette_used_colors[i * 16 + j] = PALETTE_COLOR_USED;
					else
						palette_used_colors[i * 16 + j] = PALETTE_COLOR_UNUSED;
			}
			else
				memset (&palette_used_colors[i * 16 + 0], PALETTE_COLOR_UNUSED, 16);
		}

		/* recalc */
		if (palette_recalc ())
			memset(dirtybuffer,1,punkshot_vidram_size / 2);
	}


	/* for every character in the Video RAM, check if it has been modified */
	/* since last time and update it accordingly. */
	for (offs = 0x3000 - 2;offs >= 0x2000;offs -= 2)
	{
		int sx,sy,tile,code,color;


		tile = READ_WORD(&punkshot_vidram[offs]);
		color = fg_colorbase + ((tile & 0xe000) >> 13);

		if (dirtybuffer[offs / 2])
		{
			dirtybuffer[offs / 2] = 0;

			sx = (offs/2) % 64;
			sy = (offs/2) / 64 - 64;

			code = (tile & 0x03ff) + ((tile & 0x1000) >> 2) +
					0x800 * charrombank[(tile & 0x0c00) >> 10];

			drawgfx(tmpbitmap,Machine->gfx[0],
					code,
					color,
					0,0,
					8*sx,8*sy,
					0,TRANSPARENCY_NONE,0);
		}
	}

	for (offs = 0x5000 - 2;offs >= 0x4000;offs -= 2)
	{
		int sx,sy,tile,code,color;


		tile = READ_WORD(&punkshot_vidram[offs]);
		color = bg_colorbase + ((tile & 0xe000) >> 13);

		if (dirtybuffer[offs / 2])
		{
			dirtybuffer[offs / 2] = 0;

			sx = (offs/2) % 64;
			sy = (offs/2) / 64 - 128;

			code = (tile & 0x03ff) + ((tile & 0x1000) >> 2) +
					0x800 * charrombank[(tile & 0x0c00) >> 10];

			drawgfx(tmpbitmap1,Machine->gfx[0],
					code,
					color,
					0,0,
					8*sx,8*sy,
					0,TRANSPARENCY_NONE,0);
		}
	}


	/* copy the temporary bitmap to the screen */

	if (priority == 0x3c)
	{
		int xscroll,yscroll;


		xscroll = -((READ_WORD(&punkshot_scrollram[0]) >> 8) + 256 * (READ_WORD(&punkshot_scrollram[2]) >> 8));
		xscroll += 6;
		yscroll = -(READ_WORD(punkshot_yscroll) >> 8);
		copyscrollbitmap(bitmap,tmpbitmap,1,&xscroll,1,&yscroll,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
	}


	{
		int xscroll[256],yscroll;


		yscroll = -(READ_WORD(punkshot_yscroll) & 0xff);
		for (offs = 0;offs < 256;offs++)
		{
			xscroll[(offs - yscroll) & 0xff] = -((READ_WORD(&punkshot_scrollram[4*offs]) & 0xff) + 256 * (READ_WORD(&punkshot_scrollram[4*offs+2]) & 0xff));
			xscroll[(offs - yscroll) & 0xff] += 6;
		}
		if (priority == 0x3c)
			copyscrollbitmap(bitmap,tmpbitmap1,256,xscroll,1,&yscroll,&Machine->drv->visible_area,TRANSPARENCY_PEN,palette_transparent_pen);
		else
			copyscrollbitmap(bitmap,tmpbitmap1,256,xscroll,1,&yscroll,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
	}

	if (priority == 0x26) punkshot_drawsprites(bitmap,0);

	if (priority != 0x3c)
	{
		int xscroll,yscroll;


		xscroll = -((READ_WORD(&punkshot_scrollram[0]) >> 8) + 256 * (READ_WORD(&punkshot_scrollram[2]) >> 8));
		xscroll += 6;
		yscroll = -(READ_WORD(punkshot_yscroll) >> 8);
		copyscrollbitmap(bitmap,tmpbitmap,1,&xscroll,1,&yscroll,&Machine->drv->visible_area,TRANSPARENCY_PEN,palette_transparent_pen);
	}


	if (priority != 0x26) punkshot_drawsprites(bitmap,0);


	/* draw the foreground characters */
	for (offs = 0x1000 - 2;offs >= 0;offs -= 2)
	{
		int sx,sy,tile,code,color;


		sx = (offs/2) % 64;
		sy = (offs/2) / 64;
		tile = READ_WORD(&punkshot_vidram[offs]);
		color = text_colorbase + ((tile & 0xe000) >> 13);

		code = (tile & 0x03ff) + ((tile & 0x1000) >> 2) +
				0x800 * charrombank[(tile & 0x0c00) >> 10];

		drawgfx(bitmap,Machine->gfx[0],
				code,
				color,
				0,0,
				8*sx,8*sy,
				&Machine->drv->visible_area,TRANSPARENCY_PEN,0);
	}

	punkshot_drawsprites(bitmap,1);
}

⌨️ 快捷键说明

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