summaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
author davidhay <davidhay@localhost>2008-07-11 20:49:38 +0000
committer davidhay <davidhay@localhost>2008-07-11 20:49:38 +0000
commit5d5550c907c58c8335a3eda307ee1d6271eaafad (patch)
tree30cf99ab2c9edf7ab83c7e92b86f435226152db0 /src
parent740ebd5401317bab471c741ae0b404e2987c354f (diff)
some naomi stuff. no credit wanted.
I don't want people bugging me about this, so don't bother even mentioning it.
Diffstat (limited to 'src')
-rw-r--r--src/mame/drivers/naomi.c36
-rw-r--r--src/mame/machine/gdcrypt.c352
-rw-r--r--src/mame/mame.mak2
-rw-r--r--src/mame/mamedriv.c2
4 files changed, 386 insertions, 6 deletions
diff --git a/src/mame/drivers/naomi.c b/src/mame/drivers/naomi.c
index 4d05d392611..92edeba94b0 100644
--- a/src/mame/drivers/naomi.c
+++ b/src/mame/drivers/naomi.c
@@ -873,6 +873,7 @@ Scan ROM for the text string "LOADING TEST MODE NOW" back up four (4) bytes for
NOTE: this doesn't work for the HOTD2 or multi screen boot roms
*/
+// game specific bios roms quite clearly don't belong in here.
#define NAOMI_BIOS \
ROM_SYSTEM_BIOS( 0, "bios0", "epr-21578e (Export)" ) \
@@ -905,8 +906,9 @@ Scan ROM for the text string "LOADING TEST MODE NOW" back up four (4) bytes for
ROM_LOAD16_WORD_SWAP_BIOS( 13, "epr-21330.bin", 0x000000, 0x200000, CRC(9e3bfa1b) SHA1(b539d38c767b0551b8e7956c1ff795de8bbe2fbc) ) \
ROM_SYSTEM_BIOS( 14, "bios14", "HOTD2 (Export)" ) \
ROM_LOAD16_WORD_SWAP_BIOS( 14, "epr-21331.bin", 0x000000, 0x200000, CRC(065f8500) SHA1(49a3881e8d76f952ef5e887200d77b4a415d47fe) ) \
- ROM_SYSTEM_BIOS( 15, "bios15", "Naomi Dev BIOS" ) \
- ROM_LOAD16_WORD_SWAP_BIOS( 15, "dcnaodev.bios", 0x000000, 0x080000, CRC(7a50fab9) SHA1(ef79f448e0bf735d1264ad4f051d24178822110f) ) /* This one comes from a dev / beta board. The eprom was a 27C4096 */
+
+// ROM_SYSTEM_BIOS( 15, "bios15", "Naomi Dev BIOS" )
+// ROM_LOAD16_WORD_SWAP_BIOS( 15, "dcnaodev.bios", 0x000000, 0x080000, CRC(7a50fab9) SHA1(ef79f448e0bf735d1264ad4f051d24178822110f) ) /* This one comes from a dev / beta board. The eprom was a 27C4096 */
/* only revisions d and higher support the GDROM, and there is an additional bios (and SH4!) on the DIMM board for the CD Controller */
#define NAOMIGD_BIOS \
@@ -2329,7 +2331,8 @@ a parity byte for verification (8*7 = 56, 8*8 = 64)
ROM_START( sfz3ugd )
NAOMIGD_BIOS
- ROM_REGION( 0x8400000, REGION_USER1, ROMREGION_ERASE)
+ ROM_REGION( 0xac00000, REGION_USER1, ROMREGION_ERASE) // this is the 'rom' file from the GDROM DISC, once the GDROM is emulated this won't be loaded
+ ROM_LOAD_OPTIONAL("zero3rom.bin", 0x0000000, 0xac00000, CRC(4eabda58) SHA1(e70db0e93c821838c77510fd47c91f0c4cfb09c9) )
/* GD-ROM dump, this will be replaced once an appropriate CHD format has been decided upon for the GD images*/
ROM_REGION( 0x3d8ab000, REGION_USER3, ROMREGION_ERASE)
@@ -2340,6 +2343,30 @@ ROM_START( sfz3ugd )
ROM_END
+extern void naomi_game_decrypt(UINT64 key, UINT8* region, int length);
+
+DRIVER_INIT( cvs2gd )
+{
+ // move key to game.key file?
+ naomi_game_decrypt( 0x2f3226165b9e407cULL, memory_region(machine,REGION_USER1), memory_region_length(machine,REGION_USER1));
+}
+
+
+ROM_START( cvs2gd )
+ NAOMIGD_BIOS
+
+ ROM_REGION( 0x9800000, REGION_USER1, ROMREGION_ERASE) // this is the 'rom' file from the GDROM DISC, once the GDROM is emulated this won't be loaded
+ ROM_LOAD("snkgd_sl.bin", 0x0000000, 0x9800000, CRC(f153421d) SHA1(0c2b935ae3cfb6c85410a209fec4eab497066d84) )
+
+ /* GD-ROM dump, this will be replaced once an appropriate CHD format has been decided upon for the GD images*/
+ ROM_REGION( 0x26ad4620, REGION_USER3, ROMREGION_ERASE)
+ ROM_LOAD("capcom_vs_snk2.txt", 0x0000000, 0x00000141, CRC(0db478be) SHA1(a18f87b76139e4a845ecc1456b6195574110e30c) )
+ ROM_LOAD("track01.bin",0x0000000, 0x00ac440, CRC(d48bd072) SHA1(2fc840586c655dee2686ee3b520c7760bd3b8dcb) )
+ ROM_LOAD("track02.raw",0x0000000, 0x004c8cf0, CRC(3b3a2e7b) SHA1(fd8e5cac5bd387229f4ffbe05d1bf2fabf7ea3f9) )
+ ROM_LOAD("track03.bin",0x0000000, 0x26ad4620, CRC(670d2182) SHA1(a99ceb7bb74e4a0fe6ae80b33cd2963465ae9d14) )
+ ROM_CONTINUE(0x0000000, 0x20000000)
+ROM_END
+
/* All games have the regional titles at the start of the IC22 rom in the following order
@@ -2396,7 +2423,8 @@ GAME( 1998, dybbnao, naomi, naomi, naomi, 0, ROT0, "Sega",
/* No GD-Rom Sets Supported */
GAME( 2001, naomigd, 0, naomi, naomi, 0, ROT0, "Sega", "Naomi GD-ROM Bios", GAME_NO_SOUND|GAME_NOT_WORKING|GAME_IS_BIOS_ROOT )
-GAME( 2001, sfz3ugd, naomigd, naomi, naomi, 0, ROT0, "Capcom", "Street Fighter Zero 3 Upper", GAME_NO_SOUND|GAME_NOT_WORKING|GAME_IS_BIOS_ROOT )
+GAME( 2001, sfz3ugd, naomigd, naomi, naomi, 0, ROT0, "Capcom", "Street Fighter Zero 3 Upper", GAME_NO_SOUND|GAME_NOT_WORKING )
+GAME( 2001, cvs2gd, naomigd, naomi, naomi, cvs2gd, ROT0, "Capcom", "Capcom Vs. SNK 2", GAME_NO_SOUND|GAME_NOT_WORKING )
/* Naomi 2 & Naomi 2 GD-ROM */
diff --git a/src/mame/machine/gdcrypt.c b/src/mame/machine/gdcrypt.c
new file mode 100644
index 00000000000..bd99523de41
--- /dev/null
+++ b/src/mame/machine/gdcrypt.c
@@ -0,0 +1,352 @@
+
+/* DES decryption, used by GD-ROM based titles (Naomi etc.) */
+
+#include "driver.h"
+
+static UINT32 des_subkeys[32];
+
+static const UINT32 DES_LEFTSWAP[] =
+{
+ 0x00000000, 0x00000001, 0x00000100, 0x00000101, 0x00010000, 0x00010001, 0x00010100, 0x00010101,
+ 0x01000000, 0x01000001, 0x01000100, 0x01000101, 0x01010000, 0x01010001, 0x01010100, 0x01010101
+};
+
+static const UINT32 DES_RIGHTSWAP[] =
+{
+ 0x00000000, 0x01000000, 0x00010000, 0x01010000, 0x00000100, 0x01000100, 0x00010100, 0x01010100,
+ 0x00000001, 0x01000001, 0x00010001, 0x01010001, 0x00000101, 0x01000101, 0x00010101, 0x01010101,
+};
+
+static const UINT32 DES_SBOX1[] =
+{
+ 0x00808200, 0x00000000, 0x00008000, 0x00808202, 0x00808002, 0x00008202, 0x00000002, 0x00008000,
+ 0x00000200, 0x00808200, 0x00808202, 0x00000200, 0x00800202, 0x00808002, 0x00800000, 0x00000002,
+ 0x00000202, 0x00800200, 0x00800200, 0x00008200, 0x00008200, 0x00808000, 0x00808000, 0x00800202,
+ 0x00008002, 0x00800002, 0x00800002, 0x00008002, 0x00000000, 0x00000202, 0x00008202, 0x00800000,
+ 0x00008000, 0x00808202, 0x00000002, 0x00808000, 0x00808200, 0x00800000, 0x00800000, 0x00000200,
+ 0x00808002, 0x00008000, 0x00008200, 0x00800002, 0x00000200, 0x00000002, 0x00800202, 0x00008202,
+ 0x00808202, 0x00008002, 0x00808000, 0x00800202, 0x00800002, 0x00000202, 0x00008202, 0x00808200,
+ 0x00000202, 0x00800200, 0x00800200, 0x00000000, 0x00008002, 0x00008200, 0x00000000, 0x00808002
+};
+
+static const UINT32 DES_SBOX2[] =
+{
+ 0x40084010, 0x40004000, 0x00004000, 0x00084010, 0x00080000, 0x00000010, 0x40080010, 0x40004010,
+ 0x40000010, 0x40084010, 0x40084000, 0x40000000, 0x40004000, 0x00080000, 0x00000010, 0x40080010,
+ 0x00084000, 0x00080010, 0x40004010, 0x00000000, 0x40000000, 0x00004000, 0x00084010, 0x40080000,
+ 0x00080010, 0x40000010, 0x00000000, 0x00084000, 0x00004010, 0x40084000, 0x40080000, 0x00004010,
+ 0x00000000, 0x00084010, 0x40080010, 0x00080000, 0x40004010, 0x40080000, 0x40084000, 0x00004000,
+ 0x40080000, 0x40004000, 0x00000010, 0x40084010, 0x00084010, 0x00000010, 0x00004000, 0x40000000,
+ 0x00004010, 0x40084000, 0x00080000, 0x40000010, 0x00080010, 0x40004010, 0x40000010, 0x00080010,
+ 0x00084000, 0x00000000, 0x40004000, 0x00004010, 0x40000000, 0x40080010, 0x40084010, 0x00084000
+};
+
+static const UINT32 DES_SBOX3[] =
+{
+ 0x00000104, 0x04010100, 0x00000000, 0x04010004, 0x04000100, 0x00000000, 0x00010104, 0x04000100,
+ 0x00010004, 0x04000004, 0x04000004, 0x00010000, 0x04010104, 0x00010004, 0x04010000, 0x00000104,
+ 0x04000000, 0x00000004, 0x04010100, 0x00000100, 0x00010100, 0x04010000, 0x04010004, 0x00010104,
+ 0x04000104, 0x00010100, 0x00010000, 0x04000104, 0x00000004, 0x04010104, 0x00000100, 0x04000000,
+ 0x04010100, 0x04000000, 0x00010004, 0x00000104, 0x00010000, 0x04010100, 0x04000100, 0x00000000,
+ 0x00000100, 0x00010004, 0x04010104, 0x04000100, 0x04000004, 0x00000100, 0x00000000, 0x04010004,
+ 0x04000104, 0x00010000, 0x04000000, 0x04010104, 0x00000004, 0x00010104, 0x00010100, 0x04000004,
+ 0x04010000, 0x04000104, 0x00000104, 0x04010000, 0x00010104, 0x00000004, 0x04010004, 0x00010100
+};
+
+static const UINT32 DES_SBOX4[] =
+{
+ 0x80401000, 0x80001040, 0x80001040, 0x00000040, 0x00401040, 0x80400040, 0x80400000, 0x80001000,
+ 0x00000000, 0x00401000, 0x00401000, 0x80401040, 0x80000040, 0x00000000, 0x00400040, 0x80400000,
+ 0x80000000, 0x00001000, 0x00400000, 0x80401000, 0x00000040, 0x00400000, 0x80001000, 0x00001040,
+ 0x80400040, 0x80000000, 0x00001040, 0x00400040, 0x00001000, 0x00401040, 0x80401040, 0x80000040,
+ 0x00400040, 0x80400000, 0x00401000, 0x80401040, 0x80000040, 0x00000000, 0x00000000, 0x00401000,
+ 0x00001040, 0x00400040, 0x80400040, 0x80000000, 0x80401000, 0x80001040, 0x80001040, 0x00000040,
+ 0x80401040, 0x80000040, 0x80000000, 0x00001000, 0x80400000, 0x80001000, 0x00401040, 0x80400040,
+ 0x80001000, 0x00001040, 0x00400000, 0x80401000, 0x00000040, 0x00400000, 0x00001000, 0x00401040
+};
+
+static const UINT32 DES_SBOX5[] =
+{
+ 0x00000080, 0x01040080, 0x01040000, 0x21000080, 0x00040000, 0x00000080, 0x20000000, 0x01040000,
+ 0x20040080, 0x00040000, 0x01000080, 0x20040080, 0x21000080, 0x21040000, 0x00040080, 0x20000000,
+ 0x01000000, 0x20040000, 0x20040000, 0x00000000, 0x20000080, 0x21040080, 0x21040080, 0x01000080,
+ 0x21040000, 0x20000080, 0x00000000, 0x21000000, 0x01040080, 0x01000000, 0x21000000, 0x00040080,
+ 0x00040000, 0x21000080, 0x00000080, 0x01000000, 0x20000000, 0x01040000, 0x21000080, 0x20040080,
+ 0x01000080, 0x20000000, 0x21040000, 0x01040080, 0x20040080, 0x00000080, 0x01000000, 0x21040000,
+ 0x21040080, 0x00040080, 0x21000000, 0x21040080, 0x01040000, 0x00000000, 0x20040000, 0x21000000,
+ 0x00040080, 0x01000080, 0x20000080, 0x00040000, 0x00000000, 0x20040000, 0x01040080, 0x20000080
+};
+
+static const UINT32 DES_SBOX6[] =
+{
+ 0x10000008, 0x10200000, 0x00002000, 0x10202008, 0x10200000, 0x00000008, 0x10202008, 0x00200000,
+ 0x10002000, 0x00202008, 0x00200000, 0x10000008, 0x00200008, 0x10002000, 0x10000000, 0x00002008,
+ 0x00000000, 0x00200008, 0x10002008, 0x00002000, 0x00202000, 0x10002008, 0x00000008, 0x10200008,
+ 0x10200008, 0x00000000, 0x00202008, 0x10202000, 0x00002008, 0x00202000, 0x10202000, 0x10000000,
+ 0x10002000, 0x00000008, 0x10200008, 0x00202000, 0x10202008, 0x00200000, 0x00002008, 0x10000008,
+ 0x00200000, 0x10002000, 0x10000000, 0x00002008, 0x10000008, 0x10202008, 0x00202000, 0x10200000,
+ 0x00202008, 0x10202000, 0x00000000, 0x10200008, 0x00000008, 0x00002000, 0x10200000, 0x00202008,
+ 0x00002000, 0x00200008, 0x10002008, 0x00000000, 0x10202000, 0x10000000, 0x00200008, 0x10002008
+};
+
+static const UINT32 DES_SBOX7[] =
+{
+ 0x00100000, 0x02100001, 0x02000401, 0x00000000, 0x00000400, 0x02000401, 0x00100401, 0x02100400,
+ 0x02100401, 0x00100000, 0x00000000, 0x02000001, 0x00000001, 0x02000000, 0x02100001, 0x00000401,
+ 0x02000400, 0x00100401, 0x00100001, 0x02000400, 0x02000001, 0x02100000, 0x02100400, 0x00100001,
+ 0x02100000, 0x00000400, 0x00000401, 0x02100401, 0x00100400, 0x00000001, 0x02000000, 0x00100400,
+ 0x02000000, 0x00100400, 0x00100000, 0x02000401, 0x02000401, 0x02100001, 0x02100001, 0x00000001,
+ 0x00100001, 0x02000000, 0x02000400, 0x00100000, 0x02100400, 0x00000401, 0x00100401, 0x02100400,
+ 0x00000401, 0x02000001, 0x02100401, 0x02100000, 0x00100400, 0x00000000, 0x00000001, 0x02100401,
+ 0x00000000, 0x00100401, 0x02100000, 0x00000400, 0x02000001, 0x02000400, 0x00000400, 0x00100001
+};
+
+static const UINT32 DES_SBOX8[] =
+{
+ 0x08000820, 0x00000800, 0x00020000, 0x08020820, 0x08000000, 0x08000820, 0x00000020, 0x08000000,
+ 0x00020020, 0x08020000, 0x08020820, 0x00020800, 0x08020800, 0x00020820, 0x00000800, 0x00000020,
+ 0x08020000, 0x08000020, 0x08000800, 0x00000820, 0x00020800, 0x00020020, 0x08020020, 0x08020800,
+ 0x00000820, 0x00000000, 0x00000000, 0x08020020, 0x08000020, 0x08000800, 0x00020820, 0x00020000,
+ 0x00020820, 0x00020000, 0x08020800, 0x00000800, 0x00000020, 0x08020020, 0x00000800, 0x00020820,
+ 0x08000800, 0x00000020, 0x08000020, 0x08020000, 0x08020020, 0x08000000, 0x00020000, 0x08000820,
+ 0x00000000, 0x08020820, 0x00020020, 0x08000020, 0x08020000, 0x08000800, 0x08000820, 0x00000000,
+ 0x08020820, 0x00020800, 0x00020800, 0x00000820, 0x00000820, 0x00020020, 0x08000000, 0x08020800
+};
+
+static const UINT32 DES_MASK_TABLE[] =
+{
+ 0x24000000, 0x10000000, 0x08000000, 0x02080000, 0x01000000,
+ 0x00200000, 0x00100000, 0x00040000, 0x00020000, 0x00010000,
+ 0x00002000, 0x00001000, 0x00000800, 0x00000400, 0x00000200,
+ 0x00000100, 0x00000020, 0x00000010, 0x00000008, 0x00000004,
+ 0x00000002, 0x00000001, 0x20000000, 0x10000000, 0x08000000,
+ 0x04000000, 0x02000000, 0x01000000, 0x00200000, 0x00100000,
+ 0x00080000, 0x00040000, 0x00020000, 0x00010000, 0x00002000,
+ 0x00001000, 0x00000808, 0x00000400, 0x00000200, 0x00000100,
+ 0x00000020, 0x00000011, 0x00000004, 0x00000002
+};
+
+static const UINT8 DES_ROTATE_TABLE[16] =
+{
+ 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1
+};
+
+
+INLINE void permutate(UINT32*a, UINT32*b, UINT32 m, int shift)
+{
+ UINT32 temp;
+ temp = ((*a>>shift) ^ *b) & m;
+ *a ^= temp<<shift;
+ *b ^= temp;
+}
+
+
+static void des_generate_subkeys(const UINT64 key, UINT32 *subkeys)
+{
+ UINT32 l, r;
+ int round;
+
+ l = (key & 0xffffffff00000000ULL)>>32;
+ r = (key & 0x00000000ffffffffULL)>>0;;
+
+ permutate(&r, &l, 0x0f0f0f0f, 4);
+ permutate(&r, &l, 0x10101010, 0);
+
+ l = (DES_LEFTSWAP[(l >> 0) & 0xf] << 3) |
+ (DES_LEFTSWAP[(l >> 8) & 0xf] << 2) |
+ (DES_LEFTSWAP[(l >> 16) & 0xf] << 1) |
+ (DES_LEFTSWAP[(l >> 24) & 0xf] << 0) |
+ (DES_LEFTSWAP[(l >> 5) & 0xf] << 7) |
+ (DES_LEFTSWAP[(l >> 13) & 0xf] << 6) |
+ (DES_LEFTSWAP[(l >> 21) & 0xf] << 5) |
+ (DES_LEFTSWAP[(l >> 29) & 0xf] << 4);
+
+ r = (DES_RIGHTSWAP[(r >> 1) & 0xf] << 3) |
+ (DES_RIGHTSWAP[(r >> 9) & 0xf] << 2) |
+ (DES_RIGHTSWAP[(r >> 17) & 0xf] << 1) |
+ (DES_RIGHTSWAP[(r >> 25) & 0xf] << 0) |
+ (DES_RIGHTSWAP[(r >> 4) & 0xf] << 7) |
+ (DES_RIGHTSWAP[(r >> 12) & 0xf] << 6) |
+ (DES_RIGHTSWAP[(r >> 20) & 0xf] << 5) |
+ (DES_RIGHTSWAP[(r >> 28) & 0xf] << 4);
+
+ l &= 0x0fffffff;
+ r &= 0x0fffffff;
+
+
+ for (round = 0; round < 16; round++)
+ {
+ l = ((l << DES_ROTATE_TABLE[round]) | (l >> (28 - DES_ROTATE_TABLE[round]))) & 0x0fffffff;
+ r = ((r << DES_ROTATE_TABLE[round]) | (r >> (28 - DES_ROTATE_TABLE[round]))) & 0x0fffffff;
+
+ subkeys[round*2] =
+ ((l << 4) & DES_MASK_TABLE[0]) |
+ ((l << 28) & DES_MASK_TABLE[1]) |
+ ((l << 14) & DES_MASK_TABLE[2]) |
+ ((l << 18) & DES_MASK_TABLE[3]) |
+ ((l << 6) & DES_MASK_TABLE[4]) |
+ ((l << 9) & DES_MASK_TABLE[5]) |
+ ((l >> 1) & DES_MASK_TABLE[6]) |
+ ((l << 10) & DES_MASK_TABLE[7]) |
+ ((l << 2) & DES_MASK_TABLE[8]) |
+ ((l >> 10) & DES_MASK_TABLE[9]) |
+ ((r >> 13) & DES_MASK_TABLE[10])|
+ ((r >> 4) & DES_MASK_TABLE[11])|
+ ((r << 6) & DES_MASK_TABLE[12])|
+ ((r >> 1) & DES_MASK_TABLE[13])|
+ ((r >> 14) & DES_MASK_TABLE[14])|
+ ((r >> 0) & DES_MASK_TABLE[15])|
+ ((r >> 5) & DES_MASK_TABLE[16])|
+ ((r >> 10) & DES_MASK_TABLE[17])|
+ ((r >> 3) & DES_MASK_TABLE[18])|
+ ((r >> 18) & DES_MASK_TABLE[19])|
+ ((r >> 26) & DES_MASK_TABLE[20])|
+ ((r >> 24) & DES_MASK_TABLE[21]);
+
+ subkeys[round*2+1] =
+ ((l << 15) & DES_MASK_TABLE[22])|
+ ((l << 17) & DES_MASK_TABLE[23])|
+ ((l << 10) & DES_MASK_TABLE[24])|
+ ((l << 22) & DES_MASK_TABLE[25])|
+ ((l >> 2) & DES_MASK_TABLE[26])|
+ ((l << 1) & DES_MASK_TABLE[27])|
+ ((l << 16) & DES_MASK_TABLE[28])|
+ ((l << 11) & DES_MASK_TABLE[29])|
+ ((l << 3) & DES_MASK_TABLE[30])|
+ ((l >> 6) & DES_MASK_TABLE[31])|
+ ((l << 15) & DES_MASK_TABLE[32])|
+ ((l >> 4) & DES_MASK_TABLE[33])|
+ ((r >> 2) & DES_MASK_TABLE[34])|
+ ((r << 8) & DES_MASK_TABLE[35])|
+ ((r >> 14) & DES_MASK_TABLE[36])|
+ ((r >> 9) & DES_MASK_TABLE[37])|
+ ((r >> 0) & DES_MASK_TABLE[38])|
+ ((r << 7) & DES_MASK_TABLE[39])|
+ ((r >> 7) & DES_MASK_TABLE[40])|
+ ((r >> 3) & DES_MASK_TABLE[41])|
+ ((r << 2) & DES_MASK_TABLE[42])|
+ ((r >> 21) & DES_MASK_TABLE[43]);
+ }
+}
+
+
+static UINT64 des_encrypt_decrypt(int decrypt, UINT64 ret)
+{
+ UINT32 l;
+ UINT32 r;
+ int i;
+ int subkey;
+
+ r = (ret & 0x00000000ffffffffULL) >> 0;
+ l = (ret & 0xffffffff00000000ULL) >> 32;
+
+ permutate(&l, &r, 0x0f0f0f0f, 4);
+ permutate(&l, &r, 0x0000ffff, 16);
+ permutate(&r, &l, 0x33333333, 2);
+ permutate(&r, &l, 0x00ff00ff, 8);
+ permutate(&l, &r, 0x55555555, 1);
+
+ if (decrypt) subkey = 30;
+ else subkey = 0;
+
+ for (i = 0; i < 32 ; i+=4)
+ {
+ UINT32 temp;
+
+ temp = ((r<<1) | (r>>31)) ^ des_subkeys[subkey];
+ l ^= DES_SBOX8[ (temp>>0) & 0x3f ];
+ l ^= DES_SBOX6[ (temp>>8) & 0x3f ];
+ l ^= DES_SBOX4[ (temp>>16) & 0x3f ];
+ l ^= DES_SBOX2[ (temp>>24) & 0x3f ];
+ subkey++;
+
+ temp = ((r>>3) | (r<<29)) ^ des_subkeys[subkey];
+ l ^= DES_SBOX7[ (temp>>0) & 0x3f ];
+ l ^= DES_SBOX5[ (temp>>8) & 0x3f ];
+ l ^= DES_SBOX3[ (temp>>16) & 0x3f ];
+ l ^= DES_SBOX1[ (temp>>24) & 0x3f ];
+ subkey++;
+ if (decrypt) subkey-=4;
+
+ temp = ((l<<1) | (l>>31)) ^ des_subkeys[subkey];
+ r ^= DES_SBOX8[ (temp>>0) & 0x3f ];
+ r ^= DES_SBOX6[ (temp>>8) & 0x3f ];
+ r ^= DES_SBOX4[ (temp>>16) & 0x3f ];
+ r ^= DES_SBOX2[ (temp>>24) & 0x3f ];
+ subkey++;
+
+ temp = ((l>>3) | (l<<29)) ^ des_subkeys[subkey];
+ r ^= DES_SBOX7[ (temp>>0) & 0x3f ];
+ r ^= DES_SBOX5[ (temp>>8) & 0x3f ];
+ r ^= DES_SBOX3[ (temp>>16) & 0x3f ];
+ r ^= DES_SBOX1[ (temp>>24) & 0x3f ];
+ subkey++;
+ if (decrypt) subkey-=4;
+ }
+
+ permutate(&r, &l, 0x55555555, 1);
+ permutate(&l, &r, 0x00ff00ff, 8);
+ permutate(&l, &r, 0x33333333, 2);
+ permutate(&r, &l, 0x0000ffff, 16);
+ permutate(&r, &l, 0x0f0f0f0f, 4);
+
+ return ((UINT64)r << 32) | ((UINT64)l);
+}
+
+static UINT64 rev64(UINT64 src)
+{
+ UINT64 ret;
+
+ ret = ((src & 0x00000000000000ffULL) << 56)
+ | ((src & 0x000000000000ff00ULL) << 40)
+ | ((src & 0x0000000000ff0000ULL) << 24)
+ | ((src & 0x00000000ff000000ULL) << 8 )
+ | ((src & 0x000000ff00000000ULL) >> 8 )
+ | ((src & 0x0000ff0000000000ULL) >> 24)
+ | ((src & 0x00ff000000000000ULL) >> 40)
+ | ((src & 0xff00000000000000ULL) >> 56);
+
+ return ret;
+}
+
+static UINT64 read_to_qword(UINT8* region)
+{
+ int i;
+ UINT64 ret = 0;
+
+ for (i=0;i<8;i++)
+ {
+ UINT8 byte = region[i];
+ ret += (UINT64)byte << (56-(8*i));
+ }
+
+ return ret;
+}
+
+
+static void write_from_qword(UINT8* region, UINT64 qword)
+{
+ int i;
+ for (i=0;i<8;i++)
+ {
+ region[i] = qword >> (56-(i*8));
+ }
+}
+
+void naomi_game_decrypt(UINT64 key, UINT8* region, int length)
+{
+ int i;
+
+ des_generate_subkeys (rev64(key), des_subkeys);
+
+ for(i=0;i<length;i+=8)
+ {
+ UINT64 ret;
+ ret = read_to_qword(region+i);
+ ret = rev64(ret);
+ ret = des_encrypt_decrypt(1, ret);
+ ret = rev64(ret);
+ write_from_qword(region+i, ret);
+ }
+}
+
diff --git a/src/mame/mame.mak b/src/mame/mame.mak
index a1e6770073a..88a6eb33122 100644
--- a/src/mame/mame.mak
+++ b/src/mame/mame.mak
@@ -1159,7 +1159,7 @@ $(MAMEOBJ)/sega.a: \
$(DRIVERS)/model1.o $(MACHINE)/model1.o $(VIDEO)/model1.o \
$(DRIVERS)/model2.o $(VIDEO)/model2.o \
$(DRIVERS)/model3.o $(VIDEO)/model3.o $(MACHINE)/model3.o \
- $(DRIVERS)/naomi.o $(MACHINE)/dc.o $(VIDEO)/dc.o \
+ $(DRIVERS)/naomi.o $(MACHINE)/dc.o $(VIDEO)/dc.o $(MACHINE)/gdcrypt.o \
$(DRIVERS)/puckpkmn.o \
$(DRIVERS)/segac2.o \
$(DRIVERS)/segag80r.o $(MACHINE)/segag80.o $(AUDIO)/segag80r.o $(VIDEO)/segag80r.o \
diff --git a/src/mame/mamedriv.c b/src/mame/mamedriv.c
index 4d27473fbd8..d0df182f4ee 100644
--- a/src/mame/mamedriv.c
+++ b/src/mame/mamedriv.c
@@ -4059,7 +4059,7 @@ BOMULEUL CHAJARA SEGA ST-V 1997/04/11
DRIVER( naomigd )
DRIVER( sfz3ugd )
-
+ DRIVER( cvs2gd )
DRIVER( naomi2 )
/* Atomiswave (Dreamcast-based) games */