From 1782b0a9cecd8187f24de26b57a6d5956bdcc9ef Mon Sep 17 00:00:00 2001 From: HappyASR Date: Sat, 24 Aug 2024 02:23:46 +0800 Subject: igs/igs_m027.cpp: added decryption for lhdmg and lhdmgp. (#12683) [XingXing] --- src/mame/igs/igs_m027.cpp | 17 +++++++-- src/mame/igs/pgmcrypt.cpp | 90 +++++++++++++++++++++++++++++++++++++++++++++++ src/mame/igs/pgmcrypt.h | 2 ++ 3 files changed, 107 insertions(+), 2 deletions(-) diff --git a/src/mame/igs/igs_m027.cpp b/src/mame/igs/igs_m027.cpp index ea341a7e60c..a14fdad9ea5 100644 --- a/src/mame/igs/igs_m027.cpp +++ b/src/mame/igs/igs_m027.cpp @@ -99,6 +99,7 @@ private: u32 unk_r(); u32 unk2_r(); + u32 lhdmg_unk2_r(); void unk2_w(u32 data); void dsw_io_select_w(u32 data); @@ -421,6 +422,16 @@ u32 igs_m027_state::unk2_r() return 0xffffffef; } +u32 igs_m027_state::lhdmg_unk2_r() +{ + logerror("%s: lhdmg_unk2_r\n", machine().describe_context()); + + if (m_dsw_io_select & 1) + return 0xffffffff; + else + return 0xffffffff ^ 0x400000; +} + u32 igs_m027_state::unk_r() { // this is accessed as a byte, lower 2 bytes are read? @@ -1511,16 +1522,18 @@ void igs_m027_state::init_olympic5() void igs_m027_state::init_lhdmg() { - //lhdmg_decrypt(machine()); + lhdmg_decrypt(machine()); //qlgs_gfx_decrypt(machine()); //pgm_create_dummy_internal_arm_region(); + m_maincpu->space(AS_PROGRAM).install_read_handler(0x4000000c, 0x4000000f, read32smo_delegate(*this, FUNC(igs_m027_state::lhdmg_unk2_r))); } void igs_m027_state::init_lhdmgp() { - //lhdmgp_decrypt(machine()); + lhdmgp_decrypt(machine()); //qlgs_gfx_decrypt(machine()); //pgm_create_dummy_internal_arm_region(); + m_maincpu->space(AS_PROGRAM).install_read_handler(0x4000000c, 0x4000000f, read32smo_delegate(*this, FUNC(igs_m027_state::lhdmg_unk2_r))); } diff --git a/src/mame/igs/pgmcrypt.cpp b/src/mame/igs/pgmcrypt.cpp index 861d026c393..180993f37fd 100644 --- a/src/mame/igs/pgmcrypt.cpp +++ b/src/mame/igs/pgmcrypt.cpp @@ -2318,3 +2318,93 @@ void lthy_decrypt(running_machine &machine) src[i] = x; } } + + +static const uint8_t lhdmg_tab[0x100] = { + 0x13, 0x45, 0x21, 0xa1, 0x69, 0x9a, 0x05, 0xda, 0x7d, 0x10, 0xda, 0x7f, 0x34, 0x9f, 0xf3, 0x64, + 0x35, 0xf9, 0x16, 0x1c, 0xd4, 0x60, 0x02, 0xf3, 0x42, 0xc7, 0x42, 0x29, 0xf3, 0x2c, 0x31, 0x71, + 0x50, 0x35, 0x4e, 0xaa, 0x9f, 0x09, 0xc3, 0xdd, 0x2f, 0x72, 0x30, 0x77, 0xc7, 0x30, 0xbc, 0xc8, + 0x51, 0xa0, 0x5e, 0xbb, 0xc3, 0x8e, 0x69, 0xd7, 0x4f, 0x57, 0x56, 0x77, 0xcb, 0x43, 0xd6, 0x46, + 0x62, 0x21, 0x18, 0xfd, 0x7d, 0x24, 0x58, 0x61, 0xec, 0xfe, 0xa9, 0x77, 0x59, 0x3b, 0x03, 0x0a, + 0xef, 0xdf, 0x90, 0x60, 0x46, 0x43, 0x33, 0x38, 0x92, 0x2d, 0x5a, 0x08, 0x0d, 0x2f, 0x05, 0x75, + 0x3e, 0x60, 0x87, 0x22, 0xb7, 0xbf, 0xd6, 0xf9, 0x17, 0x86, 0xea, 0x02, 0xbe, 0x23, 0xba, 0xd3, + 0xdd, 0x0d, 0x3e, 0x8c, 0x65, 0xa0, 0xf8, 0xd8, 0x2f, 0x35, 0xc6, 0x26, 0x6c, 0x81, 0xe6, 0x29, + 0x50, 0x30, 0x4a, 0x8e, 0xfa, 0xc2, 0x1e, 0xfd, 0xa7, 0xa5, 0x98, 0x53, 0x18, 0x94, 0xff, 0x1d, + 0x41, 0x2f, 0xff, 0x58, 0x33, 0xdc, 0x2b, 0x67, 0x4b, 0xdd, 0xd3, 0x56, 0x9c, 0xb2, 0x09, 0x4e, + 0x9b, 0xb1, 0xee, 0x58, 0x0a, 0xe4, 0x42, 0x56, 0x26, 0x23, 0x2c, 0x3f, 0x14, 0x73, 0x46, 0x9a, + 0xa1, 0x42, 0x17, 0x12, 0xdb, 0xa2, 0xdd, 0x5d, 0x0c, 0xec, 0xdc, 0xf7, 0xc1, 0x76, 0xe0, 0x24, + 0x65, 0xef, 0x41, 0x83, 0x35, 0x38, 0x78, 0x0e, 0x65, 0x82, 0xe3, 0x55, 0x90, 0xa8, 0xd5, 0xf7, + 0x66, 0xcf, 0xe2, 0x61, 0x91, 0x3c, 0x69, 0xcb, 0xe7, 0x75, 0x62, 0x6f, 0xd7, 0x9b, 0x69, 0x0c, + 0x0d, 0x07, 0x0c, 0x9c, 0x68, 0x24, 0x51, 0x51, 0x1f, 0x8d, 0x8b, 0xd6, 0x2e, 0x67, 0x5f, 0xc3, + 0x07, 0x00, 0x12, 0x61, 0x77, 0xa8, 0x15, 0xa1, 0xd6, 0xd0, 0xd3, 0x57, 0x73, 0x62, 0xb9, 0xbb +}; + +void lhdmg_decrypt(running_machine &machine) +{ + auto const src = util::little_endian_cast(reinterpret_cast(machine.root_device().memregion("user1")->base())); + + int const rom_size = 0x80000; + + for (int i = 0; i < rom_size / 2; i++) + { + uint16_t x = src[i]; + + IGS27_CRYPT1 + IGS27_CRYPT2_ALT + IGS27_CRYPT3 + IGS27_CRYPT4 + IGS27_CRYPT5 + IGS27_CRYPT6_ALT + IGS27_CRYPT7 + IGS27_CRYPT8 + + x ^= lhdmg_tab[(i>> 1) & 0xff] << 8; + + src[i] = x; + } +} + + +static const uint8_t lhdmgp_tab[0x100] = { + 0x49, 0x47, 0x53, 0x30, 0x30, 0x36, 0x34, 0x52, 0x44, 0x34, 0x30, 0x33, 0x30, 0x31, 0x30, 0x36, + 0xc1, 0x2f, 0xac, 0x4b, 0xe1, 0x01, 0xd6, 0xfa, 0x77, 0x85, 0xbf, 0x2e,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, 0x86, 0x1c, 0x6c, 0xb9, 0x05, 0xe0, 0x96, 0xca, 0x67, 0xcd, 0x9d, 0xf7, 0x3d, + 0x7c, 0x48, 0x53, 0x23, 0x91, 0xcb, 0x6f, 0x8c, 0xf4, 0x2e, 0xb9, 0xd1, 0x4d, 0xfb, 0x15, 0x7a, + 0xc2, 0x2b, 0xb9, 0xcb, 0xf5, 0x53, 0x4e, 0x93, 0x38, 0x0b, 0x45, 0x31, 0x13, 0x9f, 0x76, 0xe7 +}; + +void lhdmgp_decrypt(running_machine &machine) +{ + auto const src = util::little_endian_cast(reinterpret_cast(machine.root_device().memregion("user1")->base())); + + int const rom_size = 0x80000; + + for (int i = 0; i < rom_size / 2; i++) + { + uint16_t x = src[i]; + + IGS27_CRYPT1 + IGS27_CRYPT2_ALT + IGS27_CRYPT3 + IGS27_CRYPT4 + IGS27_CRYPT5 + IGS27_CRYPT6_ALT + IGS27_CRYPT7 + IGS27_CRYPT8 + + x ^= lhdmgp_tab[(i>> 1) & 0xff] << 8; + + src[i] = x; + } +} diff --git a/src/mame/igs/pgmcrypt.h b/src/mame/igs/pgmcrypt.h index 944510fb7aa..f51e210ab93 100644 --- a/src/mame/igs/pgmcrypt.h +++ b/src/mame/igs/pgmcrypt.h @@ -53,3 +53,5 @@ void icescape_decrypt(running_machine &machine); void tripfev_decrypt(running_machine &machine); void wldfruit_decrypt(running_machine &machine); void lthy_decrypt(running_machine &machine); +void lhdmg_decrypt(running_machine &machine); +void lhdmgp_decrypt(running_machine &machine); -- cgit v1.2.3