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

📄 avgdvg.c

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

				vector_add_point (currentx, currenty, colorram[color], z);

				break;

			case STAT:
				if (vectorEngine == USE_AVG_SWARS)
				{
					/* color code 0-7 stored in top 3 bits of `color' */
					color=(char)((firstwd & 0x0700)>>8);
					statz = (firstwd) & 0xff;
				}
				else
				{
					color = (firstwd) & 0x000f;
					statz = (firstwd >> 4) & 0x000f;
					if (vectorEngine == USE_AVG_TEMPEST)
								sparkle = !(firstwd & 0x0800);
					if (vectorEngine == USE_AVG_MHAVOC)
					{
						sparkle = (firstwd & 0x0800);
						xflip = firstwd & 0x0400;
						/* Bank switch the vector ROM for Major Havoc */
						vectorbank[1] = &Machine->memory_region[0][0x18000 + ((firstwd & 0x300) >> 8) * 0x2000];
					}
					if (vectorEngine == USE_AVG_BZONE)
					{
						bz_col = color;
						if (color == 0)
						{
							BZONE_CLIP;
							color = 2;
						}
						else
						{
							BZONE_NOCLIP;
						}
					}
				}

				break;

			case SCAL:
				b = ((firstwd >> 8) & 0x07)+8;
				l = (~firstwd) & 0xff;
				scale = (l << VEC_SHIFT) >> b;		/* ASG 080497 */

				/* Y-Window toggle for Major Havoc BW 980318 */
				if (vectorEngine == USE_AVG_MHAVOC)
				{
					if (firstwd & 0x0800)
					{
						if (ywindow == 0)
						{
							ywindow = 1;
							MHAVOC_CLIP;
						}
						else
						{
							ywindow = 0;
							MHAVOC_NOCLIP;
						}
					}
				}
				break;

			case CNTR:
				d = firstwd & 0xff;
				currentx = xcenter ;  /* ASG 080497 */ /*.ac JAN2498 */
				currenty = ycenter ;  /* ASG 080497 */ /*.ac JAN2498 */
				vector_add_point (currentx, currenty, 0, 0);
				break;

			case RTSL:
				if (sp == 0)
				{
					done = 1;
					sp = MAXSTACK - 1;
				}
				else
					sp--;

				pc = stack [sp];
				break;

			case HALT:
				done = 1;
				break;

			case JMPL:
				a = firstwd & 0x1fff;
				/* if a = 0x0000, treat as HALT */
				if (a == 0x0000)
					done = 1;
				else
					pc = a;
				break;

			case JSRL:
				a = firstwd & 0x1fff;
				/* if a = 0x0000, treat as HALT */
				if (a == 0x0000)
					done = 1;
				else
				{
					stack [sp] = pc;
					if (sp == (MAXSTACK - 1))
					{
						done = 1;
						sp = 0;
					}
					else
						sp++;

					pc = a;
				}
				break;

			default:
				break;
		}
	}
}


int avgdvg_done (void)
{
	if (busy)
		return 0;
	else
		return 1;
}

static void avgdvg_clr_busy (int dummy)
{
	busy = 0;
}

void avgdvg_go (int offset, int data)
{

	if (busy)
		return;

	vector_updates++;
	total_length = 1;
	busy = 1;

	if (vectorEngine == USE_DVG)
	{
		dvg_generate_vector_list();
		timer_set (TIME_IN_NSEC(4500) * total_length, 1, avgdvg_clr_busy);
	}
	else
	{
		avg_generate_vector_list();
		if (total_length > 1)
			timer_set (TIME_IN_NSEC(1500) * total_length, 1, avgdvg_clr_busy);
		/* this is for Major Havoc */
		else
		{
			vector_updates--;
			busy = 0;
		}
	}
}

void avgdvg_reset (int offset, int data)
{
	avgdvg_clr_busy (0);
}

int avgdvg_init (int vgType)
{
	int i;

	if (vectorram_size == 0)
	{
		return 1;
	}

	/* ASG 971210 -- initialize the pages */
	for (i = 0; i < NUM_BANKS; i++)
		vectorbank[i] = vectorram + (i<<BANK_BITS);
	if (vgType == USE_AVG_MHAVOC)
		vectorbank[1] = &Machine->memory_region[0][0x18000];

	vectorEngine = vgType;
	if ((vectorEngine<AVGDVG_MIN) || (vectorEngine>AVGDVG_MAX))
	{
		return 1;
	}

	if (vectorEngine==USE_AVG_SWARS)
		flipword=1;
#ifndef LSB_FIRST
	else if (vectorEngine==USE_AVG_QUANTUM)
		flipword=1;
#endif
	else
		flipword=0;

	vg_step = 0;

	busy = 0;

	xmin=Machine->drv->visible_area.min_x;
	ymin=Machine->drv->visible_area.min_y;
	xmax=Machine->drv->visible_area.max_x;
	ymax=Machine->drv->visible_area.max_y;
	width=xmax-xmin;
	height=ymax-ymin;

	xcenter=((xmax+xmin)/2) << VEC_SHIFT; /*.ac JAN2498 */
	ycenter=((ymax+ymin)/2) << VEC_SHIFT; /*.ac JAN2498 */

	vector_set_shift (VEC_SHIFT);

	if (vector_vh_start())
		return 1;

	return 0;
}

/*
 * These functions initialise the colors for all atari games.
 */

#define RED   0x04
#define GREEN 0x02
#define BLUE  0x01
#define WHITE RED|GREEN|BLUE

static void shade_fill (unsigned char *palette, int rgb, int start_index, int end_index, int start_inten, int end_inten)
{
	int i, inten, index_range, inten_range;

	index_range = end_index-start_index;
	inten_range = end_inten-start_inten;
	for (i = start_index; i <= end_index; i++)
	{
		inten = start_inten + (inten_range) * (i-start_index) / (index_range);
		palette[3*i  ] = (rgb & RED  )? inten : 0;
		palette[3*i+1] = (rgb & GREEN)? inten : 0;
		palette[3*i+2] = (rgb & BLUE )? inten : 0;
	}
}


void avg_init_colors (unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
	int i,j,k;

	int trcl1[] = { 0,0,2,2,1,1 };
	int trcl2[] = { 1,2,0,1,0,2 };
	int trcl3[] = { 2,1,1,0,2,0 };

	/* initialize the first 8 colors with the basic colors */
	/* Only these are selected by writes to the colorram. */
	for (i = 0; i < 8; i++)
	{
		palette[3*i  ] = (i & RED  ) ? 0xff : 0;
		palette[3*i+1] = (i & GREEN) ? 0xff : 0;
		palette[3*i+2] = (i & BLUE ) ? 0xff : 0;
	}

	/* initialize the colorram */
	for (i = 0; i < 16; i++)
		colorram[i] = i & 0x07;

	/* fill the rest of the 256 color entries depending on the game */
	switch (color_prom[0])
	{
		/* Black and White vector colors (Asteroids,Omega Race) .ac JAN2498 */
		case  VEC_PAL_BW:
			shade_fill (palette, RED|GREEN|BLUE, 8, 128+8, 0, 255);
			colorram[1] = 7; /* BW games use only color 1 (== white) */
			break;

		/* Monochrome Aqua colors (Asteroids Deluxe,Red Baron) .ac JAN2498 */
		case  VEC_PAL_MONO_AQUA:
			/* Use overlay if present MLR OCT0598 */
			/*if ((backdrop=artwork_load("astdelux.png", 32, Machine->drv->total_colors-32))!=NULL)
			{
				shade_fill (palette, GREEN|BLUE, 8, 23, 1, 254);
				// Some more anti-aliasing colors.
				shade_fill (palette, GREEN|BLUE, 24, 31, 1, 254);
				for (i=0; i<8; i++)
					palette[(24+i)*3]=80;
				memcpy (palette+3*backdrop->start_pen, backdrop->orig_palette,
					3*backdrop->num_pens_used);
			}
			else*/
				shade_fill (palette, GREEN|BLUE, 8, 128+8, 1, 254);
			colorram[1] =  3; /* for Asteroids */
			colorram[0] =  3; /* for Red Baron */
			break;

		/* Monochrome Green/Red vector colors (Battlezone) .ac JAN2498 */
		case  VEC_PAL_BZONE:
			/* Use overlay if present MLR OCT0598 */
			/*if ((backdrop=artwork_load("bzone_b.png", 8, Machine->drv->total_colors-8))!=NULL)
			{
				memcpy (palette+3*backdrop->start_pen, backdrop->orig_palette,
					3*backdrop->num_pens_used);
				if ((overlay = artwork_load("bzone.png",
							     8+backdrop->num_pens_used,
							     Machine->drv->total_colors -
							    (8+backdrop->num_pens_used)))!=NULL)
				{
					overlay_set_palette (overlay, palette, Machine->drv->total_colors
							     -9-backdrop->num_pens_used);
					colorram[2] = 7;
					colorram[4] = 7;
				}
			}
			else
			{*/
				/*if (backdrop)
					artwork_free(backdrop);
				backdrop = NULL;
				overlay = NULL;*/
				shade_fill (palette, RED  ,     8, 128+4, 1, 254);
				shade_fill (palette, GREEN, 128+5, 254  , 1, 254);
			/*}*/
			break;

		/* Colored games (Major Havoc, Star Wars, Tempest) .ac JAN2498 */
		case  VEC_PAL_COLOR:
		case  VEC_PAL_SWARS:
			/* put in 40 shades for red, blue and magenta */
			shade_fill (palette, RED       ,   8,  47, 10, 250);
			shade_fill (palette, BLUE      ,  48,  87, 10, 250);
			shade_fill (palette, RED|BLUE  ,  88, 127, 10, 250);

			/* put in 20 shades for yellow and green */
			shade_fill (palette, GREEN     , 128, 147, 10, 250);
			shade_fill (palette, RED|GREEN , 148, 167, 10, 250);

			/* and 14 shades for cyan and white */
			shade_fill (palette, BLUE|GREEN, 168, 181, 10, 250);
			shade_fill (palette, WHITE     , 182, 194, 10, 250);

			/* Fill in unused gaps with more anti-aliasing colors. */
			/* There are 60 slots available.           .ac JAN2498 */
			i=195;
			for (j=0; j<6; j++)
			{
				for (k=7; k<=16; k++)
				{
					palette[3*i+trcl1[j]] = ((256*k)/16)-1;
					palette[3*i+trcl2[j]] = ((128*k)/16)-1;
					palette[3*i+trcl3[j]] = 0;
					i++;
				}
			}
			break;
	}
}

/* If you want to use the next two functions, please make sure that you have
 * a fake GfxLayout, otherwise you'll crash */
static void colorram_w (int offset, int data)
{
	colorram[offset & 0x0f] = data & 0x0f;
}

/*
 * Tempest, Major Havoc and Quantum select colors via a 16 byte colorram.
 * What's more, they have a different ordering of the rgbi bits than the other
 * color avg games.
 * We need translation tables.
 */

void tempest_colorram_w (int offset, int data)
{
#if 0 /* with low intensity bit */
	int trans[]= { 7, 15, 3, 11, 6, 14, 2, 10, 5, 13, 1,  9, 4, 12, 0,  8 };
#else /* high intensity */
	int trans[]= { 7,  7, 3,  3, 6,  6, 2,  2, 5,  5, 1,  1, 4,  4, 0,  0 };
#endif
	colorram_w (offset, trans[data & 0x0f]);
}

void mhavoc_colorram_w (int offset, int data)
{
#if 0 /* with low intensity bit */
	int trans[]= { 7, 6, 5, 4, 15, 14, 13, 12, 3, 2, 1, 0, 11, 10, 9, 8 };
#else /* high intensity */
	int trans[]= { 7, 6, 5, 4,  7,  6,  5,  4, 3, 2, 1, 0,  3,  2, 1, 0 };
#endif
	colorram_w (offset , trans[data & 0x0f]);
}


void quantum_colorram_w (int offset, int data)
{
/* Notes on colors:
offset:				color:			color (game):
0 - score, some text		0 - black?
1 - nothing?			1 - blue
2 - nothing?			2 - green
3 - Quantum, streaks		3 - cyan
4 - text/part 1 player		4 - red
5 - part 2 of player		5 - purple
6 - nothing?			6 - yellow
7 - part 3 of player		7 - white
8 - stars			8 - black
9 - nothing?			9 - blue
10 - nothing?			10 - green
11 - some text, 1up, like 3	11 - cyan
12 - some text, like 4
13 - nothing?			13 - purple
14 - nothing?
15 - nothing?

1up should be blue
score should be red
high score - white? yellow?
level # - green
*/

	int trans[]= { 7/*white*/, 0, 3, 1/*blue*/, 2/*green*/, 5, 6, 4/*red*/,
		       7/*white*/, 0, 3, 1/*blue*/, 2/*green*/, 5, 6, 4/*red*/};

	colorram_w (offset >> 1, trans[data & 0x0f]);
}

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

  Draw the game screen in the given osd_bitmap.
  Do NOT call osd_update_display() from this function, it will be called by
  the main emulation engine.

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

void avg_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
	/*if (overlay && backdrop)
		vector_vh_update_artwork(bitmap, overlay, backdrop, full_refresh);
	else if (backdrop)
		vector_vh_update_backdrop(bitmap, backdrop, full_refresh);
	else*/
		vector_vh_update(bitmap,full_refresh);
}

void dvg_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
	/*if (backdrop)
		vector_vh_update_backdrop(bitmap, backdrop, full_refresh);
	else*/
		vector_vh_update(bitmap,full_refresh);
}

int dvg_start(void)
{
	/*if (backdrop)
		backdrop_refresh(backdrop);*/

	return avgdvg_init (USE_DVG);
}

int avg_start(void)
{
	return avgdvg_init (USE_AVG);
}

int avg_start_starwars(void)
{
	return avgdvg_init (USE_AVG_SWARS);
}

int avg_start_tempest(void)
{
	return avgdvg_init (USE_AVG_TEMPEST);
}

int avg_start_mhavoc(void)
{
	return avgdvg_init (USE_AVG_MHAVOC);
}

int avg_start_bzone(void)
{
	/*if (backdrop)
		backdrop_refresh(backdrop);*/

	/*if (overlay)
		overlay_remap(overlay);*/

	return avgdvg_init (USE_AVG_BZONE);
}

int avg_start_quantum(void)
{
	return avgdvg_init (USE_AVG_QUANTUM);
}

int avg_start_redbaron(void)
{
	return avgdvg_init (USE_AVG_RBARON);
}

void avg_stop(void)
{
	busy = 0;
	vector_clear_list();

	vector_vh_stop();

	/*if (backdrop) artwork_free(backdrop);
	backdrop = NULL;*/
	/*if (overlay) artwork_free(overlay);
	overlay = NULL;*/
}

void dvg_stop(void)
{
	busy = 0;
	vector_clear_list();

	vector_vh_stop();

	/*if (backdrop) artwork_free(backdrop);
	backdrop = NULL;*/
	/*if (overlay) artwork_free(overlay);
	overlay = NULL;*/
}

⌨️ 快捷键说明

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