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

📄 kchamp.c

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

Karate Champ - (c) 1984 Data East

Currently supported sets:
Karate Champ - VS Version (kchampvs)
Karate Champ - VS Version Japanese (karatedo)
Karate Champ - 1 Player Version (kchamp)

VS Version Info:
---------------
Memory Map:
Main CPU
0000-bfff ROM (encrypted)
c000-cfff RAM
d000-d3ff char videoram
d400-d7ff color videoram
d800-d8ff sprites
e000-ffff ROM (encrypted)

Sound CPU
0000-5fff ROM
6000-6300 RAM

IO Ports:
Main CPU
INPUT  00 = Player 1 Controls - ( ACTIVE LOW )
INPUT  40 = Player 2 Controls - ( ACTIVE LOW )
INPUT  80 = Coins and Start Buttons - ( ACTIVE LOW )
INPUT  C0 = Dip Switches - ( ACTIVE LOW )
OUTPUT 00 = Screen Flip? (There isnt a cocktail switch?) UNINMPLEMENTED
OUTPUT 01 = CPU Control
                bit 0 = external nmi enable
OUTPUT 02 = Sound Reset
OUTPUT 40 = Sound latch write

Sound CPU
INPUT  01 = Sound latch read
OUTPUT 00 = AY8910 #1 data write
OUTPUT 01 = AY8910 #1 control write
OUTPUT 02 = AY8910 #2 data write
OUTPUT 03 = AY8910 #2 control write
OUTPUT 04 = MSM5205 write
OUTPUT 05 = CPU Control
                bit 0 = MSM5205 trigger
                bit 1 = external nmi enable

1P Version Info:
---------------
Same as VS version but with a DAC instead of a MSM5205. Also some minor
IO ports and memory map changes. Dip switches differ too.

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

/* from vidhrdw */
extern void kchamp_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom);
extern void kchamp_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh);
extern int kchampvs_vh_start(void);
extern int kchamp1p_vh_start(void);


static int nmi_enable = 0;
static int sound_nmi_enable = 0;

static struct MemoryReadAddress readmem[] =
{
    { 0x0000, 0xbfff, MRA_ROM },
    { 0xc000, 0xcfff, MRA_RAM },
    { 0xd000, 0xd3ff, videoram_r },
    { 0xd400, 0xd7ff, colorram_r },
    { 0xd800, 0xd8ff, spriteram_r },
    { 0xd900, 0xdfff, MRA_RAM },
    { 0xe000, 0xffff, MRA_ROM },
    { -1 }
};

static struct MemoryWriteAddress writemem[] =
{
    { 0x0000, 0xbfff, MWA_ROM },
    { 0xc000, 0xcfff, MWA_RAM },
    { 0xd000, 0xd3ff, videoram_w, &videoram, &videoram_size },
    { 0xd400, 0xd7ff, colorram_w, &colorram },
    { 0xd800, 0xd8ff, spriteram_w, &spriteram, &spriteram_size },
    { 0xd900, 0xdfff, MWA_RAM },
    { 0xe000, 0xffff, MWA_ROM },
    { -1 }
};

static struct MemoryReadAddress sound_readmem[] =
{
    { 0x0000, 0x5fff, MRA_ROM },
    { 0x6000, 0xffff, MRA_RAM },
    { -1 }
};

static struct MemoryWriteAddress sound_writemem[] =
{
    { 0x0000, 0x5fff, MWA_ROM },
    { 0x6000, 0xffff, MWA_RAM },
    { -1 }
};

static void control_w( int offset, int data ) {
    nmi_enable = data & 1;
}

static void sound_reset_w( int offset, int data ) {
    if ( !( data & 1 ) )
    	cpu_reset( 1 );
}

static void sound_control_w( int offset, int data ) {
	MSM5205_reset_w( 0, !( data & 1 ) );
	sound_nmi_enable = ( ( data >> 1 ) & 1 );
}

static void sound_command_w( int offset, int data ) {
	soundlatch_w( 0, data );
	cpu_cause_interrupt( 1, 0xff );
}

static int msm_data = 0;
static int msm_play_lo_nibble = 1;

static void sound_msm_w( int offset, int data ) {
	msm_data = data;
	msm_play_lo_nibble = 1;
}

static struct IOReadPort readport[] =
{
    { 0x00, 0x00, input_port_0_r }, /* Player 1 controls - ACTIVE LOW */
    { 0x40, 0x40, input_port_1_r }, /* Player 2 controls - ACTIVE LOW */
    { 0x80, 0x80, input_port_2_r }, /* Coins & Start - ACTIVE LOW */
    { 0xC0, 0xC0, input_port_3_r }, /* Dipswitch */
    { -1 }	/* end of table */
};

static struct IOWritePort writeport[] =
{
    { 0x00, 0x00, MWA_NOP },
    { 0x01, 0x01, control_w },
    { 0x02, 0x02, sound_reset_w },
    { 0x40, 0x40, sound_command_w },
    { -1 }  /* end of table */
};

static struct IOReadPort sound_readport[] =
{
    { 0x01, 0x01, soundlatch_r },
    { -1 }	/* end of table */
};

static struct IOWritePort sound_writeport[] =
{
    { 0x00, 0x00, AY8910_write_port_0_w },
    { 0x01, 0x01, AY8910_control_port_0_w },
    { 0x02, 0x02, AY8910_write_port_1_w },
    { 0x03, 0x03, AY8910_control_port_1_w },
    { 0x04, 0x04, sound_msm_w },
    { 0x05, 0x05, sound_control_w },
	{ -1 }	/* end of table */
};

/********************
* 1 Player Version  *
********************/

static struct MemoryReadAddress kc_readmem[] =
{
    { 0x0000, 0xbfff, MRA_ROM },
    { 0xc000, 0xdfff, MRA_RAM },
    { 0xe000, 0xe3ff, videoram_r },
    { 0xe400, 0xe7ff, colorram_r },
    { 0xea00, 0xeaff, spriteram_r },
    { 0xeb00, 0xffff, MRA_RAM },
    { -1 }
};

static struct MemoryWriteAddress kc_writemem[] =
{
    { 0x0000, 0xbfff, MWA_ROM },
    { 0xc000, 0xdfff, MWA_RAM },
    { 0xe000, 0xe3ff, videoram_w, &videoram, &videoram_size },
    { 0xe400, 0xe7ff, colorram_w, &colorram },
    { 0xea00, 0xeaff, spriteram_w, &spriteram, &spriteram_size },
	{ 0xeb00, 0xffff, MWA_RAM },
    { -1 }
};

static struct MemoryReadAddress kc_sound_readmem[] =
{
	{ 0x0000, 0xdfff, MRA_ROM },
	{ 0xe000, 0xe2ff, MRA_RAM },
	{ -1 }
};

static struct MemoryWriteAddress kc_sound_writemem[] =
{
	{ 0x0000, 0xdfff, MWA_ROM },
	{ 0xe000, 0xe2ff, MWA_RAM },
	{ -1 }
};

static int sound_reset_r( int offset ) {
    cpu_reset( 1 );
    return 0;
}

static void kc_sound_control_w( int offset, int data ) {
    if ( offset == 0 )
    	sound_nmi_enable = ( ( data >> 7 ) & 1 );
}

static struct IOReadPort kc_readport[] =
{
    { 0x90, 0x90, input_port_0_r }, /* Player 1 controls - ACTIVE LOW */
    { 0x98, 0x98, input_port_1_r }, /* Player 2 controls - ACTIVE LOW */
    { 0xa0, 0xa0, input_port_2_r }, /* Coins & Start - ACTIVE LOW */
    { 0x80, 0x80, input_port_3_r }, /* Dipswitch */
    { 0xa8, 0xa8, sound_reset_r },
    { -1 }	/* end of table */
};

static struct IOWritePort kc_writeport[] =
{
    { 0x80, 0x80, MWA_NOP },
    { 0x81, 0x81, control_w },
    { 0xa8, 0xa8, sound_command_w },
    { -1 }  /* end of table */
};

static struct IOReadPort kc_sound_readport[] =
{
    { 0x06, 0x06, soundlatch_r },
    { -1 }	/* end of table */
};

static struct IOWritePort kc_sound_writeport[] =
{
    { 0x00, 0x00, AY8910_write_port_0_w },
    { 0x01, 0x01, AY8910_control_port_0_w },
    { 0x02, 0x02, AY8910_write_port_1_w },
    { 0x03, 0x03, AY8910_control_port_1_w },
    { 0x04, 0x04, DAC_data_w },
    { 0x05, 0x05, kc_sound_control_w },
	{ -1 }	/* end of table */
};


INPUT_PORTS_START( input_ports )
        PORT_START      /* IN0 */
        PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_RIGHT | IPF_4WAY )
        PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_LEFT | IPF_4WAY )
        PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_UP | IPF_4WAY )
        PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_DOWN | IPF_4WAY )
        PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_RIGHT | IPF_4WAY )
        PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_LEFT | IPF_4WAY )
        PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_UP | IPF_4WAY )
        PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_DOWN | IPF_4WAY )

        PORT_START      /* IN1 */
        PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_RIGHT | IPF_PLAYER2 | IPF_4WAY )
        PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_LEFT | IPF_PLAYER2 | IPF_4WAY )
        PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_UP | IPF_PLAYER2 | IPF_4WAY )
        PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_DOWN | IPF_PLAYER2 | IPF_4WAY )
        PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_RIGHT | IPF_PLAYER2 | IPF_4WAY )
        PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_LEFT | IPF_PLAYER2 | IPF_4WAY )
        PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_UP | IPF_PLAYER2 | IPF_4WAY )
        PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_DOWN | IPF_PLAYER2 | IPF_4WAY )

        PORT_START      /* IN2 */
        PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 )
        PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_COIN2 )
        PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_START1 )
        PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START2 )
        PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNUSED )
        PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNUSED  )
        PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNUSED  )
        PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED  )

        PORT_START      /* DSW0 */
        PORT_DIPNAME( 0x03, 0x03, "Coin B", IP_KEY_NONE )
        PORT_DIPSETTING(    0x00, "3 Coins/1 Credit" )
        PORT_DIPSETTING(    0x01, "2 Coins/1 Credit" )
        PORT_DIPSETTING(    0x03, "1 Coin/1 Credit" )
        PORT_DIPSETTING(    0x02, "1 Coin/2 Credits" )
        PORT_DIPNAME( 0x0c, 0x0c, "Coin A", IP_KEY_NONE )
        PORT_DIPSETTING(    0x00, "3 Coins/1 Credit" )
        PORT_DIPSETTING(    0x04, "2 Coins/1 Credit" )
        PORT_DIPSETTING(    0x0c, "1 Coin/1 Credit" )
        PORT_DIPSETTING(    0x08, "1 Coin/2 Credits" )
        PORT_DIPNAME( 0x30, 0x10, "Difficulty", IP_KEY_NONE )
        PORT_DIPSETTING(    0x30, "Easy" )
        PORT_DIPSETTING(    0x20, "Medium" )
        PORT_DIPSETTING(    0x10, "Hard" )
        PORT_DIPSETTING(    0x00, "Hardest" )
        PORT_DIPNAME( 0x40, 0x00, "Demo Sounds", IP_KEY_NONE )

⌨️ 快捷键说明

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