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

📄 tmnt.c

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

Teenage Mutant Ninja Turtles memory map (preliminary)

000000-05ffff ROM
060000-063fff RAM
080000-080fff Palette RAM
0a0000-0bffff input
100000-105fff Video RAM
140400-1407ff Sprite RAM

memory mapped ports:

read:
0A0000/1  Coin/Service
0A0002/3  Player 1
0A0004/5  Player 2
0A0006/7  Player 3
0A0010/1  DIP Switch 1
0A0012/3  DIP Switch 2
0A0014/5  Player 4
0A0016/7  set to 0xFF
0A0018/9  DIP Switch 3

write:
0a0001    bit 0/1 = coin counters
          bit 3 = trigger irq on sound CPU
		  bit 5 = irq enable
		  bit 7 = enable char ROM reading through the video RAM
0a0009    command for sound CPU
0a0011    watchdog reset
0c0001    bit2 = PRI bit3 = PRI2
          sprite/playfield priority is controlled by these two bits, by bit 3
		  of the background tile color code, and by the SHADOW sprite
		  attribute bit.
		  Priorities are encoded in a PROM (G19 for TMNT). However, in TMNT,
		  the PROM only takes into account the PRI and SHADOW bits.
		  PRI  Priority
		   0   bg fg spr text
		   1   bg spr fg text
		  The SHADOW bit, when set, torns a sprite into a shadow which makes
		  color below it darker (this is done by turning off three resistors
		  in parallel with the RGB output).

		  Note: the background color (color used when all of the four layers
		  are 0) is taken from the *foreground* palette, not the background
		  one as would be more intuitive.

106018    fg y scroll
106019    bg y scroll
106b01    Tile Decoder1
106e01    Tile Decoder2
140007    spritecntrl (not sure of this one)


Punk Shot memory map (preliminary)

000000 03ffff ROM
080000 083fff WRKRAM
090000 090fff COLRAM
100000 100fff FIXRAM
102000 105fff VIDRAM (103000-103fff and 105000-105fff don't seem to be used during the game)
110400 1107ff OBJRAM

read:

write:
0a0021        bit 0 = coin counter
              bit 2 = trigger irq on sound CPU
		      bit 3 = enable char ROM reading through the video RAM
0a0041        command for sound CPU
0a0081        watchdog reset
106018        fg y scroll
106019        bg y scroll
106400-1067ff bg x scroll registers; 4 bytes per scanline:
              0:unknown 1:scroll LSB 2:unknown 3:scroll MSB
              NOTE: the visible area is in the range 106440-1067bf.
			  106400-106403 contains the foreground scroll register:
			  0:scroll LSB 1:unused? 2:scroll MSB 3:unused?
106a00        bit 2 = IRQ enable

interrupts: IRQ level 4.

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

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



extern unsigned char *punkshot_vidram,*punkshot_scrollram;
extern int punkshot_vidram_size;

int tmnt_interrupt(void);
int punkshot_interrupt(void);
void punkshot_irqenable_w(int offset,int data);

void tmnt_paletteram_w(int offset,int data);
int punkshot_vidram_r(int offset);
void punkshot_vidram_w(int offset,int data);
int punkshot_spriteram_r(int offset);
void punkshot_spriteram_w(int offset,int data);
void punkshot_xscroll_w(int offset,int data);
void punkshot_yscroll_w(int offset,int data);
int punkshot_100000_r(int offset);
void punkshot_charromsubbank_w(int offset,int data);
void tmnt_0a0000_w(int offset,int data);
void punkshot_0a0020_w(int offset,int data);
void tmnt_priority_w(int offset,int data);
void punkshot_priority_w(int offset,int data);
void punkshot_charrombank0_w(int offset,int data);
void punkshot_charrombank1_w(int offset,int data);
int punkshot_vh_start (void);
void punkshot_vh_stop (void);
int tmnt_vh_start (void);
void tmnt_vh_stop (void);
void tmnt_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh);
void punkshot_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh);

static int tmnt_soundlatch = 0;


void tmnt_sound_command_w(int offset,int data)
{
	soundlatch_w(0,data & 0xff);
}

int tmnt_sres_r(int offset)
{
	return tmnt_soundlatch;
}

void tmnt_sres_w(int offset,int data)
{
	/* bit 1 resets the UPD7795C sound chip */

	/* bit 2 plays the title music */
	if (data & 4)
	{
		if (!sample_playing(0))	sample_start(0,0,0);
	}
	else sample_stop(0);

	tmnt_soundlatch = data;
}

int tmnt_decode_sample(void)
{
	int i;
	signed short *dest;
	unsigned char *source = Machine->memory_region[4];
	struct GameSamples *samples;


	if ((Machine->samples = malloc(sizeof(struct GameSamples))) == NULL)
		return 1;

	samples = Machine->samples;

	if ((samples->sample[0] = malloc(sizeof(struct GameSample) + (0x40000)*sizeof(short))) == NULL)
		return 1;

	samples->sample[0]->length = 0x40000*2;
	samples->sample[0]->volume = 0xff;
	samples->sample[0]->smpfreq = 20000;	/* 20 kHz */
	samples->sample[0]->resolution = 16;
	dest = (signed short *)samples->sample[0]->data;
	samples->total = 1;

	/*	Sound sample for TMNT.D05 is stored in the following mode:
	 *
	 *	Bit 15-13:	Exponent (2 ^ x)
	 *	Bit 12-4 :	Sound data (9 bit)
	 *
	 *	(Sound info courtesy of Dave <dayvee@rocketmail.com>)
	 */

	for (i = 0;i < 0x40000;i++)
	{
		int val = source[2*i] + source[2*i+1] * 256;
		int exp = val >> 13;

	  	val = (val >> 4) & (0x1ff);	/* 9 bit, Max Amplitude 0x200 */
		val -= 0x100;					/* Centralize value	*/

		val <<= exp;

		dest[i] = val;
	}

	/*	The sample is now ready to be used.  It's a 16 bit, 22khz sample.
	 */

	return 0;
}



int tmnt_input_r (int offset)
{
	switch (offset)
	{
		case 0x00:
			return readinputport(0);

		case 0x02:
			return readinputport(1);

		case 0x04:
			return readinputport(2);

		case 0x06:
			return readinputport(3);

		case 0x10:
			return readinputport(4);

		case 0x12:
			return readinputport(5);

		case 0x14:
			return readinputport(6);

		case 0x18:
			return readinputport(7);
	}


	return 0;
}

int punkshot_input_r(int offset)
{
	switch (offset)
	{
		case 0:	/* DSW1, DSW2 */
			return (readinputport(0) + (readinputport(1) << 8));

		case 2:	/* COIN, DSW3 */
			return (readinputport(2) + (readinputport(3) << 8));

		case 6:	/* IN0, IN1 */
			return (readinputport(4) + (readinputport(5) << 8));
	}


	return 0;
}



static int punkshot_kludge(int offset)
{
	/* I don't know what's going on here; at one point, the code reads location */
	/* 0xffffff, and returning 0 causes the game to mess up - locking up in a */
	/* loop where the ball is continuously bouncing from the basket. Returning */
	/* a random number seems to prevent that. */
	return rand();
}



static struct MemoryReadAddress tmnt_readmem[] =
{
	{ 0x000000, 0x05ffff, MRA_ROM },
	{ 0x060000, 0x063fff, MRA_BANK1 },	/* main RAM */
	{ 0x080000, 0x080fff, paletteram_word_r },
	{ 0x0a0000, 0x0a001b, tmnt_input_r },
	{ 0x100000, 0x106fff, punkshot_100000_r },	/* either video RAMs or character ROMs, */
												/* depending on bit 3 of a0021. */
												/* The area of the char ROMs appearing here */
												/* is controlled by 106b00 and 106e00 */
	{ 0x140400, 0x1407ff, punkshot_spriteram_r },
	{ -1 }	/* end of table */
};

static struct MemoryWriteAddress tmnt_writemem[] =
{
	{ 0x000000, 0x05ffff, MWA_ROM },
	{ 0x060000, 0x063fff, MWA_BANK1 },	/* main RAM */
	{ 0x080000, 0x080fff, tmnt_paletteram_w, &paletteram },
	{ 0x0a0000, 0x0a0003, tmnt_0a0000_w },
	{ 0x0a0008, 0x0a0009, tmnt_sound_command_w },
	{ 0x0a0010, 0x0a0013, watchdog_reset_w },
	{ 0x0c0000, 0x0c0003, tmnt_priority_w },
	{ 0x100000, 0x105fff, punkshot_vidram_w, &punkshot_vidram, &punkshot_vidram_size },
	{ 0x106018, 0x10601b, punkshot_yscroll_w },
	{ 0x106400, 0x1067ff, punkshot_xscroll_w, &punkshot_scrollram },
	{ 0x106b00, 0x106b03, punkshot_charrombank0_w },
	{ 0x106e00, 0x106e03, punkshot_charrombank1_w },
	{ 0x140400, 0x1407ff, punkshot_spriteram_w, &spriteram, &spriteram_size },
	{ -1 }	/* end of table */
};

static struct MemoryReadAddress punkshot_readmem[] =
{
	{ 0x000000, 0x03ffff, MRA_ROM },
	{ 0x080000, 0x083fff, MRA_BANK1 },	/* main RAM */
	{ 0x090000, 0x090fff, paletteram_word_r },
	{ 0x0a0000, 0x0a0007, punkshot_input_r },
	{ 0x100000, 0x106fff, punkshot_100000_r },	/* either video RAMs or character ROMs, */
												/* depending on bit 3 of a0021. */
												/* The area of the char ROMs appearing here */
												/* is controlled by 106b00 and 106e00 */
	{ 0x110400, 0x1107ff, punkshot_spriteram_r },
	{ 0xfffffc, 0xffffff, punkshot_kludge },
	{ -1 }	/* end of table */
};

static struct MemoryWriteAddress punkshot_writemem[] =
{
	{ 0x000000, 0x03ffff, MWA_ROM },
	{ 0x080000, 0x083fff, MWA_BANK1 },	/* main RAM */
	{ 0x090000, 0x090fff, paletteram_xBBBBBGGGGGRRRRR_word_w, &paletteram },
	{ 0x0a0020, 0x0a0023, punkshot_0a0020_w },
	{ 0x0a0040, 0x0a0041, tmnt_sound_command_w },
	{ 0x0a0068, 0x0a006b, punkshot_priority_w },
	{ 0x0a0080, 0x0a0083, watchdog_reset_w },
	{ 0x100000, 0x105fff, punkshot_vidram_w, &punkshot_vidram, &punkshot_vidram_size },
	{ 0x106018, 0x10601b, punkshot_yscroll_w },
	{ 0x106400, 0x1067ff, punkshot_xscroll_w, &punkshot_scrollram },
	{ 0x106a00, 0x106a03, punkshot_irqenable_w },
	{ 0x106b00, 0x106b03, punkshot_charrombank0_w },
	{ 0x106c00, 0x106c03, punkshot_charromsubbank_w },
	{ 0x106e00, 0x106e03, punkshot_charrombank1_w },
	{ 0x110400, 0x1107ff, punkshot_spriteram_w, &spriteram, &spriteram_size },
	{ -1 }	/* end of table */
};

static struct MemoryReadAddress tmnt_s_readmem[] =
{
	{ 0x0000, 0x7fff, MRA_ROM },
	{ 0x8000, 0x87ff, MRA_RAM },
	{ 0x9000, 0x9000, tmnt_sres_r },	/* title music & UPD7759C reset */
	{ 0xa000, 0xa000, soundlatch_r },
	{ 0xc001, 0xc001, YM2151_status_port_0_r },
	{ -1 }	/* end of table */
};

static struct MemoryWriteAddress tmnt_s_writemem[] =
{
	{ 0x0000, 0x7fff, MWA_ROM },
	{ 0x8000, 0x87ff, MWA_RAM },
	{ 0x9000, 0x9000, tmnt_sres_w },	/* title music & UPD7759C reset */
	{ 0xc000, 0xc000, YM2151_register_port_0_w },
	{ 0xc001, 0xc001, YM2151_data_port_0_w },
	{ -1 }	/* end of table */
};

static struct MemoryReadAddress punkshot_s_readmem[] =
{
	{ 0x0000, 0x7fff, MRA_ROM },
	{ 0xf000, 0xf7ff, MRA_RAM },
	{ 0xf801, 0xf801, YM2151_status_port_0_r },
	{ 0xfc00, 0xfc00, soundlatch_r },
	{ -1 }	/* end of table */
};

static struct MemoryWriteAddress punkshot_s_writemem[] =
{
	{ 0x0000, 0x7fff, MWA_ROM },
	{ 0xf000, 0xf7ff, MWA_RAM },
	{ 0xf800, 0xf800, YM2151_register_port_0_w },
	{ 0xf801, 0xf801, YM2151_data_port_0_w },
	{ -1 }	/* end of table */
};



INPUT_PORTS_START( tmnt_input_ports )
	PORT_START      /* COINS */
	PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_COIN1 )
	PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_COIN2 )
	PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_COIN3 )
	PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_COIN4 )
	PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_SERVICE )
	PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_SERVICE )
	PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_SERVICE )
	PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_SERVICE )

	PORT_START      /* PLAYER 1 */
	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT | IPF_PLAYER1 | IPF_8WAY )
	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_PLAYER1 | IPF_8WAY )
	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_UP | IPF_PLAYER1 | IPF_8WAY )
	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN | IPF_PLAYER1 | IPF_8WAY )
	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER1 )
	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER1 )
	PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )	/* button 3 - unused */
	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_START1 )

	PORT_START      /* PLAYER 2 */
	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT | IPF_PLAYER2 | IPF_8WAY )
	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_PLAYER2 | IPF_8WAY )
	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_UP | IPF_PLAYER2 | IPF_8WAY )
	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN | IPF_PLAYER2 | IPF_8WAY )
	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER2 )
	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER2 )
	PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )	/* button 3 - unused */
	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_START2 )

	PORT_START      /* PLAYER 3 */
	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT | IPF_PLAYER3 | IPF_8WAY )
	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_PLAYER3 | IPF_8WAY )
	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_UP | IPF_PLAYER3 | IPF_8WAY )
	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN | IPF_PLAYER3 | IPF_8WAY )
	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER3 )
	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER3 )
	PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )	/* button 3 - unused */
	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_START3 )

⌨️ 快捷键说明

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