src/mess/machine/nes.c
| r8217 | r8218 | |
| 34 | 34 | { |
| 35 | 35 | nes_state *state = (nes_state *)machine->driver_data; |
| 36 | 36 | const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 37 | static const char *const bank_names[] = { "bank1", "bank2", "bank3", "bank4" }; |
| 38 | int prg_banks = (state->prg_chunks == 1) ? (2 * 2) : (state->prg_chunks * 2); |
| 39 | int i; |
| 37 | 40 | |
| 38 | 41 | /* We set these here in case they weren't set in the cart loader */ |
| 39 | 42 | state->rom = memory_region(machine, "maincpu"); |
| r8217 | r8218 | |
| 89 | 92 | memory_install_read_bank(space, 0xa000, 0xbfff, 0, 0, "bank2"); |
| 90 | 93 | memory_install_read_bank(space, 0xc000, 0xdfff, 0, 0, "bank3"); |
| 91 | 94 | memory_install_read_bank(space, 0xe000, 0xffff, 0, 0, "bank4"); |
| 92 | | memory_set_bankptr(machine, "bank1", memory_region(machine, "maincpu") + 0x6000); |
| 93 | | memory_set_bankptr(machine, "bank2", memory_region(machine, "maincpu") + 0x8000); |
| 94 | | memory_set_bankptr(machine, "bank3", memory_region(machine, "maincpu") + 0xa000); |
| 95 | | memory_set_bankptr(machine, "bank4", memory_region(machine, "maincpu") + 0xc000); |
| 96 | | memory_set_bankptr(machine, "bank5", memory_region(machine, "maincpu") + 0xe000); |
| 97 | 95 | |
| 96 | // initially setup banks to maincpu 0x8000-0xffff |
| 97 | for (i = 0; i < 4; i++) |
| 98 | { |
| 99 | memory_configure_bank(machine, bank_names[i], 0, prg_banks, memory_region(machine, "maincpu") + 0x10000, 0x2000); |
| 100 | memory_set_bank(machine, bank_names[i], i); |
| 101 | state->prg_bank[i] = i; |
| 102 | } |
| 103 | |
| 104 | memory_configure_bank(machine, "bank5", 0, 1, memory_region(machine, "maincpu") + 0x6000, 0x2000); |
| 105 | memory_configure_bank(machine, "bank5", 1, prg_banks, memory_region(machine, "maincpu") + 0x10000, 0x2000); |
| 106 | memory_set_bank(machine, "bank5", 0); |
| 107 | state->prg_bank[4] = 0; |
| 108 | |
| 98 | 109 | memory_install_write8_handler(space, 0x6000, 0x7fff, 0, 0, nes_mid_mapper_w); |
| 99 | 110 | // memory_install_read8_handler(space, 0x6000, 0x7fff, 0, 0, nes_mid_mapper_r); |
| 100 | 111 | memory_install_write8_handler(space, 0x8000, 0xffff, 0, 0, nes_mapper_w); |
| r8217 | r8218 | |
| 168 | 179 | |
| 169 | 180 | int nes_ppu_vidaccess( running_device *device, int address, int data ) |
| 170 | 181 | { |
| 171 | | nes_state *state = (nes_state *)device->machine->driver_data; |
| 182 | // nes_state *state = (nes_state *)device->machine->driver_data; |
| 172 | 183 | |
| 173 | 184 | /* TODO: this is a bit of a hack, needed to get Argus, ASO, etc to work */ |
| 174 | 185 | /* but, B-Wings, submath (j) seem to use this location differently... */ |
| 175 | | if (state->chr_chunks && (address & 0x3fff) < 0x2000) |
| 176 | | { |
| 186 | // if (state->chr_chunks && (address & 0x3fff) < 0x2000) |
| 187 | // { |
| 177 | 188 | // int vrom_loc; |
| 178 | 189 | // vrom_loc = (nes_vram[(address & 0x1fff) >> 10] * 16) + (address & 0x3ff); |
| 179 | 190 | // data = state->vrom [vrom_loc]; |
| 180 | | } |
| 191 | // } |
| 181 | 192 | return data; |
| 182 | 193 | } |
| 183 | 194 | |
| r8217 | r8218 | |
| 209 | 220 | timer_adjust_oneshot(state->irq_timer, attotime_never, 0); |
| 210 | 221 | } |
| 211 | 222 | |
| 223 | static STATE_POSTLOAD( nes_banks_restore ) |
| 224 | { |
| 225 | nes_state *state = (nes_state *)machine->driver_data; |
| 226 | |
| 227 | memory_set_bank(machine, "bank1", state->prg_bank[0]); |
| 228 | memory_set_bank(machine, "bank2", state->prg_bank[1]); |
| 229 | memory_set_bank(machine, "bank3", state->prg_bank[2]); |
| 230 | memory_set_bank(machine, "bank4", state->prg_bank[3]); |
| 231 | memory_set_bank(machine, "bank5", state->prg_bank[4]); |
| 232 | } |
| 233 | |
| 212 | 234 | static void nes_state_register( running_machine *machine ) |
| 213 | 235 | { |
| 214 | 236 | nes_state *state = (nes_state *)machine->driver_data; |
| 215 | 237 | |
| 238 | state_save_register_global_array(machine, state->prg_bank); |
| 239 | |
| 216 | 240 | state_save_register_global(machine, state->MMC5_floodtile); |
| 217 | 241 | state_save_register_global(machine, state->MMC5_floodattr); |
| 218 | 242 | state_save_register_global_array(machine, state->mmc5_vram); |
| r8217 | r8218 | |
| 220 | 244 | |
| 221 | 245 | state_save_register_global_array(machine, state->nes_vram_sprite); |
| 222 | 246 | state_save_register_global(machine, state->last_frame_flip); |
| 223 | | state_save_register_global(machine, state->scanlines_per_frame); |
| 224 | 247 | state_save_register_global(machine, state->mid_ram_enable); |
| 225 | 248 | |
| 226 | 249 | // shared mapper variables |
| r8217 | r8218 | |
| 255 | 278 | state_save_register_global(machine, state->fds_write_reg); |
| 256 | 279 | state_save_register_global(machine, state->fds_last_side); |
| 257 | 280 | state_save_register_global(machine, state->fds_count); |
| 281 | |
| 282 | state_save_register_postload(machine, nes_banks_restore, NULL); |
| 258 | 283 | } |
| 259 | 284 | |
| 260 | 285 | MACHINE_START( nes ) |
src/mess/machine/nes_mmc.c
| r8217 | r8218 | |
| 322 | 322 | |
| 323 | 323 | *************************************************************/ |
| 324 | 324 | |
| 325 | INLINE void prg_bank_refresh( running_machine *machine ) |
| 326 | { |
| 327 | nes_state *state = (nes_state *)machine->driver_data; |
| 328 | memory_set_bank(machine, "bank1", state->prg_bank[0]); |
| 329 | memory_set_bank(machine, "bank2", state->prg_bank[1]); |
| 330 | memory_set_bank(machine, "bank3", state->prg_bank[2]); |
| 331 | memory_set_bank(machine, "bank4", state->prg_bank[3]); |
| 332 | } |
| 333 | |
| 325 | 334 | /* PRG ROM in 8K, 16K or 32K blocks */ |
| 326 | 335 | |
| 327 | 336 | static void prg32( running_machine *machine, int bank ) |
| r8217 | r8218 | |
| 334 | 343 | memcpy(&state->rom[0x8000], &state->rom[bank * 0x8000 + 0x10000], 0x8000); |
| 335 | 344 | else |
| 336 | 345 | { |
| 337 | | memory_set_bankptr(machine, "bank1", &state->rom[bank * 0x8000 + 0x10000]); |
| 338 | | memory_set_bankptr(machine, "bank2", &state->rom[bank * 0x8000 + 0x12000]); |
| 339 | | memory_set_bankptr(machine, "bank3", &state->rom[bank * 0x8000 + 0x14000]); |
| 340 | | memory_set_bankptr(machine, "bank4", &state->rom[bank * 0x8000 + 0x16000]); |
| 346 | state->prg_bank[0] = bank * 4 + 0; |
| 347 | state->prg_bank[1] = bank * 4 + 1; |
| 348 | state->prg_bank[2] = bank * 4 + 2; |
| 349 | state->prg_bank[3] = bank * 4 + 3; |
| 350 | prg_bank_refresh(machine); |
| 341 | 351 | } |
| 342 | 352 | } |
| 343 | 353 | |
| r8217 | r8218 | |
| 351 | 361 | memcpy(&state->rom[0x8000], &state->rom[bank * 0x4000 + 0x10000], 0x4000); |
| 352 | 362 | else |
| 353 | 363 | { |
| 354 | | memory_set_bankptr(machine, "bank1", &state->rom[bank * 0x4000 + 0x10000]); |
| 355 | | memory_set_bankptr(machine, "bank2", &state->rom[bank * 0x4000 + 0x12000]); |
| 364 | state->prg_bank[0] = bank * 2 + 0; |
| 365 | state->prg_bank[1] = bank * 2 + 1; |
| 366 | prg_bank_refresh(machine); |
| 356 | 367 | } |
| 357 | 368 | } |
| 358 | 369 | |
| r8217 | r8218 | |
| 366 | 377 | memcpy(&state->rom[0xc000], &state->rom[bank * 0x4000 + 0x10000], 0x4000); |
| 367 | 378 | else |
| 368 | 379 | { |
| 369 | | memory_set_bankptr(machine, "bank3", &state->rom[bank * 0x4000 + 0x10000]); |
| 370 | | memory_set_bankptr(machine, "bank4", &state->rom[bank * 0x4000 + 0x12000]); |
| 380 | state->prg_bank[2] = bank * 2 + 0; |
| 381 | state->prg_bank[3] = bank * 2 + 1; |
| 382 | prg_bank_refresh(machine); |
| 371 | 383 | } |
| 372 | 384 | } |
| 373 | 385 | |
| r8217 | r8218 | |
| 380 | 392 | if (state->slow_banking) |
| 381 | 393 | memcpy(&state->rom[0x8000], &state->rom[bank * 0x2000 + 0x10000], 0x2000); |
| 382 | 394 | else |
| 383 | | memory_set_bankptr(machine, "bank1", &state->rom[bank * 0x2000 + 0x10000]); |
| 395 | { |
| 396 | state->prg_bank[0] = bank; |
| 397 | prg_bank_refresh(machine); |
| 398 | } |
| 384 | 399 | } |
| 385 | 400 | |
| 386 | 401 | static void prg8_ab( running_machine *machine, int bank ) |
| r8217 | r8218 | |
| 392 | 407 | if (state->slow_banking) |
| 393 | 408 | memcpy(&state->rom[0xa000], &state->rom[bank * 0x2000 + 0x10000], 0x2000); |
| 394 | 409 | else |
| 395 | | memory_set_bankptr(machine, "bank2", &state->rom[bank * 0x2000 + 0x10000]); |
| 410 | { |
| 411 | state->prg_bank[1] = bank; |
| 412 | prg_bank_refresh(machine); |
| 413 | } |
| 396 | 414 | } |
| 397 | 415 | |
| 398 | 416 | static void prg8_cd( running_machine *machine, int bank ) |
| r8217 | r8218 | |
| 404 | 422 | if (state->slow_banking) |
| 405 | 423 | memcpy(&state->rom[0xc000], &state->rom[bank * 0x2000 + 0x10000], 0x2000); |
| 406 | 424 | else |
| 407 | | memory_set_bankptr(machine, "bank3", &state->rom[bank * 0x2000 + 0x10000]); |
| 425 | { |
| 426 | state->prg_bank[2] = bank; |
| 427 | prg_bank_refresh(machine); |
| 428 | } |
| 408 | 429 | } |
| 409 | 430 | |
| 410 | 431 | static void prg8_ef( running_machine *machine, int bank ) |
| r8217 | r8218 | |
| 416 | 437 | if (state->slow_banking) |
| 417 | 438 | memcpy(&state->rom[0xe000], &state->rom[bank * 0x2000 + 0x10000], 0x2000); |
| 418 | 439 | else |
| 419 | | memory_set_bankptr(machine, "bank4", &state->rom[bank * 0x2000 + 0x10000]); |
| 440 | { |
| 441 | state->prg_bank[3] = bank; |
| 442 | prg_bank_refresh(machine); |
| 443 | } |
| 420 | 444 | } |
| 421 | 445 | |
| 422 | 446 | /* We define an additional helper to map PRG-ROM to 0x6000-0x7000 */ |
| r8217 | r8218 | |
| 428 | 452 | |
| 429 | 453 | /* assumes that bank references an 8k chunk */ |
| 430 | 454 | bank &= ((state->prg_chunks << 1) - 1); |
| 431 | | memory_set_bankptr(machine, "bank5", &state->rom[bank * 0x2000 + 0x10000]); |
| 455 | state->prg_bank[4] = bank + 1; // we have an additional 0x2000 bank at start (pointing to 0x6000), followed by usual banks |
| 456 | memory_set_bank(machine, "bank5", state->prg_bank[4]); |
| 432 | 457 | } |
| 433 | 458 | |
| 434 | 459 | /* CHR ROM in 1K, 2K, 4K or 8K blocks */ |