📄 segacrpt.c
字号:
{
static const unsigned char xortable[8+1][8] =
{
/* note how the first lines are highly repetitive, while the */
/* last ones get more and more unique. */
{ 0x00,0x00,0x14,0x14,0x14,0x14,0x00,0x00 }, /* .0.0..0..x..x..x */
{ 0x00,0x11,0x00,0x11,0x11,0x00,0x11,0x00 }, /* .0.0..1..x..x..x */
{ 0x00,0x05,0x05,0x00,0x00,0x05,0x05,0x00 }, /* .0.1..0..x..x..x */
{ 0x00,0x00,0x44,0x44,0x14,0x14,0x50,0x50 }, /* .0.1..1..x..x..x */
{ 0x00,0x00,0x14,0x14,0x50,0x50,0x44,0x44 }, /* .1.0..0..x..x..x */
{ 0x00,0x05,0x05,0x00,0x50,0x55,0x55,0x50 }, /* .1.0..1..x..x..x */
{ 0x00,0x11,0x05,0x14,0x14,0x05,0x11,0x00 }, /* .1.1..0..x..x..x */
{ 0x00,0x41,0x05,0x44,0x14,0x55,0x11,0x50 }, /* .1.1..1..x..x..x */
{ 0x00,0x11,0x05,0x14,0x50,0x41,0x55,0x44 } /* extra line for data decode */
};
int A;
unsigned char *RAM = Machine->memory_region[Machine->drv->cpu[0].memory_region];
for (A = 0x0000;A < 0x8000;A++)
{
int row,col;
unsigned char src;
src = RAM[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);
/* pick the offset in the table from bits 0, 2, 4 and 6 of the source data */
col = ((src >> 0) & 1) + (((src >> 2) & 1) << 1) + (((src >> 4) & 1) << 2);
/* the bottom half of the translation table is the mirror image of the top */
if (src & 0x40) col = 7 - col;
/* decode the opcodes */
ROM[A] = src ^ xortable[row >> 3][col] ^ 0x40;
if (row & 1) ROM[A] ^= 0x10;
if (row & 2) ROM[A] ^= 0x04;
if (row & 4) ROM[A] ^= 0x01;
/* decode the data */
row++; /* the data XOR table is shifted by one position!!!! */
RAM[A] = src ^ xortable[row >> 3][col];
if (row & 1) RAM[A] ^= 0x10;
if (row & 2) RAM[A] ^= 0x04;
if (row & 4) RAM[A] ^= 0x01;
}
/* copy the opcodes from the not encrypted part of the ROMs */
for (A = 0x8000;A < 0x10000;A++)
ROM[A] = RAM[A];
}
/******************************************************************************
Wonder Boy
This is different again. It is similar to 4D Warriors - it affects the same
data bits and is selected by the same address lines, but I haven't been able
to find any regularities in the XOR table, so I'm using a huge 1024 bytes
array.
******************************************************************************/
void wboy3_decode(void)
{
/* not decoded yet! */
}
void wboy4_decode(void)
{
static const unsigned char opcode_xortable[8*8][8] =
{
{ 0x00,0x00,0x44,0x44,0x00,0x00,0x44,0x44 }, /* .0.0 ..0. .0.. 0..0 */
{ 0x45,0x54,0x45,0x54,0x54,0x45,0x54,0x45 }, /* .0.0 ..0. .0.. 0..1 */
{ 0x11,0x11,0x11,0x11,0x41,0x41,0x41,0x41 }, /* .0.0 ..0. .0.. 1..0 */
{ 0x01,0x10,0x01,0x10,0x10,0x01,0x10,0x01 }, /* .0.0 ..0. .0.. 1..1 */
{ 0x44,0x44,0x44,0x44,0x14,0x14,0x14,0x14 }, /* .0.0 ..0. .1.. 0..0 */
{ 0x10,0x01,0x10,0x01,0x01,0x10,0x01,0x10 }, /* .0.0 ..0. .1.. 0..1 */
{ 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55 }, /* .0.0 ..0. .1.. 1..0 */
{ 0x05,0x05,0x11,0x11,0x11,0x11,0x05,0x05 }, /* .0.0 ..0. .1.. 1..1 */
{ 0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41 }, /* .0.0 ..1. .0.. 0..0 */
{ 0x14,0x14,0x00,0x00,0x00,0x00,0x14,0x14 }, /* .0.0 ..1. .0.. 0..1 */
{ 0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04 }, /* .0.0 ..1. .0.. 1..0 */
{ 0x40,0x40,0x54,0x54,0x54,0x54,0x40,0x40 }, /* .0.0 ..1. .0.. 1..1 */
{ 0x15,0x15,0x51,0x51,0x01,0x01,0x45,0x45 }, /* .0.0 ..1. .1.. 0..0 */
{ 0x51,0x10,0x51,0x10,0x51,0x10,0x51,0x10 }, /* .0.0 ..1. .1.. 0..1 */
{ 0x01,0x01,0x45,0x45,0x15,0x15,0x51,0x51 }, /* .0.0 ..1. .1.. 1..0 */
{ 0x44,0x05,0x44,0x05,0x44,0x05,0x44,0x05 }, /* .0.0 ..1. .1.. 1..1 */
{ 0x10,0x10,0x54,0x54,0x04,0x04,0x40,0x40 }, /* .0.1 ..0. .0.. 0..0 */
{ 0x00,0x41,0x00,0x41,0x00,0x41,0x00,0x41 }, /* .0.1 ..0. .0.. 0..1 */
{ 0x45,0x40,0x40,0x45,0x45,0x40,0x40,0x45 }, /* .0.1 ..0. .0.. 1..0 */
{ 0x11,0x11,0x55,0x55,0x11,0x11,0x55,0x55 }, /* .0.1 ..0. .0.. 1..1 */
{ 0x54,0x51,0x51,0x54,0x54,0x51,0x51,0x54 }, /* .0.1 ..0. .1.. 0..0 */
{ 0x04,0x04,0x40,0x40,0x04,0x04,0x40,0x40 }, /* .0.1 ..0. .1.. 0..1 */
{ 0x40,0x45,0x45,0x40,0x40,0x45,0x45,0x40 }, /* .0.1 ..0. .1.. 1..0 */
{ 0x15,0x15,0x15,0x15,0x45,0x45,0x45,0x45 }, /* .0.1 ..0. .1.. 1..1 */
{ 0x05,0x14,0x05,0x14,0x14,0x05,0x14,0x05 }, /* .0.1 ..1. .0.. 0..0 */
{ 0x41,0x41,0x41,0x41,0x11,0x11,0x11,0x11 }, /* .0.1 ..1. .0.. 0..1 */
{ 0x14,0x05,0x14,0x05,0x05,0x14,0x05,0x14 }, /* .0.1 ..1. .0.. 1..0 */
{ 0x50,0x50,0x50,0x50,0x00,0x00,0x00,0x00 }, /* .0.1 ..1. .0.. 1..1 */
{ 0x00,0x11,0x00,0x11,0x11,0x00,0x11,0x00 }, /* .0.1 ..1. .1.. 0..0 */
{ 0x45,0x45,0x45,0x45,0x45,0x45,0x45,0x45 }, /* .0.1 ..1. .1.. 0..1 */
{ 0x11,0x11,0x05,0x05,0x05,0x05,0x11,0x11 }, /* .0.1 ..1. .1.. 1..0 */
{ 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01 }, /* .0.1 ..1. .1.. 1..1 */
{ 0x00,0x11,0x05,0x14,0x14,0x05,0x11,0x00 }, /* .1.0 ..0. .0.. 0..0 */
{ 0x45,0x04,0x40,0x01,0x45,0x04,0x40,0x01 }, /* .1.0 ..0. .0.. 0..1 */
{ 0x11,0x14,0x14,0x11,0x41,0x44,0x44,0x41 }, /* .1.0 ..0. .0.. 1..0 */
{ 0x01,0x40,0x04,0x45,0x01,0x40,0x04,0x45 }, /* .1.0 ..0. .0.. 1..1 */
{ 0x44,0x41,0x41,0x44,0x14,0x11,0x11,0x14 }, /* .1.0 ..0. .1.. 0..0 */
{ 0x10,0x51,0x15,0x54,0x10,0x51,0x15,0x54 }, /* .1.0 ..0. .1.. 0..1 */
{ 0x55,0x55,0x41,0x41,0x05,0x05,0x11,0x11 }, /* .1.0 ..0. .1.. 1..0 */
{ 0x05,0x14,0x00,0x11,0x55,0x44,0x50,0x41 }, /* .1.0 ..0. .1.. 1..1 */
{ 0x41,0x41,0x55,0x55,0x11,0x11,0x05,0x05 }, /* .1.0 ..1. .0.. 0..0 */
{ 0x14,0x05,0x11,0x00,0x44,0x55,0x41,0x50 }, /* .1.0 ..1. .0.. 0..1 */
{ 0x04,0x04,0x10,0x10,0x54,0x54,0x40,0x40 }, /* .1.0 ..1. .0.. 1..0 */
{ 0x40,0x51,0x45,0x54,0x10,0x01,0x15,0x04 }, /* .1.0 ..1. .0.. 1..1 */
{ 0x15,0x10,0x51,0x54,0x04,0x01,0x40,0x45 }, /* .1.0 ..1. .1.. 0..0 */
{ 0x51,0x10,0x54,0x15,0x45,0x04,0x40,0x01 }, /* .1.0 ..1. .1.. 0..1 */
{ 0x01,0x04,0x45,0x40,0x10,0x15,0x54,0x51 }, /* .1.0 ..1. .1.. 1..0 */
{ 0x44,0x05,0x41,0x00,0x50,0x11,0x55,0x14 }, /* .1.0 ..1. .1.. 1..1 */
/* the following are all FF because there is no code to decode */
{ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff }, /* .1.1 ..0. .0.. 0..0 */
{ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff }, /* .1.1 ..0. .0.. 0..1 */
{ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff }, /* .1.1 ..0. .0.. 1..0 */
{ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff }, /* .1.1 ..0. .0.. 1..1 */
{ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff }, /* .1.1 ..0. .1.. 0..0 */
{ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff }, /* .1.1 ..0. .1.. 0..1 */
{ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff }, /* .1.1 ..0. .1.. 1..0 */
{ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff }, /* .1.1 ..0. .1.. 1..1 */
{ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff }, /* .1.1 ..1. .0.. 0..0 */
{ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff }, /* .1.1 ..1. .0.. 0..1 */
{ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff }, /* .1.1 ..1. .0.. 1..0 */
{ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff }, /* .1.1 ..1. .0.. 1..1 */
{ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff }, /* .1.1 ..1. .1.. 0..0 */
{ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff }, /* .1.1 ..1. .1.. 0..1 */
{ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff }, /* .1.1 ..1. .1.. 1..0 */
{ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff }, /* .1.1 ..1. .1.. 1..1 */
};
static const unsigned char data_xortable[8*8][8] =
{
{ 0x55,0x14,0x55,0x14,0x55,0x14,0x55,0x14 }, /* .0.0 ..0. .0.. 0..0 */
{ 0x05,0x05,0x41,0x41,0x11,0x11,0x55,0x55 }, /* .0.0 ..0. .0.. 0..1 */
{ 0x41,0x00,0x41,0x00,0x41,0x00,0x41,0x00 }, /* .0.0 ..0. .0.. 1..0 */
{ 0x14,0x14,0x50,0x50,0x00,0x00,0x44,0x44 }, /* .0.0 ..0. .0.. 1..1 */
{ 0x50,0x11,0x50,0x11,0x50,0x11,0x50,0x11 }, /* .0.0 ..0. .1.. 0..0 */
{ 0x00,0x00,0x44,0x44,0x14,0x14,0x50,0x50 }, /* .0.0 ..0. .1.. 0..1 */
{ 0x15,0x15,0x51,0x51,0x15,0x15,0x51,0x51 }, /* .0.0 ..0. .1.. 1..0 */
{ 0x51,0x54,0x54,0x51,0x51,0x54,0x54,0x51 }, /* .0.0 ..0. .1.. 1..1 */
{ 0x01,0x01,0x45,0x45,0x01,0x01,0x45,0x45 }, /* .0.0 ..1. .0.. 0..0 */
{ 0x44,0x41,0x41,0x44,0x44,0x41,0x41,0x44 }, /* .0.0 ..1. .0.. 0..1 */
{ 0x10,0x10,0x54,0x54,0x10,0x10,0x54,0x54 }, /* .0.0 ..1. .0.. 1..0 */
{ 0x55,0x44,0x55,0x44,0x44,0x55,0x44,0x55 }, /* .0.0 ..1. .0.. 1..1 */
{ 0x05,0x05,0x05,0x05,0x55,0x55,0x55,0x55 }, /* .0.0 ..1. .1.. 0..0 */
{ 0x11,0x00,0x11,0x00,0x00,0x11,0x00,0x11 }, /* .0.0 ..1. .1.. 0..1 */
{ 0x54,0x54,0x54,0x54,0x04,0x04,0x04,0x04 }, /* .0.0 ..1. .1.. 1..0 */
{ 0x04,0x15,0x04,0x15,0x15,0x04,0x15,0x04 }, /* .0.0 ..1. .1.. 1..1 */
{ 0x40,0x40,0x40,0x40,0x10,0x10,0x10,0x10 }, /* .0.1 ..0. .0.. 0..0 */
{ 0x15,0x15,0x01,0x01,0x01,0x01,0x15,0x15 }, /* .0.1 ..0. .0.. 0..1 */
{ 0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51 }, /* .0.1 ..0. .0.. 1..0 */
{ 0x01,0x01,0x15,0x15,0x15,0x15,0x01,0x01 }, /* .0.1 ..0. .0.. 1..1 */
{ 0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14 }, /* .0.1 ..0. .1.. 0..0 */
{ 0x50,0x50,0x44,0x44,0x44,0x44,0x50,0x50 }, /* .0.1 ..0. .1.. 0..1 */
{ 0x00,0x00,0x14,0x14,0x50,0x50,0x44,0x44 }, /* .0.1 ..0. .1.. 1..0 */
{ 0x45,0x04,0x45,0x04,0x45,0x04,0x45,0x04 }, /* .0.1 ..0. .1.. 1..1 */
{ 0x11,0x11,0x55,0x55,0x05,0x05,0x41,0x41 }, /* .0.1 ..1. .0.. 0..0 */
{ 0x54,0x15,0x54,0x15,0x54,0x15,0x54,0x15 }, /* .0.1 ..1. .0.. 0..1 */
{ 0x04,0x04,0x40,0x40,0x10,0x10,0x54,0x54 }, /* .0.1 ..1. .0.. 1..0 */
{ 0x10,0x51,0x10,0x51,0x10,0x51,0x10,0x51 }, /* .0.1 ..1. .0.. 1..1 */
{ 0x55,0x50,0x50,0x55,0x55,0x50,0x50,0x55 }, /* .0.1 ..1. .1.. 0..0 */
{ 0x05,0x05,0x41,0x41,0x05,0x05,0x41,0x41 }, /* .0.1 ..1. .1.. 0..1 */
{ 0x41,0x44,0x44,0x41,0x41,0x44,0x44,0x41 }, /* .0.1 ..1. .1.. 1..0 */
{ 0x14,0x14,0x50,0x50,0x14,0x14,0x50,0x50 }, /* .0.1 ..1. .1.. 1..1 */
{ 0x55,0x14,0x50,0x11,0x41,0x00,0x44,0x05 }, /* .1.0 ..0. .0.. 0..0 */
{ 0x05,0x00,0x41,0x44,0x14,0x11,0x50,0x55 }, /* .1.0 ..0. .0.. 0..1 */
{ 0x41,0x00,0x44,0x05,0x55,0x14,0x50,0x11 }, /* .1.0 ..0. .0.. 1..0 */
{ 0x14,0x11,0x50,0x55,0x05,0x00,0x41,0x44 }, /* .1.0 ..0. .0.. 1..1 */
{ 0x50,0x11,0x55,0x14,0x44,0x05,0x41,0x00 }, /* .1.0 ..0. .1.. 0..0 */
{ 0x00,0x05,0x44,0x41,0x11,0x14,0x55,0x50 }, /* .1.0 ..0. .1.. 0..1 */
{ 0x15,0x04,0x10,0x01,0x01,0x10,0x04,0x15 }, /* .1.0 ..0. .1.. 1..0 */
{ 0x51,0x54,0x45,0x40,0x40,0x45,0x54,0x51 }, /* .1.0 ..0. .1.. 1..1 */
{ 0x01,0x10,0x04,0x15,0x15,0x04,0x10,0x01 }, /* .1.0 ..1. .0.. 0..0 */
{ 0x44,0x41,0x50,0x55,0x55,0x50,0x41,0x44 }, /* .1.0 ..1. .0.. 0..1 */
{ 0x10,0x01,0x15,0x04,0x04,0x15,0x01,0x10 }, /* .1.0 ..1. .0.. 1..0 */
{ 0x55,0x14,0x50,0x11,0x55,0x14,0x50,0x11 }, /* .1.0 ..1. .0.. 1..1 */
{ 0x05,0x00,0x00,0x05,0x55,0x50,0x50,0x55 }, /* .1.0 ..1. .1.. 0..0 */
{ 0x11,0x50,0x14,0x55,0x11,0x50,0x14,0x55 }, /* .1.0 ..1. .1.. 0..1 */
{ 0x54,0x51,0x51,0x54,0x04,0x01,0x01,0x04 }, /* .1.0 ..1. .1.. 1..0 */
{ 0x04,0x45,0x01,0x40,0x04,0x45,0x01,0x40 }, /* .1.0 ..1. .1.. 1..1 */
{ 0x40,0x45,0x45,0x40,0x10,0x15,0x15,0x10 }, /* .1.1 ..0. .0.. 0..0 */
{ 0x15,0x04,0x10,0x01,0x45,0x54,0x40,0x51 }, /* .1.1 ..0. .0.. 0..1 */
{ 0x51,0x51,0x45,0x45,0x01,0x01,0x15,0x15 }, /* .1.1 ..0. .0.. 1..0 */
{ 0x01,0x10,0x04,0x15,0x51,0x40,0x54,0x45 }, /* .1.1 ..0. .0.. 1..1 */
{ 0x14,0x14,0x00,0x00,0x44,0x44,0x50,0x50 }, /* .1.1 ..0. .1.. 0..0 */
{ 0x50,0x41,0x55,0x44,0x00,0x11,0x05,0x14 }, /* .1.1 ..0. .1.. 0..1 */
{ 0x00,0x41,0x00,0x41,0x11,0x50,0x11,0x50 }, /* .1.1 ..0. .1.. 1..0 */
{ 0x45,0x04,0x40,0x01,0x51,0x10,0x54,0x15 }, /* .1.1 ..0. .1.. 1..1 */
{ 0x11,0x14,0x55,0x50,0x00,0x05,0x44,0x41 }, /* .1.1 ..1. .0.. 0..0 */
{ 0x54,0x15,0x51,0x10,0x40,0x01,0x45,0x04 }, /* .1.1 ..1. .0.. 0..1 */
{ 0x04,0x01,0x40,0x45,0x15,0x10,0x51,0x54 }, /* .1.1 ..1. .0.. 1..0 */
{ 0x10,0x51,0x15,0x54,0x04,0x45,0x01,0x40 }, /* .1.1 ..1. .0.. 1..1 */
{ 0x55,0x50,0x41,0x44,0x44,0x41,0x50,0x55 }, /* .1.1 ..1. .1.. 0..0 */
{ 0x05,0x14,0x00,0x11,0x11,0x00,0x14,0x05 }, /* .1.1 ..1. .1.. 0..1 */
{ 0x41,0x44,0x55,0x50,0x50,0x55,0x44,0x41 }, /* .1.1 ..1. .1.. 1..0 */
{ 0x14,0x05,0x11,0x00,0x00,0x11,0x05,0x14 }, /* .1.1 ..1. .1.. 1..1 */
};
int A;
unsigned char *RAM = Machine->memory_region[Machine->drv->cpu[0].memory_region];
for (A = 0x0000;A < 0x8000;A++)
{
int row,col;
unsigned char src;
src = RAM[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);
/* pick the offset in the table from bits 0, 2, 4 and 6 of the source data */
col = ((src >> 0) & 1) + (((src >> 2) & 1) << 1) + (((src >> 4) & 1) << 2);
/* the bottom half of the translation table is the mirror image of the top */
if (src & 0x40) col = 7 - col;
/* decode the opcodes */
ROM[A] = src ^ opcode_xortable[row][col] ^ 0x00;
/* decode the data */
RAM[A] = src ^ data_xortable[row][col];
}
/* copy the opcodes from the not encrypted part of the ROMs */
for (A = 0x8000;A < 0x10000;A++)
ROM[A] = RAM[A];
}
void gardia_decode(void)
{
/* not decoded yet! */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -