summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/machine/drakton.c
blob: 70a6556ac46ba63cd075bf8acbfec0c9f12f2227 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/***************************************************************************************
    Drakton (c) 1984 Epos
    decryption by Pierpaolo Prazzoli
    based on decryptions of the other Epos games

    For general documentation on how the encryption works, see machine/theglobp.c
****************************************************************************************/

#include "driver.h"
#include "includes/dkong.h"

static void drakton_decrypt_rom_8(void)
{
	UINT8 oldbyte,newbyte;
	UINT8 *ROM;
	int mem;

	ROM = memory_region(REGION_CPU1);

	for (mem=0;mem<0x4000;mem++)
	{
		oldbyte = ROM[mem];

		/*  Note: D2 is inverted and connected to D1, D5 is inverted and
            connected to D0.  The other six data bits are converted by a
            PAL10H8 driven by the counter. */

		newbyte = (oldbyte & 0x02) | (~oldbyte & ~0x02);
		newbyte = BITSWAP8(newbyte,7,6,1,3,0,4,2,5);

		ROM[mem + 0x10000] = newbyte;
	}
}

static void drakton_decrypt_rom_9(void)
{
	UINT8 oldbyte,newbyte;
	UINT8 *ROM;
	int mem;

	ROM = memory_region(REGION_CPU1);

	for (mem=0;mem<0x4000;mem++)
	{
		oldbyte = ROM[mem];

		/*  Note: D2 is inverted and connected to D1, D5 is inverted and
            connected to D0.  The other six data bits are converted by a
            PAL10H8 driven by the counter. */

		newbyte = (oldbyte & 0x40) | (~oldbyte & ~0x40);
		newbyte = BITSWAP8(newbyte,7,1,4,3,0,6,2,5);

		ROM[mem + 0x14000] = newbyte;
	}
}

static void drakton_decrypt_rom_A(void)
{
	UINT8 oldbyte,newbyte;
	UINT8 *ROM;
	int mem;

	ROM = memory_region(REGION_CPU1);

	for (mem=0;mem<0x4000;mem++)
	{
		oldbyte = ROM[mem];

		/*  Note: D2 is inverted and connected to D1, D5 is inverted and
            connected to D0.  The other six data bits are converted by a
            PAL10H8 driven by the counter. */

		newbyte = (oldbyte & 0x8a) | (~oldbyte & ~0x8a);
		newbyte = BITSWAP8(newbyte,7,6,1,0,3,4,2,5);

		ROM[mem + 0x18000] = newbyte;
	}
}

static void drakton_decrypt_rom_B(void)
{
	UINT8 oldbyte,newbyte;
	UINT8 *ROM;
	int mem;

	ROM = memory_region(REGION_CPU1);

	for (mem=0;mem<0x4000;mem++)
	{
		oldbyte = ROM[mem];

		/*  Note: D2 is inverted and connected to D1, D5 is inverted and
            connected to D0.  The other six data bits are converted by a
            PAL10H8 driven by the counter. */

		newbyte = (oldbyte & 0xc8) | (~oldbyte & ~0xc8);
		newbyte = BITSWAP8(newbyte,7,1,4,0,3,6,2,5);

		ROM[mem + 0x1C000] = newbyte;
	}
}

DRIVER_INIT( drakton )
{
	/* While the PAL supports up to 16 decryption methods, only four
        are actually used in the PAL.  Therefore, we'll take a little
        memory overhead and decrypt the ROMs using each method in advance. */
	drakton_decrypt_rom_8();
	drakton_decrypt_rom_9();
	drakton_decrypt_rom_A();
	drakton_decrypt_rom_B();
}