trunk/src/mame/drivers/suna8.c
| r241382 | r241383 | |
| 86 | 86 | |
| 87 | 87 | UINT8 *suna8_state::brickzn_decrypt() |
| 88 | 88 | { |
| 89 | | address_space &space = m_maincpu->space(AS_PROGRAM); |
| 90 | 89 | UINT8 *RAM = memregion("maincpu")->base(); |
| 91 | 90 | size_t size = memregion("maincpu")->bytes(); |
| 92 | 91 | UINT8 *decrypt = auto_alloc_array(machine(), UINT8, size); |
| 93 | 92 | int i; |
| 94 | 93 | |
| 95 | | space.set_decrypted_region(0x0000, 0x7fff, decrypt); |
| 96 | | |
| 97 | 94 | /* Opcodes and data */ |
| 98 | 95 | for (i = 0; i < 0x50000; i++) |
| 99 | 96 | { |
| r241382 | r241383 | |
| 133 | 130 | |
| 134 | 131 | DRIVER_INIT_MEMBER(suna8_state,brickzn) |
| 135 | 132 | { |
| 136 | | UINT8 *RAM = memregion("maincpu")->base(); |
| 137 | | UINT8 *decrypt = brickzn_decrypt(); |
| 138 | | int i; |
| 133 | m_decrypt = brickzn_decrypt(); |
| 139 | 134 | |
| 140 | | // Opcodes decrypted as data (to do: activated at run-time) |
| 141 | | for (i = 0; i < 0x8000; i++) |
| 142 | | { |
| 143 | | if ( ((i >= 0x072b) && (i <= 0x076f)) || |
| 144 | | ((i >= 0x45c5) && (i <= 0x45e4)) || |
| 145 | | ((i >= 0x7393) && (i <= 0x73ba)) || |
| 146 | | ((i >= 0x7a79) && (i <= 0x7aa9)) ) |
| 147 | | { |
| 148 | | decrypt[i] = RAM[i]; |
| 149 | | } |
| 150 | | } |
| 151 | | |
| 152 | 135 | // !!!!!! PATCHES !!!!!! |
| 153 | 136 | |
| 154 | 137 | // To do: ROM banking should be disabled here |
| 155 | | decrypt[0x11bb] = 0x00; // LD ($C040),A -> NOP |
| 156 | | decrypt[0x11bc] = 0x00; // LD ($C040),A -> NOP |
| 157 | | decrypt[0x11bd] = 0x00; // LD ($C040),A -> NOP |
| 138 | m_decrypt[0x11bb] = 0x00; // LD ($C040),A -> NOP |
| 139 | m_decrypt[0x11bc] = 0x00; // LD ($C040),A -> NOP |
| 140 | m_decrypt[0x11bd] = 0x00; // LD ($C040),A -> NOP |
| 158 | 141 | |
| 159 | | decrypt[0x3349] = 0xc9; // RET Z -> RET (to avoid: jp $C800) |
| 142 | m_decrypt[0x3349] = 0xc9; // RET Z -> RET (to avoid: jp $C800) |
| 160 | 143 | |
| 161 | 144 | // NMI enable / source?? |
| 162 | | decrypt[0x1431] = 0xc9; // HALT -> RET |
| 163 | | decrypt[0x24b5] = 0x00; // HALT -> NOP |
| 164 | | decrypt[0x2593] = 0x00; // HALT -> NOP |
| 145 | m_decrypt[0x1431] = 0xc9; // HALT -> RET |
| 146 | m_decrypt[0x24b5] = 0x00; // HALT -> NOP |
| 147 | m_decrypt[0x2593] = 0x00; // HALT -> NOP |
| 165 | 148 | |
| 149 | // Non-banked opcodes |
| 150 | address_space &space = m_maincpu->space(AS_PROGRAM); |
| 151 | space.set_decrypted_region(0x0000, 0x7fff, m_decrypt); |
| 152 | |
| 166 | 153 | // Data banks: 00-0f normal data decryption, 10-1f alternate data decryption: |
| 167 | 154 | membank("bank1")->configure_entries(0, 16*2, memregion("maincpu")->base() + 0x10000, 0x4000); |
| 168 | 155 | // Opcode banks: 00-1f normal opcode decryption: |
| 169 | | membank("bank1")->configure_decrypted_entries(0, 16, decrypt + 0x10000, 0x4000); |
| 170 | | membank("bank1")->configure_decrypted_entries(16, 16, decrypt + 0x10000, 0x4000); |
| 156 | membank("bank1")->configure_decrypted_entries(0, 16, m_decrypt + 0x10000, 0x4000); |
| 157 | membank("bank1")->configure_decrypted_entries(16, 16, m_decrypt + 0x10000, 0x4000); |
| 171 | 158 | } |
| 172 | 159 | |
| 173 | 160 | DRIVER_INIT_MEMBER(suna8_state,brickznv4) |
| 174 | 161 | { |
| 175 | | UINT8 *RAM = memregion("maincpu")->base(); |
| 176 | | UINT8 *decrypt = brickzn_decrypt(); |
| 177 | | int i; |
| 178 | | |
| 179 | | // Opcodes decrypted as data (to do: activated at run-time) |
| 180 | | for (i = 0; i < 0x8000; i++) |
| 181 | | { |
| 182 | | if ( ((i >= 0x072b) && (i <= 0x076f)) || |
| 183 | | ((i >= 0x4541) && (i <= 0x4560)) || |
| 184 | | ((i >= 0x72f3) && (i <= 0x7322)) || |
| 185 | | ((i >= 0x79d9) && (i <= 0x7a09)) ) |
| 186 | | { |
| 187 | | decrypt[i] = RAM[i]; |
| 188 | | } |
| 189 | | } |
| 190 | | |
| 162 | m_decrypt = brickzn_decrypt(); |
| 191 | 163 | // !!!!!! PATCHES !!!!!! |
| 192 | 164 | |
| 193 | 165 | // To do: ROM banking should be disabled here |
| 194 | | decrypt[0x1190] = 0x00; // LD ($C040),A -> NOP |
| 195 | | decrypt[0x1191] = 0x00; // LD ($C040),A -> NOP |
| 196 | | decrypt[0x1192] = 0x00; // LD ($C040),A -> NOP |
| 166 | m_decrypt[0x1190] = 0x00; // LD ($C040),A -> NOP |
| 167 | m_decrypt[0x1191] = 0x00; // LD ($C040),A -> NOP |
| 168 | m_decrypt[0x1192] = 0x00; // LD ($C040),A -> NOP |
| 197 | 169 | |
| 198 | | decrypt[0x3337] = 0xc9; // RET Z -> RET (to avoid: jp $C800) |
| 170 | m_decrypt[0x3337] = 0xc9; // RET Z -> RET (to avoid: jp $C800) |
| 199 | 171 | |
| 200 | 172 | // NMI enable / source?? |
| 201 | | decrypt[0x1406] = 0xc9; // HALT -> RET |
| 202 | | decrypt[0x2487] = 0x00; // HALT -> NOP |
| 203 | | decrypt[0x256c] = 0x00; // HALT -> NOP |
| 173 | m_decrypt[0x1406] = 0xc9; // HALT -> RET |
| 174 | m_decrypt[0x2487] = 0x00; // HALT -> NOP |
| 175 | m_decrypt[0x256c] = 0x00; // HALT -> NOP |
| 204 | 176 | |
| 177 | // Non-banked opcodes |
| 178 | address_space &space = m_maincpu->space(AS_PROGRAM); |
| 179 | space.set_decrypted_region(0x0000, 0x7fff, m_decrypt); |
| 180 | |
| 205 | 181 | // Data banks: 00-0f normal data decryption, 10-1f alternate data decryption: |
| 206 | 182 | membank("bank1")->configure_entries(0, 16*2, memregion("maincpu")->base() + 0x10000, 0x4000); |
| 207 | 183 | // Opcode banks: 00-1f normal opcode decryption: |
| 208 | | membank("bank1")->configure_decrypted_entries(0, 16, decrypt + 0x10000, 0x4000); |
| 209 | | membank("bank1")->configure_decrypted_entries(16, 16, decrypt + 0x10000, 0x4000); |
| 184 | membank("bank1")->configure_decrypted_entries(0, 16, m_decrypt + 0x10000, 0x4000); |
| 185 | membank("bank1")->configure_decrypted_entries(16, 16, m_decrypt + 0x10000, 0x4000); |
| 210 | 186 | } |
| 211 | 187 | |
| 212 | 188 | |
| r241382 | r241383 | |
| 700 | 676 | */ |
| 701 | 677 | WRITE8_MEMBER(suna8_state::brickzn_multi_w) |
| 702 | 678 | { |
| 703 | | if ((m_protection_val & 0xfc) == 0x88 || (m_protection_val & 0xfc) == 0x8c) |
| 679 | int protselect = m_protection_val & 0xfc; |
| 680 | |
| 681 | if ((protselect == 0x88) || (protselect == 0x8c)) |
| 704 | 682 | { |
| 705 | 683 | m_palettebank = data & 0x01; |
| 706 | 684 | |
| r241382 | r241383 | |
| 713 | 691 | |
| 714 | 692 | logerror("CPU #0 - PC %04X: soundlatch = %02X\n",space.device().safe_pc(),data); |
| 715 | 693 | } |
| 716 | | else if ((m_protection_val & 0xfc) == 0x04) |
| 694 | else if (protselect == 0x04) |
| 717 | 695 | { |
| 718 | 696 | set_led_status(machine(), 0, data & 0x01); |
| 719 | 697 | set_led_status(machine(), 1, data & 0x02); |
| r241382 | r241383 | |
| 722 | 700 | logerror("CPU #0 - PC %04X: leds = %02X\n",space.device().safe_pc(),data); |
| 723 | 701 | if (data & ~0x07) logerror("CPU #0 - PC %04X: unknown leds bits: %02X\n",space.device().safe_pc(),data); |
| 724 | 702 | } |
| 725 | | else if ((m_protection_val & 0xfc) == 0x9c) |
| 703 | else if (protselect == 0x80) |
| 726 | 704 | { |
| 727 | | // controls opcode decryption |
| 728 | | // see code at 71b, 45b7, 7380, 7a6b |
| 729 | | |
| 730 | | // To be done: run-time opcode decryption change. Done in driver_init for now. |
| 731 | | |
| 732 | | logerror("CPU #0 - PC %04X: op-decrypt = %02X\n",space.device().safe_pc(),data); |
| 733 | | } |
| 734 | | else if ((m_protection_val & 0xfc) == 0x80) |
| 735 | | { |
| 736 | 705 | // disables rom banking? |
| 737 | 706 | // see code at 11b1: |
| 738 | 707 | |
| r241382 | r241383 | |
| 742 | 711 | { |
| 743 | 712 | logerror("CPU #0 - PC %04X: ignore = %02X\n",space.device().safe_pc(),data); |
| 744 | 713 | } |
| 714 | |
| 715 | if ((m_protection_val & 0x1f) == 0x1c) |
| 716 | { |
| 717 | // controls opcode decryption |
| 718 | // see code at 71b, 45b7, 7380, 7a6b |
| 719 | //printf("CPU #0 - PC %04X: alt op-decrypt tog = %02X\n",space.device().safe_pc(),data); |
| 720 | m_prot_opcode_toggle ^= 1; |
| 721 | |
| 722 | if (m_prot_opcode_toggle == 0) |
| 723 | { |
| 724 | address_space &space = m_maincpu->space(AS_PROGRAM); |
| 725 | space.set_decrypted_region(0x0000, 0x7fff, m_decrypt); |
| 726 | } |
| 727 | else |
| 728 | { |
| 729 | address_space &space = m_maincpu->space(AS_PROGRAM); |
| 730 | space.set_decrypted_region(0x0000, 0x7fff, memregion("maincpu")->base()); |
| 731 | } |
| 732 | |
| 733 | |
| 734 | } |
| 735 | |
| 745 | 736 | } |
| 746 | 737 | |
| 747 | 738 | /* |