Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void brickzn_decrypt()
- {
- UINT8 *RAM = DrvZ80ROM0;
- size_t size = 0x50000;
- UINT8 *decrypt = DrvZ80Decrypted;
- int i;
- memcpy(decrypt, RAM, size);
- for (i = 0; i < 0x50000; i++)
- {
- static const UINT8 opcode_swaptable[8] =
- {
- 1,1,1,0,0,1,1,0
- };
- static const UINT8 data_swaptable[16] =
- {
- 1,1,1,0,0,1,1,1,1,0,1,1,1,1,1,1
- };
- int opcode_swap = opcode_swaptable[((i & 0x00c) >> 2) | ((i & 0x040) >> 4)];
- int data_swap = (i >= 0x8000) ? 0 : data_swaptable[(i & 0x003) | ((i & 0x008) >> 1) | ((i & 0x400) >> 7)];
- UINT8 x = RAM[i];
- if (data_swap)
- {
- x = BITSWAP8(x, 7,6,5,4,3,2,0,1);
- RAM[i] = BITSWAP8(x, 7,2,3,4,5,6,1,0) ^ 0x10;
- }
- if (opcode_swap)
- x ^= 0x80;
- if (opcode_swap || data_swap)
- x = BITSWAP8(x, 7,2,3,4,5,6,1,0) ^ 0x10;
- decrypt[i] = x;
- // Alternate data decryption, activated at run-time. Store in higher banks.
- if (i >= 0x10000)
- RAM[i+0x40000] = RAM[i] ^ 0x44;
- }
- return decrypt;
- }
- DRIVER_INIT_MEMBER(suna8_state,brickzn)
- {
- UINT8 *RAM = memregion("maincpu")->base();
- UINT8 *decrypt = brickzn_decrypt();
- int i;
- // Opcodes decrypted as data (to do: activated at run-time)
- for (i = 0; i < 0x8000; i++)
- {
- if ( ((i >= 0x072b) && (i <= 0x076f)) ||
- ((i >= 0x45c5) && (i <= 0x45e4)) ||
- ((i >= 0x7393) && (i <= 0x73ba)) ||
- ((i >= 0x7a79) && (i <= 0x7aa9)) )
- {
- decrypt[i] = RAM[i];
- }
- }
- // !!!!!! PATCHES !!!!!!
- // To do: ROM banking should be disabled here
- decrypt[0x11bb] = 0x00; // LD ($C040),A -> NOP
- decrypt[0x11bc] = 0x00; // LD ($C040),A -> NOP
- decrypt[0x11bd] = 0x00; // LD ($C040),A -> NOP
- decrypt[0x3349] = 0xc9; // RET Z -> RET (to avoid: jp $C800)
- // NMI enable / source??
- decrypt[0x1431] = 0xc9; // HALT -> RET
- decrypt[0x24b5] = 0x00; // HALT -> NOP
- decrypt[0x2593] = 0x00; // HALT -> NOP
- // Data banks: 00-0f normal data decryption, 10-1f alternate data decryption:
- membank("bank1")->configure_entries(0, 16*2, memregion("maincpu")->base() + 0x10000, 0x4000);
- // Opcode banks: 00-1f normal opcode decryption:
- membank("bank1")->configure_decrypted_entries(0, 16, decrypt + 0x10000, 0x4000);
- membank("bank1")->configure_decrypted_entries(16, 16, decrypt + 0x10000, 0x4000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement