summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author Nicola Salmoria <nicola@mamedev.org>2010-07-05 19:38:55 +0000
committer Nicola Salmoria <nicola@mamedev.org>2010-07-05 19:38:55 +0000
commit0664448c9d71ba4e7b333be7d804f2be7e440e84 (patch)
tree56994de8480b9e6d1c2f08ff1f8bd1394cbff4aa
parentc82cf78f3987713c71eea59e7ac1b8e7019d631a (diff)
divided segacrpt.c in two files, one for the old encryption and one for the new one.
-rw-r--r--.gitattributes2
-rw-r--r--src/mame/drivers/angelkds.c4
-rw-r--r--src/mame/drivers/appoooh.c4
-rw-r--r--src/mame/drivers/calorie.c4
-rw-r--r--src/mame/drivers/segae.c4
-rw-r--r--src/mame/drivers/system1.c13
-rw-r--r--src/mame/machine/segacrp2.c382
-rw-r--r--src/mame/machine/segacrp2.h9
-rw-r--r--src/mame/machine/segacrpt.c358
-rw-r--r--src/mame/machine/segacrpt.h10
-rw-r--r--src/mame/mame.mak1
11 files changed, 409 insertions, 382 deletions
diff --git a/.gitattributes b/.gitattributes
index bd4065032f6..70b92acff6a 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -3224,6 +3224,8 @@ src/mame/machine/s24fd.c svneol=native#text/plain
src/mame/machine/scramble.c svneol=native#text/plain
src/mame/machine/scudsp.c svneol=native#text/plain
src/mame/machine/scudsp.h svneol=native#text/plain
+src/mame/machine/segacrp2.c svneol=native#text/plain
+src/mame/machine/segacrp2.h svneol=native#text/plain
src/mame/machine/segacrpt.c svneol=native#text/plain
src/mame/machine/segacrpt.h svneol=native#text/plain
src/mame/machine/segag80.c svneol=native#text/plain
diff --git a/src/mame/drivers/angelkds.c b/src/mame/drivers/angelkds.c
index c5f8f542b9d..91cf36a662c 100644
--- a/src/mame/drivers/angelkds.c
+++ b/src/mame/drivers/angelkds.c
@@ -128,7 +128,7 @@ Dumped by Chackn
#include "emu.h"
#include "cpu/z80/z80.h"
-#include "machine/segacrpt.h"
+#include "machine/segacrp2.h"
#include "sound/2203intf.h"
#include "includes/angelkds.h"
@@ -762,7 +762,7 @@ static DRIVER_INIT( spcpostn )
{
UINT8 *RAM = memory_region(machine, "user1");
- spcpostn_decode(machine, "maincpu");
+ sega_317_0005_decode(machine, "maincpu");
memory_configure_bank(machine, "bank1", 0, 10, &RAM[0x0000], 0x4000);
}
diff --git a/src/mame/drivers/appoooh.c b/src/mame/drivers/appoooh.c
index ba6b19235ca..0d23fae8409 100644
--- a/src/mame/drivers/appoooh.c
+++ b/src/mame/drivers/appoooh.c
@@ -164,7 +164,7 @@ Language
#include "emu.h"
#include "cpu/z80/z80.h"
#include "includes/appoooh.h"
-#include "machine/segacrpt.h" // needed for robowres_decode
+#include "machine/segacrp2.h"
#include "sound/msm5205.h"
#include "sound/sn76496.h"
@@ -600,7 +600,7 @@ ROM_END
static DRIVER_INIT(robowres)
{
- robowres_decode(machine, "maincpu");
+ sega_315_5179_decode(machine, "maincpu");
}
static DRIVER_INIT(robowresb)
diff --git a/src/mame/drivers/calorie.c b/src/mame/drivers/calorie.c
index da174cf0153..3ea2673520f 100644
--- a/src/mame/drivers/calorie.c
+++ b/src/mame/drivers/calorie.c
@@ -79,7 +79,7 @@ Notes:
#include "emu.h"
#include "cpu/z80/z80.h"
-#include "machine/segacrpt.h"
+#include "machine/segacrp2.h"
#include "sound/ay8910.h"
@@ -549,7 +549,7 @@ ROM_END
static DRIVER_INIT( calorie )
{
- calorie_decode(machine, "maincpu");
+ sega_317_0004_decode(machine, "maincpu");
}
static DRIVER_INIT( calorieb )
diff --git a/src/mame/drivers/segae.c b/src/mame/drivers/segae.c
index 6f8942ddad2..d846b0e6270 100644
--- a/src/mame/drivers/segae.c
+++ b/src/mame/drivers/segae.c
@@ -297,7 +297,7 @@ covert megatech / megaplay drivers to use new code etc. etc.
#include "cpu/z80/z80.h"
#include "sound/sn76496.h"
#include "machine/mc8123.h"
-#include "machine/segacrpt.h"
+#include "machine/segacrp2.h"
#include "includes/segamsys.h"
/****************************************************************************************
@@ -996,7 +996,7 @@ static DRIVER_INIT( astrofl )
{
DRIVER_INIT_CALL(segasyse);
- astrofl_decode(machine, "maincpu");
+ sega_315_5177_decode(machine, "maincpu");
}
GAME( 1985, hangonjr, 0, systeme, hangonjr, hangonjr, ROT0, "Sega", "Hang-On Jr.", 0 )
diff --git a/src/mame/drivers/system1.c b/src/mame/drivers/system1.c
index 958c99bc4f2..74983cea8f6 100644
--- a/src/mame/drivers/system1.c
+++ b/src/mame/drivers/system1.c
@@ -194,6 +194,7 @@ Notes:
#include "machine/z80pio.h"
#include "machine/8255ppi.h"
#include "machine/segacrpt.h"
+#include "machine/segacrp2.h"
#include "machine/mc8123.h"
#include "sound/sn76496.h"
@@ -4515,19 +4516,19 @@ static DRIVER_INIT( seganinj ) { DRIVER_INIT_CALL(bank00); seganinj_decode(machi
static DRIVER_INIT( imsorry ) { DRIVER_INIT_CALL(bank00); imsorry_decode(machine, "maincpu"); }
static DRIVER_INIT( teddybb ) { DRIVER_INIT_CALL(bank00); teddybb_decode(machine, "maincpu"); }
static DRIVER_INIT( myheroj ) { DRIVER_INIT_CALL(bank00); myheroj_decode(machine, "maincpu"); }
-static DRIVER_INIT( 4dwarrio ) { DRIVER_INIT_CALL(bank00); fdwarrio_decode(machine, "maincpu"); }
-static DRIVER_INIT( wboy ) { DRIVER_INIT_CALL(bank00); astrofl_decode(machine, "maincpu"); }
-static DRIVER_INIT( wboy2 ) { DRIVER_INIT_CALL(bank00); wboy2_decode(machine, "maincpu"); }
+static DRIVER_INIT( 4dwarrio ) { DRIVER_INIT_CALL(bank00); sega_315_5162_decode(machine, "maincpu"); }
+static DRIVER_INIT( wboy ) { DRIVER_INIT_CALL(bank00); sega_315_5177_decode(machine, "maincpu"); }
+static DRIVER_INIT( wboy2 ) { DRIVER_INIT_CALL(bank00); sega_315_5178_decode(machine, "maincpu"); }
static DRIVER_INIT( wboyo ) { DRIVER_INIT_CALL(bank00); hvymetal_decode(machine, "maincpu"); }
static DRIVER_INIT( blockgal ) { DRIVER_INIT_CALL(bank00); mc8123_decrypt_rom(machine, "maincpu", "key", NULL, 0); }
static DRIVER_INIT( hvymetal ) { DRIVER_INIT_CALL(bank44); hvymetal_decode(machine, "maincpu"); }
-static DRIVER_INIT( gardia ) { DRIVER_INIT_CALL(bank44); gardia_decode(machine, "maincpu"); }
-static DRIVER_INIT( gardiab ) { DRIVER_INIT_CALL(bank44); gardiab_decode(machine, "maincpu"); }
+static DRIVER_INIT( gardia ) { DRIVER_INIT_CALL(bank44); sega_317_0006_decode(machine, "maincpu"); }
+static DRIVER_INIT( gardiab ) { DRIVER_INIT_CALL(bank44); sega_317_0007_decode(machine, "maincpu"); }
static DRIVER_INIT( wbml ) { DRIVER_INIT_CALL(bank0c); mc8123_decrypt_rom(machine, "maincpu", "key", "bank1", 4); }
static DRIVER_INIT( ufosensi ) { DRIVER_INIT_CALL(bank0c); mc8123_decrypt_rom(machine, "maincpu", "key", "bank1", 4); }
-static DRIVER_INIT( wboysys2 ) { DRIVER_INIT_CALL(bank0c); astrofl_decode(machine, "maincpu"); }
+static DRIVER_INIT( wboysys2 ) { DRIVER_INIT_CALL(bank0c); sega_315_5177_decode(machine, "maincpu"); }
static DRIVER_INIT( dakkochn )
diff --git a/src/mame/machine/segacrp2.c b/src/mame/machine/segacrp2.c
new file mode 100644
index 00000000000..0fc35c5eff6
--- /dev/null
+++ b/src/mame/machine/segacrp2.c
@@ -0,0 +1,382 @@
+/******************************************************************************
+
+ Sega encryption emulation by Nicola Salmoria
+
+
+ This encryption is an evolution of the one implemented in segacrpt.c.
+ It works on more data and address bits but apart from that it's essentially
+ the same.
+
+ The encryption affects D0, D2, D4, and D6, and depends on M1, A0, A3, A6, A9,
+ A12, and A14.
+
+ The encryption consists of a permutation of the four data bits, which can also
+ be inverted. Therefore there are 4! * 2^4 = 384 different possible encryptions.
+
+ An interesting peculiarity is that four games in the list below use an almost
+ identical key, just offset by one or more bytes. This leads to believe that
+ keys were generated using a PRNG like in other Sega encryptions (MC8123 etc.)
+ and the CPU part# used to skip the first N bytes.
+
+
+ List of encrypted games currently known:
+
+ CPU Part # Game Comments
+ 315-5162 4D Warriors & used I'm Sorry for k.p.a.
+ Rafflesia &
+ Wonder Boy (set 4)
+ 315-5177 Astro Flash &
+ Wonder Boy (set 1)
+ 315-5178 Wonder Boy (set 2) unencrypted version available
+ 315-5179 Robo-Wrestle 2001
+
+
+ The following games seem to use the same algorithm as the above ones, but
+ using a key which almost doesn't change
+
+ 317-0004 Calorie Kun unencrypted bootleg available
+ 317-0005 Space Position
+ 317-0006 Gardia (set 1)
+ 317-0007 Gardia (set 2)
+
+******************************************************************************/
+
+#include "emu.h"
+#include "segacrp2.h"
+
+
+/******************************************************************************
+
+ New encryption
+
+ This encryption is quite different from the older one. It permutates bits
+ D0, D2, D4 and D6, then inverts some of them.
+
+ The permutation and inversion depend on A0, A3, A6, A9, A12, and A14.
+
+******************************************************************************/
+
+static void sega_decode_2(running_machine *machine,const char *cputag,
+ const UINT8 opcode_xor[64],const int opcode_swap_select[64],
+ const UINT8 data_xor[64],const int data_swap_select[64])
+{
+ int A;
+ static const UINT8 swaptable[24][4] =
+ {
+ { 6,4,2,0 }, { 4,6,2,0 }, { 2,4,6,0 }, { 0,4,2,6 },
+ { 6,2,4,0 }, { 6,0,2,4 }, { 6,4,0,2 }, { 2,6,4,0 },
+ { 4,2,6,0 }, { 4,6,0,2 }, { 6,0,4,2 }, { 0,6,4,2 },
+ { 4,0,6,2 }, { 0,4,6,2 }, { 6,2,0,4 }, { 2,6,0,4 },
+ { 0,6,2,4 }, { 2,0,6,4 }, { 0,2,6,4 }, { 4,2,0,6 },
+ { 2,4,0,6 }, { 4,0,2,6 }, { 2,0,4,6 }, { 0,2,4,6 },
+ };
+
+
+ const address_space *space = cputag_get_address_space(machine, cputag, ADDRESS_SPACE_PROGRAM);
+ UINT8 *rom = memory_region(machine, cputag);
+ UINT8 *decrypted = auto_alloc_array(machine, UINT8, 0x8000);
+
+ memory_set_decrypted_region(space, 0x0000, 0x7fff, decrypted);
+
+
+ for (A = 0x0000;A < 0x8000;A++)
+ {
+ int row;
+ UINT8 src;
+ const UINT8 *tbl;
+
+
+ src = rom[A];
+
+ /* pick the translation table from bits 0, 3, 6, 9, 12 and 14 of the address */
+ row = (A & 1) + (((A >> 3) & 1) << 1) + (((A >> 6) & 1) << 2)
+ + (((A >> 9) & 1) << 3) + (((A >> 12) & 1) << 4) + (((A >> 14) & 1) << 5);
+
+ /* decode the opcodes */
+ tbl = swaptable[opcode_swap_select[row]];
+ decrypted[A] = BITSWAP8(src,7,tbl[0],5,tbl[1],3,tbl[2],1,tbl[3]) ^ opcode_xor[row];
+
+ /* decode the data */
+ tbl = swaptable[data_swap_select[row]];
+ rom[A] = BITSWAP8(src,7,tbl[0],5,tbl[1],3,tbl[2],1,tbl[3]) ^ data_xor[row];
+ }
+}
+
+
+
+void sega_315_5162_decode(running_machine *machine, const char *cputag)
+{
+ static const UINT8 opcode_xor[64] =
+ {
+ 0x40,0x50,0x44,0x54,0x41,0x51,0x45,0x55,
+ 0x40,0x50,0x44,0x54,0x41,0x51,0x45,0x55,
+ 0x40,0x50,0x44,0x54,0x41,0x51,0x45,0x55,
+ 0x40,0x50,0x44,0x54,0x41,0x51,0x45,0x55,
+ 0x40,0x50,0x44,0x54,0x41,0x51,0x45,0x55,
+ 0x40,0x50,0x44,0x54,0x41,0x51,0x45,0x55,
+ 0x40,0x50,0x44,0x54,0x41,0x51,0x45,0x55,
+ 0x40,0x50,0x44,0x54,0x41,0x51,0x45,0x55,
+ };
+
+ static const UINT8 data_xor[64] =
+ {
+ 0x10,0x04,0x14,0x01,0x11,0x05,0x15,0x00,
+ 0x10,0x04,0x14,0x01,0x11,0x05,0x15,0x00,
+ 0x10,0x04,0x14,0x01,0x11,0x05,0x15,0x00,
+ 0x10,0x04,0x14,0x01,0x11,0x05,0x15,0x00,
+ 0x10,0x04,0x14,0x01,0x11,0x05,0x15,0x00,
+ 0x10,0x04,0x14,0x01,0x11,0x05,0x15,0x00,
+ 0x10,0x04,0x14,0x01,0x11,0x05,0x15,0x00,
+ 0x10,0x04,0x14,0x01,0x11,0x05,0x15,0x00,
+ };
+
+ static const int opcode_swap_select[64] =
+ {
+ 4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,
+ 6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,
+ 8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,
+ 10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,
+ };
+
+ static const int data_swap_select[64] =
+ {
+ 4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,
+ 6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,
+ 8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,
+ 10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,
+ 12,
+ };
+
+
+ sega_decode_2(machine,cputag,opcode_xor,opcode_swap_select,data_xor,data_swap_select);
+}
+
+
+void sega_315_5177_decode(running_machine *machine, const char *cputag)
+{
+ static const UINT8 opcode_xor[64] =
+ {
+ 0x04,0x51,0x40,0x01,0x55,0x44,0x05,0x50,0x41,0x00,0x54,0x45,
+ 0x04,0x51,0x40,0x01,0x55,0x44,0x05,0x50,0x41,0x00,0x54,0x45,
+ 0x04,0x51,0x40,0x01,0x55,0x44,0x05,0x50,
+ 0x04,0x51,0x40,0x01,0x55,0x44,0x05,0x50,0x41,0x00,0x54,0x45,
+ 0x04,0x51,0x40,0x01,0x55,0x44,0x05,0x50,0x41,0x00,0x54,0x45,
+ 0x04,0x51,0x40,0x01,0x55,0x44,0x05,0x50,
+ };
+
+ static const UINT8 data_xor[64] =
+ {
+ 0x54,0x15,0x44,0x51,0x10,0x41,0x55,0x14,0x45,0x50,0x11,0x40,
+ 0x54,0x15,0x44,0x51,0x10,0x41,0x55,0x14,0x45,0x50,0x11,0x40,
+ 0x54,0x15,0x44,0x51,0x10,0x41,0x55,0x14,
+ 0x54,0x15,0x44,0x51,0x10,0x41,0x55,0x14,0x45,0x50,0x11,0x40,
+ 0x54,0x15,0x44,0x51,0x10,0x41,0x55,0x14,0x45,0x50,0x11,0x40,
+ 0x54,0x15,0x44,0x51,0x10,0x41,0x55,0x14,
+ };
+
+ static const int opcode_swap_select[64] =
+ {
+ 0,0,1,1,1,2,2,3,3,4,4,4,5,5,6,6,
+ 6,7,7,8,8,9,9,9,10,10,11,11,11,12,12,13,
+
+ 8,8,9,9,9,10,10,11,11,12,12,12,13,13,14,14,
+ 14,15,15,16,16,17,17,17,18,18,19,19,19,20,20,21,
+ };
+
+ static const int data_swap_select[64] =
+ {
+ 0,0,1,1,2,2,2,3,3,4,4,5,5,5,6,6,
+ 7,7,7,8,8,9,9,10,10,10,11,11,12,12,12,13,
+
+ 8,8,9,9,10,10,10,11,11,12,12,13,13,13,14,14,
+ 15,15,15,16,16,17,17,18,18,18,19,19,20,20,20,21,
+ };
+
+
+ sega_decode_2(machine,cputag,opcode_xor,opcode_swap_select,data_xor,data_swap_select);
+}
+
+
+void sega_315_5178_decode(running_machine *machine, const char *cputag)
+{
+ static const UINT8 opcode_xor[64] =
+ {
+ 0x00,0x45,0x11,0x01,0x44,0x10,0x55,0x05,0x41,0x14,0x04,0x40,0x15,0x51,
+ 0x01,0x44,0x10,0x00,0x45,0x11,0x54,0x04,0x40,0x15,0x05,0x41,0x14,0x50,
+ 0x00,0x45,0x11,0x01,
+ 0x00,0x45,0x11,0x01,0x44,0x10,0x55,0x05,0x41,0x14,0x04,0x40,0x15,0x51,
+ 0x01,0x44,0x10,0x00,0x45,0x11,0x54,0x04,0x40,0x15,0x05,0x41,0x14,0x50,
+ 0x00,0x45,0x11,0x01,
+ };
+
+ static const UINT8 data_xor[64] =
+ {
+ 0x55,0x05,0x41,0x14,0x50,0x00,0x15,0x51,0x01,0x44,0x10,0x55,0x05,0x11,
+ 0x54,0x04,0x40,0x15,0x51,0x01,0x14,0x50,0x00,0x45,0x11,0x54,0x04,0x10,
+ 0x55,0x05,0x41,0x14,
+ 0x55,0x05,0x41,0x14,0x50,0x00,0x15,0x51,0x01,0x44,0x10,0x55,0x05,0x11,
+ 0x54,0x04,0x40,0x15,0x51,0x01,0x14,0x50,0x00,0x45,0x11,0x54,0x04,0x10,
+ 0x55,0x05,0x41,0x14,
+ };
+
+ static const int opcode_swap_select[64] =
+ {
+ 2,
+ 5,1,5,1,5,
+ 0,4,0,4,0,4,
+ 7,3,7,3,7,3,
+ 6,2,6,2,6,
+ 1,5,1,5,1,5,
+ 0,4,0,
+
+ 10,
+ 13,9,13,9,13,
+ 8,12,8,12,8,12,
+ 15,11,15,11,15,11,
+ 14,10,14,10,14,
+ 9,13,9,13,9,13,
+ 8,12,8,
+ };
+
+ static const int data_swap_select[64] =
+ {
+ 3,7,3,7,3,7,
+ 2,6,2,6,2,
+ 5,1,5,1,5,1,
+ 4,0,4,0,4,
+ 8,
+ 3,7,3,7,3,
+ 6,2,6,2,
+
+ 11,15,11,15,11,15,
+ 10,14,10,14,10,
+ 13,9,13,9,13,9,
+ 12,8,12,8,12,
+ 16,
+ 11,15,11,15,11,
+ 14,10,14,10,
+ };
+
+
+ sega_decode_2(machine,cputag,opcode_xor,opcode_swap_select,data_xor,data_swap_select);
+}
+
+
+void sega_315_5179_decode(running_machine *machine, const char *cputag)
+{
+ static const UINT8 opcode_xor[64] =
+ {
+ 0x00,0x41,0x10,0x51,0x04,0x45,0x14, 0x00,0x41,0x10,0x51,0x04,0x45,0x14, 0x55,
+ 0x01,0x40,0x11,0x50,0x05,0x44,0x15, 0x01,0x40,0x11,0x50,0x05,0x44,0x15, 0x54,
+ 0x00,0x41,
+ 0x50,0x05,0x44,0x15,0x54,0x00,0x41, 0x50,0x05,0x44,0x15,0x54,0x00,0x41, 0x10,
+ 0x51,0x04,0x45,0x14,0x55,0x01,0x40, 0x51,0x04,0x45,0x14,0x55,0x01,0x40, 0x11,
+ 0x50,0x05
+ };
+
+ static const UINT8 data_xor[64] =
+ {
+ 0x45,0x14,0x55,0x01,0x40,0x11,0x50, 0x05,0x44,0x15,0x54,0x00,0x41,0x10, 0x05,
+ 0x44,0x15,0x54,0x00,0x41,0x10,0x51, 0x04,0x45,0x14,0x55,0x01,0x40,0x11, 0x04,
+ 0x45,0x14,
+ 0x00,0x41,0x10,0x51,0x04,0x45,0x14, 0x55,0x01,0x40,0x11,0x50,0x05,0x44, 0x55,
+ 0x01,0x40,0x11,0x50,0x05,0x44,0x15, 0x54,0x00,0x41,0x10,0x51,0x04,0x45, 0x54,
+ 0x00,0x41
+ };
+
+ static const int opcode_swap_select[64] =
+ {
+ 8,11,15,2,6,
+ 9,13,1,4,8,11,15,2,6,
+ 9,13,1,4,8,11,15,2,6,
+ 10,13,1,4,8,11,15,3,6,
+
+ 7,2,6,1,5,
+ 1,4,0,3,7,2,6,2,5,
+ 1,4,0,3,7,2,6,2,5,
+ 1,4,0,3,7,3,6,2,5,
+ };
+
+ static const int data_swap_select[64] =
+ {
+ 9,13,0,4,8,11,15,2,6,
+ 9,13,1,4,8,11,15,2,6,
+ 10,13,1,4,8,11,15,2,6,
+ 10,13,1,4,8,
+
+ 1,4,0,3,7,2,6,1,5,
+ 1,4,0,3,7,2,6,2,5,
+ 1,4,0,3,7,3,6,2,5,
+ 1,4,0,4,7,
+ };
+
+
+ sega_decode_2(machine,cputag,opcode_xor,opcode_swap_select,data_xor,data_swap_select);
+}
+
+
+/******************************************************************************
+
+ These games (all 317-xxxx CPUs) use the same algorithm, but the key doesn't
+ change much - just one or two positions shift in the table.
+
+******************************************************************************/
+
+static void sega_decode_317(running_machine *machine, const char *cputag, int order, int opcode_shift, int data_shift)
+{
+ static const UINT8 xor1_317[1+64] =
+ {
+ 0x54,
+ 0x14,0x15,0x41,0x14,0x50,0x55,0x05,0x41,0x01,0x10,0x51,0x05,0x11,0x05,0x14,0x55,
+ 0x41,0x05,0x04,0x41,0x14,0x10,0x45,0x50,0x00,0x45,0x00,0x00,0x00,0x45,0x00,0x00,
+ 0x54,0x04,0x15,0x10,0x04,0x05,0x11,0x44,0x04,0x01,0x05,0x00,0x44,0x15,0x40,0x45,
+ 0x10,0x15,0x51,0x50,0x00,0x15,0x51,0x44,0x15,0x04,0x44,0x44,0x50,0x10,0x04,0x04,
+ };
+
+ static const UINT8 xor2_317[2+64] =
+ {
+ 0x04,
+ 0x44,
+ 0x15,0x51,0x41,0x10,0x15,0x54,0x04,0x51,0x05,0x55,0x05,0x54,0x45,0x04,0x10,0x01,
+ 0x51,0x55,0x45,0x55,0x45,0x04,0x55,0x40,0x11,0x15,0x01,0x40,0x01,0x11,0x45,0x44,
+ 0x40,0x05,0x15,0x15,0x01,0x50,0x00,0x44,0x04,0x50,0x51,0x45,0x50,0x54,0x41,0x40,
+ 0x14,0x40,0x50,0x45,0x10,0x05,0x50,0x01,0x40,0x01,0x50,0x50,0x50,0x44,0x40,0x10,
+ };
+
+ static const int swap1_317[1+64] =
+ {
+ 7,
+ 1,11,23,17,23, 0,15,19,
+ 20,12,10, 0,18,18, 5,20,
+ 13, 0,18,14, 5, 6,10,21,
+ 1,11, 9, 3,21, 4, 1,17,
+ 5, 7,16,13,19,23,20, 2,
+ 10,23,23,15,10,12, 0,22,
+ 14, 6,15,11,17,15,21, 0,
+ 6, 1, 1,18, 5,15,15,20,
+ };
+
+ static const int swap2_317[2+64] =
+ {
+ 7,
+ 12,
+ 18, 8,21, 0,22,21,13,21,
+ 20,13,20,14, 6, 3, 5,20,
+ 8,20, 4, 8,17,22, 0, 0,
+ 6,17,17, 9, 0,16,13,21,
+ 3, 2,18, 6,11, 3, 3,18,
+ 18,19, 3, 0, 5, 0,11, 8,
+ 8, 1, 7, 2,10, 8,10, 2,
+ 1, 3,12,16, 0,17,10, 1,
+ };
+
+ if (order)
+ sega_decode_2( machine, cputag, xor2_317+opcode_shift, swap2_317+opcode_shift, xor1_317+data_shift, swap1_317+data_shift );
+ else
+ sega_decode_2( machine, cputag, xor1_317+opcode_shift, swap1_317+opcode_shift, xor2_317+data_shift, swap2_317+data_shift );
+}
+
+void sega_317_0004_decode(running_machine *machine, const char *cputag) { sega_decode_317( machine, cputag, 1, 0, 0 ); }
+void sega_317_0005_decode(running_machine *machine, const char *cputag) { sega_decode_317( machine, cputag, 0, 0, 1 ); }
+void sega_317_0006_decode(running_machine *machine, const char *cputag) { sega_decode_317( machine, cputag, 1, 1, 1 ); }
+void sega_317_0007_decode(running_machine *machine, const char *cputag) { sega_decode_317( machine, cputag, 0, 1, 2 ); }
diff --git a/src/mame/machine/segacrp2.h b/src/mame/machine/segacrp2.h
new file mode 100644
index 00000000000..e605df4e0ac
--- /dev/null
+++ b/src/mame/machine/segacrp2.h
@@ -0,0 +1,9 @@
+void sega_315_5162_decode(running_machine *machine, const char *cputag);
+void sega_315_5177_decode(running_machine *machine, const char *cputag);
+void sega_315_5178_decode(running_machine *machine, const char *cputag);
+void sega_315_5179_decode(running_machine *machine, const char *cputag);
+void sega_317_0004_decode(running_machine *machine, const char *cputag);
+void sega_317_0005_decode(running_machine *machine, const char *cputag);
+void sega_317_0006_decode(running_machine *machine, const char *cputag);
+void sega_317_0007_decode(running_machine *machine, const char *cputag);
+
diff --git a/src/mame/machine/segacrpt.c b/src/mame/machine/segacrpt.c
index 00a0722ed44..1fd4419d224 100644
--- a/src/mame/machine/segacrpt.c
+++ b/src/mame/machine/segacrpt.c
@@ -136,26 +136,6 @@
???-???? Lovely Cards
- The following games use a different encryption algorithm:
-
- 315-5162 4D Warriors & used I'm Sorry for k.p.a.
- Rafflesia &
- Wonder Boy (set 4)
- 315-5177 Astro Flash &
- Wonder Boy (set 1)
- 315-5178 Wonder Boy (set 2) unencrypted version available
- 315-5179 Robo-Wrestle 2001
-
-
- The following games seem to use the same algorithm as the above ones, but
- using a key which almost doesn't change
-
- 317-0004 Calorie Kun unencrypted bootleg available
- 317-0005 Space Position
- 317-0006 Gardia (set 1)
- 317-0007 Gardia (set 2)
-
-
Some text found in the ROMs:
Buck Rogers SECULITY BY MASATOSHI,MIZUNAGA
@@ -1087,341 +1067,3 @@ void lvcards_decode(running_machine *machine, const char *cputag)
sega_decode(machine, cputag, convtable);
}
-
-
-
-/******************************************************************************
-
- New encryption
-
- This encryption is quite different from the older one. It permutates bits
- D0, D2, D4 and D6, then inverts some of them.
-
- The permutation and inversion depend on A0, A3, A6, A9, A12, and A14.
-
-******************************************************************************/
-
-static void sega_decode_2(running_machine *machine,const char *cputag,
- const UINT8 opcode_xor[64],const int opcode_swap_select[64],
- const UINT8 data_xor[64],const int data_swap_select[64])
-{
- int A;
- static const UINT8 swaptable[24][4] =
- {
- { 6,4,2,0 }, { 4,6,2,0 }, { 2,4,6,0 }, { 0,4,2,6 },
- { 6,2,4,0 }, { 6,0,2,4 }, { 6,4,0,2 }, { 2,6,4,0 },
- { 4,2,6,0 }, { 4,6,0,2 }, { 6,0,4,2 }, { 0,6,4,2 },
- { 4,0,6,2 }, { 0,4,6,2 }, { 6,2,0,4 }, { 2,6,0,4 },
- { 0,6,2,4 }, { 2,0,6,4 }, { 0,2,6,4 }, { 4,2,0,6 },
- { 2,4,0,6 }, { 4,0,2,6 }, { 2,0,4,6 }, { 0,2,4,6 },
- };
-
-
- const address_space *space = cputag_get_address_space(machine, cputag, ADDRESS_SPACE_PROGRAM);
- UINT8 *rom = memory_region(machine, cputag);
- UINT8 *decrypted = auto_alloc_array(machine, UINT8, 0x8000);
-
- memory_set_decrypted_region(space, 0x0000, 0x7fff, decrypted);
-
-
- for (A = 0x0000;A < 0x8000;A++)
- {
- int row;
- UINT8 src;
- const UINT8 *tbl;
-
-
- src = rom[A];
-
- /* pick the translation table from bits 0, 3, 6, 9, 12 and 14 of the address */
- row = (A & 1) + (((A >> 3) & 1) << 1) + (((A >> 6) & 1) << 2)
- + (((A >> 9) & 1) << 3) + (((A >> 12) & 1) << 4) + (((A >> 14) & 1) << 5);
-
- /* decode the opcodes */
- tbl = swaptable[opcode_swap_select[row]];
- decrypted[A] = BITSWAP8(src,7,tbl[0],5,tbl[1],3,tbl[2],1,tbl[3]) ^ opcode_xor[row];
-
- /* decode the data */
- tbl = swaptable[data_swap_select[row]];
- rom[A] = BITSWAP8(src,7,tbl[0],5,tbl[1],3,tbl[2],1,tbl[3]) ^ data_xor[row];
- }
-}
-
-
-
-void fdwarrio_decode(running_machine *machine, const char *cputag)
-{
- static const UINT8 opcode_xor[64] =
- {
- 0x40,0x50,0x44,0x54,0x41,0x51,0x45,0x55,
- 0x40,0x50,0x44,0x54,0x41,0x51,0x45,0x55,
- 0x40,0x50,0x44,0x54,0x41,0x51,0x45,0x55,
- 0x40,0x50,0x44,0x54,0x41,0x51,0x45,0x55,
- 0x40,0x50,0x44,0x54,0x41,0x51,0x45,0x55,
- 0x40,0x50,0x44,0x54,0x41,0x51,0x45,0x55,
- 0x40,0x50,0x44,0x54,0x41,0x51,0x45,0x55,
- 0x40,0x50,0x44,0x54,0x41,0x51,0x45,0x55,
- };
-
- static const UINT8 data_xor[64] =
- {
- 0x10,0x04,0x14,0x01,0x11,0x05,0x15,0x00,
- 0x10,0x04,0x14,0x01,0x11,0x05,0x15,0x00,
- 0x10,0x04,0x14,0x01,0x11,0x05,0x15,0x00,
- 0x10,0x04,0x14,0x01,0x11,0x05,0x15,0x00,
- 0x10,0x04,0x14,0x01,0x11,0x05,0x15,0x00,
- 0x10,0x04,0x14,0x01,0x11,0x05,0x15,0x00,
- 0x10,0x04,0x14,0x01,0x11,0x05,0x15,0x00,
- 0x10,0x04,0x14,0x01,0x11,0x05,0x15,0x00,
- };
-
- static const int opcode_swap_select[64] =
- {
- 4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,
- 6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,
- 8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,
- 10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,
- };
-
- static const int data_swap_select[64] =
- {
- 4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,
- 6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,
- 8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,
- 10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,
- 12,
- };
-
-
- sega_decode_2(machine,cputag,opcode_xor,opcode_swap_select,data_xor,data_swap_select);
-}
-
-
-void astrofl_decode(running_machine *machine, const char *cputag)
-{
- static const UINT8 opcode_xor[64] =
- {
- 0x04,0x51,0x40,0x01,0x55,0x44,0x05,0x50,0x41,0x00,0x54,0x45,
- 0x04,0x51,0x40,0x01,0x55,0x44,0x05,0x50,0x41,0x00,0x54,0x45,
- 0x04,0x51,0x40,0x01,0x55,0x44,0x05,0x50,
- 0x04,0x51,0x40,0x01,0x55,0x44,0x05,0x50,0x41,0x00,0x54,0x45,
- 0x04,0x51,0x40,0x01,0x55,0x44,0x05,0x50,0x41,0x00,0x54,0x45,
- 0x04,0x51,0x40,0x01,0x55,0x44,0x05,0x50,
- };
-
- static const UINT8 data_xor[64] =
- {
- 0x54,0x15,0x44,0x51,0x10,0x41,0x55,0x14,0x45,0x50,0x11,0x40,
- 0x54,0x15,0x44,0x51,0x10,0x41,0x55,0x14,0x45,0x50,0x11,0x40,
- 0x54,0x15,0x44,0x51,0x10,0x41,0x55,0x14,
- 0x54,0x15,0x44,0x51,0x10,0x41,0x55,0x14,0x45,0x50,0x11,0x40,
- 0x54,0x15,0x44,0x51,0x10,0x41,0x55,0x14,0x45,0x50,0x11,0x40,
- 0x54,0x15,0x44,0x51,0x10,0x41,0x55,0x14,
- };
-
- static const int opcode_swap_select[64] =
- {
- 0,0,1,1,1,2,2,3,3,4,4,4,5,5,6,6,
- 6,7,7,8,8,9,9,9,10,10,11,11,11,12,12,13,
-
- 8,8,9,9,9,10,10,11,11,12,12,12,13,13,14,14,
- 14,15,15,16,16,17,17,17,18,18,19,19,19,20,20,21,
- };
-
- static const int data_swap_select[64] =
- {
- 0,0,1,1,2,2,2,3,3,4,4,5,5,5,6,6,
- 7,7,7,8,8,9,9,10,10,10,11,11,12,12,12,13,
-
- 8,8,9,9,10,10,10,11,11,12,12,13,13,13,14,14,
- 15,15,15,16,16,17,17,18,18,18,19,19,20,20,20,21,
- };
-
-
- sega_decode_2(machine,cputag,opcode_xor,opcode_swap_select,data_xor,data_swap_select);
-}
-
-
-void wboy2_decode(running_machine *machine, const char *cputag)
-{
- static const UINT8 opcode_xor[64] =
- {
- 0x00,0x45,0x11,0x01,0x44,0x10,0x55,0x05,0x41,0x14,0x04,0x40,0x15,0x51,
- 0x01,0x44,0x10,0x00,0x45,0x11,0x54,0x04,0x40,0x15,0x05,0x41,0x14,0x50,
- 0x00,0x45,0x11,0x01,
- 0x00,0x45,0x11,0x01,0x44,0x10,0x55,0x05,0x41,0x14,0x04,0x40,0x15,0x51,
- 0x01,0x44,0x10,0x00,0x45,0x11,0x54,0x04,0x40,0x15,0x05,0x41,0x14,0x50,
- 0x00,0x45,0x11,0x01,
- };
-
- static const UINT8 data_xor[64] =
- {
- 0x55,0x05,0x41,0x14,0x50,0x00,0x15,0x51,0x01,0x44,0x10,0x55,0x05,0x11,
- 0x54,0x04,0x40,0x15,0x51,0x01,0x14,0x50,0x00,0x45,0x11,0x54,0x04,0x10,
- 0x55,0x05,0x41,0x14,
- 0x55,0x05,0x41,0x14,0x50,0x00,0x15,0x51,0x01,0x44,0x10,0x55,0x05,0x11,
- 0x54,0x04,0x40,0x15,0x51,0x01,0x14,0x50,0x00,0x45,0x11,0x54,0x04,0x10,
- 0x55,0x05,0x41,0x14,
- };
-
- static const int opcode_swap_select[64] =
- {
- 2,
- 5,1,5,1,5,
- 0,4,0,4,0,4,
- 7,3,7,3,7,3,
- 6,2,6,2,6,
- 1,5,1,5,1,5,
- 0,4,0,
-
- 10,
- 13,9,13,9,13,
- 8,12,8,12,8,12,
- 15,11,15,11,15,11,
- 14,10,14,10,14,
- 9,13,9,13,9,13,
- 8,12,8,
- };
-
- static const int data_swap_select[64] =
- {
- 3,7,3,7,3,7,
- 2,6,2,6,2,
- 5,1,5,1,5,1,
- 4,0,4,0,4,
- 8,
- 3,7,3,7,3,
- 6,2,6,2,
-
- 11,15,11,15,11,15,
- 10,14,10,14,10,
- 13,9,13,9,13,9,
- 12,8,12,8,12,
- 16,
- 11,15,11,15,11,
- 14,10,14,10,
- };
-
-
- sega_decode_2(machine,cputag,opcode_xor,opcode_swap_select,data_xor,data_swap_select);
-}
-
-
-void robowres_decode(running_machine *machine, const char *cputag)
-{
- static const UINT8 opcode_xor[64] =
- {
- 0x00,0x41,0x10,0x51,0x04,0x45,0x14, 0x00,0x41,0x10,0x51,0x04,0x45,0x14, 0x55,
- 0x01,0x40,0x11,0x50,0x05,0x44,0x15, 0x01,0x40,0x11,0x50,0x05,0x44,0x15, 0x54,
- 0x00,0x41,
- 0x50,0x05,0x44,0x15,0x54,0x00,0x41, 0x50,0x05,0x44,0x15,0x54,0x00,0x41, 0x10,
- 0x51,0x04,0x45,0x14,0x55,0x01,0x40, 0x51,0x04,0x45,0x14,0x55,0x01,0x40, 0x11,
- 0x50,0x05
- };
-
- static const UINT8 data_xor[64] =
- {
- 0x45,0x14,0x55,0x01,0x40,0x11,0x50, 0x05,0x44,0x15,0x54,0x00,0x41,0x10, 0x05,
- 0x44,0x15,0x54,0x00,0x41,0x10,0x51, 0x04,0x45,0x14,0x55,0x01,0x40,0x11, 0x04,
- 0x45,0x14,
- 0x00,0x41,0x10,0x51,0x04,0x45,0x14, 0x55,0x01,0x40,0x11,0x50,0x05,0x44, 0x55,
- 0x01,0x40,0x11,0x50,0x05,0x44,0x15, 0x54,0x00,0x41,0x10,0x51,0x04,0x45, 0x54,
- 0x00,0x41
- };
-
- static const int opcode_swap_select[64] =
- {
- 8,11,15,2,6,
- 9,13,1,4,8,11,15,2,6,
- 9,13,1,4,8,11,15,2,6,
- 10,13,1,4,8,11,15,3,6,
-
- 7,2,6,1,5,
- 1,4,0,3,7,2,6,2,5,
- 1,4,0,3,7,2,6,2,5,
- 1,4,0,3,7,3,6,2,5,
- };
-
- static const int data_swap_select[64] =
- {
- 9,13,0,4,8,11,15,2,6,
- 9,13,1,4,8,11,15,2,6,
- 10,13,1,4,8,11,15,2,6,
- 10,13,1,4,8,
-
- 1,4,0,3,7,2,6,1,5,
- 1,4,0,3,7,2,6,2,5,
- 1,4,0,3,7,3,6,2,5,
- 1,4,0,4,7,
- };
-
-
- sega_decode_2(machine,cputag,opcode_xor,opcode_swap_select,data_xor,data_swap_select);
-}
-
-
-/******************************************************************************
-
- These games (all 317-xxxx CPUs) use the same algorithm, but the key doesn't
- change much - just one or two positions shift in the table.
-
-******************************************************************************/
-
-static void sega_decode_317(running_machine *machine, const char *cputag, int order, int opcode_shift, int data_shift)
-{
- static const UINT8 xor1_317[1+64] =
- {
- 0x54,
- 0x14,0x15,0x41,0x14,0x50,0x55,0x05,0x41,0x01,0x10,0x51,0x05,0x11,0x05,0x14,0x55,
- 0x41,0x05,0x04,0x41,0x14,0x10,0x45,0x50,0x00,0x45,0x00,0x00,0x00,0x45,0x00,0x00,
- 0x54,0x04,0x15,0x10,0x04,0x05,0x11,0x44,0x04,0x01,0x05,0x00,0x44,0x15,0x40,0x45,
- 0x10,0x15,0x51,0x50,0x00,0x15,0x51,0x44,0x15,0x04,0x44,0x44,0x50,0x10,0x04,0x04,
- };
-
- static const UINT8 xor2_317[2+64] =
- {
- 0x04,
- 0x44,
- 0x15,0x51,0x41,0x10,0x15,0x54,0x04,0x51,0x05,0x55,0x05,0x54,0x45,0x04,0x10,0x01,
- 0x51,0x55,0x45,0x55,0x45,0x04,0x55,0x40,0x11,0x15,0x01,0x40,0x01,0x11,0x45,0x44,
- 0x40,0x05,0x15,0x15,0x01,0x50,0x00,0x44,0x04,0x50,0x51,0x45,0x50,0x54,0x41,0x40,
- 0x14,0x40,0x50,0x45,0x10,0x05,0x50,0x01,0x40,0x01,0x50,0x50,0x50,0x44,0x40,0x10,
- };
-
- static const int swap1_317[1+64] =
- {
- 7,
- 1,11,23,17,23, 0,15,19,
- 20,12,10, 0,18,18, 5,20,
- 13, 0,18,14, 5, 6,10,21,
- 1,11, 9, 3,21, 4, 1,17,
- 5, 7,16,13,19,23,20, 2,
- 10,23,23,15,10,12, 0,22,
- 14, 6,15,11,17,15,21, 0,
- 6, 1, 1,18, 5,15,15,20,
- };
-
- static const int swap2_317[2+64] =
- {
- 7,
- 12,
- 18, 8,21, 0,22,21,13,21,
- 20,13,20,14, 6, 3, 5,20,
- 8,20, 4, 8,17,22, 0, 0,
- 6,17,17, 9, 0,16,13,21,
- 3, 2,18, 6,11, 3, 3,18,
- 18,19, 3, 0, 5, 0,11, 8,
- 8, 1, 7, 2,10, 8,10, 2,
- 1, 3,12,16, 0,17,10, 1,
- };
-
- if (order)
- sega_decode_2( machine, cputag, xor2_317+opcode_shift, swap2_317+opcode_shift, xor1_317+data_shift, swap1_317+data_shift );
- else
- sega_decode_2( machine, cputag, xor1_317+opcode_shift, swap1_317+opcode_shift, xor2_317+data_shift, swap2_317+data_shift );
-}
-
-void spcpostn_decode(running_machine *machine, const char *cputag) { sega_decode_317( machine, cputag, 0, 0, 1 ); }
-void calorie_decode(running_machine *machine, const char *cputag) { sega_decode_317( machine, cputag, 1, 0, 0 ); }
-void gardia_decode(running_machine *machine, const char *cputag) { sega_decode_317( machine, cputag, 1, 1, 1 ); }
-void gardiab_decode(running_machine *machine, const char *cputag) { sega_decode_317( machine, cputag, 0, 1, 2 ); }
diff --git a/src/mame/machine/segacrpt.h b/src/mame/machine/segacrpt.h
index afdaca99dc6..522b2ed0cd8 100644
--- a/src/mame/machine/segacrpt.h
+++ b/src/mame/machine/segacrpt.h
@@ -23,13 +23,3 @@ void teddybb_decode(running_machine *machine, const char *cputag);
void myheroj_decode(running_machine *machine, const char *cputag);
void hvymetal_decode(running_machine *machine, const char *cputag);
void lvcards_decode(running_machine *machine, const char *cputag);
-
-void fdwarrio_decode(running_machine *machine, const char *cputag);
-void astrofl_decode(running_machine *machine, const char *cputag);
-void wboy2_decode(running_machine *machine, const char *cputag);
-void robowres_decode(running_machine *machine, const char *cputag);
-void calorie_decode(running_machine *machine, const char *cputag);
-void spcpostn_decode(running_machine *machine, const char *cputag);
-void gardia_decode(running_machine *machine, const char *cputag);
-void gardiab_decode(running_machine *machine, const char *cputag);
-
diff --git a/src/mame/mame.mak b/src/mame/mame.mak
index 72b4ac0b7ac..80ec155eb23 100644
--- a/src/mame/mame.mak
+++ b/src/mame/mame.mak
@@ -334,6 +334,7 @@ $(MAMEOBJ)/shared.a: \
$(MACHINE)/pckeybrd.o \
$(MACHINE)/pcshare.o \
$(MACHINE)/segacrpt.o \
+ $(MACHINE)/segacrp2.o \
$(MACHINE)/ticket.o \
$(VIDEO)/avgdvg.o \