// license:BSD-3-Clause // copyright-holders:Luca Elia, David Haywood #include "emu.h" #include "machine/jalcrpt.h" void phantasm_rom_decode(running_machine &machine, const char *region) { uint16_t *RAM = (uint16_t *) machine.root_device().memregion(region)->base(); int i, size = machine.root_device().memregion(region)->bytes(); if (size > 0x40000) size = 0x40000; for (i = 0 ; i < size/2 ; i++) { uint16_t x,y; x = RAM[i]; // [0] def0 189a bc56 7234 // [1] fdb9 7531 eca8 6420 // [2] 0123 4567 ba98 fedc #define BITSWAP_0 BITSWAP16(x,0xd,0xe,0xf,0x0,0x1,0x8,0x9,0xa,0xb,0xc,0x5,0x6,0x7,0x2,0x3,0x4) #define BITSWAP_1 BITSWAP16(x,0xf,0xd,0xb,0x9,0x7,0x5,0x3,0x1,0xe,0xc,0xa,0x8,0x6,0x4,0x2,0x0) #define BITSWAP_2 BITSWAP16(x,0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0xb,0xa,0x9,0x8,0xf,0xe,0xd,0xc) if (i < 0x08000/2) { if ( (i | (0x248/2)) != i ) {y = BITSWAP_0;} else {y = BITSWAP_1;} } else if (i < 0x10000/2) { y = BITSWAP_2; } else if (i < 0x18000/2) { if ( (i | (0x248/2)) != i ) {y = BITSWAP_0;} else {y = BITSWAP_1;} } else if (i < 0x20000/2) { y = BITSWAP_1; } else { y = BITSWAP_2; } #undef BITSWAP_0 #undef BITSWAP_1 #undef BITSWAP_2 RAM[i] = y; } } void astyanax_rom_decode(running_machine &machine, const char *region) { uint16_t *RAM = (uint16_t *) machine.root_device().memregion(region)->base(); int i, size = machine.root_device().memregion(region)->bytes(); if (size > 0x40000) size = 0x40000; for (i = 0 ; i < size/2 ; i++) { uint16_t x,y; x = RAM[i]; // [0] def0 a981 65cb 7234 // [1] fdb9 7531 8ace 0246 // [2] 4567 0123 ba98 fedc #define BITSWAP_0 BITSWAP16(x,0xd,0xe,0xf,0x0,0xa,0x9,0x8,0x1,0x6,0x5,0xc,0xb,0x7,0x2,0x3,0x4) #define BITSWAP_1 BITSWAP16(x,0xf,0xd,0xb,0x9,0x7,0x5,0x3,0x1,0x8,0xa,0xc,0xe,0x0,0x2,0x4,0x6) #define BITSWAP_2 BITSWAP16(x,0x4,0x5,0x6,0x7,0x0,0x1,0x2,0x3,0xb,0xa,0x9,0x8,0xf,0xe,0xd,0xc) if (i < 0x08000/2) { if ( (i | (0x248/2)) != i ) {y = BITSWAP_0;} else {y = BITSWAP_1;} } else if (i < 0x10000/2) { y = BITSWAP_2; } else if (i < 0x18000/2) { if ( (i | (0x248/2)) != i ) {y = BITSWAP_0;} else {y = BITSWAP_1;} } else if (i < 0x20000/2) { y = BITSWAP_1; } else { y = BITSWAP_2; } #undef BITSWAP_0 #undef BITSWAP_1 #undef BITSWAP_2 RAM[i] = y; } } void rodland_rom_decode(running_machine &machine, const char *region) { uint16_t *RAM = (uint16_t *) machine.root_device().memregion(region)->base(); int i, size = machine.root_device().memregion(region)->bytes(); if (size > 0x40000) size = 0x40000; for (i = 0 ; i < size/2 ; i++) { uint16_t x,y; x = RAM[i]; // [0] d0a9 6ebf 5c72 3814 [1] 4567 0123 ba98 fedc // [2] fdb9 ce07 5318 a246 [3] 4512 ed3b a967 08fc #define BITSWAP_0 BITSWAP16(x,0xd,0x0,0xa,0x9,0x6,0xe,0xb,0xf,0x5,0xc,0x7,0x2,0x3,0x8,0x1,0x4); #define BITSWAP_1 BITSWAP16(x,0x4,0x5,0x6,0x7,0x0,0x1,0x2,0x3,0xb,0xa,0x9,0x8,0xf,0xe,0xd,0xc); #define BITSWAP_2 BITSWAP16(x,0xf,0xd,0xb,0x9,0xc,0xe,0x0,0x7,0x5,0x3,0x1,0x8,0xa,0x2,0x4,0x6); #define BITSWAP_3 BITSWAP16(x,0x4,0x5,0x1,0x2,0xe,0xd,0x3,0xb,0xa,0x9,0x6,0x7,0x0,0x8,0xf,0xc); if (i < 0x08000/2) { if ( (i | (0x248/2)) != i ) {y = BITSWAP_0;} else {y = BITSWAP_1;} } else if (i < 0x10000/2) { if ( (i | (0x248/2)) != i ) {y = BITSWAP_2;} else {y = BITSWAP_3;} } else if (i < 0x18000/2) { if ( (i | (0x248/2)) != i ) {y = BITSWAP_0;} else {y = BITSWAP_1;} } else if (i < 0x20000/2) { y = BITSWAP_1; } else { y = BITSWAP_3; } #undef BITSWAP_0 #undef BITSWAP_1 #undef BITSWAP_2 #undef BITSWAP_3 RAM[i] = y; } } /********** DECRYPT **********/ /* 4 known types */ /* SS91022-10: desertwr, gratiaa, tp2m32, gametngk */ /* SS92046_01: bbbxing, f1superb, tetrisp, hayaosi2 */ /* SS92047-01: gratia, kirarast */ /* SS92048-01: p47aces, 47pie2, 47pie2o */ void ms32_rearrange_sprites(running_machine &machine, const char *region) { /* sprites are not encrypted, but we need to move the data around to handle them as 256x256 tiles */ int i; uint8_t *source_data; int source_size; source_data = machine.root_device().memregion ( region )->base(); source_size = machine.root_device().memregion( region )->bytes(); std::vector result_data(source_size); for(i=0; i> 5); result_data[i] = source_data[j]; } memcpy (source_data, &result_data[0], source_size); } void decrypt_ms32_tx(running_machine &machine, int addr_xor,int data_xor, const char *region) { int i; uint8_t *source_data; int source_size; source_data = machine.root_device().memregion ( region )->base(); source_size = machine.root_device().memregion( region )->bytes(); std::vector result_data(source_size); addr_xor ^= 0x1005d; for(i=0; ibase(); source_size = machine.root_device().memregion( region )->bytes(); std::vector result_data(source_size); addr_xor ^= 0xc1c5b; for(i=0; i