From 5391b74d56495a190c2d0a772b24cd34cc3a8d87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Banaan=20Ananas?= Date: Wed, 25 Sep 2013 19:25:52 +0000 Subject: [PATCH] protection emulation should be crashproof now --- src/mame/drivers/sidepckt.c | 155 +++++++++++++++-------------------- src/mame/includes/sidepckt.h | 33 +++++--- src/mame/video/sidepckt.c | 8 ++ 3 files changed, 98 insertions(+), 98 deletions(-) diff --git a/src/mame/drivers/sidepckt.c b/src/mame/drivers/sidepckt.c index ccc93d63c82..4a10a62a927 100644 --- a/src/mame/drivers/sidepckt.c +++ b/src/mame/drivers/sidepckt.c @@ -130,6 +130,15 @@ Stephh's notes (based on the games M6809 code and some tests) : #include "sound/3526intf.h" #include "includes/sidepckt.h" +// protection tables +static const UINT8 sidepckt_prot_table_1[0x10]={0x05,0x03,0x02,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}; +static const UINT8 sidepckt_prot_table_2[0x10]={0x8e,0x42,0xad,0x58,0xec,0x85,0xdd,0x4c,0xad,0x9f,0x00,0x4c,0x7e,0x42,0xa2,0xff}; +static const UINT8 sidepckt_prot_table_3[0x10]={0xbd,0x73,0x80,0xbd,0x73,0xa7,0xbd,0x73,0xe0,0x7e,0x72,0x56,0xff,0xff,0xff,0xff}; + +static const UINT8 sidepcktj_prot_table_1[0x10]={0x05,0x03,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}; +static const UINT8 sidepcktj_prot_table_2[0x10]={0x8e,0x42,0xb2,0x58,0xec,0x85,0xdd,0x4c,0xad,0x9f,0x00,0x4c,0x7e,0x42,0xa7,0xff}; +static const UINT8 sidepcktj_prot_table_3[0x10]={0xbd,0x71,0xc8,0xbd,0x71,0xef,0xbd,0x72,0x28,0x7e,0x70,0x9e,0xff,0xff,0xff,0xff}; + WRITE8_MEMBER(sidepckt_state::sound_cpu_command_w) { @@ -144,88 +153,38 @@ READ8_MEMBER(sidepckt_state::sidepckt_i8751_r) WRITE8_MEMBER(sidepckt_state::sidepckt_i8751_w) { - static const int table_1[]={5,3,2}; - static const int table_2[]={0x8e,0x42,0xad,0x58,0xec,0x85,0xdd,0x4c,0xad,0x9f,0x00,0x4c,0x7e,0x42,0xa2,0xff}; - static const int table_3[]={0xbd,0x73,0x80,0xbd,0x73,0xa7,0xbd,0x73,0xe0,0x7e,0x72,0x56,0xff,0xff,0xff,0xff}; - m_maincpu->set_input_line(M6809_FIRQ_LINE, HOLD_LINE); /* i8751 triggers FIRQ on main cpu */ /* This function takes multiple parameters */ - if (m_in_math==1) { - m_in_math=2; - m_i8751_return=m_math_param=data; + if (m_in_math == 1) + { + m_in_math = 2; + m_math_param = data; + m_i8751_return = m_math_param; } - else if (m_in_math==2) { - m_in_math=0; - m_i8751_return=m_math_param/data; + else if (m_in_math == 2) + { + m_in_math = 0; + m_i8751_return = (data) ? (m_math_param / data) : 0; } - else switch (data) { + else switch (data) + { case 1: /* ID Check */ - m_current_table=1; m_current_ptr=0; m_i8751_return=table_1[m_current_ptr++]; break; - case 2: /* Protection data (executable code) */ - m_current_table=2; m_current_ptr=0; m_i8751_return=table_2[m_current_ptr++]; break; - case 3: /* Protection data (executable code) */ - m_current_table=3; m_current_ptr=0; m_i8751_return=table_3[m_current_ptr++]; break; + m_current_table = data - 1; + m_current_ptr = 0; + case 6: /* Read table data */ + m_i8751_return = m_prot_table[m_current_table][m_current_ptr]; + m_current_ptr = (m_current_ptr + 1) & 0x0f; + break; case 4: /* Divide function - multiple parameters */ - m_in_math=1; - m_i8751_return=4; + m_in_math = 1; + m_i8751_return = 4; break; - case 6: /* Read table data */ - if (m_current_table==1) - { - assert(m_current_ptr >= 0 && m_current_ptr < ARRAY_LENGTH(table_1)); - m_i8751_return=table_1[m_current_ptr++]; - } - if (m_current_table==2) m_i8751_return=table_2[m_current_ptr++]; - if (m_current_table==3) m_i8751_return=table_3[m_current_ptr++]; - break; - } -} - -WRITE8_MEMBER(sidepckt_state::sidepctj_i8751_w) -{ - static const int table_1[]={5,3,0}; - static const int table_2[]={0x8e,0x42,0xb2,0x58,0xec,0x85,0xdd,0x4c,0xad,0x9f,0x00,0x4c,0x7e,0x42,0xa7,0xff}; - static const int table_3[]={0xbd,0x71,0xc8,0xbd,0x71,0xef,0xbd,0x72,0x28,0x7e,0x70,0x9e,0xff,0xff,0xff,0xff}; - - m_maincpu->set_input_line(M6809_FIRQ_LINE, HOLD_LINE); /* i8751 triggers FIRQ on main cpu */ - - /* This function takes multiple parameters */ - if (m_in_math==1) { - m_in_math=2; - m_i8751_return=m_math_param=data; - } - else if (m_in_math==2) { - m_in_math=0; - m_i8751_return=m_math_param/data; - } - else switch (data) { - case 1: /* ID Check */ - m_current_table=1; m_current_ptr=0; m_i8751_return=table_1[m_current_ptr++]; break; - - case 2: /* Protection data (executable code) */ - m_current_table=2; m_current_ptr=0; m_i8751_return=table_2[m_current_ptr++]; break; - - case 3: /* Protection data (executable code) */ - m_current_table=3; m_current_ptr=0; m_i8751_return=table_3[m_current_ptr++]; break; - - case 4: /* Divide function - multiple parameters */ - m_in_math=1; - m_i8751_return=4; - break; - - case 6: /* Read table data */ - if (m_current_table==1) - { - assert(m_current_ptr >= 0 && m_current_ptr < ARRAY_LENGTH(table_1)); - m_i8751_return=table_1[m_current_ptr++]; - } - if (m_current_table==2) m_i8751_return=table_2[m_current_ptr++]; - if (m_current_table==3) m_i8751_return=table_3[m_current_ptr++]; + default: break; } } @@ -246,11 +205,18 @@ static ADDRESS_MAP_START( sidepckt_map, AS_PROGRAM, 8, sidepckt_state ) AM_RANGE(0x3003, 0x3003) AM_READ_PORT("DSW2") AM_RANGE(0x3004, 0x3004) AM_WRITE(sound_cpu_command_w) AM_RANGE(0x300c, 0x300c) AM_READNOP AM_WRITE(sidepckt_flipscreen_w) -// AM_RANGE(0x3014, 0x3014) //i8751 read -// AM_RANGE(0x3018, 0x3018) //i8751 write + AM_RANGE(0x3014, 0x3014) AM_READ(sidepckt_i8751_r) + AM_RANGE(0x3018, 0x3018) AM_WRITE(sidepckt_i8751_w) AM_RANGE(0x4000, 0xffff) AM_ROM ADDRESS_MAP_END +static ADDRESS_MAP_START( sidepcktb_map, AS_PROGRAM, 8, sidepckt_state ) + AM_RANGE(0x3014, 0x3014) AM_READNOP + AM_RANGE(0x3018, 0x3018) AM_WRITENOP + AM_IMPORT_FROM( sidepckt_map ) +ADDRESS_MAP_END + + static ADDRESS_MAP_START( sound_map, AS_PROGRAM, 8, sidepckt_state ) AM_RANGE(0x0000, 0x0fff) AM_RAM AM_RANGE(0x1000, 0x1001) AM_DEVWRITE("ym1", ym2203_device, write) @@ -386,22 +352,29 @@ static GFXDECODE_START( sidepckt ) GFXDECODE_END +void sidepckt_state::machine_reset() +{ + m_i8751_return = 0; + m_current_ptr = 0; + m_current_table = 0; + m_in_math = 0; + m_math_param = 0; +} static MACHINE_CONFIG_START( sidepckt, sidepckt_state ) /* basic machine hardware */ - MCFG_CPU_ADD("maincpu", M6809, 2000000) /* 2 MHz */ + MCFG_CPU_ADD("maincpu", M6809, 2000000) /* 2 MHz */ MCFG_CPU_PROGRAM_MAP(sidepckt_map) - MCFG_CPU_VBLANK_INT_DRIVER("screen", sidepckt_state, nmi_line_pulse) + MCFG_CPU_VBLANK_INT_DRIVER("screen", sidepckt_state, nmi_line_pulse) - MCFG_CPU_ADD("audiocpu", M6502, 1500000) /* 1.5 MHz */ + MCFG_CPU_ADD("audiocpu", M6502, 1500000) /* 1.5 MHz */ MCFG_CPU_PROGRAM_MAP(sound_map) - /* NMIs are triggered by the main cpu */ /* video hardware */ MCFG_SCREEN_ADD("screen", RASTER) - MCFG_SCREEN_REFRESH_RATE(58) - MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500) /* not accurate */ /* VERIFY: May be 55 or 56 */) + MCFG_SCREEN_REFRESH_RATE(58) /* VERIFY: May be 55 or 56 */ + MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500) /* not accurate */ ) MCFG_SCREEN_SIZE(32*8, 32*8) MCFG_SCREEN_VISIBLE_AREA(0*8, 32*8-1, 2*8, 30*8-1) MCFG_SCREEN_UPDATE_DRIVER(sidepckt_state, screen_update_sidepckt) @@ -409,7 +382,6 @@ static MACHINE_CONFIG_START( sidepckt, sidepckt_state ) MCFG_GFXDECODE(sidepckt) MCFG_PALETTE_LENGTH(256) - /* sound hardware */ MCFG_SPEAKER_STANDARD_MONO("mono") @@ -421,6 +393,13 @@ static MACHINE_CONFIG_START( sidepckt, sidepckt_state ) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0) MACHINE_CONFIG_END +static MACHINE_CONFIG_DERIVED( sidepcktb, sidepckt ) + + /* basic machine hardware */ + MCFG_CPU_MODIFY("maincpu") + MCFG_CPU_PROGRAM_MAP(sidepcktb_map) +MACHINE_CONFIG_END + /*************************************************************************** @@ -504,17 +483,19 @@ ROM_END DRIVER_INIT_MEMBER(sidepckt_state,sidepckt) { - m_maincpu->space(AS_PROGRAM).install_read_handler(0x3014, 0x3014, read8_delegate(FUNC(sidepckt_state::sidepckt_i8751_r),this)); - m_maincpu->space(AS_PROGRAM).install_write_handler(0x3018, 0x3018, write8_delegate(FUNC(sidepckt_state::sidepckt_i8751_w),this)); + m_prot_table[0] = sidepckt_prot_table_1; + m_prot_table[1] = sidepckt_prot_table_2; + m_prot_table[2] = sidepckt_prot_table_3; } -DRIVER_INIT_MEMBER(sidepckt_state,sidepctj) +DRIVER_INIT_MEMBER(sidepckt_state,sidepcktj) { - m_maincpu->space(AS_PROGRAM).install_read_handler(0x3014, 0x3014, read8_delegate(FUNC(sidepckt_state::sidepckt_i8751_r),this)); - m_maincpu->space(AS_PROGRAM).install_write_handler(0x3018, 0x3018, write8_delegate(FUNC(sidepckt_state::sidepctj_i8751_w),this)); + m_prot_table[0] = sidepcktj_prot_table_1; + m_prot_table[1] = sidepcktj_prot_table_2; + m_prot_table[2] = sidepcktj_prot_table_3; } -GAME( 1986, sidepckt, 0, sidepckt, sidepckt, sidepckt_state, sidepckt, ROT0, "Data East Corporation", "Side Pocket (World)", GAME_NO_COCKTAIL ) -GAME( 1986, sidepcktj, sidepckt, sidepckt, sidepcktj, sidepckt_state, sidepctj, ROT0, "Data East Corporation", "Side Pocket (Japan)", GAME_NO_COCKTAIL ) -GAME( 1986, sidepcktb, sidepckt, sidepckt, sidepcktb, driver_device, 0, ROT0, "bootleg", "Side Pocket (bootleg)", GAME_NO_COCKTAIL ) +GAME( 1986, sidepckt, 0, sidepckt, sidepckt, sidepckt_state, sidepckt, ROT0, "Data East Corporation", "Side Pocket (World)", GAME_NO_COCKTAIL ) +GAME( 1986, sidepcktj, sidepckt, sidepckt, sidepcktj, sidepckt_state, sidepcktj, ROT0, "Data East Corporation", "Side Pocket (Japan)", GAME_NO_COCKTAIL ) +GAME( 1986, sidepcktb, sidepckt, sidepcktb, sidepcktb, driver_device, 0, ROT0, "bootleg", "Side Pocket (bootleg)", GAME_NO_COCKTAIL ) diff --git a/src/mame/includes/sidepckt.h b/src/mame/includes/sidepckt.h index 616dee04e8c..03ba5fd32ff 100644 --- a/src/mame/includes/sidepckt.h +++ b/src/mame/includes/sidepckt.h @@ -1,23 +1,35 @@ +/****************************************************************************** + + Data East Side Pocket hardware + +******************************************************************************/ + class sidepckt_state : public driver_device { public: sidepckt_state(const machine_config &mconfig, device_type type, const char *tag) : driver_device(mconfig, type, tag), + m_maincpu(*this, "maincpu"), + m_audiocpu(*this, "audiocpu"), m_videoram(*this, "videoram"), m_colorram(*this, "colorram"), - m_spriteram(*this, "spriteram"), - m_maincpu(*this, "maincpu"), - m_audiocpu(*this, "audiocpu") { } + m_spriteram(*this, "spriteram") + { } tilemap_t *m_bg_tilemap; + required_device m_maincpu; + required_device m_audiocpu; required_shared_ptr m_videoram; required_shared_ptr m_colorram; required_shared_ptr m_spriteram; - int m_i8751_return; - int m_current_ptr; - int m_current_table; - int m_in_math; - int m_math_param; + + const UINT8* m_prot_table[3]; + UINT8 m_i8751_return; + UINT8 m_current_ptr; + UINT8 m_current_table; + UINT8 m_in_math; + UINT8 m_math_param; + DECLARE_WRITE8_MEMBER(sound_cpu_command_w); DECLARE_READ8_MEMBER(sidepckt_i8751_r); DECLARE_WRITE8_MEMBER(sidepckt_i8751_w); @@ -26,12 +38,11 @@ public: DECLARE_WRITE8_MEMBER(sidepckt_colorram_w); DECLARE_WRITE8_MEMBER(sidepckt_flipscreen_w); DECLARE_DRIVER_INIT(sidepckt); - DECLARE_DRIVER_INIT(sidepctj); + DECLARE_DRIVER_INIT(sidepcktj); TILE_GET_INFO_MEMBER(get_tile_info); + virtual void machine_reset(); virtual void video_start(); virtual void palette_init(); UINT32 screen_update_sidepckt(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); void draw_sprites(bitmap_ind16 &bitmap,const rectangle &cliprect); - required_device m_maincpu; - required_device m_audiocpu; }; diff --git a/src/mame/video/sidepckt.c b/src/mame/video/sidepckt.c index bc47335b9f9..78f43286bdf 100644 --- a/src/mame/video/sidepckt.c +++ b/src/mame/video/sidepckt.c @@ -1,3 +1,11 @@ +/****************************************************************************** + + Data East Side Pocket hardware + + Functions to emulate the video hardware + +******************************************************************************/ + #include "emu.h" #include "includes/sidepckt.h"