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

📄 cps1.c

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

  Capcom System 1
  ===============

  Driver provided by:
	Paul Leaman

  M680000 for game, Z80, YM-2151 and OKIM6295 for sound.

  68000 clock speeds are unknown for all games (except where commented)

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

#include "driver.h"
#include "vidhrdw/generic.h"

#include "cps1.h"       /* External CPS1 definitions */



int cps1_input2_r(int offset)
{
	  int buttons=readinputport(6);
	  return buttons << 8 | buttons;
}

static int cps1_sound_fade_timer;

void cps1_snd_bankswitch_w(int offset,int data)
{
	unsigned char *RAM = Machine->memory_region[Machine->drv->cpu[1].memory_region];

	cpu_setbank (1, &RAM[0x10000+(data&0x01)*0x4000]);
}

void cps1_sound_fade_w(int offset, int data)
{
	cps1_sound_fade_timer=data;
}

int cps1_snd_fade_timer_r(int offset)
{
	return cps1_sound_fade_timer;
}


/********************************************************************
*
*  Q Sound
*  =======
*
********************************************************************/

static unsigned char *cps1_qram;

int cps1_qram_kludge_r(int offset)
{
	int value=READ_WORD(&cps1_qram[0xffe]);
	if (value)
	{
	 return value;
	}
	return 0x77;
}

/********************************************************************
*
*  EEPROM
*  ======
*
*   The EEPROM appears to be accessed by a serial protocol using
*   the register 0xf1c006
*
********************************************************************/

static unsigned char cps1_eeprom[0x40];
static unsigned int  cps1_eeprom_register;
static unsigned int  cps1_eeprom_index;
static unsigned int  cps1_eeprom_shift;

int cps1_eeprom_port_r(int offset)
{
	int value;
	value=cps1_eeprom[cps1_eeprom_index];
	return (cps1_eeprom_register&0xfe) | 0x01;
}

void cps1_eeprom_port_w(int offset, int data)
{
	cps1_eeprom_register=data;
}

static void cps1_eeprom_save (void)
{
	void *f;

	f = osd_fopen (Machine->gamedrv->name, 0, OSD_FILETYPE_HIGHSCORE, 1);
	if (f)
	{
		osd_fwrite (f, cps1_eeprom, sizeof(cps1_eeprom));
		osd_fclose (f);
	}
}

static int cps1_eeprom_load (void)
{
	void *f;

	f = osd_fopen (Machine->gamedrv->name, 0, OSD_FILETYPE_HIGHSCORE, 0);
	if (f)
	{
		osd_fread (f, cps1_eeprom, sizeof(cps1_eeprom));
		osd_fclose (f);
	}
	else
	{
		memset(cps1_eeprom, 0, sizeof(cps1_eeprom));
	}

	return 1;
}



static struct MemoryReadAddress cps1_readmem[] =
{
	{ 0x000000, 0x1fffff, MRA_ROM },     /* 68000 ROM */
	{ 0x800000, 0x800003, cps1_player_input_r }, /* Player input ports */
	{ 0x800010, 0x800013, cps1_player_input_r }, /* ?? */
	{ 0x800018, 0x80001f, cps1_input_r }, /* Input ports */
	{ 0x800020, 0x800021, MRA_NOP }, /* ? Used by Rockman ? */
	{ 0x800176, 0x800177, cps1_input2_r }, /* Extra input ports */
	{ 0x8001fc, 0x8001fc, cps1_input2_r }, /* Input ports (SF Rev E) */
	{ 0x800100, 0x8001ff, cps1_output_r },   /* Output ports */
	{ 0x900000, 0x92ffff, cps1_gfxram_r },
	{ 0xf19ffe, 0xf19fff, cps1_qram_kludge_r },       /* Q RAM Kludge */
	{ 0xf18000, 0xf19fff, MRA_BANK6 },       /* Q RAM */
	{ 0xf1c000, 0xf1c005, MRA_NOP }, /* Unknown */
	{ 0xf1c006, 0xf1c007, cps1_eeprom_port_r },
	{ 0xff0000, 0xffffff, MRA_BANK2 },   /* RAM */
	{ -1 }  /* end of table */
};

static struct MemoryWriteAddress cps1_writemem[] =
{
	{ 0x000000, 0x1fffff, MWA_ROM },      /* ROM */
	{ 0x800030, 0x800033, MWA_NOP },      /* ??? Unknown ??? */
	{ 0x800180, 0x800181, soundlatch_w },  /* Sound command */
	{ 0x800188, 0x80018b, cps1_sound_fade_w },
	{ 0x800100, 0x8001ff, cps1_output_w, &cps1_output, &cps1_output_size },  /* Output ports */
	{ 0x900000, 0x92ffff, cps1_gfxram_w, &cps1_gfxram, &cps1_gfxram_size },
	{ 0xf18000, 0xf19fff, MWA_BANK6, &cps1_qram }, /* Q RAM */
	{ 0xf1c004, 0xf1c005, MWA_NOP }, /* Unknown */
	{ 0xf1c006, 0xf1c007, cps1_eeprom_port_w },
	{ 0xff0000, 0xffffff, MWA_BANK2, &cps1_ram, &cps1_ram_size },        /* RAM */
	{ -1 }  /* end of table */
};


static struct MemoryReadAddress sound_readmem[] =
{
	{ 0x0000, 0x7fff, MRA_ROM },
	{ 0x8000, 0xbfff, MRA_BANK1 },
	{ 0xd000, 0xd7ff, MRA_RAM },
	{ 0xf001, 0xf001, YM2151_status_port_0_r },
	{ 0xf002, 0xf002, OKIM6295_status_r },
	{ 0xf008, 0xf008, soundlatch_r },
	{ 0xf00a, 0xf00a, cps1_snd_fade_timer_r }, /* Sound timer fade */
	{ -1 }  /* end of table */
};

static struct MemoryWriteAddress sound_writemem[] =
{
	{ 0x0000, 0xbfff, MWA_ROM },
	{ 0xd000, 0xd7ff, MWA_RAM },
	{ 0xf000, 0xf000, YM2151_register_port_0_w },
	{ 0xf001, 0xf001, YM2151_data_port_0_w },
	{ 0xf002, 0xf002, OKIM6295_data_w },
	{ 0xf004, 0xf004, cps1_snd_bankswitch_w },
	{ 0xf006, 0xf006, MWA_NOP }, /* ???? Unknown ???? */
	{ -1 }  /* end of table */
};



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

			Configuration table:

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

static struct CPS1config cps1_config_table[]=
{
	/* DRIVER    BANK   BANK    BANK    START      CPSB CPSB
	  NAME      OBJ   SCRL1   SCRL2   SCRL3    A ADDR VAL */
	{"forgottn",0,      0,      0,      0,       5,0x00,0x0000}, /* ??? */
	{"ghouls",  0,      0,      0,      0,       5,0x00,0x0000, 1},
	{"ghoulsj", 0,      0,      0,      0,       5,0x00,0x0000, 1},
	{"strider", 0,      1,      0,      1,       4,0x00,0x0000},
	{"striderj",0,      1,      0,      1,       4,0x00,0x0000},
	{"dwj",     0,      0,      1,      1,       9,0x00,0x0000},
	{"willow",  0,      0,      1,      0,       1,0x00,0x0000},
	{"willowj", 0,      0,      1,      0,       1,0x00,0x0000},
	{"unsquad", 0,      0,      0,      0,       0,0x00,0x0000},
	{"area88",  0,      0,      0,      0,       0,0x00,0x0000},
	{"ffight",  0,      0,      0,      0,       2,0x60,0x0004},
	{"ffightu", 0,      0,      0,      0,       3,0x00,0x0000},
	{"ffightj", 0,      0,      0,      0,       2,0x60,0x0004},
	{"1941",    0,      0,      0,      0,      19,0x60,0x0005},
	{"1941j",   0,      0,      0,      0,      19,0x60,0x0005},
	{"mercs",   0,      0,      0,      0,      22,0x60,0x0402},
	{"mercsu",  0,      0,      0,      0,      22,0x60,0x0402},
	{"mercsj",  0,      0,      0,      0,      22,0x60,0x0402},
	{"mtwins",  0,      0,      0,      0,      21,0x5e,0x0404},
	{"chikij",  0,      0,      0,      0,      21,0x5e,0x0404},
	{"msword",  0,      0,      0,      0,       7,0x00,0x0000},
	{"mswordu", 0,      0,      0,      0,       7,0x00,0x0000},
	{"mswordj", 0,      0,      0,      0,       7,0x00,0x0000},
	{"cawing",  0,      0,      0,      0,      11,0x00,0x0000},
	{"cawingj", 0,      0,      0,      0,      11,0x00,0x0000},
	{"nemo",    0,      0,      0,      0,       8,0x4e,0x0405},
	{"nemoj",   0,      0,      0,      0,       8,0x4e,0x0405},
	{"sf2",     0,      2,      2,      2,      12,0x48,0x0407},
	{"sf2a",    0,      2,      2,      2,      12,0x48,0x0407},
	{"sf2b",    0,      2,      2,      2,      12,0x48,0x0407},
	{"sf2e",    0,      2,      2,      2,      15,0xd0,0x0408},
	{"sf2j",    0,      2,      2,      2,      13,0x6e,0x0403},
	{"3wonders",0,      0,      1,      1,      16,0x72,0x0800, 2},
	{"3wonderj",0,      0,      1,      1,      16,0x72,0x0800, 2},
	{"kod",     0,      0,      0,      0,      10,0x00,0x0000},
	{"kodj",    0,      0,      0,      0,      10,0x00,0x0000},
	{"kodb",    0,      0,      0,      0,      10,0x00,0x0000},
	{"captcomm",0,      0,      0,      0,      29,0x00,0x0000},
	{"captcomu",0,      0,      0,      0,      29,0x00,0x0000},
	{"captcomj",0,      0,      0,      0,      29,0x00,0x0000},
	{"knights", 0,      0,      0,      0,       6,0x00,0x0000},
	{"knightsj",0,      0,      0,      0,       6,0x00,0x0000},
	{"sf2ce",   0,      2,      2,      2,      14,0x00,0x0000},
	{"sf2cej",  0,      2,      2,      2,      14,0x00,0x0000},
	{"sf2rb",   0,      2,      2,      2,      14,0x00,0x0000},
	{"varth",   0,      0,      0,      0,      17,0x00,0x0000},
	{"varthj",  0,      0,      0,      0,      18,0x00,0x0000},
	{"cworld2j",0,      0,      0,      0,      24,0x00,0x0000},
	{"wof",     0,      0,      0,      0,      30,0x00,0x0000},
	{"wofj",    0,      0,      0,      0,      33,0x00,0x0000},
	{"dino",    0,      0,      0,      0,      27,0x00,0x0000},
	{"punisher",0,      0,      0,      0,      28,0x4e,0x0c00},
	{"punishrj",0,      0,      0,      0,      28,0x4e,0x0c00},
	{"slammast",0,      0,      0,      0,      31,0x6e,0x0c01},
	{"mbomber", 0,      0,      0,      0,      32,0x5e,0x0c02},
	{"mbomberj",0,      0,      0,      0,      32,0x5e,0x0c02},
	{"sf2t",    0,      2,      2,      2,      14,0x00,0x0000},
	{"sf2tj",   0,      2,      2,      2,      14,0x00,0x0000},
	{"pnickj",  0,      0,      0,      0,      25,0x00,0x0000},
	{"qad",     0,      0,      0,      0,      23,0x00,0x0000},
	{"qadj",    0,      0,      0,      0,      26,0x00,0x0000},
	{"megaman", 0,      0,      0,      0,      20,0x00,0x0000},
	{"rockmanj",0,      0,      0,      0,      20,0x00,0x0000},
	/* End of table (default values) */
	{0,         0,     0,       0,      0,       0,0x00,0x0000},
};

static void cps1_init_machine(void)
{
	const char *gamename = Machine->gamedrv->name;
	unsigned char *RAM = Machine->memory_region[Machine->drv->cpu[0].memory_region];


	struct CPS1config *pCFG=&cps1_config_table[0];
	while(pCFG->name)
	{
		if (strcmp(pCFG->name, gamename) == 0)
		{
			break;
		}
		pCFG++;
	}
	cps1_game_config=pCFG;

	if (strcmp(gamename, "ghouls" )==0)
	{
		/* Patch out self-test... it takes forever */
		WRITE_WORD(&RAM[0x61964+0], 0x4ef9);
		WRITE_WORD(&RAM[0x61964+2], 0x0000);
		WRITE_WORD(&RAM[0x61964+4], 0x0400);
	}
	else if (strcmp(gamename, "ghoulsj" )==0)
	{
		/* Patch out self-test... it takes forever */
		WRITE_WORD(&RAM[0x61930+0], 0x4ef9);
		WRITE_WORD(&RAM[0x61930+2], 0x0000);
		WRITE_WORD(&RAM[0x61930+4], 0x0400);
	}
}




INPUT_PORTS_START( forgottn_input_ports )
	PORT_START      /* IN0 */
	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 )
	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_COIN2 )
	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_COIN3 )  /* Service, but it doesn't give any credit */
	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNKNOWN )
	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_START1 )
	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_START2 )
	PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )

⌨️ 快捷键说明

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