From 0dd80b1dbac1cce11dc9c7dcb050822cf94e61ae Mon Sep 17 00:00:00 2001 From: angelosa Date: Sat, 21 Apr 2018 17:22:06 +0200 Subject: galivan.cpp, terracre.cpp: rewritten NB1412M2 into a device [Angelo Salese] --- src/mame/drivers/galivan.cpp | 49 +++---------- src/mame/drivers/terracre.cpp | 155 ++++-------------------------------------- src/mame/includes/galivan.h | 25 ++++--- src/mame/includes/terracre.h | 24 ++++--- src/mame/machine/nb1412m2.cpp | 142 ++++++++++++++++++++++++++++++++++++++ src/mame/machine/nb1412m2.h | 66 ++++++++++++++++++ src/mame/machine/nb1413m3.h | 6 +- src/mame/machine/nb1414m4.cpp | 2 +- src/mame/machine/nb1414m4.h | 6 +- 9 files changed, 267 insertions(+), 208 deletions(-) create mode 100644 src/mame/machine/nb1412m2.cpp create mode 100644 src/mame/machine/nb1412m2.h diff --git a/src/mame/drivers/galivan.cpp b/src/mame/drivers/galivan.cpp index eb5b3101900..498b493e95e 100644 --- a/src/mame/drivers/galivan.cpp +++ b/src/mame/drivers/galivan.cpp @@ -58,41 +58,6 @@ READ8_MEMBER(galivan_state::IO_port_c0_r) return (0x58); /* To Avoid Reset on Ufo Robot dangar */ } -// simplified version of the 1412M2 in cop01 (needs to be device-ified) -READ8_MEMBER(galivan_state::prot_data_r) -{ - if(m_prot_command == 0x37) - { - uint16_t prot_offset = (m_prot_reg[1]<<8)|(m_prot_reg[2]); - uint8_t *prot_rom = memregion("prot_data")->base(); - uint8_t prot_adj = 0x44; - - //printf("%02x",(prot_rom[prot_offset] - 0x44) & 0xff); - - return prot_rom[prot_offset & 0x1fff] - prot_adj; // minus value correct? - } - - popmessage("%02x protection read used",m_prot_command); - - return 0; -} - -WRITE8_MEMBER(galivan_state::prot_data_w) -{ - if( m_prot_command >=0x32 && m_prot_command <=0x37 ) - { - m_prot_reg[m_prot_command-0x32] = data; - return; - } - - popmessage("%02x protection write used",m_prot_command); -} - -WRITE8_MEMBER(galivan_state::prot_address_w) -{ - m_prot_command = data; -} - void galivan_state::galivan_map(address_map &map) { map(0x0000, 0xbfff).rom(); @@ -132,12 +97,12 @@ void galivan_state::io_map(address_map &map) map(0xc0, 0xc0).r(this, FUNC(galivan_state::IO_port_c0_r)); /* dangar needs to return 0x58 */ } -void galivan_state::dangarj_io_map(address_map &map) +void dangarj_state::dangarj_io_map(address_map &map) { io_map(map); // 1412M2 - map(0x80, 0x80).rw(this, FUNC(galivan_state::prot_data_r), FUNC(galivan_state::prot_data_w)); - map(0x81, 0x81).w(this, FUNC(galivan_state::prot_address_w)); + map(0x80, 0x80).rw("prot_chip", FUNC(nb1412m2_device::data_r), FUNC(nb1412m2_device::data_w)); + map(0x81, 0x81).w("prot_chip", FUNC(nb1412m2_device::command_w)); } @@ -514,10 +479,12 @@ MACHINE_CONFIG_START(galivan_state::galivan) MCFG_SOUND_ROUTE_EX(0, "dac2", 1.0, DAC_VREF_POS_INPUT) MCFG_SOUND_ROUTE_EX(0, "dac2", -1.0, DAC_VREF_NEG_INPUT) MACHINE_CONFIG_END -MACHINE_CONFIG_START(galivan_state::dangarj) +MACHINE_CONFIG_START(dangarj_state::dangarj) galivan(config); MCFG_CPU_MODIFY("maincpu") MCFG_CPU_IO_MAP(dangarj_io_map) + + MCFG_DEVICE_ADD("prot_chip", NB1412M2, XTAL(8'000'000)) // divided by 2 maybe MACHINE_CONFIG_END MACHINE_CONFIG_START(galivan_state::ninjemak) @@ -844,7 +811,7 @@ ROM_START( dangarj ) /* all rom labels are simply numbers, with the owl logo and ROM_REGION( 0x0100, "user1", 0 ) ROM_LOAD( "82s129.7f", 0x0000, 0x0100, CRC(29bc6216) SHA1(1d7864ad06ad0cd5e3d1905fc6066bee1cd90995) ) /* sprite palette bank */ - ROM_REGION( 0x2000, "prot_data", 0 ) /* located on a daughter card DG-3 with an additional 8.00MHz OSC & Nichibutsu 1412M2 XBA (unknown MCU?) */ + ROM_REGION( 0x2000, "prot_chip", 0 ) /* located on a daughter card DG-3 with an additional 8.00MHz OSC & Nichibutsu 1412M2 XBA (unknown MCU?) */ ROM_LOAD( "dg-3.ic7.2764", 0x0000, 0x2000, CRC(84a56d26) SHA1(6a1cdac7b9e04ccbcc29491f37f7554d09ea6d34) ) ROM_END @@ -1240,7 +1207,7 @@ GAME( 1985, galivan2, galivan, galivan, galivan, galivan_state, 0, ROT27 GAME( 1985, galivan3, galivan, galivan, galivan, galivan_state, 0, ROT270, "Nichibutsu", "Cosmo Police Galivan (12/11/1985)", MACHINE_SUPPORTS_SAVE ) GAME( 1986, dangar, 0, galivan, dangar, galivan_state, 0, ROT270, "Nichibutsu", "Ufo Robo Dangar (4/07/1987)", MACHINE_SUPPORTS_SAVE ) GAME( 1986, dangara, dangar, galivan, dangar2, galivan_state, 0, ROT270, "Nichibutsu", "Ufo Robo Dangar (12/1/1986)", MACHINE_SUPPORTS_SAVE ) -GAME( 1986, dangarj, dangar, dangarj, dangar2, galivan_state, 0, ROT270, "Nichibutsu", "Ufo Robo Dangar (9/26/1986, Japan)", MACHINE_SUPPORTS_SAVE|MACHINE_IMPERFECT_SOUND ) // wrong BGM in game, no SFXs +GAME( 1986, dangarj, dangar, dangarj, dangar2, dangarj_state, 0, ROT270, "Nichibutsu", "Ufo Robo Dangar (9/26/1986, Japan)", MACHINE_SUPPORTS_SAVE|MACHINE_IMPERFECT_SOUND ) // wrong BGM in game, no SFXs GAME( 1986, dangarb, dangar, galivan, dangar2, galivan_state, 0, ROT270, "Nichibutsu", "Ufo Robo Dangar (9/26/1986, bootleg set 1)", MACHINE_SUPPORTS_SAVE ) // checks protection like dangarj but check readback is patched at 0x9d58 (also checks i/o port 0xc0?) GAME( 1986, dangarbt, dangar, galivan, dangarb, galivan_state, 0, ROT270, "bootleg", "Ufo Robo Dangar (9/26/1986, bootleg set 2)", MACHINE_SUPPORTS_SAVE ) // directly patched at entry point 0x9d44 GAME( 1986, ninjemak, 0, ninjemak, ninjemak, galivan_state, 0, ROT270, "Nichibutsu", "Ninja Emaki (US)", MACHINE_SUPPORTS_SAVE|MACHINE_UNEMULATED_PROTECTION ) diff --git a/src/mame/drivers/terracre.cpp b/src/mame/drivers/terracre.cpp index 091871f6154..a26cf0b0c1f 100644 --- a/src/mame/drivers/terracre.cpp +++ b/src/mame/drivers/terracre.cpp @@ -93,78 +93,6 @@ AT-2 #include "speaker.h" -#ifdef UNUSED_FUNCTION -/* -0000 5000 5341 4b45 5349 4755 5245 -0000 4000 0e4b 4154 5544 4f4e 0e0e -0000 3000 414e 4b41 4b45 5544 4f4e -0000 2000 0e0e 4b49 5455 4e45 0e0e -0000 1000 0e4b 414b 4553 4f42 410e -2079 0001 0004 4ed0 2079 0001 0008 -4ed0 7c -*/ - -// protection data left for reference -static const uint16_t mAmazonProtData[] = -{ - /* default high scores (0x40db4) - wrong data ? */ - 0x0000,0x5000,0x5341,0x4b45,0x5349,0x4755,0x5245, - 0x0000,0x4000,0x0e4b,0x4154,0x5544,0x4f4e,0x0e0e, - 0x0000,0x3000,0x414e,0x4b41,0x4b45,0x5544,0x4f4e, - 0x0000,0x2000,0x0e0e,0x4b49,0x5455,0x4e45,0x0e0e, - 0x0000,0x1000,0x0e4b,0x414b,0x4553,0x4f42,0x410e, - - /* code (0x40d92) */ - 0x4ef9,0x0000,0x62fa,0x0000,0x4ef9,0x0000,0x805E,0x0000, - 0xc800 /* checksum */ -}; - -/* -0000 5000 5341 4b45 5349 4755 5245 -0000 4000 0e4b 4154 5544 4f4e 0e0e -0000 3000 414e 4b41 4b45 5544 4f4e -0000 2000 0e0e 4b49 5455 4e45 0e0e -0000 1000 0e4b 414b 4553 4f42 410e -2079 0001 0004 4ed0 2079 0001 0008 -4ed0 7c - */ - -static const uint16_t mAmatelasProtData[] = -{ - /* default high scores (0x40db4) */ - 0x0000,0x5000,0x5341,0x4b45,0x5349,0x4755,0x5245, - 0x0000,0x4000,0x0e4b,0x4154,0x5544,0x4f4e,0x0e0e, - 0x0000,0x3000,0x414e,0x4b41,0x4b45,0x5544,0x4f4e, - 0x0000,0x2000,0x0e0e,0x4b49,0x5455,0x4e45,0x0e0e, - 0x0000,0x1000,0x0e4b,0x414b,0x4553,0x4f42,0x410e, - - /* code (0x40d92) */ - 0x4ef9,0x0000,0x632e,0x0000,0x4ef9,0x0000,0x80C2,0x0000, - 0x6100 /* checksum */ -}; - -/* -2079 0001 0004 4ed0 2079 0001 0008 -4ed0 7c - -It actually never jumps to 0x40dba? -*/ - -static const uint16_t mHoreKidProtData[] = -{ - /* N/A */ - 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, - 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, - 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, - 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, - 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, - - /* code (0x40dba) */ - 0x4e75,0x4e75,0x4e75,0x4e75,0x4e75,0x4e75,0x4e75,0x4e75, - 0x1800 /* checksum */ -}; -#endif - WRITE16_MEMBER(terracre_state::amazon_sound_w) { m_soundlatch->write(space,0,((data & 0x7f) << 1) | 1); @@ -176,61 +104,6 @@ READ8_MEMBER(terracre_state::soundlatch_clear_r) return 0; } -// 1412M2 -READ16_MEMBER(terracre_state::amazon_protection_r) -{ - if(m_mAmazonProtCmd == 0x37) - { - //m_mAmazonProtReg[4] bit 0 used on hiscore data (clear on code), 0x29f vs 0x29e (not an offset?) - //its usage is more variable in mightguy for whatever reason. - uint16_t prot_offset = (m_mAmazonProtReg[1]<<8)|(m_mAmazonProtReg[2]); - uint8_t *prot_rom = memregion("prot_data")->base(); - - //printf("Mode %02x:%04x %04x R -> %02x (fixed %02x)\n",m_mAmazonProtReg[0],prot_offset,(m_mAmazonProtReg[3]<<8)|(m_mAmazonProtReg[4]),prot_rom[prot_offset],(prot_rom[prot_offset] - 0x44) & 0xff); - - return prot_rom[prot_offset & 0x1fff] - 0x44; - } - - popmessage("unknown prot cmd R %02x",m_mAmazonProtCmd); - - return 0; -} - -WRITE16_MEMBER(terracre_state::amazon_protection_w) -{ - if( ACCESSING_BITS_0_7 ) - { - if( offset==1 ) - { - m_mAmazonProtCmd = data; - } - else - { - if( m_mAmazonProtCmd>=0x32 && m_mAmazonProtCmd<=0x37 ) - { - m_mAmazonProtReg[m_mAmazonProtCmd-0x32] = data; - - #if 0 - if(m_mAmazonProtCmd == 0x32) - { - for(int i=0;i<6;i++) - printf("%02x ",m_mAmazonProtReg[i]); - - printf("\n"); - } - #endif - } - } - } -} - -MACHINE_START_MEMBER(terracre_state,amazon) -{ - /* set up for save */ - save_item(NAME(m_mAmazonProtCmd)); - save_item(NAME(m_mAmazonProtReg)); -} - void terracre_state::terracre_map(address_map &map) { map(0x000000, 0x01ffff).rom(); @@ -271,10 +144,12 @@ void terracre_state::amazon_base_map(address_map &map) map(0x070000, 0x070003).noprw(); // protection (nop for bootlegs) } -void terracre_state::amazon_1412m2_map(address_map &map) +void amazon_state::amazon_1412m2_map(address_map &map) { amazon_base_map(map); - map(0x070000, 0x070003).rw(this, FUNC(terracre_state::amazon_protection_r), FUNC(terracre_state::amazon_protection_w)); + map(0x070000, 0x070001).rw("prot_chip", FUNC(nb1412m2_device::data_r), FUNC(nb1412m2_device::data_w)).umask16(0x00ff); + map(0x070002, 0x070003).w("prot_chip", FUNC(nb1412m2_device::command_w)).umask16(0x00ff); + } void terracre_state::sound_map(address_map &map) @@ -637,16 +512,14 @@ MACHINE_CONFIG_START(terracre_state::amazon_base) ym3526(config); MCFG_CPU_MODIFY("maincpu") MCFG_CPU_PROGRAM_MAP(amazon_base_map) - - MCFG_MACHINE_START_OVERRIDE(terracre_state,amazon) MACHINE_CONFIG_END -MACHINE_CONFIG_START(terracre_state::amazon_1412m2) +MACHINE_CONFIG_START(amazon_state::amazon_1412m2) amazon_base(config); MCFG_CPU_MODIFY("maincpu") MCFG_CPU_PROGRAM_MAP(amazon_1412m2_map) - // TODO: install 1412m2 here + MCFG_DEVICE_ADD("prot_chip", NB1412M2, XTAL(16'000'000)) // divided by 4 maybe MACHINE_CONFIG_END @@ -849,7 +722,7 @@ ROM_START( amazon ) ROM_REGION( 0x0100, "user1", 0 ) ROM_LOAD( "4e", 0x000, 0x100, CRC(035f2c7b) SHA1(36e32a50146631e763711b586936b2815600f52d) ) /* ctable */ - ROM_REGION( 0x2000, "prot_data", 0 ) /* unknown, mostly text */ + ROM_REGION( 0x2000, "prot_chip", 0 ) /* unknown, mostly text */ ROM_LOAD( "16.18g", 0x0000, 0x2000, CRC(1d8d592b) SHA1(be8d6df8b5926069ae2cbc1dc26e1fa92d63f297) ) ROM_END @@ -888,7 +761,7 @@ ROM_START( amatelas ) ROM_REGION( 0x0100, "user1", 0 ) ROM_LOAD( "4e", 0x000, 0x100, CRC(035f2c7b) SHA1(36e32a50146631e763711b586936b2815600f52d) ) /* ctable */ - ROM_REGION( 0x2000, "prot_data", 0 ) /* unknown, mostly text */ + ROM_REGION( 0x2000, "prot_chip", 0 ) /* unknown, mostly text */ ROM_LOAD( "16.18g", 0x0000, 0x2000, CRC(1d8d592b) SHA1(be8d6df8b5926069ae2cbc1dc26e1fa92d63f297) ) ROM_END @@ -928,7 +801,7 @@ ROM_START( horekid ) ROM_REGION( 0x0100, "user1", 0 ) ROM_LOAD( "kid_prom.4e", 0x000, 0x100, CRC(e4fb54ee) SHA1(aba89d347b24dc6680e6f25b4a6c0d6657bb6a83) ) /* ctable */ - ROM_REGION( 0x2000, "prot_data", 0 ) /* unknown, mostly text */ + ROM_REGION( 0x2000, "prot_chip", 0 ) /* unknown, mostly text */ ROM_LOAD( "horekid.17", 0x0000, 0x2000, CRC(1d8d592b) SHA1(be8d6df8b5926069ae2cbc1dc26e1fa92d63f297) ) ROM_END @@ -968,7 +841,7 @@ ROM_START( horekidb ) ROM_REGION( 0x0100, "user1", 0 ) ROM_LOAD( "kid_prom.4e", 0x000, 0x100, CRC(e4fb54ee) SHA1(aba89d347b24dc6680e6f25b4a6c0d6657bb6a83) ) /* ctable */ - ROM_REGION( 0x2000, "prot_data", 0 ) /* unknown, mostly text */ + ROM_REGION( 0x2000, "prot_chip", 0 ) /* unknown, mostly text */ ROM_LOAD( "horekid.17", 0x0000, 0x2000, CRC(1d8d592b) SHA1(be8d6df8b5926069ae2cbc1dc26e1fa92d63f297) ) ROM_END @@ -1024,10 +897,10 @@ GAME( 1985, terracrea,terracre, ym3526, terracre, terracre_state, 0, ROT GAME( 1985, terracren,terracre, ym2203, terracre, terracre_state, 0, ROT270, "Nichibutsu", "Terra Cresta (YM2203)", MACHINE_SUPPORTS_SAVE ) // later HW: supports 1412M2 device, see also mightguy.cpp -GAME( 1986, amazon, 0, amazon_1412m2, amazon, terracre_state, 0, ROT270, "Nichibutsu", "Soldier Girl Amazon", MACHINE_SUPPORTS_SAVE ) -GAME( 1986, amatelas, amazon, amazon_1412m2, amazon, terracre_state, 0, ROT270, "Nichibutsu", "Sei Senshi Amatelass", MACHINE_SUPPORTS_SAVE ) -GAME( 1987, horekid, 0, amazon_1412m2, horekid, terracre_state, 0, ROT270, "Nichibutsu", "Kid no Hore Hore Daisakusen", MACHINE_SUPPORTS_SAVE ) +GAME( 1986, amazon, 0, amazon_1412m2, amazon, amazon_state, 0, ROT270, "Nichibutsu", "Soldier Girl Amazon", MACHINE_SUPPORTS_SAVE ) +GAME( 1986, amatelas, amazon, amazon_1412m2, amazon, amazon_state, 0, ROT270, "Nichibutsu", "Sei Senshi Amatelass", MACHINE_SUPPORTS_SAVE ) +GAME( 1987, horekid, 0, amazon_1412m2, horekid, amazon_state, 0, ROT270, "Nichibutsu", "Kid no Hore Hore Daisakusen", MACHINE_SUPPORTS_SAVE ) // bootlegs -GAME( 1987, horekidb, horekid, amazon_base, horekid, terracre_state, 0, ROT270, "bootleg", "Kid no Hore Hore Daisakusen (bootleg)", MACHINE_SUPPORTS_SAVE ) +GAME( 1987, horekidb, horekid, amazon_base, horekid, terracre_state, 0, ROT270, "bootleg", "Kid no Hore Hore Daisakusen (bootleg)", MACHINE_SUPPORTS_SAVE ) GAME( 1987, boobhack, horekid, amazon_base, horekid, terracre_state, 0, ROT270, "bootleg", "Booby Kids (Italian manufactured graphic hack / bootleg of Kid no Hore Hore Daisakusen (bootleg))", MACHINE_SUPPORTS_SAVE ) diff --git a/src/mame/includes/galivan.h b/src/mame/includes/galivan.h index 7cec54ef92b..0038eb1db04 100644 --- a/src/mame/includes/galivan.h +++ b/src/mame/includes/galivan.h @@ -6,6 +6,7 @@ ***************************************************************************/ +#include "machine/nb1412m2.h" #include "machine/nb1414m4.h" #include "machine/gen_latch.h" #include "video/bufsprite.h" @@ -42,10 +43,6 @@ public: DECLARE_WRITE8_MEMBER(galivan_sound_command_w); DECLARE_READ8_MEMBER(soundlatch_clear_r); DECLARE_READ8_MEMBER(IO_port_c0_r); - DECLARE_WRITE8_MEMBER(prot_address_w); - DECLARE_WRITE8_MEMBER(prot_data_w); - DECLARE_READ8_MEMBER(prot_data_r); - DECLARE_WRITE8_MEMBER(blit_trigger_w); DECLARE_WRITE8_MEMBER(youmab_extra_bank_w); DECLARE_READ8_MEMBER(youmab_8a_r); @@ -78,19 +75,27 @@ public: required_device m_palette; required_device m_soundlatch; void galivan(machine_config &config); - void dangarj(machine_config &config); void ninjemak(machine_config &config); void youmab(machine_config &config); void galivan_map(address_map &map); void io_map(address_map &map); - void dangarj_io_map(address_map &map); void ninjemak_io_map(address_map &map); void ninjemak_map(address_map &map); void sound_io_map(address_map &map); void sound_map(address_map &map); +}; + +class dangarj_state : public galivan_state +{ +public: + dangarj_state(const machine_config &mconfig, device_type type, const char *tag) + : galivan_state(mconfig, type, tag), + m_prot(*this, "prot_chip") + {} + void dangarj(machine_config &config); + private: - // dangarj specific (to be removed from here) - uint8_t m_prot_command; - uint8_t m_prot_reg[6]; - uint8_t test; + required_device m_prot; + + void dangarj_io_map(address_map &map); }; diff --git a/src/mame/includes/terracre.h b/src/mame/includes/terracre.h index 61fe0ba2644..f6082ee1c30 100644 --- a/src/mame/includes/terracre.h +++ b/src/mame/includes/terracre.h @@ -1,6 +1,7 @@ // license:BSD-3-Clause // copyright-holders:Carlos A. Lozano +#include "machine/nb1412m2.h" #include "machine/gen_latch.h" #include "video/bufsprite.h" @@ -26,18 +27,12 @@ public: required_shared_ptr m_bg_videoram; required_shared_ptr m_fg_videoram; - // move to 1412m2 - uint8_t m_mAmazonProtCmd; - uint8_t m_mAmazonProtReg[6]; - uint16_t m_xscroll; uint16_t m_yscroll; tilemap_t *m_background; tilemap_t *m_foreground; DECLARE_WRITE16_MEMBER(amazon_sound_w); DECLARE_READ8_MEMBER(soundlatch_clear_r); - DECLARE_READ16_MEMBER(amazon_protection_r); - DECLARE_WRITE16_MEMBER(amazon_protection_w); DECLARE_WRITE16_MEMBER(amazon_background_w); DECLARE_WRITE16_MEMBER(amazon_foreground_w); DECLARE_WRITE16_MEMBER(amazon_flipscreen_w); @@ -47,17 +42,28 @@ public: TILE_GET_INFO_MEMBER(get_fg_tile_info); virtual void video_start() override; DECLARE_PALETTE_INIT(terracre); - DECLARE_MACHINE_START(amazon); uint32_t screen_update_amazon(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); void draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect ); void amazon_base(machine_config &config); - void amazon_1412m2(machine_config &config); void ym2203(machine_config &config); void ym3526(machine_config &config); - void amazon_1412m2_map(address_map &map); void amazon_base_map(address_map &map); void sound_2203_io_map(address_map &map); void sound_3526_io_map(address_map &map); void sound_map(address_map &map); void terracre_map(address_map &map); }; + +class amazon_state : public terracre_state +{ +public: + amazon_state(const machine_config &mconfig, device_type type, const char *tag) + : terracre_state(mconfig, type, tag), + m_prot(*this, "prot_chip") + {} + + void amazon_1412m2(machine_config &config); + void amazon_1412m2_map(address_map &map); +private: + required_device m_prot; +}; diff --git a/src/mame/machine/nb1412m2.cpp b/src/mame/machine/nb1412m2.cpp new file mode 100644 index 00000000000..047e9e2eda9 --- /dev/null +++ b/src/mame/machine/nb1412m2.cpp @@ -0,0 +1,142 @@ +// license:LGPL-2.1+ +// copyright-holders:Angelo Salese +/*************************************************************************** + +Nichibutsu 1412M2 device emulation + +Written by Angelo Salese + +Fancy data decrypter + timer + ? +Most creative usage is hooked up in Mighty Guy sound CPU, +other games just uses it as a much simpler protection chip providing code +snippets. +It is unknown at current stage if inside the chip there's a MCU +(with internal ROM). + +TODO: +- understand how Mighty Guy decrypts data (uses port adjuster in a + different way than the other games); + +Legacy notes from drivers: +- m_mAmazonProtReg[4] bit 0 used on hiscore data (clear on code), + 0x29f vs 0x29e (not an offset?) +- static const uint16_t mAmazonProtData[] = +{ + 0x0000,0x5000,0x5341,0x4b45,0x5349,0x4755,0x5245, <- default high scores (0x40db4) - wrong data ? + 0x0000,0x4000,0x0e4b,0x4154,0x5544,0x4f4e,0x0e0e, + 0x0000,0x3000,0x414e,0x4b41,0x4b45,0x5544,0x4f4e, + 0x0000,0x2000,0x0e0e,0x4b49,0x5455,0x4e45,0x0e0e, + 0x0000,0x1000,0x0e4b,0x414b,0x4553,0x4f42,0x410e, + + 0x4ef9,0x0000,0x62fa,0x0000,0x4ef9,0x0000,0x805E,0x0000, <- code (0x40d92) + 0xc800 <- checksum +}; +- static const uint16_t mAmatelasProtData[] = +{ + 0x0000,0x5000,0x5341,0x4b45,0x5349,0x4755,0x5245, <- default high scores (0x40db4) + 0x0000,0x4000,0x0e4b,0x4154,0x5544,0x4f4e,0x0e0e, + 0x0000,0x3000,0x414e,0x4b41,0x4b45,0x5544,0x4f4e, + 0x0000,0x2000,0x0e0e,0x4b49,0x5455,0x4e45,0x0e0e, + 0x0000,0x1000,0x0e4b,0x414b,0x4553,0x4f42,0x410e, + 0x4ef9,0x0000,0x632e,0x0000,0x4ef9,0x0000,0x80C2,0x0000, <- code (0x40d92) + 0x6100 <- checksum +}; +- static const uint16_t mHoreKidProtData[] = +{ + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, <- N/A + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + 0x4e75,0x4e75,0x4e75,0x4e75,0x4e75,0x4e75,0x4e75,0x4e75, <- code (0x40dba) It actually never jumps there? + 0x1800 <- checksum +}; + +***************************************************************************/ + +#include "emu.h" +#include "machine/nb1412m2.h" + + + +//************************************************************************** +// GLOBAL VARIABLES +//************************************************************************** + +// device type definition +DEFINE_DEVICE_TYPE(NB1412M2, nb1412m2_device, "nb1412m2", "NB1412M2 Mahjong Custom") + + +//************************************************************************** +// LIVE DEVICE +//************************************************************************** + +//------------------------------------------------- +// nb1412m2_device - constructor +//------------------------------------------------- + +nb1412m2_device::nb1412m2_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) + : device_t(mconfig, NB1412M2, tag, owner, clock) + , m_data(*this, DEVICE_SELF) +{ +} + + +//------------------------------------------------- +// device_start - device-specific startup +//------------------------------------------------- + +void nb1412m2_device::device_start() +{ + save_item(NAME(m_command)); + save_item(NAME(m_rom_address)); +} + + +//------------------------------------------------- +// device_reset - device-specific reset +//------------------------------------------------- + +void nb1412m2_device::device_reset() +{ + m_command = 0xff; + m_rom_address = 0; +} + + +//************************************************************************** +// READ/WRITE HANDLERS +//************************************************************************** + +READ8_MEMBER( nb1412m2_device::data_r ) +{ + if(m_command == 0x37) // readback from ROM data + { + // TODO: provided by commands 0x35 & 0x36 (maybe 0x32 too) + uint8_t prot_adj = 0x44; + + return m_data[m_rom_address & 0x1fff] - prot_adj; + } + + return 0; +} + +WRITE8_MEMBER( nb1412m2_device::data_w ) +{ + switch(m_command) + { + case 0x33: // rom hi + m_rom_address &= 0x00ff; + m_rom_address |= data << 8; + break; + case 0x34: // rom lo + m_rom_address &= 0xff00; + m_rom_address |= data; + break; + } +} + +WRITE8_MEMBER( nb1412m2_device::command_w ) +{ + m_command = data; +} diff --git a/src/mame/machine/nb1412m2.h b/src/mame/machine/nb1412m2.h new file mode 100644 index 00000000000..5df96f4a439 --- /dev/null +++ b/src/mame/machine/nb1412m2.h @@ -0,0 +1,66 @@ +// license:LGPL-2.1+ +// copyright-holders:Angelo Salese +/*************************************************************************** + +Nichibutsu 1412M2 device emulation + +***************************************************************************/ + +#ifndef MAME_MACHINE_NB1412M2_H +#define MAME_MACHINE_NB1412M2_H + +#pragma once + + + +//************************************************************************** +// INTERFACE CONFIGURATION MACROS +//************************************************************************** + +#define MCFG_NB1412M2_ADD(tag, freq) \ + MCFG_DEVICE_ADD((tag), NB1412M2, (freq)) + + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + +// ======================> nb1412m2_device + +class nb1412m2_device : public device_t +{ +public: + // construction/destruction + nb1412m2_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); + + // I/O operations + DECLARE_WRITE8_MEMBER( command_w ); + DECLARE_WRITE8_MEMBER( data_w ); + DECLARE_READ8_MEMBER( data_r ); + +protected: + // device-level overrides +// virtual void device_validity_check(validity_checker &valid) const override; +// virtual void device_add_mconfig(machine_config &config) override; + virtual void device_start() override; + virtual void device_reset() override; + +private: + uint8_t m_command; + uint16_t m_rom_address; + + required_region_ptr m_data; +}; + + +// device type definition +DECLARE_DEVICE_TYPE(NB1412M2, nb1412m2_device) + + + +//************************************************************************** +// GLOBAL VARIABLES +//************************************************************************** + + +#endif // MAME_MACHINE_NB1412M2_H diff --git a/src/mame/machine/nb1413m3.h b/src/mame/machine/nb1413m3.h index 30d62a002f1..3a871150d1a 100644 --- a/src/mame/machine/nb1413m3.h +++ b/src/mame/machine/nb1413m3.h @@ -7,8 +7,8 @@ Driver by Takahiro Nogi 1999/11/05 - ******************************************************************************/ -#ifndef MAME_INCLUDES_NB1413M3_H -#define MAME_INCLUDES_NB1413M3_H +#ifndef MAME_MACHINE_NB1413M3_H +#define MAME_MACHINE_NB1413M3_H #pragma once @@ -202,4 +202,4 @@ DECLARE_DEVICE_TYPE(NB1413M3, nb1413m3_device) #define MCFG_NB1413M3_ADD(_tag) \ MCFG_DEVICE_ADD(_tag, NB1413M3, 0) -#endif // MAME_INCLUDES_NB1413M3_H +#endif // MAME_MACHINE_NB1413M3_H diff --git a/src/mame/machine/nb1414m4.cpp b/src/mame/machine/nb1414m4.cpp index 103defd75af..57071cfdf0a 100644 --- a/src/mame/machine/nb1414m4.cpp +++ b/src/mame/machine/nb1414m4.cpp @@ -319,7 +319,7 @@ void nb1414m4_device::exec(uint16_t mcu_cmd, uint8_t *vram, uint16_t &scrollx, u case 0x8000: break; //Ninja Emaki, attract mode case 0xff00: break; //Ninja Emaki POST, presumably invalid default: - popmessage("NB 1414M4 executes %04x command, contact MAMEdev\n",mcu_cmd); + popmessage("NB 1414M4 executes %04x command, contact MAMEdev",mcu_cmd); break; } diff --git a/src/mame/machine/nb1414m4.h b/src/mame/machine/nb1414m4.h index bba25f89e12..8989e421417 100644 --- a/src/mame/machine/nb1414m4.h +++ b/src/mame/machine/nb1414m4.h @@ -1,7 +1,7 @@ // license:LGPL-2.1+ // copyright-holders:Angelo Salese -#ifndef MAME_INCLUDES_NB1414M4_H -#define MAME_INCLUDES_NB1414M4_H +#ifndef MAME_MACHINE_NB1414M4_H +#define MAME_MACHINE_NB1414M4_H #pragma once @@ -33,4 +33,4 @@ private: DECLARE_DEVICE_TYPE(NB1414M4, nb1414m4_device) -#endif // MAME_INCLUDES_NB1414M4_H +#endif // MAME_MACHINE_NB1414M4_H -- cgit v1.2.3