Previous 15994 Revisions Next

r8227 Saturday 5th June, 2010 at 09:24:17 UTC by Fabio Priuli
[NES] A few more memory_set_bankptr -> memory_set_bank replacements, added
PRG RAM banks to the banks which can be mapped in 0x8000-0xffff (needed by e.g. MMC5),
fixed a small mistake in bank config when less than 8K WRAM is present.
[src/mess/includes]nes.h
[src/mess/machine]nes.c nes_ines.c

src/mess/includes/nes.h
r8226r8227
7373   chr_bank      chr_map[8];  //quick banking structure, because some of this changes multiple times per scanline!
7474   name_table    nt_page[4];  //quick banking structure for a maximum of 4K of RAM/ROM/ExRAM
7575
76   int prgram_bank_start;
76   int prgram_bank5_start;
7777   int MMC5_floodtile;
7878   int MMC5_floodattr;
7979   UINT8 mmc5_vram[0x400];
src/mess/machine/nes.c
r8226r8227
9696         memory_install_read_bank(space, 0xc000, 0xdfff, 0, 0, "bank3");
9797         memory_install_read_bank(space, 0xe000, 0xffff, 0, 0, "bank4");
9898
99         // initially setup banks to maincpu 0x8000-0xffff
99         /* configure banks 1-4 */
100100         for (i = 0; i < 4; i++)
101101         {
102102            memory_configure_bank(machine, bank_names[i], 0, prg_banks, memory_region(machine, "maincpu") + 0x10000, 0x2000);
103            // some mappers (e.g. MMC5) can map PRG RAM in  0x8000-0xffff as well
104            if (state->prg_ram)
105               memory_configure_bank(machine, bank_names[i], prg_banks, state->wram_size / 0x2000, state->wram, 0x2000);
106            // however, at start we point to PRG ROM
103107            memory_set_bank(machine, bank_names[i], i);
104108            state->prg_bank[i] = i;
105109         }
106110
107         state->prgram_bank_start = prg_banks;
108111         /* bank 5 configuration is more delicate, since it can have PRG RAM, PRG ROM or SRAM mapped to it */
109112         /* we first map PRG ROM banks, then the battery bank (if a battery is present), and finally PRG RAM (state->wram) */
110113         memory_configure_bank(machine, "bank5", 0, prg_banks, memory_region(machine, "maincpu") + 0x10000, 0x2000);
114         state->prgram_bank5_start = prg_banks;
111115         /* add battery ram, but only if there's no trainer since they share overlapping memory. */
112116         if (state->battery && !state->trainer)
113117         {
114118            memory_configure_bank(machine, "bank5", prg_banks, 1, state->battery_ram, state->battery_size);
115            state->prgram_bank_start += 1;
119            state->prgram_bank5_start += 1;
116120         }
117121         /* add prg ram. */
118122         if (state->prg_ram)
119            memory_configure_bank(machine, "bank5", state->prgram_bank_start, 8, state->wram, 0x2000);
123            memory_configure_bank(machine, "bank5", state->prgram_bank5_start, state->wram_size / 0x2000, state->wram, 0x2000);
120124
121125         /* if we have any additional PRG RAM, point bank5 to its first bank */
122126         if (state->battery || state->prg_ram)
src/mess/machine/nes_ines.c
r8226r8227
513513
514514      case 0x1013: /* $5113 */
515515         LOG_MMC(("MMC5 mid RAM bank select: %02x\n", data & 0x07));
516         state->prg_bank[4] = state->prgram_bank_start + (data & 0x07);
516         state->prg_bank[4] = state->prgram_bank5_start + (data & 0x07);
517517         memory_set_bank(space->machine, "bank5", state->prg_bank[4]);
518518         break;
519519
r8226r8227
526526               if (data & 0x80)
527527               {
528528                  /* ROM */
529                  LOG_MMC(("\tROM bank select (8k, $8000): %02x\n", data));
530                  data &= ((state->prg_chunks << 1) - 1);
531                  memory_set_bankptr(space->machine, "bank1", &state->rom[data * 0x2000 + 0x10000]);
529                  LOG_MMC(("\tROM bank select (8k, $8000): %02x\n", data & 0x7f));
530                  prg8_89(space->machine, data & 0x7f);
532531               }
533532               else
534533               {
535534                  /* RAM */
536535                  LOG_MMC(("\tRAM bank select (8k, $8000): %02x\n", data & 0x07));
537                  /* The & 4 is a hack that'll tide us over for now */
538                  memory_set_bankptr(space->machine, "bank1", &state->wram[(data & 4) * 0x2000]);
536                  state->prg_bank[0] = state->prg_chunks + data & 0x07;
537                  memory_set_bank(space->machine, "bank1", state->prg_bank[0]);
539538               }
540539               break;
541540         }
r8226r8227
549548               if (data & 0x80)
550549               {
551550                  /* 16k switch - ROM only */
551                  LOG_MMC(("\tROM bank select (16k, $8000): %02x\n", (data & 0x7f) >> 1));
552552                  prg16_89ab(space->machine, (data & 0x7f) >> 1);
553553               }
554554               else
555555               {
556556                  /* RAM */
557                  LOG_MMC(("\tRAM bank select (16k, $8000): %02x\n", data & 0x07));
558                  /* The & 4 is a hack that'll tide us over for now */
559                  memory_set_bankptr(space->machine, "bank1", &state->wram[((data & 4) >> 1) * 0x4000]);
560                  memory_set_bankptr(space->machine, "bank2", &state->wram[((data & 4) >> 1) * 0x4000 + 0x2000]);
557                  LOG_MMC(("\tRAM bank select (16k, $8000): %02x\n", (data & 0x07) >> 1));
558                  state->prg_bank[0] = state->prg_chunks + (data & 0x06);
559                  state->prg_bank[1] = state->prg_chunks + (data & 0x06) + 1;
560                  memory_set_bank(space->machine, "bank1", state->prg_bank[0]);
561                  memory_set_bank(space->machine, "bank2", state->prg_bank[1]);
561562               }
562563               break;
563564            case 0x03:
r8226r8227
565566               if (data & 0x80)
566567               {
567568                  /* ROM */
568                  data &= ((state->prg_chunks << 1) - 1);
569                  memory_set_bankptr(space->machine, "bank2", &state->rom[data * 0x2000 + 0x10000]);
569                  LOG_MMC(("\tROM bank select (8k, $a000): %02x\n", data & 0x7f));
570                  prg8_ab(space->machine, data & 0x7f);
570571               }
571572               else
572573               {
573574                  /* RAM */
574575                  LOG_MMC(("\tRAM bank select (8k, $a000): %02x\n", data & 0x07));
575                  /* The & 4 is a hack that'll tide us over for now */
576                  memory_set_bankptr(space->machine, "bank2", &state->wram[(data & 4) * 0x2000]);
576                  state->prg_bank[1] = state->prg_chunks + data & 0x07;
577                  memory_set_bank(space->machine, "bank2", state->prg_bank[1]);
577578               }
578579               break;
579580         }
r8226r8227
588589               if (data & 0x80)
589590               {
590591                  /* ROM */
591                  data &= ((state->prg_chunks << 1) - 1);
592                  memory_set_bankptr(space->machine, "bank3", &state->rom[data * 0x2000 + 0x10000]);
592                  LOG_MMC(("\tROM bank select (8k, $c000): %02x\n", data & 0x7f));
593                  prg8_cd(space->machine, data & 0x7f);
593594               }
594595               else
595596               {
596597                  /* RAM */
597598                  LOG_MMC(("\tRAM bank select (8k, $c000): %02x\n", data & 0x07));
598                  /* The & 4 is a hack that'll tide us over for now */
599                  memory_set_bankptr(space->machine, "bank3", &state->wram[(data & 4)* 0x2000]);
599                  state->prg_bank[2] = state->prg_chunks + data & 0x07;
600                  memory_set_bank(space->machine, "bank3", state->prg_bank[2]);
600601               }
601602               break;
602603         }
r8226r8227
607608         {
608609            case 0x00:
609610               /* 32k switch - ROM only */
611               LOG_MMC(("\tROM bank select (32k, $8000): %02x\n", (data & 0x7f) >> 2));
610612               prg32(space->machine, data >> 2);
611613               break;
612614            case 0x01:
613615               /* 16k switch - ROM only */
616               LOG_MMC(("\tROM bank select (16k, $c000): %02x\n", (data & 0x7f) >> 1));
614617               prg16_cdef(space->machine, data >> 1);
615618               break;
616619            case 0x02:
617620            case 0x03:
618621               /* 8k switch */
619               data &= ((state->prg_chunks << 1) - 1);
620               memory_set_bankptr(space->machine, "bank4", &state->rom[data * 0x2000 + 0x10000]);
622               LOG_MMC(("\tROM bank select (8k, $e000): %02x\n", data & 0x7f));
623               prg8_ef(space->machine, data & 0x7f);
621624               break;
622625         }
623626         break;

Previous 15994 Revisions Next


© 1998-2018 The MESS Team