Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. static void brickzn_decrypt()
  2. {
  3. UINT8 *RAM = DrvZ80ROM0;
  4. size_t size = 0x50000;
  5. UINT8 *decrypt = DrvZ80Decrypted;
  6. int i;
  7.  
  8.  
  9. memcpy(decrypt, RAM, size);
  10. for (i = 0; i < 0x50000; i++)
  11. {
  12. static const UINT8 opcode_swaptable[8] =
  13. {
  14. 1,1,1,0,0,1,1,0
  15. };
  16. static const UINT8 data_swaptable[16] =
  17. {
  18. 1,1,1,0,0,1,1,1,1,0,1,1,1,1,1,1
  19. };
  20. int opcode_swap = opcode_swaptable[((i & 0x00c) >> 2) | ((i & 0x040) >> 4)];
  21. int data_swap = (i >= 0x8000) ? 0 : data_swaptable[(i & 0x003) | ((i & 0x008) >> 1) | ((i & 0x400) >> 7)];
  22. UINT8 x = RAM[i];
  23.  
  24. if (data_swap)
  25. {
  26. x = BITSWAP8(x, 7,6,5,4,3,2,0,1);
  27. RAM[i] = BITSWAP8(x, 7,2,3,4,5,6,1,0) ^ 0x10;
  28. }
  29.  
  30. if (opcode_swap)
  31. x ^= 0x80;
  32.  
  33. if (opcode_swap || data_swap)
  34. x = BITSWAP8(x, 7,2,3,4,5,6,1,0) ^ 0x10;
  35.  
  36. decrypt[i] = x;
  37.  
  38. // Alternate data decryption, activated at run-time. Store in higher banks.
  39. if (i >= 0x10000)
  40. RAM[i+0x40000] = RAM[i] ^ 0x44;
  41. }
  42.  
  43. return decrypt;
  44. }
  45.  
  46. DRIVER_INIT_MEMBER(suna8_state,brickzn)
  47. {
  48. UINT8 *RAM = memregion("maincpu")->base();
  49. UINT8 *decrypt = brickzn_decrypt();
  50. int i;
  51.  
  52. // Opcodes decrypted as data (to do: activated at run-time)
  53. for (i = 0; i < 0x8000; i++)
  54. {
  55. if ( ((i >= 0x072b) && (i <= 0x076f)) ||
  56. ((i >= 0x45c5) && (i <= 0x45e4)) ||
  57. ((i >= 0x7393) && (i <= 0x73ba)) ||
  58. ((i >= 0x7a79) && (i <= 0x7aa9)) )
  59. {
  60. decrypt[i] = RAM[i];
  61. }
  62. }
  63.  
  64. // !!!!!! PATCHES !!!!!!
  65.  
  66. // To do: ROM banking should be disabled here
  67. decrypt[0x11bb] = 0x00; // LD ($C040),A -> NOP
  68. decrypt[0x11bc] = 0x00; // LD ($C040),A -> NOP
  69. decrypt[0x11bd] = 0x00; // LD ($C040),A -> NOP
  70.  
  71. decrypt[0x3349] = 0xc9; // RET Z -> RET (to avoid: jp $C800)
  72.  
  73. // NMI enable / source??
  74. decrypt[0x1431] = 0xc9; // HALT -> RET
  75. decrypt[0x24b5] = 0x00; // HALT -> NOP
  76. decrypt[0x2593] = 0x00; // HALT -> NOP
  77.  
  78. // Data banks: 00-0f normal data decryption, 10-1f alternate data decryption:
  79. membank("bank1")->configure_entries(0, 16*2, memregion("maincpu")->base() + 0x10000, 0x4000);
  80. // Opcode banks: 00-1f normal opcode decryption:
  81. membank("bank1")->configure_decrypted_entries(0, 16, decrypt + 0x10000, 0x4000);
  82. membank("bank1")->configure_decrypted_entries(16, 16, decrypt + 0x10000, 0x4000);
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement