From 287f7db3253041621b3000771d6db95a0c0fd578 Mon Sep 17 00:00:00 2001 From: AJR Date: Sun, 21 May 2023 06:05:33 -0400 Subject: subsino_m.cpp: Rename to subsino_crypt.cpp and don't hardcode region --- src/mame/subsino/subsino.cpp | 26 +++++---- src/mame/subsino/subsino2.cpp | 8 +-- src/mame/subsino/subsino_crypt.cpp | 94 ++++++++++++++++++++++++++++++ src/mame/subsino/subsino_crypt.h | 23 ++++++++ src/mame/subsino/subsino_m.cpp | 114 ------------------------------------- src/mame/subsino/subsino_m.h | 23 -------- 6 files changed, 135 insertions(+), 153 deletions(-) create mode 100644 src/mame/subsino/subsino_crypt.cpp create mode 100644 src/mame/subsino/subsino_crypt.h delete mode 100644 src/mame/subsino/subsino_m.cpp delete mode 100644 src/mame/subsino/subsino_m.h diff --git a/src/mame/subsino/subsino.cpp b/src/mame/subsino/subsino.cpp index c064e7f3bcb..14c9f9c4075 100644 --- a/src/mame/subsino/subsino.cpp +++ b/src/mame/subsino/subsino.cpp @@ -223,7 +223,7 @@ To Do: ***************************************************************************/ #include "emu.h" -#include "subsino_m.h" +#include "subsino_crypt.h" #include "cpu/z180/hd647180x.h" #include "machine/i8255.h" @@ -3901,7 +3901,8 @@ ROM_END void subsino_state::init_victor5() { - subsino_decrypt(machine(), victor5_bitswaps, victor5_xors, 0xc000); + uint8_t *rom = memregion( "maincpu" )->base(); + subsino_decrypt(rom, victor5_bitswaps, victor5_xors, 0xc000); m_flash_packet = 0; m_flash_packet_start = 0; @@ -3914,12 +3915,14 @@ void subsino_state::init_victor5() void subsino_state::init_victor21() { - subsino_decrypt(machine(), victor21_bitswaps, victor21_xors, 0xc000); + uint8_t *rom = memregion( "maincpu" )->base(); + subsino_decrypt(rom, victor21_bitswaps, victor21_xors, 0xc000); } void subsino_state::init_crsbingo() { - subsino_decrypt(machine(), crsbingo_bitswaps, crsbingo_xors, 0xc000); + uint8_t *rom = memregion( "maincpu" )->base(); + subsino_decrypt(rom, crsbingo_bitswaps, crsbingo_xors, 0xc000); m_flash_packet = 0; m_flash_packet_start = 0; @@ -3932,12 +3935,14 @@ void subsino_state::init_crsbingo() void subsino_state::init_sharkpy() { - subsino_decrypt(machine(), sharkpy_bitswaps, sharkpy_xors, 0xa000); + uint8_t *rom = memregion( "maincpu" )->base(); + subsino_decrypt(rom, sharkpy_bitswaps, sharkpy_xors, 0xa000); } void subsino_state::init_sharkpye() { - subsino_decrypt(machine(), victor5_bitswaps, victor5_xors, 0xa000); + uint8_t *rom = memregion( "maincpu" )->base(); + subsino_decrypt(rom, victor5_bitswaps, victor5_xors, 0xa000); } void subsino_state::init_smoto20() @@ -3955,8 +3960,7 @@ void subsino_state::init_smoto13() void subsino_state::init_tisub() { uint8_t *rom = memregion( "maincpu" )->base(); - - init_victor5(); + subsino_decrypt(rom, victor5_bitswaps, victor5_xors, 0xc000); /* this trips a z180 MMU core bug? It unmaps a region then the program code jumps to that region... */ rom[0x64c8] = 0x00; @@ -3970,8 +3974,7 @@ void subsino_state::init_tisub() void subsino_state::init_tisuba() { uint8_t *rom = memregion( "maincpu" )->base(); - - init_victor5(); + subsino_decrypt(rom, victor5_bitswaps, victor5_xors, 0xc000); /* this trips a z180 MMU core bug? It unmaps a region then the program code jumps to that region... */ rom[0x6491] = 0x00; @@ -3984,9 +3987,8 @@ void subsino_state::init_tisuba() void subsino_state::init_tisubb() { - subsino_decrypt(machine(), tisubb_bitswaps, tisubb_xors, 0xc000); - uint8_t *rom = memregion( "maincpu" )->base(); + subsino_decrypt(rom, tisubb_bitswaps, tisubb_xors, 0xc000); /* this trips a z180 MMU core bug? It unmaps a region then the program code jumps to that region... */ rom[0x60da] = 0x00; diff --git a/src/mame/subsino/subsino2.cpp b/src/mame/subsino/subsino2.cpp index 806845f92ad..b67c6a763bb 100644 --- a/src/mame/subsino/subsino2.cpp +++ b/src/mame/subsino/subsino2.cpp @@ -55,8 +55,8 @@ by the otherwise seemingly unnecessary internal ROMs. ************************************************************************************************************/ #include "emu.h" +#include "subsino_crypt.h" #include "subsino_io.h" -#include "subsino_m.h" #include "cpu/h8/h83048.h" #include "cpu/i86/i186.h" @@ -3583,7 +3583,7 @@ ROM_END void subsino2_state::init_mtrain() { - subsino_decrypt(machine(), crsbingo_bitswaps, crsbingo_xors, 0x8000); + subsino_decrypt(memregion("maincpu")->base(), crsbingo_bitswaps, crsbingo_xors, 0x8000); } @@ -3618,7 +3618,7 @@ ROM_END void subsino2_state::init_tbonusal() { - subsino_decrypt(machine(), sharkpy_bitswaps, sharkpy_xors, 0x8000); + subsino_decrypt(memregion("maincpu")->base(), sharkpy_bitswaps, sharkpy_xors, 0x8000); } /*************************************************************************** @@ -3919,7 +3919,7 @@ ROM_END void subsino2_state::init_wtrnymph() { - subsino_decrypt(machine(), victor5_bitswaps, victor5_xors, 0x8000); + subsino_decrypt(memregion("maincpu")->base(), victor5_bitswaps, victor5_xors, 0x8000); } GAME( 1996, mtrain, 0, mtrain, mtrain, subsino2_state, init_mtrain, ROT0, "Subsino", "Magic Train (Ver. 1.31)", 0 ) diff --git a/src/mame/subsino/subsino_crypt.cpp b/src/mame/subsino/subsino_crypt.cpp new file mode 100644 index 00000000000..2e7f71e5fff --- /dev/null +++ b/src/mame/subsino/subsino_crypt.cpp @@ -0,0 +1,94 @@ +// license:BSD-3-Clause +// copyright-holders:Luca Elia, David Haywood, Angelo Salese, Roberto Fresca +/*************************************************************************** + +Subsino XOR + Bitswap Encryption +by David Haywood + +***************************************************************************/ + +#include "emu.h" + +// XORs: + +extern const uint8_t crsbingo_xors[8] = { 0xbb, 0xcc, 0xcc, 0xdd, 0xaa, 0x11, 0x44, 0xee }; +extern const uint8_t sharkpy_xors [8] = { 0xcc, 0xaa, 0x66, 0xaa, 0xee, 0x33, 0xff, 0xff }; +extern const uint8_t tisubb_xors [8] = { 0x44, 0x99, 0x55, 0x77, 0xaa, 0x77, 0x88, 0x55 }; +extern const uint8_t victor5_xors [8] = { 0x99, 0x99, 0x33, 0x44, 0xbb, 0x88, 0x88, 0xbb }; +extern const uint8_t victor21_xors[8] = { 0x44, 0xbb, 0x66, 0x44, 0xaa, 0x55, 0x88, 0x22 }; + +// Bitswaps: + +void crsbingo_bitswaps(uint8_t *decrypt, int i) +{ + if ((i&7) == 0) decrypt[i] = bitswap<8>(decrypt[i], 7,2,5,4,3,6,1,0 ); + if ((i&7) == 1) decrypt[i] = bitswap<8>(decrypt[i], 7,2,1,0,3,6,5,4 ); + if ((i&7) == 2) decrypt[i] = bitswap<8>(decrypt[i], 3,2,5,0,7,6,1,4 ); + if ((i&7) == 3) decrypt[i] = bitswap<8>(decrypt[i], 7,2,5,0,3,6,1,4 ); + if ((i&7) == 4) decrypt[i] = bitswap<8>(decrypt[i], 7,6,5,0,3,2,1,4 ); + if ((i&7) == 5) decrypt[i] = bitswap<8>(decrypt[i], 7,2,1,4,3,6,5,0 ); + if ((i&7) == 6) decrypt[i] = bitswap<8>(decrypt[i], 7,2,1,0,3,6,5,4 ); + if ((i&7) == 7) decrypt[i] = bitswap<8>(decrypt[i], 3,2,1,0,7,6,5,4 ); +} + +void sharkpy_bitswaps(uint8_t *decrypt, int i) +{ + if ((i&7) == 0) decrypt[i] = bitswap<8>(decrypt[i], 3,2,1,0,7,6,5,4 ); + if ((i&7) == 1) decrypt[i] = bitswap<8>(decrypt[i], 7,2,5,4,3,6,1,0 ); + if ((i&7) == 2) decrypt[i] = bitswap<8>(decrypt[i], 7,2,1,4,3,6,5,0 ); + if ((i&7) == 3) decrypt[i] = bitswap<8>(decrypt[i], 3,6,1,0,7,2,5,4 ); + if ((i&7) == 4) decrypt[i] = bitswap<8>(decrypt[i], 7,2,5,4,3,6,1,0 ); + if ((i&7) == 5) decrypt[i] = bitswap<8>(decrypt[i], 3,2,5,4,7,6,1,0 ); + if ((i&7) == 6) decrypt[i] = bitswap<8>(decrypt[i], 7,6,1,4,3,2,5,0 ); + if ((i&7) == 7) decrypt[i] = bitswap<8>(decrypt[i], 3,6,1,4,7,2,5,0 ); +} + +void tisubb_bitswaps(uint8_t *decrypt, int i) +{ + if ((i&7) == 0) decrypt[i] = bitswap<8>(decrypt[i], 7,2,1,0,3,6,5,4 ); + if ((i&7) == 1) decrypt[i] = bitswap<8>(decrypt[i], 7,6,1,4,3,2,5,0 ); + if ((i&7) == 2) decrypt[i] = bitswap<8>(decrypt[i], 3,6,5,0,7,2,1,4 ); + if ((i&7) == 3) decrypt[i] = bitswap<8>(decrypt[i], 7,2,5,4,3,6,1,0 ); + if ((i&7) == 4) decrypt[i] = bitswap<8>(decrypt[i], 3,2,5,4,7,6,1,0 ); + if ((i&7) == 5) decrypt[i] = bitswap<8>(decrypt[i], 3,6,1,0,7,2,5,4 ); + if ((i&7) == 6) decrypt[i] = bitswap<8>(decrypt[i], 3,6,1,0,7,2,5,4 ); + if ((i&7) == 7) decrypt[i] = bitswap<8>(decrypt[i], 3,2,1,0,7,6,5,4 ); +} + +void victor5_bitswaps(uint8_t *decrypt, int i) +{ + if ((i&7) == 0) decrypt[i] = bitswap<8>(decrypt[i], 7,2,5,4,3,6,1,0 ); + if ((i&7) == 1) decrypt[i] = bitswap<8>(decrypt[i], 7,6,5,0,3,2,1,4 ); + if ((i&7) == 2) decrypt[i] = bitswap<8>(decrypt[i], 7,2,1,0,3,6,5,4 ); + if ((i&7) == 3) decrypt[i] = bitswap<8>(decrypt[i], 7,2,1,0,3,6,5,4 ); + if ((i&7) == 4) decrypt[i] = bitswap<8>(decrypt[i], 3,2,1,0,7,6,5,4 ); + if ((i&7) == 5) decrypt[i] = bitswap<8>(decrypt[i], 7,6,5,0,3,2,1,4 ); + if ((i&7) == 6) decrypt[i] = bitswap<8>(decrypt[i], 3,6,1,0,7,2,5,4 ); + if ((i&7) == 7) decrypt[i] = bitswap<8>(decrypt[i], 7,2,1,4,3,6,5,0 ); +} + +void victor21_bitswaps(uint8_t *decrypt, int i) +{ + if ((i&7) == 0) decrypt[i] = bitswap<8>(decrypt[i], 7,2,1,0,3,6,5,4 ); + if ((i&7) == 1) decrypt[i] = bitswap<8>(decrypt[i], 3,6,1,4,7,2,5,0 ); + if ((i&7) == 2) decrypt[i] = bitswap<8>(decrypt[i], 3,2,1,4,7,6,5,0 ); + if ((i&7) == 3) decrypt[i] = bitswap<8>(decrypt[i], 7,2,5,4,3,6,1,0 ); + if ((i&7) == 4) decrypt[i] = bitswap<8>(decrypt[i], 7,2,5,4,3,6,1,0 ); + if ((i&7) == 5) decrypt[i] = bitswap<8>(decrypt[i], 3,6,5,0,7,2,1,4 ); + if ((i&7) == 6) decrypt[i] = bitswap<8>(decrypt[i], 7,6,5,4,3,2,1,0 ); + if ((i&7) == 7) decrypt[i] = bitswap<8>(decrypt[i], 3,2,1,4,7,6,5,0 ); +} + +// Decrypt: + +void subsino_decrypt(uint8_t *region, void (*bitswaps)(uint8_t *decrypt, int i), const uint8_t *xors, int size) +{ + std::unique_ptr decrypt = std::make_unique(size); + + for (int i = 0; i < size; i++) + { + decrypt[i] = region[i] ^ xors[i & 7]; + bitswaps(decrypt.get(), i); + } + memcpy(region, decrypt.get(), size); +} diff --git a/src/mame/subsino/subsino_crypt.h b/src/mame/subsino/subsino_crypt.h new file mode 100644 index 00000000000..b9365fadd83 --- /dev/null +++ b/src/mame/subsino/subsino_crypt.h @@ -0,0 +1,23 @@ +// license:BSD-3-Clause +// copyright-holders:Luca Elia, David Haywood, Angelo Salese, Roberto Fresca +#ifndef MAME_SUBSINO_SUBSINO_CRYPT_H +#define MAME_SUBSINO_SUBSINO_CRYPT_H + +#pragma once + + +extern const uint8_t crsbingo_xors[8]; +extern const uint8_t sharkpy_xors [8]; +extern const uint8_t tisubb_xors [8]; +extern const uint8_t victor5_xors [8]; +extern const uint8_t victor21_xors[8]; + +void crsbingo_bitswaps(uint8_t *decrypt, int i); +void sharkpy_bitswaps (uint8_t *decrypt, int i); +void tisubb_bitswaps (uint8_t *decrypt, int i); +void victor5_bitswaps (uint8_t *decrypt, int i); +void victor21_bitswaps(uint8_t *decrypt, int i); + +void subsino_decrypt(uint8_t *region, void (*bitswaps)(uint8_t *decrypt, int i), const uint8_t *xors, int size); + +#endif // MAME_SUBSINO_SUBSINO_CRYPT_H diff --git a/src/mame/subsino/subsino_m.cpp b/src/mame/subsino/subsino_m.cpp deleted file mode 100644 index a162c503352..00000000000 --- a/src/mame/subsino/subsino_m.cpp +++ /dev/null @@ -1,114 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Luca Elia, David Haywood, Angelo Salese, Roberto Fresca -/*************************************************************************** - -Subsino XOR + Bitswap Encryption -by David Haywood - -***************************************************************************/ - -#include "emu.h" - -// XORs: - -extern const uint8_t crsbingo_xors[8] = { 0xbb, 0xcc, 0xcc, 0xdd, 0xaa, 0x11, 0x44, 0xee }; -extern const uint8_t sharkpy_xors [8] = { 0xcc, 0xaa, 0x66, 0xaa, 0xee, 0x33, 0xff, 0xff }; -extern const uint8_t tisubb_xors [8] = { 0x44, 0x99, 0x55, 0x77, 0xaa, 0x77, 0x88, 0x55 }; -extern const uint8_t victor5_xors [8] = { 0x99, 0x99, 0x33, 0x44, 0xbb, 0x88, 0x88, 0xbb }; -extern const uint8_t victor21_xors[8] = { 0x44, 0xbb, 0x66, 0x44, 0xaa, 0x55, 0x88, 0x22 }; - -// Bitswaps: - -void crsbingo_bitswaps(uint8_t *decrypt, int i) -{ - if ((i&7) == 0) decrypt[i] = bitswap<8>(decrypt[i], 7,2,5,4,3,6,1,0 ); - if ((i&7) == 1) decrypt[i] = bitswap<8>(decrypt[i], 7,2,1,0,3,6,5,4 ); - if ((i&7) == 2) decrypt[i] = bitswap<8>(decrypt[i], 3,2,5,0,7,6,1,4 ); - if ((i&7) == 3) decrypt[i] = bitswap<8>(decrypt[i], 7,2,5,0,3,6,1,4 ); - if ((i&7) == 4) decrypt[i] = bitswap<8>(decrypt[i], 7,6,5,0,3,2,1,4 ); - if ((i&7) == 5) decrypt[i] = bitswap<8>(decrypt[i], 7,2,1,4,3,6,5,0 ); - if ((i&7) == 6) decrypt[i] = bitswap<8>(decrypt[i], 7,2,1,0,3,6,5,4 ); - if ((i&7) == 7) decrypt[i] = bitswap<8>(decrypt[i], 3,2,1,0,7,6,5,4 ); -} - -void sharkpy_bitswaps(uint8_t *decrypt, int i) -{ - if ((i&7) == 0) decrypt[i] = bitswap<8>(decrypt[i], 3,2,1,0,7,6,5,4 ); - if ((i&7) == 1) decrypt[i] = bitswap<8>(decrypt[i], 7,2,5,4,3,6,1,0 ); - if ((i&7) == 2) decrypt[i] = bitswap<8>(decrypt[i], 7,2,1,4,3,6,5,0 ); - if ((i&7) == 3) decrypt[i] = bitswap<8>(decrypt[i], 3,6,1,0,7,2,5,4 ); - if ((i&7) == 4) decrypt[i] = bitswap<8>(decrypt[i], 7,2,5,4,3,6,1,0 ); - if ((i&7) == 5) decrypt[i] = bitswap<8>(decrypt[i], 3,2,5,4,7,6,1,0 ); - if ((i&7) == 6) decrypt[i] = bitswap<8>(decrypt[i], 7,6,1,4,3,2,5,0 ); - if ((i&7) == 7) decrypt[i] = bitswap<8>(decrypt[i], 3,6,1,4,7,2,5,0 ); -} - -void tisubb_bitswaps(uint8_t *decrypt, int i) -{ - if ((i&7) == 0) decrypt[i] = bitswap<8>(decrypt[i], 7,2,1,0,3,6,5,4 ); - if ((i&7) == 1) decrypt[i] = bitswap<8>(decrypt[i], 7,6,1,4,3,2,5,0 ); - if ((i&7) == 2) decrypt[i] = bitswap<8>(decrypt[i], 3,6,5,0,7,2,1,4 ); - if ((i&7) == 3) decrypt[i] = bitswap<8>(decrypt[i], 7,2,5,4,3,6,1,0 ); - if ((i&7) == 4) decrypt[i] = bitswap<8>(decrypt[i], 3,2,5,4,7,6,1,0 ); - if ((i&7) == 5) decrypt[i] = bitswap<8>(decrypt[i], 3,6,1,0,7,2,5,4 ); - if ((i&7) == 6) decrypt[i] = bitswap<8>(decrypt[i], 3,6,1,0,7,2,5,4 ); - if ((i&7) == 7) decrypt[i] = bitswap<8>(decrypt[i], 3,2,1,0,7,6,5,4 ); -} - -void victor5_bitswaps(uint8_t *decrypt, int i) -{ - if ((i&7) == 0) decrypt[i] = bitswap<8>(decrypt[i], 7,2,5,4,3,6,1,0 ); - if ((i&7) == 1) decrypt[i] = bitswap<8>(decrypt[i], 7,6,5,0,3,2,1,4 ); - if ((i&7) == 2) decrypt[i] = bitswap<8>(decrypt[i], 7,2,1,0,3,6,5,4 ); - if ((i&7) == 3) decrypt[i] = bitswap<8>(decrypt[i], 7,2,1,0,3,6,5,4 ); - if ((i&7) == 4) decrypt[i] = bitswap<8>(decrypt[i], 3,2,1,0,7,6,5,4 ); - if ((i&7) == 5) decrypt[i] = bitswap<8>(decrypt[i], 7,6,5,0,3,2,1,4 ); - if ((i&7) == 6) decrypt[i] = bitswap<8>(decrypt[i], 3,6,1,0,7,2,5,4 ); - if ((i&7) == 7) decrypt[i] = bitswap<8>(decrypt[i], 7,2,1,4,3,6,5,0 ); -} - -void victor21_bitswaps(uint8_t *decrypt, int i) -{ - if ((i&7) == 0) decrypt[i] = bitswap<8>(decrypt[i], 7,2,1,0,3,6,5,4 ); - if ((i&7) == 1) decrypt[i] = bitswap<8>(decrypt[i], 3,6,1,4,7,2,5,0 ); - if ((i&7) == 2) decrypt[i] = bitswap<8>(decrypt[i], 3,2,1,4,7,6,5,0 ); - if ((i&7) == 3) decrypt[i] = bitswap<8>(decrypt[i], 7,2,5,4,3,6,1,0 ); - if ((i&7) == 4) decrypt[i] = bitswap<8>(decrypt[i], 7,2,5,4,3,6,1,0 ); - if ((i&7) == 5) decrypt[i] = bitswap<8>(decrypt[i], 3,6,5,0,7,2,1,4 ); - if ((i&7) == 6) decrypt[i] = bitswap<8>(decrypt[i], 7,6,5,4,3,2,1,0 ); - if ((i&7) == 7) decrypt[i] = bitswap<8>(decrypt[i], 3,2,1,4,7,6,5,0 ); -} - -// Decrypt: - -[[maybe_unused]] static void dump_decrypted(running_machine& machine, uint8_t* decrypt) -{ - auto filename = "dat_" + std::string(machine.system().name); - auto fp = fopen(filename.c_str(), "w+b"); - if (fp) - { - fwrite(decrypt, 0x10000, 1, fp); - fclose(fp); - } -} - -void subsino_decrypt(running_machine& machine, void (*bitswaps)(uint8_t *decrypt, int i), const uint8_t *xors, int size) -{ - std::unique_ptr decrypt = std::make_unique(0x10000); - uint8_t *const region = machine.root_device().memregion("maincpu")->base(); - - for (int i = 0; i < 0x10000; i++) - { - if (i < size) - { - decrypt[i] = region[i] ^ xors[i & 7]; - bitswaps(decrypt.get(), i); - } - else - { - decrypt[i] = region[i]; - } - } -// dump_decrypted(machine, decrypt); - memcpy(region, decrypt.get(), 0x10000); -} diff --git a/src/mame/subsino/subsino_m.h b/src/mame/subsino/subsino_m.h deleted file mode 100644 index ffad2f463f0..00000000000 --- a/src/mame/subsino/subsino_m.h +++ /dev/null @@ -1,23 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Luca Elia, David Haywood, Angelo Salese, Roberto Fresca -#ifndef MAME_SUBSINO_SUBSINO_M_H -#define MAME_SUBSINO_SUBSINO_M_H - -#pragma once - - -extern const uint8_t crsbingo_xors[8]; -extern const uint8_t sharkpy_xors [8]; -extern const uint8_t tisubb_xors [8]; -extern const uint8_t victor5_xors [8]; -extern const uint8_t victor21_xors[8]; - -void crsbingo_bitswaps(uint8_t *decrypt, int i); -void sharkpy_bitswaps (uint8_t *decrypt, int i); -void tisubb_bitswaps (uint8_t *decrypt, int i); -void victor5_bitswaps (uint8_t *decrypt, int i); -void victor21_bitswaps(uint8_t *decrypt, int i); - -void subsino_decrypt(running_machine& machine, void (*bitswaps)(uint8_t *decrypt, int i), const uint8_t *xors, int size); - -#endif // MAME_SUBSINO_SUBSINO_M_H -- cgit v1.2.3