Previous 15994 Revisions Next

r5945 Saturday 3rd October, 2009 at 00:53:11 UTC by Fabio Priuli
[NES] Fixed last regressions compared to 0.130, fixed scrolling problem with FF3, greatly simplified MMC1 code, added more mappers, various cleanups
[src/mess/machine]nes.c nes_mmc.c

src/mess/machine/nes.c
r5944r5945
155155         mmc_write_mid = mapper->mmc_write_mid;
156156         mmc_write = mapper->mmc_write;
157157         ppu_latch = mapper->ppu_latch;
158//          mmc_irq = mmc_list[i].mmc_irq;
159158      }
160159      else
161160      {
162161         logerror("Mapper %d is not yet supported, defaulting to no mapper.\n",nes.mapper);
163162         mmc_write_low = mmc_write_mid = mmc_write = NULL;
164163         mmc_read_low = NULL;
164         ppu_latch = NULL;
165165      }
166166   }
167167
r5944r5945
684684
685685            if (unif_board == NULL)
686686            {
687               logerror("Unsupported UNIF board.\n");
688//                  return INIT_FAIL;
687               fatalerror("Unsupported UNIF board.\n");
688//                  logerror("Unsupported UNIF board.\n");
689689            }
690690         }
691691         else if ((magic2[0] == 'R') && (magic2[1] == 'E') && (magic2[2] == 'A') && (magic2[3] == 'D'))
src/mess/machine/nes_mmc.c
r5944r5945
1212
1313    Known issues on specific mappers:
1414
15    * 001 AD&D Hillsfar seems to be broken.
15    * 001 AD&D Hillsfar and Bill & Ted are broken. We need to ignore the case of writes happening on 2
16          consecutive CPU cycles because these games use dirty tricks to reset counters (see note in mapper1_w)
17    * 001, 155 We don't handle (yet) WRAM enable/disable bit
1618    * 002, 003 Bus conflict?
1719    * 005 has some issues (e.g. Just Breed is not working), RAM banking needs hardware flags to determine size
1820    * 015 Shanghai Tycoon has corrupted graphics
r5944r5945
2729    * 039 Study n Game 32 in 1 misses keyboard and starts differently than in NEStopia
2830    * 040 is not dealing correctly 0x6000-0x7fff (this got broken long ago)
2931    * 042 Ai Senshi Nicol has broken graphics (our Mapper 42 implementation does not handle CHR banks)
30    * 045 is not fully working
31    * 047 selection menu is totally glitched (unique regression left from 0.130u2 changes)
3232    * 051 only half of the games work
3333    * 064 has some IRQ problems - see Skull & Crossbones. Klax has broken graphics.
3434    * 065 Spartan X 2 has various glitches
3535    * 067 display issues, but vrom fixed
3636    * 071 Fire Hawk is not properly working (it requires one hack to support both boards using this mapper)
3737    * 072, 086, 092 lack samples support (maybe others as well)
38    * 074 is only preliminar (no correct CHR swap)
3938    * 077 Requires 4-screen mirroring. Currently, it is very glitchy
4039    * 078 Cosmo Carrier is not working (it requires one hack to support both boards using this mapper).
4140          also, we lack NT mirroring
r5944r5945
131130} name_table;
132131
133132/* Global variables */
134static int prg_mask;
135
136133static chr_bank chr_map[8];  //quick banking structure, because some of this changes multiple times per scanline!
137134static name_table nt_page[4];  //quick banking structure for a maximum of 4K of RAM/ROM/ExRAM
138135
r5944r5945
149146read8_space_func mmc_read_mid;
150147write8_space_func mmc_write;
151148
152static int vrom_bank[16];
153149static int mult1, mult2;
154150
155151/* common local variables */
156static UINT8 mmc_chr_source;            // this is set at init to CHRROM or CHRRAM. a few mappers can swap between
157                        // the two (this is done in the specific handlers)
158static UINT8 mmc_cmd1, mmc_cmd2;         // these represent registers where the mapper writes important values
159static UINT8 mmc_bank_latch1, mmc_bank_latch2;   // some mappers change banks by writing subsets of these bits
152static UINT8 mmc_chr_source;      // This is set at init to CHRROM or CHRRAM. a few mappers can swap between
153                  // the two (this is done in the specific handlers).
160154
155static UINT8 mmc_cmd1, mmc_cmd2;   // These represent registers where the mapper writes important values
156static UINT8 mmc_count;         // This is used as counter in mappers like 1 and 45
157
158static int prg_bank[4];         // Many mappers writes only some bits of the selected bank (for both PRG and CHR),
159static int vrom_bank[16];      // hence these are handy to latch bank values.
160
161
161162// FIXME: mapper specific variables should be unified as much as possible to make easier future implementation of save states
162163/* Local variables (a few more are defined just before handlers that use them...) */
163static int MMC1_Size_16k;
164static int MMC1_High;
165static int MMC1_reg;
166static int MMC1_reg_count;
167static int MMC1_Switch_Low, MMC1_SizeVrom_4k;
168static int MMC1_bank1, MMC1_bank2, MMC1_bank3, MMC1_bank4;
169static int MMC1_extended_bank;
170static int MMC1_extended_base;
171static int MMC1_extended_swap;
172164
173static int MMC2_bank0, MMC2_bank0_hi, MMC2_bank0_latch, MMC2_bank1, MMC2_bank1_hi, MMC2_bank1_latch;
165static UINT8 MMC1_regs[4];
174166
167static UINT8 MMC2_regs[4];   // these replace bank0/bank0_hi/bank1/bank1_hi
168
175169static int MMC3_cmd;
176static int MMC3_prg0, MMC3_prg1;
177static int MMC3_chr[6];
178static int MMC3_prg_base, MMC3_prg_mask;
179static int MMC3_chr_base, MMC3_chr_mask;
180170UINT8* extended_ntram;
181171
172static int mmc_prg_base, mmc_prg_mask;   // MMC3 based multigame carts select a block of banks by using these (and then act like normal MMC3),
173static int mmc_chr_base, mmc_chr_mask;   // while MMC3 and clones (mapper 118 & 119) simply set them as 0 and 0xff resp.
174
182175static int MMC5_rom_bank_mode;
183176static int MMC5_vrom_bank_mode;
184177static int MMC5_vram_protect;
r5944r5945
188181UINT8 MMC5_vram[0x400];
189182int MMC5_vram_control;
190183
191static int mapper45_data[4], mapper45_cmd;
184static UINT8 mapper45_reg[4];
185static UINT8 mapper51_reg[3];
186static UINT8 mapper64_reg[11];
187static UINT8 mapper83_reg[10];
188static UINT8 mapper83_low_reg[4];
189static UINT8 mapper95_reg[4];
190static UINT8 mapper115_reg[4];
191static UINT8 txc_reg[4];    // used by mappers 132, 172 & 173
192static UINT8 subor_reg[4];   // used by mappers 166 & 167
193static UINT8 sachen_reg[8];   // used by mappers 137, 138, 139 & 141
194static UINT8 mapper12_reg;
195static UINT8 map52_reg_written;
196static UINT8 map114_reg, map114_reg_enabled;
192197
193static int mapper64_data[0x10], mapper64_cmd;
194
195static int mapper83_data[10];
196static int mapper83_low_data[4];
197
198198static int mapper_warning;
199199
200200static emu_timer   *nes_irq_timer;
r5944r5945
693693
694694*************************************************************/
695695
696static WRITE8_HANDLER( mapper1_w )
696static void MMC1_set_prg( running_machine *machine )
697697{
698   int reg;
698   UINT8 prg_mode, prg_offset;
699699
700   /* Find which register we are dealing with */
700   prg_mode = MMC1_regs[0] & 0x0c;
701   /* prg_mode&0x8 determines bank size: 32k (if 0) or 16k (if 1)? when in 16k mode,
702       prg_mode&0x4 determines which half of the PRG space we can swap: if it is 4,
703       MMC1_regs[3] sets banks at 0x8000; if it is 0, MMC1_regs[3] sets banks at 0xc000. */
704
705   prg_offset = MMC1_regs[1] & 0x10;
706   /* In principle, MMC1_regs[2]&0x10 might affect "extended" banks as well, when chr_mode=1.
707       However, quoting Disch's docs: When in 4k CHR mode, 0x10 in both $A000 and $C000 *must* be
708       set to the same value, or else pages will constantly be swapped as graphics render!
709       Hence, we use only MMC1_regs[1]&0x10 for prg_offset */
710
711   switch (prg_mode)
712   {
713   case 0x00:
714   case 0x04:
715      prg32(machine, prg_offset + MMC1_regs[3]);
716      break;
717   case 0x08:
718      prg16_89ab(machine, prg_offset + 0);
719      prg16_cdef(machine, prg_offset + MMC1_regs[3]);
720      break;
721   case 0x0c:
722      prg16_89ab(machine, prg_offset + MMC1_regs[3]);
723      prg16_cdef(machine, prg_offset + 0x0f);
724      break;
725   }
726}
727
728static void MMC1_set_chr( running_machine *machine )
729{
730   UINT8 chr_mode = MMC1_regs[0] & 0x10;
731
732   if (nes.chr_chunks)
733   {
734      if (chr_mode)
735      {
736         chr4_0(machine, MMC1_regs[1] & 0x1f, CHRROM);
737         chr4_4(machine, MMC1_regs[2] & 0x1f, CHRROM);
738      }
739      else
740         chr8(machine, (MMC1_regs[1] & 0x1f) >> 1, CHRROM);
741   }
742}
743
744static WRITE8_HANDLER( mapper1_w )
745{
701746   /* Note that there is only one latch and shift counter, shared amongst the 4 regs */
702747   /* Space Shuttle will not work if they have independent variables. */
703   reg = (offset >> 13);
748   LOG_MMC(("mapper1_w offset: %04x, data: %02x\n", offset, data));
704749
750
751   /* here we would need to add an if(cpu_cycles_passed>1) test, and
752       if requirement is not met simply return without writing anything.
753       AD&D Hillsfar and Bill & Ted rely on this behavior!! */
705754   if (data & 0x80)
706755   {
707      MMC1_reg_count = 0;
708      MMC1_reg = 0;
756      mmc_count = 0;
757      mmc_cmd1 = 0;
709758
710      /* Set these to their defaults - needed for Robocop 3, Dynowars */
711      MMC1_Size_16k = 1;
712      MMC1_Switch_Low = 1;
713      /* TODO: should we switch banks at this time also? */
759      /* Set reg at 0x8000 to size 16k and lower half swap - needed for Robocop 3, Dynowars */
760      MMC1_regs[0] |= 0x0c;
761      MMC1_set_prg(space->machine);
762
714763      LOG_MMC(("=== MMC1 regs reset to default\n"));
715764      return;
716765   }
717766
718   if (MMC1_reg_count < 5)
767   if (mmc_count < 5)
719768   {
720      if (MMC1_reg_count == 0) MMC1_reg = 0;
721      MMC1_reg >>= 1;
722      MMC1_reg |= (data & 0x01) ? 0x10 : 0x00;
723      MMC1_reg_count ++;
769      if (mmc_count == 0) mmc_cmd1 = 0;
770      mmc_cmd1 >>= 1;
771      mmc_cmd1 |= (data & 0x01) ? 0x10 : 0x00;
772      mmc_count++;
724773   }
725774
726   if (MMC1_reg_count == 5)
775   if (mmc_count == 5)
727776   {
728//      LOG_MMC(("   MMC1 reg#%02x val:%02x\n", offset, MMC1_reg));
729      switch (reg)
777      switch (offset & 0x6000)   /* Which reg shall we write to? */
730778      {
731         case 0:
732            MMC1_Switch_Low = MMC1_reg & 0x04;
733            MMC1_Size_16k =   MMC1_reg & 0x08;
779      case 0x0000:
780         MMC1_regs[0] = mmc_cmd1;
734781
735            switch (MMC1_reg & 0x03)
736            {
737               case 0: set_nt_mirroring(PPU_MIRROR_LOW); break;
738               case 1: set_nt_mirroring(PPU_MIRROR_HIGH); break;
739               case 2: set_nt_mirroring(PPU_MIRROR_VERT); break;
740               case 3: set_nt_mirroring(PPU_MIRROR_HORZ); break;
741            }
742
743            MMC1_SizeVrom_4k = (MMC1_reg & 0x10);
744            LOG_MMC(("   MMC1 reg #1 val:%02x\n", MMC1_reg));
745               LOG_MMC(("\t\tBank Size: "));
746               if (MMC1_Size_16k)
747                  LOG_MMC(("16k\n"));
748               else LOG_MMC(("32k\n"));
749
750               LOG_MMC(("\t\tBank Select: "));
751               if (MMC1_Switch_Low)
752                  LOG_MMC(("$8000\n"));
753               else LOG_MMC(("$C000\n"));
754
755               LOG_MMC(("\t\tVROM Bankswitch Size Select: "));
756               if (MMC1_SizeVrom_4k)
757                  LOG_MMC(("4k\n"));
758               else LOG_MMC(("8k\n"));
759
760               LOG_MMC(("\t\tMirroring: %d\n", MMC1_reg & 0x03));
761            break;
762
763         case 1:
764            MMC1_extended_bank = (MMC1_extended_bank & ~0x01) | ((MMC1_reg & 0x10) >> 4);
765            if (MMC1_extended == 2)
766            {
767               /* MMC1_SizeVrom_4k determines if we use the special 256k bank register */
768                if (!MMC1_SizeVrom_4k)
769                {
770                  /* Pick 1st or 4th 256k bank */
771                  MMC1_extended_base = 0xc0000 * (MMC1_extended_bank & 0x01) + 0x10000;
772                  memory_set_bankptr(space->machine, 1, &nes.rom[MMC1_extended_base + MMC1_bank1]);
773                  memory_set_bankptr(space->machine, 2, &nes.rom[MMC1_extended_base + MMC1_bank2]);
774                  memory_set_bankptr(space->machine, 3, &nes.rom[MMC1_extended_base + MMC1_bank3]);
775                  memory_set_bankptr(space->machine, 4, &nes.rom[MMC1_extended_base + MMC1_bank4]);
776                  LOG_MMC(("MMC1_extended 1024k bank (no reg) select: %02x\n", MMC1_extended_bank));
777               }
778               else
779               {
780                  /* Set 256k bank based on the 256k bank select register */
781                  if (MMC1_extended_swap)
782                  {
783                     MMC1_extended_base = 0x40000 * MMC1_extended_bank + 0x10000;
784                     memory_set_bankptr(space->machine, 1, &nes.rom[MMC1_extended_base + MMC1_bank1]);
785                     memory_set_bankptr(space->machine, 2, &nes.rom[MMC1_extended_base + MMC1_bank2]);
786                     memory_set_bankptr(space->machine, 3, &nes.rom[MMC1_extended_base + MMC1_bank3]);
787                     memory_set_bankptr(space->machine, 4, &nes.rom[MMC1_extended_base + MMC1_bank4]);
788                     LOG_MMC(("MMC1_extended 1024k bank (reg 1) select: %02x\n", MMC1_extended_bank));
789                     MMC1_extended_swap = 0;
790                  }
791                  else MMC1_extended_swap = 1;
792               }
793            }
794            else if (MMC1_extended == 1 && nes.chr_chunks == 0)
795            {
796               /* Pick 1st or 2nd 256k bank */
797               MMC1_extended_base = 0x40000 * (MMC1_extended_bank & 0x01) + 0x10000;
798               memory_set_bankptr(space->machine, 1, &nes.rom[MMC1_extended_base + MMC1_bank1]);
799               memory_set_bankptr(space->machine, 2, &nes.rom[MMC1_extended_base + MMC1_bank2]);
800               memory_set_bankptr(space->machine, 3, &nes.rom[MMC1_extended_base + MMC1_bank3]);
801               memory_set_bankptr(space->machine, 4, &nes.rom[MMC1_extended_base + MMC1_bank4]);
802               LOG_MMC(("MMC1_extended 512k bank select: %02x\n", MMC1_extended_bank & 0x01));
803            }
804            else if (nes.chr_chunks > 0)
805            {
806//                  LOG_MMC(("MMC1_SizeVrom_4k: %02x bank:%02x\n", MMC1_SizeVrom_4k, MMC1_reg));
807
808               if (!MMC1_SizeVrom_4k)
809               {
810                  /* we take care of the actual bank size when we divide bank by 2 in the chr8 call */
811                  //int bank = MMC1_reg & (nes.chr_chunks - 1);   // this breaks Pinball Quest
812                  int bank = MMC1_reg & ((nes.chr_chunks << 1) - 1);
813                  chr8(space->machine, bank >> 1, CHRROM);
814                  LOG_MMC(("MMC1 8k VROM switch: %02x\n", MMC1_reg));
815               }
816               else
817               {
818                  int bank = MMC1_reg & ((nes.chr_chunks << 1) - 1);
819                  chr4_0(space->machine, bank, CHRROM);
820                  LOG_MMC(("MMC1 4k VROM switch (low): %02x\n", MMC1_reg));
821               }
822            }
823            break;
824         case 2:
825//              LOG_MMC(("MMC1_Reg_2: %02x\n",MMC1_Reg_2));
826            MMC1_extended_bank = (MMC1_extended_bank & ~0x02) | ((MMC1_reg & 0x10) >> 3);
827            if (MMC1_extended == 2 && MMC1_SizeVrom_4k)
828            {
829               if (MMC1_extended_swap)
830               {
831                  /* Set 256k bank based on the 256k bank select register */
832                  MMC1_extended_base = 0x40000 * MMC1_extended_bank + 0x10000;
833                  memory_set_bankptr(space->machine, 1, &nes.rom[MMC1_extended_base + MMC1_bank1]);
834                  memory_set_bankptr(space->machine, 2, &nes.rom[MMC1_extended_base + MMC1_bank2]);
835                  memory_set_bankptr(space->machine, 3, &nes.rom[MMC1_extended_base + MMC1_bank3]);
836                  memory_set_bankptr(space->machine, 4, &nes.rom[MMC1_extended_base + MMC1_bank4]);
837                  LOG_MMC(("MMC1_extended 1024k bank (reg 2) select: %02x\n", MMC1_extended_bank));
838                  MMC1_extended_swap = 0;
839               }
840               else
841                  MMC1_extended_swap = 1;
842            }
843            if (MMC1_SizeVrom_4k)
844            {
845               int bank = MMC1_reg & ((nes.chr_chunks << 1) - 1);
846               chr4_4(space->machine, bank, CHRROM);
847               LOG_MMC(("MMC1 4k VROM switch (high): %02x\n", MMC1_reg));
848            }
849            break;
850         case 3:
851            /* Switching 1 32k bank of PRG ROM */
852            MMC1_reg &= 0x0f;
853            if (!MMC1_Size_16k)
854            {
855               int bank = MMC1_reg & (nes.prg_chunks - 1);
856
857               MMC1_bank1 = bank * 0x4000;
858               MMC1_bank2 = bank * 0x4000 + 0x2000;
859               memory_set_bankptr(space->machine, 1, &nes.rom[MMC1_extended_base + MMC1_bank1]);
860               memory_set_bankptr(space->machine, 2, &nes.rom[MMC1_extended_base + MMC1_bank2]);
861               if (!MMC1_extended)
862               {
863                  MMC1_bank3 = bank * 0x4000 + 0x4000;
864                  MMC1_bank4 = bank * 0x4000 + 0x6000;
865                  memory_set_bankptr(space->machine, 3, &nes.rom[MMC1_extended_base + MMC1_bank3]);
866                  memory_set_bankptr(space->machine, 4, &nes.rom[MMC1_extended_base + MMC1_bank4]);
867               }
868               LOG_MMC(("MMC1 32k bank select: %02x\n", MMC1_reg));
869            }
870            else
871            /* Switching one 16k bank */
872            {
873               if (MMC1_Switch_Low)
874               {
875                  int bank = MMC1_reg & (nes.prg_chunks - 1);
876
877                  MMC1_bank1 = bank * 0x4000;
878                  MMC1_bank2 = bank * 0x4000 + 0x2000;
879
880                  memory_set_bankptr(space->machine, 1, &nes.rom[MMC1_extended_base + MMC1_bank1]);
881                  memory_set_bankptr(space->machine, 2, &nes.rom[MMC1_extended_base + MMC1_bank2]);
882                  if (!MMC1_extended)
883                  {
884                     MMC1_bank3 = MMC1_High;
885                     MMC1_bank4 = MMC1_High + 0x2000;
886                     memory_set_bankptr(space->machine, 3, &nes.rom[MMC1_extended_base + MMC1_bank3]);
887                     memory_set_bankptr(space->machine, 4, &nes.rom[MMC1_extended_base + MMC1_bank4]);
888                  }
889                  LOG_MMC(("MMC1 16k-low bank select: %02x\n", MMC1_reg));
890               }
891               else
892               {
893                  int bank = MMC1_reg & (nes.prg_chunks - 1);
894
895                  if (!MMC1_extended)
896                  {
897
898                     MMC1_bank1 = 0;
899                     MMC1_bank2 = 0x2000;
900                     MMC1_bank3 = bank * 0x4000;
901                     MMC1_bank4 = bank * 0x4000 + 0x2000;
902
903                     memory_set_bankptr(space->machine, 1, &nes.rom[MMC1_extended_base + MMC1_bank1]);
904                     memory_set_bankptr(space->machine, 2, &nes.rom[MMC1_extended_base + MMC1_bank2]);
905                     memory_set_bankptr(space->machine, 3, &nes.rom[MMC1_extended_base + MMC1_bank3]);
906                     memory_set_bankptr(space->machine, 4, &nes.rom[MMC1_extended_base + MMC1_bank4]);
907                  }
908                  LOG_MMC(("MMC1 16k-high bank select: %02x\n", MMC1_reg));
909               }
910            }
911
912            LOG_MMC(("-- page1: %06x\n", MMC1_bank1));
913            LOG_MMC(("-- page2: %06x\n", MMC1_bank2));
914            LOG_MMC(("-- page3: %06x\n", MMC1_bank3));
915            LOG_MMC(("-- page4: %06x\n", MMC1_bank4));
916            break;
782         switch (MMC1_regs[0] & 0x03)
783         {
784            case 0: set_nt_mirroring(PPU_MIRROR_LOW); break;
785            case 1: set_nt_mirroring(PPU_MIRROR_HIGH); break;
786            case 2: set_nt_mirroring(PPU_MIRROR_VERT); break;
787            case 3: set_nt_mirroring(PPU_MIRROR_HORZ); break;
788         }
789         MMC1_set_chr(space->machine);
790         MMC1_set_prg(space->machine);
791         break;
792      case 0x2000:
793         MMC1_regs[1] = mmc_cmd1;
794         MMC1_set_chr(space->machine);
795         MMC1_set_prg(space->machine);
796         break;
797      case 0x4000:
798         MMC1_regs[2] = mmc_cmd1;
799         MMC1_set_chr(space->machine);
800         break;
801      case 0x6000:
802         MMC1_regs[3] = mmc_cmd1;
803         MMC1_set_prg(space->machine);
804         break;
917805      }
918      MMC1_reg_count = 0;
806
807      mmc_count = 0;
919808   }
920809}
921810
r5944r5945
932821
933822static WRITE8_HANDLER( mapper2_w )
934823{
824   LOG_MMC(("mapper2_w offset: %04x, data: %02x\n", offset, data));
825
935826   prg16_89ab(space->machine, data);
936827}
937828
r5944r5945
951842
952843static WRITE8_HANDLER( mapper3_w )
953844{
845   LOG_MMC(("mapper3_w offset: %04x, data: %02x\n", offset, data));
846
954847   chr8(space->machine, data, CHRROM);
955848}
956849
r5944r5945
968861
969862*************************************************************/
970863
971static void mapper4_set_prg( running_machine *machine )
864/* Many multigame carts based on MMC3 works as follows: they select a
865  block of banks by writing in the 0x6000-0x7fff range and then they
866  operate like a common MMC3 board on that specific block. To emulate this
867  we use the concept of bases and masks. Original MMC3 boards simply
868  set base = 0 and mask = 0xff at start and never change them */
869
870static void mapper4_set_prg( running_machine *machine, int prg_base, int prg_mask )
972871{
973   int prg0_bank = MMC3_prg_base | (MMC3_prg0 & MMC3_prg_mask);
974   int prg1_bank = MMC3_prg_base | (MMC3_prg1 & MMC3_prg_mask);
975   int last_bank = MMC3_prg_base | MMC3_prg_mask;
872   int prg0_bank = prg_base | (prg_bank[0] & prg_mask);
873   int prg1_bank = prg_base | (prg_bank[1] & prg_mask);
874   int last_bank = prg_base | prg_mask;
976875
977876   if (MMC3_cmd & 0x40)
978877   {
979      memory_set_bankptr(machine, 1, &nes.rom[(last_bank - 1) * 0x2000 + 0x10000]);
980      memory_set_bankptr(machine, 3, &nes.rom[0x2000 * (prg0_bank) + 0x10000]);
878      prg8_89(machine, last_bank - 1);
879      prg8_cd(machine, prg0_bank);
981880   }
982881   else
983882   {
984      memory_set_bankptr(machine, 1, &nes.rom[0x2000 * (prg0_bank) + 0x10000]);
985      memory_set_bankptr(machine, 3, &nes.rom[(last_bank - 1) * 0x2000 + 0x10000]);
883      prg8_89(machine, prg0_bank);
884      prg8_cd(machine, last_bank - 1);
986885   }
987   memory_set_bankptr(machine, 2, &nes.rom[0x2000 * (prg1_bank) + 0x10000]);
988   memory_set_bankptr(machine, 4, &nes.rom[(last_bank) * 0x2000 + 0x10000]);
886
887   prg8_ab(machine, prg1_bank);
888   prg8_ef(machine, last_bank);
989889}
990890
991static void mapper4_set_chr( running_machine *machine, UINT8 chr )
891static void mapper4_set_chr( running_machine *machine, UINT8 chr, int chr_base, int chr_mask )
992892{
993893   UINT8 chr_page = (MMC3_cmd & 0x80) >> 5;
994894
995   chr2_x(machine, chr_page ^ 0, MMC3_chr_base | ((MMC3_chr[0] >> 1) & MMC3_chr_mask), chr);
996   chr2_x(machine, chr_page ^ 2, MMC3_chr_base | ((MMC3_chr[1] >> 1) & MMC3_chr_mask), chr);
997   chr1_x(machine, chr_page ^ 4, MMC3_chr_base | (MMC3_chr[2]& MMC3_chr_mask), chr);
998   chr1_x(machine, chr_page ^ 5, MMC3_chr_base | (MMC3_chr[3]& MMC3_chr_mask), chr);
999   chr1_x(machine, chr_page ^ 6, MMC3_chr_base | (MMC3_chr[4]& MMC3_chr_mask), chr);
1000   chr1_x(machine, chr_page ^ 7, MMC3_chr_base | (MMC3_chr[5]& MMC3_chr_mask), chr);
895   chr1_x(machine, chr_page ^ 0, chr_base | ((vrom_bank[0] & ~0x01) & chr_mask), chr);
896   chr1_x(machine, chr_page ^ 1, chr_base | ((vrom_bank[0] |  0x01) & chr_mask), chr);
897   chr1_x(machine, chr_page ^ 2, chr_base | ((vrom_bank[1] & ~0x01) & chr_mask), chr);
898   chr1_x(machine, chr_page ^ 3, chr_base | ((vrom_bank[1] |  0x01) & chr_mask), chr);
899   chr1_x(machine, chr_page ^ 4, chr_base | (vrom_bank[2] & chr_mask), chr);
900   chr1_x(machine, chr_page ^ 5, chr_base | (vrom_bank[3] & chr_mask), chr);
901   chr1_x(machine, chr_page ^ 6, chr_base | (vrom_bank[4] & chr_mask), chr);
902   chr1_x(machine, chr_page ^ 7, chr_base | (vrom_bank[5] & chr_mask), chr);
1001903}
1002904
1003905static void mapper4_irq( const device_config *device, int scanline, int vblank, int blanked )
r5944r5945
1005907   if ((scanline < PPU_BOTTOM_VISIBLE_SCANLINE) /*|| (scanline == ppu_scanlines_per_frame-1)*/)
1006908   {
1007909      int priorCount = IRQ_count;
1008      if ((IRQ_count == 0) || IRQ_reload)
910      if ((IRQ_count == 0))
1009911      {
1010912         IRQ_count = IRQ_count_latch;
1011         IRQ_reload = 0;
1012913      }
1013914      else
1014         IRQ_count --;
915         IRQ_count--;
1015916
1016917      if (IRQ_enable && !blanked && (IRQ_count == 0) && priorCount)
1017918      {
1018919         LOG_MMC(("irq fired, scanline: %d (MAME %d, beam pos: %d)\n", scanline,
1019920               video_screen_get_vpos(device->machine->primary_screen), video_screen_get_hpos(device->machine->primary_screen)));
1020921         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
1021//          timer_adjust_oneshot(nes_irq_timer, cputag_clocks_to_attotime(device->machine, "maincpu", 4), 0);
1022922      }
1023923   }
1024924}
1025925
1026926static WRITE8_HANDLER( mapper4_w )
1027927{
1028   static UINT8 last_bank = 0xff;
928   UINT8 MMC3_helper, cmd;
1029929
1030//  LOG_MMC(("mapper4_w offset: %04x, data: %02x, scanline: %d\n", offset, data, current_scanline));
930   LOG_MMC(("mapper4_w offset: %04x, data: %02x\n", offset, data));
1031931
1032   //only bits 14,13, and 0 matter for offset!
1033932   switch (offset & 0x6001)
1034933   {
1035      case 0x0000: /* $8000 */
934      case 0x0000:
935         MMC3_helper = MMC3_cmd ^ data;
1036936         MMC3_cmd = data;
1037937
1038         /* Toggle between switching $8000 and $c000 */
1039         if (last_bank != (data & 0xc0))
1040         {
1041            /* Reset the banks */
1042            mapper4_set_prg(space->machine);
1043            mapper4_set_chr(space->machine, mmc_chr_source);
1044            LOG_MMC(("     MMC3 reset banks\n"));
1045         }
1046         last_bank = data & 0xc0;
938         /* Has PRG Mode changed? */
939         if (MMC3_helper & 0x40)
940            mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
941
942         /* Has CHR Mode changed? */
943         if (MMC3_helper & 0x80)
944            mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
1047945         break;
1048946
1049      case 0x0001: /* $8001 */
1050      {
1051         UINT8 cmd = MMC3_cmd & 0x07;
947      case 0x0001:
948         cmd = MMC3_cmd & 0x07;
1052949         switch (cmd)
1053950         {
1054            case 0: case 1:
1055               data &= 0xfe;
1056               MMC3_chr[cmd] = data;
1057               mapper4_set_chr(space->machine, mmc_chr_source);
1058               LOG_MMC(("     MMC3 set vram %d: %d\n", cmd, data));
1059               break;
1060
951            case 0: case 1:   // these do not need to be separated because we shift banks in set_chr!
1061952            case 2: case 3: case 4: case 5:
1062               MMC3_chr[cmd] = data;
1063               mapper4_set_chr(space->machine, mmc_chr_source);
1064               LOG_MMC(("     MMC3 set vram %d: %d\n", cmd, data));
953               vrom_bank[cmd] = data;
954               mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
1065955               break;
1066
1067956            case 6:
1068               MMC3_prg0 = data;
1069               mapper4_set_prg(space->machine);
1070               break;
1071
1072957            case 7:
1073               MMC3_prg1 = data;
1074               mapper4_set_prg(space->machine);
958               prg_bank[cmd - 6] = data;
959               mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
1075960               break;
1076961         }
1077962         break;
1078      }
1079      case 0x2000: /* $a000 */
1080         if (data & 0x40)
1081            set_nt_mirroring(PPU_MIRROR_HIGH);
1082         else
1083         {
1084            if (data & 0x01)
1085               set_nt_mirroring(PPU_MIRROR_HORZ);
1086            else
1087               set_nt_mirroring(PPU_MIRROR_VERT);
1088         }
963
964      case 0x2000:
965         set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
1089966         break;
1090967
1091      case 0x2001: /* $a001 - extra RAM enable/disable */
968      case 0x2001: /* extra RAM enable/disable */
969         mmc_cmd2 = data;    /* This actually is made of two parts: data&0x80 = WRAM enabled and data&0x40 = WRAM readonly!  */
970                  /* We save this twice because we will need mmc_cmd2 in some clone mapper */
1092971         nes.mid_ram_enable = data;
1093         LOG_MMC(("     MMC3 mid_ram enable: %02x\n", 0));
1094972         break;
1095973
1096      case 0x4000: /* $c000 - IRQ scanline counter */
974      case 0x4000: /* IRQ scanline counter */
1097975         IRQ_count_latch = data;
1098//          LOG_MMC(("     MMC3 set irq count latch: %02x (scanline %d)\n", data, ppu2c0x_get_current_scanline(0)));
1099976         break;
1100977
1101      case 0x4001: /* $c001 - IRQ scanline latch */
1102         IRQ_reload = 1;
1103//          LOG_MMC(("     MMC3 set irq reload (scanline %d)\n", ppu2c0x_get_current_scanline(0)));
978      case 0x4001: /* IRQ scanline latch */
979         IRQ_count = 0;
1104980         break;
1105981
1106      case 0x6000: /* $e000 - Disable IRQs */
982      case 0x6000: /* Disable IRQs */
1107983         IRQ_enable = 0;
1108         LOG_MMC(("     MMC3 disable irqs\n"));
1109984         break;
1110985
1111      case 0x6001: /* $e001 - Enable IRQs */
986      case 0x6001: /* Enable IRQs */
1112987         IRQ_enable = 1;
1113         LOG_MMC(("     MMC3 enable irqs\n"));
1114988         break;
1115989
1116990      default:
r5944r5945
17471621{
17481622   LOG_MMC(("mapper8_w, offset: %04x, data: %02x\n", offset, data));
17491623
1750   /* Switch 8k VROM bank */
17511624   chr8(space->machine, data & 0x07, CHRROM);
1752
1753   /* Switch 16k PRG bank */
17541625   data = (data >> 3) & (nes.prg_chunks - 1);
17551626   memory_set_bankptr(space->machine, 1, &nes.rom[data * 0x4000 + 0x10000]);
17561627   memory_set_bankptr(space->machine, 2, &nes.rom[data * 0x4000 + 0x12000]);
r5944r5945
17721643{
17731644   if ((offset & 0x3ff0) == 0x0fd0)
17741645   {
1775      LOG_MMC(("mapper9 vrom latch switch (bank 0 low): %02x\n", MMC2_bank0));
1776      MMC2_bank0_latch = 0xfd;
1777      chr4_0(device->machine, MMC2_bank0, CHRROM);
1646      LOG_MMC(("mapper9 vrom latch switch (bank 0 low): %02x\n", MMC2_regs[0]));
1647      mmc_cmd1 = 0xfd;
1648      chr4_0(device->machine, MMC2_regs[0], CHRROM);
17781649   }
17791650   else if ((offset & 0x3ff0) == 0x0fe0)
17801651   {
1781      LOG_MMC(("mapper9 vrom latch switch (bank 0 high): %02x\n", MMC2_bank0_hi));
1782      MMC2_bank0_latch = 0xfe;
1783      chr4_0(device->machine, MMC2_bank0_hi, CHRROM);
1652      LOG_MMC(("mapper9 vrom latch switch (bank 0 high): %02x\n", MMC2_regs[1]));
1653      mmc_cmd1 = 0xfe;
1654      chr4_0(device->machine, MMC2_regs[1], CHRROM);
17841655   }
17851656   else if ((offset & 0x3ff0) == 0x1fd0)
17861657   {
1787      LOG_MMC(("mapper9 vrom latch switch (bank 1 low): %02x\n", MMC2_bank1));
1788      MMC2_bank1_latch = 0xfd;
1789      chr4_4(device->machine, MMC2_bank1, CHRROM);
1658      LOG_MMC(("mapper9 vrom latch switch (bank 1 low): %02x\n", MMC2_regs[2]));
1659      mmc_cmd2 = 0xfd;
1660      chr4_4(device->machine, MMC2_regs[2], CHRROM);
17901661   }
17911662   else if ((offset & 0x3ff0) == 0x1fe0)
17921663   {
1793      LOG_MMC(("mapper9 vrom latch switch (bank 0 high): %02x\n", MMC2_bank1_hi));
1794      MMC2_bank1_latch = 0xfe;
1795      chr4_4(device->machine, MMC2_bank1_hi, CHRROM);
1664      LOG_MMC(("mapper9 vrom latch switch (bank 0 high): %02x\n", MMC2_regs[3]));
1665      mmc_cmd2 = 0xfe;
1666      chr4_4(device->machine, MMC2_regs[3], CHRROM);
17961667   }
17971668}
17981669
r5944r5945
18011672   switch (offset & 0x7000)
18021673   {
18031674      case 0x2000:
1804         /* Switch the first 8k prg bank */
18051675         prg8_89(space->machine, data);
18061676         break;
18071677      case 0x3000:
1808         MMC2_bank0 = data;
1809         if (MMC2_bank0_latch == 0xfd)
1810            chr4_0(space->machine, MMC2_bank0, CHRROM);
1811         LOG_MMC(("MMC2 VROM switch #1 (low): %02x\n", MMC2_bank0));
1678         MMC2_regs[0] = data;
1679         if (mmc_cmd1 == 0xfd)
1680            chr4_0(space->machine, MMC2_regs[0], CHRROM);
1681         LOG_MMC(("MMC2 VROM switch #1 (low): %02x\n", MMC2_regs[0]));
18121682         break;
18131683      case 0x4000:
1814         MMC2_bank0_hi = data;
1815         if (MMC2_bank0_latch == 0xfe)
1816            chr4_0(space->machine, MMC2_bank0_hi, CHRROM);
1817         LOG_MMC(("MMC2 VROM switch #1 (high): %02x\n", MMC2_bank0_hi));
1684         MMC2_regs[1] = data;
1685         if (mmc_cmd1 == 0xfe)
1686            chr4_0(space->machine, MMC2_regs[1], CHRROM);
1687         LOG_MMC(("MMC2 VROM switch #1 (high): %02x\n", MMC2_regs[1]));
18181688         break;
18191689      case 0x5000:
1820         MMC2_bank1 = data;
1821         if (MMC2_bank1_latch == 0xfd)
1822            chr4_4(space->machine, MMC2_bank1, CHRROM);
1690         MMC2_regs[2] = data;
1691         if (mmc_cmd2 == 0xfd)
1692            chr4_4(space->machine, MMC2_regs[2], CHRROM);
18231693         LOG_MMC(("MMC2 VROM switch #2 (low): %02x\n", data));
18241694         break;
18251695      case 0x6000:
1826         MMC2_bank1_hi = data;
1827         if (MMC2_bank1_latch == 0xfe)
1828            chr4_4(space->machine, MMC2_bank1_hi, CHRROM);
1696         MMC2_regs[3] = data;
1697         if (mmc_cmd2 == 0xfe)
1698            chr4_4(space->machine, MMC2_regs[3], CHRROM);
18291699         LOG_MMC(("MMC2 VROM switch #2 (high): %02x\n", data));
18301700         break;
18311701      case 0x7000:
r5944r5945
18551725   switch (offset & 0x7000)
18561726   {
18571727      case 0x2000:
1858         /* Switch the first 16k prg bank */
18591728         prg16_89ab(space->machine, data);
18601729         break;
18611730      default:
r5944r5945
18791748{
18801749   LOG_MMC(("mapper11_w, offset: %04x, data: %02x\n", offset, data));
18811750
1882   /* Switch 8k VROM bank */
18831751   chr8(space->machine, data >> 4, CHRROM);
1884
1885   /* Switch 32k prg bank */
18861752   prg32(space->machine, data & 0x0f);
18871753}
18881754
r5944r5945
18951761
18961762    MMC3 clone
18971763
1898    In MESS: Unsupported
1764    In MESS: Partially Supported
18991765
19001766*************************************************************/
19011767
1768static WRITE8_HANDLER( mapper12_l_w )
1769{
1770   LOG_MMC(("mapper12_l_w, offset: %04x, data: %02x\n", offset, data));
1771
1772   mapper12_reg = data;
1773}
1774
1775/* we would need to use this read handler in 0x6000-0x7fff as well */
1776static READ8_HANDLER( mapper12_l_r )
1777{
1778   LOG_MMC(("mapper12_l_r, offset: %04x\n", offset));
1779   return 0x01;
1780}
1781
1782static void mapper12_set_chr( running_machine *machine )
1783{
1784   UINT8 chr_page = (MMC3_cmd & 0x80) >> 5;
1785
1786   chr1_x(machine, chr_page ^ 0, ((mapper12_reg & 0x01) << 8) | (vrom_bank[0] & ~0x01), CHRROM);
1787   chr1_x(machine, chr_page ^ 1, ((mapper12_reg & 0x01) << 8) | (vrom_bank[0] |  0x01), CHRROM);
1788   chr1_x(machine, chr_page ^ 2, ((mapper12_reg & 0x01) << 8) | (vrom_bank[1] & ~0x01), CHRROM);
1789   chr1_x(machine, chr_page ^ 3, ((mapper12_reg & 0x01) << 8) | (vrom_bank[1] |  0x01), CHRROM);
1790   chr1_x(machine, chr_page ^ 4, ((mapper12_reg & 0x10) << 4) | vrom_bank[2], CHRROM);
1791   chr1_x(machine, chr_page ^ 5, ((mapper12_reg & 0x10) << 4) | vrom_bank[3], CHRROM);
1792   chr1_x(machine, chr_page ^ 6, ((mapper12_reg & 0x10) << 4) | vrom_bank[4], CHRROM);
1793   chr1_x(machine, chr_page ^ 7, ((mapper12_reg & 0x10) << 4) | vrom_bank[5], CHRROM);
1794}
1795
1796static WRITE8_HANDLER( mapper12_w )
1797{
1798   UINT8 MMC3_helper, cmd;
1799   LOG_MMC(("mapper12_w, offset: %04x, data: %02x\n", offset, data));
1800
1801   switch (offset & 0x6001)
1802   {
1803   case 0x0000:
1804      MMC3_helper = MMC3_cmd ^ data;
1805      MMC3_cmd = data;
1806
1807      /* Has PRG Mode changed? */
1808      if (MMC3_helper & 0x40)
1809         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
1810
1811      /* Has CHR Mode changed? */
1812      if (MMC3_helper & 0x80)
1813         mapper12_set_chr(space->machine);
1814      break;
1815
1816   case 0x0001:
1817      cmd = MMC3_cmd & 0x07;
1818      switch (cmd)
1819      {
1820      case 0: case 1:   // these do not need to be separated because we shift banks in set_chr!
1821      case 2: case 3: case 4: case 5:
1822         vrom_bank[cmd] = data;
1823         mapper12_set_chr(space->machine);
1824         break;
1825      case 6:
1826      case 7:
1827         prg_bank[cmd - 6] = data;
1828         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
1829         break;
1830      }
1831      break;
1832
1833   default:
1834      mapper4_w(space, offset, data);
1835      break;
1836   }
1837}
1838
19021839/*************************************************************
19031840
19041841    Mapper 13
r5944r5945
20151952
20161953   switch (offset & 0x000f)
20171954   {
2018      case 0:
2019      case 1:
2020      case 2:
2021      case 3:
2022      case 4:
2023      case 5:
2024      case 6:
2025      case 7:
1955      case 0: case 1:
1956      case 2: case 3:
1957      case 4: case 5:
1958      case 6: case 7:
20261959         chr1_x(space->machine, offset & 0x07, data, CHRROM);
20271960         break;
20281961      case 8:
2029         /* Switch 16k bank at $8000 */
20301962         prg16_89ab(space->machine, data);
20311963         break;
20321964      case 9:
20331965         switch (data & 0x03)
20341966         {
2035            case 0:
2036               set_nt_mirroring(PPU_MIRROR_HORZ);
2037               break;
2038            case 1:
2039               set_nt_mirroring(PPU_MIRROR_VERT);
2040               break;
2041            case 2:
2042               set_nt_mirroring(PPU_MIRROR_LOW);
2043               break;
2044            case 3:
2045               set_nt_mirroring(PPU_MIRROR_HIGH);
2046               break;
1967            case 0: set_nt_mirroring(PPU_MIRROR_HORZ); break;
1968            case 1: set_nt_mirroring(PPU_MIRROR_VERT); break;
1969            case 2: set_nt_mirroring(PPU_MIRROR_LOW); break;
1970            case 3: set_nt_mirroring(PPU_MIRROR_HIGH); break;
20471971         }
20481972         break;
20491973      case 0x0a:
r5944r5945
21892113
21902114static WRITE8_HANDLER( mapper18_w )
21912115{
2192//  static int irq;
2193   static int bank_8000 = 0;
2194   static int bank_a000 = 0;
2195   static int bank_c000 = 0;
2196
2116   UINT8 bank;
21972117   LOG_MMC(("mapper18_w, offset: %04x, data: %02x\n", offset, data));
21982118
21992119   switch (offset & 0x7003)
22002120   {
22012121      case 0x0000:
22022122         /* Switch 8k bank at $8000 - low 4 bits */
2203         bank_8000 = (bank_8000 & 0xf0) | (data & 0x0f);
2204         bank_8000 &= prg_mask;
2205         memory_set_bankptr(space->machine, 1, &nes.rom[0x2000 * (bank_8000) + 0x10000]);
2123         prg_bank[0] = (prg_bank[0] & 0xf0) | (data & 0x0f);
2124         prg8_89(space->machine, prg_bank[0]);
22062125         break;
22072126      case 0x0001:
22082127         /* Switch 8k bank at $8000 - high 4 bits */
2209         bank_8000 = (bank_8000 & 0x0f) | (data << 4);
2210         bank_8000 &= prg_mask;
2211         memory_set_bankptr(space->machine, 1, &nes.rom[0x2000 * (bank_8000) + 0x10000]);
2128         prg_bank[0] = (prg_bank[0] & 0x0f) | (data << 4);
2129         prg8_89(space->machine, prg_bank[0]);
22122130         break;
22132131      case 0x0002:
22142132         /* Switch 8k bank at $a000 - low 4 bits */
2215         bank_a000 = (bank_a000 & 0xf0) | (data & 0x0f);
2216         bank_a000 &= prg_mask;
2217         memory_set_bankptr(space->machine, 2, &nes.rom[0x2000 * (bank_a000) + 0x10000]);
2133         prg_bank[1] = (prg_bank[1] & 0xf0) | (data & 0x0f);
2134         prg8_ab(space->machine, prg_bank[1]);
22182135         break;
22192136      case 0x0003:
22202137         /* Switch 8k bank at $a000 - high 4 bits */
2221         bank_a000 = (bank_a000 & 0x0f) | (data << 4);
2222         bank_a000 &= prg_mask;
2223         memory_set_bankptr(space->machine, 2, &nes.rom[0x2000 * (bank_a000) + 0x10000]);
2138         prg_bank[1] = (prg_bank[1] & 0x0f) | (data << 4);
2139         prg8_ab(space->machine, prg_bank[1]);
22242140         break;
22252141      case 0x1000:
22262142         /* Switch 8k bank at $c000 - low 4 bits */
2227         bank_c000 = (bank_c000 & 0xf0) | (data & 0x0f);
2228         bank_c000 &= prg_mask;
2229         memory_set_bankptr(space->machine, 3, &nes.rom[0x2000 * (bank_c000) + 0x10000]);
2143         prg_bank[2] = (prg_bank[2] & 0xf0) | (data & 0x0f);
2144         prg8_cd(space->machine, prg_bank[2]);
22302145         break;
22312146      case 0x1001:
22322147         /* Switch 8k bank at $c000 - high 4 bits */
2233         bank_c000 = (bank_c000 & 0x0f) | (data << 4);
2234         bank_c000 &= prg_mask;
2235         memory_set_bankptr(space->machine, 3, &nes.rom[0x2000 * (bank_c000) + 0x10000]);
2148         prg_bank[2] = (prg_bank[2] & 0x0f) | (data << 4);
2149         prg8_cd(space->machine, prg_bank[2]);
22362150         break;
22372151
22382152      /* $9002, 3 (1002, 3) uncaught = Jaleco Baseball writes 0 */
22392153      /* believe it's related to battery-backed ram enable/disable */
22402154
22412155      case 0x2000:
2242         /* Switch 1k vrom at $0000 - low 4 bits */
2243         vrom_bank[0] = (vrom_bank[0] & 0xf0) | (data & 0x0f);
2244         vrom_bank[0] &= ((nes.chr_chunks << 3) - 1);
2245         chr1_0(space->machine, vrom_bank[0], CHRROM);
2246         break;
22472156      case 0x2001:
2248         /* Switch 1k vrom at $0000 - high 4 bits */
2249         vrom_bank[0] = (vrom_bank[0] & 0x0f) | (data << 4);
2250         vrom_bank[0] &= ((nes.chr_chunks << 3) - 1);
2251         chr1_0(space->machine, vrom_bank[0], CHRROM);
2252         break;
22532157      case 0x2002:
2254         /* Switch 1k vrom at $0400 - low 4 bits */
2255         vrom_bank[1] = (vrom_bank[1] & 0xf0) | (data & 0x0f);
2256         vrom_bank[1] &= ((nes.chr_chunks << 3) - 1);
2257         chr1_1(space->machine, vrom_bank[1], CHRROM);
2258         break;
22592158      case 0x2003:
2260         /* Switch 1k vrom at $0400 - high 4 bits */
2261         vrom_bank[1] = (vrom_bank[1] & 0x0f) | (data << 4);
2262         vrom_bank[1] &= ((nes.chr_chunks << 3) - 1);
2263         chr1_1(space->machine, vrom_bank[1], CHRROM);
2264         break;
22652159      case 0x3000:
2266         /* Switch 1k vrom at $0800 - low 4 bits */
2267         vrom_bank[2] = (vrom_bank[2] & 0xf0) | (data & 0x0f);
2268         vrom_bank[2] &= ((nes.chr_chunks << 3) - 1);
2269         chr1_2(space->machine, vrom_bank[2], CHRROM);
2270         break;
22712160      case 0x3001:
2272         /* Switch 1k vrom at $0800 - high 4 bits */
2273         vrom_bank[2] = (vrom_bank[2] & 0x0f) | (data << 4);
2274         vrom_bank[2] &= ((nes.chr_chunks << 3) - 1);
2275         chr1_2(space->machine, vrom_bank[2], CHRROM);
2276         break;
22772161      case 0x3002:
2278         /* Switch 1k vrom at $0c00 - low 4 bits */
2279         vrom_bank[3] = (vrom_bank[3] & 0xf0) | (data & 0x0f);
2280         vrom_bank[3] &= ((nes.chr_chunks << 3) - 1);
2281         chr1_3(space->machine, vrom_bank[3], CHRROM);
2282         break;
22832162      case 0x3003:
2284         /* Switch 1k vrom at $0c00 - high 4 bits */
2285         vrom_bank[3] = (vrom_bank[3] & 0x0f) | (data << 4);
2286         vrom_bank[3] &= ((nes.chr_chunks << 3) - 1);
2287         chr1_3(space->machine, vrom_bank[3], CHRROM);
2288         break;
22892163      case 0x4000:
2290         /* Switch 1k vrom at $1000 - low 4 bits */
2291         vrom_bank[4] = (vrom_bank[4] & 0xf0) | (data & 0x0f);
2292         vrom_bank[4] &= ((nes.chr_chunks << 3) - 1);
2293         chr1_4(space->machine, vrom_bank[4], CHRROM);
2294         break;
22952164      case 0x4001:
2296         /* Switch 1k vrom at $1000 - high 4 bits */
2297         vrom_bank[4] = (vrom_bank[4] & 0x0f) | (data << 4);
2298         vrom_bank[4] &= ((nes.chr_chunks << 3) - 1);
2299         chr1_4(space->machine, vrom_bank[4], CHRROM);
2300         break;
23012165      case 0x4002:
2302         /* Switch 1k vrom at $1400 - low 4 bits */
2303         vrom_bank[5] = (vrom_bank[5] & 0xf0) | (data & 0x0f);
2304         vrom_bank[5] &= ((nes.chr_chunks << 3) - 1);
2305         chr1_5(space->machine, vrom_bank[5], CHRROM);
2306         break;
23072166      case 0x4003:
2308         /* Switch 1k vrom at $1400 - high 4 bits */
2309         vrom_bank[5] = (vrom_bank[5] & 0x0f) | (data << 4);
2310         vrom_bank[5] &= ((nes.chr_chunks << 3) - 1);
2311         chr1_5(space->machine, vrom_bank[5], CHRROM);
2312         break;
23132167      case 0x5000:
2314         /* Switch 1k vrom at $1800 - low 4 bits */
2315         vrom_bank[6] = (vrom_bank[6] & 0xf0) | (data & 0x0f);
2316         vrom_bank[6] &= ((nes.chr_chunks << 3) - 1);
2317         chr1_6(space->machine, vrom_bank[6], CHRROM);
2318         break;
23192168      case 0x5001:
2320         /* Switch 1k vrom at $1800 - high 4 bits */
2321         vrom_bank[6] = (vrom_bank[6] & 0x0f) | (data << 4);
2322         vrom_bank[6] &= ((nes.chr_chunks << 3) - 1);
2323         chr1_6(space->machine, vrom_bank[6], CHRROM);
2324         break;
23252169      case 0x5002:
2326         /* Switch 1k vrom at $1c00 - low 4 bits */
2327         vrom_bank[7] = (vrom_bank[7] & 0xf0) | (data & 0x0f);
2328         vrom_bank[7] &= ((nes.chr_chunks << 3) - 1);
2329         chr1_7(space->machine, vrom_bank[7], CHRROM);
2330         break;
23312170      case 0x5003:
2332         /* Switch 1k vrom at $1c00 - high 4 bits */
2333         vrom_bank[7] = (vrom_bank[7] & 0x0f) | (data << 4);
2334         vrom_bank[7] &= ((nes.chr_chunks << 3) - 1);
2335         chr1_7(space->machine, vrom_bank[7], CHRROM);
2171         bank = ((offset & 0x7000) - 0x2000) / 0x0400 + ((offset & 0x0002) >> 1);
2172         if (offset & 0x0001)
2173            vrom_bank[bank] = (vrom_bank[bank] & 0x0f) | (data << 4);
2174         else
2175            vrom_bank[bank] = (vrom_bank[bank] & 0xf0) | (data & 0x0f);
2176
2177         chr1_x(space->machine, bank, vrom_bank[bank], CHRROM);
23362178         break;
23372179
23382180/* LBO - these are unverified */
r5944r5945
24052247
24062248static void namcot_irq( const device_config *device, int scanline, int vblank, int blanked )
24072249{
2408   IRQ_count ++;
2409   /* Increment & check the IRQ scanline counter */
2410   if (IRQ_enable && (IRQ_count == 0x7fff))
2250   if (IRQ_enable)
24112251   {
2412      cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
2252      if (IRQ_count == 0x7fff)
2253         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
2254      else
2255         IRQ_count++;
24132256   }
24142257}
24152258
r5944r5945
24192262
24202263   switch (offset & 0x1800)
24212264   {
2422      case 0x1000:
2423         /* low byte of IRQ */
2265      case 0x0800:
2266         LOG_MMC(("Mapper 19 sound port write, data: %02x\n", data));
2267         break;
2268      case 0x1000: /* low byte of IRQ */
24242269         IRQ_count = (IRQ_count & 0x7f00) | data;
24252270         break;
2426      case 0x1800:
2427         /* high byte of IRQ, IRQ enable in high bit */
2271      case 0x1800: /* high byte of IRQ, IRQ enable in high bit */
24282272         IRQ_count = (IRQ_count & 0xff) | ((data & 0x7f) << 8);
24292273         IRQ_enable = data & 0x80;
24302274         break;
24312275   }
24322276}
24332277
2278static READ8_HANDLER( mapper19_l_r )
2279{
2280   LOG_MMC(("mapper19_l_r, offset: %04x\n", offset));
2281
2282   switch (offset & 0x1800)
2283   {
2284      case 0x1000:
2285         return IRQ_count & 0xff;
2286      case 0x1800:
2287         return (IRQ_count >> 8) & 0xff;
2288      default:
2289         return 0x00;
2290   }
2291}
2292
24342293static WRITE8_HANDLER( mapper19_w )
24352294{
24362295   LOG_MMC(("mapper19_w, offset: %04x, data: %02x\n", offset, data));
24372296   switch (offset & 0x7800)
24382297   {
2439      case 0x0000:
2440      case 0x0800:
2441      case 0x1000:
2442      case 0x1800:
2443      case 0x2000:
2444      case 0x2800:
2445      case 0x3000:
2446      case 0x3800:
2298      case 0x0000: case 0x0800:
2299      case 0x1000: case 0x1800:
2300      case 0x2000: case 0x2800:
2301      case 0x3000: case 0x3800:
24472302         chr1_x(space->machine, offset / 0x800, data, CHRROM);
24482303         break;
24492304      case 0x4000:
r5944r5945
26292484   switch (offset & 0x7007)
26302485   {
26312486      case 0x0000:
2632         /* Switch 8k bank at $8000 */
26332487         prg8_89(space->machine, data);
26342488         break;
26352489      case 0x1000:
r5944r5945
26452499      /* $1001 is uncaught */
26462500
26472501      case 0x2000:
2648         /* Switch 8k bank at $a000 */
26492502         prg8_ab(space->machine, data);
26502503         break;
26512504      case 0x3000:
r5944r5945
27522605      case 0x7004:
27532606      case 0x7001:
27542607      case 0x7080:
2755         IRQ_count = IRQ_count_latch;
27562608         IRQ_enable = data & 0x02;
27572609         IRQ_enable_latch = data & 0x01;
2610         if (data & 0x02)
2611            IRQ_count = IRQ_count_latch;
27582612//          LOG_MMC(("konami_vrc4 irq_count set: %02x\n", IRQ_count));
27592613//          LOG_MMC(("konami_vrc4 enable: %02x\n", IRQ_enable));
27602614//          LOG_MMC(("konami_vrc4 enable latch: %02x\n", IRQ_enable_latch));
r5944r5945
28492703      switch (offset & 0x3000)
28502704      {
28512705         case 0:
2852            /* Switch 8k bank at $8000 */
28532706            prg8_89(space->machine, data);
28542707            break;
28552708         case 0x1000:
r5944r5945
28612714               case 0x03: set_nt_mirroring(PPU_MIRROR_HIGH); break;
28622715            }
28632716            break;
2864
28652717         case 0x2000:
2866            /* Switch 8k bank at $a000 */
28672718            prg8_ab(space->machine, data);
28682719            break;
28692720         default:
r5944r5945
28942745   case 0x6001:
28952746   case 0x6002:
28962747   case 0x6003:
2897      /* switch 1k vrom at $0000-$1c00 */
28982748      bank = ((select & 0x7000) - 0x3000) / 0x0800 + ((select & 0x0002) >> 1);
28992749      if (select & 0x0001)
29002750         vrom_bank[bank] = (vrom_bank[bank] & 0x0f) | (data << 4);
r5944r5945
29142764      IRQ_count_latch |= (data << 4) & 0xf0;
29152765      break;
29162766   case 0x7002:
2917      IRQ_count = IRQ_count_latch;
29182767      IRQ_enable = data & 0x02;
29192768      IRQ_enable_latch = data & 0x01;
2769      if (data & 0x02)
2770         IRQ_count = IRQ_count_latch;
29202771      break;
29212772
29222773   default:
r5944r5945
29472798      case 0x0001:
29482799      case 0x0002:
29492800      case 0x0003:
2950         /* Switch 16k bank at $8000 */
29512801         prg16_89ab(space->machine, data);
29522802         break;
29532803
r5944r5945
29682818      case 0x4001:
29692819      case 0x4002:
29702820      case 0x4003:
2971         /* Switch 8k bank at $c000 */
29722821         prg8_cd(space->machine, data);
29732822         break;
29742823      case 0x5000:
r5944r5945
29792828      case 0x6001:
29802829      case 0x6002:
29812830      case 0x6003:
2982         /* switch 1k vrom at $0000-$1c00 */
29832831         bank = ((offset & 0x7000) - 0x5000) / 0x0400 + (offset & 0x0003);
29842832         chr1_x(space->machine, bank, data, CHRROM);
29852833         break;
r5944r5945
29882836         IRQ_count_latch = data;
29892837         break;
29902838      case 0x7001:
2991         IRQ_count = IRQ_count_latch;
29922839         IRQ_enable = data & 0x02;
29932840         IRQ_enable_latch = data & 0x01;
2841         if (data & 0x02)
2842            IRQ_count = IRQ_count_latch;
29942843         break;
29952844      case 0x7002:
29962845         IRQ_enable = IRQ_enable_latch;
r5944r5945
30222871   switch (offset & 0x7003)
30232872   {
30242873      case 0: case 1: case 2: case 3:
3025         /* Switch 16k bank at $8000 */
30262874         prg16_89ab(space->machine, data);
30272875         break;
30282876
r5944r5945
30402888         }
30412889         break;
30422890      case 0x4000: case 0x4001: case 0x4002: case 0x4003:
3043         /* Switch 8k bank at $c000 */
30442891         prg8_cd(space->machine, data);
30452892         break;
30462893      case 0x5000:
r5944r5945
30512898      case 0x6001:
30522899      case 0x6002:
30532900      case 0x6003:
3054         /* switch 1k vrom at $0000-$1c00 */
30552901         bank = ((offset & 0x7000) - 0x5000) / 0x0400 + ((offset & 0x0001) << 1) + ((offset & 0x0002) >> 1);
30562902         chr1_x(space->machine, bank, data, CHRROM);
30572903         break;
r5944r5945
30622908         IRQ_enable = IRQ_enable_latch;
30632909         break;
30642910      case 0x7002:
3065         IRQ_count = IRQ_count_latch;
30662911         IRQ_enable = data & 0x02;
30672912         IRQ_enable_latch = data & 0x01;
2913         if (data & 0x02)
2914            IRQ_count = IRQ_count_latch;
30682915         break;
30692916
30702917      default:
r5944r5945
31543001         set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
31553002         break;
31563003      case 0x2000:
3157         /* Switch 8k bank at $A000 */
31583004         prg8_ab(space->machine, data);
31593005         break;
31603006      case 0x3000:
3161         /* Switch 1k VROM at $1000 */
31623007         chr1_x(space->machine, offset & 0x07, data, CHRROM);
31633008         break;
31643009      default:
r5944r5945
32333078   switch (offset)
32343079   {
32353080      case 0x1ffd:
3236         /* Switch 32k prg banks */
32373081         prg32(space->machine, data);
32383082         break;
32393083      case 0x1ffe:
3240         /* Switch 4k VNES_ROM at 0x0000 */
32413084         chr4_0(space->machine, data, CHRROM);
32423085         break;
32433086      case 0x1fff:
3244         /* Switch 4k VNES_ROM at 0x1000 */
32453087         chr4_4(space->machine, data, CHRROM);
32463088         break;
32473089   }
r5944r5945
32983140
32993141    MMC3 clone
33003142
3301    In MESS: Unsupported.
3143    In MESS: Supported.
33023144
33033145*************************************************************/
33043146
3147static WRITE8_HANDLER( mapper37_m_w )
3148{
3149   UINT8 map37_helper;
3150   LOG_MMC(("mapper37_m_w, offset: %04x, data: %02x\n", offset, data));
3151
3152   map37_helper = (data & 0x06) >> 1;
3153
3154   mmc_prg_base = map37_helper << 3;
3155   mmc_prg_mask = (map37_helper == 2) ? 0x0f : 0x07;
3156   mmc_chr_base = map37_helper << 6;
3157   mmc_chr_mask = 0x7f;
3158   mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
3159   mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
3160}
3161
33053162/*************************************************************
33063163
33073164    Mapper 38
r5944r5945
35303387
35313388static WRITE8_HANDLER( mapper44_w )
35323389{
3533//  LOG_MMC(("mapper44_w offset: %04x, data: %02x, scanline: %d\n", offset, data, current_scanline));
3390   UINT8 page;
3391   LOG_MMC(("mapper44_w offset: %04x, data: %02x\n", offset, data));
35343392
3535   //only bits 14,13, and 0 matter for offset!
35363393   switch (offset & 0x6001)
35373394   {
35383395   case 0x2001: /* $a001 - Select 128K ROM/VROM base (0..5) or last 256K ROM/VRAM base (6) */
3539      {
3540         UINT8 page = (data & 0x07);
3541         if (page > 6)
3542            page = 6;
3543         MMC3_prg_base = page * 16;
3544         MMC3_prg_mask = (page > 5) ? 0x1f : 0x0f;
3545         MMC3_chr_base = page * 128;
3546         MMC3_chr_mask = (page > 5) ? 0xff : 0x7f;
3547      }
3548      mapper4_set_prg(space->machine);
3549      mapper4_set_chr(space->machine, mmc_chr_source);
3396      page = (data & 0x07);
3397      if (page > 6)
3398         page = 6;
3399
3400      mmc_prg_base = page << 4;
3401      mmc_prg_mask = (page > 5) ? 0x1f : 0x0f;
3402      mmc_chr_base = page << 7;
3403      mmc_chr_mask = (page > 5) ? 0xff : 0x7f;
3404      mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
3405      mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
35503406      break;
35513407
35523408   default:
r5944r5945
35703426{
35713427   LOG_MMC(("mapper45_m_w, offset: %04x, data: %02x\n", offset, data));
35723428
3573   if (offset == 0)
3429   /* This bit is the "register lock". Once register are locked, writes go to WRAM
3430        and there is no way to unlock them (except by resetting the machine) */
3431   if (mapper45_reg[3] & 0x40)
3432      nes.wram[offset] = data;
3433   else
35743434   {
3575      mapper45_data[mapper45_cmd] = data;
3576      mapper45_cmd = (mapper45_cmd + 1) & 0x03;
3435      mapper45_reg[mmc_count] = data;
3436      mmc_count = (mmc_count + 1) & 0x03;
35773437
3578      if (!mapper45_cmd)
3438      if (!mmc_count)
35793439      {
3580         LOG_MMC(("mapper45_m_w, command completed %02x %02x %02x %02x\n", mapper45_data[3],
3581            mapper45_data[2], mapper45_data[1], mapper45_data[0]));
3440         LOG_MMC(("mapper45_m_w, command completed %02x %02x %02x %02x\n", mapper45_reg[3],
3441            mapper45_reg[2], mapper45_reg[1], mapper45_reg[0]));
35823442
3583         MMC3_prg_base = mapper45_data[1];
3584         MMC3_prg_mask = 0x3f ^ (mapper45_data[3] & 0x3f);
3585         MMC3_chr_base = ((mapper45_data[2] & 0xf0) << 4) + mapper45_data[0];
3586
3587         if (mapper45_data[2] & 0x08)
3588            MMC3_chr_mask = (1 << ((mapper45_data[2] & 0x07) + 1)) - 1;
3589         else
3590            MMC3_chr_mask = 0;
3591
3592         mapper4_set_prg(space->machine);
3593         mapper4_set_chr(space->machine, mmc_chr_source);
3443         mmc_prg_base = mapper45_reg[1];
3444         mmc_prg_mask = 0x3f ^ (mapper45_reg[3] & 0x3f);
3445         mmc_chr_base = ((mapper45_reg[2] & 0xf0) << 4) + mapper45_reg[0];
3446         mmc_chr_mask = 0xff >> (~mapper45_reg[2] & 0x0f);
3447         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
3448         mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
35943449      }
35953450   }
3596   if (mapper45_data[3] & 0x40)
3597      nes.wram[offset] = data;
35983451}
35993452
36003453/*************************************************************
r5944r5945
36123465{
36133466   LOG_MMC(("mapper46_m_w, offset: %04x, data: %02x\n", offset, data));
36143467
3615   mmc_bank_latch1 = (mmc_bank_latch1 & 0x01) | ((data & 0x0f) << 1);
3616   mmc_bank_latch2 = (mmc_bank_latch2 & 0x07) | ((data & 0xf0) >> 1);
3617   prg32(space->machine, mmc_bank_latch1);
3618   chr8(space->machine, mmc_bank_latch2, CHRROM);
3468   prg_bank[0] = (prg_bank[0] & 0x01) | ((data & 0x0f) << 1);
3469   vrom_bank[0] = (vrom_bank[0] & 0x07) | ((data & 0xf0) >> 1);
3470   prg32(space->machine, prg_bank[0]);
3471   chr8(space->machine, vrom_bank[0], CHRROM);
36193472}
36203473
36213474static WRITE8_HANDLER( mapper46_w )
36223475{
36233476   LOG_MMC(("mapper46_w, offset: %04x, data: %02x\n", offset, data));
36243477
3625   mmc_bank_latch1 = (mmc_bank_latch1 & ~0x01) | (data & 0x01);
3626   mmc_bank_latch2 = (mmc_bank_latch2 & ~0x07) | ((data & 0x70) >> 4);
3627   prg32(space->machine, mmc_bank_latch1);
3628   chr8(space->machine, mmc_bank_latch2, CHRROM);
3478   prg_bank[0] = (prg_bank[0] & ~0x01) | (data & 0x01);
3479   vrom_bank[0] = (vrom_bank[0] & ~0x07) | ((data & 0x70) >> 4);
3480   prg32(space->machine, prg_bank[0]);
3481   chr8(space->machine, vrom_bank[0], CHRROM);
36293482}
36303483
36313484/*************************************************************
r5944r5945
36433496{
36443497   LOG_MMC(("mapper47_m_w, offset: %04x, data: %02x\n", offset, data));
36453498
3646   if (offset == 0)
3647   {
3648      MMC3_prg_base = (data & 0x01) << 4;
3649      MMC3_prg_mask = 0x0f;
3650      MMC3_chr_base = (data & 0x01) << 7;
3651      MMC3_chr_mask = 0x7f;
3652      mapper4_set_prg(space->machine);
3653      mapper4_set_chr(space->machine, mmc_chr_source);
3654   }
3499   mmc_prg_base = (data & 0x01) << 4;
3500   mmc_prg_mask = 0x0f;
3501   mmc_chr_base = (data & 0x01) << 7;
3502   mmc_chr_mask = 0x7f;
3503   mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
3504   mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
36553505}
36563506
36573507/*************************************************************
r5944r5945
36813531{
36823532   LOG_MMC(("mapper49_m_w, offset: %04x, data: %02x\n", offset, data));
36833533
3684   if ((offset & 0x1800) == 0x0800 && (offset & 0xff) == data)
3534   /* mid writes only work when WRAM is enabled. not sure if I should
3535       change the condition to mmc_cmd2==0x80 (i.e. what is the effect of
3536       the read-only bit?) */
3537   if (mmc_cmd2 & 0x80)
36853538   {
3686      MMC3_prg_base = (data & 0xc0) >> 2;
3687      MMC3_prg_mask = 0x0f;
3688      MMC3_chr_base = (data & 0xc0) << 1;
3689      MMC3_chr_mask = 0x7f;
3690      mapper4_set_prg(space->machine);
3691      mapper4_set_chr(space->machine, mmc_chr_source);
3539      if (data & 0x01)   /* if this is 0, then we have 32k PRG blocks */
3540      {
3541         mmc_prg_base = (data & 0xc0) >> 2;
3542         mmc_prg_mask = 0x0f;
3543         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
3544      }
3545      else
3546         prg32(space->machine, (data & 0x30) >> 4);
3547
3548      mmc_chr_base = (data & 0xc0) << 1;
3549      mmc_chr_mask = 0x7f;
3550      mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
36923551   }
36933552}
36943553
r5944r5945
37163575
37173576static void mapper51_set_banks( running_machine *machine )
37183577{
3719   set_nt_mirroring((MMC1_bank1 == 3) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
3578   set_nt_mirroring((mapper51_reg[0] == 3) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
37203579
3721   if (MMC1_bank1 & 0x01)
3580   if (mapper51_reg[0] & 0x01)
37223581   {
3723      prg32(machine, MMC1_bank2);
3582      prg32(machine, mapper51_reg[1]);
37243583   }
37253584   else
37263585   {
3727      prg16_cdef(machine, (MMC1_bank2 * 2) + 1);
3728      prg16_89ab(machine, MMC1_bank3 * 2);
3586      prg16_cdef(machine, (mapper51_reg[1] * 2) + 1);
3587      prg16_89ab(machine, mapper51_reg[2] * 2);
37293588   }
37303589}
37313590
r5944r5945
37333592{
37343593   LOG_MMC(("mapper51_m_w, offset: %04x, data: %02x\n", offset, data));
37353594
3736   MMC1_bank1 = ((data >> 1) & 0x01) | ((data >> 3) & 0x02);
3595   mapper51_reg[0] = ((data >> 1) & 0x01) | ((data >> 3) & 0x02);
37373596   mapper51_set_banks(space->machine);
37383597}
37393598
r5944r5945
37423601   LOG_MMC(("mapper51_w, offset: %04x, data: %02x\n", offset, data));
37433602
37443603   if (offset & 0x4000)
3745   {
3746      MMC1_bank3 = data;
3747   }
3604      mapper51_reg[2] = data;
37483605   else
3749   {
3750      MMC1_bank2 = data;
3751   }
3606      mapper51_reg[1] = data;
3607
37523608   mapper51_set_banks(space->machine);
37533609}
37543610
r5944r5945
37613617
37623618    MMC3 clone
37633619
3764    In MESS: Unsupported.
3620    In MESS: Supported.
37653621
37663622*************************************************************/
37673623
3624static WRITE8_HANDLER( mapper52_m_w )
3625{
3626   UINT8 map52_helper1, map52_helper2;
3627   LOG_MMC(("mapper52_m_w, offset: %04x, data: %02x\n", offset, data));
3628
3629   /* mid writes only work when WRAM is enabled. not sure if I should
3630       change the condition to mmc_cmd2==0x80 (i.e. what is the effect of
3631       the read-only bit?) and it only can happen once! */
3632   if ((mmc_cmd2 & 0x80) && !map52_reg_written)
3633   {
3634      map52_helper1 = (data & 0x08);
3635      map52_helper2 = (data & 0x40);
3636
3637      mmc_prg_base = map52_helper1 ? ((data & 0x06) << 4) : ((data & 0x07) << 4);
3638      mmc_prg_mask = map52_helper1 ? 0x0f : 0x1f;
3639      mmc_chr_base = ((data & 0x20) << 4) | ((data & 0x04) << 6) | (map52_helper2 ? ((data & 0x10) << 3) : 0);
3640      mmc_chr_mask = map52_helper2 ? 0x7f : 0xff;
3641      mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
3642      mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
3643
3644      map52_reg_written = 1;
3645   }
3646   else
3647      nes.wram[offset] = data;
3648}
3649
37683650/*************************************************************
37693651
37703652    Mapper 53
r5944r5945
39833865
39843866static void mapper64_set_banks( running_machine *machine )
39853867{
3986   if (mapper64_cmd & 0x20)
3868   if (mmc_cmd1 & 0x20)
39873869   {
3988      chr1_0(machine, mapper64_data[0], CHRROM);
3989      chr1_2(machine, mapper64_data[1], CHRROM);
3990      chr1_1(machine, mapper64_data[8], CHRROM);
3991      chr1_3(machine, mapper64_data[9], CHRROM);
3870      chr1_0(machine, mapper64_reg[0], CHRROM);
3871      chr1_2(machine, mapper64_reg[1], CHRROM);
3872      chr1_1(machine, mapper64_reg[8], CHRROM);
3873      chr1_3(machine, mapper64_reg[9], CHRROM);
39923874   }
39933875   else
39943876   {
3995      chr1_0(machine, mapper64_data[0] & 0xfe, CHRROM);
3996      chr1_1(machine, (mapper64_data[0] & 0xfe) | 1, CHRROM);
3997      chr1_2(machine, mapper64_data[1] & 0xfe, CHRROM);
3998      chr1_3(machine, (mapper64_data[1] & 0xfe) | 1, CHRROM);
3877      chr1_0(machine, mapper64_reg[0] & 0xfe, CHRROM);
3878      chr1_1(machine, (mapper64_reg[0] & 0xfe) | 1, CHRROM);
3879      chr1_2(machine, mapper64_reg[1] & 0xfe, CHRROM);
3880      chr1_3(machine, (mapper64_reg[1] & 0xfe) | 1, CHRROM);
39993881   }
40003882
4001   chr1_4(machine, mapper64_data[2], CHRROM);
4002   chr1_5(machine, mapper64_data[3], CHRROM);
4003   chr1_6(machine, mapper64_data[4], CHRROM);
4004   chr1_7(machine, mapper64_data[5], CHRROM);
3883   chr1_4(machine, mapper64_reg[2], CHRROM);
3884   chr1_5(machine, mapper64_reg[3], CHRROM);
3885   chr1_6(machine, mapper64_reg[4], CHRROM);
3886   chr1_7(machine, mapper64_reg[5], CHRROM);
40053887
4006   prg8_89(machine, mapper64_data[6]);
4007   prg8_ab(machine, mapper64_data[7]);
4008   prg8_cd(machine, mapper64_data[10]);
3888   prg8_89(machine, mapper64_reg[6]);
3889   prg8_ab(machine, mapper64_reg[7]);
3890   prg8_cd(machine, mapper64_reg[10]);
40093891}
40103892
40113893static WRITE8_HANDLER( mapper64_m_w )
r5944r5945
40223904   switch (offset & 0x7001)
40233905   {
40243906      case 0x0000:
4025         mapper64_cmd = data;
3907         mmc_cmd1 = data;
40263908         break;
40273909      case 0x0001:
4028         if ((mapper64_cmd & 0x0f) < 10)
4029            mapper64_data[mapper64_cmd & 0x0f] = data;
4030         if ((mapper64_cmd & 0x0f) == 0x0f)
4031            mapper64_data[10] = data;
3910         if ((mmc_cmd1 & 0x0f) < 10)
3911            mapper64_reg[mmc_cmd1 & 0x0f] = data;
3912         if ((mmc_cmd1 & 0x0f) == 0x0f)
3913            mapper64_reg[10] = data;
40323914
40333915         mapper64_set_banks(space->machine);
40343916         break;
r5944r5945
40373919         if (data & 0x40)
40383920            set_nt_mirroring(PPU_MIRROR_HIGH);
40393921         else
4040         {
4041            if (data & 0x01)
4042               set_nt_mirroring(PPU_MIRROR_HORZ);
4043            else
4044               set_nt_mirroring(PPU_MIRROR_VERT);
4045         }
3922            set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
40463923         break;
40473924      case 0x4000: /* $c000 - IRQ scanline counter */
40483925         IRQ_count_latch = data;
r5944r5945
41093986   switch (offset & 0x7007)
41103987   {
41113988      case 0x0000:
4112         /* Switch 8k bank at $8000 */
4113         data &= prg_mask;
4114         memory_set_bankptr(space->machine, 1, &nes.rom[0x2000 * (data) + 0x10000]);
3989         prg8_89(space->machine, data);
41153990         LOG_MMC(("     Mapper 65 switch ($8000) value: %02x\n", data));
41163991         break;
41173992      case 0x1001:
r5944r5945
41284003         break;
41294004
41304005      case 0x2000:
4131         /* Switch 8k bank at $a000 */
4132         data &= prg_mask;
4133         memory_set_bankptr(space->machine, 2, &nes.rom[0x2000 * (data) + 0x10000]);
4006         prg8_ab(space->machine, data);
41344007         LOG_MMC(("     Mapper 65 switch ($a000) value: %02x\n", data));
41354008         break;
41364009
r5944r5945
41434016      case 0x3006:
41444017      case 0x3007:
41454018         /* Switch 1k VROM at $0000-$1c00 */
4146         chr1_x(space->machine, offset &7, data, CHRROM);
4147         //ppu2c0x_set_videorom_bank(state->ppu, offset & 7, 1, data, 64);
4019         chr1_x(space->machine, offset & 0x07, data, CHRROM);
41484020         break;
41494021
41504022      case 0x4000:
4151         /* Switch 8k bank at $c000 */
4152         data &= prg_mask;
4153         memory_set_bankptr(space->machine, 3, &nes.rom[0x2000 * (data) + 0x10000]);
4023         prg8_cd(space->machine, data);
41544024         LOG_MMC(("     Mapper 65 switch ($c000) value: %02x\n", data));
41554025         break;
41564026
r5944r5945
45724442    Games: Columbus - Ougon no Yoake (C), Ji Jia Zhan Shi,
45734443          Jia A Fung Yun, Wei Luo Chuan Qi
45744444
4575    In MESS: Partially Supported, but we ignore accesses to 0x5000 / 0x6000 atm
4576    (is this the reason for missing graphics?)
4445    This mapper is quite similar to MMC3, but with two differences:
4446    mirroring is not the same, and when VROM banks 8,9 are accessed
4447    they point to CHRRAM and not CHRROM.
45774448
4449    In MESS: Supported
4450
45784451*************************************************************/
45794452
45804453/* MIRROR_LOW and MIRROR_HIGH are swapped! */
r5944r5945
45984471   }
45994472}
46004473
4474static void mapper74_set_chr( running_machine *machine, int chr_base, int chr_mask )
4475{
4476   UINT8 chr_page = (MMC3_cmd & 0x80) >> 5;
4477   UINT8 chr_src[6];
4478   int i;
4479
4480   for (i = 0; i < 6; i++)
4481      chr_src[i] = ((vrom_bank[i] == 8) || (vrom_bank[i] == 9)) ? CHRRAM : CHRROM;
4482
4483   chr1_x(machine, chr_page ^ 0, chr_base | ((vrom_bank[0] & ~0x01) & chr_mask), chr_src[0]);
4484   chr1_x(machine, chr_page ^ 1, chr_base | ((vrom_bank[0] |  0x01) & chr_mask), chr_src[0]);
4485   chr1_x(machine, chr_page ^ 2, chr_base | ((vrom_bank[1] & ~0x01) & chr_mask), chr_src[1]);
4486   chr1_x(machine, chr_page ^ 3, chr_base | ((vrom_bank[1] |  0x01) & chr_mask), chr_src[1]);
4487   chr1_x(machine, chr_page ^ 4, chr_base | (vrom_bank[2] & chr_mask), chr_src[2]);
4488   chr1_x(machine, chr_page ^ 5, chr_base | (vrom_bank[3] & chr_mask), chr_src[3]);
4489   chr1_x(machine, chr_page ^ 6, chr_base | (vrom_bank[4] & chr_mask), chr_src[4]);
4490   chr1_x(machine, chr_page ^ 7, chr_base | (vrom_bank[5] & chr_mask), chr_src[5]);
4491}
4492
46014493static WRITE8_HANDLER( mapper74_w )
46024494{
4495   UINT8 MMC3_helper, cmd;
46034496   LOG_MMC(("mapper74_w, offset: %04x, data: %02x\n", offset, data));
46044497
46054498   switch (offset & 0x6001)
46064499   {
4500   case 0x0000:
4501      MMC3_helper = MMC3_cmd ^ data;
4502      MMC3_cmd = data;
4503
4504      /* Has PRG Mode changed? */
4505      if (MMC3_helper & 0x40)
4506         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
4507
4508      /* Has CHR Mode changed? */
4509      if (MMC3_helper & 0x80)
4510         mapper74_set_chr(space->machine, mmc_chr_base, mmc_chr_mask);
4511      break;
4512
4513   case 0x0001:
4514      cmd = MMC3_cmd & 0x07;
4515      switch (cmd)
4516      {
4517      case 0: case 1:   // these do not need to be separated because we shift banks in set_chr!
4518      case 2: case 3: case 4: case 5:
4519         vrom_bank[cmd] = data;
4520         mapper74_set_chr(space->machine, mmc_chr_base, mmc_chr_mask);
4521         break;
4522      case 6:
4523      case 7:
4524         prg_bank[cmd - 6] = data;
4525         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
4526         break;
4527      }
4528      break;
4529
46074530   case 0x2000:
46084531      waixing_set_mirror(data);   //maybe data & 0x03?
46094532      break;
4533
46104534   case 0x2001:
46114535      break;
4536
46124537   default:
46134538      mapper4_w(space, offset, data);
46144539      break;
r5944r5945
46374562         break;
46384563      case 0x1000:
46394564         set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
4640         mmc_bank_latch1 = (mmc_bank_latch1 & 0x0f) | ((data & 0x02) << 3);
4641         mmc_bank_latch2 = (mmc_bank_latch2 & 0x0f) | ((data & 0x04) << 2);
4642         chr4_0(space->machine, mmc_bank_latch1, CHRROM);
4643         chr4_4(space->machine, mmc_bank_latch2, CHRROM);
4565         vrom_bank[0] = (vrom_bank[0] & 0x0f) | ((data & 0x02) << 3);
4566         vrom_bank[1] = (vrom_bank[1] & 0x0f) | ((data & 0x04) << 2);
4567         chr4_0(space->machine, vrom_bank[0], CHRROM);
4568         chr4_4(space->machine, vrom_bank[1], CHRROM);
46444569         break;
46454570      case 0x2000:
46464571         prg8_ab(space->machine, data);
r5944r5945
46494574         prg8_cd(space->machine, data);
46504575         break;
46514576      case 0x6000:
4652         mmc_bank_latch1 = (mmc_bank_latch1 & 0x10) | (data & 0x0f);
4653         chr4_0(space->machine, mmc_bank_latch1, CHRROM);
4577         vrom_bank[0] = (vrom_bank[0] & 0x10) | (data & 0x0f);
4578         chr4_0(space->machine, vrom_bank[0], CHRROM);
46544579         break;
46554580      case 0x7000:
4656         mmc_bank_latch2 = (mmc_bank_latch2 & 0x10) | (data & 0x0f);
4657         chr4_4(space->machine, mmc_bank_latch2, CHRROM);
4581         vrom_bank[1] = (vrom_bank[1] & 0x10) | (data & 0x0f);
4582         chr4_4(space->machine, vrom_bank[1], CHRROM);
46584583         break;
46594584   }
46604585}
r5944r5945
48714796   switch (offset)
48724797   {
48734798      case 0x1ef0:
4874         /* Switch 2k VROM at $0000 or $1000 */
48754799         if (vrom_switch)
4876            chr2_4 (space->machine, data, CHRROM);
4800            chr2_4(space->machine, data, CHRROM);
48774801         else
4878            chr2_0 (space->machine, data, CHRROM);
4802            chr2_0(space->machine, data, CHRROM);
48794803         break;
48804804      case 0x1ef1:
4881         /* Switch 2k VROM at $0800 or $1800 */
48824805         if (vrom_switch)
4883            chr2_6 (space->machine, data, CHRROM);
4806            chr2_6(space->machine, data, CHRROM);
48844807         else
4885            chr2_2 (space->machine, data, CHRROM);
4808            chr2_2(space->machine, data, CHRROM);
48864809         break;
48874810      case 0x1ef2:
4888         /* Switch 1k VROM at $1000 */
48894811         chr1_x(space->machine, 4 ^ vrom_switch, data, CHRROM);
4890         //ppu2c0x_set_videorom_bank(state->ppu, 4 ^ vrom_switch, 1, data, 64);
48914812         break;
48924813      case 0x1ef3:
4893         /* Switch 1k VROM at $1400 */
48944814         chr1_x(space->machine, 5 ^ vrom_switch, data, CHRROM);
4895//          ppu2c0x_set_videorom_bank(state->ppu, 5 ^ vrom_switch, 1, data, 64);
48964815         break;
48974816      case 0x1ef4:
4898         /* Switch 1k VROM at $1800 */
48994817         chr1_x(space->machine, 6 ^ vrom_switch, data, CHRROM);
4900//          ppu2c0x_set_videorom_bank(state->ppu, 6 ^ vrom_switch, 1, data, 64);
49014818         break;
49024819      case 0x1ef5:
4903         /* Switch 1k VROM at $1c00 */
49044820         chr1_x(space->machine, 7 ^ vrom_switch, data, CHRROM);
4905//          ppu2c0x_set_videorom_bank(state->ppu, 7 ^ vrom_switch, 1, data, 64);
49064821         break;
49074822      case 0x1ef6:
4908         (data&0x1)?set_nt_mirroring(PPU_MIRROR_VERT):set_nt_mirroring(PPU_MIRROR_HORZ);
4823         set_nt_mirroring((data & 0x1) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
49094824         //doc says 1= swapped. Causes in-game issues, but mostly fixes title screen
49104825         vrom_switch = ((data & 0x02) << 1);
49114826         break;
49124827
49134828      case 0x1efa:
4914         /* Switch 8k ROM at $8000 */
49154829         prg8_89(space->machine, data >> 2);
49164830         break;
49174831      case 0x1efb:
4918         /* Switch 8k ROM at $a000 */
49194832         prg8_ab(space->machine, data >> 2);
49204833         break;
49214834      case 0x1efc:
4922         /* Switch 8k ROM at $c000 */
49234835         prg8_cd(space->machine, data >> 2);
49244836         break;
49254837      default:
r5944r5945
49424854
49434855static WRITE8_HANDLER( mapper83_l_w )
49444856{
4945   mapper83_low_data[offset & 0x03] = data;
4857   mapper83_low_reg[offset & 0x03] = data;
49464858}
49474859
49484860static READ8_HANDLER( mapper83_l_r )
49494861{
4950   return mapper83_low_data[offset & 0x03];
4862   return mapper83_low_reg[offset & 0x03];
49514863}
49524864
49534865static void mapper83_set_prg( running_machine *machine )
49544866{
4955   prg16_89ab(machine, mapper83_data[8] & 0x3f);
4956   prg16_cdef(machine, (mapper83_data[8] & 0x30) | 0x0f);
4867   prg16_89ab(machine, mapper83_reg[8] & 0x3f);
4868   prg16_cdef(machine, (mapper83_reg[8] & 0x30) | 0x0f);
49574869}
49584870
49594871static void mapper83_set_chr( running_machine *machine )
49604872{
4961   chr1_0(machine, mapper83_data[0] | ((mapper83_data[8] & 0x30) << 4), CHRROM);
4962   chr1_1(machine, mapper83_data[1] | ((mapper83_data[8] & 0x30) << 4), CHRROM);
4963   chr1_2(machine, mapper83_data[2] | ((mapper83_data[8] & 0x30) << 4), CHRROM);
4964   chr1_3(machine, mapper83_data[3] | ((mapper83_data[8] & 0x30) << 4), CHRROM);
4965   chr1_4(machine, mapper83_data[4] | ((mapper83_data[8] & 0x30) << 4), CHRROM);
4966   chr1_5(machine, mapper83_data[5] | ((mapper83_data[8] & 0x30) << 4), CHRROM);
4967   chr1_6(machine, mapper83_data[6] | ((mapper83_data[8] & 0x30) << 4), CHRROM);
4968   chr1_7(machine, mapper83_data[7] | ((mapper83_data[8] & 0x30) << 4), CHRROM);
4873   chr1_0(machine, mapper83_reg[0] | ((mapper83_reg[8] & 0x30) << 4), CHRROM);
4874   chr1_1(machine, mapper83_reg[1] | ((mapper83_reg[8] & 0x30) << 4), CHRROM);
4875   chr1_2(machine, mapper83_reg[2] | ((mapper83_reg[8] & 0x30) << 4), CHRROM);
4876   chr1_3(machine, mapper83_reg[3] | ((mapper83_reg[8] & 0x30) << 4), CHRROM);
4877   chr1_4(machine, mapper83_reg[4] | ((mapper83_reg[8] & 0x30) << 4), CHRROM);
4878   chr1_5(machine, mapper83_reg[5] | ((mapper83_reg[8] & 0x30) << 4), CHRROM);
4879   chr1_6(machine, mapper83_reg[6] | ((mapper83_reg[8] & 0x30) << 4), CHRROM);
4880   chr1_7(machine, mapper83_reg[7] | ((mapper83_reg[8] & 0x30) << 4), CHRROM);
49694881}
49704882
49714883static WRITE8_HANDLER( mapper83_w )
r5944r5945
49784890   case 0x3000:
49794891   case 0x30ff:
49804892   case 0x31ff:
4981      mapper83_data[8] = data;
4893      mapper83_reg[8] = data;
49824894      mapper83_set_prg(space->machine);
49834895      mapper83_set_chr(space->machine);
49844896      break;
r5944r5945
50234935   case 0x0315:
50244936   case 0x0316:
50254937   case 0x0317:
5026      mapper83_data[offset - 0x0310] = data;
4938      mapper83_reg[offset - 0x0310] = data;
50274939      mapper83_set_chr(space->machine);
50284940      break;
50294941   case 0x0318:
5030      mapper83_data[9] = data;
4942      mapper83_reg[9] = data;
50314943      mapper83_set_prg(space->machine);
50324944      break;
50334945   }
r5944r5945
50574969
50584970static WRITE8_HANDLER( konami_vrc7_w )
50594971{
4972   UINT8 bank;
50604973   LOG_MMC(("konami_vrc7_w, offset: %04x, data: %02x\n", offset, data));
50614974
50624975   switch (offset & 0x7018)
r5944r5945
50804993/* TODO: there are sound regs in here */
50814994
50824995      case 0x2000:
5083         /* Switch 1k VROM at $0000 */
5084         chr1_0(space->machine, data, mmc_chr_source);
5085         break;
5086      case 0x2008: case 0x2010: case 0x2018:
5087         /* Switch 1k VROM at $0400 */
5088         chr1_1(space->machine, data, mmc_chr_source);
5089         break;
4996      case 0x2008:
4997      case 0x2010:
4998      case 0x2018:
50904999      case 0x3000:
5091         /* Switch 1k VROM at $0800 */
5092         chr1_2(space->machine, data, mmc_chr_source);
5093         break;
5094      case 0x3008: case 0x3010: case 0x3018:
5095         /* Switch 1k VROM at $0c00 */
5096         chr1_3(space->machine, data, mmc_chr_source);
5097         break;
5000      case 0x3008:
5001      case 0x3010:
5002      case 0x3018:
50985003      case 0x4000:
5099         /* Switch 1k VROM at $1000 */
5100         chr1_4(space->machine, data, mmc_chr_source);
5101         break;
5102      case 0x4008: case 0x4010: case 0x4018:
5103         /* Switch 1k VROM at $1400 */
5104         chr1_5(space->machine, data, mmc_chr_source);
5105         break;
5004      case 0x4008:
5005      case 0x4010:
5006      case 0x4018:
51065007      case 0x5000:
5107         /* Switch 1k VROM at $1800 */
5108         chr1_6(space->machine, data, mmc_chr_source);
5008      case 0x5008:
5009      case 0x5010:
5010      case 0x5018:
5011         bank = ((offset & 0x7000) - 0x2000) / 0x0800 + ((offset & 0x0018) ? 1 : 0);
5012         chr1_x(space->machine, bank, data, mmc_chr_source);
51095013         break;
5110      case 0x5008: case 0x5010: case 0x5018:
5111         /* Switch 1k VROM at $1c00 */
5112         chr1_7(space->machine, data, mmc_chr_source);
5113         break;
51145014
51155015      case 0x6000:
51165016         switch (data & 0x03)
r5944r5945
51255025         IRQ_count_latch = data;
51265026         break;
51275027      case 0x7000:
5128         IRQ_count = IRQ_count_latch;
51295028         IRQ_enable = data & 0x02;
51305029         IRQ_enable_latch = data & 0x01;
5030         if (data & 0x02)
5031            IRQ_count = IRQ_count_latch;
51315032         break;
51325033      case 0x7008: case 0x7010: case 0x7018:
51335034         IRQ_enable = IRQ_enable_latch;
r5944r5945
51995100   switch (offset & 1)
52005101   {
52015102   case 0:
5202      {
5203         mmc_cmd1 = data & 7;
5204         break;
5205      }
5103      mmc_cmd1 = data & 7;
5104      break;
52065105   case 1:
5106      switch (mmc_cmd1)
52075107      {
5208         switch (mmc_cmd1)
5209         {
5210            case 0: chr2_0(space->machine, data >> 1, CHRROM); break;
5211            case 1: chr2_2(space->machine, data >> 1, CHRROM); break;
5212            case 2: chr1_4(space->machine, data | 0x40, CHRROM); break;
5213            case 3: chr1_5(space->machine, data | 0x40, CHRROM); break;
5214            case 4: chr1_6(space->machine, data | 0x40, CHRROM); break;
5215            case 5: chr1_7(space->machine, data | 0x40, CHRROM); break;
5216            case 6: prg8_89(space->machine,data); break;
5217            case 7: prg8_ab(space->machine,data); break;
5218         }
5219         break;
5108         case 0: chr2_0(space->machine, data >> 1, CHRROM); break;
5109         case 1: chr2_2(space->machine, data >> 1, CHRROM); break;
5110         case 2: chr1_4(space->machine, data | 0x40, CHRROM); break;
5111         case 3: chr1_5(space->machine, data | 0x40, CHRROM); break;
5112         case 4: chr1_6(space->machine, data | 0x40, CHRROM); break;
5113         case 5: chr1_7(space->machine, data | 0x40, CHRROM); break;
5114         case 6: prg8_89(space->machine,data); break;
5115         case 7: prg8_ab(space->machine,data); break;
52205116      }
5117      break;
52215118   }
52225119}
52235120
r5944r5945
53725269
53735270*************************************************************/
53745271
5375UINT8 map95_reg[4];
5376
53775272static WRITE8_HANDLER( mapper95_w )
53785273{
53795274   LOG_MMC(("mapper95_w, offset: %04x, data: %02x\n", offset, data));
r5944r5945
53985293            case 4:
53995294            case 5:
54005295               chr1_x(space->machine, 2 + mmc_cmd1, data & 0x1f, CHRROM);
5401               map95_reg[mmc_cmd1 - 2] = data & 0x20;
5296               mapper95_reg[mmc_cmd1 - 2] = data & 0x20;
54025297               if (!(mmc_cmd1 & 0x80))
54035298               {
5404                  set_nt_page(0, CIRAM, map95_reg[0] ? 1 : 0, 1);
5405                  set_nt_page(1, CIRAM, map95_reg[1] ? 1 : 0, 1);
5406                  set_nt_page(2, CIRAM, map95_reg[2] ? 1 : 0, 1);
5407                  set_nt_page(3, CIRAM, map95_reg[3] ? 1 : 0, 1);
5299                  set_nt_page(0, CIRAM, mapper95_reg[0] ? 1 : 0, 1);
5300                  set_nt_page(1, CIRAM, mapper95_reg[1] ? 1 : 0, 1);
5301                  set_nt_page(2, CIRAM, mapper95_reg[2] ? 1 : 0, 1);
5302                  set_nt_page(3, CIRAM, mapper95_reg[3] ? 1 : 0, 1);
54085303               }
54095304               else
54105305                  set_nt_mirroring(PPU_MIRROR_HORZ);
r5944r5945
55615456   {
55625457      if (data & 0x08)
55635458      {
5564         mmc_bank_latch1 = ((data & 0x07) << 4) | (mmc_bank_latch1 & 0x0f);
5565         prg16_89ab(space->machine, mmc_bank_latch1);
5459         prg_bank[0] = ((data & 0x07) << 4) | (prg_bank[0] & 0x0f);
5460         prg16_89ab(space->machine, prg_bank[0]);
55665461         prg16_cdef(space->machine, ((data & 0x07) << 4) | 0x0f);
55675462      }
55685463
55695464   }
55705465   else
55715466   {
5572         mmc_bank_latch1 = (mmc_bank_latch1 & 0x70) | (data & 0x0f);
5573         prg16_89ab(space->machine, mmc_bank_latch1);
5467         prg_bank[0] = (prg_bank[0] & 0x70) | (data & 0x0f);
5468         prg16_89ab(space->machine, prg_bank[0]);
55745469   }
55755470}
55765471
r5944r5945
57575652    Known Boards: Unknown Bootleg Board
57585653    Games: The Lion King
57595654
5760    MMC3 clone
5655    MMC3 clone.
57615656
5762    In MESS: Unsupported.
5657    In MESS: Supported.
57635658
57645659*************************************************************/
57655660
5661static WRITE8_HANDLER( mapper114_m_w )
5662{
5663   LOG_MMC(("mapper114_m_w, offset: %04x, data: %02x\n", offset, data));
5664
5665   map114_reg = data;
5666
5667   if (map114_reg & 0x80)
5668   {
5669      prg16_89ab(space->machine, data & 0x1f);
5670      prg16_cdef(space->machine, data & 0x1f);
5671   }
5672   else
5673      mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
5674
5675}
5676
5677static WRITE8_HANDLER( mapper114_w )
5678{
5679   static const UINT8 conv_table[8] = {0, 3, 1, 5, 6, 7, 2, 4};
5680   LOG_MMC(("mapper114_w, offset: %04x, data: %02x\n", offset, data));
5681
5682   if (offset < 0x6000)
5683   {
5684      switch (offset & 0x6000)
5685      {
5686      case 0x0000:
5687         set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
5688         break;
5689      case 0x2000:
5690         map114_reg_enabled = 1;
5691         data = (data & 0xc0) | conv_table[data & 0x07];
5692         mapper4_w(space, 0x8000, data);
5693         break;
5694      case 0x4000:
5695         if (map114_reg_enabled && (map114_reg & 0x80) == 0)
5696         {
5697            map114_reg_enabled = 0;
5698            mapper4_w(space, 0x8001, data);
5699         }
5700         break;
5701      }
5702   }
5703   else
5704   {
5705      switch (offset & 0x03)
5706      {
5707      case 0x02:
5708         mapper4_w(space, 0xe000, data);
5709         break;
5710      case 0x03:
5711         mapper4_w(space, 0xe001, data);
5712         mapper4_w(space, 0xc000, data);
5713         mapper4_w(space, 0xc001, data);
5714         break;
5715      }
5716   }
5717}
5718
57665719/*************************************************************
57675720
57685721    Mapper 115 (formerly 248)
r5944r5945
57795732
57805733static void mapper115_set_prg( running_machine *machine )
57815734{
5782   if (MMC1_bank4 & 0x80)
5735   if (mapper115_reg[3] & 0x80)
57835736   {
5784      prg16_89ab(machine, MMC1_bank4 & 0x0f);
5737      prg16_89ab(machine, mapper115_reg[3] & 0x0f);
57855738   }
57865739   else
57875740   {
5788      prg8_89(machine, MMC1_bank2 & 0x1f);
5789      prg8_ab(machine, MMC1_bank3 & 0x1f);
5741      prg8_89(machine, mapper115_reg[1] & 0x1f);
5742      prg8_ab(machine, mapper115_reg[2] & 0x1f);
57905743   }
57915744}
57925745
r5944r5945
57945747{
57955748   LOG_MMC(("mapper115_m_w, offset: %04x, data: %02x\n", offset, data));
57965749
5797   MMC1_bank4 = data;
5750   mapper115_reg[3] = data;
57985751   mapper115_set_prg(space->machine);
57995752}
58005753
r5944r5945
58055758   switch (offset & 0x7001)
58065759   {
58075760   case 0x0000:
5808      MMC1_bank1 = data;
5761      mapper115_reg[0] = data;
58095762      break;
58105763   case 0x0001:
5811      switch (MMC1_bank1 & 0x07)
5764      switch (mapper115_reg[0] & 0x07)
58125765      {
58135766      case 0:
58145767         chr2_0(space->machine, data >> 1, CHRROM);
r5944r5945
58295782         chr1_7(space->machine, data, CHRROM);
58305783         break;
58315784      case 6:
5832         MMC1_bank2 = data;
5785         mapper115_reg[1] = data;
58335786         mapper115_set_prg(space->machine);
58345787         break;
58355788      case 7:
5836         MMC1_bank3 = data;
5789         mapper115_reg[2] = data;
58375790         mapper115_set_prg(space->machine);
58385791         break;
58395792      }
r5944r5945
59145867
59155868static WRITE8_HANDLER( mapper118_w )
59165869{
5917   static UINT8 last_bank = 0xff;
59185870   LOG_MMC(("mapper118_w, offset: %04x, data: %02x\n", offset, data));
59195871
5920   //uses just bits 14, 13, and 0
59215872   switch (offset & 0x6001)
59225873   {
5923      case 0x0000: /* $8000 */
5924         MMC3_cmd = data;
5925
5926         /* Toggle between switching $8000 and $c000 */
5927         if (last_bank != (data & 0xc0))
5928         {
5929            /* Reset the banks */
5930            mapper4_set_prg(space->machine);
5931            mapper4_set_chr(space->machine, mmc_chr_source);
5932         }
5933         last_bank = data & 0xc0;
5934         break;
5935
5936      case 0x0001: /* $8001 */
5937      {
5938         UINT8 cmd = MMC3_cmd & 0x07;
5939         switch (cmd)
5940         {
5941            case 0: case 1:
5942               data &= 0xfe;
5943               MMC3_chr[cmd] = data;
5944               mapper4_set_chr(space->machine, mmc_chr_source);
5945               break;
5946
5947            case 2: case 3: case 4: case 5:
5948               MMC3_chr[cmd] = data;
5949               mapper4_set_chr(space->machine, mmc_chr_source);
5950               break;
5951
5952            case 6:
5953               MMC3_prg0 = data;
5954               mapper4_set_prg(space->machine);
5955               break;
5956
5957            case 7:
5958               MMC3_prg1 = data;
5959               mapper4_set_prg(space->machine);
5960               break;
5961         }
5962         break;
5963      }
59645874      case 0x2000: /* $a000 */
59655875         LOG_MMC(("     mapper 118 mirroring: %02x\n", data));
59665876         switch (data & 0x02)
r5944r5945
59705880         }
59715881         break;
59725882
5973      case 0x2001: /* $a001 - extra RAM enable/disable */
5974         nes.mid_ram_enable = data;
5975         LOG_MMC(("     MMC3 mid_ram enable: %02x\n", data));
5976         break;
5977
59785883      case 0x4000: /* $c000 - IRQ scanline counter */
59795884         IRQ_count = data;
5980         LOG_MMC(("     MMC3 set irq count: %02x\n", data));
59815885         break;
59825886
59835887      case 0x4001: /* $c001 - IRQ scanline latch */
59845888         IRQ_count_latch = data;
5985         LOG_MMC(("     MMC3 set irq count latch: %02x\n", data));
59865889         break;
59875890
5988      case 0x6000: /* $e000 - Disable IRQs */
5989         IRQ_enable = 0;
5990         IRQ_count = IRQ_count_latch; /* TODO: verify this */
5991         LOG_MMC(("     MMC3 disable irqs: %02x\n", data));
5992         break;
5993
5994      case 0x6001: /* $e001 - Enable IRQs */
5995         IRQ_enable = 1;
5996         LOG_MMC(("     MMC3 enable irqs: %02x\n", data));
5997         break;
5998
59995891      default:
6000         logerror("mapper4_w uncaught: %04x value: %02x\n", offset + 0x8000, data);
5892         mapper4_w(space, offset, data);
60015893         break;
60025894   }
60035895}
r5944r5945
60175909{
60185910   UINT8 chr_page = (MMC3_cmd & 0x80) >> 5;
60195911
6020   if (MMC3_chr[0] & 0x40)
6021      chr2_x(machine, chr_page ^ 0, (MMC3_chr[0] >> 1) & 0x03, CHRRAM);
5912   if (vrom_bank[0] & 0x40)
5913      chr2_x(machine, chr_page ^ 0, (vrom_bank[0] >> 1) & 0x03, CHRRAM);
60225914   else
6023      chr2_x(machine, chr_page ^ 0, ((MMC3_chr[0] & 0x3f) >> 1), CHRROM);
5915      chr2_x(machine, chr_page ^ 0, ((vrom_bank[0] & 0x3f) >> 1), CHRROM);
60245916
6025   if (MMC3_chr[1] & 0x40)
6026      chr2_x(machine, chr_page ^ 2, (MMC3_chr[1] >> 1) & 0x03, CHRRAM);
5917   if (vrom_bank[1] & 0x40)
5918      chr2_x(machine, chr_page ^ 2, (vrom_bank[1] >> 1) & 0x03, CHRRAM);
60275919   else
6028      chr2_x(machine, chr_page ^ 2, ((MMC3_chr[1] & 0x3f) >> 1), CHRROM);
5920      chr2_x(machine, chr_page ^ 2, ((vrom_bank[1] & 0x3f) >> 1), CHRROM);
60295921
6030   if (MMC3_chr[2] & 0x40)
6031      chr1_x(machine, chr_page ^ 4, MMC3_chr[2] & 0x07, CHRRAM);
5922   if (vrom_bank[2] & 0x40)
5923      chr1_x(machine, chr_page ^ 4, vrom_bank[2] & 0x07, CHRRAM);
60325924   else
6033      chr1_x(machine, chr_page ^ 4, MMC3_chr[2] & 0x3f, CHRROM);
5925      chr1_x(machine, chr_page ^ 4, vrom_bank[2] & 0x3f, CHRROM);
60345926
6035   if (MMC3_chr[3] & 0x40)
6036      chr1_x(machine, chr_page ^ 5, MMC3_chr[3] & 0x07, CHRRAM);
5927   if (vrom_bank[3] & 0x40)
5928      chr1_x(machine, chr_page ^ 5, vrom_bank[3] & 0x07, CHRRAM);
60375929   else
6038      chr1_x(machine, chr_page ^ 5, MMC3_chr[3] & 0x3f, CHRROM);
5930      chr1_x(machine, chr_page ^ 5, vrom_bank[3] & 0x3f, CHRROM);
60395931
6040   if (MMC3_chr[4] & 0x40)
6041      chr1_x(machine, chr_page ^ 6, MMC3_chr[4] & 0x07, CHRRAM);
5932   if (vrom_bank[4] & 0x40)
5933      chr1_x(machine, chr_page ^ 6, vrom_bank[4] & 0x07, CHRRAM);
60425934   else
6043      chr1_x(machine, chr_page ^ 6, MMC3_chr[4] & 0x3f, CHRROM);
5935      chr1_x(machine, chr_page ^ 6, vrom_bank[4] & 0x3f, CHRROM);
60445936
6045   if (MMC3_chr[5] & 0x40)
6046      chr1_x(machine, chr_page ^ 7, MMC3_chr[5] & 0x07, CHRRAM);
5937   if (vrom_bank[5] & 0x40)
5938      chr1_x(machine, chr_page ^ 7, vrom_bank[5] & 0x07, CHRRAM);
60475939   else
6048      chr1_x(machine, chr_page ^ 7, MMC3_chr[5] & 0x3f, CHRROM);
5940      chr1_x(machine, chr_page ^ 7, vrom_bank[5] & 0x3f, CHRROM);
60495941}
60505942
60515943static WRITE8_HANDLER( mapper119_w )
r5944r5945
60535945   static UINT8 last_bank = 0xff;
60545946   LOG_MMC(("mapper119_w, offset: %04x, data: %02x\n", offset, data));
60555947
6056   //only bits 14,13, and 0 matter for offset!
60575948   switch (offset & 0x6001)
60585949   {
60595950      case 0x0000: /* $8000 */
r5944r5945
60635954         if (last_bank != (data & 0xc0))
60645955         {
60655956            /* Reset the banks */
6066            mapper4_set_prg(space->machine);
5957            mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
60675958            mapper119_set_chr(space->machine);
60685959            LOG_MMC(("     MMC3 reset banks\n"));
60695960         }
r5944r5945
60755966         UINT8 cmd = MMC3_cmd & 0x07;
60765967         switch (cmd)
60775968         {
6078            case 0: case 1:
6079               MMC3_chr[cmd] = data;
6080               mapper119_set_chr(space->machine);
6081               LOG_MMC(("     MMC3 set vram %d: %d\n", cmd, data));
6082               break;
6083
5969            case 0: case 1:   // these do not need to be separated because we shift banks in set_chr!
60845970            case 2: case 3: case 4: case 5:
6085               MMC3_chr[cmd] = data;
5971               vrom_bank[cmd] = data;
60865972               mapper119_set_chr(space->machine);
6087               LOG_MMC(("     MMC3 set vram %d: %d\n", cmd, data));
60885973               break;
6089
60905974            case 6:
6091               MMC3_prg0 = data;
6092               mapper4_set_prg(space->machine);
6093               break;
6094
60955975            case 7:
6096               MMC3_prg1 = data;
6097               mapper4_set_prg(space->machine);
5976               prg_bank[cmd - 6] = data;
5977               mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
60985978               break;
60995979         }
61005980         break;
61015981      }
6102      case 0x2000: /* $a000 */
6103         if (data & 0x40)
6104            set_nt_mirroring(PPU_MIRROR_HIGH);
6105         else
6106         {
6107            if (data & 0x01)
6108               set_nt_mirroring(PPU_MIRROR_HORZ);
6109            else
6110               set_nt_mirroring(PPU_MIRROR_VERT);
6111         }
6112         break;
6113
6114      case 0x2001: /* $a001 - extra RAM enable/disable */
6115         nes.mid_ram_enable = data;
6116         LOG_MMC(("     MMC3 mid_ram enable: %02x\n", 0));
6117         break;
6118
6119      case 0x4000: /* $c000 - IRQ scanline counter */
6120         IRQ_count_latch = data;
6121//          LOG_MMC(("     MMC3 set irq count latch: %02x (scanline %d)\n", data, ppu2c0x_get_current_scanline(0)));
6122         break;
6123
6124      case 0x4001: /* $c001 - IRQ scanline latch */
6125         IRQ_reload = 1;
6126//          LOG_MMC(("     MMC3 set irq reload (scanline %d)\n", ppu2c0x_get_current_scanline(0)));
6127         break;
6128
6129      case 0x6000: /* $e000 - Disable IRQs */
6130         IRQ_enable = 0;
6131         LOG_MMC(("     MMC3 disable irqs\n"));
6132         break;
6133
6134      case 0x6001: /* $e001 - Enable IRQs */
6135         IRQ_enable = 1;
6136         LOG_MMC(("     MMC3 enable irqs\n"));
6137         break;
6138
61395982      default:
6140         logerror("mapper119_w uncaught: %04x value: %02x\n", offset + 0x8000, data);
5983         mapper4_w(space, offset, data);
61415984         break;
61425985   }
61435986}
r5944r5945
62916134
62926135*************************************************************/
62936136
6294UINT8 txc_reg[4]; // also used by mappers 172 & 173
6295
62966137static WRITE8_HANDLER( mapper132_l_w )
62976138{
62986139   LOG_MMC(("mapper132_l_w, offset: %04x, data: %02x\n", offset, data));
r5944r5945
63076148
63086149   if (offset == 0x0000)
63096150      return (txc_reg[1] ^ txc_reg[2]) | 0x40;
6310
63116151   else
63126152      return 0x00;
63136153}
r5944r5945
63396179   chr8(space->machine, data, CHRROM);
63406180}
63416181
6182static WRITE8_HANDLER( mapper133_m_w )
6183{
6184   LOG_MMC(("mapper133_l_w %04x:%02x\n", offset, data));
6185
6186   if (offset == 0)
6187{
6188   prg32(space->machine, data >> 2);
6189   chr8(space->machine, data, CHRROM);}
6190}
6191
63426192/*************************************************************
63436193
63446194    Mapper 134
r5944r5945
64066256
64076257*************************************************************/
64086258
6409UINT8 sachen_regs[8]; // used by mappers 137, 138, 139, 141
6410
64116259static void sachen_set_mirror( UINT8 nt ) // used by mappers 137, 138, 139, 141
64126260{
64136261   switch (nt)
r5944r5945
64436291         mmc_cmd1 = data & 0x07;
64446292      else
64456293      {
6446         sachen_regs[mmc_cmd1] = data;
6294         sachen_reg[mmc_cmd1] = data;
64476295
64486296         switch (mmc_cmd1)
64496297         {
r5944r5945
64566304         default:
64576305            if (mmc_chr_source == CHRROM)
64586306            {
6459               chr1_0(space->machine, (sachen_regs[0] & 0x07), CHRROM);
6460               chr1_1(space->machine, (sachen_regs[1] & 0x07) | (sachen_regs[4] << 4 & 0x10), CHRROM);
6461               chr1_2(space->machine, (sachen_regs[2] & 0x07) | (sachen_regs[4] << 3 & 0x10), CHRROM);
6462               chr1_3(space->machine, (sachen_regs[3] & 0x07) | (sachen_regs[4] << 2 & 0x10) | (sachen_regs[6] << 3 & 0x08), CHRROM);
6307               chr1_0(space->machine, (sachen_reg[0] & 0x07), CHRROM);
6308               chr1_1(space->machine, (sachen_reg[1] & 0x07) | (sachen_reg[4] << 4 & 0x10), CHRROM);
6309               chr1_2(space->machine, (sachen_reg[2] & 0x07) | (sachen_reg[4] << 3 & 0x10), CHRROM);
6310               chr1_3(space->machine, (sachen_reg[3] & 0x07) | (sachen_reg[4] << 2 & 0x10) | (sachen_reg[6] << 3 & 0x08), CHRROM);
64636311            }
64646312            break;
64656313         }
r5944r5945
64716319{
64726320   LOG_MMC(("mapper137_m_w, offset: %04x, data: %02x\n", offset, data));
64736321
6474   mapper137_l_w(space, (offset + 0x100) & 0x01, data);
6322   mapper137_l_w(space, offset + 0x100, data);
64756323}
64766324
64776325/*************************************************************
r5944r5945
64986346         mmc_cmd1 = data & 0x07;
64996347      else
65006348      {
6501         sachen_regs[mmc_cmd1] = data;
6349         sachen_reg[mmc_cmd1] = data;
65026350
65036351         switch (mmc_cmd1)
65046352         {
r5944r5945
65116359         default:
65126360            if (mmc_chr_source == CHRROM)
65136361            {
6514               bank_helper1 = sachen_regs[7] & 0x01;
6515               bank_helper2 = (sachen_regs[4] & 0x07) << 3;
6516               chr2_0(space->machine, ((sachen_regs[bank_helper1 ? 0 : 0] & 0x07) | bank_helper2), CHRROM);
6517               chr2_2(space->machine, ((sachen_regs[bank_helper1 ? 0 : 1] & 0x07) | bank_helper2), CHRROM);
6518               chr2_4(space->machine, ((sachen_regs[bank_helper1 ? 0 : 2] & 0x07) | bank_helper2), CHRROM);
6519               chr2_6(space->machine, ((sachen_regs[bank_helper1 ? 0 : 3] & 0x07) | bank_helper2), CHRROM);
6362               bank_helper1 = sachen_reg[7] & 0x01;
6363               bank_helper2 = (sachen_reg[4] & 0x07) << 3;
6364               chr2_0(space->machine, ((sachen_reg[bank_helper1 ? 0 : 0] & 0x07) | bank_helper2), CHRROM);
6365               chr2_2(space->machine, ((sachen_reg[bank_helper1 ? 0 : 1] & 0x07) | bank_helper2), CHRROM);
6366               chr2_4(space->machine, ((sachen_reg[bank_helper1 ? 0 : 2] & 0x07) | bank_helper2), CHRROM);
6367               chr2_6(space->machine, ((sachen_reg[bank_helper1 ? 0 : 3] & 0x07) | bank_helper2), CHRROM);
65206368            }
65216369            break;
65226370         }
r5944r5945
65286376{
65296377   LOG_MMC(("mapper138_m_w, offset: %04x, data: %02x\n", offset, data));
65306378
6531   mapper138_l_w(space, offset & 0x01, data);
6379   mapper138_l_w(space, offset + 0x100, data);
65326380}
65336381
65346382/*************************************************************
r5944r5945
65556403         mmc_cmd1 = data & 0x07;
65566404      else
65576405      {
6558         sachen_regs[mmc_cmd1] = data;
6406         sachen_reg[mmc_cmd1] = data;
65596407
65606408         switch (mmc_cmd1)
65616409         {
r5944r5945
65686416         default:
65696417            if (mmc_chr_source == CHRROM)
65706418            {
6571               bank_helper1 = sachen_regs[7] & 0x01;
6572               bank_helper2 = (sachen_regs[4] & 0x07) << 3;
6573               chr2_0(space->machine, ((sachen_regs[bank_helper1 ? 0 : 0] & 0x07) | bank_helper2) << 2, CHRROM);
6574               chr2_2(space->machine, ((sachen_regs[bank_helper1 ? 0 : 1] & 0x07) | bank_helper2) << 2 | 0x01, CHRROM);
6575               chr2_4(space->machine, ((sachen_regs[bank_helper1 ? 0 : 2] & 0x07) | bank_helper2) << 2 | 0x02, CHRROM)   ;
6576               chr2_6(space->machine, ((sachen_regs[bank_helper1 ? 0 : 3] & 0x07) | bank_helper2) << 2 | 0x03, CHRROM);
6419               bank_helper1 = sachen_reg[7] & 0x01;
6420               bank_helper2 = (sachen_reg[4] & 0x07) << 3;
6421               chr2_0(space->machine, ((sachen_reg[bank_helper1 ? 0 : 0] & 0x07) | bank_helper2) << 2, CHRROM);
6422               chr2_2(space->machine, ((sachen_reg[bank_helper1 ? 0 : 1] & 0x07) | bank_helper2) << 2 | 0x01, CHRROM);
6423               chr2_4(space->machine, ((sachen_reg[bank_helper1 ? 0 : 2] & 0x07) | bank_helper2) << 2 | 0x02, CHRROM)   ;
6424               chr2_6(space->machine, ((sachen_reg[bank_helper1 ? 0 : 3] & 0x07) | bank_helper2) << 2 | 0x03, CHRROM);
65776425            }
65786426            break;
65796427         }
r5944r5945
65856433{
65866434   LOG_MMC(("mapper139_m_w, offset: %04x, data: %02x\n", offset, data));
65876435
6588   mapper139_l_w(space, (offset + 0x100) & 0x01, data);
6436   mapper139_l_w(space, offset + 0x100, data);
65896437}
65906438
65916439/*************************************************************
r5944r5945
66326480         mmc_cmd1 = data & 0x07;
66336481      else
66346482      {
6635         sachen_regs[mmc_cmd1] = data;
6483         sachen_reg[mmc_cmd1] = data;
66366484
66376485         switch (mmc_cmd1)
66386486         {
r5944r5945
66456493         default:
66466494            if (mmc_chr_source == CHRROM)
66476495            {
6648               bank_helper1 = sachen_regs[7] & 0x01;
6649               bank_helper2 = (sachen_regs[4] & 0x07) << 3;
6650               chr2_0(space->machine, ((sachen_regs[bank_helper1 ? 0 : 0] & 0x07) | bank_helper2) << 1, mmc_chr_source);
6651               chr2_2(space->machine, ((sachen_regs[bank_helper1 ? 0 : 1] & 0x07) | bank_helper2) << 1 | 0x01, mmc_chr_source);
6652               chr2_4(space->machine, ((sachen_regs[bank_helper1 ? 0 : 2] & 0x07) | bank_helper2) << 1, mmc_chr_source);
6653               chr2_6(space->machine, ((sachen_regs[bank_helper1 ? 0 : 3] & 0x07) | bank_helper2) << 1 | 0x01, mmc_chr_source);
6496               bank_helper1 = sachen_reg[7] & 0x01;
6497               bank_helper2 = (sachen_reg[4] & 0x07) << 3;
6498               chr2_0(space->machine, ((sachen_reg[bank_helper1 ? 0 : 0] & 0x07) | bank_helper2) << 1, mmc_chr_source);
6499               chr2_2(space->machine, ((sachen_reg[bank_helper1 ? 0 : 1] & 0x07) | bank_helper2) << 1 | 0x01, mmc_chr_source);
6500               chr2_4(space->machine, ((sachen_reg[bank_helper1 ? 0 : 2] & 0x07) | bank_helper2) << 1, mmc_chr_source);
6501               chr2_6(space->machine, ((sachen_reg[bank_helper1 ? 0 : 3] & 0x07) | bank_helper2) << 1 | 0x01, mmc_chr_source);
66546502            }
66556503            break;
66566504         }
r5944r5945
66626510{
66636511   LOG_MMC(("mapper141_m_w, offset: %04x, data: %02x\n", offset, data));
66646512
6665   mapper141_l_w(space, (offset + 0x100) & 0x01, data);
6513   mapper141_l_w(space, offset + 0x100, data);
66666514}
66676515
66686516/*************************************************************
r5944r5945
67226570
67236571   data = data |(memory_read_byte(space, offset) & 1);
67246572
6725   /* Switch 8k VROM bank */
67266573   chr8(space->machine, data >> 4, CHRROM);
6727
6728   /* Switch 32k prg bank */
67296574   prg32(space->machine, data & 0x07);
67306575}
67316576
r5944r5945
67936638{
67946639   LOG_MMC(("mapper147_m_w, offset: %04x, data: %02x\n", offset, data));
67956640
6796   mapper147_l_w(space, offset & 0x01, data);
6641   mapper147_l_w(space, offset + 0x100, data);
67976642}
67986643
67996644static WRITE8_HANDLER( mapper147_w )
68006645{
68016646   LOG_MMC(("mapper147_w, offset: %04x, data: %02x\n", offset, data));
68026647
6803   mapper147_l_w(space, (offset + 0x100) & 0x01, data);
6648   mapper147_l_w(space, offset + 0x100, data);
68046649}
68056650
68066651/*************************************************************
r5944r5945
68536698    Games: Chess Academy, Chinese Checkers Jpn, Mahjong Academy,
68546699          Olympic IQ, Poker II, Tasac
68556700
6856    Still investigating this mapper...
6701    In MESS: Supported.
68576702
6858    In MESS: Preliminary Support.
6859
68606703*************************************************************/
68616704
68626705static WRITE8_HANDLER( mapper150_l_w )
r5944r5945
68746717         switch (mmc_cmd1)
68756718         {
68766719         case 0x02:
6720            vrom_bank[0] = (vrom_bank[0] & ~0x08) | ((data << 3) & 0x08);
6721            chr8(space->machine, vrom_bank[0], CHRROM);
68776722            prg32(space->machine, data & 0x01);
6878            chr8(space->machine, (mmc_bank_latch1 & ~0x08) | ((data << 3) & 0x08), CHRROM);
68796723            break;
68806724         case 0x04:
6881            chr8(space->machine, (mmc_bank_latch1 & ~0x04) | ((data << 2) & 0x04), CHRROM);
6725            vrom_bank[0] = (vrom_bank[0] & ~0x04) | ((data << 2) & 0x04);
6726            chr8(space->machine, vrom_bank[0], CHRROM);
68826727            break;
68836728         case 0x05:
68846729            prg32(space->machine, data & 0x07);
68856730            break;
68866731         case 0x06:
6887            chr8(space->machine, (mmc_bank_latch1 & ~0x03) | (data << 0 & 0x03), CHRROM);
6732            vrom_bank[0] = (vrom_bank[0] & ~0x03) | (data << 0 & 0x03);
6733            chr8(space->machine, vrom_bank[0], CHRROM);
68886734            break;
68896735         case 0x07:
68906736            sachen_set_mirror((data >> 1) & 0x03);
r5944r5945
69006746{
69016747   LOG_MMC(("mapper150_l_r, offset: %04x", offset));
69026748
6903   /* read  happens only if we are at 0x4100 + k * 0x200,
6904    but 0x4100 is offset = 0 */
6749   /* read  happens only if we are at 0x4100 + k * 0x200, but 0x4100 is offset = 0 */
69056750   if (!(offset & 0x100))
69066751      return (~mmc_cmd1 & 0x3f) /* ^ dips*/;   // we would need to check the Dips here
69076752   else
r5944r5945
69126757{
69136758   LOG_MMC(("mapper150_m_w, offset: %04x, data: %02x\n", offset, data));
69146759
6915   mapper150_l_w(space, (offset + 0x100) & 0x01, data);
6760   mapper150_l_w(space, offset + 0x100, data);
69166761}
69176762
69186763/*************************************************************
r5944r5945
70056850
70066851    Mapper 155
70076852
7008    Known Boards: ???
6853    Known Boards: SKROM
70096854    Games: Tatakae!! Rahmen Man - Sakuretsu Choujin 102 Gei
70106855
7011    In MESS: Unsupported.
6856    This is basically MMC1 with a different way to handle WRAM
6857    (this difference is not emulated yet, since we don't fully
6858    emulate WRAM in MMC1 either)
70126859
6860    In MESS: Supported (as complete as MMC1).
6861
70136862*************************************************************/
70146863
70156864/*************************************************************
r5944r5945
71907039
71917040*************************************************************/
71927041
7193UINT8 subor_reg[4];   // used also by 167 below
7194
71957042static WRITE8_HANDLER( mapper166_w )
71967043{
71977044   UINT8 map166_helper1, map166_helper2;
r5944r5945
75687415      set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
75697416      break;
75707417   case 0x2000:
7571      mmc_bank_latch1 = data;
7418      mmc_cmd1 = data;
75727419      break;
75737420   case 0x4000:
7574      switch (mmc_bank_latch1)
7421      switch (mmc_cmd1)
75757422      {
75767423      case 0:
75777424         chr2_0(space->machine, data >> 1, CHRROM);
r5944r5945
88978744    Known Boards: Bootleg Board by Sachen (74SL374A)
88988745    Games: Poker III
88998746
8900    Conflicting info about this. Still investigating. The board is similar
8901    to the one of mapper 150.
8747    The board is similar to the one of mapper 150.
89028748
89038749    In MESS: Supported.
89048750
r5944r5945
89238769            chr8(space->machine, 3, CHRROM);
89248770            break;
89258771         case 0x02:
8926            chr8(space->machine, (mmc_bank_latch1 & ~0x08) | (data << 3 & 0x08), CHRROM);   // Nestopia
8772            vrom_bank[0] = (vrom_bank[0] & ~0x08) | (data << 3 & 0x08);
8773            chr8(space->machine, vrom_bank[0], CHRROM);
89278774            break;
89288775         case 0x04:
8929            chr8(space->machine, (mmc_bank_latch1 & ~0x01) | (data << 0 & 0x01), CHRROM);   // Nestopia
8776            vrom_bank[0] = (vrom_bank[0] & ~0x01) | (data << 0 & 0x01);
8777            chr8(space->machine, vrom_bank[0], CHRROM);
89308778            break;
89318779         case 0x05:
89328780            prg32(space->machine, data & 0x01);
89338781            break;
89348782         case 0x06:
8935            chr8(space->machine, (mmc_bank_latch1 & ~0x06) | (data << 1 & 0x06), CHRROM);   // Nestopia
8783            vrom_bank[0] = (vrom_bank[0] & ~0x06) | (data << 1 & 0x06);
8784            chr8(space->machine, vrom_bank[0], CHRROM);
89368785            break;
89378786         case 0x07:
89388787            set_nt_mirroring(data & 0x01 ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
r5944r5945
92039052   {  9, "MMC2",                 NULL, NULL, NULL, mapper9_w, mapper9_latch, NULL, NULL},
92049053   { 10, "MMC4",                 NULL, NULL, NULL, mapper10_w, mapper9_latch, NULL, NULL },
92059054   { 11, "Color Dreams Mapper",  NULL, NULL, NULL, mapper11_w, NULL, NULL, NULL },
9206   { 13, "CP-ROM",               NULL, NULL,   NULL, mapper13_w, NULL, NULL, NULL }, //needs CHR-RAM hooked up
9055   { 12, "Rex Soft DBZ5",        mapper12_l_w, mapper12_l_r, NULL, mapper12_w, NULL, NULL, mapper4_irq },
9056   { 13, "CP-ROM",               NULL, NULL,   NULL, mapper13_w, NULL, NULL, NULL },
92079057   { 15, "100-in-1",             NULL, NULL, NULL, mapper15_w, NULL, NULL, NULL },
92089058   { 16, "Bandai",               NULL, NULL, mapper16_m_w, mapper16_w, NULL,NULL,  bandai_irq },
92099059   { 17, "FFE F8xxx",            mapper17_l_w, NULL, NULL, NULL, NULL, NULL, mapper4_irq },
92109060   { 18, "Jaleco",               NULL, NULL, NULL, mapper18_w, NULL, NULL, jaleco_irq },
9211   { 19, "Namco 106",            mapper19_l_w, NULL, NULL, mapper19_w, NULL, NULL, namcot_irq },
9061   { 19, "Namco 106",            mapper19_l_w, mapper19_l_r, NULL, mapper19_w, NULL, NULL, namcot_irq },
92129062   { 20, "Famicom Disk System",  NULL, NULL, NULL, NULL, NULL, NULL, fds_irq },
92139063   { 21, "Konami VRC 4",         NULL, NULL, NULL, konami_vrc4_w, NULL, NULL, konami_irq },
92149064   { 22, "Konami VRC 2a",        NULL, NULL, NULL, konami_vrc2a_w, NULL, NULL, NULL },
r5944r5945
92209070   { 33, "Taito TC0190",         NULL, NULL, NULL, mapper33_w, NULL, NULL, NULL },
92219071   { 34, "Nina-1",               NULL, NULL, mapper34_m_w, mapper34_w, NULL, NULL, NULL },
92229072   { 36, "TXC Policeman",        NULL, NULL, NULL, mapper36_w, NULL, NULL, NULL },
9073   { 37, "ZZ Board",             NULL, NULL, mapper37_m_w, mapper4_w, NULL, NULL, mapper4_irq },
92239074   { 38, "Crime Buster",         NULL, NULL, mapper38_m_w, NULL, NULL, NULL, NULL },
92249075   { 39, "Subor Study n Game",   NULL, NULL, NULL, mapper39_w, NULL, NULL, NULL },
92259076   { 40, "SMB2j (bootleg)",      NULL, NULL, NULL, mapper40_w, NULL, NULL, mapper40_irq },
r5944r5945
92329083   { 47, "2-in-1 MMC3",          NULL, NULL, mapper47_m_w, mapper4_w, NULL, NULL, mapper4_irq },
92339084   { 49, "4-in-1 MMC3",          NULL, NULL, mapper49_m_w, mapper4_w, NULL, NULL, mapper4_irq },
92349085   { 51, "11-in-1",              NULL, NULL, mapper51_m_w, mapper51_w, NULL, NULL, NULL },
9086   { 52, "Mario 7-in-1",         NULL, NULL, mapper52_m_w, mapper4_w, NULL, NULL, mapper4_irq },
92359087   { 57, "6-in-1",               NULL, NULL, NULL, mapper57_w, NULL, NULL, NULL },
92369088   { 58, "X-in-1",               NULL, NULL, NULL, mapper58_w, NULL, NULL, NULL },
92379089   { 61, "20-in-1",              NULL, NULL, NULL, mapper61_w, NULL, NULL, NULL },
r5944r5945
92769128   { 107, "Magic Dragon",        NULL, NULL, NULL, mapper107_w, NULL, NULL, NULL },
92779129   { 112, "Asper",               NULL, NULL, NULL, mapper112_w, NULL, NULL, NULL },
92789130   { 113, "Sachen/Hacker/Nina",  mapper113_l_w, NULL, NULL, NULL, NULL, NULL, NULL },
9131   { 114, "The Lion King",       NULL, NULL, mapper114_m_w, mapper114_w, NULL, NULL, mapper4_irq },
92799132   { 115, "Bao Qing Tian",       NULL, NULL, mapper115_m_w, mapper115_w, NULL, NULL, mapper115_irq },
92809133   { 118, "MMC3?",               NULL, NULL, NULL, mapper118_w, NULL, NULL, mapper4_irq },
92819134   { 119, "MMC3 - Pinbot",       NULL, NULL, NULL, mapper119_w, NULL, NULL, mapper4_irq },
92829135   { 132, "TXC T22211A",         mapper132_l_w, mapper132_l_r, NULL, mapper132_w, NULL, NULL, NULL },
9283   { 133, "Sachen SA72008",      mapper133_l_w, NULL, NULL, NULL, NULL, NULL, NULL },
9136   { 133, "Sachen SA72008",      mapper133_l_w, NULL, mapper133_m_w, NULL, NULL, NULL, NULL },
92849137   { 136, "Sachen TCU01",        mapper136_l_w, mapper136_l_r, NULL, NULL, NULL, NULL, NULL },
92859138   { 137, "Sachen 8259D",        mapper137_l_w, NULL, mapper137_m_w, NULL, NULL, NULL, NULL },
92869139   { 138, "Sachen 8259B",        mapper138_l_w, NULL, mapper138_m_w, NULL, NULL, NULL, NULL },
r5944r5945
92979150   { 150, "Sachen 74LS374B",     mapper150_l_w, mapper150_l_r, mapper150_m_w, NULL, NULL, NULL, NULL },
92989151   { 152, "Taito Discrete",      NULL, NULL, NULL, mapper152_w, NULL, NULL, NULL },
92999152   { 154, "Devil Man",           NULL, NULL, NULL, mapper154_w, NULL, NULL, NULL },
9153   { 155, "Devil Man",           NULL, NULL, NULL, mapper1_w, NULL, NULL, NULL }, // diff compared to MMC1 concern WRAM (unsupported for MMC1 as well, atm)
93009154   { 156, "Open Corp. DAOU36",   NULL, NULL, NULL, mapper156_w, NULL, NULL, NULL },
93019155   { 164, "Final Fantasy V",     mapper164_l_w, NULL, NULL, mapper164_w, NULL, NULL, NULL },
93029156   { 166, "Subor Board Type 1",  NULL, NULL, NULL, mapper166_w, NULL, NULL, NULL },
r5944r5945
93759229{
93769230   const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
93779231   nes_state *state = machine->driver_data;
9378   int err = 0;
9232   int err = 0, i;
93799233   const mmc *mapper;
93809234
93819235   if (nes.chr_chunks == 0)
r5944r5945
93879241   mapper = nes_mapper_lookup(mmc_num);
93889242
93899243   if (mapper == NULL)
9390      fatalerror("Unimplemented Mapper");
9244      fatalerror("Unimplemented Mapper %d", mmc_num);
9245//      logerror("Mapper %d is not yet supported, defaulting to no mapper.\n", mmc_num);    // this one would be a better output
93919246
9247
93929248   ppu2c0x_set_scanline_callback(state->ppu, mapper ? mapper->mmc_scanline : NULL);
93939249   ppu2c0x_set_hblank_callback(state->ppu, mapper ? mapper->mmc_hblank : NULL);
93949250
r5944r5945
93969252      nes_irq_timer = timer_alloc(machine, nes_irq_callback, NULL);
93979253
93989254   mapper_warning = 0;
9399   /* 8k mask */
9400   prg_mask = ((nes.prg_chunks << 1) - 1);
94019255
94029256   MMC5_vram_control = 0;
94039257
9258   /* Here, we init a few helpers: 4 prg banks and 16 chr banks - some mappers use them */
9259   for (i = 0; i < 4; i++)
9260   {
9261      prg_bank[i] = 0;
9262      vrom_bank[4 * i + 0] = 0;
9263      vrom_bank[4 * i + 1] = 0;
9264      vrom_bank[4 * i + 2] = 0;
9265      vrom_bank[4 * i + 3] = 0;
9266   }
9267
94049268   /* Point the WRAM/battery area to the first RAM bank */
94059269   if (mmc_num != 20 && mmc_num != 40)
94069270      memory_set_bankptr(space->machine, 5, &nes.wram[0x0000]);
r5944r5945
94129276         prg32(space->machine, 0);
94139277         break;
94149278      case 1:
9415         /* Reset the latch */
9416         MMC1_reg = 0;
9417         MMC1_reg_count = 0;
9418
9419         MMC1_Size_16k = 1;
9420         MMC1_Switch_Low = 1;
9421         MMC1_SizeVrom_4k = 0;
9422         MMC1_extended_bank = 0;
9423         MMC1_extended_swap = 0;
9424         MMC1_extended_base = 0x10000;
9425         MMC1_extended = ((nes.prg_chunks << 4) + nes.chr_chunks * 8) >> 9;
9426
9427         if (!MMC1_extended)
9428            /* Set it to the end of the prg rom */
9429            MMC1_High = (nes.prg_chunks - 1) * 0x4000;
9430         else
9431            /* Set it to the end of the first 256k bank */
9432            MMC1_High = 15 * 0x4000;
9433
9434         MMC1_bank1 = 0;
9435         MMC1_bank2 = 0x2000;
9436         MMC1_bank3 = MMC1_High;
9437         MMC1_bank4 = MMC1_High + 0x2000;
9438
9439         memory_set_bankptr(space->machine, 1, &nes.rom[MMC1_extended_base + MMC1_bank1]);
9440         memory_set_bankptr(space->machine, 2, &nes.rom[MMC1_extended_base + MMC1_bank2]);
9441         memory_set_bankptr(space->machine, 3, &nes.rom[MMC1_extended_base + MMC1_bank3]);
9442         memory_set_bankptr(space->machine, 4, &nes.rom[MMC1_extended_base + MMC1_bank4]);
9443         logerror("-- page1: %06x\n", MMC1_bank1);
9444         logerror("-- page2: %06x\n", MMC1_bank2);
9445         logerror("-- page3: %06x\n", MMC1_bank3);
9446         logerror("-- page4: %06x\n", MMC1_bank4);
9279      case 155:
9280         mmc_cmd1 = 0;
9281         mmc_count = 0;
9282         MMC1_regs[0] = 0x0f;
9283         MMC1_regs[1] = MMC1_regs[2] = MMC1_regs[3] = 0;
9284         set_nt_mirroring(PPU_MIRROR_HORZ);
9285         MMC1_set_chr(space->machine);
9286         MMC1_set_prg(space->machine);
94479287         break;
94489288      case 2:
94499289         /* These games don't switch VROM, but some ROMs incorrectly have CHR chunks */
r5944r5945
94749314            set_nt_page(2, CART_NTRAM, 2, 1);
94759315            set_nt_page(3, CART_NTRAM, 3, 1);
94769316         }
9317      case 12:
94779318      case 118:
94789319      case 119:
94799320      case 196:
r5944r5945
94829323         IRQ_enable = 0;
94839324         IRQ_count = IRQ_count_latch = 0;
94849325         IRQ_reload = 0;
9485         MMC3_prg0 = 0xfe;
9486         MMC3_prg1 = 0xff;
9326         prg_bank[0] = 0xfe;
9327         prg_bank[1] = 0xff;
94879328         MMC3_cmd = 0;
9488         MMC3_prg_base = 0;
9489         MMC3_prg_mask = (nes.prg_chunks << 1) - 1;
9490         MMC3_chr_base = 0;
9491         MMC3_chr_mask = (nes.chr_chunks << 3) - 1;
9329         mmc_cmd2 = 0x80;
9330         mmc_prg_base = mmc_chr_base = 0;
9331         mmc_prg_mask = mmc_chr_mask = 0xff;
94929332         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
9493         mapper4_set_prg(space->machine);
9494         mapper4_set_chr(space->machine, mmc_chr_source);
9333         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
9334         mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
94959335         break;
94969336      case 5:
94979337         /* Can switch 8k prg banks, but they are saved as 16k in size */
r5944r5945
95199359         /* Can switch 8k prg banks */
95209360         /* Note that the iNES header defines the number of banks as 8k in size, rather than 16k */
95219361         /* Reset VROM latches */
9522         MMC2_bank0 = MMC2_bank1 = 0;
9523         MMC2_bank0_hi = MMC2_bank1_hi = 0;
9524         MMC2_bank0_latch = MMC2_bank1_latch = 0xfe;
9362         MMC2_regs[0] = MMC2_regs[2] = 0;
9363         MMC2_regs[1] = MMC2_regs[3] = 0;
9364         mmc_cmd1 = mmc_cmd2 = 0xfe;
95259365         prg8_89(space->machine, 0);
95269366         //ugly hack to deal with iNES header usage of chunk count.
95279367         prg8_ab(space->machine, (nes.prg_chunks << 1) - 3);
r5944r5945
95309370         break;
95319371      case 10:
95329372         /* Reset VROM latches */
9533         MMC2_bank0 = MMC2_bank1 = 0;
9534         MMC2_bank0_hi = MMC2_bank1_hi = 0;
9535         MMC2_bank0_latch = MMC2_bank1_latch = 0xfe;
9373         MMC2_regs[0] = MMC2_regs[2] = 0;
9374         MMC2_regs[1] = MMC2_regs[3] = 0;
9375         mmc_cmd1 = mmc_cmd2 = 0xfe;
95369376         prg16_89ab(space->machine, 0);
95379377         prg16_cdef(space->machine, nes.prg_chunks - 1);
95389378         break;
r5944r5945
95909430         /* Can switch 32k prg banks */
95919431         prg32(space->machine, 0);
95929432         break;
9433      case 37:
9434         IRQ_enable = 0;
9435         IRQ_count = IRQ_count_latch = 0;
9436         IRQ_reload = 0;
9437         prg_bank[0] = 0xfe;
9438         prg_bank[1] = 0xff;
9439         MMC3_cmd = 0;
9440         mmc_cmd2 = 0x80;
9441         mmc_prg_base = mmc_chr_base = 0;
9442         mmc_prg_mask = 0x07;
9443         mmc_chr_mask = 0x7f;
9444         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
9445         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
9446         mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
9447         break;
95939448      case 40:
95949449         IRQ_enable = 0;
95959450         IRQ_count = 0;
r5944r5945
96189473         IRQ_enable = 0;
96199474         IRQ_count = IRQ_count_latch = 0;
96209475         IRQ_reload = 0;
9621         MMC3_prg0 = 0xfe;
9622         MMC3_prg1 = 0xff;
9476         prg_bank[0] = 0xfe;
9477         prg_bank[1] = 0xff;
96239478         MMC3_cmd = 0;
9624         MMC3_prg_base = 0;
9625         MMC3_prg_mask = 0x0f;
9626         MMC3_chr_base = 0;
9627         MMC3_chr_mask = 0x7f;
9479         mmc_cmd2 = 0x80;
9480         mmc_prg_base = mmc_chr_base = 0;
9481         mmc_prg_mask = 0x0f;
9482         mmc_chr_mask = 0x7f;
96289483         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
9629         mapper4_set_prg(space->machine);
9630         mapper4_set_chr(space->machine, mmc_chr_source);
9484         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
9485         mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
96319486         break;
96329487      case 45:
96339488         IRQ_enable = 0;
96349489         IRQ_count = IRQ_count_latch = 0;
96359490         IRQ_reload = 0;
9636         MMC3_prg0 = 0xfe;
9637         MMC3_prg1 = 0xff;
9638         MMC3_cmd = 0;
9639         MMC3_prg_base = 0x30;
9640         MMC3_prg_mask = 0x0f;
9641         MMC3_chr_base = 0;
9642         MMC3_chr_mask = 0x7f;
9491         prg_bank[0] = 0xfe;
9492         prg_bank[1] = 0xff;
9493         mmc_cmd1 = 0;
9494         mmc_cmd2 = 0x80;
96439495         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
9644         mapper45_cmd = 0;
9645         mapper45_data[0] = mapper45_data[1] = mapper45_data[2] = mapper45_data[3] = 0;
9646         mapper4_set_prg(space->machine);
9647         mapper4_set_chr(space->machine, mmc_chr_source);
9496         mapper45_reg[0] = mapper45_reg[1] = mapper45_reg[2] = mapper45_reg[3] = 0;
9497         mmc_prg_base = 0x30;
9498         mmc_prg_mask = 0x3f;
9499         mmc_chr_base = 0;
9500         mmc_chr_mask = 0x7f;
9501         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
9502         mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
96489503         memory_set_bankptr(space->machine, 5, nes.wram);
96499504         break;
96509505      case 46:
9651         mmc_bank_latch1 = 0;
9652         mmc_bank_latch2 = 0;
96539506         prg32(space->machine, 0);
96549507         chr8(space->machine, 0, CHRROM);
96559508         break;
9509      case 52:
9510         IRQ_enable = 0;
9511         IRQ_count = IRQ_count_latch = 0;
9512         IRQ_reload = 0;
9513         prg_bank[0] = 0xfe;
9514         prg_bank[1] = 0xff;
9515         mmc_cmd1 = 0;
9516         mmc_cmd2 = 0x80;
9517         map52_reg_written = 0;
9518         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
9519         mmc_prg_base = 0;
9520         mmc_prg_mask = 0x1f;
9521         mmc_chr_base = 0;
9522         mmc_chr_mask = 0xff;
9523         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
9524         mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
9525         memory_set_bankptr(space->machine, 5, nes.wram);
9526         break;
96569527      case 51:
9657         MMC1_bank1 = 0x01;
9658         MMC1_bank2 = 0x00;
9659         MMC1_bank3 = 0x00;
9528         mapper51_reg[0] = 0x01;
9529         mapper51_reg[1] = 0x00;
9530         mapper51_reg[2] = 0x00;
96609531         mapper51_set_banks(space->machine);
96619532         break;
96629533      case 57:
9663         MMC1_bank1 = 0x00;
9664         MMC1_bank2 = 0x00;
9534         mmc_cmd1 = 0x00;
9535         mmc_cmd2 = 0x00;
96659536         prg16_89ab(space->machine, 0);
96669537         prg16_cdef(space->machine, 0);
96679538         chr8(space->machine, 0, CHRROM);
r5944r5945
97429613         prg16_cdef(space->machine, nes.prg_chunks - 1);
97439614         break;
97449615      case 83:
9745         mapper83_data[9] = 0x0f;
9616         mapper83_reg[9] = 0x0f;
97469617         prg8_cd(space->machine, 0x1e);
97479618         prg8_ef(space->machine, 0x1f);
97489619         break;
r5944r5945
97969667         prg32(space->machine, 0);
97979668         break;
97989669      case 104:
9799         mmc_bank_latch1 = 0;
98009670         prg16_89ab(space->machine, 0x00);
98019671         prg16_cdef(space->machine, 0x0f);
98029672         break;
9673      case 114:
9674         IRQ_enable = 0;
9675         IRQ_count = IRQ_count_latch = 0;
9676         IRQ_reload = 0;
9677         map114_reg = map114_reg_enabled = 0;
9678         prg_bank[0] = 0xfe;
9679         prg_bank[1] = 0xff;
9680         MMC3_cmd = 0;
9681         mmc_cmd2 = 0x80;
9682         mmc_prg_base = mmc_chr_base = 0;
9683         mmc_prg_mask = mmc_chr_mask = 0xff;
9684         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
9685         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
9686         mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
9687         break;
9688      case 115:
9689         mapper115_reg[0] = mapper115_reg[1] = mapper115_reg[2] = mapper115_reg[3] = 0;
9690         prg32(space->machine, 0xff);
9691         break;
98039692      case 132:
98049693      case 172:
98059694      case 173:
r5944r5945
98509739         chr8(space->machine, 0, CHRROM);
98519740         break;
98529741      case 150:
9853         mmc_bank_latch1 = 0;
98549742         mmc_cmd1 = 0;
98559743         prg32(space->machine, 0);
98569744         chr8(space->machine, 0, CHRROM);
r5944r5945
99649852         mapper232_set_prg(space->machine);
99659853         break;
99669854      case 243:
9967         mmc_bank_latch1 = 3;
9855         vrom_bank[0] = 3;
99689856         mmc_cmd1 = 0;
99699857         chr8(space->machine, 3, CHRROM);
99709858         prg32(space->machine, 0);
r5944r5945
99739861      case 246:
99749862         prg32(space->machine, 0xff);
99759863         break;
9976      case 248:
9977         MMC1_bank1 = MMC1_bank2 = MMC1_bank3 = MMC1_bank4 = 0;
9978         prg32(space->machine, 0xff);
9979         break;
99809864      default:
99819865         /* Mapper not supported */
99829866         err = 2;

Previous 15994 Revisions Next


© 1998-2018 The MESS Team