shangkid.cpp: Redo interrupt handling based on Chinese Hero schematics (nw)

This commit is contained in:
AJR 2017-08-20 19:44:22 -04:00
parent de19e7b844
commit 51f084d3a7
2 changed files with 117 additions and 55 deletions

View File

@ -64,43 +64,79 @@ Games by Nihon Game/Culture Brain:
/***************************************************************************************/
WRITE_LINE_MEMBER(shangkid_state::cpu_reset_w)
{
if (!state)
{
//m_bbx->set_input_line(INPUT_LINE_RESET, PULSE_LINE);
}
else
{
m_maincpu->set_input_line(INPUT_LINE_RESET, PULSE_LINE);
}
}
WRITE_LINE_MEMBER(shangkid_state::sound_enable_w)
{
m_bbx_sound_enable = state;
if (!state)
m_aysnd->reset();
}
WRITE_LINE_MEMBER(shangkid_state::int_enable_1_w)
{
m_int_enable[0] = state;
if (!m_int_enable[0])
m_maincpu->set_input_line(0, CLEAR_LINE);
}
WRITE_LINE_MEMBER(shangkid_state::int_enable_2_w)
{
m_int_enable[1] = state;
if (!m_int_enable[1])
m_bbx->set_input_line(0, CLEAR_LINE);
}
WRITE_LINE_MEMBER(shangkid_state::nmi_enable_1_w)
{
m_nmi_enable[0] = state;
if (!m_int_enable[0])
m_maincpu->set_input_line(INPUT_LINE_NMI, CLEAR_LINE);
}
WRITE_LINE_MEMBER(shangkid_state::nmi_enable_2_w)
{
m_nmi_enable[1] = state;
if (!m_nmi_enable[1])
m_bbx->set_input_line(INPUT_LINE_NMI, CLEAR_LINE);
}
WRITE_LINE_MEMBER(shangkid_state::irq_1_w)
{
if (state && m_int_enable[0])
m_maincpu->set_input_line(0, ASSERT_LINE);
}
WRITE_LINE_MEMBER(shangkid_state::irq_2_w)
{
if (state && m_int_enable[1])
m_bbx->set_input_line(0, ASSERT_LINE);
}
WRITE8_MEMBER(shangkid_state::nmiq_1_w)
{
if (m_nmi_enable[0])
m_maincpu->set_input_line(INPUT_LINE_NMI, ASSERT_LINE);
}
WRITE8_MEMBER(shangkid_state::nmiq_2_w)
{
if (m_nmi_enable[1])
m_bbx->set_input_line(INPUT_LINE_NMI, ASSERT_LINE);
}
WRITE8_MEMBER(shangkid_state::chinhero_ay8910_porta_w)
{
if( m_bbx_sound_enable )
{
if( data == 0x01 )
/* 0->1 transition triggers interrupt on Sound CPU */
m_audiocpu->set_input_line(0, HOLD_LINE );
}
if (BIT(data, 0))
/* 0->1 transition triggers interrupt on Sound CPU */
m_audiocpu->set_input_line(0, HOLD_LINE );
}
WRITE8_MEMBER(shangkid_state::shangkid_ay8910_porta_w)
{
if( m_bbx_sound_enable )
{
if( data == 0x01 )
/* 0->1 transition triggers interrupt on Sound CPU */
m_audiocpu->set_input_line(0, HOLD_LINE );
}
else
membank("bank2")->set_entry(data ? 0 : 1);
logerror("Writing %02X to port A\n");
if (BIT(data, 0))
/* 0->1 transition triggers interrupt on Sound CPU */
m_audiocpu->set_input_line(0, HOLD_LINE );
membank("bank2")->set_entry((data & 0xfe) ? 0 : 1);
}
WRITE8_MEMBER(shangkid_state::ay8910_portb_w)
@ -117,12 +153,18 @@ READ8_MEMBER(shangkid_state::soundlatch_r)
/***************************************************************************************/
DRIVER_INIT_MEMBER(shangkid_state,dynamski)
{
save_item(NAME(m_int_enable[0]));
}
DRIVER_INIT_MEMBER(shangkid_state,chinhero)
{
m_gfx_type = 0;
save_item(NAME(m_bbx_sound_enable));
save_item(NAME(m_sound_latch));
save_item(NAME(m_int_enable));
save_item(NAME(m_nmi_enable));
}
DRIVER_INIT_MEMBER(shangkid_state,shangkid)
@ -133,16 +175,13 @@ DRIVER_INIT_MEMBER(shangkid_state,shangkid)
membank("bank1")->configure_entries(0, 2, memregion("maincpu")->base() + 0x8000, 0x8000);
membank("bank2")->configure_entries(0, 2, memregion("audiocpu")->base() + 0x0000, 0x10000);
save_item(NAME(m_bbx_sound_enable));
save_item(NAME(m_sound_latch));
save_item(NAME(m_int_enable));
save_item(NAME(m_nmi_enable));
}
/***************************************************************************************/
MACHINE_RESET_MEMBER(shangkid_state,chinhero)
{
}
MACHINE_RESET_MEMBER(shangkid_state,shangkid)
{
membank("bank2")->set_entry(0);
@ -230,7 +269,8 @@ GFXDECODE_END
static ADDRESS_MAP_START( chinhero_main_map, AS_PROGRAM, 8, shangkid_state )
AM_RANGE(0x0000, 0x9fff) AM_ROM
AM_RANGE(0xa000, 0xa000) AM_WRITENOP /* ? */
AM_RANGE(0xa000, 0xa000) AM_WRITE(nmiq_1_w)
AM_RANGE(0xa800, 0xa800) AM_WRITE(nmiq_2_w)
AM_RANGE(0xb000, 0xb007) AM_DEVWRITE("mainlatch", ls259_device, write_d0)
AM_RANGE(0xb800, 0xb800) AM_READ_PORT("DSW")
AM_RANGE(0xb801, 0xb801) AM_READ_PORT("SYSTEM")
@ -245,7 +285,8 @@ ADDRESS_MAP_END
static ADDRESS_MAP_START( shangkid_main_map, AS_PROGRAM, 8, shangkid_state )
AM_RANGE(0x0000, 0x7fff) AM_ROM
AM_RANGE(0x8000, 0x9fff) AM_ROMBANK("bank1")
AM_RANGE(0xa000, 0xa000) AM_WRITENOP /* ? */
AM_RANGE(0xa000, 0xa000) AM_WRITE(nmiq_1_w)
AM_RANGE(0xa800, 0xa800) AM_WRITE(nmiq_2_w)
AM_RANGE(0xb000, 0xb007) AM_DEVWRITE("mainlatch", ls259_device, write_d0)
AM_RANGE(0xb800, 0xb800) AM_READ_PORT("DSW")
AM_RANGE(0xb801, 0xb801) AM_READ_PORT("SYSTEM")
@ -261,7 +302,8 @@ ADDRESS_MAP_END
static ADDRESS_MAP_START( chinhero_bbx_map, AS_PROGRAM, 8, shangkid_state )
AM_RANGE(0x0000, 0x9fff) AM_ROM
AM_RANGE(0xa000, 0xa000) AM_WRITENOP /* ? */
AM_RANGE(0xa000, 0xa000) AM_WRITE(nmiq_1_w)
AM_RANGE(0xa800, 0xa800) AM_WRITE(nmiq_2_w)
AM_RANGE(0xb000, 0xb007) AM_DEVWRITE("mainlatch", ls259_device, write_d0)
AM_RANGE(0xb800, 0xb800) AM_READ_PORT("DSW")
AM_RANGE(0xb801, 0xb801) AM_READ_PORT("SYSTEM")
@ -274,7 +316,8 @@ ADDRESS_MAP_END
static ADDRESS_MAP_START( shangkid_bbx_map, AS_PROGRAM, 8, shangkid_state )
AM_RANGE(0x0000, 0x9fff) AM_ROM
AM_RANGE(0xa000, 0xa000) AM_WRITENOP /* ? */
AM_RANGE(0xa000, 0xa000) AM_WRITE(nmiq_1_w)
AM_RANGE(0xa800, 0xa800) AM_WRITE(nmiq_2_w)
AM_RANGE(0xb000, 0xb007) AM_DEVWRITE("mainlatch", ls259_device, write_d0)
AM_RANGE(0xb800, 0xb800) AM_READ_PORT("DSW")
AM_RANGE(0xb801, 0xb801) AM_READ_PORT("SYSTEM")
@ -299,12 +342,12 @@ ADDRESS_MAP_END
static ADDRESS_MAP_START( chinhero_sound_map, AS_PROGRAM, 8, shangkid_state )
AM_RANGE(0x0000, 0xdfff) AM_ROM
AM_RANGE(0xe000, 0xefff) AM_RAM
AM_RANGE(0xe000, 0xe7ff) AM_RAM AM_MIRROR(0x0800)
ADDRESS_MAP_END
static ADDRESS_MAP_START( shangkid_sound_map, AS_PROGRAM, 8, shangkid_state )
AM_RANGE(0x0000, 0xdfff) AM_ROMBANK("bank2") /* sample player writes to ROM area */
AM_RANGE(0xe000, 0xefff) AM_RAM
AM_RANGE(0xe000, 0xe7ff) AM_RAM AM_MIRROR(0x0800)
ADDRESS_MAP_END
static ADDRESS_MAP_START( sound_portmap, AS_IO, 8, shangkid_state )
@ -319,27 +362,25 @@ static MACHINE_CONFIG_START( chinhero )
/* basic machine hardware */
MCFG_CPU_ADD("maincpu", Z80, XTAL_18_432MHz/6) /* verified on pcb */
MCFG_CPU_PROGRAM_MAP(chinhero_main_map)
MCFG_CPU_VBLANK_INT_DRIVER("screen", shangkid_state, irq0_line_hold)
MCFG_CPU_ADD("bbx", Z80, XTAL_18_432MHz/6) /* verified on pcb */
MCFG_CPU_PROGRAM_MAP(chinhero_bbx_map)
MCFG_CPU_IO_MAP(chinhero_bbx_portmap)
MCFG_CPU_VBLANK_INT_DRIVER("screen", shangkid_state, irq0_line_hold)
MCFG_CPU_ADD("audiocpu", Z80, XTAL_18_432MHz/6) /* verified on pcb */
MCFG_CPU_PROGRAM_MAP(chinhero_sound_map)
MCFG_CPU_IO_MAP(sound_portmap)
MCFG_DEVICE_ADD("mainlatch", LS259, 0)
MCFG_ADDRESSABLE_LATCH_Q0_OUT_CB(INPUTLINE("bbx", INPUT_LINE_HALT)) MCFG_DEVCB_INVERT
MCFG_ADDRESSABLE_LATCH_Q1_OUT_CB(WRITELINE(shangkid_state, sound_enable_w))
MCFG_ADDRESSABLE_LATCH_Q2_OUT_CB(NOOP) /* main CPU interrupt-related */
MCFG_ADDRESSABLE_LATCH_Q3_OUT_CB(NOOP) /* BBX interrupt-related */
MCFG_ADDRESSABLE_LATCH_Q4_OUT_CB(WRITELINE(shangkid_state, cpu_reset_w))
MCFG_ADDRESSABLE_LATCH_Q0_OUT_CB(INPUTLINE("bbx", INPUT_LINE_RESET)) MCFG_DEVCB_INVERT // RESET2
MCFG_ADDRESSABLE_LATCH_Q1_OUT_CB(INPUTLINE("audiocpu", INPUT_LINE_RESET)) MCFG_DEVCB_INVERT // RESET3
MCFG_DEVCB_CHAIN_OUTPUT(WRITELINE(shangkid_state, sound_enable_w))
MCFG_ADDRESSABLE_LATCH_Q2_OUT_CB(WRITELINE(shangkid_state, int_enable_1_w)) // INTE1
MCFG_ADDRESSABLE_LATCH_Q3_OUT_CB(WRITELINE(shangkid_state, int_enable_2_w)) // INTE2
MCFG_ADDRESSABLE_LATCH_Q4_OUT_CB(WRITELINE(shangkid_state, nmi_enable_1_w)) // NMIE1
MCFG_ADDRESSABLE_LATCH_Q5_OUT_CB(WRITELINE(shangkid_state, nmi_enable_2_w)) // NMIE2
MCFG_ADDRESSABLE_LATCH_Q6_OUT_CB(NOOP) /* coin counter */
MCFG_MACHINE_RESET_OVERRIDE(shangkid_state,chinhero)
MCFG_QUANTUM_TIME(attotime::from_hz(600))
/* video hardware */
@ -350,6 +391,8 @@ static MACHINE_CONFIG_START( chinhero )
MCFG_SCREEN_VISIBLE_AREA(16, 319-16, 0, 223)
MCFG_SCREEN_UPDATE_DRIVER(shangkid_state, screen_update_shangkid)
MCFG_SCREEN_PALETTE("palette")
MCFG_SCREEN_VBLANK_CALLBACK(WRITELINE(shangkid_state, irq_1_w))
MCFG_DEVCB_CHAIN_OUTPUT(WRITELINE(shangkid_state, irq_2_w))
MCFG_GFXDECODE_ADD("gfxdecode", "palette", chinhero)
MCFG_PALETTE_ADD_RRRRGGGGBBBB_PROMS("palette", "proms", 256)
@ -383,6 +426,8 @@ static MACHINE_CONFIG_DERIVED( shangkid, chinhero )
MCFG_CPU_PROGRAM_MAP(shangkid_sound_map)
MCFG_DEVICE_MODIFY("mainlatch")
// Q1 should *not* reset the AY-3-8910 here, or else banking writes will be lost!
MCFG_ADDRESSABLE_LATCH_Q1_OUT_CB(INPUTLINE("audiocpu", INPUT_LINE_RESET)) MCFG_DEVCB_INVERT
MCFG_ADDRESSABLE_LATCH_Q7_OUT_CB(MEMBANK("bank1"))
MCFG_MACHINE_RESET_OVERRIDE(shangkid_state,shangkid)
@ -403,8 +448,7 @@ static ADDRESS_MAP_START( dynamski_map, AS_PROGRAM, 8, shangkid_state )
AM_RANGE(0xc800, 0xcbff) AM_RAM
AM_RANGE(0xd000, 0xd3ff) AM_RAM
AM_RANGE(0xd800, 0xdbff) AM_RAM
AM_RANGE(0xe000, 0xe000) AM_WRITENOP /* IRQ disable */
AM_RANGE(0xe001, 0xe002) AM_RAM /* screen flip */
AM_RANGE(0xe000, 0xe007) AM_DEVWRITE("mainlatch", ls259_device, write_d0)
AM_RANGE(0xe800, 0xe800) AM_READ_PORT("SYSTEM")
AM_RANGE(0xe801, 0xe801) AM_READ_PORT("P1")
AM_RANGE(0xe802, 0xe802) AM_READ_PORT("P2")
@ -424,7 +468,11 @@ static MACHINE_CONFIG_START( dynamski )
MCFG_CPU_ADD("maincpu", Z80, 3000000) /* ? */
MCFG_CPU_PROGRAM_MAP(dynamski_map)
MCFG_CPU_IO_MAP(dynamski_portmap)
MCFG_CPU_VBLANK_INT_DRIVER("screen", shangkid_state, irq0_line_hold)
MCFG_DEVICE_ADD("mainlatch", LS259, 0)
MCFG_ADDRESSABLE_LATCH_Q0_OUT_CB(WRITELINE(shangkid_state, int_enable_1_w))
MCFG_ADDRESSABLE_LATCH_Q1_OUT_CB(NOOP) // screen flip?
MCFG_ADDRESSABLE_LATCH_Q2_OUT_CB(NOOP) // screen flip?
/* video hardware */
MCFG_SCREEN_ADD("screen", RASTER)
@ -434,6 +482,7 @@ static MACHINE_CONFIG_START( dynamski )
MCFG_SCREEN_VISIBLE_AREA(0, 255+32, 16, 255-16)
MCFG_SCREEN_UPDATE_DRIVER(shangkid_state, screen_update_dynamski)
MCFG_SCREEN_PALETTE("palette")
MCFG_SCREEN_VBLANK_CALLBACK(WRITELINE(shangkid_state, irq_1_w))
MCFG_GFXDECODE_ADD("gfxdecode", "palette", dynamski)
MCFG_PALETTE_ADD("palette", 16*4+16*4)
@ -986,7 +1035,7 @@ ROM_START( dynamski )
ROM_END
GAME( 1984, dynamski, 0, dynamski, dynamski, shangkid_state, 0, ROT90, "Taiyo", "Dynamic Ski", MACHINE_NO_COCKTAIL | MACHINE_SUPPORTS_SAVE )
GAME( 1984, dynamski, 0, dynamski, dynamski, shangkid_state, dynamski, ROT90, "Taiyo", "Dynamic Ski", MACHINE_NO_COCKTAIL | MACHINE_SUPPORTS_SAVE )
GAME( 1984, chinhero, 0, chinhero, chinhero, shangkid_state, chinhero, ROT90, "Taiyo", "Chinese Hero", MACHINE_SUPPORTS_SAVE ) // by Nihon Game?
GAME( 1984, chinhero2, chinhero, chinhero, chinhero, shangkid_state, chinhero, ROT90, "Taiyo", "Chinese Hero (older, set 1)", MACHINE_SUPPORTS_SAVE )
GAME( 1984, chinhero3, chinhero, chinhero, chinhero, shangkid_state, chinhero, ROT90, "Taiyo", "Chinese Hero (older, set 2)", MACHINE_SUPPORTS_SAVE )

View File

@ -1,5 +1,8 @@
// license:BSD-3-Clause
// copyright-holders:Phil Stroffolino
#include "sound/ay8910.h"
class shangkid_state : public driver_device
{
public:
@ -8,6 +11,7 @@ public:
m_maincpu(*this, "maincpu"),
m_audiocpu(*this, "audiocpu"),
m_bbx(*this, "bbx"),
m_aysnd(*this, "aysnd"),
m_gfxdecode(*this, "gfxdecode"),
m_palette(*this, "palette"),
m_videoram(*this, "videoram"),
@ -17,6 +21,7 @@ public:
required_device<cpu_device> m_maincpu;
optional_device<cpu_device> m_audiocpu;
optional_device<cpu_device> m_bbx;
required_device<ay8910_device> m_aysnd;
required_device<gfxdecode_device> m_gfxdecode;
required_device<palette_device> m_palette;
@ -24,14 +29,22 @@ public:
optional_shared_ptr<uint8_t> m_spriteram;
optional_shared_ptr<uint8_t> m_videoreg;
uint8_t m_bbx_sound_enable;
bool m_int_enable[2];
bool m_nmi_enable[2];
uint8_t m_sound_latch;
int m_gfx_type;
tilemap_t *m_background;
// shangkid and chinhero
DECLARE_WRITE_LINE_MEMBER(cpu_reset_w);
DECLARE_WRITE_LINE_MEMBER(sound_enable_w);
DECLARE_WRITE_LINE_MEMBER(int_enable_1_w);
DECLARE_WRITE_LINE_MEMBER(int_enable_2_w);
DECLARE_WRITE_LINE_MEMBER(nmi_enable_1_w);
DECLARE_WRITE_LINE_MEMBER(nmi_enable_2_w);
DECLARE_WRITE_LINE_MEMBER(irq_1_w);
DECLARE_WRITE_LINE_MEMBER(irq_2_w);
DECLARE_WRITE8_MEMBER(nmiq_1_w);
DECLARE_WRITE8_MEMBER(nmiq_2_w);
DECLARE_READ8_MEMBER(soundlatch_r);
DECLARE_WRITE8_MEMBER(videoram_w);
DECLARE_WRITE8_MEMBER(ay8910_portb_w);
@ -42,9 +55,9 @@ public:
TILE_GET_INFO_MEMBER(get_bg_tile_info);
DECLARE_DRIVER_INIT(dynamski);
DECLARE_DRIVER_INIT(shangkid);
DECLARE_DRIVER_INIT(chinhero);
DECLARE_MACHINE_RESET(chinhero);
DECLARE_VIDEO_START(shangkid);
DECLARE_PALETTE_INIT(dynamski);
DECLARE_MACHINE_RESET(shangkid);