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

📄 megasys1.c

📁 这个是延伸mame的在wince平台下的游戏模拟器的代码
💻 C
📖 第 1 页 / 共 5 页
字号:
unsigned char *RAM;
int i,size;

	RAM  = Machine->memory_region[Machine->drv->cpu[0].memory_region];
	size = Machine->memory_region_length[Machine->drv->cpu[0].memory_region];
	if (size > 0x40000)	size = 0x40000;

	for (i = 0 ; i < size ; i+=2)
	{
	int x,y;

		x = READ_WORD(&RAM[i]);
		y = 0;

		y |= (x & (1 << 0x4))?(1<<0x0):0;
		y |= (x & (1 << 0x1))?(1<<0x1):0;
		y |= (x & (1 << 0x8))?(1<<0x2):0;
		y |= (x & (1 << 0x3))?(1<<0x3):0;
		y |= (x & (1 << 0x2))?(1<<0x4):0;
		y |= (x & (1 << 0x7))?(1<<0x5):0;
		y |= (x & (1 << 0xc))?(1<<0x6):0;
		y |= (x & (1 << 0x5))?(1<<0x7):0;
		y |= (x & (1 << 0xf))?(1<<0x8):0;
		y |= (x & (1 << 0xb))?(1<<0x9):0;
		y |= (x & (1 << 0xe))?(1<<0xa):0;
		y |= (x & (1 << 0x6))?(1<<0xb):0;
		y |= (x & (1 << 0x9))?(1<<0xc):0;
		y |= (x & (1 << 0xa))?(1<<0xd):0;
		y |= (x & (1 << 0x0))?(1<<0xe):0;
		y |= (x & (1 << 0xd))?(1<<0xf):0;

		WRITE_WORD(&ROM[i],y);
	}

}





/*
**
**	Main cpu data
**
**
*/


/******************** System A ***********************/


void paletteram_RRRRGGGGBBBBRGBx_word_w(int offset, int data)
{
	/*	byte 0    byte 1	*/
	/*	RRRR GGGG BBBB RGB?	*/
	/*	4321 4321 4321 000?	*/

	int oldword = READ_WORD (&paletteram[offset]);
	int newword = COMBINE_WORD (oldword, data);

	int r = ((newword >> 8) & 0xF0 ) | ((newword << 0) & 0x08);
	int g = ((newword >> 4) & 0xF0 ) | ((newword << 1) & 0x08);
	int b = ((newword >> 0) & 0xF0 ) | ((newword << 2) & 0x08);

	palette_change_color( offset/2, r,g,b );

	WRITE_WORD (&paletteram[offset], newword);
}


#define interrupt_num_A		2
int interrupt_A(void)		{ if (cpu_getiloops()%2) return 1; else return 2; }
int sound_interrupt_A(void)	{return 4;} /* stdragon */

#define videoreg_sx(_n_) 	{scrollx[_n_] = -new_data;} break;
#define videoreg_sy(_n_) 	{scrolly[_n_] = -new_data;} break;
#define videoreg_flag(_n_)\
{\
	scrollflag[_n_] = new_data;\
	if (new_data != old_data)\
	{	if (scroll_bitmap[_n_])\
		{\
			osd_free_bitmap(scroll_bitmap[_n_]);\
			scroll_bitmap[_n_] = 0;\
			mark_dirty(_n_);\
/*			if (errorlog) fprintf(errorlog, "freeing scroll %d\n",_n_);*/ \
		}\
	}\
} break;


void videoregs_A_w(int offset, int data)
{
int old_data, new_data;

	old_data = READ_WORD(&videoregs[offset]);
	COMBINE_WORD_MEM(&videoregs[offset],data);
	new_data  = READ_WORD(&videoregs[offset]);

	switch (offset)
	{
		case 0x000   : {active_layers = new_data;} break;
		case 0x008+0 : videoreg_sx(2)
		case 0x008+2 : videoreg_sy(2)
		case 0x008+4 : videoreg_flag(2)
		case 0x200+0 : videoreg_sx(0)
		case 0x200+2 : videoreg_sy(0)
		case 0x200+4 : videoreg_flag(0)
		case 0x208+0 : videoreg_sx(1)
		case 0x208+2 : videoreg_sy(1)
		case 0x208+4 : videoreg_flag(1)
		case 0x100   : {spriteflag = new_data;} break;
		case 0x300   : {screenflag = new_data;} break;
		case 0x308   : {soundlatch_w(0,new_data);

/* the only game checking if the  sound cpu echoes the sound  command
   is Rodland. If the check fails,  the game is just slowed down.  So
   to allow diabling the sound cpu without the slow down, we echo the
   sound command here */
						soundlatch2_w(0,new_data);} break;

		default: break; /*{if (errorlog) fprintf(errorlog, "CPU #0 PC %06X : Warning, videoreg %04X <- %04X\n",cpu_get_pc(),offset,data);}*/
	}
}



#define scrollram_handler(_n_)\
void scrollram_##_n_##_w(int offset, int data)\
{\
int old_data;\
\
	old_data = READ_WORD(&scrollram[_n_][offset]);\
	COMBINE_WORD_MEM(&scrollram[_n_][offset],data);\
\
	if ( old_data != READ_WORD(&scrollram[_n_][offset]) )\
		scrollram_dirty[_n_][offset/2] = 1;\
}\

scrollram_handler(0)
scrollram_handler(1)
scrollram_handler(2)




int coins_r(int offset)   {return input_port_0_r(0);}	
int player1_r(int offset) {return input_port_1_r(0);}	
int player2_r(int offset) {return (input_port_2_r(0)<<8)+input_port_3_r(0);}	
int dipsw_r(int offset)	  {return (input_port_4_r(0)<<8)+input_port_5_r(0);}	




static struct MemoryReadAddress readmem_A[] =
{
	{ 0x000000, 0x07ffff, MRA_ROM }, /* P47 has half that */
	{ 0x0f0000, 0x0fffff, MRA_BANK2 },
	{ 0x080000, 0x080001, coins_r },
	{ 0x080002, 0x080003, player1_r },
	{ 0x080004, 0x080005, player2_r },
	{ 0x080006, 0x080007, dipsw_r },
	{ 0x080008, 0x080009, soundlatch2_r },	/* Echo from sound cpu */
	{ 0x084000, 0x084fff, MRA_BANK3 },		/* Video Regist. */
	{ 0x088000, 0x0887ff, paletteram_word_r },
	{ 0x08e000, 0x08ffff, MRA_BANK4 },		/* Object  RAM   */
	{ 0x090000, 0x093fff, MRA_BANK5 },		/* Scroll RAM 1  */
	{ 0x094000, 0x097fff, MRA_BANK6 },		/* Scroll RAM 2  */
	{ 0x098000, 0x09bfff, MRA_BANK7 },		/* Scroll RAM 3  */
	{ -1 }
};

static struct MemoryWriteAddress writemem_A[] =
{
 	{ 0x000000, 0x07ffff, MWA_ROM },
	{ 0x0f0000, 0x0fffff, MWA_BANK2, &ram },
	{ 0x084000, 0x0843ff, videoregs_A_w, &videoregs },
	{ 0x088000, 0x0887ff, paletteram_RRRRGGGGBBBBRGBx_word_w, &paletteram },
	{ 0x08e000, 0x08ffff, MWA_BANK4, &objectram },
	{ 0x090000, 0x093fff, scrollram_0_w, &scrollram[0] },
	{ 0x094000, 0x097fff, scrollram_1_w, &scrollram[1] },
	{ 0x098000, 0x09bfff, scrollram_2_w, &scrollram[2] },
	{ -1 }
};



/******************** System C ***********************/




#define interrupt_num_C 30
int interrupt_C(void)
{
#if 1
	if (cpu_getiloops()==0)	return 4; /* Once */
	else
	{
		if (cpu_getiloops()%2)	return 1;
		else 					return 2;
	}
#else
	if (cpu_getiloops()%2)	return 2;
	else 					return 4;
#endif

}

int sound_interrupt_C(void)	{return 4;}


void videoregs_C_w(int offset, int data)
{
int old_data, new_data;

	old_data = READ_WORD(&videoregs[offset]);
	COMBINE_WORD_MEM(&videoregs[offset],data);
	new_data  = READ_WORD(&videoregs[offset]);

	switch (offset)
	{
		case 0x2208   : {active_layers = new_data;} break;
		case 0x2100+0 : videoreg_sx(2)
		case 0x2100+2 : videoreg_sy(2)
		case 0x2100+4 : videoreg_flag(2)
		case 0x2000+0 : videoreg_sx(0)
		case 0x2000+2 : videoreg_sy(0)
		case 0x2000+4 : videoreg_flag(0)
		case 0x2008+0 : videoreg_sx(1)
		case 0x2008+2 : videoreg_sy(1)
		case 0x2008+4 : videoreg_flag(1)
		case 0x2108   : {spritebank = new_data;} break;
		case 0x2200   : {spriteflag = new_data;} break;
		case 0x2308   : {screenflag = new_data;} break;
		case 0x8000   : {soundlatch_w(0,new_data);} break;
		default: break; /*{if (errorlog) fprintf(errorlog, "CPU #0 PC %06X : Warning, videoreg %04X <- %04X\n",cpu_get_pc(),offset,data);}*/
	}
}




/* Read the input ports, through a protection device */
int ip_select_r(int offset)
{


	/* f(x) = ((x*x)>>4)&0xFF ; f(f($D)) == 6 */
	if ((ip_select & 0xF0) == 0xF0) return 0x0D;

	switch (ip_select & 0xFF)
	{
			case 0x20 :
			case 0x37 :
			case 0x57 :	return coins_r(0); break;

			case 0x21 :
			case 0x35 :
			case 0x53 : return player1_r(0); break;

			case 0x22 :
			case 0x36 :
			case 0x54 : return player2_r(0); break;

			case 0x23 :
			case 0x33 :
			case 0x55 : return ((dipsw_r(0)&0xFF00)>>8); break;

			case 0x24 :
			case 0x34 :
			case 0x56 : return ((dipsw_r(0)&0x00FF)>>0); break;

			default   : return 0x06;
	}
}

void ip_select_w(int offset,int data)
{
	ip_select = COMBINE_WORD(ip_select,data);

	cpu_cause_interrupt(0,3);	/* EDF needs it */
}





static struct MemoryReadAddress readmem_C[] =
{
	{ 0x000000, 0x07ffff, MRA_ROM },
	{ 0xff0000, 0xffffff, MRA_BANK2 },
	{ 0x080000, 0x080001, coins_r },
	{ 0x080002, 0x080003, player1_r },
	{ 0x080004, 0x080005, player2_r },
	{ 0x080006, 0x080007, dipsw_r },
	{ 0x0c0000, 0x0cffff, MRA_BANK3 },		/* Video Regist. */
	{ 0x0d2000, 0x0d3fff, MRA_BANK4 },		/* Object  RAM   */
	{ 0x0e0000, 0x0e3fff, MRA_BANK5 },		/* Scroll RAM 1  */
	{ 0x0e8000, 0x0ebfff, MRA_BANK6 },		/* Scroll RAM 2  */
	{ 0x0f0000, 0x0f3fff, MRA_BANK7 },		/* Scroll RAM 3  */
	{ 0x0f8000, 0x0f87ff, paletteram_word_r },
	{ 0x0d8000, 0x0d8001, ip_select_r },
	{ -1 }
};

static struct MemoryWriteAddress writemem_C[] =
{
 	{ 0x000000, 0x07ffff, MWA_ROM },
	{ 0xff0000, 0xffffff, MWA_BANK2, &ram },
	{ 0x0c0000, 0x0cffff, videoregs_C_w, &videoregs },
	{ 0x0d2000, 0x0d3fff, MWA_BANK4, &objectram },
	{ 0x0e0000, 0x0e3fff, scrollram_0_w, &scrollram[0] },
	{ 0x0e8000, 0x0ebfff, scrollram_1_w, &scrollram[1] },
	{ 0x0f0000, 0x0f3fff, scrollram_2_w, &scrollram[2] },
	{ 0x0f8000, 0x0f87ff, paletteram_RRRRGGGGBBBBRGBx_word_w, &paletteram },
	{ 0x0d8000, 0x0d8001, ip_select_w },
	{ -1 }
};


/******************** System B ***********************/


#define interrupt_num_B	interrupt_num_C
#define interrupt_B		interrupt_C


static struct MemoryReadAddress readmem_B[] =
{
	{ 0x000000, 0x03ffff, MRA_ROM },
	{ 0x080000, 0x0bffff, MRA_ROM },
	{ 0x060000, 0x07ffff, MRA_BANK2 },
	{ 0x044000, 0x044fff, MRA_BANK3 },		/* Video Regist. */
	{ 0x048000, 0x0487ff, paletteram_word_r },
	{ 0x04e000, 0x04ffff, MRA_BANK4 },		/* Object  RAM   */
	{ 0x050000, 0x053fff, MRA_BANK5 },		/* Scroll RAM 1  */
	{ 0x054000, 0x057fff, MRA_BANK6 },		/* Scroll RAM 2  */
	{ 0x058000, 0x05bfff, MRA_BANK7 },		/* Scroll RAM 3  */
	{ 0x0e0000, 0x0e0001, ip_select_r },
	{ -1 }
};

static struct MemoryWriteAddress writemem_B[] =
{
 	{ 0x000000, 0x03ffff, MWA_ROM },
	{ 0x080000, 0x0bffff, MWA_ROM },
	{ 0x060000, 0x07ffff, MWA_BANK2, &ram },
	{ 0x044000, 0x0443ff, videoregs_A_w, &videoregs },
	{ 0x048000, 0x0487ff, paletteram_RRRRGGGGBBBBRGBx_word_w, &paletteram },
	{ 0x04e000, 0x04ffff, MWA_BANK4, &objectram },
	{ 0x050000, 0x053fff, scrollram_0_w	, &scrollram[0] },
	{ 0x054000, 0x057fff, scrollram_1_w	, &scrollram[1] },
	{ 0x058000, 0x05bfff, scrollram_2_w, &scrollram[2] },
	{ 0x0e0000, 0x0e0001, ip_select_w },
	{ -1 }
};






/*
**
**	Sound cpu data
**
**
*/


/******************** System A ***********************/


static struct MemoryReadAddress sound_readmem_A[] =
{
	{ 0x000000, 0x01ffff, MRA_ROM },
	{ 0x040000, 0x040001, soundlatch_r },
	{ 0x080002, 0x080003, YM2151_status_port_0_r },
	{ 0x0a0000, 0x0a0001, OKIM6295_status_0_r },
	{ 0x0c0000, 0x0c0001, OKIM6295_status_1_r },
	{ 0x0e0000, 0x0fffff, MRA_BANK1 },
	{ -1 }
};

static struct MemoryWriteAddress sound_writemem_A[] =
{
	{ 0x000000, 0x01ffff, MWA_ROM },
	{ 0x060000, 0x060001, soundlatch2_w },	/* Echo to main cpu */
	{ 0x080000, 0x080001, YM2151_register_port_0_w },
	{ 0x080002, 0x080003, YM2151_data_port_0_w},
	{ 0x0a0000, 0x0a0003, OKIM6295_data_0_w },
	{ 0x0c0000, 0x0c0003, OKIM6295_data_1_w },
	{ 0x0e0000, 0x0fffff, MWA_BANK1 },
	{ -1 }
};





/******************** System B / C ***********************/





static struct MemoryReadAddress sound_readmem_C[] =
{
	{ 0x000000, 0x03ffff, MRA_ROM },		/* MS1-C has half that */
	{ 0x040000, 0x040001, soundlatch_r },	/* MS1-B */

⌨️ 快捷键说明

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