src/mess/machine/nes.c
| r8315 | r8316 | |
| 90 | 90 | pcb_handlers_setup(machine); |
| 91 | 91 | |
| 92 | 92 | /* Set up the memory handlers for the mapper */ |
| 93 | | switch (state->mapper) |
| 93 | state->slow_banking = 0; |
| 94 | memory_install_read_bank(space, 0x8000, 0x9fff, 0, 0, "bank1"); |
| 95 | memory_install_read_bank(space, 0xa000, 0xbfff, 0, 0, "bank2"); |
| 96 | memory_install_read_bank(space, 0xc000, 0xdfff, 0, 0, "bank3"); |
| 97 | memory_install_read_bank(space, 0xe000, 0xffff, 0, 0, "bank4"); |
| 98 | memory_install_readwrite_bank(space, 0x6000, 0x7fff, 0, 0, "bank5"); |
| 99 | |
| 100 | /* configure banks 1-4 */ |
| 101 | for (i = 0; i < 4; i++) |
| 94 | 102 | { |
| 95 | | case 50: |
| 96 | | memory_install_write8_handler(space, 0x4020, 0x403f, 0, 0, nes_mapper50_add_w); |
| 97 | | memory_install_write8_handler(space, 0x40a0, 0x40bf, 0, 0, nes_mapper50_add_w); |
| 98 | | default: |
| 99 | | state->slow_banking = 0; |
| 100 | | memory_install_read_bank(space, 0x8000, 0x9fff, 0, 0, "bank1"); |
| 101 | | memory_install_read_bank(space, 0xa000, 0xbfff, 0, 0, "bank2"); |
| 102 | | memory_install_read_bank(space, 0xc000, 0xdfff, 0, 0, "bank3"); |
| 103 | | memory_install_read_bank(space, 0xe000, 0xffff, 0, 0, "bank4"); |
| 104 | | memory_install_readwrite_bank(space, 0x6000, 0x7fff, 0, 0, "bank5"); |
| 105 | | |
| 106 | | /* configure banks 1-4 */ |
| 107 | | for (i = 0; i < 4; i++) |
| 108 | | { |
| 109 | | memory_configure_bank(machine, bank_names[i], 0, prg_banks, memory_region(machine, "maincpu") + 0x10000, 0x2000); |
| 110 | | // some mappers (e.g. MMC5) can map PRG RAM in 0x8000-0xffff as well |
| 111 | | if (state->prg_ram) |
| 112 | | memory_configure_bank(machine, bank_names[i], prg_banks, state->wram_size / 0x2000, state->wram, 0x2000); |
| 113 | | // however, at start we point to PRG ROM |
| 114 | | memory_set_bank(machine, bank_names[i], i); |
| 115 | | state->prg_bank[i] = i; |
| 116 | | } |
| 117 | | |
| 118 | | /* bank 5 configuration is more delicate, since it can have PRG RAM, PRG ROM or SRAM mapped to it */ |
| 119 | | /* we first map PRG ROM banks, then the battery bank (if a battery is present), and finally PRG RAM (state->wram) */ |
| 120 | | memory_configure_bank(machine, "bank5", 0, prg_banks, memory_region(machine, "maincpu") + 0x10000, 0x2000); |
| 121 | | state->battery_bank5_start = prg_banks; |
| 122 | | state->prgram_bank5_start = prg_banks; |
| 123 | | state->empty_bank5_start = prg_banks; |
| 124 | | |
| 125 | | /* add battery ram, but only if there's no trainer since they share overlapping memory. */ |
| 126 | | if (state->battery && !state->trainer) |
| 127 | | { |
| 128 | | UINT32 bank_size = (state->battery_size > 0x2000) ? 0x2000 : state->battery_size; |
| 129 | | int bank_num = (state->battery_size > 0x2000) ? state->battery_size / 0x2000 : 1; |
| 130 | | memory_configure_bank(machine, "bank5", prg_banks, bank_num, state->battery_ram, bank_size); |
| 131 | | state->prgram_bank5_start += bank_num; |
| 132 | | state->empty_bank5_start += bank_num; |
| 133 | | } |
| 134 | | /* add prg ram. */ |
| 135 | | if (state->prg_ram) |
| 136 | | { |
| 137 | | memory_configure_bank(machine, "bank5", state->prgram_bank5_start, state->wram_size / 0x2000, state->wram, 0x2000); |
| 138 | | state->empty_bank5_start += state->wram_size / 0x2000; |
| 139 | | } |
| 140 | | |
| 141 | | memory_configure_bank(machine, "bank5", state->empty_bank5_start, 1, state->rom + 0x6000, 0x2000); |
| 142 | | |
| 143 | | /* if we have any additional PRG RAM, point bank5 to its first bank */ |
| 144 | | if (state->battery || state->prg_ram) |
| 145 | | state->prg_bank[4] = state->battery_bank5_start; |
| 146 | | else |
| 147 | | state->prg_bank[4] = state->empty_bank5_start; // or shall we point to "maincpu" region at 0x6000? point is that we should never access this region if no sram or wram is present! |
| 148 | | |
| 149 | | memory_set_bank(machine, "bank5", state->prg_bank[4]); |
| 150 | | |
| 151 | | if (state->four_screen_vram) |
| 152 | | { |
| 153 | | state->extended_ntram = auto_alloc_array(machine, UINT8, 0x2000); |
| 154 | | state_save_register_global_pointer(machine, state->extended_ntram, 0x2000); |
| 155 | | } |
| 156 | | |
| 157 | | // there are still some quirk about writes to bank5... I hope to fix them soon. (mappers 34,45,52,246 have both mid_w and WRAM-->check) |
| 158 | | if (state->mmc_write_mid) |
| 159 | | memory_install_write8_handler(space, 0x6000, 0x7fff, 0, 0, state->mmc_write_mid); |
| 160 | | if (state->mmc_write) |
| 161 | | memory_install_write8_handler(space, 0x8000, 0xffff, 0, 0, state->mmc_write); |
| 162 | | |
| 163 | | // In fact, we also allow single pcbs to overwrite the bank read handlers defined above, |
| 164 | | // because some pcbs (mainly pirate ones) require protection values to be read instead of |
| 165 | | // the expected ROM banks: these handlers, though, must take care of the ROM access as well |
| 166 | | if (state->mmc_read_mid) |
| 167 | | memory_install_read8_handler(space, 0x6000, 0x7fff, 0, 0, state->mmc_read_mid); |
| 168 | | if (state->mmc_read) |
| 169 | | memory_install_read8_handler(space, 0x8000, 0xffff, 0, 0, state->mmc_read); |
| 170 | | break; |
| 103 | memory_configure_bank(machine, bank_names[i], 0, prg_banks, memory_region(machine, "maincpu") + 0x10000, 0x2000); |
| 104 | // some mappers (e.g. MMC5) can map PRG RAM in 0x8000-0xffff as well |
| 105 | if (state->prg_ram) |
| 106 | memory_configure_bank(machine, bank_names[i], prg_banks, state->wram_size / 0x2000, state->wram, 0x2000); |
| 107 | // however, at start we point to PRG ROM |
| 108 | memory_set_bank(machine, bank_names[i], i); |
| 109 | state->prg_bank[i] = i; |
| 171 | 110 | } |
| 172 | | |
| 111 | |
| 112 | /* bank 5 configuration is more delicate, since it can have PRG RAM, PRG ROM or SRAM mapped to it */ |
| 113 | /* we first map PRG ROM banks, then the battery bank (if a battery is present), and finally PRG RAM (state->wram) */ |
| 114 | memory_configure_bank(machine, "bank5", 0, prg_banks, memory_region(machine, "maincpu") + 0x10000, 0x2000); |
| 115 | state->battery_bank5_start = prg_banks; |
| 116 | state->prgram_bank5_start = prg_banks; |
| 117 | state->empty_bank5_start = prg_banks; |
| 118 | |
| 119 | /* add battery ram, but only if there's no trainer since they share overlapping memory. */ |
| 120 | if (state->battery && !state->trainer) |
| 121 | { |
| 122 | UINT32 bank_size = (state->battery_size > 0x2000) ? 0x2000 : state->battery_size; |
| 123 | int bank_num = (state->battery_size > 0x2000) ? state->battery_size / 0x2000 : 1; |
| 124 | memory_configure_bank(machine, "bank5", prg_banks, bank_num, state->battery_ram, bank_size); |
| 125 | state->prgram_bank5_start += bank_num; |
| 126 | state->empty_bank5_start += bank_num; |
| 127 | } |
| 128 | /* add prg ram. */ |
| 129 | if (state->prg_ram) |
| 130 | { |
| 131 | memory_configure_bank(machine, "bank5", state->prgram_bank5_start, state->wram_size / 0x2000, state->wram, 0x2000); |
| 132 | state->empty_bank5_start += state->wram_size / 0x2000; |
| 133 | } |
| 134 | |
| 135 | memory_configure_bank(machine, "bank5", state->empty_bank5_start, 1, state->rom + 0x6000, 0x2000); |
| 136 | |
| 137 | /* if we have any additional PRG RAM, point bank5 to its first bank */ |
| 138 | if (state->battery || state->prg_ram) |
| 139 | state->prg_bank[4] = state->battery_bank5_start; |
| 140 | else |
| 141 | state->prg_bank[4] = state->empty_bank5_start; // or shall we point to "maincpu" region at 0x6000? point is that we should never access this region if no sram or wram is present! |
| 142 | |
| 143 | memory_set_bank(machine, "bank5", state->prg_bank[4]); |
| 144 | |
| 145 | if (state->four_screen_vram) |
| 146 | { |
| 147 | state->extended_ntram = auto_alloc_array(machine, UINT8, 0x2000); |
| 148 | state_save_register_global_pointer(machine, state->extended_ntram, 0x2000); |
| 149 | } |
| 150 | |
| 151 | // there are still some quirk about writes to bank5... I hope to fix them soon. (mappers 34,45,52,246 have both mid_w and WRAM-->check) |
| 152 | if (state->mmc_write_mid) |
| 153 | memory_install_write8_handler(space, 0x6000, 0x7fff, 0, 0, state->mmc_write_mid); |
| 154 | if (state->mmc_write) |
| 155 | memory_install_write8_handler(space, 0x8000, 0xffff, 0, 0, state->mmc_write); |
| 156 | |
| 157 | // In fact, we also allow single pcbs to overwrite the bank read handlers defined above, |
| 158 | // because some pcbs (mainly pirate ones) require protection values to be read instead of |
| 159 | // the expected ROM banks: these handlers, though, must take care of the ROM access as well |
| 160 | if (state->mmc_read_mid) |
| 161 | memory_install_read8_handler(space, 0x6000, 0x7fff, 0, 0, state->mmc_read_mid); |
| 162 | if (state->mmc_read) |
| 163 | memory_install_read8_handler(space, 0x8000, 0xffff, 0, 0, state->mmc_read); |
| 164 | |
| 173 | 165 | // install additional handlers |
| 174 | 166 | if (state->pcb_id == BTL_SMB2B) |
| 175 | 167 | { |
| 176 | 168 | memory_install_write8_handler(space, 0x4020, 0x403f, 0, 0, smb2jb_extra_w); |
| 177 | 169 | memory_install_write8_handler(space, 0x40a0, 0x40bf, 0, 0, smb2jb_extra_w); |
| 178 | 170 | } |
| 171 | if (state->mapper == 50) |
| 172 | { |
| 173 | memory_install_write8_handler(space, 0x4020, 0x403f, 0, 0, nes_mapper50_add_w); |
| 174 | memory_install_write8_handler(space, 0x40a0, 0x40bf, 0, 0, nes_mapper50_add_w); |
| 175 | } |
| 179 | 176 | } |
| 180 | 177 | |
| 181 | 178 | // to be probably removed (it does nothing since a long time) |