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

📄 toki.c

📁 这个是延伸mame的在wince平台下的游戏模拟器的代码
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "driver.h"
#include "vidhrdw/generic.h"
#include "z80/z80.h"


static unsigned char *ram;
extern unsigned char *toki_foreground_videoram;
extern unsigned char *toki_background1_videoram;
extern unsigned char *toki_background2_videoram;
extern unsigned char *toki_sprites_dataram;
extern unsigned char *toki_scrollram;

extern int toki_foreground_videoram_size;
extern int toki_background1_videoram_size;
extern int toki_background2_videoram_size;
extern int toki_sprites_dataram_size;

int toki_interrupt(void);
int  toki_vh_start(void);
void toki_vh_stop(void);
void toki_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh);
int  toki_foreground_videoram_r(int offset);
void toki_foreground_videoram_w(int offset,int data);
int  toki_background1_videoram_r(int offset);
void toki_background1_videoram_w(int offset,int data);
int  toki_background2_videoram_r(int offset);
void toki_background2_videoram_w(int offset,int data);
void toki_linescroll_w(int offset,int data);


int toki_read_ports(int offset)
{
    switch(offset)
    {
		case 0:
			return input_port_3_r(0) + (input_port_4_r(0) << 8);
		case 2:
			return input_port_1_r(0) + (input_port_2_r(0) << 8);
		case 4:
			return input_port_0_r(0);
		default:
			return 0;
    }
}

void toki_soundcommand_w(int offset,int data)
{
	soundlatch_w(0,data & 0xff);
	cpu_cause_interrupt(1,0xff);
}

void toki_adpcm_int (int data)
{
	static int toggle;

	toggle = 1 - toggle;
	if (toggle)
		cpu_cause_interrupt(1,Z80_NMI_INT);
}

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


	/* the code writes either 2 or 3 in the bottom two bits */
	bankaddress = 0x10000 + (data & 0x01) * 0x4000;
	cpu_setbank(1,&RAM[bankaddress]);

	MSM5205_reset_w(0,data & 0x08);
}

void toki_adpcm_data_w(int offset,int data)
{
	MSM5205_data_w(offset,data & 0x0f);
	MSM5205_data_w(offset,data >> 4);
}

static int pip(int offset)
{
	return 0xffff;
}


static struct MemoryReadAddress readmem[] =
{
	{ 0x000000, 0x05ffff, MRA_ROM },
	{ 0x060000, 0x06dfff, MRA_BANK2, &ram },
	{ 0x06e000, 0x06e7ff, paletteram_word_r },
	{ 0x06e800, 0x06efff, toki_background1_videoram_r },
	{ 0x06f000, 0x06f7ff, toki_background2_videoram_r },
	{ 0x06f800, 0x06ffff, toki_foreground_videoram_r },
	{ 0x072000, 0x072001, watchdog_reset_r },	/* probably */
	{ 0x0c0000, 0x0c0005, toki_read_ports },
	{ 0x0c000e, 0x0c000f, pip },	/* sound related, if we return 0 the code writes */
									/* the sound command quickly followed by 0 and the */
									/* sound CPU often misses the command. */
	{ -1 }  /* end of table */
};

static struct MemoryWriteAddress writemem[] =
{
	{ 0x000000, 0x05ffff, MWA_ROM },
	{ 0x060000, 0x06dfff, MWA_BANK2 },
	{ 0x06e000, 0x06e7ff, paletteram_xxxxBBBBGGGGRRRR_word_w, &paletteram },
	{ 0x06e800, 0x06efff, toki_background1_videoram_w, &toki_background1_videoram, &toki_background1_videoram_size },
	{ 0x06f000, 0x06f7ff, toki_background2_videoram_w, &toki_background2_videoram, &toki_background2_videoram_size },
	{ 0x06f800, 0x06ffff, toki_foreground_videoram_w, &toki_foreground_videoram, &toki_foreground_videoram_size },
	{ 0x071000, 0x071001, MWA_NOP },	/* sprite related? seems another scroll register; */
										/* gets written the same value as 75000a (bg2 scrollx) */
	{ 0x071804, 0x071807, MWA_NOP },	/* sprite related; always 01be0100 */
	{ 0x07180e, 0x071e45, MWA_BANK3, &toki_sprites_dataram, &toki_sprites_dataram_size },
	{ 0x075000, 0x075001, toki_soundcommand_w },
	{ 0x075004, 0x07500b, MWA_BANK4, &toki_scrollram },
	{ 0x0a002a, 0x0a002d, toki_linescroll_w },	/* scroll register used to waggle the title screen */
	{ -1 }  /* end of table */
};

static struct MemoryReadAddress sound_readmem[] =
{
	{ 0x0000, 0x7fff, MRA_ROM },
	{ 0x8000, 0xbfff, MRA_BANK1 },
	{ 0xec00, 0xec00, YM3812_status_port_0_r },
	{ 0xf000, 0xf7ff, MRA_RAM },
	{ 0xf800, 0xf800, soundlatch_r },
	{ -1 }  /* end of table */
};

static struct MemoryWriteAddress sound_writemem[] =
{
	{ 0x0000, 0xbfff, MWA_ROM },
	{ 0xe000, 0xe000, toki_adpcm_control_w },	/* MSM5205 + ROM bank */
	{ 0xe400, 0xe400, toki_adpcm_data_w },
	{ 0xec00, 0xec00, YM3812_control_port_0_w },
	{ 0xec01, 0xec01, YM3812_write_port_0_w },
	{ 0xec08, 0xec08, YM3812_control_port_0_w },	/* mirror address, it seems */
	{ 0xec09, 0xec09, YM3812_write_port_0_w },	/* mirror address, it seems */
	{ 0xf000, 0xf7ff, MWA_RAM },
	{ -1 }  /* end of table */
};



INPUT_PORTS_START( 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 )
	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START1 )
	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_START2 )
	PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_UNKNOWN )
	PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_UNKNOWN )
	PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_UNKNOWN )

	PORT_START	/* IN1 */
	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY )
	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY )
	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY )
	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY )
	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 )
	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 )
	PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_UNKNOWN )
	PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_UNKNOWN )

	PORT_START	/* IN2 */
	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY | IPF_COCKTAIL )
	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY | IPF_COCKTAIL )
	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY | IPF_COCKTAIL )
	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY | IPF_COCKTAIL )
	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_COCKTAIL )
	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_COCKTAIL )
	PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_UNKNOWN )
	PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_UNKNOWN )

	PORT_START      /* DSW0 */
	PORT_DIPNAME( 0x1F, 0x1F, "Coinage", IP_KEY_NONE )
	PORT_DIPSETTING(    0x15, "6 Coins/1 Credit" )
	PORT_DIPSETTING(    0x17, "5 Coins/1 Credit" )
	PORT_DIPSETTING(    0x19, "4 Coins/1 Credit" )
	PORT_DIPSETTING(    0x1B, "3 Coins/1 Credit" )
	PORT_DIPSETTING(    0x03, "8 Coins/3 Credits" )
	PORT_DIPSETTING(    0x1D, "2 Coins/1 Credit" )
	PORT_DIPSETTING(    0x05, "5 Coins/3 Credits" )
	PORT_DIPSETTING(    0x07, "3 Coins/2 Credits" )
	PORT_DIPSETTING(    0x1F, "1 Coin/1 Credit" )
	PORT_DIPSETTING(    0x09, "2 Coins/3 Credits" )
	PORT_DIPSETTING(    0x13, "1 Coin/2 Credits" )
	PORT_DIPSETTING(    0x11, "1 Coin/3 Credits" )
	PORT_DIPSETTING(    0x0F, "1 Coin/4 Credits" )
	PORT_DIPSETTING(    0x0D, "1 Coin/5 Credits" )
	PORT_DIPSETTING(    0x0B, "1 Coin/6 Credits" )
	PORT_DIPSETTING(    0x1E, "A 1/1 B 1/2" )
	PORT_DIPSETTING(    0x14, "A 2/1 B 1/3" )
	PORT_DIPSETTING(    0x0A, "A 3/1 B 1/5" )
	PORT_DIPSETTING(    0x00, "A 5/1 B 1/6" )
	PORT_DIPSETTING(    0x01, "Free Play" )
	PORT_DIPNAME( 0x20, 0x20, "Joysticks", IP_KEY_NONE )
	PORT_DIPSETTING(    0x20, "1" )
	PORT_DIPSETTING(    0x00, "2" )
	PORT_DIPNAME( 0x40, 0x40, "Cabinet", IP_KEY_NONE )
	PORT_DIPSETTING(    0x40, "Upright" )
	PORT_DIPSETTING(    0x00, "Cocktail" )
	PORT_DIPNAME( 0x80, 0x80, "Flip Screen", IP_KEY_NONE )
	PORT_DIPSETTING(    0x80, "Off" )
	PORT_DIPSETTING(    0x00, "On" )

	PORT_START	/* DSW1 */
	PORT_DIPNAME( 0x03, 0x03, "Lives", IP_KEY_NONE )
	PORT_DIPSETTING(    0x02, "2" )
	PORT_DIPSETTING(    0x03, "3" )
	PORT_DIPSETTING(    0x01, "5" )
	PORT_BITX( 0,       0x00, IPT_DIPSWITCH_SETTING | IPF_CHEAT, "Infinite", IP_KEY_NONE, IP_JOY_NONE, 0 )
	PORT_DIPNAME( 0x0C, 0x0C, "Bonus Life", IP_KEY_NONE )
	PORT_DIPSETTING(    0x08, "50000 150000" )
	PORT_DIPSETTING(    0x00, "70000 140000 210000" )
	PORT_DIPSETTING(    0x0C, "70000" )
	PORT_DIPSETTING(    0x04, "100000 200000" )
	PORT_DIPNAME( 0x30, 0x30, "Difficulty", IP_KEY_NONE )
	PORT_DIPSETTING(    0x20, "Easy" )
	PORT_DIPSETTING(    0x30, "Medium" )
	PORT_DIPSETTING(    0x10, "Hard" )
	PORT_DIPSETTING(    0x00, "Hardest" )
	PORT_DIPNAME( 0x40, 0x40, "Allow Continue", IP_KEY_NONE )
	PORT_DIPSETTING(    0x00, "No" )
	PORT_DIPSETTING(    0x40, "Yes" )
	PORT_DIPNAME( 0x80, 0x80, "Demo Sounds", IP_KEY_NONE )
	PORT_DIPSETTING(    0x00, "Off" )
	PORT_DIPSETTING(    0x80, "On" )
INPUT_PORTS_END


static struct GfxLayout charlayout =
{
	8,8,	/* 8 by 8 */
	4096,	/* 4096 characters */
	4,	/* 4 bits per pixel */
        {4096*8*8*3,4096*8*8*2,4096*8*8*1,4096*8*8*0 },	/* planes */
	{ 0, 1,  2,  3,  4,  5,  6,  7},		/* x bit */
	{ 0, 8, 16, 24, 32, 40, 48, 56},		/* y bit */
	8*8
};

static struct GfxLayout backgroundlayout =
{
	16,16,	/* 16 by 16 */

⌨️ 快捷键说明

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