Previous 15994 Revisions Next

r5927 Wednesday 30th September, 2009 at 20:04:33 UTC by Fabio Priuli
[NES] Added many mappers, fixed some longstanding bugs and a couple of 0.130/0.134 regressions
[hash]nes.hsi
[src/mess/drivers]nes.c
[src/mess/machine]nes.c nes_mmc.c nes_mmc.h

hash/nes.hsi
r5926r5927
45084508   </hash>
45094509   <hash crc32="47918d84" sha1="587e90896e17897682e80b43643a22ec336ed54e" name="Auto-Upturn (Sachen)">
45104510      <status>GoodNES Verified Image</status>
4511      <extrainfo>243 0 2 8</extrainfo>
4511      <extrainfo>150 0 2 8</extrainfo>
45124512
45134513   </hash>
45144514   <hash crc32="89e12946" sha1="6e5a4f701c8aaba2c89357a5fbfb11467e1cc61b" name="Auto-Upturn (Sachen) [U]">
r5926r5927
1162411624   </hash>
1162511625   <hash crc32="471173e7" sha1="62a6b4db403911f74a0eaa1b726f3d127ea48242" name="Chinese Checkers (Sachen-USA)">
1162611626      <status>GoodNES Verified Image</status>
11627      <extrainfo>243 0 2 2</extrainfo>
11627      <extrainfo>150 0 2 2</extrainfo>
1162811628
1162911629   </hash>
1163011630   <hash crc32="12a95930" sha1="a58b71b4b9ff14be13f3539405b23bccbca93b69" name="Chinese Checkers (Sachen-USA) [U]">
r5926r5927
2656926569   </hash>
2657026570   <hash crc32="2394ae1c" sha1="ca8905c8ab70154e77ca1c93fe014db2de51bf2a" name="Happy Pairs (Sachen)">
2657126571      <status>GoodNES Verified Image</status>
26572      <extrainfo>243 0 2 8</extrainfo>
26572      <extrainfo>150 0 2 8</extrainfo>
2657326573
2657426574   </hash>
2657526575   <hash crc32="fe361c47" sha1="8579d9b67e9053ed1bd31a5f849a041ec6542064" name="Happy Pairs (Sachen) [U]">
r5926r5927
3575635756   </hash>
3575735757   <hash crc32="cab40a6c" sha1="b7a6d5782d0266a7e2f1c1c1c159a41fb122bd08" name="Magic Cubes (Sachen)">
3575835758      <status>GoodNES Verified Image</status>
35759      <extrainfo>243 0 2 2</extrainfo>
35759      <extrainfo>150 0 2 2</extrainfo>
3576035760
3576135761   </hash>
3576235762   <hash crc32="61625581" sha1="13475548a492e045895006e49eb4c11a1b0bce20" name="Magic Cubes (Sachen) [U]">
r5926r5927
4719947199   </hash>
4720047200   <hash crc32="6096f84e" sha1="60fc5fa5b5accaf3aefeba73fc8bffd3c4dae558" name="Pegasus 5-in-1 (Golden Five)">
4720147201      <status>GoodNES Verified Image</status>
47202      <extrainfo>71 0 80 0</extrainfo>
47202      <extrainfo>104 0 80 0</extrainfo>
4720347203
4720447204   </hash>
4720547205   <hash crc32="9b78dff5" sha1="bad382331c30b22a908da4bff2759c25113cc26a" name="Pegasus 5-in-1 (Golden Five)">
r5926r5927
5805658056   </hash>
5805758057   <hash crc32="34ddf806" sha1="cb319ae39b41d8ed695fa40bdd899be4aa839f2d" name="Strategist (Sachen)">
5805858058      <status>GoodNES Verified Image</status>
58059      <extrainfo>243 0 2 4</extrainfo>
58059      <extrainfo>150 0 2 4</extrainfo>
5806058060
5806158061   </hash>
5806258062   <hash crc32="16caf76b" sha1="347c1eff0165ac7b93fbd64887d348b2f0b46601" name="Strategist (Sachen) [U]">
r5926r5927
5806658066   </hash>
5806758067   <hash crc32="c06facfc" sha1="757560b286cb1064cd105acca55e5c2287adc673" name="Strategist (With Intro) (Sachen)">
5806858068      <status>GoodNES Verified Image</status>
58069      <extrainfo>243 0 2 4</extrainfo>
58069      <extrainfo>150 0 2 4</extrainfo>
5807058070
5807158071   </hash>
5807258072   <hash crc32="7e8fb99a" sha1="afb13f9986e4f8362a5a856504f2ff44afc7065a" name="Strategist (With Intro) (Sachen) [U]">
r5926r5927
7261672616
7261772617   </hash>
7261872618   <hash crc32="02c41438" sha1="17473c223453d2d80fcb9dcfa317947287dc5c52" name="Xing He Zhan Shi (Ch)">
72619      <extrainfo>177 2 32 0</extrainfo>
72619      <extrainfo>179 2 32 0</extrainfo>
7262072620
7262172621   </hash>
7262272622   <hash crc32="e197932b" sha1="705e5a1218f1b22201b357fa5440cac9f3765f66" name="Xing Ji Wu Shi - Super Fighter (Ch)">
src/mess/machine/nes.c
r5926r5927
1616/* Set to dump info about the inputs to the errorlog */
1717#define LOG_JOY      0
1818
19/* Set to generate prg chunk files when the cart is loaded */
19/* Set to generate prg (16k) & chr (8k) chunk files when the cart is loaded */
2020#define SPLIT_PRG   0
21#define SPLIT_CHR   0
2122
2223#define BATTERY_SIZE 0x2000
2324
24
25
2625/***************************************************************************
2726    TYPE DEFINITIONS
2827***************************************************************************/
r5926r5927
3433   UINT32 i0, i1, i2;
3534};
3635
37
38
3936/***************************************************************************
4037    GLOBAL VARIABLES
4138***************************************************************************/
r5926r5927
4946static nes_input in_0;
5047static nes_input in_1;
5148
52
53
5449/***************************************************************************
5550    FUNCTION PROTOTYPES
5651***************************************************************************/
r5926r5927
5853static void init_nes_core(running_machine *machine);
5954static void nes_machine_stop(running_machine *machine);
6055
61
62
6356/***************************************************************************
6457    FUNCTIONS
6558***************************************************************************/
r5926r5927
115108         break;
116109      case 40:
117110         nes.slow_banking = 1;
118         /* Game runs code in between banks, so we do things different */
119         memory_install_read8_handler(space, 0x6000, 0x7fff, 0, 0, SMH_RAM);
120         memory_install_read8_handler(space, 0x8000, 0xffff, 0, 0, SMH_ROM);
111         memory_install_read8_handler(space, 0x8000, 0x9fff, 0, 0, SMH_BANK(1));
112         memory_install_read8_handler(space, 0xa000, 0xbfff, 0, 0, SMH_BANK(2));
113         memory_install_read8_handler(space, 0xc000, 0xdfff, 0, 0, SMH_BANK(3));
114         memory_install_read8_handler(space, 0xe000, 0xffff, 0, 0, SMH_BANK(4));
115         memory_set_bankptr(machine, 1, memory_region(machine, "maincpu") + 0x6000);
116         memory_set_bankptr(machine, 2, memory_region(machine, "maincpu") + 0x8000);
117         memory_set_bankptr(machine, 3, memory_region(machine, "maincpu") + 0xa000);
118         memory_set_bankptr(machine, 4, memory_region(machine, "maincpu") + 0xc000);
121119
120         /* FIXME: this is wrong, but at least it fixes the crash */
121         memory_install_read8_handler(space, 0x6000, 0x7fff, 0, 0, SMH_BANK(5));
122         memory_set_bankptr(machine, 5, memory_region(machine, "maincpu") + 0xe000);
123
124         /* Game runs code in between banks, so we do things different here */
122125         memory_install_write8_handler(space, 0x6000, 0x7fff, 0, 0, nes_mid_mapper_w);
123126         memory_install_write8_handler(space, 0x8000, 0xffff, 0, 0, nes_mapper_w);
124127         break;
r5926r5927
444447   int local_options = 0;
445448   char m;
446449   int i;
450   const char *filetype = image_filetype(image);
447451
448   /* Verify the file is in iNES format */
449   memset(magic, '\0', sizeof(magic));
450   image_fread(image, magic, 4);
452   if (!mame_stricmp(filetype, "nes"))
453   {   
454      /* Verify the file is in iNES format */
455      memset(magic, '\0', sizeof(magic));
456      image_fread(image, magic, 4);
451457
452   if ((magic[0] != 'N') || (magic[1] != 'E') || (magic[2] != 'S'))
453   {
454      logerror("%s is NOT a file in iNES format.\n", image_filename(image));
455      return INIT_FAIL;
456   }
458      if ((magic[0] != 'N') || (magic[1] != 'E') || (magic[2] != 'S'))
459      {
460         logerror("%s is NOT a file in iNES format.\n", image_filename(image));
461         return INIT_FAIL;
462      }
457463
458   mapinfo = image_extrainfo(image);
464      mapinfo = image_extrainfo(image);
459465
460   if (mapinfo)
461   {
462      if (4 == sscanf(mapinfo,"%d %d %d %d", &mapint1, &mapint2, &mapint3, &mapint4))
466      if (mapinfo)
463467      {
464         nes.mapper = mapint1;
465         local_options = mapint2;
466         nes.prg_chunks = mapint3;
467         nes.chr_chunks = mapint4;
468         logerror("NES.CRC info: %d %d %d %d\n",mapint1,mapint2,mapint3,mapint4);
469         goodcrcinfo = 1;
468         if (4 == sscanf(mapinfo,"%d %d %d %d", &mapint1, &mapint2, &mapint3, &mapint4))
469         {
470            nes.mapper = mapint1;
471            local_options = mapint2;
472            nes.prg_chunks = mapint3;
473            nes.chr_chunks = mapint4;
474            logerror("NES.HSI info: %d %d %d %d\n", mapint1, mapint2, mapint3, mapint4);
475            goodcrcinfo = 1;
476         }
477         else
478         {
479            logerror("NES: [%s], Invalid mapinfo found\n",mapinfo);
480         }
470481      }
471482      else
472483      {
473         logerror("NES: [%s], Invalid mapinfo found\n",mapinfo);
484         logerror("NES: No extrainfo found\n");
474485      }
475   }
476   else
477   {
478      logerror("NES: No extrainfo found\n");
479   }
480486
481   if (!goodcrcinfo)
482   {
483      // image_extrainfo() resets the file position back to start.
484      // Let's skip past the magic header once again.
485      image_fseek(image, 4, SEEK_SET);
487      if (!goodcrcinfo)
488      {
489         // image_extrainfo() resets the file position back to start.
490         // Let's skip past the magic header once again.
491         image_fseek(image, 4, SEEK_SET);
486492
487      image_fread(image, &nes.prg_chunks, 1);
488      image_fread(image, &nes.chr_chunks, 1);
489      /* Read the first ROM option byte (offset 6) */
490      image_fread(image, &m, 1);
493         image_fread(image, &nes.prg_chunks, 1);
494         image_fread(image, &nes.chr_chunks, 1);
495         /* Read the first ROM option byte (offset 6) */
496         image_fread(image, &m, 1);
491497
492      /* Interpret the iNES header flags */
493      nes.mapper = (m & 0xf0) >> 4;
494      local_options = m & 0x0f;
498         /* Interpret the iNES header flags */
499         nes.mapper = (m & 0xf0) >> 4;
500         local_options = m & 0x0f;
495501
502         /* Read the second ROM option byte (offset 7) */
503         image_fread(image, &m, 1);
504   
505         /* Check for skanky headers */
506         image_fread(image, &skank, 8);
496507
497      /* Read the second ROM option byte (offset 7) */
498      image_fread(image, &m, 1);
499
500      /* Check for skanky headers */
501      image_fread(image, &skank, 8);
502
503      /* If the header has junk in the unused bytes, assume the extra mapper byte is also invalid */
504      /* We only check the first 4 unused bytes for now */
505      for (i = 0; i < 4; i ++)
506      {
507         logerror("%02x ", skank[i]);
508         if (skank[i] != 0x00)
508         /* If the header has junk in the unused bytes, assume the extra mapper byte is also invalid */
509         /* We only check the first 4 unused bytes for now */
510         for (i = 0; i < 4; i ++)
509511         {
510            logerror("(skank: %d)", i);
511//              m = 0;
512            logerror("%02x ", skank[i]);
513            if (skank[i] != 0x00)
514            {
515               logerror("(skank: %d)", i);
516            }
512517         }
518         logerror("\n");
519   
520         nes.mapper = nes.mapper | (m & 0xf0);
513521      }
514      logerror("\n");
515522
516      nes.mapper = nes.mapper | (m & 0xf0);
517   }
523      nes.hard_mirroring = local_options & 0x01;
524      nes.battery = local_options & 0x02;
525      nes.trainer = local_options & 0x04;
526      nes.four_screen_vram = local_options & 0x08;
518527
519   nes.hard_mirroring = local_options & 0x01;
520   nes.battery = local_options & 0x02;
521   nes.trainer = local_options & 0x04;
522   nes.four_screen_vram = local_options & 0x08;
528      if (nes.battery)
529         logerror("-- Battery found\n");
523530
524   if (nes.battery) logerror("-- Battery found\n");
525   if (nes.trainer) logerror("-- Trainer found\n");
526   if (nes.four_screen_vram) logerror("-- 4-screen VRAM\n");
531      if (nes.trainer)
532         logerror("-- Trainer found\n");
527533
528   /* Free the regions that were allocated by the ROM loader */
529   memory_region_free(image->machine, "maincpu");
530   memory_region_free(image->machine, "gfx1");
534      if (nes.four_screen_vram)
535         logerror("-- 4-screen VRAM\n");
531536
532   /* Allocate them again with the proper size */
533   memory_region_alloc(image->machine, "maincpu", 0x10000 + (nes.prg_chunks + 1) * 0x4000,0);
534   if (nes.chr_chunks)
535      memory_region_alloc(image->machine, "gfx1", nes.chr_chunks * 0x2000,0);
537      /* Free the regions that were allocated by the ROM loader */
538      memory_region_free(image->machine, "maincpu");
539      memory_region_free(image->machine, "gfx1");
536540
537   nes.rom = memory_region(image->machine, "maincpu");
538   nes.vrom = memory_region(image->machine, "gfx1");
539   nes.vram = memory_region(image->machine, "gfx2");
540   nes.wram = memory_region(image->machine, "user1");
541      /* Allocate them again with the proper size */
542      memory_region_alloc(image->machine, "maincpu", 0x10000 + (nes.prg_chunks + 1) * 0x4000,0);
543      if (nes.chr_chunks)
544         memory_region_alloc(image->machine, "gfx1", nes.chr_chunks * 0x2000,0);
541545
542   /* Position past the header */
543   image_fseek(image, 16, SEEK_SET);
546      nes.rom = memory_region(image->machine, "maincpu");
547      nes.vrom = memory_region(image->machine, "gfx1");
548      nes.vram = memory_region(image->machine, "gfx2");
549      nes.wram = memory_region(image->machine, "user1");
544550
545   /* Load the 0x200 byte trainer at 0x7000 if it exists */
546   if (nes.trainer)
547   {
548      image_fread(image, &nes.wram[0x1000], 0x200);
549   }
551      /* Position past the header */
552      image_fseek(image, 16, SEEK_SET);
550553
551   /* Read in the program chunks */
552   if (nes.prg_chunks == 1)
553   {
554      image_fread(image, &nes.rom[0x14000], 0x4000);
555      /* Mirror this bank into $8000 */
556      memcpy(&nes.rom[0x10000], &nes.rom [0x14000], 0x4000);
557   }
558   else
559      image_fread(image, &nes.rom[0x10000], 0x4000 * nes.prg_chunks);
554      /* Load the 0x200 byte trainer at 0x7000 if it exists */
555      if (nes.trainer)
556         image_fread(image, &nes.wram[0x1000], 0x200);
560557
558      /* Read in the program chunks */
559      if (nes.prg_chunks == 1)
560      {
561         image_fread(image, &nes.rom[0x14000], 0x4000);
562         /* Mirror this bank into $8000 */
563         memcpy(&nes.rom[0x10000], &nes.rom [0x14000], 0x4000);
564      }
565      else
566         image_fread(image, &nes.rom[0x10000], 0x4000 * nes.prg_chunks);
567
561568#if SPLIT_PRG
562   {
563      FILE *prgout;
564      char outname[255];
569      {
570         FILE *prgout;
571         char outname[255];
565572
566      for (i = 0; i < nes.prg_chunks; i ++)
567      {
568         sprintf(outname, "%s.p%d", battery_name, i);
569         prgout = fopen(outname, "wb");
570         if (prgout)
573         for (i = 0; i < nes.prg_chunks; i ++)
571574         {
572            fwrite(&nes.rom[0x10000 + 0x4000 * i], 1, 0x4000, prgout);
573            fclose(prgout);
575            sprintf(outname, "%s.p%d", image_filename(image), i);
576            prgout = fopen(outname, "wb");
577            if (prgout)
578            {
579               fwrite(&nes.rom[0x10000 + 0x4000 * i], 1, 0x4000, prgout);
580               fclose(prgout);
581            }
574582         }
575583      }
576   }
577584#endif /* SPLIT_PRG */
578585
579   logerror("**\n");
580   logerror("Mapper: %d\n", nes.mapper);
581   logerror("PRG chunks: %02x, size: %06x\n", nes.prg_chunks, 0x4000 * nes.prg_chunks);
586      logerror("**\n");
587      logerror("Mapper: %d\n", nes.mapper);
588      logerror("PRG chunks: %02x, size: %06x\n", nes.prg_chunks, 0x4000 * nes.prg_chunks);
589//      printf("Mapper: %d\n", nes.mapper);
590//      printf("PRG chunks: %02x, size: %06x\n", nes.prg_chunks, 0x4000 * nes.prg_chunks);
582591
583   /* Read in any chr chunks */
584   if (nes.chr_chunks > 0)
592      /* Read in any chr chunks */
593      if (nes.chr_chunks > 0)
594      {
595         image_fread(image, nes.vrom, nes.chr_chunks * 0x2000);
596         if (nes.mapper == 2)
597            logerror("Warning: VROM has been found in VRAM-based mapper. Either the mapper is set wrong or the ROM image is incorrect.\n");
598      }
599
600#if SPLIT_CHR
601      {
602         FILE *chrout;
603         char outname[255];
604
605         for (i = 0; i < nes.chr_chunks; i ++)
606         {
607            sprintf(outname, "%s.c%d", image_filename(image), i);
608            chrout= fopen(outname, "wb");
609            if (chrout)
610            {
611               fwrite(&nes.rom[0x10000 + 0x2000 * i], 1, 0x2000, chrout);
612               fclose(chrout);
613            }
614         }
615      }
616#endif /* SPLIT_CHR */
617
618      logerror("CHR chunks: %02x, size: %06x\n", nes.chr_chunks, 0x4000 * nes.chr_chunks);
619      logerror("**\n");
620//      printf("CHR chunks: %02x, size: %06x\n", nes.chr_chunks, 0x4000 * nes.chr_chunks);
621//      printf("**\n");
622
623      /* Attempt to load a battery file for this ROM. If successful, we */
624      /* must wait until later to move it to the system memory. */
625      if (nes.battery)
626         image_battery_load(image, battery_data, BATTERY_SIZE);
627
628   }
629   else if (!mame_stricmp(filetype, "unf"))
585630   {
586      image_fread(image, nes.vrom, nes.chr_chunks * 0x2000);
587      if (nes.mapper == 2)
588         logerror("Warning: VROM has been found in VRAM-based mapper. Either the mapper is set wrong or the ROM image is incorrect.\n");
589   }
631      UINT32 unif_ver = 0;
632      char magic2[4];
633      UINT8 buffer[4];
634      UINT32 chunk_length = 0, read_length = 0x20;
635      char unif_mapr[32];   // here we should store MAPR chunks
636      UINT32 size = image_length(image);
637      const unif *unif_board;
590638
591   logerror("CHR chunks: %02x, size: %06x\n", nes.chr_chunks, 0x4000 * nes.chr_chunks);
592   logerror("**\n");
639      /* Verify the file is in iNES format */
640      memset(magic, '\0', sizeof(magic));
641      image_fread(image, magic, 4);
593642
594   /* Attempt to load a battery file for this ROM. If successful, we */
595   /* must wait until later to move it to the system memory. */
596   if (nes.battery)
597      image_battery_load(image, battery_data, BATTERY_SIZE);
643      if ((magic[0] != 'U') || (magic[1] != 'N') || (magic[2] != 'I') || (magic[3] != 'F'))
644      {
645         logerror("%s is NOT a file in UNIF format.\n", image_filename(image));
646         return INIT_FAIL;
647      }
598648
649      image_fread(image, &buffer, 4);
650      unif_ver = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
651      logerror("UNIF file found, version %d\n", unif_ver);
652
653      if (size <= 0x20)
654      {
655         logerror("%s only contains the UNIF header and no data.\n", image_filename(image));
656         return INIT_FAIL;
657      }
658
659      do
660      {
661         image_fseek(image, read_length, SEEK_SET);
662
663         memset(magic2, '\0', sizeof(magic2));
664         image_fread(image, &magic2, 4);
665
666         /* What kind of chunk do we have here? */
667         if ((magic2[0] == 'M') && (magic2[1] == 'A') && (magic2[2] == 'P') && (magic2[3] == 'R'))
668         {
669            int i;
670            logerror("[MAPR] chunk found: ");
671            image_fread(image, &buffer, 4);
672            chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
673
674            if (chunk_length <= 0x20)
675               image_fread(image, &unif_mapr, chunk_length);
676
677            read_length += (chunk_length + 8);
678
679            unif_board = nes_unif_lookup(unif_mapr);   // this does not work atm, it's mainly a proof of concept
680
681            for(i = 0; i < chunk_length; i++)
682               logerror("%c", unif_mapr[i]);
683            logerror("\n");
684
685            if (unif_board == NULL)
686            {
687               logerror("Unsupported UNIF board.\n");
688//               return INIT_FAIL;
689            }
690         }
691         else if ((magic2[0] == 'R') && (magic2[1] == 'E') && (magic2[2] == 'A') && (magic2[3] == 'D'))
692         {
693            logerror("[READ] chunk found. No support yet.\n");
694            image_fread(image, &buffer, 4);
695            chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
696
697            read_length += (chunk_length + 8);
698         }
699         else if ((magic2[0] == 'N') && (magic2[1] == 'A') && (magic2[2] == 'M') && (magic2[3] == 'E'))
700         {
701            logerror("[NAME] chunk found. No support yet.\n");
702            image_fread(image, &buffer, 4);
703            chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
704
705            read_length += (chunk_length + 8);
706         }
707         else if ((magic2[0] == 'T') && (magic2[1] == 'V') && (magic2[2] == 'C') && (magic2[3] == 'I'))
708         {
709            logerror("[TVCI] chunk found. No support yet.\n");
710            image_fread(image, &buffer, 4);
711            chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
712
713            read_length += (chunk_length + 8);
714         }
715         else if ((magic2[0] == 'D') && (magic2[1] == 'I') && (magic2[2] == 'N') && (magic2[3] == 'F'))
716         {
717            logerror("[DINF] chunk found. No support yet.\n");
718            image_fread(image, &buffer, 4);
719            chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
720
721            read_length += (chunk_length + 8);
722         }
723         else if ((magic2[0] == 'C') && (magic2[1] == 'T') && (magic2[2] == 'R') && (magic2[3] == 'L'))
724         {
725            logerror("[CTRL] chunk found. No support yet.\n");
726            image_fread(image, &buffer, 4);
727            chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
728
729            read_length += (chunk_length + 8);
730         }
731         else if ((magic2[0] == 'B') && (magic2[1] == 'A') && (magic2[2] == 'T') && (magic2[3] == 'R'))
732         {
733            logerror("[BATR] chunk found. No support yet.\n");
734            image_fread(image, &buffer, 4);
735            chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
736
737            read_length += (chunk_length + 8);
738         }
739         else if ((magic2[0] == 'V') && (magic2[1] == 'R') && (magic2[2] == 'O') && (magic2[3] == 'R'))
740         {
741            logerror("[VROR] chunk found. No support yet.\n");
742            image_fread(image, &buffer, 4);
743            chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
744
745            read_length += (chunk_length + 8);
746         }
747         else if ((magic2[0] == 'M') && (magic2[1] == 'I') && (magic2[2] == 'R') && (magic2[3] == 'R'))
748         {
749            logerror("[MIRR] chunk found. No support yet.\n");
750            image_fread(image, &buffer, 4);
751            chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
752
753            read_length += (chunk_length + 8);
754         }
755         else if ((magic2[0] == 'P') && (magic2[1] == 'C') && (magic2[2] == 'K'))
756         {
757            logerror("[PCKx] chunk found. No support yet.\n");
758            image_fread(image, &buffer, 4);
759            chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
760
761            read_length += (chunk_length + 8);
762         }
763         else if ((magic2[0] == 'C') && (magic2[1] == 'C') && (magic2[2] == 'K'))
764         {
765            logerror("[CCKx] chunk found. No support yet.\n");
766               image_fread(image, &buffer, 4);
767            chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
768
769            read_length += (chunk_length + 8);
770         }
771         else if ((magic2[0] == 'P') && (magic2[1] == 'R') && (magic2[2] == 'G'))
772         {
773            logerror("[PRGx] chunk found. No support yet.\n");
774            image_fread(image, &buffer, 4);
775            chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
776
777            read_length += (chunk_length + 8);
778         }
779         else if ((magic2[0] == 'C') && (magic2[1] == 'H') && (magic2[2] == 'R'))
780         {
781            logerror("[CHRx] chunk found. No support yet.\n");
782            image_fread(image, &buffer, 4);
783            chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
784
785            read_length += (chunk_length + 8);
786         }
787         else
788         {
789            printf("Unsupported UNIF chunk. Please report the problem at MESS Board.\n");
790            read_length = size;
791         }
792      } while (size > read_length);
793
794   logerror("UNIF support is only very preliminary.\n");
795   return INIT_FAIL;   // if we let Unif init to pass, emulation would crash due to no PRG/CHR settings ;-)
796   }
797
599798   return INIT_PASS;
600799}
601800
src/mess/machine/nes_mmc.c
r5926r5927
1/*
1/*****************************************************************************************
2
3    NES MMC Emulation
4
5
6    MESS source file to handle various Multi-Memory Controllers (aka Mappers) used by NES carts.
7
8    Many information about the mappers below come from the wonderful doc written by Disch.
9    Current info (when used) are based on v0.6.1 of his docs.
10    You can find the latest version of the doc at http://www.romhacking.net/docs/362/
11
12
13    Known issues on specific mappers:
14
15    * 001 AD&D Hillsfar seems to be broken.
16    * 002, 003 Bus conflict?
17    * 005 has some issues (e.g. Just Breed is not working), RAM banking needs hardware flags to determine size
18    * 015 Shanghai Tycoon has corrupted graphics
19    * 016 some graphics problem (e.g. Rokudenashi Blues misses some element of graphics)
20    * 018 Pizza Pop and Plasma Ball shows graphics issues for this mapper
21    * 024, 026, 085 Registers of the additional sound hardware are not emulated
22    * 032 Major League is not properly working: check missing windows or field graphics in top view screens
23          (it requires one hack to support both boards using this mapper)
24    * 033 has still some graphics problem (e.g. missing text in Akira)
25    * 034 Impossible Mission 2 is not working
26    * 038 seems to miss inputs. separate reads?
27    * 039 Study n Game 32 in 1 misses keyboard and starts differently than in NEStopia
28    * 040 is not dealing correctly 0x6000-0x7fff (this got broken long ago)
29    * 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)
32    * 051 only half of the games work
33    * 064 has some IRQ problems - see Skull & Crossbones. Klax has broken graphics.
34    * 065 Spartan X 2 has various glitches
35    * 067 display issues, but vrom fixed
36    * 071 Fire Hawk is not properly working (it requires one hack to support both boards using this mapper)
37    * 072, 086, 092 lack samples support (maybe others as well)
38    * 074 is only preliminar (no correct CHR swap)
39    * 077 Requires 4-screen mirroring. Currently, it is very glitchy
40    * 078 Cosmo Carrier is not working (it requires one hack to support both boards using this mapper).
41          also, we lack NT mirroring
42    * 082 has chr-rom banking problems. Also mapper is in the middle of sram, which is unemulated.
43    * 083 has serious glitches
44    * 091 lacks IRQ needed by MK2
45    * 094 Bus conflict?
46    * 096 is preliminary (no correct chr switch in connection to NT)
47    * 097 Bus conflict?
48    * 104 Not all the games work
49    * 107 Are the scrolling glitches (check status bar) correct? NEStopia behaves similarly
50    * 112 Master Shooter is not working and misses some graphics
51    * 113 is not following docs (missing NT mirroring and high CHR bit)
52    * 115 (formerly 248) is preliminary
53    * 118 mirroring is a guess, chr-rom banking is likely different
54    * 143 are dancing block borders (in the intro) correct?
55    * 146 Pyramid 2 does not work
56    * 150 some problems (Magic Cubes, Mahjong Academy, others?), maybe mirroring related
57    * 152 Bus conflict?
58    * 164 preliminary - no sprites?
59    * 176 has some graphics problem
60    * 178 Fan Kong Jin Ying is not working (but not even in NEStopia)
61    * 180 Crazy Climber controller?
62    * 188 needs mic input (reads from 0x6000-0x7fff)
63    * 225 115-in-1 has glitches in the menu (games seem fine)
64    * 228 seems wrong. e.g. Action52 starts with a game rather than in the menu
65    * 229 is preliminary
66    * 230 not working yet (needs a value to flip at reset)
67    * 231 not working yet
68    * 232 has graphics glitches
69    * 241 Commandos is not working (but not even in NEStopia)
70    * 242 DQ7 is not working (it requires one hack to support both boards using this mapper)
71    * 243 has glitches in Sachen logo
72    * 255 does not really select game (same in NEStopia apparently)
73
74    Details to investigate:
75    * 034 writes to 0x8000-0xffff should not be used for NINA-001 and BNROM, only unlicensed BxROM...
76    * 144 we ignore writes to 0x8000 while NEStopia does not. is it a problem?
77    * 240 we do not map writes to 0x4020-0x40ff. is this a problem?
78
79    Remember that the MMC # does not equal the mapper #. In particular, Mapper 4 is
80    in fact MMC3, Mapper 9 is MMC2 and Mapper 10 is MMC4. Makes perfect sense, right?
81
282    TODO:
3    . 5 has some issues, RAM banking needs hardware flags to determine size
4    . 45 mapper is not fully working
5    . 51 only half of the games work
6    . 64 has some IRQ problems - see Skull & Crossbones
7    . 67 display issues, but vrom fixed
8    . 70 (ark2j) starts on round 0 - is this right? Yep!
9    . 82 has chr-rom banking problems. Also mapper is in the middle of sram, which is unemulated.
10    . 95 doesn't match documentation
11    . 96 is preliminary.
12    . 118 mirroring is a guess, chr-rom banking is likely different
13    . 164 preliminary - no sprites?
14    . 228 seems wrong
15    . 229 is preliminary
16    . 230 not working yet
17    . 232 not working yet
18    . 241 preliminary
83    - add more info
84    - complete the removal of global variable
85    - add missing mappers
1986
20    AD&D Hillsfar (mapper 1) seems to be broken. Not sure what's up there
87****************************************************************************************/
2188
22    Also, remember that the MMC does not equal the mapper #. In particular, Mapper 4 is
23    really MMC3, Mapper 9 is MMC2 and Mapper 10 is MMC4. Makes perfect sense, right?
24*/
25
89#include "driver.h"
2690#include "cpu/m6502/m6502.h"
2791#include "video/ppu2c0x.h"
28#include "driver.h"
2992#include "includes/nes.h"
3093#include "nes_mmc.h"
3194#include "sound/nes_apu.h"
3295
96#ifdef MAME_DEBUG
3397#define VERBOSE 1
98#else
99#define VERBOSE 0
100#endif
34101
35102#define LOG_MMC(x) do { if (VERBOSE) logerror x; } while (0)
36103#define LOG_FDS(x) do { if (VERBOSE) logerror x; } while (0)
r5926r5927
85152static int vrom_bank[16];
86153static int mult1, mult2;
87154
88/* Local variables */
155/* 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
160
161// FIXME: mapper specific variables should be unified as much as possible to make easier future implementation of save states
162/* Local variables (a few more are defined just before handlers that use them...) */
89163static int MMC1_Size_16k;
90164static int MMC1_High;
91165static int MMC1_reg;
r5926r5927
103177static int MMC3_chr[6];
104178static int MMC3_prg_base, MMC3_prg_mask;
105179static int MMC3_chr_base, MMC3_chr_mask;
106static int MMC3_chr_source;
107180UINT8* extended_ntram;
108181
109182static int MMC5_rom_bank_mode;
r5926r5927
115188UINT8 MMC5_vram[0x400];
116189int MMC5_vram_control;
117190
118static int mapper41_chr, mapper41_reg2;
119
120static int mapper154_reg;
121
122191static int mapper45_data[4], mapper45_cmd;
123192
124193static int mapper64_data[0x10], mapper64_cmd;
r5926r5927
130199
131200static emu_timer   *nes_irq_timer;
132201
133static void set_nt_page(int page, int source, int bank, int writable);
134202
135static TIMER_CALLBACK(nes_irq_callback)
203/*************************************************************
204
205    Base emulation (see drivers/nes.c):
206    memory 0x0000-0x1fff RAM
207           0x2000-0x3fff PPU
208           0x4000-0x4017 APU
209           0x4018-0x5fff Expansion Area
210           0x6000-0x7fff SRAM
211           0x8000-0xffff PRG ROM
212
213    nes_chr_r/w take care of RAM, nes_nt_r/w take care of PPU.
214    for mapper specific emulation, we generically setup the
215    following handlers:
216    - nes_low_mapper_r/w take care of accesses to 0x4100-0x5fff
217    - nes_mid_mapper_r/w take care of accesses to 0x6000-0x7fff
218    - nes_mapper_w takes care of writes to 0x8000-0xffff
219    some mappers may access 0x4018-0x4100: this must be taken
220    care separately in init_nes_core (see e.g. mapper 40)
221
222*************************************************************/
223
224static TIMER_CALLBACK( nes_irq_callback )
136225{
137226   cputag_set_input_line(machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
138227   timer_adjust_oneshot(nes_irq_timer, attotime_never, 0);
r5926r5927
193282   }
194283}
195284
196/* Handle mapper reads from $4100-$5fff */
197285READ8_HANDLER( nes_low_mapper_r )
198286{
199287   if (mmc_read_low)
r5926r5927
259347   }
260348}
261349
262/*
263 * Some helpful routines used by the mappers
264 */
265350
266static void ppu_mirror_MMC5( int page, int src )
351/*************************************************************
352
353    Helpers to handle MMC
354
355*************************************************************/
356
357/* PRG ROM in 8K, 16K or 32K blocks */
358
359static void prg32( running_machine *machine, int bank )
267360{
268   switch (src)
361   /* assumes that bank references a 32k chunk */
362   bank &= ((nes.prg_chunks >> 1) - 1);
363   if (nes.slow_banking)
364      memcpy(&nes.rom[0x8000], &nes.rom[bank * 0x8000 + 0x10000], 0x8000);
365   else
269366   {
270   case 0:   /* CIRAM0 */
271      set_nt_page(page, CIRAM, 0, 1);
272      break;
273   case 1:   /* CIRAM1 */
274      set_nt_page(page, CIRAM, 1, 1);
275      break;
276   case 2:   /* ExRAM */
277      set_nt_page(page, EXRAM, 0, 1);   // actually only works during rendering.
278      break;
279   case 3: /* Fill Registers */
280      set_nt_page(page, MMC5FILL, 0, 0);
281      break;
282   default:
283      fatalerror("This should never happen");
284      break;
367      memory_set_bankptr(machine, 1, &nes.rom[bank * 0x8000 + 0x10000]);
368      memory_set_bankptr(machine, 2, &nes.rom[bank * 0x8000 + 0x12000]);
369      memory_set_bankptr(machine, 3, &nes.rom[bank * 0x8000 + 0x14000]);
370      memory_set_bankptr(machine, 4, &nes.rom[bank * 0x8000 + 0x16000]);
285371   }
286372}
287373
288static void ppu_mirror_custom_vrom( int page, int address )
374static void prg16_89ab( running_machine *machine, int bank )
289375{
290   set_nt_page(page, ROM, address, 0);
376   /* assumes that bank references a 16k chunk */
377   bank &= (nes.prg_chunks - 1);
378   if (nes.slow_banking)
379      memcpy(&nes.rom[0x8000], &nes.rom[bank * 0x4000 + 0x10000], 0x4000);
380   else
381   {
382      memory_set_bankptr(machine, 1, &nes.rom[bank * 0x4000 + 0x10000]);
383      memory_set_bankptr(machine, 2, &nes.rom[bank * 0x4000 + 0x12000]);
384   }
291385}
292386
387static void prg16_cdef( running_machine *machine, int bank )
388{
389   /* assumes that bank references a 16k chunk */
390   bank &= (nes.prg_chunks - 1);
391   if (nes.slow_banking)
392      memcpy(&nes.rom[0xc000], &nes.rom[bank * 0x4000 + 0x10000], 0x4000);
393   else
394   {
395      memory_set_bankptr(machine, 3, &nes.rom[bank * 0x4000 + 0x10000]);
396      memory_set_bankptr(machine, 4, &nes.rom[bank * 0x4000 + 0x12000]);
397   }
398}
399
293400static void prg8_89( running_machine *machine, int bank )
294401{
295402   /* assumes that bank references an 8k chunk */
296403   bank &= ((nes.prg_chunks << 1) - 1);
297404   if (nes.slow_banking)
298      memcpy (&nes.rom[0x8000], &nes.rom[bank * 0x2000 + 0x10000], 0x2000);
405      memcpy(&nes.rom[0x8000], &nes.rom[bank * 0x2000 + 0x10000], 0x2000);
299406   else
300407      memory_set_bankptr(machine, 1, &nes.rom[bank * 0x2000 + 0x10000]);
301408}
r5926r5927
305412   /* assumes that bank references an 8k chunk */
306413   bank &= ((nes.prg_chunks << 1) - 1);
307414   if (nes.slow_banking)
308      memcpy (&nes.rom[0xa000], &nes.rom[bank * 0x2000 + 0x10000], 0x2000);
415      memcpy(&nes.rom[0xa000], &nes.rom[bank * 0x2000 + 0x10000], 0x2000);
309416   else
310417      memory_set_bankptr(machine, 2, &nes.rom[bank * 0x2000 + 0x10000]);
311418}
r5926r5927
315422   /* assumes that bank references an 8k chunk */
316423   bank &= ((nes.prg_chunks << 1) - 1);
317424   if (nes.slow_banking)
318      memcpy (&nes.rom[0xc000], &nes.rom[bank * 0x2000 + 0x10000], 0x2000);
425      memcpy(&nes.rom[0xc000], &nes.rom[bank * 0x2000 + 0x10000], 0x2000);
319426   else
320427      memory_set_bankptr(machine, 3, &nes.rom[bank * 0x2000 + 0x10000]);
321428}
r5926r5927
325432   /* assumes that bank references an 8k chunk */
326433   bank &= ((nes.prg_chunks << 1) - 1);
327434   if (nes.slow_banking)
328      memcpy (&nes.rom[0xe000], &nes.rom[bank * 0x2000 + 0x10000], 0x2000);
435      memcpy(&nes.rom[0xe000], &nes.rom[bank * 0x2000 + 0x10000], 0x2000);
329436   else
330437      memory_set_bankptr(machine, 4, &nes.rom[bank * 0x2000 + 0x10000]);
331438}
332439
333static void prg16_89ab( running_machine *machine, int bank )
334{
335   /* assumes that bank references a 16k chunk */
336   bank &= (nes.prg_chunks - 1);
337   if (nes.slow_banking)
338      memcpy (&nes.rom[0x8000], &nes.rom[bank * 0x4000 + 0x10000], 0x4000);
339   else
340   {
341      memory_set_bankptr(machine, 1, &nes.rom[bank * 0x4000 + 0x10000]);
342      memory_set_bankptr(machine, 2, &nes.rom[bank * 0x4000 + 0x12000]);
343   }
344}
440/* CHR ROM in 1K, 2K, 4K or 8K blocks */
345441
346static void prg16_cdef( running_machine *machine, int bank )
347{
348   /* assumes that bank references a 16k chunk */
349   bank &= (nes.prg_chunks - 1);
350   if (nes.slow_banking)
351      memcpy (&nes.rom[0xc000], &nes.rom[bank * 0x4000 + 0x10000], 0x4000);
352   else
353   {
354      memory_set_bankptr(machine, 3, &nes.rom[bank * 0x4000 + 0x10000]);
355      memory_set_bankptr(machine, 4, &nes.rom[bank * 0x4000 + 0x12000]);
356   }
357}
358
359static void prg32( running_machine *machine, int bank )
360{
361   /* assumes that bank references a 32k chunk */
362   bank &= ((nes.prg_chunks >> 1) - 1);
363   if (nes.slow_banking)
364      memcpy (&nes.rom[0x8000], &nes.rom[bank * 0x8000 + 0x10000], 0x8000);
365   else
366   {
367      memory_set_bankptr(machine, 1, &nes.rom[bank * 0x8000 + 0x10000]);
368      memory_set_bankptr(machine, 2, &nes.rom[bank * 0x8000 + 0x12000]);
369      memory_set_bankptr(machine, 3, &nes.rom[bank * 0x8000 + 0x14000]);
370      memory_set_bankptr(machine, 4, &nes.rom[bank * 0x8000 + 0x16000]);
371   }
372}
373
374static void set_nt_page( int page, int source, int bank, int writable )
375{
376   UINT8* base_ptr;
377
378   switch (source)
379   {
380      case CART_NTRAM:
381         base_ptr = extended_ntram;
382         break;
383      case MMC5FILL:
384         base_ptr = NULL;
385         break;
386      case ROM:
387         base_ptr = nes.vrom;
388         break;
389      case EXRAM:
390         base_ptr = MMC5_vram;
391         break;
392      case CIRAM:
393      default:
394         base_ptr = nes.ciram;
395         break;
396   }
397
398   page &= 3; /* mask down to the 4 logical pages */
399   nt_page[page].source = source;
400   if(NULL != base_ptr)
401   {
402      nt_page[page].origin = bank * 0x400;
403      nt_page[page].access = base_ptr + nt_page[page].origin;
404   }
405   nt_page[page].writable = writable;
406}
407
408void set_nt_mirroring( int mirroring )
409{
410   /* setup our videomem handlers based on mirroring */
411   switch (mirroring)
412   {
413      case PPU_MIRROR_VERT:
414         set_nt_page(0, CIRAM, 0, 1);
415         set_nt_page(1, CIRAM, 1, 1);
416         set_nt_page(2, CIRAM, 0, 1);
417         set_nt_page(3, CIRAM, 1, 1);
418         break;
419
420      case PPU_MIRROR_HORZ:
421         set_nt_page(0, CIRAM, 0, 1);
422         set_nt_page(1, CIRAM, 0, 1);
423         set_nt_page(2, CIRAM, 1, 1);
424         set_nt_page(3, CIRAM, 1, 1);
425         break;
426
427      case PPU_MIRROR_HIGH:
428         set_nt_page(0, CIRAM, 1, 1);
429         set_nt_page(1, CIRAM, 1, 1);
430         set_nt_page(2, CIRAM, 1, 1);
431         set_nt_page(3, CIRAM, 1, 1);
432         break;
433
434      case PPU_MIRROR_LOW:
435         set_nt_page(0, CIRAM, 0, 1);
436         set_nt_page(1, CIRAM, 0, 1);
437         set_nt_page(2, CIRAM, 0, 1);
438         set_nt_page(3, CIRAM, 0, 1);
439         break;
440
441      case PPU_MIRROR_NONE:
442      case PPU_MIRROR_4SCREEN:
443      default:
444         /* external RAM needs to be used somehow. */
445         /* but as a default, we'll arbitrarily set vertical so as not to crash*/
446         /* mappers should use set_nt_page and assign which pages are which */
447
448         logerror("Mapper set 4-screen mirroring without supplying external nametable memory!\n");
449
450         set_nt_page(0, CIRAM, 0, 1);
451         set_nt_page(1, CIRAM, 0, 1);
452         set_nt_page(2, CIRAM, 1, 1);
453         set_nt_page(3, CIRAM, 1, 1);
454         break;
455   }
456}
457
458442static void chr8( running_machine *machine, int bank, int source )
459443{
460444   int i;
r5926r5927
589573}
590574
591575
576/* NameTable paging and mirroring */
577
578static void set_nt_page( int page, int source, int bank, int writable )
579{
580   UINT8* base_ptr;
581
582   switch (source)
583   {
584      case CART_NTRAM:
585         base_ptr = extended_ntram;
586         break;
587      case MMC5FILL:
588         base_ptr = NULL;
589         break;
590      case ROM:
591         base_ptr = nes.vrom;
592         break;
593      case EXRAM:
594         base_ptr = MMC5_vram;
595         break;
596      case CIRAM:
597      default:
598         base_ptr = nes.ciram;
599         break;
600   }
601
602   page &= 3; /* mask down to the 4 logical pages */
603   nt_page[page].source = source;
604   if (NULL != base_ptr)
605   {
606      nt_page[page].origin = bank * 0x400;
607      nt_page[page].access = base_ptr + nt_page[page].origin;
608   }
609   nt_page[page].writable = writable;
610}
611
612void set_nt_mirroring( int mirroring )
613{
614   /* setup our videomem handlers based on mirroring */
615   switch (mirroring)
616   {
617      case PPU_MIRROR_VERT:
618         set_nt_page(0, CIRAM, 0, 1);
619         set_nt_page(1, CIRAM, 1, 1);
620         set_nt_page(2, CIRAM, 0, 1);
621         set_nt_page(3, CIRAM, 1, 1);
622         break;
623
624      case PPU_MIRROR_HORZ:
625         set_nt_page(0, CIRAM, 0, 1);
626         set_nt_page(1, CIRAM, 0, 1);
627         set_nt_page(2, CIRAM, 1, 1);
628         set_nt_page(3, CIRAM, 1, 1);
629         break;
630
631      case PPU_MIRROR_HIGH:
632         set_nt_page(0, CIRAM, 1, 1);
633         set_nt_page(1, CIRAM, 1, 1);
634         set_nt_page(2, CIRAM, 1, 1);
635         set_nt_page(3, CIRAM, 1, 1);
636         break;
637
638      case PPU_MIRROR_LOW:
639         set_nt_page(0, CIRAM, 0, 1);
640         set_nt_page(1, CIRAM, 0, 1);
641         set_nt_page(2, CIRAM, 0, 1);
642         set_nt_page(3, CIRAM, 0, 1);
643         break;
644
645      case PPU_MIRROR_NONE:
646      case PPU_MIRROR_4SCREEN:
647      default:
648         /* external RAM needs to be used somehow. */
649         /* but as a default, we'll arbitrarily set vertical so as not to crash*/
650         /* mappers should use set_nt_page and assign which pages are which */
651
652         logerror("Mapper set 4-screen mirroring without supplying external nametable memory!\n");
653
654         set_nt_page(0, CIRAM, 0, 1);
655         set_nt_page(1, CIRAM, 0, 1);
656         set_nt_page(2, CIRAM, 1, 1);
657         set_nt_page(3, CIRAM, 1, 1);
658         break;
659   }
660}
661
662/*  Other custom mirroring helpers are defined below: Waixing games use waixing_set_mirror (which swaps
663    MIRROR_HIGH and MIRROR_LOW compared to the above) and Sachen games use sachen_set_mirror (which has
664    a slightly different MIRROR_HIGH, with page 0 set to 0) */
665
666
667/*************************************************************
668
669    Mapper 0
670
671    32K PRG ROM + 8K or less CHR ROM
672    No need of additional MMC
673
674    Known Boards: NROM, FB02??, FB04??, Jaleco JF01, JF02, JF03, JF04
675    Games: Mario Bros., Super Mario Bros., Tennis and most of
676          the first generation games
677
678    In MESS: Supported, no need of specific handlers or IRQ
679
680*************************************************************/
681
682/*************************************************************
683
684    Mapper 1
685
686    Known Boards: MMC1 based Boards, i.e. SAROM, SBROM, SCROM,
687          SEROM, SFROM, SGROM, SHROM, SJROM, SKROM, SLROM, SNROM,
688          SOROM, SUROM, SXROM, WH??
689    Games: Faxanadu, Final Fantasy I & II, Kid Icarus, Legend
690          of Zelda, Metroid
691
692    In MESS: Supported
693
694*************************************************************/
695
592696static WRITE8_HANDLER( mapper1_w )
593697{
594698   int reg;
r5926r5927
621725
622726   if (MMC1_reg_count == 5)
623727   {
624//      logerror("   MMC1 reg#%02x val:%02x\n", offset, MMC1_reg);
728//      LOG_MMC(("   MMC1 reg#%02x val:%02x\n", offset, MMC1_reg));
625729      switch (reg)
626730      {
627731         case 0:
r5926r5927
699803            }
700804            else if (nes.chr_chunks > 0)
701805            {
702//                  logerror("MMC1_SizeVrom_4k: %02x bank:%02x\n", MMC1_SizeVrom_4k, MMC1_reg);
806//                  LOG_MMC(("MMC1_SizeVrom_4k: %02x bank:%02x\n", MMC1_SizeVrom_4k, MMC1_reg));
703807
704808               if (!MMC1_SizeVrom_4k)
705809               {
r5926r5927
718822            }
719823            break;
720824         case 2:
721//              logerror("MMC1_Reg_2: %02x\n",MMC1_Reg_2);
825//              LOG_MMC(("MMC1_Reg_2: %02x\n",MMC1_Reg_2));
722826            MMC1_extended_bank = (MMC1_extended_bank & ~0x02) | ((MMC1_reg & 0x10) >> 3);
723827            if (MMC1_extended == 2 && MMC1_SizeVrom_4k)
724828            {
r5926r5927
815919   }
816920}
817921
922/*************************************************************
923
924    Mapper 2
925
926    Known Boards: UNROM, UOROM, UXROM, Jaleco JF15, JF18 & JF39
927    Games: Castlevania, Dragon Quest II, Duck Tales, MegaMan, Metal Gear
928
929    In MESS: Supported
930
931*************************************************************/
932
818933static WRITE8_HANDLER( mapper2_w )
819934{
820935   prg16_89ab(space->machine, data);
821936}
822937
938/*************************************************************
939
940    Mapper 3
941
942    Known Boards: CNROM, CXROM, X79B?, Bandai Aerobics Board,
943          Tengen 800008, Bootleg Board by NTDEC (N715062)
944    Games: Adventure Island, Flipull, Friday 13th, GeGeGe no
945          Kitarou, Ghostbusters, Gradius, Hokuto no Ken, Milon's
946          Secret Castle
947
948    In MESS: Supported
949
950*************************************************************/
951
823952static WRITE8_HANDLER( mapper3_w )
824953{
825954   chr8(space->machine, data, CHRROM);
826955}
827956
957/*************************************************************
958
959    Mapper 4
960
961    Known Boards: MMC3 based Boards, i.e. HKROM, TEROM, TBROM,
962          TFROM, TGROM, TKROM, TLROM, TNROM, TR1ROM, TSROM,
963          TVROM, TRXROM
964    Games: Final Fantasy III, MegaMan 3,4,5 & 6, Startropics,
965          Super Mario Bros. 2 & 3,
966
967    In MESS: Supported
968
969*************************************************************/
970
828971static void mapper4_set_prg( running_machine *machine )
829972{
830973   int prg0_bank = MMC3_prg_base | (MMC3_prg0 & MMC3_prg_mask);
r5926r5927
8721015
8731016      if (IRQ_enable && !blanked && (IRQ_count == 0) && priorCount)
8741017      {
875         logerror("irq fired, scanline: %d (MAME %d, beam pos: %d)\n", scanline, video_screen_get_vpos(device->machine->primary_screen), video_screen_get_hpos(device->machine->primary_screen));
1018         LOG_MMC(("irq fired, scanline: %d (MAME %d, beam pos: %d)\n", scanline,
1019               video_screen_get_vpos(device->machine->primary_screen), video_screen_get_hpos(device->machine->primary_screen)));
8761020         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
8771021//          timer_adjust_oneshot(nes_irq_timer, cputag_clocks_to_attotime(device->machine, "maincpu", 4), 0);
8781022      }
r5926r5927
8831027{
8841028   static UINT8 last_bank = 0xff;
8851029
886//  logerror("mapper4_w offset: %04x, data: %02x, scanline: %d\n", offset, data, current_scanline);
1030//  LOG_MMC(("mapper4_w offset: %04x, data: %02x, scanline: %d\n", offset, data, current_scanline));
8871031
8881032   //only bits 14,13, and 0 matter for offset!
8891033   switch (offset & 0x6001)
r5926r5927
8961040         {
8971041            /* Reset the banks */
8981042            mapper4_set_prg(space->machine);
899            mapper4_set_chr(space->machine, MMC3_chr_source);
1043            mapper4_set_chr(space->machine, mmc_chr_source);
9001044            LOG_MMC(("     MMC3 reset banks\n"));
9011045         }
9021046         last_bank = data & 0xc0;
r5926r5927
9101054            case 0: case 1:
9111055               data &= 0xfe;
9121056               MMC3_chr[cmd] = data;
913               mapper4_set_chr(space->machine, MMC3_chr_source);
1057               mapper4_set_chr(space->machine, mmc_chr_source);
9141058               LOG_MMC(("     MMC3 set vram %d: %d\n", cmd, data));
9151059               break;
9161060
9171061            case 2: case 3: case 4: case 5:
9181062               MMC3_chr[cmd] = data;
919               mapper4_set_chr(space->machine, MMC3_chr_source);
1063               mapper4_set_chr(space->machine, mmc_chr_source);
9201064               LOG_MMC(("     MMC3 set vram %d: %d\n", cmd, data));
9211065               break;
9221066
r5926r5927
9751119   }
9761120}
9771121
978static WRITE8_HANDLER( mapper118_w )
979{
980   static UINT8 last_bank = 0xff;
1122/*************************************************************
9811123
982//  logerror("mapper4_w offset: %04x, data: %02x, scanline: %d\n", offset, data, current_scanline);
1124    Mapper 5
9831125
984   //uses just bits 14, 13, and 0
985   switch (offset & 0x6001)
986   {
987      case 0x0000: /* $8000 */
988         MMC3_cmd = data;
1126    Known Boards:  MMC3 based Boards, i.e. ELROM, EKROM, ETROM,
1127          EWROM and EXROM variants
1128    Games: Castlevania III, Just Breed, many Koei titles
9891129
990         /* Toggle between switching $8000 and $c000 */
991         if (last_bank != (data & 0xc0))
992         {
993            /* Reset the banks */
994            mapper4_set_prg(space->machine);
995            mapper4_set_chr(space->machine, MMC3_chr_source);
996         }
997         last_bank = data & 0xc0;
998         break;
1130    In MESS: Partially supported
9991131
1000      case 0x0001: /* $8001 */
1001      {
1002         UINT8 cmd = MMC3_cmd & 0x07;
1003         switch (cmd)
1004         {
1005            case 0: case 1:
1006               data &= 0xfe;
1007               MMC3_chr[cmd] = data;
1008               mapper4_set_chr(space->machine, MMC3_chr_source);
1009               break;
1132*************************************************************/
10101133
1011            case 2: case 3: case 4: case 5:
1012               MMC3_chr[cmd] = data;
1013               mapper4_set_chr(space->machine, MMC3_chr_source);
1014               break;
1015
1016            case 6:
1017               MMC3_prg0 = data;
1018               mapper4_set_prg(space->machine);
1019               break;
1020
1021            case 7:
1022               MMC3_prg1 = data;
1023               mapper4_set_prg(space->machine);
1024               break;
1025         }
1026         break;
1027      }
1028      case 0x2000: /* $a000 */
1029         LOG_MMC(("     mapper 118 mirroring: %02x\n", data));
1030         switch (data & 0x02)
1031         {
1032            case 0x00: set_nt_mirroring(PPU_MIRROR_LOW); break;
1033            case 0x01: set_nt_mirroring(PPU_MIRROR_LOW); break;
1034         }
1035         break;
1036
1037      case 0x2001: /* $a001 - extra RAM enable/disable */
1038         nes.mid_ram_enable = data;
1039         LOG_MMC(("     MMC3 mid_ram enable: %02x\n", data));
1040         break;
1041
1042      case 0x4000: /* $c000 - IRQ scanline counter */
1043         IRQ_count = data;
1044         LOG_MMC(("     MMC3 set irq count: %02x\n", data));
1045         break;
1046
1047      case 0x4001: /* $c001 - IRQ scanline latch */
1048         IRQ_count_latch = data;
1049         LOG_MMC(("     MMC3 set irq count latch: %02x\n", data));
1050         break;
1051
1052      case 0x6000: /* $e000 - Disable IRQs */
1053         IRQ_enable = 0;
1054         IRQ_count = IRQ_count_latch; /* TODO: verify this */
1055         LOG_MMC(("     MMC3 disable irqs: %02x\n", data));
1056         break;
1057
1058      case 0x6001: /* $e001 - Enable IRQs */
1059         IRQ_enable = 1;
1060         LOG_MMC(("     MMC3 enable irqs: %02x\n", data));
1061         break;
1062
1063      default:
1064         logerror("mapper4_w uncaught: %04x value: %02x\n", offset + 0x8000, data);
1065         break;
1066   }
1067}
1068
1069
1070static void mapper119_set_chr( running_machine *machine )
1071{
1072   UINT8 chr_page = (MMC3_cmd & 0x80) >> 5;
1073   if (MMC3_chr[0] & 0x40)
1074      chr2_x(machine, chr_page ^ 0, (MMC3_chr[0] >> 1) & 0x03, CHRRAM);
1075   else
1076      chr2_x(machine, chr_page ^ 0, ((MMC3_chr[0] & 0x3f) >> 1), CHRROM);
1077
1078   if (MMC3_chr[1] & 0x40)
1079      chr2_x(machine, chr_page ^ 2, (MMC3_chr[1] >> 1) & 0x03, CHRRAM);
1080   else
1081      chr2_x(machine, chr_page ^ 2, ((MMC3_chr[1] & 0x3f) >> 1), CHRROM);
1082
1083   if (MMC3_chr[2] & 0x40)
1084      chr1_x(machine, chr_page ^ 4, MMC3_chr[2] & 0x07, CHRRAM);
1085   else
1086      chr1_x(machine, chr_page ^ 4, MMC3_chr[2] & 0x3f, CHRROM);
1087
1088   if (MMC3_chr[3] & 0x40)
1089      chr1_x(machine, chr_page ^ 5, MMC3_chr[3] & 0x07, CHRRAM);
1090   else
1091      chr1_x(machine, chr_page ^ 5, MMC3_chr[3] & 0x3f, CHRROM);
1092
1093   if (MMC3_chr[4] & 0x40)
1094      chr1_x(machine, chr_page ^ 6, MMC3_chr[4] & 0x07, CHRRAM);
1095   else
1096      chr1_x(machine, chr_page ^ 6, MMC3_chr[4] & 0x3f, CHRROM);
1097
1098   if (MMC3_chr[5] & 0x40)
1099      chr1_x(machine, chr_page ^ 7, MMC3_chr[5] & 0x07, CHRRAM);
1100   else
1101      chr1_x(machine, chr_page ^ 7, MMC3_chr[5] & 0x3f, CHRROM);
1102}
1103
1104static WRITE8_HANDLER( mapper119_w )
1105{
1106   static UINT8 last_bank = 0xff;
1107
1108//  logerror("mapper4_w offset: %04x, data: %02x, scanline: %d\n", offset, data, current_scanline);
1109
1110   //only bits 14,13, and 0 matter for offset!
1111   switch (offset & 0x6001)
1112   {
1113      case 0x0000: /* $8000 */
1114         MMC3_cmd = data;
1115
1116         /* Toggle between switching $8000 and $c000 */
1117         if (last_bank != (data & 0xc0))
1118         {
1119            /* Reset the banks */
1120            mapper4_set_prg(space->machine);
1121            mapper119_set_chr(space->machine);
1122            LOG_MMC(("     MMC3 reset banks\n"));
1123         }
1124         last_bank = data & 0xc0;
1125         break;
1126
1127      case 0x0001: /* $8001 */
1128      {
1129         UINT8 cmd = MMC3_cmd & 0x07;
1130         switch (cmd)
1131         {
1132            case 0: case 1:
1133               MMC3_chr[cmd] = data;
1134               mapper119_set_chr(space->machine);
1135               LOG_MMC(("     MMC3 set vram %d: %d\n", cmd, data));
1136               break;
1137
1138            case 2: case 3: case 4: case 5:
1139               MMC3_chr[cmd] = data;
1140               mapper119_set_chr(space->machine);
1141               LOG_MMC(("     MMC3 set vram %d: %d\n", cmd, data));
1142               break;
1143
1144            case 6:
1145               MMC3_prg0 = data;
1146               mapper4_set_prg(space->machine);
1147               break;
1148
1149            case 7:
1150               MMC3_prg1 = data;
1151               mapper4_set_prg(space->machine);
1152               break;
1153         }
1154         break;
1155      }
1156      case 0x2000: /* $a000 */
1157         if (data & 0x40)
1158            set_nt_mirroring(PPU_MIRROR_HIGH);
1159         else
1160         {
1161            if (data & 0x01)
1162               set_nt_mirroring(PPU_MIRROR_HORZ);
1163            else
1164               set_nt_mirroring(PPU_MIRROR_VERT);
1165         }
1166         break;
1167
1168      case 0x2001: /* $a001 - extra RAM enable/disable */
1169         nes.mid_ram_enable = data;
1170         LOG_MMC(("     MMC3 mid_ram enable: %02x\n", 0));
1171         break;
1172
1173      case 0x4000: /* $c000 - IRQ scanline counter */
1174         IRQ_count_latch = data;
1175//          LOG_MMC(("     MMC3 set irq count latch: %02x (scanline %d)\n", data, ppu2c0x_get_current_scanline(0)));
1176         break;
1177
1178      case 0x4001: /* $c001 - IRQ scanline latch */
1179         IRQ_reload = 1;
1180//          LOG_MMC(("     MMC3 set irq reload (scanline %d)\n", ppu2c0x_get_current_scanline(0)));
1181         break;
1182
1183      case 0x6000: /* $e000 - Disable IRQs */
1184         IRQ_enable = 0;
1185         LOG_MMC(("     MMC3 disable irqs\n"));
1186         break;
1187
1188      case 0x6001: /* $e001 - Enable IRQs */
1189         IRQ_enable = 1;
1190         LOG_MMC(("     MMC3 enable irqs\n"));
1191         break;
1192
1193      default:
1194         logerror("mapper119_w uncaught: %04x value: %02x\n", offset + 0x8000, data);
1195         break;
1196   }
1197}
1198
1199
12001134static void mapper5_irq( const device_config *device, int scanline, int vblank, int blanked )
12011135{
12021136#if 1
r5926r5927
12151149   }
12161150}
12171151
1152static void ppu_mirror_MMC5( int page, int src )
1153{
1154   switch (src)
1155   {
1156   case 0:   /* CIRAM0 */
1157      set_nt_page(page, CIRAM, 0, 1);
1158      break;
1159   case 1:   /* CIRAM1 */
1160      set_nt_page(page, CIRAM, 1, 1);
1161      break;
1162   case 2:   /* ExRAM */
1163      set_nt_page(page, EXRAM, 0, 1);   // actually only works during rendering.
1164      break;
1165   case 3: /* Fill Registers */
1166      set_nt_page(page, MMC5FILL, 0, 0);
1167      break;
1168   default:
1169      fatalerror("This should never happen");
1170      break;
1171   }
1172}
1173
12181174static READ8_HANDLER( mapper5_l_r )
12191175{
12201176   int retVal;
r5926r5927
12661222   static int vrom_page_a;
12671223   static int vrom_page_b;
12681224
1269//  logerror("Mapper 5 write, offset: %04x, data: %02x\n", offset + 0x4100, data);
1225//  LOG_MMC(("Mapper 5 write, offset: %04x, data: %02x\n", offset + 0x4100, data));
12701226   /* Send $5000-$5015 to the sound chip */
12711227   if ((offset >= 0xf00) && (offset <= 0xf15))
12721228   {
r5926r5927
12861242   {
12871243      case 0x1000: /* $5100 */
12881244         MMC5_rom_bank_mode = data & 0x03;
1289         logerror ("MMC5 rom bank mode: %02x\n", data);
1245         LOG_MMC(("MMC5 rom bank mode: %02x\n", data));
12901246         break;
12911247
12921248      case 0x1001: /* $5101 */
12931249         MMC5_vrom_bank_mode = data & 0x03;
1294         logerror ("MMC5 vrom bank mode: %02x\n", data);
1250         LOG_MMC(("MMC5 vrom bank mode: %02x\n", data));
12951251         break;
12961252
12971253      case 0x1002: /* $5102 */
r5926r5927
12991255            MMC5_vram_protect |= 1;
13001256         else
13011257            MMC5_vram_protect = 0;
1302         logerror ("MMC5 vram protect 1: %02x\n", data);
1258         LOG_MMC(("MMC5 vram protect 1: %02x\n", data));
13031259         break;
13041260      case 0x1003: /* 5103 */
13051261         if (data == 0x01)
13061262            MMC5_vram_protect |= 2;
13071263         else
13081264            MMC5_vram_protect = 0;
1309         logerror ("MMC5 vram protect 2: %02x\n", data);
1265         LOG_MMC(("MMC5 vram protect 2: %02x\n", data));
13101266         break;
13111267
13121268      case 0x1004: /* $5104 - Extra VRAM (EXRAM) control */
13131269         MMC5_vram_control = data;
1314         logerror ("MMC5 exram control: %02x\n", data);
1270         LOG_MMC(("MMC5 exram control: %02x\n", data));
13151271         break;
13161272
13171273      case 0x1005: /* $5105 */
1318         ppu_mirror_MMC5 (0, data & 0x03);
1319         ppu_mirror_MMC5 (1, (data & 0x0c) >> 2);
1320         ppu_mirror_MMC5 (2, (data & 0x30) >> 4);
1321         ppu_mirror_MMC5 (3, (data & 0xc0) >> 6);
1274         ppu_mirror_MMC5(0, data & 0x03);
1275         ppu_mirror_MMC5(1, (data & 0x0c) >> 2);
1276         ppu_mirror_MMC5(2, (data & 0x30) >> 4);
1277         ppu_mirror_MMC5(3, (data & 0xc0) >> 6);
13221278         break;
13231279
13241280      /* tile data for MMC5 flood-fill NT mode */
r5926r5927
13391295         break;
13401296
13411297      case 0x1013: /* $5113 */
1342         logerror ("MMC5 mid RAM bank select: %02x\n", data & 0x07);
1298         LOG_MMC(("MMC5 mid RAM bank select: %02x\n", data & 0x07));
13431299         memory_set_bankptr(space->machine, 5, &nes.wram[data * 0x2000]);
13441300         /* The & 4 is a hack that'll tide us over for now */
13451301         nes_battery_ram = &nes.wram[(data & 4) * 0x2000];
13461302         break;
13471303
13481304      case 0x1014: /* $5114 */
1349         logerror ("MMC5 $5114 bank select: %02x (mode: %d)\n", data, MMC5_rom_bank_mode);
1305         LOG_MMC(("MMC5 $5114 bank select: %02x (mode: %d)\n", data, MMC5_rom_bank_mode));
13501306         switch (MMC5_rom_bank_mode)
13511307         {
13521308            case 0x03:
r5926r5927
13541310               if (data & 0x80)
13551311               {
13561312                  /* ROM */
1357                  logerror ("\tROM bank select (8k, $8000): %02x\n", data);
1313                  LOG_MMC(("\tROM bank select (8k, $8000): %02x\n", data));
13581314                  data &= ((nes.prg_chunks << 1) - 1);
13591315                  memory_set_bankptr(space->machine, 1, &nes.rom[data * 0x2000 + 0x10000]);
13601316               }
13611317               else
13621318               {
13631319                  /* RAM */
1364                  logerror ("\tRAM bank select (8k, $8000): %02x\n", data & 0x07);
1320                  LOG_MMC(("\tRAM bank select (8k, $8000): %02x\n", data & 0x07));
13651321                  /* The & 4 is a hack that'll tide us over for now */
13661322                  memory_set_bankptr(space->machine, 1, &nes.wram[(data & 4) * 0x2000]);
13671323               }
r5926r5927
13691325         }
13701326         break;
13711327      case 0x1015: /* $5115 */
1372         logerror ("MMC5 $5115 bank select: %02x (mode: %d)\n", data, MMC5_rom_bank_mode);
1328         LOG_MMC(("MMC5 $5115 bank select: %02x (mode: %d)\n", data, MMC5_rom_bank_mode));
13731329         switch (MMC5_rom_bank_mode)
13741330         {
13751331            case 0x01:
r5926r5927
13821338               else
13831339               {
13841340                  /* RAM */
1385                  logerror ("\tRAM bank select (16k, $8000): %02x\n", data & 0x07);
1341                  LOG_MMC(("\tRAM bank select (16k, $8000): %02x\n", data & 0x07));
13861342                  /* The & 4 is a hack that'll tide us over for now */
13871343                  memory_set_bankptr(space->machine, 1, &nes.wram[((data & 4) >> 1) * 0x4000]);
13881344                  memory_set_bankptr(space->machine, 2, &nes.wram[((data & 4) >> 1) * 0x4000 + 0x2000]);
r5926r5927
13991355               else
14001356               {
14011357                  /* RAM */
1402                  logerror ("\tRAM bank select (8k, $a000): %02x\n", data & 0x07);
1358                  LOG_MMC(("\tRAM bank select (8k, $a000): %02x\n", data & 0x07));
14031359                  /* The & 4 is a hack that'll tide us over for now */
14041360                  memory_set_bankptr(space->machine, 2, &nes.wram[(data & 4) * 0x2000]);
14051361               }
r5926r5927
14071363         }
14081364         break;
14091365      case 0x1016: /* $5116 */
1410         logerror ("MMC5 $5116 bank select: %02x (mode: %d)\n", data, MMC5_rom_bank_mode);
1366         LOG_MMC(("MMC5 $5116 bank select: %02x (mode: %d)\n", data, MMC5_rom_bank_mode));
14111367         switch (MMC5_rom_bank_mode)
14121368         {
14131369            case 0x02:
r5926r5927
14221378               else
14231379               {
14241380                  /* RAM */
1425                  logerror ("\tRAM bank select (8k, $c000): %02x\n", data & 0x07);
1381                  LOG_MMC(("\tRAM bank select (8k, $c000): %02x\n", data & 0x07));
14261382                  /* The & 4 is a hack that'll tide us over for now */
14271383                  memory_set_bankptr(space->machine, 3, &nes.wram[(data & 4)* 0x2000]);
14281384               }
r5926r5927
14301386         }
14311387         break;
14321388      case 0x1017: /* $5117 */
1433         logerror ("MMC5 $5117 bank select: %02x (mode: %d)\n", data, MMC5_rom_bank_mode);
1389         LOG_MMC(("MMC5 $5117 bank select: %02x (mode: %d)\n", data, MMC5_rom_bank_mode));
14341390         switch (MMC5_rom_bank_mode)
14351391         {
14361392            case 0x00:
r5926r5927
14501406         }
14511407         break;
14521408      case 0x1020: /* $5120 */
1453         logerror ("MMC5 $5120 vrom select: %02x (mode: %d)\n", data, MMC5_vrom_bank_mode);
1409         LOG_MMC(("MMC5 $5120 vrom select: %02x (mode: %d)\n", data, MMC5_vrom_bank_mode));
14541410         switch (MMC5_vrom_bank_mode)
14551411         {
14561412            case 0x03:
r5926r5927
14671423         }
14681424         break;
14691425      case 0x1021: /* $5121 */
1470         logerror ("MMC5 $5121 vrom select: %02x (mode: %d)\n", data, MMC5_vrom_bank_mode);
1426         LOG_MMC(("MMC5 $5121 vrom select: %02x (mode: %d)\n", data, MMC5_vrom_bank_mode));
14711427         switch (MMC5_vrom_bank_mode)
14721428         {
14731429            case 0x02:
r5926r5927
14881444         }
14891445         break;
14901446      case 0x1022: /* $5122 */
1491         logerror ("MMC5 $5122 vrom select: %02x (mode: %d)\n", data, MMC5_vrom_bank_mode);
1447         LOG_MMC(("MMC5 $5122 vrom select: %02x (mode: %d)\n", data, MMC5_vrom_bank_mode));
14921448         switch (MMC5_vrom_bank_mode)
14931449         {
14941450            case 0x03:
r5926r5927
15051461         }
15061462         break;
15071463      case 0x1023: /* $5123 */
1508         logerror ("MMC5 $5123 vrom select: %02x (mode: %d)\n", data, MMC5_vrom_bank_mode);
1464         LOG_MMC(("MMC5 $5123 vrom select: %02x (mode: %d)\n", data, MMC5_vrom_bank_mode));
15091465         switch (MMC5_vrom_bank_mode)
15101466         {
15111467            case 0x01:
r5926r5927
15291485         }
15301486         break;
15311487      case 0x1024: /* $5124 */
1532         logerror ("MMC5 $5124 vrom select: %02x (mode: %d)\n", data, MMC5_vrom_bank_mode);
1488         LOG_MMC(("MMC5 $5124 vrom select: %02x (mode: %d)\n", data, MMC5_vrom_bank_mode));
15331489         switch (MMC5_vrom_bank_mode)
15341490         {
15351491            case 0x03:
r5926r5927
15461502         }
15471503         break;
15481504      case 0x1025: /* $5125 */
1549         logerror ("MMC5 $5125 vrom select: %02x (mode: %d)\n", data, MMC5_vrom_bank_mode);
1505         LOG_MMC(("MMC5 $5125 vrom select: %02x (mode: %d)\n", data, MMC5_vrom_bank_mode));
15501506         switch (MMC5_vrom_bank_mode)
15511507         {
15521508            case 0x02:
r5926r5927
15671523         }
15681524         break;
15691525      case 0x1026: /* $5126 */
1570         logerror ("MMC5 $5126 vrom select: %02x (mode: %d)\n", data, MMC5_vrom_bank_mode);
1526         LOG_MMC(("MMC5 $5126 vrom select: %02x (mode: %d)\n", data, MMC5_vrom_bank_mode));
15711527         switch (MMC5_vrom_bank_mode)
15721528         {
15731529            case 0x03:
r5926r5927
15841540         }
15851541         break;
15861542      case 0x1027: /* $5127 */
1587         logerror ("MMC5 $5127 vrom select: %02x (mode: %d)\n", data, MMC5_vrom_bank_mode);
1543         LOG_MMC(("MMC5 $5127 vrom select: %02x (mode: %d)\n", data, MMC5_vrom_bank_mode));
15881544         switch (MMC5_vrom_bank_mode)
15891545         {
15901546            case 0x00:
r5926r5927
16131569         }
16141570         break;
16151571      case 0x1028: /* $5128 */
1616         logerror ("MMC5 $5128 vrom select: %02x (mode: %d)\n", data, MMC5_vrom_bank_mode);
1572         LOG_MMC(("MMC5 $5128 vrom select: %02x (mode: %d)\n", data, MMC5_vrom_bank_mode));
16171573         switch (MMC5_vrom_bank_mode)
16181574         {
16191575            case 0x03:
r5926r5927
16341590         }
16351591         break;
16361592      case 0x1029: /* $5129 */
1637         logerror ("MMC5 $5129 vrom select: %02x (mode: %d)\n", data, MMC5_vrom_bank_mode);
1593         LOG_MMC(("MMC5 $5129 vrom select: %02x (mode: %d)\n", data, MMC5_vrom_bank_mode));
16381594         switch (MMC5_vrom_bank_mode)
16391595         {
16401596            case 0x02:
r5926r5927
16601616         }
16611617         break;
16621618      case 0x102a: /* $512a */
1663         logerror ("MMC5 $512a vrom select: %02x (mode: %d)\n", data, MMC5_vrom_bank_mode);
1619         LOG_MMC(("MMC5 $512a vrom select: %02x (mode: %d)\n", data, MMC5_vrom_bank_mode));
16641620         switch (MMC5_vrom_bank_mode)
16651621         {
16661622            case 0x03:
r5926r5927
16811637         }
16821638         break;
16831639      case 0x102b: /* $512b */
1684         logerror ("MMC5 $512b vrom select: %02x (mode: %d)\n", data, MMC5_vrom_bank_mode);
1640         LOG_MMC(("MMC5 $512b vrom select: %02x (mode: %d)\n", data, MMC5_vrom_bank_mode));
16851641         switch (MMC5_vrom_bank_mode)
16861642         {
16871643            case 0x00:
r5926r5927
17211677      case 0x1103: /* $5203 */
17221678         IRQ_count = data;
17231679         MMC5_scanline = data;
1724         logerror ("MMC5 irq scanline: %d\n", IRQ_count);
1680         LOG_MMC(("MMC5 irq scanline: %d\n", IRQ_count));
17251681         break;
17261682      case 0x1104: /* $5204 */
17271683         IRQ_enable = data & 0x80;
1728         logerror ("MMC5 irq enable: %02x\n", data);
1684         LOG_MMC(("MMC5 irq enable: %02x\n", data));
17291685         break;
17301686      case 0x1105: /* $5205 */
17311687         mult1 = data;
r5926r5927
17451701   logerror("MMC5 uncaught high mapper w, %04x: %02x\n", offset, data);
17461702}
17471703
1704/*************************************************************
1705
1706    Mapper 6
1707
1708    Known Boards: FFE4 Copier Board
1709    Games: Hacked versions of games
1710
1711    In MESS: Unsupported, low priority
1712
1713*************************************************************/
1714
1715/*************************************************************
1716
1717    Mapper 7
1718
1719    Known Boards: AMROM, ANROM, AN1ROM, AOROM and unlicensed
1720          AxROM
1721    Games: Arch Rivals, Battletoads, Cabal, Commando, Solstice
1722
1723    In MESS: Supported
1724
1725*************************************************************/
1726
17481727static WRITE8_HANDLER( mapper7_w )
17491728{
1750   if (data & 0x10)
1751      set_nt_mirroring(PPU_MIRROR_HIGH);
1752   else
1753      set_nt_mirroring(PPU_MIRROR_LOW);
1729   LOG_MMC(("mapper7_w, offset: %04x, data: %02x\n", offset, data));
17541730
1731   set_nt_mirroring((data & 0x10) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
17551732   prg32(space->machine, data);
17561733}
17571734
1735/*************************************************************
1736
1737    Mapper 8
1738
1739    Known Boards: FFE3 Copier Board
1740    Games: Hacked versions of games
1741
1742    In MESS: Supported
1743
1744*************************************************************/
1745
17581746static WRITE8_HANDLER( mapper8_w )
17591747{
1760   LOG_MMC(("* Mapper 8 switch, vrom: %02x, rom: %02x\n", data & 0x07, (data >> 3)));
1748   LOG_MMC(("mapper8_w, offset: %04x, data: %02x\n", offset, data));
1749
17611750   /* Switch 8k VROM bank */
17621751   chr8(space->machine, data & 0x07, CHRROM);
17631752
r5926r5927
17681757}
17691758
17701759
1760/*************************************************************
1761
1762    Mapper 9
1763
1764    Known Boards: MMC2 based Boards, i.e. PNROM & PEEOROM
1765    Games: Punch Out!!, Mike Tyson's Punch Out!!
1766
1767    In MESS: Supported
1768
1769*************************************************************/
1770
17711771static void mapper9_latch (const device_config *device, offs_t offset)
17721772{
17731773   if ((offset & 0x3ff0) == 0x0fd0)
17741774   {
1775      logerror ("mapper9 vrom latch switch (bank 0 low): %02x\n", MMC2_bank0);
1775      LOG_MMC(("mapper9 vrom latch switch (bank 0 low): %02x\n", MMC2_bank0));
17761776      MMC2_bank0_latch = 0xfd;
1777      chr4_0 (device->machine, MMC2_bank0, CHRROM);
1777      chr4_0(device->machine, MMC2_bank0, CHRROM);
17781778   }
17791779   else if ((offset & 0x3ff0) == 0x0fe0)
17801780   {
1781      logerror ("mapper9 vrom latch switch (bank 0 high): %02x\n", MMC2_bank0_hi);
1781      LOG_MMC(("mapper9 vrom latch switch (bank 0 high): %02x\n", MMC2_bank0_hi));
17821782      MMC2_bank0_latch = 0xfe;
1783      chr4_0 (device->machine, MMC2_bank0_hi, CHRROM);
1783      chr4_0(device->machine, MMC2_bank0_hi, CHRROM);
17841784   }
17851785   else if ((offset & 0x3ff0) == 0x1fd0)
17861786   {
1787      logerror ("mapper9 vrom latch switch (bank 1 low): %02x\n", MMC2_bank1);
1787      LOG_MMC(("mapper9 vrom latch switch (bank 1 low): %02x\n", MMC2_bank1));
17881788      MMC2_bank1_latch = 0xfd;
1789      chr4_4 (device->machine, MMC2_bank1, CHRROM);
1789      chr4_4(device->machine, MMC2_bank1, CHRROM);
17901790   }
17911791   else if ((offset & 0x3ff0) == 0x1fe0)
17921792   {
1793      logerror ("mapper9 vrom latch switch (bank 0 high): %02x\n", MMC2_bank1_hi);
1793      LOG_MMC(("mapper9 vrom latch switch (bank 0 high): %02x\n", MMC2_bank1_hi));
17941794      MMC2_bank1_latch = 0xfe;
1795      chr4_4 (device->machine, MMC2_bank1_hi, CHRROM);
1795      chr4_4(device->machine, MMC2_bank1_hi, CHRROM);
17961796   }
17971797}
17981798
17991799static WRITE8_HANDLER( mapper9_w )
18001800{
1801   //nes_state *state = space->machine->driver_data;
1802
18031801   switch (offset & 0x7000)
18041802   {
18051803      case 0x2000:
r5926r5927
18091807      case 0x3000:
18101808         MMC2_bank0 = data;
18111809         if (MMC2_bank0_latch == 0xfd)
1812            chr4_0 (space->machine, MMC2_bank0, CHRROM);
1813         logerror("MMC2 VROM switch #1 (low): %02x\n", MMC2_bank0);
1810            chr4_0(space->machine, MMC2_bank0, CHRROM);
1811         LOG_MMC(("MMC2 VROM switch #1 (low): %02x\n", MMC2_bank0));
18141812         break;
18151813      case 0x4000:
18161814         MMC2_bank0_hi = data;
18171815         if (MMC2_bank0_latch == 0xfe)
1818            chr4_0 (space->machine, MMC2_bank0_hi, CHRROM);
1819         logerror("MMC2 VROM switch #1 (high): %02x\n", MMC2_bank0_hi);
1816            chr4_0(space->machine, MMC2_bank0_hi, CHRROM);
1817         LOG_MMC(("MMC2 VROM switch #1 (high): %02x\n", MMC2_bank0_hi));
18201818         break;
18211819      case 0x5000:
18221820         MMC2_bank1 = data;
18231821         if (MMC2_bank1_latch == 0xfd)
1824            chr4_4 (space->machine, MMC2_bank1, CHRROM);
1825         logerror("MMC2 VROM switch #2 (low): %02x\n", data);
1822            chr4_4(space->machine, MMC2_bank1, CHRROM);
1823         LOG_MMC(("MMC2 VROM switch #2 (low): %02x\n", data));
18261824         break;
18271825      case 0x6000:
18281826         MMC2_bank1_hi = data;
18291827         if (MMC2_bank1_latch == 0xfe)
1830            chr4_4 (space->machine, MMC2_bank1_hi, CHRROM);
1831         logerror("MMC2 VROM switch #2 (high): %02x\n", data);
1828            chr4_4(space->machine, MMC2_bank1_hi, CHRROM);
1829         LOG_MMC(("MMC2 VROM switch #2 (high): %02x\n", data));
18321830         break;
18331831      case 0x7000:
1834         if (data&1)
1835            set_nt_mirroring(PPU_MIRROR_HORZ);
1836         else
1837            set_nt_mirroring(PPU_MIRROR_VERT);
1832         set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
18381833         break;
18391834      default:
1840         logerror("MMC2 uncaught w: %04x:%02x\n", offset, data);
1835         LOG_MMC(("MMC2 uncaught w: %04x:%02x\n", offset, data));
18411836         break;
18421837   }
18431838}
18441839
18451840
1846static void mapper10_latch (const device_config *device, offs_t offset)
1847{
1848   if ((offset & 0x3ff0) == 0x0fd0)
1849   {
1850      logerror ("mapper10 vrom latch switch (bank 0 low): %02x\n", MMC2_bank0);
1851      MMC2_bank0_latch = 0xfd;
1852      chr4_0 (device->machine, MMC2_bank0, CHRROM);
1853   }
1854   else if ((offset & 0x3ff0) == 0x0fe0)
1855   {
1856      logerror ("mapper10 vrom latch switch (bank 0 high): %02x\n", MMC2_bank0_hi);
1857      MMC2_bank0_latch = 0xfe;
1858      chr4_0 (device->machine, MMC2_bank0_hi, CHRROM);
1859   }
1860   else if ((offset & 0x3ff0) == 0x1fd0)
1861   {
1862      logerror ("mapper10 vrom latch switch (bank 1 low): %02x\n", MMC2_bank1);
1863      MMC2_bank1_latch = 0xfd;
1864      chr4_4 (device->machine, MMC2_bank1, CHRROM);
1865   }
1866   else if ((offset & 0x3ff0) == 0x1fe0)
1867   {
1868      logerror ("mapper10 vrom latch switch (bank 0 high): %02x\n", MMC2_bank1_hi);
1869      MMC2_bank1_latch = 0xfe;
1870      chr4_4 (device->machine, MMC2_bank1_hi, CHRROM);
1871   }
1872}
1841/*************************************************************
18731842
1843    Mapper 10
1844
1845    Known Boards: MMC4 based Boards, i.e. FJROM & FKROM
1846    Games: Famicom Wars, Fire Emblem, Fire Emblem Gaiden
1847
1848    In MESS: Supported
1849
1850*************************************************************/
1851
18741852static WRITE8_HANDLER( mapper10_w )
18751853{
1854   LOG_MMC(("mapper10_w, offset: %04x, data: %02x\n", offset, data));
18761855   switch (offset & 0x7000)
18771856   {
18781857      case 0x2000:
18791858         /* Switch the first 16k prg bank */
18801859         prg16_89ab(space->machine, data);
18811860         break;
1882      case 0x3000:
1883         MMC2_bank0 = data;
1884         if (MMC2_bank0_latch == 0xfd)
1885            chr4_0 (space->machine, MMC2_bank0, CHRROM);
1886         logerror("MMC4 VROM switch #1 (low): %02x\n", MMC2_bank0);
1887         break;
1888      case 0x4000:
1889         MMC2_bank0_hi = data;
1890         if (MMC2_bank0_latch == 0xfe)
1891            chr4_0 (space->machine, MMC2_bank0_hi, CHRROM);
1892         logerror("MMC4 VROM switch #1 (high): %02x\n", MMC2_bank0_hi);
1893         break;
1894      case 0x5000:
1895         MMC2_bank1 = data;
1896         if (MMC2_bank1_latch == 0xfd)
1897            chr4_4 (space->machine, MMC2_bank1, CHRROM);
1898         logerror("MMC4 VROM switch #2 (low): %02x\n", data);
1899         break;
1900      case 0x6000:
1901         MMC2_bank1_hi = data;
1902         if (MMC2_bank1_latch == 0xfe)
1903            chr4_4 (space->machine, MMC2_bank1_hi, CHRROM);
1904         logerror("MMC4 VROM switch #2 (high): %02x\n", data);
1905         break;
1906      case 0x7000:
1907         if (data&1)
1908            set_nt_mirroring(PPU_MIRROR_HORZ);
1909         else
1910            set_nt_mirroring(PPU_MIRROR_VERT);
1911         break;
19121861      default:
1913         logerror("MMC4 uncaught w: %04x:%02x\n", offset, data);
1862         mapper9_w(space, offset, data);
19141863         break;
19151864   }
19161865}
19171866
1867/*************************************************************
1868
1869    Mapper 11
1870
1871    Known Boards: Discrete Logic Board, NINA07
1872    Games: many Color Dreams and Wisdom Tree titles
1873
1874    In MESS: Supported
1875
1876*************************************************************/
1877
19181878static WRITE8_HANDLER( mapper11_w )
19191879{
1920   LOG_MMC(("* Mapper 11 switch, data: %02x\n", data));
1880   LOG_MMC(("mapper11_w, offset: %04x, data: %02x\n", offset, data));
19211881
19221882   /* Switch 8k VROM bank */
19231883   chr8(space->machine, data >> 4, CHRROM);
r5926r5927
19251885   /* Switch 32k prg bank */
19261886   prg32(space->machine, data & 0x0f);
19271887}
1888
1889/*************************************************************
1890
1891    Mapper 12
1892
1893    Known Boards: Bootleg Board by Rex Soft
1894    Games: Dragon Ball Z 5, Dragon Ball Z Super
1895
1896    MMC3 clone
1897
1898    In MESS: Unsupported
1899
1900*************************************************************/
1901
1902/*************************************************************
1903
1904    Mapper 13
1905
1906    Known Boards: CPROM
1907    Games: Videomation
1908
1909    In MESS: Supported
1910
1911*************************************************************/
1912
19281913static WRITE8_HANDLER( mapper13_w )
19291914{
1915   LOG_MMC(("mapper13_w, offset: %04x, data: %02x\n", offset, data));
19301916   chr4_4(space->machine, data, CHRRAM);
19311917}
19321918
1919/*************************************************************
1920
1921    Mapper 14
1922
1923    Known Boards: Bootleg Board by Rex Soft (SL1632)
1924    Games: [no games in nes.hsi]
1925
1926    MMC3 clone
1927
1928    In MESS: Unsupported
1929
1930*************************************************************/
1931
1932/*************************************************************
1933
1934    Mapper 15
1935
1936    Known Boards: Bootleg Board by Waixing (and probably others)
1937    Games: Bao Xiao Tien Guo, Bio Hazard, Pokemon Gold, Subor (R)
1938
1939    In MESS: Supported
1940
1941*************************************************************/
1942
19331943static WRITE8_HANDLER( mapper15_w )
19341944{
1935   int bank = (data & (nes.prg_chunks - 1)) * 0x4000;
1936   int base = data & 0x80 ? 0x12000 : 0x10000;
1945   UINT8 map15_flip = (data & 0x80) >> 7;
1946   UINT8 map15_helper = (data & 0x7f) << 1;
19371947
1938   switch (offset)
1948   LOG_MMC(("mapper15_w, offset: %04x, data: %02x\n", offset, data));
1949
1950   set_nt_mirroring((data & 0x40) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
1951
1952   switch (offset & 0x0fff)
19391953   {
1940      case 0x0000:
1941         if (data & 0x40)
1942            set_nt_mirroring(PPU_MIRROR_HORZ);
1943         else
1944            set_nt_mirroring(PPU_MIRROR_VERT);
1945         memory_set_bankptr(space->machine, 1, &nes.rom[bank + base]);
1946         memory_set_bankptr(space->machine, 2, &nes.rom[bank + (base ^ 0x2000)]);
1947         memory_set_bankptr(space->machine, 3, &nes.rom[bank + (base ^ 0x4000)]);
1948         memory_set_bankptr(space->machine, 4, &nes.rom[bank + (base ^ 0x6000)]);
1954      case 0x000:
1955         prg8_89(space->machine, (map15_helper + 0) ^ map15_flip);
1956         prg8_ab(space->machine, (map15_helper + 1) ^ map15_flip);
1957         prg8_cd(space->machine, (map15_helper + 2) ^ map15_flip);
1958         prg8_ef(space->machine, (map15_helper + 3) ^ map15_flip);
19491959         break;
1950
1951      case 0x0001:
1952         memory_set_bankptr(space->machine, 3, &nes.rom[bank + base]);
1953         memory_set_bankptr(space->machine, 4, &nes.rom[bank + (base ^ 0x2000)]);
1960      case 0x001:
1961         map15_helper |= map15_flip;
1962         prg8_89(space->machine, map15_helper);
1963         prg8_ab(space->machine, map15_helper + 1);
1964         prg8_cd(space->machine, map15_helper + 1);
1965         prg8_ef(space->machine, map15_helper);
19541966         break;
1955
1956      case 0x0002:
1957         memory_set_bankptr(space->machine, 1, &nes.rom[bank + base]);
1958         memory_set_bankptr(space->machine, 2, &nes.rom[bank + base]);
1959         memory_set_bankptr(space->machine, 3, &nes.rom[bank + base]);
1960         memory_set_bankptr(space->machine, 4, &nes.rom[bank + base]);
1961           break;
1962
1963      case 0x0003:
1964         if (data & 0x40)
1965            set_nt_mirroring(PPU_MIRROR_HORZ);
1966         else
1967            set_nt_mirroring(PPU_MIRROR_VERT);
1968         memory_set_bankptr(space->machine, 3, &nes.rom[bank + base]);
1969         memory_set_bankptr(space->machine, 4, &nes.rom[bank + (base ^ 0x2000)]);
1970           break;
1967      case 0x002:
1968         map15_helper |= map15_flip;
1969         prg8_89(space->machine, map15_helper);
1970         prg8_ab(space->machine, map15_helper);
1971         prg8_cd(space->machine, map15_helper);
1972         prg8_ef(space->machine, map15_helper);
1973              break;
1974      case 0x003:
1975         map15_helper |= map15_flip;
1976         prg8_89(space->machine, map15_helper);
1977         prg8_ab(space->machine, map15_helper + 1);
1978         prg8_cd(space->machine, map15_helper);
1979         prg8_ef(space->machine, map15_helper);
1980         break;
19711981   }
19721982}
19731983
1984/*************************************************************
1985
1986    Mapper 16
1987
1988    Known Boards: Bandai LZ93D50 24C02
1989    Games: Crayon Shin-Chan - Ora to Poi Poi, Dragon Ball Z Gaiden,
1990          Dragon Ball Z II & III, Rokudenashi Blues, SD Gundam
1991          Gaiden - KGM2
1992
1993    In MESS: Supported
1994
1995*************************************************************/
1996
19741997static void bandai_irq( const device_config *device, int scanline, int vblank, int blanked )
19751998{
19761999   /* 114 is the number of cycles per scanline */
r5926r5927
19862009   }
19872010}
19882011
1989static WRITE8_HANDLER( mapper16_w )
2012static WRITE8_HANDLER( mapper16_m_w )
19902013{
1991   logerror ("mapper16 (mid and high) w, offset: %04x, data: %02x\n", offset, data);
2014   LOG_MMC(("mapper16_m_w, offset: %04x, data: %02x\n", offset, data));
19922015
19932016   switch (offset & 0x000f)
19942017   {
r5926r5927
20002023      case 5:
20012024      case 6:
20022025      case 7:
2003         chr1_x(space->machine, offset&0x07, data, CHRROM);
2026         chr1_x(space->machine, offset & 0x07, data, CHRROM);
20042027         break;
20052028      case 8:
20062029         /* Switch 16k bank at $8000 */
r5926r5927
20402063   }
20412064}
20422065
2066static WRITE8_HANDLER( mapper16_w )
2067{
2068   LOG_MMC(("mapper16_w, offset: %04x, data: %02x\n", offset, data));
2069
2070   mapper16_m_w(space, offset, data);
2071}
2072
2073/*************************************************************
2074
2075    Mapper 17
2076
2077    Known Boards: FFE8 Copier Board
2078    Games: Hacked versions of games
2079
2080    In MESS: Supported. it also uses mapper4_irq.
2081
2082*************************************************************/
2083
20432084static WRITE8_HANDLER( mapper17_l_w )
20442085{
2086   LOG_MMC(("mapper17_l_w, offset: %04x, data: %02x\n", offset, data));
2087
20452088   switch (offset)
20462089   {
20472090      /* $42fe - mirroring */
r5926r5927
20702113      case 0x406:
20712114      case 0x407:
20722115         data &= ((nes.prg_chunks << 1) - 1);
2073//          logerror("Mapper 17 bank switch, bank: %02x, data: %02x\n", offset & 0x03, data);
2116//          LOG_MMC(("Mapper 17 bank switch, bank: %02x, data: %02x\n", offset & 0x03, data));
20742117         memory_set_bankptr(space->machine, (offset & 0x03) + 1, &nes.rom[0x2000 * (data) + 0x10000]);
20752118         break;
20762119      /* $4510 - $4517 : 1k CHR-Rom switch */
r5926r5927
20912134   }
20922135}
20932136
2137/*************************************************************
2138
2139    Mapper 18
2140
2141    Known Boards: Jaleco JF23, JF24, JF25, JF27, JF29, JF30, JF31,
2142          JF32, JF33, JF34, JF35, JF36, JF37, JF38, JF40, JF41, SS88006
2143    Games: Lord of King, Magic John, Moe Pro '90, Ninja Jajamaru,
2144          Pizza Pop, Plasma Ball
2145
2146    In MESS: Supported
2147
2148*************************************************************/
2149
20942150static void jaleco_irq( const device_config *device, int scanline, int vblank, int blanked )
20952151{
20962152   if (scanline <= PPU_BOTTOM_VISIBLE_SCANLINE)
r5926r5927
21002156      {
21012157         IRQ_count -= 0x100;
21022158
2103         logerror ("scanline: %d, irq count: %04x\n", scanline, IRQ_count);
2159         LOG_MMC(("scanline: %d, irq count: %04x\n", scanline, IRQ_count));
21042160         if (IRQ_mode & 0x08)
21052161         {
21062162            if ((IRQ_count & 0x0f) == 0x00)
r5926r5927
21382194   static int bank_a000 = 0;
21392195   static int bank_c000 = 0;
21402196
2197   LOG_MMC(("mapper18_w, offset: %04x, data: %02x\n", offset, data));
2198
21412199   switch (offset & 0x7003)
21422200   {
21432201      case 0x0000:
r5926r5927
22812339
22822340      case 0x6000: /* IRQ scanline counter - low byte, low nibble */
22832341         IRQ_count_latch = (IRQ_count_latch & 0xfff0) | (data & 0x0f);
2284         logerror("     Mapper 18 copy/set irq latch (l-l): %02x\n", data);
2342         LOG_MMC(("     Mapper 18 copy/set irq latch (l-l): %02x\n", data));
22852343         break;
22862344      case 0x6001: /* IRQ scanline counter - low byte, high nibble */
22872345         IRQ_count_latch = (IRQ_count_latch & 0xff0f) | ((data & 0x0f) << 4);
2288         logerror("     Mapper 18 copy/set irq latch (l-h): %02x\n", data);
2346         LOG_MMC(("     Mapper 18 copy/set irq latch (l-h): %02x\n", data));
22892347         break;
22902348      case 0x6002:
22912349         IRQ_count_latch = (IRQ_count_latch & 0xf0ff) | ((data & 0x0f) << 9);
2292         logerror("     Mapper 18 copy/set irq latch (h-l): %02x\n", data);
2350         LOG_MMC(("     Mapper 18 copy/set irq latch (h-l): %02x\n", data));
22932351         break;
22942352      case 0x6003:
22952353         IRQ_count_latch = (IRQ_count_latch & 0x0fff) | ((data & 0x0f) << 13);
2296         logerror("     Mapper 18 copy/set irq latch (h-h): %02x\n", data);
2354         LOG_MMC(("     Mapper 18 copy/set irq latch (h-h): %02x\n", data));
22972355         break;
22982356
22992357/* LBO - these 2 are likely wrong */
r5926r5927
23042362//              IRQ_enable = 1;
23052363            IRQ_count = IRQ_count_latch;
23062364         }
2307         logerror("     Mapper 18 IRQ Control 0: %02x\n", data);
2365         LOG_MMC(("     Mapper 18 IRQ Control 0: %02x\n", data));
23082366         break;
23092367      case 0x7001: /* IRQ Control 1 */
23102368         IRQ_enable = data & 0x01;
23112369         IRQ_mode = data & 0x0e;
2312         logerror("     Mapper 18 IRQ Control 1: %02x\n", data);
2370         LOG_MMC(("     Mapper 18 IRQ Control 1: %02x\n", data));
23132371         break;
23142372
23152373      case 0x7002: /* Misc */
r5926r5927
23332391   }
23342392}
23352393
2394/*************************************************************
2395
2396    Mapper 19
2397
2398    Known Boards: Namcot 163 & 163S
2399    Games: Battle Fleet, Family Circuit '91, Famista '90, '91,
2400          '92 & '94, Megami Tensei II, Top Striker, Wagyan Land 2 & 3
2401
2402    In MESS: Supported
2403
2404*************************************************************/
2405
23362406static void namcot_irq( const device_config *device, int scanline, int vblank, int blanked )
23372407{
23382408   IRQ_count ++;
r5926r5927
23452415
23462416static WRITE8_HANDLER( mapper19_l_w )
23472417{
2418   LOG_MMC(("mapper19_l_w, offset: %04x, data: %02x\n", offset, data));
2419
23482420   switch (offset & 0x1800)
23492421   {
23502422      case 0x1000:
r5926r5927
23612433
23622434static WRITE8_HANDLER( mapper19_w )
23632435{
2436   LOG_MMC(("mapper19_w, offset: %04x, data: %02x\n", offset, data));
23642437   switch (offset & 0x7800)
23652438   {
23662439      case 0x0000:
r5926r5927
23712444      case 0x2800:
23722445      case 0x3000:
23732446      case 0x3800:
2374         /* Switch 1k VROM at $0000-$1c00 */
2375         chr1_x(space->machine, offset /0x800, data, CHRROM);
2376//          ppu2c0x_set_videorom_bank(state->ppu, offset / 0x800, 1, data, 64);
2447         chr1_x(space->machine, offset / 0x800, data, CHRROM);
23772448         break;
2378
2449      case 0x4000:
2450         set_nt_page(0, CIRAM, data & 0x01, 1);
2451         break;
2452      case 0x4800:
2453         set_nt_page(1, CIRAM, data & 0x01, 1);
2454         break;
2455      case 0x5000:
2456         set_nt_page(2, CIRAM, data & 0x01, 1);
2457         break;
2458      case 0x5800:
2459         set_nt_page(3, CIRAM, data & 0x01, 1);
2460         break;
23792461      case 0x6000:
2380         /* Switch 8k bank at $8000 */
2381         data &= prg_mask;
2382         memory_set_bankptr(space->machine, 1, &nes.rom[0x2000 * (data) + 0x10000]);
2462         prg8_89(space->machine, data);
23832463         break;
23842464      case 0x6800:
2385         /* Switch 8k bank at $a000 */
2386         data &= prg_mask;
2387         memory_set_bankptr(space->machine, 2, &nes.rom[0x2000 * (data) + 0x10000]);
2465         prg8_ab(space->machine, data);
23882466         break;
23892467      case 0x7000:
2390         /* Switch 8k bank at $c000 */
2391         data &= prg_mask;
2392         memory_set_bankptr(space->machine, 3, &nes.rom[0x2000 * (data) + 0x10000]);
2468         prg8_cd(space->machine, data);
23932469         break;
23942470   }
23952471}
23962472
2473/*************************************************************
2474
2475    Mapper 20
2476
2477    Known Boards: Reserved for FDS
2478    Games: any FDS disk
2479
2480    In MESS: Supported
2481
2482*************************************************************/
2483
23972484static void fds_irq( const device_config *device, int scanline, int vblank, int blanked )
23982485{
23992486   if (IRQ_enable_latch)
r5926r5927
24192506   static int last_side = 0;
24202507   static int count = 0;
24212508
2509   LOG_MMC(("fds_r, offset: %04x\n", offset));
2510
24222511   switch (offset)
24232512   {
24242513      case 0x00: /* $4030 - disk status 0 */
r5926r5927
24682557
24692558WRITE8_HANDLER( fds_w )
24702559{
2560   LOG_MMC(("fds_w, offset: %04x, data: %02x\n", offset, data));
2561
24712562   switch (offset)
24722563   {
24732564      case 0x00: /* $4020 */
r5926r5927
25082599   LOG_FDS(("fds_w, address: %04x, data: %02x\n", offset + 0x4020, data));
25092600}
25102601
2602/*************************************************************
2603
2604    Mapper 21 & 25
2605
2606    Known Boards: Konami VRC4A & VRC4C (21), VRC4B & VRC4D (25)
2607    Games: Ganbare Goemon Gaiden 2, Wai Wai World 2 (21), Bio
2608          Miracle Bokutte Upa, Ganbare Goemon Gaiden, TMNT 1 & 2 Jpn (25)
2609
2610    In MESS: Supported
2611
2612*************************************************************/
2613
25112614static void konami_irq( const device_config *device, int scanline, int vblank, int blanked )
25122615{
25132616   /* Increment & check the IRQ scanline counter */
r5926r5927
25192622   }
25202623}
25212624
2522static WRITE8_HANDLER( konami_vrc2a_w )
2625static WRITE8_HANDLER( konami_vrc4_w )
25232626{
2524   if (offset < 0x3000)
2525   {
2526      switch (offset & 0x3000)
2527      {
2528         case 0:
2529            /* Switch 8k bank at $8000 */
2530            data &= ((nes.prg_chunks << 1) - 1);
2531            memory_set_bankptr(space->machine, 1, &nes.rom[0x2000 * (data) + 0x10000]);
2532            break;
2533         case 0x1000:
2534            switch (data & 0x03)
2535            {
2536               case 0x00: set_nt_mirroring(PPU_MIRROR_VERT); break;
2537               case 0x01: set_nt_mirroring(PPU_MIRROR_HORZ); break;
2538               case 0x02: set_nt_mirroring(PPU_MIRROR_LOW); break;
2539               case 0x03: set_nt_mirroring(PPU_MIRROR_HIGH); break;
2540            }
2541            break;
2627   LOG_MMC(("konami_vrc4_w, offset: %04x, data: %02x\n", offset, data));
25422628
2543         case 0x2000:
2544            /* Switch 8k bank at $a000 */
2545            data &= ((nes.prg_chunks << 1) - 1);
2546            memory_set_bankptr(space->machine, 2, &nes.rom[0x2000 * (data) + 0x10000]);
2547            break;
2548         default:
2549            logerror("konami_vrc2a_w uncaught offset: %04x value: %02x\n", offset, data);
2550            break;
2551      }
2552      return;
2553   }
2554
2555   switch (offset & 0x7000)
2556   {
2557      case 0x3000:
2558      case 0x3001:
2559      case 0x4000:
2560      case 0x4001:
2561      case 0x5000:
2562      case 0x5001:
2563      case 0x6000:
2564      case 0x6001:
2565         /* switch 1k vrom at $0000-$1c00 */
2566         {
2567            int bank = (offset & 0x7000) / 0x0800 + (offset & 0x0001);
2568            vrom_bank[bank] = data >> 1;
2569            vrom_bank[bank] &= ((nes.chr_chunks << 3) - 1);
2570            chr1_x(space->machine, bank, vrom_bank[bank], CHRROM);
2571            //ppu2c0x_set_videorom_bank(state->ppu, bank, 1, vrom_bank[bank], 64);
2572         }
2573         break;
2574
2575      case 0x7000:
2576         /* Set low 4 bits of latch */
2577         IRQ_count_latch &= ~0x0f;
2578         IRQ_count_latch |= data & 0x0f;
2579         break;
2580      case 0x7001:
2581         /* Set high 4 bits of latch */
2582         IRQ_count_latch &= ~0xf0;
2583         IRQ_count_latch |= (data << 4) & 0xf0;
2584         break;
2585      case 0x7002:
2586         IRQ_count = IRQ_count_latch;
2587         IRQ_enable = data & 0x02;
2588         IRQ_enable_latch = data & 0x01;
2589         break;
2590
2591      default:
2592         logerror("konami_vrc2a_w uncaught offset: %04x value: %02x\n", offset, data);
2593         break;
2594   }
2595}
2596
2597static WRITE8_HANDLER( konami_vrc2b_w )
2598{
2599   UINT16 select;
2600
2601//  logerror("konami_vrc2b_w offset: %04x value: %02x\n", offset, data);
2602
2603   if (offset < 0x3000)
2604   {
2605      switch (offset & 0x3000)
2606      {
2607         case 0:
2608            /* Switch 8k bank at $8000 */
2609            data &= ((nes.prg_chunks << 1) - 1);
2610            memory_set_bankptr(space->machine, 1, &nes.rom[0x2000 * (data) + 0x10000]);
2611            break;
2612         case 0x1000:
2613            switch (data & 0x03)
2614            {
2615               case 0x00: set_nt_mirroring(PPU_MIRROR_VERT); break;
2616               case 0x01: set_nt_mirroring(PPU_MIRROR_HORZ); break;
2617               case 0x02: set_nt_mirroring(PPU_MIRROR_LOW); break;
2618               case 0x03: set_nt_mirroring(PPU_MIRROR_HIGH); break;
2619            }
2620            break;
2621
2622         case 0x2000:
2623            /* Switch 8k bank at $a000 */
2624            data &= ((nes.prg_chunks << 1) - 1);
2625            memory_set_bankptr(space->machine, 2, &nes.rom[0x2000 * (data) + 0x10000]);
2626            break;
2627         default:
2628            logerror("konami_vrc2b_w offset: %04x value: %02x\n", offset, data);
2629            break;
2630      }
2631      return;
2632   }
2633
2634   /* The low 2 select bits vary from cart to cart */
2635   select = (offset & 0x7000) |
2636      (offset & 0x03) |
2637      ((offset & 0x0c) >> 2);
2638
2639   switch (select)
2640   {
2641      case 0x3000:
2642         /* Switch 1k vrom at $0000 - low 4 bits */
2643         vrom_bank[0] = (vrom_bank[0] & 0xf0) | (data & 0x0f);
2644         vrom_bank[0] &= ((nes.chr_chunks << 3) - 1);
2645         chr1_0(space->machine, vrom_bank[0], CHRROM);
2646         break;
2647      case 0x3001:
2648         /* Switch 1k vrom at $0000 - high 4 bits */
2649         vrom_bank[0] = (vrom_bank[0] & 0x0f) | (data << 4);
2650         vrom_bank[0] &= ((nes.chr_chunks << 3) - 1);
2651         chr1_0(space->machine, vrom_bank[0], CHRROM);
2652         break;
2653      case 0x3002:
2654         /* Switch 1k vrom at $0400 - low 4 bits */
2655         vrom_bank[1] = (vrom_bank[1] & 0xf0) | (data & 0x0f);
2656         vrom_bank[1] &= ((nes.chr_chunks << 3) - 1);
2657         chr1_1(space->machine, vrom_bank[1], CHRROM);
2658         break;
2659      case 0x3003:
2660         /* Switch 1k vrom at $0400 - high 4 bits */
2661         vrom_bank[1] = (vrom_bank[1] & 0x0f) | (data << 4);
2662         vrom_bank[1] &= ((nes.chr_chunks << 3) - 1);
2663         chr1_1(space->machine, vrom_bank[1], CHRROM);
2664         break;
2665      case 0x4000:
2666         /* Switch 1k vrom at $0800 - low 4 bits */
2667         vrom_bank[2] = (vrom_bank[2] & 0xf0) | (data & 0x0f);
2668         vrom_bank[2] &= ((nes.chr_chunks << 3) - 1);
2669         chr1_2(space->machine, vrom_bank[2], CHRROM);
2670         break;
2671      case 0x4001:
2672         /* Switch 1k vrom at $0800 - high 4 bits */
2673         vrom_bank[2] = (vrom_bank[2] & 0x0f) | (data << 4);
2674         vrom_bank[2] &= ((nes.chr_chunks << 3) - 1);
2675         chr1_2(space->machine, vrom_bank[2], CHRROM);
2676         break;
2677      case 0x4002:
2678         /* Switch 1k vrom at $0c00 - low 4 bits */
2679         vrom_bank[3] = (vrom_bank[3] & 0xf0) | (data & 0x0f);
2680         vrom_bank[3] &= ((nes.chr_chunks << 3) - 1);
2681         chr1_3(space->machine, vrom_bank[3], CHRROM);
2682         break;
2683      case 0x4003:
2684         /* Switch 1k vrom at $0c00 - high 4 bits */
2685         vrom_bank[3] = (vrom_bank[3] & 0x0f) | (data << 4);
2686         vrom_bank[3] &= ((nes.chr_chunks << 3) - 1);
2687         chr1_3(space->machine, vrom_bank[3], CHRROM);
2688         break;
2689      case 0x5000:
2690         /* Switch 1k vrom at $1000 - low 4 bits */
2691         vrom_bank[4] = (vrom_bank[4] & 0xf0) | (data & 0x0f);
2692         vrom_bank[4] &= ((nes.chr_chunks << 3) - 1);
2693         chr1_4(space->machine, vrom_bank[4], CHRROM);
2694         break;
2695      case 0x5001:
2696         /* Switch 1k vrom at $1000 - high 4 bits */
2697         vrom_bank[4] = (vrom_bank[4] & 0x0f) | (data << 4);
2698         vrom_bank[4] &= ((nes.chr_chunks << 3) - 1);
2699         chr1_4(space->machine, vrom_bank[4], CHRROM);
2700         break;
2701      case 0x5002:
2702         /* Switch 1k vrom at $1400 - low 4 bits */
2703         vrom_bank[5] = (vrom_bank[5] & 0xf0) | (data & 0x0f);
2704         vrom_bank[5] &= ((nes.chr_chunks << 3) - 1);
2705         chr1_5(space->machine, vrom_bank[5], CHRROM);
2706         break;
2707      case 0x5003:
2708         /* Switch 1k vrom at $1400 - high 4 bits */
2709         vrom_bank[5] = (vrom_bank[5] & 0x0f) | (data << 4);
2710         vrom_bank[5] &= ((nes.chr_chunks << 3) - 1);
2711         chr1_5(space->machine, vrom_bank[5], CHRROM);
2712         break;
2713      case 0x6000:
2714         /* Switch 1k vrom at $1800 - low 4 bits */
2715         vrom_bank[6] = (vrom_bank[6] & 0xf0) | (data & 0x0f);
2716         vrom_bank[6] &= ((nes.chr_chunks << 3) - 1);
2717         chr1_6(space->machine, vrom_bank[6], CHRROM);
2718         break;
2719      case 0x6001:
2720         /* Switch 1k vrom at $1800 - high 4 bits */
2721         vrom_bank[6] = (vrom_bank[6] & 0x0f) | (data << 4);
2722         vrom_bank[6] &= ((nes.chr_chunks << 3) - 1);
2723         chr1_6(space->machine, vrom_bank[6], CHRROM);
2724         break;
2725      case 0x6002:
2726         /* Switch 1k vrom at $1c00 - low 4 bits */
2727         vrom_bank[7] = (vrom_bank[7] & 0xf0) | (data & 0x0f);
2728         vrom_bank[7] &= ((nes.chr_chunks << 3) - 1);
2729         chr1_7(space->machine, vrom_bank[7], CHRROM);
2730         break;
2731      case 0x6003:
2732         /* Switch 1k vrom at $1c00 - high 4 bits */
2733         vrom_bank[7] = (vrom_bank[7] & 0x0f) | (data << 4);
2734         vrom_bank[7] &= ((nes.chr_chunks << 3) - 1);
2735         chr1_7(space->machine, vrom_bank[7], CHRROM);
2736         break;
2737      case 0x7000:
2738         /* Set low 4 bits of latch */
2739         IRQ_count_latch &= ~0x0f;
2740         IRQ_count_latch |= data & 0x0f;
2741         break;
2742      case 0x7001:
2743         /* Set high 4 bits of latch */
2744         IRQ_count_latch &= ~0xf0;
2745         IRQ_count_latch |= (data << 4) & 0xf0;
2746         break;
2747      case 0x7002:
2748         IRQ_count = IRQ_count_latch;
2749         IRQ_enable = data & 0x02;
2750         IRQ_enable_latch = data & 0x01;
2751         break;
2752
2753      default:
2754         logerror("konami_vrc2b_w uncaught offset: %04x value: %02x\n", offset, data);
2755         break;
2756   }
2757}
2758
2759static WRITE8_HANDLER( konami_vrc4_w )
2760{
27612629   switch (offset & 0x7007)
27622630   {
27632631      case 0x0000:
27642632         /* Switch 8k bank at $8000 */
2765         data &= ((nes.prg_chunks << 1) - 1);
2766         memory_set_bankptr(space->machine, 1, &nes.rom[0x2000 * (data) + 0x10000]);
2633         prg8_89(space->machine, data);
27672634         break;
27682635      case 0x1000:
27692636         switch (data & 0x03)
r5926r5927
27792646
27802647      case 0x2000:
27812648         /* Switch 8k bank at $a000 */
2782         data &= ((nes.prg_chunks << 1) - 1);
2783         memory_set_bankptr(space->machine, 2, &nes.rom[0x2000 * (data) + 0x10000]);
2649         prg8_ab(space->machine, data);
27842650         break;
27852651      case 0x3000:
27862652         /* Switch 1k vrom at $0000 - low 4 bits */
27872653         vrom_bank[0] = (vrom_bank[0] & 0xf0) | (data & 0x0f);
2788         vrom_bank[0] &= ((nes.chr_chunks << 3) - 1);
27892654         chr1_0(space->machine, vrom_bank[0], CHRROM);
27902655         break;
27912656      case 0x3002:
27922657         /* Switch 1k vrom at $0000 - high 4 bits */
27932658         vrom_bank[0] = (vrom_bank[0] & 0x0f) | (data << 4);
2794         vrom_bank[0] &= ((nes.chr_chunks << 3) - 1);
27952659         chr1_0(space->machine, vrom_bank[0], CHRROM);
27962660         break;
27972661      case 0x3001:
27982662      case 0x3004:
27992663         /* Switch 1k vrom at $0400 - low 4 bits */
28002664         vrom_bank[1] = (vrom_bank[1] & 0xf0) | (data & 0x0f);
2801         vrom_bank[1] &= ((nes.chr_chunks << 3) - 1);
28022665         chr1_1(space->machine, vrom_bank[1], CHRROM);
28032666         break;
28042667      case 0x3003:
28052668      case 0x3006:
28062669         /* Switch 1k vrom at $0400 - high 4 bits */
28072670         vrom_bank[1] = (vrom_bank[1] & 0x0f) | (data << 4);
2808         vrom_bank[1] &= ((nes.chr_chunks << 3) - 1);
28092671         chr1_1(space->machine, vrom_bank[1], CHRROM);
28102672         break;
28112673      case 0x4000:
28122674         /* Switch 1k vrom at $0800 - low 4 bits */
28132675         vrom_bank[2] = (vrom_bank[2] & 0xf0) | (data & 0x0f);
2814         vrom_bank[2] &= ((nes.chr_chunks << 3) - 1);
28152676         chr1_2(space->machine, vrom_bank[2], CHRROM);
28162677         break;
28172678      case 0x4002:
28182679         /* Switch 1k vrom at $0800 - high 4 bits */
28192680         vrom_bank[2] = (vrom_bank[2] & 0x0f) | (data << 4);
2820         vrom_bank[2] &= ((nes.chr_chunks << 3) - 1);
28212681         chr1_2(space->machine, vrom_bank[2], CHRROM);
28222682         break;
28232683      case 0x4001:
28242684      case 0x4004:
28252685         /* Switch 1k vrom at $0c00 - low 4 bits */
28262686         vrom_bank[3] = (vrom_bank[3] & 0xf0) | (data & 0x0f);
2827         vrom_bank[3] &= ((nes.chr_chunks << 3) - 1);
28282687         chr1_3(space->machine, vrom_bank[3], CHRROM);
28292688         break;
28302689      case 0x4003:
28312690      case 0x4006:
28322691         /* Switch 1k vrom at $0c00 - high 4 bits */
28332692         vrom_bank[3] = (vrom_bank[3] & 0x0f) | (data << 4);
2834         vrom_bank[3] &= ((nes.chr_chunks << 3) - 1);
28352693         chr1_3(space->machine, vrom_bank[3], CHRROM);
28362694         break;
28372695      case 0x5000:
28382696         /* Switch 1k vrom at $1000 - low 4 bits */
28392697         vrom_bank[4] = (vrom_bank[4] & 0xf0) | (data & 0x0f);
2840         vrom_bank[4] &= ((nes.chr_chunks << 3) - 1);
28412698         chr1_4(space->machine, vrom_bank[4], CHRROM);
28422699         break;
28432700      case 0x5002:
28442701         /* Switch 1k vrom at $1000 - high 4 bits */
28452702         vrom_bank[4] = (vrom_bank[4] & 0x0f) | (data << 4);
2846         vrom_bank[4] &= ((nes.chr_chunks << 3) - 1);
28472703         chr1_4(space->machine, vrom_bank[4], CHRROM);
28482704         break;
28492705      case 0x5001:
28502706      case 0x5004:
28512707         /* Switch 1k vrom at $1400 - low 4 bits */
28522708         vrom_bank[5] = (vrom_bank[5] & 0xf0) | (data & 0x0f);
2853         vrom_bank[5] &= ((nes.chr_chunks << 3) - 1);
28542709         chr1_5(space->machine, vrom_bank[5], CHRROM);
28552710         break;
28562711      case 0x5003:
28572712      case 0x5006:
28582713         /* Switch 1k vrom at $1400 - high 4 bits */
28592714         vrom_bank[5] = (vrom_bank[5] & 0x0f) | (data << 4);
2860         vrom_bank[5] &= ((nes.chr_chunks << 3) - 1);
28612715         chr1_5(space->machine, vrom_bank[5], CHRROM);
28622716         break;
28632717      case 0x6000:
28642718         /* Switch 1k vrom at $1800 - low 4 bits */
28652719         vrom_bank[6] = (vrom_bank[6] & 0xf0) | (data & 0x0f);
2866         vrom_bank[6] &= ((nes.chr_chunks << 3) - 1);
28672720         chr1_6(space->machine, vrom_bank[6], CHRROM);
28682721         break;
28692722      case 0x6002:
28702723         /* Switch 1k vrom at $1800 - high 4 bits */
28712724         vrom_bank[6] = (vrom_bank[6] & 0x0f) | (data << 4);
2872         vrom_bank[6] &= ((nes.chr_chunks << 3) - 1);
28732725         chr1_6(space->machine, vrom_bank[6], CHRROM);
28742726         break;
28752727      case 0x6001:
28762728      case 0x6004:
28772729         /* Switch 1k vrom at $1c00 - low 4 bits */
28782730         vrom_bank[7] = (vrom_bank[7] & 0xf0) | (data & 0x0f);
2879         vrom_bank[7] &= ((nes.chr_chunks << 3) - 1);
28802731         chr1_7(space->machine, vrom_bank[7], CHRROM);
28812732         break;
28822733      case 0x6003:
28832734      case 0x6006:
28842735         /* Switch 1k vrom at $1c00 - high 4 bits */
28852736         vrom_bank[7] = (vrom_bank[7] & 0x0f) | (data << 4);
2886         vrom_bank[7] &= ((nes.chr_chunks << 3) - 1);
28872737         chr1_7(space->machine, vrom_bank[7], CHRROM);
28882738         break;
28892739      case 0x7000:
28902740         /* Set low 4 bits of latch */
28912741         IRQ_count_latch &= ~0x0f;
28922742         IRQ_count_latch |= data & 0x0f;
2893//          logerror("konami_vrc4 irq_latch low: %02x\n", IRQ_count_latch);
2743//          LOG_MMC(("konami_vrc4 irq_latch low: %02x\n", IRQ_count_latch));
28942744         break;
28952745      case 0x7002:
28962746      case 0x7040:
28972747         /* Set high 4 bits of latch */
28982748         IRQ_count_latch &= ~0xf0;
28992749         IRQ_count_latch |= (data << 4) & 0xf0;
2900//          logerror("konami_vrc4 irq_latch high: %02x\n", IRQ_count_latch);
2750//          LOG_MMC(("konami_vrc4 irq_latch high: %02x\n", IRQ_count_latch));
29012751         break;
29022752      case 0x7004:
29032753      case 0x7001:
r5926r5927
29052755         IRQ_count = IRQ_count_latch;
29062756         IRQ_enable = data & 0x02;
29072757         IRQ_enable_latch = data & 0x01;
2908//          logerror("konami_vrc4 irq_count set: %02x\n", IRQ_count);
2909//          logerror("konami_vrc4 enable: %02x\n", IRQ_enable);
2910//          logerror("konami_vrc4 enable latch: %02x\n", IRQ_enable_latch);
2758//          LOG_MMC(("konami_vrc4 irq_count set: %02x\n", IRQ_count));
2759//          LOG_MMC(("konami_vrc4 enable: %02x\n", IRQ_enable));
2760//          LOG_MMC(("konami_vrc4 enable latch: %02x\n", IRQ_enable_latch));
29112761         break;
29122762      case 0x7006:
29132763      case 0x7003:
29142764      case 0x70c0:
29152765         IRQ_enable = IRQ_enable_latch;
2916//          logerror("konami_vrc4 enable copy: %02x\n", IRQ_enable);
2766//          LOG_MMC(("konami_vrc4 enable copy: %02x\n", IRQ_enable));
29172767         break;
29182768      default:
2919         logerror("konami_vrc4_w uncaught offset: %04x value: %02x\n", offset, data);
2769         LOG_MMC(("konami_vrc4_w uncaught offset: %04x value: %02x\n", offset, data));
29202770         break;
29212771   }
29222772}
29232773
2774/*************************************************************
2775
2776    Mapper 22
2777
2778    Known Boards: Konami VRC2A
2779    Games: Ganbare Pennant Race, Twin Bee 3
2780
2781    In MESS: Supported.
2782
2783*************************************************************/
2784
2785static WRITE8_HANDLER( konami_vrc2a_w )
2786{
2787   UINT8 bank;
2788   LOG_MMC(("konami_vrc2a_w, offset: %04x, data: %02x\n", offset, data));
2789
2790   switch (offset & 0x7000)
2791   {
2792   case 0x0000:
2793      prg8_89(space->machine, data);
2794      break;
2795   case 0x1000:
2796      switch (data & 0x03)
2797      {
2798         case 0x00: set_nt_mirroring(PPU_MIRROR_VERT); break;
2799         case 0x01: set_nt_mirroring(PPU_MIRROR_HORZ); break;
2800         case 0x02: set_nt_mirroring(PPU_MIRROR_LOW); break;
2801         case 0x03: set_nt_mirroring(PPU_MIRROR_HIGH); break;
2802      }
2803      break;
2804   case 0x2000:
2805      /* Switch 8k bank at $a000 */
2806      prg8_ab(space->machine, data);
2807      break;
2808   case 0x3000:
2809   case 0x4000:
2810   case 0x5000:
2811   case 0x6000:
2812      /* switch 1k vrom at $0000-$1c00 */
2813      bank = ((offset & 0x7000) - 0x3000) / 0x0800 + (offset & 0x0001);
2814      /* Notice that we store the banks as in other VRC, but then we take vrom_bank>>1 because it's VRC2A!*/
2815      if (offset & 0x0002)
2816         vrom_bank[bank] = (vrom_bank[bank] & 0x0f) | (data << 4);
2817      else
2818         vrom_bank[bank] = (vrom_bank[bank] & 0xf0) | (data & 0x0f);
2819
2820      chr1_x(space->machine, bank, vrom_bank[bank] >> 1, CHRROM);
2821      break;
2822
2823   default:
2824      LOG_MMC(("konami_vrc2a_w uncaught offset: %04x value: %02x\n", offset, data));
2825      break;
2826   }
2827}
2828
2829/*************************************************************
2830
2831    Mapper 23
2832
2833    Known Boards: Konami VRC2B & VRC4E
2834    Games: Getsufuu Maden, Parodius Da!
2835
2836    In MESS: Supported. It also uses konami_irq.
2837
2838*************************************************************/
2839
2840static WRITE8_HANDLER( konami_vrc2b_w )
2841{
2842   UINT16 select;
2843   UINT8 bank;
2844
2845   LOG_MMC(("konami_vrc2b_w, offset: %04x, data: %02x\n", offset, data));
2846
2847   if (offset < 0x3000)
2848   {
2849      switch (offset & 0x3000)
2850      {
2851         case 0:
2852            /* Switch 8k bank at $8000 */
2853            prg8_89(space->machine, data);
2854            break;
2855         case 0x1000:
2856            switch (data & 0x03)
2857            {
2858               case 0x00: set_nt_mirroring(PPU_MIRROR_VERT); break;
2859               case 0x01: set_nt_mirroring(PPU_MIRROR_HORZ); break;
2860               case 0x02: set_nt_mirroring(PPU_MIRROR_LOW); break;
2861               case 0x03: set_nt_mirroring(PPU_MIRROR_HIGH); break;
2862            }
2863            break;
2864
2865         case 0x2000:
2866            /* Switch 8k bank at $a000 */
2867            prg8_ab(space->machine, data);
2868            break;
2869         default:
2870            LOG_MMC(("konami_vrc2b_w offset: %04x value: %02x\n", offset, data));
2871            break;
2872      }
2873      return;
2874   }
2875
2876   /* The low 2 select bits vary from cart to cart */
2877   select = (offset & 0x7000) | (offset & 0x03) | ((offset & 0x0c) >> 2);
2878
2879   switch (select)
2880   {
2881   case 0x3000:
2882   case 0x3001:
2883   case 0x3002:
2884   case 0x3003:
2885   case 0x4000:
2886   case 0x4001:
2887   case 0x4002:
2888   case 0x4003:
2889   case 0x5000:
2890   case 0x5001:
2891   case 0x5002:
2892   case 0x5003:
2893   case 0x6000:
2894   case 0x6001:
2895   case 0x6002:
2896   case 0x6003:
2897      /* switch 1k vrom at $0000-$1c00 */
2898      bank = ((select & 0x7000) - 0x3000) / 0x0800 + ((select & 0x0002) >> 1);
2899      if (select & 0x0001)
2900         vrom_bank[bank] = (vrom_bank[bank] & 0x0f) | (data << 4);
2901      else
2902         vrom_bank[bank] = (vrom_bank[bank] & 0xf0) | (data & 0x0f);
2903
2904      chr1_x(space->machine, bank, vrom_bank[bank], CHRROM);
2905      break;
2906   case 0x7000:
2907      /* Set low 4 bits of latch */
2908      IRQ_count_latch &= ~0x0f;
2909      IRQ_count_latch |= data & 0x0f;
2910      break;
2911   case 0x7001:
2912      /* Set high 4 bits of latch */
2913      IRQ_count_latch &= ~0xf0;
2914      IRQ_count_latch |= (data << 4) & 0xf0;
2915      break;
2916   case 0x7002:
2917      IRQ_count = IRQ_count_latch;
2918      IRQ_enable = data & 0x02;
2919      IRQ_enable_latch = data & 0x01;
2920      break;
2921
2922   default:
2923      logerror("konami_vrc2b_w uncaught offset: %04x value: %02x\n", offset, data);
2924      break;
2925   }
2926}
2927
2928/*************************************************************
2929
2930    Mapper 24
2931
2932    Known Boards: Konami VRC6
2933    Games: Akumajou Densetsu
2934
2935    In MESS: Supported. It also uses konami_irq.
2936
2937*************************************************************/
2938
29242939static WRITE8_HANDLER( konami_vrc6a_w )
29252940{
2926//  logerror("konami_vrc6_w offset: %04x, data: %02x, scanline: %d\n", offset, data, current_scanline);
2941   UINT8 bank;
2942   LOG_MMC(("konami_vrc6a_w, offset: %04x, data: %02x\n", offset, data));
29272943
29282944   switch (offset & 0x7003)
29292945   {
2930      case 0: case 1: case 2: case 3:
2946      case 0x0000:
2947      case 0x0001:
2948      case 0x0002:
2949      case 0x0003:
29312950         /* Switch 16k bank at $8000 */
29322951         prg16_89ab(space->machine, data);
29332952         break;
r5926r5927
29452964            case 0x0c: set_nt_mirroring(PPU_MIRROR_HIGH); break;
29462965         }
29472966         break;
2948      case 0x4000: case 0x4001: case 0x4002: case 0x4003:
2967      case 0x4000:
2968      case 0x4001:
2969      case 0x4002:
2970      case 0x4003:
29492971         /* Switch 8k bank at $c000 */
29502972         prg8_cd(space->machine, data);
29512973         break;
r5926r5927
29532975      case 0x5001:
29542976      case 0x5002:
29552977      case 0x5003:
2956         /* switch 1k VROM at $0000-$0c00 */
2957         chr1_x(space->machine, offset&3, data, CHRROM);
2958         break;
2959
29602978      case 0x6000:
29612979      case 0x6001:
29622980      case 0x6002:
29632981      case 0x6003:
2964         /* switch 1k VROM at $1000-$1c00 */
2965         chr1_x(space->machine, (offset&3)+4, data, CHRROM);
2982         /* switch 1k vrom at $0000-$1c00 */
2983         bank = ((offset & 0x7000) - 0x5000) / 0x0400 + (offset & 0x0003);
2984         chr1_x(space->machine, bank, data, CHRROM);
29662985         break;
29672986
29682987      case 0x7000:
r5926r5927
29833002   }
29843003}
29853004
3005/*************************************************************
29863006
3007    Mapper 26
3008
3009    Known Boards: Konami VRC6 variant
3010    Games: Esper Dream 2, Mouryou Senki Madara
3011
3012    In MESS: Supported. It also uses konami_irq.
3013
3014*************************************************************/
3015
29873016static WRITE8_HANDLER( konami_vrc6b_w )
29883017{
2989// logerror("konami_vrc6_w offset: %04x, data: %02x, scanline: %d\n", offset, data, current_scanline);
3018   UINT8 bank;
29903019
3020   LOG_MMC(("konami_vrc6b_w, offset: %04x, data: %02x\n", offset, data));
3021
29913022   switch (offset & 0x7003)
29923023   {
29933024      case 0: case 1: case 2: case 3:
r5926r5927
30133044         prg8_cd(space->machine, data);
30143045         break;
30153046      case 0x5000:
3016         /* Switch 1k VROM at $0000 */
3017         chr1_0(space->machine,data, CHRROM);
3018         break;
3047      case 0x5001:
30193048      case 0x5002:
3020         /* Switch 1k VROM at $0400 */
3021         chr1_1(space->machine,data, CHRROM);
3022         break;
3023      case 0x5001:
3024         /* Switch 1k VROM at $0800 */
3025         chr1_2(space->machine,data, CHRROM);
3026         break;
30273049      case 0x5003:
3028         /* Switch 1k VROM at $0c00 */
3029         chr1_3(space->machine,data, CHRROM);
3030         break;
30313050      case 0x6000:
3032         /* Switch 1k VROM at $1000 */
3033         chr1_4(space->machine,data, CHRROM);
3034         break;
3051      case 0x6001:
30353052      case 0x6002:
3036         /* Switch 1k VROM at $1400 */
3037         chr1_5(space->machine,data, CHRROM);
3038         break;
3039      case 0x6001:
3040         /* Switch 1k VROM at $1800 */
3041         chr1_6(space->machine,data, CHRROM);
3042         break;
30433053      case 0x6003:
3044         /* Switch 1k VROM at $1c00 */
3045         chr1_7(space->machine,data, CHRROM);
3054         /* switch 1k vrom at $0000-$1c00 */
3055         bank = ((offset & 0x7000) - 0x5000) / 0x0400 + ((offset & 0x0001) << 1) + ((offset & 0x0002) >> 1);
3056         chr1_x(space->machine, bank, data, CHRROM);
30463057         break;
30473058      case 0x7000:
30483059         IRQ_count_latch = data;
r5926r5927
30623073   }
30633074}
30643075
3076/*************************************************************
3077
3078    Mapper 27
3079
3080    Known Boards: Unknown Bootleg Board
3081    Games: World Hero
3082
3083    In MESS: Unsupported.
3084
3085*************************************************************/
3086
3087/*************************************************************
3088
3089    Mapper 28
3090
3091    Known Boards: Undocumented / Unused ?!?
3092    Games: ----------
3093
3094    In MESS: ----------
3095
3096*************************************************************/
3097
3098/*************************************************************
3099
3100    Mapper 29
3101
3102    Known Boards: Undocumented / Unused ?!?
3103    Games: ----------
3104
3105    In MESS: ----------
3106
3107*************************************************************/
3108
3109/*************************************************************
3110
3111    Mapper 30
3112
3113    Known Boards: Undocumented / Unused ?!?
3114    Games: ----------
3115
3116    In MESS: ----------
3117
3118*************************************************************/
3119
3120/*************************************************************
3121
3122    Mapper 31
3123
3124    Known Boards: Undocumented / Unused ?!?
3125    Games: ----------
3126
3127    In MESS: ----------
3128
3129*************************************************************/
3130
3131/*************************************************************
3132
3133    Mapper 32
3134
3135    Known Boards: Irem G101A & G101B
3136    Games: Ai Sensei no Oshiete, Image Fight, Kaiketsu
3137          Yanchamaru 2, Maikyuu Shima, Paaman, Paaman 2
3138
3139    In MESS: Supported.
3140
3141*************************************************************/
3142
30653143static WRITE8_HANDLER( mapper32_w )
30663144{
3067   static int bankSel;
3145   LOG_MMC(("mapper32_w, offset: %04x, data: %02x\n", offset, data));
30683146
3069//  logerror("mapper32_w offset: %04x, data: %02x, scanline: %d\n", offset, data, current_scanline);
3070
30713147   switch (offset & 0x7000)
30723148   {
30733149      case 0x0000:
3074         /* Switch 8k bank at $8000 or $c000 */
3075         if (bankSel)
3076            prg8_cd(space->machine, data);
3077         else
3078            prg8_89(space->machine, data);
3150         mmc_cmd1 ? prg8_cd(space->machine, data) : prg8_89(space->machine, data);
30793151         break;
30803152      case 0x1000:
3081         bankSel = data & 0x02;
3082         if (data & 0x01)
3083            set_nt_mirroring(PPU_MIRROR_HORZ);
3084         else
3085            set_nt_mirroring(PPU_MIRROR_VERT);
3153         mmc_cmd1 = data & 0x02;
3154         set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
30863155         break;
30873156      case 0x2000:
30883157         /* Switch 8k bank at $A000 */
r5926r5927
30903159         break;
30913160      case 0x3000:
30923161         /* Switch 1k VROM at $1000 */
3093         chr1_x(space->machine, offset&7, data, CHRROM);
3162         chr1_x(space->machine, offset & 0x07, data, CHRROM);
30943163         break;
30953164      default:
30963165         logerror("Uncaught mapper 32 write, addr: %04x value: %02x\n", offset + 0x8000, data);
r5926r5927
30983167   }
30993168}
31003169
3170/*************************************************************
3171
3172    Mapper 33
3173
3174    Known Boards: Taito TC0190FMC
3175    Games: Akira, Bakushou!! Jinsei Gekijou, Don Doko Don,
3176          Insector X, Operation Wolf, Power Blazer, Takeshi no
3177          Sengoku Fuuunji
3178
3179    In MESS: Supported.
3180
3181*************************************************************/
3182
31013183static WRITE8_HANDLER( mapper33_w )
31023184{
3103//  logerror("mapper33_w offset: %04x, data: %02x, scanline: %d\n", offset, data, current_scanline);
3185   LOG_MMC(("mapper33_w, offset: %04x, data: %02x\n", offset, data));
31043186
31053187   switch (offset & 0x7003)
31063188   {
31073189      case 0x0000:
3108         /* Switch 8k bank at $8000 */
3109         data &= ((nes.prg_chunks << 1) - 1);
3110         memory_set_bankptr(space->machine, 1, &nes.rom[0x2000 * (data) + 0x10000]);
3190         set_nt_mirroring((data & 0x40) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
3191         prg8_89(space->machine, data);
31113192         break;
31123193      case 0x0001:
3113         /* Switch 8k bank at $A000 */
3114         data &= ((nes.prg_chunks << 1) - 1);
3115         memory_set_bankptr(space->machine, 2, &nes.rom[0x2000 * (data) + 0x10000]);
3194         prg8_ab(space->machine, data);
31163195         break;
31173196      case 0x0002:
3118         /* Switch 2k VROM at $0000 */
31193197         chr2_0(space->machine, data, CHRROM);
31203198         break;
31213199      case 0x0003:
3122         /* Switch 2k VROM at $0800 */
31233200         chr2_2(space->machine, data, CHRROM);
31243201         break;
31253202      case 0x2000:
3126         /* Switch 1k VROM at $1000 */
31273203         chr1_4(space->machine, data, CHRROM);
31283204         break;
31293205      case 0x2001:
3130         /* Switch 1k VROM at $1400 */
31313206         chr1_5(space->machine, data, CHRROM);
31323207         break;
31333208      case 0x2002:
3134         /* Switch 1k VROM at $1800 */
31353209         chr1_6(space->machine, data, CHRROM);
31363210         break;
31373211      case 0x2003:
3138         /* Switch 1k VROM at $1c00 */
31393212         chr1_7(space->machine, data, CHRROM);
31403213         break;
3141      default:
3142         logerror("Uncaught mapper 33 write, addr: %04x value: %02x\n", offset + 0x8000, data);
3143         break;
31443214   }
31453215}
31463216
3217/*************************************************************
3218
3219    Mapper 34
3220
3221    Known Boards: BNROM, Unlicensed BxROM, NINA001, NINA002
3222    Games: Deadly Tower, Impossible Mission II, Titanic 1912,
3223          Dance Xtreme
3224
3225    In MESS: Supported.
3226
3227*************************************************************/
3228
31473229static WRITE8_HANDLER( mapper34_m_w )
31483230{
3149   logerror("mapper34_m_w, offset: %04x, data: %02x\n", offset, data);
3231   LOG_MMC(("mapper34_m_w, offset: %04x, data: %02x\n", offset, data));
31503232
31513233   switch (offset)
31523234   {
r5926r5927
31563238         break;
31573239      case 0x1ffe:
31583240         /* Switch 4k VNES_ROM at 0x0000 */
3159         chr4_0 (space->machine, data, CHRROM);
3241         chr4_0(space->machine, data, CHRROM);
31603242         break;
31613243      case 0x1fff:
31623244         /* Switch 4k VNES_ROM at 0x1000 */
3163         chr4_4 (space->machine, data, CHRROM);
3245         chr4_4(space->machine, data, CHRROM);
31643246         break;
31653247   }
31663248}
31673249
3168
31693250static WRITE8_HANDLER( mapper34_w )
31703251{
31713252   /* This portion of the mapper is nearly identical to Mapper 7, except no one-screen mirroring */
31723253   /* Deadly Towers is really a Mapper 34 game - the demo screens look wrong using mapper 7. */
3173   logerror("Mapper 34 w, offset: %04x, data: %02x\n", offset, data);
3254   LOG_MMC(("mapper34_w, offset: %04x, data: %02x\n", offset, data));
31743255
31753256   prg32(space->machine, data);
31763257}
31773258
3259/*************************************************************
3260
3261    Mapper 35
3262
3263    Known Boards: Undocumented / Unused ?!?
3264    Games: ----------
3265
3266    In MESS: ----------
3267
3268*************************************************************/
3269
3270/*************************************************************
3271
3272    Mapper 36
3273
3274    Known Boards: Bootleg Board by TXC
3275    Games: Strike Wolf (also Policeman?? according to Nestopia)
3276
3277    In MESS: Supported.
3278
3279*************************************************************/
3280
3281static WRITE8_HANDLER( mapper36_w )
3282{
3283   LOG_MMC(("mapper36_w, offset: %04x, data: %02x\n", offset, data));
3284
3285   if ((offset >= 0x400) && (offset < 0x7fff))
3286   {
3287      prg32(space->machine, data >> 4);
3288      chr8(space->machine, data & 0x0f, CHRROM);
3289   }
3290}
3291
3292/*************************************************************
3293
3294    Mapper 37
3295
3296    Known Boards: Custom ZZ??
3297    Games: Super Mario Bros. + Tetris + Nintendo World Cup (E)
3298
3299    MMC3 clone
3300
3301    In MESS: Unsupported.
3302
3303*************************************************************/
3304
3305/*************************************************************
3306
3307    Mapper 38
3308
3309    Known Boards: Discrete Logic Board
3310    Games: Crime Busters
3311
3312    In MESS: Supported.
3313
3314*************************************************************/
3315
3316static WRITE8_HANDLER( mapper38_m_w )
3317{
3318   LOG_MMC(("mapper38_m_w, offset: %04x, data: %02x\n", offset, data));
3319
3320   prg32(space->machine, data);
3321   chr8(space->machine, data >> 4, CHRROM);
3322}
3323
3324/*************************************************************
3325
3326    Mapper 39
3327
3328    Known Boards: Bootleg Board by Subor
3329    Games: Study n Game 32 in 1
3330
3331    In MESS: Partially Supported.
3332
3333*************************************************************/
3334
3335static WRITE8_HANDLER( mapper39_w )
3336{
3337   LOG_MMC(("mapper39_w, offset: %04x, data: %02x\n", offset, data));
3338
3339   prg32(space->machine, data);
3340}
3341
3342/*************************************************************
3343
3344    Mapper 40
3345
3346    Known Boards: Unknown Bootleg Board
3347    Games: Super Mario Bros. 2 Lost Levels Pirate
3348
3349    In MESS: Supported.
3350
3351*************************************************************/
3352
31783353static void mapper40_irq( const device_config *device, int scanline, int vblank, int blanked )
31793354{
31803355   /* Decrement & check the IRQ scanline counter */
r5926r5927
31893364
31903365static WRITE8_HANDLER( mapper40_w )
31913366{
3192   logerror("mapper40_w, offset: %04x, data: %02x\n", offset, data);
3367   LOG_MMC(("mapper40_w, offset: %04x, data: %02x\n", offset, data));
31933368
31943369   switch (offset & 0x6000)
31953370   {
r5926r5927
32073382   }
32083383}
32093384
3385/*************************************************************
3386
3387    Mapper 41
3388
3389    Known Boards: Caltron Board
3390    Games: 6 in 1 by Caltron
3391
3392    In MESS: Supported.
3393
3394*************************************************************/
3395
32103396static WRITE8_HANDLER( mapper41_m_w )
32113397{
32123398   LOG_MMC(("mapper41_m_w, offset: %04x, data: %02x\n", offset, data));
32133399
3214   if (offset & 0x20)
3215      set_nt_mirroring(PPU_MIRROR_HORZ);
3216   else
3217      set_nt_mirroring(PPU_MIRROR_VERT);
3218
3219   mapper41_reg2 = offset & 0x04;
3220   mapper41_chr &= ~0x0c;
3221   mapper41_chr |= (offset & 0x18) >> 1;
3400   mmc_cmd1 = offset & 0xff;
3401   set_nt_mirroring((offset & 0x20) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
32223402   prg32(space->machine, offset & 0x07);
32233403}
32243404
r5926r5927
32263406{
32273407   LOG_MMC(("mapper41_w, offset: %04x, data: %02x\n", offset, data));
32283408
3229   if (mapper41_reg2)
3230   {
3231      mapper41_chr &= ~0x03;
3232      mapper41_chr |= data & 0x03;
3233      chr8(space->machine, mapper41_chr, CHRROM);
3234   }
3409   if (mmc_cmd1 & 0x04)
3410      chr8(space->machine, ((mmc_cmd1 & 0x18) >> 1) | (data & 0x03), CHRROM);
32353411}
32363412
3413/*************************************************************
3414
3415    Mapper 42
3416
3417    Known Boards: Unknown Bootleg Board
3418    Games: Mario Baby, Ai Senshi Nicol
3419
3420    In MESS: Supported.
3421
3422*************************************************************/
3423
32373424static WRITE8_HANDLER( mapper42_w )
32383425{
32393426   LOG_MMC(("mapper42_w, offset: %04x, data: %02x\n", offset, data));
r5926r5927
32653452   }
32663453}
32673454
3455/*************************************************************
3456
3457    Mapper 43
3458
3459    Known Boards: Unknown Bootleg Board
3460    Games: Super Mario Bros. 2 Pirate (LF36)
3461
3462    In MESS: Supported.
3463
3464*************************************************************/
3465
32683466static WRITE8_HANDLER( mapper43_w )
32693467{
32703468   int bank = (((offset >> 8) & 0x03) * 0x20) + (offset & 0x1f);
r5926r5927
33193517   }
33203518}
33213519
3520/*************************************************************
3521
3522    Mapper 44
3523
3524    Known Boards: Unknown Multigame Bootleg Board
3525    Games: Kunio 8 in 1, Super Big 7 in 1
3526
3527    In MESS: Supported. It also uses mapper4_irq.
3528
3529*************************************************************/
3530
33223531static WRITE8_HANDLER( mapper44_w )
33233532{
3324//  logerror("mapper44_w offset: %04x, data: %02x, scanline: %d\n", offset, data, current_scanline);
3533//  LOG_MMC(("mapper44_w offset: %04x, data: %02x, scanline: %d\n", offset, data, current_scanline));
33253534
33263535   //only bits 14,13, and 0 matter for offset!
33273536   switch (offset & 0x6001)
r5926r5927
33373546         MMC3_chr_mask = (page > 5) ? 0xff : 0x7f;
33383547      }
33393548      mapper4_set_prg(space->machine);
3340      mapper4_set_chr(space->machine, MMC3_chr_source);
3549      mapper4_set_chr(space->machine, mmc_chr_source);
33413550      break;
33423551
33433552   default:
r5926r5927
33463555   }
33473556}
33483557
3558/*************************************************************
3559
3560    Mapper 45
3561
3562    Known Boards: Unknown Multigame Bootleg Board
3563    Games: Street Fighter V, various multigame carts
3564
3565    In MESS: Supported. It also uses mapper4_irq.
3566
3567*************************************************************/
3568
33493569static WRITE8_HANDLER( mapper45_m_w )
33503570{
33513571   LOG_MMC(("mapper45_m_w, offset: %04x, data: %02x\n", offset, data));
r5926r5927
33703590            MMC3_chr_mask = 0;
33713591
33723592         mapper4_set_prg(space->machine);
3373         mapper4_set_chr(space->machine, MMC3_chr_source);
3593         mapper4_set_chr(space->machine, mmc_chr_source);
33743594      }
33753595   }
33763596   if (mapper45_data[3] & 0x40)
33773597      nes.wram[offset] = data;
33783598}
33793599
3600/*************************************************************
3601
3602    Mapper 46
3603
3604    Known Boards: Rumblestation Board
3605    Games: Rumblestation 15 in 1
3606
3607    In MESS: Partially Supported.
3608
3609*************************************************************/
3610
33803611static WRITE8_HANDLER( mapper46_m_w )
33813612{
33823613   LOG_MMC(("mapper46_m_w, offset: %04x, data: %02x\n", offset, data));
33833614
3384   MMC1_bank1 = (MMC1_bank1 & 0x01) | ((data & 0x0f) << 1);
3385   MMC1_bank2 = (MMC1_bank2 & 0x07) | ((data & 0xf0) >> 1);
3386   prg32(space->machine, MMC1_bank1);
3387   chr8(space->machine, MMC1_bank2, CHRROM);
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);
33883619}
33893620
33903621static WRITE8_HANDLER( mapper46_w )
33913622{
33923623   LOG_MMC(("mapper46_w, offset: %04x, data: %02x\n", offset, data));
33933624
3394   MMC1_bank1 = (MMC1_bank1 & ~0x01) | ((data & 0x02) >> 1);
3395   MMC1_bank2 = (MMC1_bank2 & ~0x07) | ((data & 0x70) >> 4);
3396   prg32(space->machine, MMC1_bank1);
3397   chr8(space->machine, MMC1_bank2, CHRROM);
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);
33983629}
33993630
3631/*************************************************************
3632
3633    Mapper 47
3634
3635    Known Boards: Custom QJ??
3636    Games: Super Spike V'Ball + Nintendo World Cup
3637
3638    In MESS: Supported. It also uses mapper4_irq.
3639
3640*************************************************************/
3641
34003642static WRITE8_HANDLER( mapper47_m_w )
34013643{
34023644   LOG_MMC(("mapper47_m_w, offset: %04x, data: %02x\n", offset, data));
r5926r5927
34083650      MMC3_chr_base = (data & 0x01) << 7;
34093651      MMC3_chr_mask = 0x7f;
34103652      mapper4_set_prg(space->machine);
3411      mapper4_set_chr(space->machine, MMC3_chr_source);
3653      mapper4_set_chr(space->machine, mmc_chr_source);
34123654   }
34133655}
34143656
3657/*************************************************************
3658
3659    Mapper 48
3660
3661    Known Boards: Taito TC0190FMC PAL16R4
3662    Games: Bakushou!! Jinsei Gekijou 3, Bubble Bobble 2,
3663          Captain Saver, Don Doko Don 2, Flintstones, Jetsons
3664
3665    In MESS: Unsupported.
3666
3667*************************************************************/
3668
3669/*************************************************************
3670
3671    Mapper 49
3672
3673    Known Boards: Unknown Multigame Bootleg Board
3674    Games: Super HIK 4 in 1
3675
3676    In MESS: Supported. It also uses mapper4_irq.
3677
3678*************************************************************/
3679
34153680static WRITE8_HANDLER( mapper49_m_w )
34163681{
34173682   LOG_MMC(("mapper49_m_w, offset: %04x, data: %02x\n", offset, data));
r5926r5927
34233688      MMC3_chr_base = (data & 0xc0) << 1;
34243689      MMC3_chr_mask = 0x7f;
34253690      mapper4_set_prg(space->machine);
3426      mapper4_set_chr(space->machine, MMC3_chr_source);
3691      mapper4_set_chr(space->machine, mmc_chr_source);
34273692   }
34283693}
34293694
3695/*************************************************************
3696
3697    Mapper 50
3698
3699    Known Boards: Unknown Bootleg Board
3700    Games: Super Mario Bros. Pirate Alt. Levels
3701
3702    In MESS: Unsupported.
3703
3704*************************************************************/
3705
3706/*************************************************************
3707
3708    Mapper 51
3709
3710    Known Boards: Unknown Multigame Bootleg Board
3711    Games: 11 in 1 Ball Games
3712
3713    In MESS: Supported.
3714
3715*************************************************************/
3716
34303717static void mapper51_set_banks( running_machine *machine )
34313718{
34323719   set_nt_mirroring((MMC1_bank1 == 3) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
r5926r5927
34653752   mapper51_set_banks(space->machine);
34663753}
34673754
3755/*************************************************************
3756
3757    Mapper 52
3758
3759    Known Boards: Unknown Multigame Bootleg Board
3760    Games: Mario 7 in 1
3761
3762    MMC3 clone
3763
3764    In MESS: Unsupported.
3765
3766*************************************************************/
3767
3768/*************************************************************
3769
3770    Mapper 53
3771
3772    Known Boards: Unknown Multigame Bootleg Board
3773    Games: Supervision 16 in 1
3774
3775    In MESS: Unsupported.
3776
3777*************************************************************/
3778
3779/*************************************************************
3780
3781    Mapper 54
3782
3783    Known Boards: Unknown Multigame Bootleg Board
3784    Games: [no games in nes.hsi]
3785
3786    In MESS: Unsupported.
3787
3788*************************************************************/
3789
3790/*************************************************************
3791
3792    Mapper 55
3793
3794    Known Boards: Unknown Bootleg Board
3795    Games: [no games in nes.hsi]
3796
3797    In MESS: Unsupported.
3798
3799*************************************************************/
3800
3801/*************************************************************
3802
3803    Mapper 56
3804
3805    Known Boards: Bootleg Board by Kaiser (KS202)
3806    Games: Super Mario Bros. 3 Pirate
3807
3808    In MESS: Unsupported.
3809
3810*************************************************************/
3811
3812/*************************************************************
3813
3814    Mapper 57
3815
3816    Known Boards: Unknown Multigame Bootleg Board
3817    Games: 6 in 1, 54 in 1, 106 in 1
3818
3819    In MESS: Supported.
3820
3821*************************************************************/
3822
34683823static WRITE8_HANDLER( mapper57_w )
34693824{
34703825   LOG_MMC(("mapper57_w, offset: %04x, data: %02x\n", offset, data));
34713826
34723827   if (offset & 0x0800)
34733828   {
3474      MMC1_bank2 = data;
3829      mmc_cmd2 = data;
34753830   }
34763831   else
34773832   {
3478      MMC1_bank1 = data;
3833      mmc_cmd1 = data;
34793834   }
34803835
3481   if (MMC1_bank2 & 0x80)
3836   if (mmc_cmd2 & 0x80)
34823837   {
3483      prg32(space->machine, 2 | (MMC1_bank2 >> 6));
3838      prg32(space->machine, 2 | (mmc_cmd2 >> 6));
34843839   }
34853840   else
34863841   {
3487      prg16_89ab(space->machine, (MMC1_bank2 >> 5) & 0x03);
3488      prg16_cdef(space->machine, (MMC1_bank2 >> 5) & 0x03);
3842      prg16_89ab(space->machine, (mmc_cmd2 >> 5) & 0x03);
3843      prg16_cdef(space->machine, (mmc_cmd2 >> 5) & 0x03);
34893844   }
34903845
3491   set_nt_mirroring((MMC1_bank2 & 0x08) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
3846   set_nt_mirroring((mmc_cmd2 & 0x08) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
34923847
3493   chr8(space->machine, (MMC1_bank1 & 0x03) | (MMC1_bank2 & 0x07) | ((MMC1_bank2 & 0x10) >> 1), CHRROM);
3848   chr8(space->machine, (mmc_cmd1 & 0x03) | (mmc_cmd2 & 0x07) | ((mmc_cmd2 & 0x10) >> 1), CHRROM);
34943849}
34953850
3851/*************************************************************
3852
3853    Mapper 58
3854
3855    Known Boards: Unknown Multigame Bootleg Board
3856    Games: 68 in 1, 73 in 1, 98 in 1
3857
3858    In MESS: Supported.
3859
3860*************************************************************/
3861
34963862static WRITE8_HANDLER( mapper58_w )
34973863{
3864   UINT8 bank = (offset & 0x40) ? 0 : 1;
34983865   LOG_MMC(("mapper58_w, offset: %04x, data: %02x\n", offset, data));
34993866
3500   if (offset & 0x4000)
3501   {
3502      if (offset & 0x40)
3503      {
3504         prg16_89ab(space->machine, offset & 0x07);
3505         prg16_cdef(space->machine, offset & 0x07);
3506      }
3507      else
3508      {
3509         prg32(space->machine, (offset & 0x06) >> 1);
3510      }
3867   prg16_89ab(space->machine, offset & ~bank);
3868   prg16_cdef(space->machine, offset | bank);
3869   chr8(space->machine, offset >> 3, CHRROM);
3870   set_nt_mirroring((data & 0x80) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
3871}
35113872
3512      chr8(space->machine, (offset & 0x38) >> 3, CHRROM);
3873/*************************************************************
35133874
3514      set_nt_mirroring((data & 0x02) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
3515   }
3516}
3875    Mapper 59
35173876
3877    Known Boards: Undocumented / Unused ?!?
3878    Games: ----------
3879
3880    In MESS: ----------
3881
3882*************************************************************/
3883
3884/*************************************************************
3885
3886    Mapper 60
3887
3888    Known Boards: Unknown Multigame Bootleg Board
3889    Games: 4 in 1, 35 in 1
3890
3891    In MESS: Unsupported.
3892
3893*************************************************************/
3894
3895/*************************************************************
3896
3897    Mapper 61
3898
3899    Known Boards: Bootleg Board by RCM
3900    Games: Tetris Family 9 in 1, 20 in 1
3901
3902    Simple Mapper: prg/chr/nt are swapped depending on the offset
3903    of writes in 0x8000-0xffff. offset&0x80 set NT mirroring,
3904    when (offset&0x30) is 0,3 prg32 is set; when it is 1,2
3905    two 16k prg banks are set. See below for the values used in
3906    these banks.
3907
3908    In MESS: Supported.
3909
3910*************************************************************/
3911
35183912static WRITE8_HANDLER( mapper61_w )
35193913{
35203914   LOG_MMC(("mapper61_w, offset: %04x, data: %02x\n", offset, data));
r5926r5927
35343928   set_nt_mirroring((offset & 0x80) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
35353929}
35363930
3931/*************************************************************
3932
3933    Mapper 62
3934
3935    Known Boards: Unknown Multigame Bootleg Board
3936    Games: Super 700 in 1
3937
3938    In MESS: Supported.
3939
3940*************************************************************/
3941
35373942static WRITE8_HANDLER( mapper62_w )
35383943{
35393944   LOG_MMC(("mapper62_w, offset :%04x, data: %02x\n", offset, data));
r5926r5927
35533958   set_nt_mirroring((offset & 0x80) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
35543959}
35553960
3961/*************************************************************
3962
3963    Mapper 63
3964
3965    Known Boards: Unknown Multigame Bootleg Board
3966    Games: [no games in nes.hsi]
3967
3968    In MESS: Unsupported.
3969
3970*************************************************************/
3971
3972/*************************************************************
3973
3974    Mapper 64
3975
3976    Known Boards: Tengen 800032
3977    Games: Klax, Road Runner, Rolling Thunder, Shinobi, Skulls
3978          & Croosbones, Xybots
3979
3980    In MESS: Supported. It also uses mapper4_irq.
3981
3982*************************************************************/
3983
35563984static void mapper64_set_banks( running_machine *machine )
35573985{
35583986   if (mapper64_cmd & 0x20)
r5926r5927
35824010
35834011static WRITE8_HANDLER( mapper64_m_w )
35844012{
3585   logerror("mapper64_m_w, offset: %04x, data: %02x\n", offset, data);
4013   LOG_MMC(("mapper64_m_w, offset: %04x, data: %02x\n", offset, data));
35864014}
35874015
35884016static WRITE8_HANDLER( mapper64_w )
35894017{
35904018/* TODO: something in the IRQ handling hoses Skull & Crossbones */
35914019
3592//  logerror("mapper64_w offset: %04x, data: %02x, scanline: %d\n", offset, data, current_scanline);
4020//  LOG_MMC(("mapper64_w offset: %04x, data: %02x, scanline: %d\n", offset, data, current_scanline));
35934021
35944022   switch (offset & 0x7001)
35954023   {
r5926r5927
36214049         if (0)
36224050            IRQ_count = IRQ_count_latch;
36234051
3624         logerror("     MMC3 copy/set irq latch: %02x\n", data);
4052         LOG_MMC(("     MMC3 copy/set irq latch: %02x\n", data));
36254053         break;
36264054
36274055      case 0x4001: /* $c001 - IRQ scanline latch */
36284056         IRQ_count = IRQ_count_latch;
36294057         IRQ_mode = data & 0x01;
3630         logerror("     MMC3 set latch: %02x\n", data);
4058         LOG_MMC(("     MMC3 set latch: %02x\n", data));
36314059         break;
36324060
36334061      case 0x6000: /* $e000 - Disable IRQs */
r5926r5927
36354063         if (0)
36364064            IRQ_count = IRQ_count_latch;
36374065
3638         logerror("     MMC3 disable irqs: %02x\n", data);
4066         LOG_MMC(("     MMC3 disable irqs: %02x\n", data));
36394067         break;
36404068
36414069      case 0x6001: /* $e001 - Enable IRQs */
r5926r5927
36434071         if (0)
36444072            IRQ_count = IRQ_count_latch;
36454073
3646         logerror("     MMC3 enable irqs: %02x\n", data);
4074         LOG_MMC(("     MMC3 enable irqs: %02x\n", data));
36474075         break;
36484076
36494077      default:
3650         logerror("Mapper 64 addr: %04x value: %02x\n", offset + 0x8000, data);
4078         LOG_MMC(("Mapper 64 write. addr: %04x value: %02x\n", offset + 0x8000, data));
36514079         break;
36524080   }
36534081}
36544082
4083/*************************************************************
4084
4085    Mapper 65
4086
4087    Known Boards: Irem H3001
4088    Games: Daiku no Gen San 2 - Akage no Dan no Gyakushuu,
4089          Kaiketsu Yanchamaru 3, Spartan X 2
4090
4091    In MESS: Supported.
4092
4093*************************************************************/
4094
36554095static void irem_irq( const device_config *device, int scanline, int vblank, int blanked )
36564096{
36574097   /* Increment & check the IRQ scanline counter */
r5926r5927
36624102   }
36634103}
36644104
3665
3666
36674105static WRITE8_HANDLER( mapper65_w )
36684106{
4107   LOG_MMC(("mapper65_w, offset %04x, data: %02x\n", offset, data));
4108
36694109   switch (offset & 0x7007)
36704110   {
36714111      case 0x0000:
r5926r5927
37154155         break;
37164156
37174157      default:
3718         logerror("Mapper 65 addr: %04x value: %02x\n", offset + 0x8000, data);
4158         LOG_MMC(("Mapper 65 addr: %04x value: %02x\n", offset + 0x8000, data));
37194159         break;
37204160   }
37214161}
37224162
4163/*************************************************************
4164
4165    Mapper 66
4166
4167    Known Boards: GNROM, GXROM, MHROM
4168    Games: Mobile Suit Z Gundam, Paris-Dakar Rally Special,
4169          Takahashi Meijin no Bugutte Honey
4170
4171    In MESS: Supported.
4172
4173*************************************************************/
4174
37234175static WRITE8_HANDLER( mapper66_w )
37244176{
3725   LOG_MMC(("* Mapper 66 switch, offset %04x, data: %02x\n", offset, data));
4177   LOG_MMC(("mapper66_w, offset %04x, data: %02x\n", offset, data));
37264178
37274179   prg32(space->machine, (data & 0x30) >> 4);
37284180   chr8(space->machine, data & 0x03, CHRROM);
37294181}
37304182
3731static void sunsoft_irq( const device_config *device, int scanline, int vblank, int blanked )
3732{
3733   /* 114 is the number of cycles per scanline */
3734   /* TODO: change to reflect the actual number of cycles spent */
4183/*************************************************************
37354184
3736   if (IRQ_enable)
3737   {
3738      if (IRQ_count <= 114)
3739      {
3740         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
3741      }
3742      IRQ_count -= 114;
3743   }
3744}
4185    Mapper 67
37454186
4187    Known Boards: Sunsoft 3
4188    Games: Fantasy Zone 2, Mito Koumon
37464189
4190    In MESS: Supported. It also uses mapper4_irq.
4191
4192*************************************************************/
4193
37474194static WRITE8_HANDLER( mapper67_w )
37484195{
3749//  logerror("mapper67_w, offset %04x, data: %02x\n", offset, data);
4196   LOG_MMC(("mapper67_w, offset %04x, data: %02x\n", offset, data));
37504197   switch (offset & 0x7801)
37514198   {
37524199//      case 0x0000: /* IRQ acknowledge */
r5926r5927
37934240         prg16_89ab(space->machine, data);
37944241         break;
37954242      default:
3796         logerror("mapper67_w uncaught offset: %04x, data: %02x\n", offset, data);
4243         LOG_MMC(("mapper67_w uncaught offset: %04x, data: %02x\n", offset, data));
37974244         break;
37984245
37994246   }
38004247}
38014248
3802static void mapper68_mirror (running_machine *machine, int m68_mirror, int m0, int m1)
4249/*************************************************************
4250
4251    Mapper 68
4252
4253    Known Boards: Sunsoft 4, Sunsoft with DCS, NTBROM, Tengen 800042
4254    Games: After Burner, After Burner II, Maharaja
4255
4256    In MESS: Supported.
4257
4258*************************************************************/
4259
4260static void mapper68_mirror( running_machine *machine, int m68_mirror, int m0, int m1 )
38034261{
38044262   /* The 0x20000 (128k) offset is a magic number */
38054263   #define M68_OFFSET 0x20000
38064264
38074265   switch (m68_mirror)
38084266   {
3809      case 0x00: set_nt_mirroring(PPU_MIRROR_HORZ); break;
3810      case 0x01: set_nt_mirroring(PPU_MIRROR_VERT); break;
3811      case 0x02: set_nt_mirroring(PPU_MIRROR_LOW); break;
3812      case 0x03: set_nt_mirroring(PPU_MIRROR_HIGH); break;
4267      case 0x00:
4268         set_nt_mirroring(PPU_MIRROR_HORZ);
4269         break;
4270      case 0x01:
4271         set_nt_mirroring(PPU_MIRROR_VERT);
4272         break;
4273      case 0x02:
4274         set_nt_mirroring(PPU_MIRROR_LOW);
4275         break;
4276      case 0x03:
4277         set_nt_mirroring(PPU_MIRROR_HIGH);
4278         break;
38134279      case 0x10:
3814         ppu_mirror_custom_vrom (0, m0|0x80); //(m0 << 10) + M68_OFFSET);
3815         ppu_mirror_custom_vrom (1, m1|0x80);//(m1 << 10) + M68_OFFSET);
3816         ppu_mirror_custom_vrom (2, m0|0x80);//(m0 << 10) + M68_OFFSET);
3817         ppu_mirror_custom_vrom (3, m1|0x80);//(m1 << 10) + M68_OFFSET);
4280         set_nt_page(0, ROM, m0 | 0x80, 0);   //(m0 << 10) + M68_OFFSET);
4281         set_nt_page(1, ROM, m1 | 0x80, 0);   //(m1 << 10) + M68_OFFSET);
4282         set_nt_page(2, ROM, m0 | 0x80, 0);   //(m0 << 10) + M68_OFFSET);
4283         set_nt_page(3, ROM, m1 | 0x80, 0);   //(m1 << 10) + M68_OFFSET);
38184284         break;
38194285      case 0x11:
3820         ppu_mirror_custom_vrom (0, m0|0x80);//(m0 << 10) + M68_OFFSET);
3821         ppu_mirror_custom_vrom (1, m0|0x80);//(m0 << 10) + M68_OFFSET);
3822         ppu_mirror_custom_vrom (2, m1|0x80);//(m1 << 10) + M68_OFFSET);
3823         ppu_mirror_custom_vrom (3, m1|0x80);//(m1 << 10) + M68_OFFSET);
4286         set_nt_page(0, ROM, m0 | 0x80, 0);   //(m0 << 10) + M68_OFFSET);
4287         set_nt_page(1, ROM, m0 | 0x80, 0);   //(m0 << 10) + M68_OFFSET);
4288         set_nt_page(2, ROM, m1 | 0x80, 0);   //(m1 << 10) + M68_OFFSET);
4289         set_nt_page(3, ROM, m1 | 0x80, 0);   //(m1 << 10) + M68_OFFSET);
38244290         break;
38254291      case 0x12:
3826         ppu_mirror_custom_vrom (0,  m0|0x80);//(m0 << 10) + M68_OFFSET);
3827         ppu_mirror_custom_vrom (1,  m0|0x80);//(m0 << 10) + M68_OFFSET);
3828         ppu_mirror_custom_vrom (2,  m0|0x80);//(m0 << 10) + M68_OFFSET);
3829         ppu_mirror_custom_vrom (3,  m0|0x80);//(m0 << 10) + M68_OFFSET);
4292         set_nt_page(0, ROM, m0 | 0x80, 0);   //(m0 << 10) + M68_OFFSET);
4293         set_nt_page(1, ROM, m0 | 0x80, 0);   //(m0 << 10) + M68_OFFSET);
4294         set_nt_page(2, ROM, m0 | 0x80, 0);   //(m0 << 10) + M68_OFFSET);
4295         set_nt_page(3, ROM, m0 | 0x80, 0);   //(m0 << 10) + M68_OFFSET);
38304296         break;
38314297      case 0x13:
3832         ppu_mirror_custom_vrom (0, m1|0x80);//(m1 << 10) + M68_OFFSET);
3833         ppu_mirror_custom_vrom (1, m1|0x80);//(m1 << 10) + M68_OFFSET);
3834         ppu_mirror_custom_vrom (2, m1|0x80);//(m1 << 10) + M68_OFFSET);
3835         ppu_mirror_custom_vrom (3, m1|0x80);//(m1 << 10) + M68_OFFSET);
4298         set_nt_page(0, ROM, m1 | 0x80, 0);   //(m1 << 10) + M68_OFFSET);
4299         set_nt_page(1, ROM, m1 | 0x80, 0);   //(m1 << 10) + M68_OFFSET);
4300         set_nt_page(2, ROM, m1 | 0x80, 0);   //(m1 << 10) + M68_OFFSET);
4301         set_nt_page(3, ROM, m1 | 0x80, 0);   //(m1 << 10) + M68_OFFSET);
38364302         break;
38374303   }
38384304}
r5926r5927
38424308   static int m68_mirror;
38434309   static int m0, m1;
38444310
4311   LOG_MMC(("mapper68_w, offset %04x, data: %02x\n", offset, data));
4312
38454313   switch (offset & 0x7000)
38464314   {
38474315      case 0x0000:
38484316         /* Switch 2k VROM at $0000 */
3849         chr2_0 (space->machine, data, CHRROM);
4317         chr2_0(space->machine, data, CHRROM);
38504318         break;
38514319      case 0x1000:
38524320         /* Switch 2k VROM at $0800 */
3853         chr2_2 (space->machine, data, CHRROM);
4321         chr2_2(space->machine, data, CHRROM);
38544322         break;
38554323      case 0x2000:
38564324         /* Switch 2k VROM at $1000 */
3857         chr2_4 (space->machine, data, CHRROM);
4325         chr2_4(space->machine, data, CHRROM);
38584326         break;
38594327      case 0x3000:
38604328         /* Switch 2k VROM at $1800 */
3861         chr2_6 (space->machine, data, CHRROM);
4329         chr2_6(space->machine, data, CHRROM);
38624330         break;
38634331      case 0x4000:
3864         m0 = data&0x7F;
3865         mapper68_mirror (space->machine, m68_mirror, m0, m1);
4332         m0 = data & 0x7f;
4333         mapper68_mirror(space->machine, m68_mirror, m0, m1);
38664334         break;
38674335      case 0x5000:
3868         m1 = data&0x7F;
3869         mapper68_mirror (space->machine, m68_mirror, m0, m1);
4336         m1 = data & 0x7f;
4337         mapper68_mirror(space->machine, m68_mirror, m0, m1);
38704338         break;
38714339      case 0x6000:
38724340         m68_mirror = data & 0x13;
3873         mapper68_mirror (space->machine, m68_mirror, m0, m1);
4341         mapper68_mirror(space->machine, m68_mirror, m0, m1);
38744342         break;
38754343      case 0x7000:
38764344         prg16_89ab(space->machine, data);
38774345         break;
38784346      default:
3879         logerror("mapper68_w uncaught offset: %04x, data: %02x\n", offset, data);
4347         LOG_MMC(("mapper68_w uncaught offset: %04x, data: %02x\n", offset, data));
38804348         break;
4349   }
4350}
38814351
4352/*************************************************************
4353
4354    Mapper 69
4355
4356    Known Boards: JLROM, JSROM, Sunsoft 5B, Sunsoft FME7 and
4357         Custom
4358    Games: Barcode World, Batman - Return of the Joker, Gimmick!,
4359          Splatter House - Wanpaku Graffiti
4360
4361    In MESS: Supported.
4362
4363*************************************************************/
4364
4365/* should this be used for Mapper 67 as well?!? */
4366static void sunsoft_irq( const device_config *device, int scanline, int vblank, int blanked )
4367{
4368   /* 114 is the number of cycles per scanline */
4369   /* TODO: change to reflect the actual number of cycles spent */
4370
4371   if (IRQ_enable)
4372   {
4373      if (IRQ_count <= 114)
4374      {
4375         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
4376      }
4377      IRQ_count -= 114;
38824378   }
38834379}
38844380
38854381static WRITE8_HANDLER( mapper69_w )
38864382{
38874383   static int cmd = 0;
4384   LOG_MMC(("mapper69_w, offset %04x, data: %02x\n", offset, data));
38884385
3889//  logerror("mapper69_w offset: %04x, data: %02x, scanline: %d\n", offset, data, current_scanline);
3890
38914386   switch (offset & 0x7000)
38924387   {
38934388      case 0x0000:
r5926r5927
39114406               }
39124407               else
39134408#endif
3914                  logerror ("mapper69_w, cmd 8, data: %02x\n", data);
4409                  LOG_MMC(("mapper69_w, cmd 8, data: %02x\n", data));
39154410               break;
39164411
39174412            case 9:
r5926r5927
39504445   }
39514446}
39524447
4448/*************************************************************
4449
4450    Mapper 70
4451
4452    Known Boards: Discrete Logic Board
4453    Games: Space Shadow, Family Trainer Manhattan Police,
4454          Kamen Rider Club
4455
4456    Same board as mapper 152, but no NT mirroring
4457
4458    In MESS: Supported.
4459
4460*************************************************************/
4461
4462
39534463static WRITE8_HANDLER( mapper70_w )
39544464{
3955   logerror("mapper70_w offset %04x, data: %02x\n", offset, data);
4465   LOG_MMC(("mapper70_w, offset: %04x, data: %02x\n", offset, data));
39564466
3957   /* TODO: is the data being written irrelevant? */
4467   // we lack bus emulation
4468   prg16_89ab(space->machine, (data >> 4) & 0x07);
4469   chr8(space->machine, data, CHRROM);
4470}
39584471
3959   prg16_89ab(space->machine, (data & 0xf0) >> 4);
4472/*************************************************************
39604473
3961   chr8(space->machine, data & 0x0f, CHRROM);
4474 Mapper 71
39624475
3963#if 1
3964   if (data & 0x80)
3965//      set_nt_mirroring(state->ppu, PPU_MIRROR_HORZ);
3966      set_nt_mirroring(PPU_MIRROR_HIGH);
3967   else
3968//      set_nt_mirroring(state->ppu, PPU_MIRROR_VERT);
3969      set_nt_mirroring(PPU_MIRROR_LOW);
3970#endif
3971}
4476    Known Boards: Camerica Boards (BF9093, BF9097, BF909X, ALGNV11)
4477    Games: Linus Spacehead's Cosmic Crusade, Micro Machines,
4478          Mig-29, Stunt Kids
39724479
4480    We currently do not emulate NT mirroring for BF9097 board
4481    (missing in BF9093). As a result Fire Hawk is broken.
4482
4483    In MESS: Partially Supported.
4484
4485*************************************************************/
4486
39734487static WRITE8_HANDLER( mapper71_m_w )
39744488{
3975   logerror("mapper71_m_w offset: %04x, data: %02x\n", offset, data);
4489   LOG_MMC(("mapper71_m_w offset: %04x, data: %02x\n", offset, data));
39764490
39774491   prg16_89ab(space->machine, data);
39784492}
39794493
39804494static WRITE8_HANDLER( mapper71_w )
39814495{
3982   logerror("mapper71_w offset: %04x, data: %02x\n", offset, data);
4496   LOG_MMC(("mapper71_w offset: %04x, data: %02x\n", offset, data));
39834497
39844498   if (offset >= 0x4000)
39854499      prg16_89ab(space->machine, data);
39864500}
39874501
4502/*************************************************************
4503
4504    Mapper 72
4505
4506    Known Boards: Jaleco JF17, JF26 and JF28
4507    Games: Moero!! Juudou Warriors, Moero!! Pro Tennis, Pinball
4508          Quest Jpn
4509
4510    In MESS: Supported.
4511
4512*************************************************************/
4513
39884514static WRITE8_HANDLER( mapper72_w )
39894515{
3990   logerror("mapper72_w, offset %04x, data: %02x\n", offset, data);
4516   LOG_MMC(("mapper72_w, offset %04x, data: %02x\n", offset, data));
39914517
3992   if(data&0x80)
4518   if (data & 0x80)
39934519      prg16_89ab(space->machine, data & 0x0f);
3994   if(data&0x40)
4520   if (data & 0x40)
39954521      chr8(space->machine, data & 0x0f, CHRROM);
39964522
39974523}
39984524
4525/*************************************************************
4526
4527    Mapper 73
4528
4529    Known Boards: Konami VRC3
4530    Games: Salamander
4531
4532    In MESS: Supported. It also uses konami_irq.
4533
4534*************************************************************/
4535
39994536static WRITE8_HANDLER( mapper73_w )
40004537{
40014538   switch (offset & 0x7000)
r5926r5927
40274564}
40284565
40294566
4567/*************************************************************
4568
4569    Mapper 74
4570
4571    Known Boards: Type A by Waixing
4572    Games: Columbus - Ougon no Yoake (C), Ji Jia Zhan Shi,
4573          Jia A Fung Yun, Wei Luo Chuan Qi
4574
4575    In MESS: Partially Supported, but we ignore accesses to 0x5000 / 0x6000 atm
4576   (is this the reason for missing graphics?)
4577
4578*************************************************************/
4579
4580/* MIRROR_LOW and MIRROR_HIGH are swapped! */
4581static void waixing_set_mirror( UINT8 nt )
4582{
4583   switch (nt)
4584   {
4585   case 0:
4586   case 1:
4587      set_nt_mirroring(nt ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
4588      break;
4589   case 2:
4590      set_nt_mirroring(PPU_MIRROR_LOW);
4591      break;
4592   case 3:
4593      set_nt_mirroring(PPU_MIRROR_HIGH);
4594      break;
4595   default:
4596      LOG_MMC(("Mapper set NT to invalid value %02x", nt));
4597      break;
4598   }
4599}
4600
4601static WRITE8_HANDLER( mapper74_w )
4602{
4603   LOG_MMC(("mapper74_w, offset: %04x, data: %02x\n", offset, data));
4604
4605   switch (offset & 0x6001)
4606   {
4607   case 0x2000:
4608      waixing_set_mirror(data);   //maybe data & 0x03?
4609      break;
4610   case 0x2001:
4611      break;
4612   default:
4613      mapper4_w(space, offset, data);
4614      break;
4615   }
4616}
4617
4618/*************************************************************
4619
4620    Mapper 75
4621
4622    Known Boards: Komani VRC1 and Jaleco JF20, JF22
4623    Games: Exciting Boxing, Ganbare Goemon!, Tetsuwan Atom
4624
4625    In MESS: Supported.
4626
4627*************************************************************/
4628
40304629static WRITE8_HANDLER( mapper75_w )
40314630{
4032   logerror("mapper75_w, offset: %04x, data: %02x\n", offset, data);
4631   LOG_MMC(("mapper75_w, offset: %04x, data: %02x\n", offset, data));
40334632
40344633   switch (offset & 0x7000)
40354634   {
40364635      case 0x0000:
40374636         prg8_89(space->machine, data);
40384637         break;
4039      case 0x1000: /* TODO: verify */
4040         if (data & 0x01)
4041            set_nt_mirroring(PPU_MIRROR_HORZ);
4042         else
4043            set_nt_mirroring(PPU_MIRROR_VERT);
4044         /* vrom banking as well? */
4638      case 0x1000:
4639         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);
40454644         break;
40464645      case 0x2000:
40474646         prg8_ab(space->machine, data);
r5926r5927
40504649         prg8_cd(space->machine, data);
40514650         break;
40524651      case 0x6000:
4053         chr4_0(space->machine, data, CHRROM);
4652         mmc_bank_latch1 = (mmc_bank_latch1 & 0x10) | (data & 0x0f);
4653         chr4_0(space->machine, mmc_bank_latch1, CHRROM);
40544654         break;
40554655      case 0x7000:
4056         chr4_4(space->machine, data, CHRROM);
4656         mmc_bank_latch2 = (mmc_bank_latch2 & 0x10) | (data & 0x0f);
4657         chr4_4(space->machine, mmc_bank_latch2, CHRROM);
40574658         break;
40584659   }
40594660}
40604661
4662/*************************************************************
4663
4664    Mapper 76
4665
4666    Known Boards: Namcot 3446
4667    Games: Digital Devil Monogatari - Megami Tensei
4668
4669    In MESS: Supported.
4670
4671*************************************************************/
4672
40614673static WRITE8_HANDLER( mapper76_w )
40624674{
4063   static int cmd = 0;
4675   LOG_MMC(("mapper76_w, offset: %04x, data: %02x\n", offset, data));
40644676
4065   logerror("mapper76_w, offset: %04x, data: %02x\n", offset, data);
4066
40674677   switch (offset & 0x7001)
40684678   {
40694679   case 0:
4070      cmd = data;
4680      mmc_cmd1 = data;
40714681      break;
40724682   case 1:
40734683      {
4074         switch (cmd & 7)
4684         switch (mmc_cmd1 & 0x07)
40754685         {
40764686         case 2: chr2_0(space->machine, data, CHRROM); break;
40774687         case 3: chr2_2(space->machine, data, CHRROM); break;
40784688         case 4: chr2_4(space->machine, data, CHRROM); break;
40794689         case 5: chr2_6(space->machine, data, CHRROM); break;
40804690         case 6:
4081            (cmd & 0x40) ? prg8_cd(space->machine, data) : prg8_89(space->machine, data);
4691            (mmc_cmd1 & 0x40) ? prg8_cd(space->machine, data) : prg8_89(space->machine, data);
40824692            break;
40834693         case 7: prg8_ab(space->machine, data); break;
4084         default: logerror("mapper76 unsupported command: %02x, data: %02x\n", cmd, data); break;
4694         default: logerror("mapper76 unsupported command: %02x, data: %02x\n", mmc_cmd1, data); break;
40854695         }
40864696      }
40874697   case 0x2000:
4088      (data & 1) ? set_nt_mirroring(PPU_MIRROR_HORZ) : set_nt_mirroring(PPU_MIRROR_VERT);
4698      set_nt_mirroring((data & 1) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
40894699      break;
40904700   default:
40914701      logerror("mapper76 unmapped write, offset: %04x, data: %02x\n", offset, data);
40924702      break;
40934703   }
40944704}
4705
4706/*************************************************************
4707
4708    Mapper 77
4709
4710    Known Boards: Irem LROG017
4711    Games: Napoleon Senki
4712
4713    In MESS: Supported.
4714
4715*************************************************************/
4716
40954717static WRITE8_HANDLER( mapper77_w )
40964718{
4719   LOG_MMC(("mapper77_w, offset: %04x, data: %02x\n", offset, data));
40974720
4098/* Mapper is busted */
4099
4100   logerror("mapper77_w, offset: %04x, data: %02x\n", offset, data);
4101   switch (offset)
4102   {
4103      case 0x7c84:
4104//          prg8_89(space->machine, data);
4105         break;
4106      case 0x7c86:
4107//          prg8_89(space->machine, data);
4108//          prg8_ab(space->machine, data);
4109//          prg8_cd(space->machine, data);
4110//          prg16_89ab(space->machine, data); /* red screen */
4111//          prg16_cdef(space->machine, data);
4112         break;
4113   }
4721   prg32(space->machine, data & 0x0f);
4722   chr2_0(space->machine, (data >> 4), CHRROM);
41144723}
41154724
4725/*************************************************************
4726
4727    Mapper 78
4728
4729    Known Boards: Jaleco JF16 and Irem
4730    Games: Holy Diver, Portopia Renzoku Satsujin Jiken,
4731          Uchuusen - Cosmo Carrier
4732
4733    In MESS: Partially Supported.
4734
4735*************************************************************/
4736
41164737static WRITE8_HANDLER( mapper78_w )
41174738{
4118   logerror("mapper78_w, offset: %04x, data: %02x\n", offset, data);
4739   LOG_MMC(("mapper78_w, offset: %04x, data: %02x\n", offset, data));
41194740   /* Switch 8k VROM bank */
41204741   chr8(space->machine, (data & 0xf0) >> 4, CHRROM);
41214742
r5926r5927
41234744   prg16_89ab(space->machine, data & 0x0f);
41244745}
41254746
4747/*************************************************************
4748
4749    Mapper 79
4750
4751    Known Boards: NINA03, NINA06 by AVE
4752    Games: Krazy Kreatures, Poke Block, Puzzle, Pyramid,
4753          Solitaire, Ultimate League Soccer
4754
4755    In MESS: Supported.
4756
4757*************************************************************/
4758
41264759static WRITE8_HANDLER( mapper79_l_w )
41274760{
4128   logerror("mapper79_l_w: %04x:%02x\n", offset, data);
4761   LOG_MMC(("mapper79_l_w, offset: %04x, data: %02x\n", offset, data));
41294762
4130   if ((offset-0x100) & 0x0100)
4763   if (!(offset & 0x0100))
41314764   {
4132      /* Select 8k VROM bank */
4133      chr8(space->machine, data & 0x07, CHRROM);
4134
4135      /* Select 32k ROM bank? */
4136      prg32(space->machine, (data & 0x08) >> 3);
4765      prg32(space->machine, data >> 3);
4766      chr8(space->machine, data, CHRROM);
41374767   }
41384768}
41394769
4140static WRITE8_HANDLER( mapper79_w )
4141{
4142   logerror("mapper79_w, offset: %04x, data: %02x\n", offset, data);
4143}
4770/*************************************************************
41444771
4772    Mapper 80
4773
4774    Known Boards: Taito X1-005 Ver. A
4775    Games: Bakushou!! Jinsei Gekijou 2, Kyonshiizu 2, Minelvaton
4776          Saga, Taito Grand Prix
4777
4778    Registers are at 0x7ef0-0x7eff. first six ones choose chr
4779    (2x2k + 4x1k) banks, the seventh sets NT mirroring, the
4780    remaining ones chose prg banks.
4781
4782    In MESS: Supported.
4783
4784*************************************************************/
4785
41454786static WRITE8_HANDLER( mapper80_m_w )
41464787{
4147   logerror("mapper80_m_w, offset: %04x, data: %02x\n", offset, data);
4788   LOG_MMC(("mapper80_m_w, offset: %04x, data: %02x\n", offset, data));
41484789
41494790   switch (offset)
41504791   {
41514792      case 0x1ef0:
41524793         /* Switch 2k VROM at $0000 */
4153         chr2_0 (space->machine, (data & 0x7f) >> 1, CHRROM);
4794         chr2_0(space->machine, (data & 0x7f) >> 1, CHRROM);
41544795         break;
41554796      case 0x1ef1:
41564797         /* Switch 2k VROM at $0000 */
4157         chr2_2 (space->machine, (data & 0x7f) >> 1, CHRROM);
4798         chr2_2(space->machine, (data & 0x7f) >> 1, CHRROM);
41584799         break;
41594800      case 0x1ef2:
41604801         /* Switch 1k VROM at $1000 */
r5926r5927
41734814         chr1_7(space->machine, data, CHRROM);
41744815         break;
41754816      case 0x1ef6:
4176         /* Switch 1k VROM at $1c00 */
4177         (data&1)? set_nt_mirroring(PPU_MIRROR_VERT):set_nt_mirroring(PPU_MIRROR_HORZ);
4817         set_nt_mirroring((data & 0x01) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
41784818         break;
4179      case 0x1efa: case 0x1efb:
4819      case 0x1efa:
4820      case 0x1efb:
41804821         /* Switch 8k ROM at $8000 */
41814822         prg8_89(space->machine, data);
41824823         break;
4183      case 0x1efc: case 0x1efd:
4824      case 0x1efc:
4825      case 0x1efd:
41844826         /* Switch 8k ROM at $a000 */
41854827         prg8_ab(space->machine, data);
41864828         break;
4187      case 0x1efe: case 0x1eff:
4829      case 0x1efe:
4830      case 0x1eff:
41884831         /* Switch 8k ROM at $c000 */
41894832         prg8_cd(space->machine, data);
41904833         break;
r5926r5927
41934836         break;
41944837   }
41954838}
4196/* clone of 80, but with custom nametable stuff */
4197static WRITE8_HANDLER( mapper207_m_w )
4198{
4199   logerror("mapper80_m_w, offset: %04x, data: %02x\n", offset, data);
42004839
4201   switch (offset)
4202   {
4203      case 0x1ef0:
4204         /* Switch 2k VROM at $0000 */
4205         chr2_0 (space->machine, (data & 0x7f) >> 1, CHRROM);
4206         if (data & 0x80)
4207         {
4208            set_nt_page(0, CIRAM, 1, 1);
4209            set_nt_page(1, CIRAM, 1, 1);
4210         }
4211         else
4212         {
4213            set_nt_page(0, CIRAM, 0, 1);
4214            set_nt_page(1, CIRAM, 0, 1);
4215         }
4216         break;
4217      case 0x1ef1:
4218         /* Switch 2k VROM at $0000 */
4219         chr2_2 (space->machine, (data & 0x7f) >> 1, CHRROM);
4220         if (data & 0x80)
4221         {
4222            set_nt_page(2, CIRAM, 1, 1);
4223            set_nt_page(3, CIRAM, 1, 1);
4224         }
4225         else
4226         {
4227            set_nt_page(2, CIRAM, 0, 1);
4228            set_nt_page(3, CIRAM, 0, 1);
4229         }
4230         break;
4231      case 0x1ef2:
4232         /* Switch 1k VROM at $1000 */
4233         chr1_4(space->machine, data, CHRROM);
4234//          ppu2c0x_set_videorom_bank(state->ppu, 4, 1, data, 64);
4235         break;
4236      case 0x1ef3:
4237         /* Switch 1k VROM at $1400 */
4238         chr1_5(space->machine, data, CHRROM);
4239//          ppu2c0x_set_videorom_bank(state->ppu, 5, 1, data, 64);
4240         break;
4241      case 0x1ef4:
4242         /* Switch 1k VROM at $1800 */
4243         chr1_6(space->machine, data, CHRROM);
4244//          ppu2c0x_set_videorom_bank(state->ppu, 6, 1, data, 64);
4245         break;
4246      case 0x1ef5:
4247         /* Switch 1k VROM at $1c00 */
4248         chr1_7(space->machine, data, CHRROM);
4249//          ppu2c0x_set_videorom_bank(state->ppu, 7, 1, data, 64);
4250         break;
4251      case 0x1efa: case 0x1efb:
4252         /* Switch 8k ROM at $8000 */
4253         prg8_89(space->machine, data);
4254         break;
4255      case 0x1efc: case 0x1efd:
4256         /* Switch 8k ROM at $a000 */
4257         prg8_ab(space->machine, data);
4258         break;
4259      case 0x1efe: case 0x1eff:
4260         /* Switch 8k ROM at $c000 */
4261         prg8_cd(space->machine, data);
4262         break;
4263      default:
4264         logerror("mapper80_m_w uncaught addr: %04x, value: %02x\n", offset + 0x6000, data);
4265         break;
4266   }
4267}
4840/*************************************************************
42684841
4842    Mapper 81
4843
4844    Known Boards: Undocumented / Unused ?!?
4845    Games: ----------
4846
4847    In MESS: ----------
4848
4849*************************************************************/
4850
4851/*************************************************************
4852
4853    Mapper 82
4854
4855    Known Boards: Taito X1017
4856    Games: Kyuukyoku Harikiri Koushien, Kyuukyoku Harikiri
4857          Stadium, SD Keiji - Blader
4858
4859    In MESS: Supported.
4860
4861*************************************************************/
4862
42694863static WRITE8_HANDLER( mapper82_m_w )
42704864{
42714865   static int vrom_switch;
42724866
42734867   /* This mapper has problems */
42744868
4275   logerror("mapper82_m_w, offset: %04x, data: %02x\n", offset, data);
4869   LOG_MMC(("mapper82_m_w, offset: %04x, data: %02x\n", offset, data));
42764870
42774871   switch (offset)
42784872   {
r5926r5927
43344928   }
43354929}
43364930
4931/*************************************************************
4932
4933    Mapper 83
4934
4935    Known Boards: Unknown Multigame Bootleg Board
4936    Games: Dragon Ball Party, Fatal Fury 2, Street Blaster II
4937          Pro, World Heroes 2
4938
4939    In MESS: Supported.
4940
4941*************************************************************/
4942
43374943static WRITE8_HANDLER( mapper83_l_w )
43384944{
43394945   mapper83_low_data[offset & 0x03] = data;
r5926r5927
44275033   }
44285034}
44295035
5036/*************************************************************
5037
5038    Mapper 84
5039
5040    Known Boards: Undocumented / Unused ?!?
5041    Games: ----------
5042
5043    In MESS: ----------
5044
5045*************************************************************/
5046
5047/*************************************************************
5048
5049    Mapper 85
5050
5051    Known Boards: Konami VRC7
5052    Games: Lagrange Point, Tiny Toon Adventures 2
5053
5054    In MESS: Supported. It also uses konami_irq.
5055
5056*************************************************************/
5057
44305058static WRITE8_HANDLER( konami_vrc7_w )
44315059{
4432//  logerror("konami_vrc7_w offset: %04x, data: %02x, scanline: %d\n", offset, data, current_scanline);
5060   LOG_MMC(("konami_vrc7_w, offset: %04x, data: %02x\n", offset, data));
44335061
44345062   switch (offset & 0x7018)
44355063   {
r5926r5927
44375065         /* Switch 8k bank at $8000 */
44385066         prg8_89(space->machine, data);
44395067         break;
4440      case 0x0008: case 0x0010: case 0x0018:
5068      case 0x0008:
5069      case 0x0010:
5070      case 0x0018:
44415071         /* Switch 8k bank at $a000 */
44425072         prg8_ab(space->machine, data);
44435073         break;
r5926r5927
44515081
44525082      case 0x2000:
44535083         /* Switch 1k VROM at $0000 */
4454         chr1_0(space->machine, data, CHRROM);
4455//          ppu2c0x_set_videorom_bank(state->ppu, 0, 1, data, 64);
5084         chr1_0(space->machine, data, mmc_chr_source);
44565085         break;
44575086      case 0x2008: case 0x2010: case 0x2018:
44585087         /* Switch 1k VROM at $0400 */
4459         chr1_1(space->machine, data, CHRROM);
5088         chr1_1(space->machine, data, mmc_chr_source);
44605089         break;
44615090      case 0x3000:
44625091         /* Switch 1k VROM at $0800 */
4463         chr1_2(space->machine, data, CHRROM);
5092         chr1_2(space->machine, data, mmc_chr_source);
44645093         break;
44655094      case 0x3008: case 0x3010: case 0x3018:
44665095         /* Switch 1k VROM at $0c00 */
4467         chr1_3(space->machine, data, CHRROM);
5096         chr1_3(space->machine, data, mmc_chr_source);
44685097         break;
44695098      case 0x4000:
44705099         /* Switch 1k VROM at $1000 */
4471         chr1_4(space->machine, data, CHRROM);
5100         chr1_4(space->machine, data, mmc_chr_source);
44725101         break;
44735102      case 0x4008: case 0x4010: case 0x4018:
44745103         /* Switch 1k VROM at $1400 */
4475         chr1_5(space->machine, data, CHRROM);
5104         chr1_5(space->machine, data, mmc_chr_source);
44765105         break;
44775106      case 0x5000:
44785107         /* Switch 1k VROM at $1800 */
4479         chr1_6(space->machine, data, CHRROM);
5108         chr1_6(space->machine, data, mmc_chr_source);
44805109         break;
44815110      case 0x5008: case 0x5010: case 0x5018:
44825111         /* Switch 1k VROM at $1c00 */
4483         chr1_7(space->machine, data, CHRROM);
5112         chr1_7(space->machine, data, mmc_chr_source);
44845113         break;
44855114
44865115      case 0x6000:
r5926r5927
45105139   }
45115140}
45125141
4513static WRITE8_HANDLER( mapper86_w )
5142/*************************************************************
5143
5144    Mapper 86
5145
5146    Known Boards: Jaleco JF13
5147    Games: Moero Pro Yakyuu
5148
5149    In MESS: Supported.
5150
5151*************************************************************/
5152
5153static WRITE8_HANDLER( mapper86_m_w )
45145154{
4515   logerror("mapper86_w, offset: %04x, data: %02x\n", offset, data);
4516   switch (offset)
5155   LOG_MMC(("mapper86_m_w, offset: %04x, data: %02x\n", offset, data));
5156
5157   if (offset == 0)
45175158   {
4518      case 0x7541:
4519         prg16_89ab(space->machine, data >> 4);
4520//          prg16_cdef(space->machine, data >> 4);
4521         break;
4522      case 0x7d41:
4523//          prg16_89ab(space->machine, data >> 4);
4524//          prg16_cdef(space->machine, data >> 4);
4525         break;
5159      prg32(space->machine, (data >> 4) & 0x03);
5160      chr8(space->machine, ((data >> 4) & 0x04) | (data & 0x03), CHRROM);
45265161   }
45275162}
45285163
5164/*************************************************************
5165
5166    Mapper 87
5167
5168    Known Boards: Jaleco JF05, JF06, JF07, JF08, JF09, JF10 and
5169                 Discrete Logic Board
5170    Games: The Goonies, Hyper Olympics, Jajamaru no Daibouken,
5171          Legend of Kage, Twin Bee
5172
5173    In MESS: Supported.
5174
5175*************************************************************/
5176
45295177static WRITE8_HANDLER( mapper87_m_w )
45305178{
4531   logerror("mapper87_m_w %04x:%02x\n", offset, data);
5179   LOG_MMC(("mapper87_m_w, offset: %04x, data: %02x\n", offset, data));
45325180
4533   /* TODO: verify */
4534   chr8(space->machine, data >> 1, CHRROM);
5181   chr8(space->machine, ((data & 0x02) >> 1) | ((data & 0x01) << 1), CHRROM);
45355182}
5183
5184/*************************************************************
5185
5186    Mapper 88
5187
5188    Known Boards: Namcot 3433 & 3443
5189    Games: Dragon Spirit - Aratanaru Densetsu, Namcot Mahjong, Quinty
5190
5191    In MESS: Supported.
5192
5193*************************************************************/
5194
5195static WRITE8_HANDLER( mapper88_w )
5196{
5197   LOG_MMC(("mapper88_w, offset: %04x, data: %02x\n", offset, data));
5198
5199   switch (offset & 1)
5200   {
5201   case 0:
5202      {
5203         mmc_cmd1 = data & 7;
5204         break;
5205      }
5206   case 1:
5207      {
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;
5220      }
5221   }
5222}
5223
5224/*************************************************************
5225
5226    Mapper 89
5227
5228    Known Boards: Sunsoft 2B
5229    Games: Tenka no Goikenban - Mito Koumon
5230
5231    In MESS: Supported.
5232
5233*************************************************************/
5234
45365235static WRITE8_HANDLER( mapper89_w )
45375236{
4538   int chr;
4539   logerror("mapper89_m_w %04x:%02x\n", offset, data);
4540   prg16_89ab(space->machine, (data>>4)&7);
4541   chr=(data&7)|((data&0x80)?8:0);
4542   chr8(space->machine, chr, CHRROM);
4543   (data&8)?set_nt_mirroring(PPU_MIRROR_HIGH):set_nt_mirroring(PPU_MIRROR_LOW);
5237   UINT8 map89_helper;
5238   LOG_MMC(("mapper89_m_w, offset: %04x, data: %02x\n", offset, data));
45445239
5240   map89_helper = (data & 0x07) | ((data & 0x80) ? 0x08 : 0x00);
5241
5242   prg16_89ab(space->machine, (data >> 4) & 0x07);
5243   chr8(space->machine, map89_helper, CHRROM);
5244   set_nt_mirroring((data & 0x08) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
45455245}
45465246
5247/*************************************************************
5248
5249    Mapper 90
5250
5251    Known Boards: Type A by J.Y. Company
5252    Games: Aladdin, Final Fight 3, Super Mario World, Tekken 2
5253
5254    In MESS: Unsupported.
5255
5256*************************************************************/
5257
5258/*************************************************************
5259
5260    Mapper 91
5261
5262    Known Boards: Unknown Bootleg Board
5263    Games: Mortal Kombat II, Street Fighter III, Super Mario
5264          Kart Rider
5265
5266    In MESS: Partially supported.
5267
5268*************************************************************/
5269
45475270static WRITE8_HANDLER( mapper91_m_w )
45485271{
4549   logerror ("mapper91_m_w, offset: %04x, data: %02x\n", offset, data);
5272   LOG_MMC(("mapper91_m_w, offset: %04x, data: %02x\n", offset, data));
45505273
45515274   switch (offset & 0x7000)
45525275   {
45535276      case 0x0000:
45545277         switch (offset & 0x03)
45555278         {
4556            case 0x00: chr2_0 (space->machine, data, CHRROM); break;
4557            case 0x01: chr2_2 (space->machine, data, CHRROM); break;
4558            case 0x02: chr2_4 (space->machine, data, CHRROM); break;
4559            case 0x03: chr2_6 (space->machine, data, CHRROM); break;
5279            case 0x00: chr2_0(space->machine, data, CHRROM); break;
5280            case 0x01: chr2_2(space->machine, data, CHRROM); break;
5281            case 0x02: chr2_4(space->machine, data, CHRROM); break;
5282            case 0x03: chr2_6(space->machine, data, CHRROM); break;
45605283         }
45615284         break;
45625285      case 0x1000:
r5926r5927
45715294         break;
45725295   }
45735296}
5297
5298/*************************************************************
5299
5300    Mapper 92
5301
5302    Known Boards: Jaleco JF19 & JF21
5303    Games: Moero Pro Soccer, Moero Pro Yakyuu '88
5304
5305    In MESS: Supported (no samples).
5306
5307*************************************************************/
5308
45745309static WRITE8_HANDLER( mapper92_w )
45755310{
4576   logerror("mapper92_w, offset %04x, data: %02x\n", offset, data);
5311   LOG_MMC(("mapper92_w, offset %04x, data: %02x\n", offset, data));
45775312
4578   if(data&0x80)
5313   if(data & 0x80)
45795314      prg16_cdef(space->machine, data & 0x0f);
4580   if(data&0x40)
5315   if(data & 0x40)
45815316      chr8(space->machine, data & 0x0f, CHRROM);
4582
45835317}
45845318
4585static WRITE8_HANDLER( mapper93_m_w )
4586{
4587   LOG_MMC(("mapper93_m_w %04x:%02x\n", offset, data));
5319/*************************************************************
45885320
4589   prg16_89ab(space->machine, data);
4590}
5321    Mapper 93
45915322
5323    Known Boards: Sunsoft 2A
5324    Games: Shanghai, Fantasy Zone
5325
5326    Very similar to mapper 89, but no NT mirroring for data&8
5327    and only CHRRAM present
5328
5329    In MESS: Supported.
5330
5331*************************************************************/
5332
45925333static WRITE8_HANDLER( mapper93_w )
45935334{
45945335   LOG_MMC(("mapper93_w %04x:%02x\n", offset, data));
45955336
4596   /* The high nibble appears to be the same prg bank as */
4597   /* was written to the mid-area mapper */
5337   prg16_89ab(space->machine, data >> 4);
45985338}
45995339
5340/*************************************************************
5341
5342    Mapper 94
5343
5344    Known Boards: UN1ROM
5345    Games: Senjou no Okami
5346
5347    Writes to 0x8000-0xffff set 16k prg bank at 0x8000. The
5348    bank at 0xc000 is always set to the last one.
5349
5350    In MESS: Supported.
5351
5352*************************************************************/
5353
46005354static WRITE8_HANDLER( mapper94_w )
46015355{
46025356   LOG_MMC(("mapper94_w %04x:%02x\n", offset, data));
r5926r5927
46045358   prg16_89ab(space->machine, data >> 2);
46055359}
46065360
5361/*************************************************************
5362
5363    Mapper 95
5364
5365    Known Boards: Namcot 3425
5366    Games: Dragon Buster
5367
5368    Quite similar to other Namco boards, but with a peculiar
5369    NT mirroring.
5370
5371    In MESS: Supported.
5372
5373*************************************************************/
5374
5375UINT8 map95_reg[4];
5376
46075377static WRITE8_HANDLER( mapper95_w )
46085378{
4609   LOG_MMC(("mapper95_w %04x:%02x\n", offset, data));
5379   LOG_MMC(("mapper95_w, offset: %04x, data: %02x\n", offset, data));
46105380
4611   switch (offset)
5381   switch (offset & 1)
46125382   {
4613      case 0x0000:
4614         /* Switch 8k bank at $8000 */
4615//          prg8_89(space->machine, data);
4616//          prg8_ab(space->machine, data);
4617//          prg16_89ab(space->machine, data);
5383   case 0:
5384      {
5385         mmc_cmd1 = data;
46185386         break;
4619      case 0x0001:
4620         /* Switch 8k bank at $a000 */
4621         prg8_ab(space->machine, data >> 1);
5387      }
5388   case 1:
5389      {
5390         switch (mmc_cmd1 & 0x07)
5391         {
5392            case 0:
5393            case 1:
5394               chr2_x(space->machine, mmc_cmd1 ? 2 : 0, (data >> 1) & 0x1f, CHRROM);
5395               break;
5396            case 2:
5397            case 3:
5398            case 4:
5399            case 5:
5400               chr1_x(space->machine, 2 + mmc_cmd1, data & 0x1f, CHRROM);
5401               map95_reg[mmc_cmd1 - 2] = data & 0x20;
5402               if (!(mmc_cmd1 & 0x80))
5403               {
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);
5408               }
5409               else
5410                  set_nt_mirroring(PPU_MIRROR_HORZ);
5411               break;
5412            case 6:
5413               prg8_89(space->machine,data & 0x1f);
5414               break;
5415            case 7:
5416               prg8_ab(space->machine,data & 0x1f);
5417               break;
5418         }
46225419         break;
5420      }
46235421   }
46245422}
5423
5424/*************************************************************
5425
5426    Mapper 96
5427
5428    Known Boards: Bandai Oeka Kids Board
5429    Games: Oeka Kids - Anpanman no Hiragana Daisuki, Oeka
5430          Kids - Anpanman to Oekaki Shiyou!!
5431
5432    In MESS: Preliminary Support.
5433
5434*************************************************************/
5435
46255436static WRITE8_HANDLER( mapper96_w )
46265437{
5438   LOG_MMC(("mapper96_w, offset: %04x, data: %02x\n", offset, data));
5439
46275440   prg32(space->machine, data);
46285441}
46295442
5443/*************************************************************
5444
5445    Mapper 97
5446
5447    Known Boards: Irem Board
5448    Games: Kaiketsu Yanchamaru
5449
5450    In MESS: Supported.
5451
5452*************************************************************/
5453
46305454static WRITE8_HANDLER( mapper97_w )
46315455{
4632   if(offset&0x4000)
4633      return;
4634   if(data&0x80)
4635      set_nt_mirroring(PPU_MIRROR_VERT);
4636   else set_nt_mirroring(PPU_MIRROR_HORZ);
4637   prg16_cdef(space->machine, data&0x0F);
5456   LOG_MMC(("mapper97_w, offset: %04x, data: %02x\n", offset, data));
5457
5458   if (offset < 0x4000)
5459   {
5460      set_nt_mirroring((data & 0x80) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
5461      prg16_cdef(space->machine, data & 0x0f);
5462   }
46385463}
5464
5465/*************************************************************
5466
5467    Mapper 98
5468
5469    Known Boards: Undocumented / Unused ?!?
5470    Games: ----------
5471
5472    In MESS: ----------
5473
5474*************************************************************/
5475
5476/*************************************************************
5477
5478    Mapper 99
5479
5480    Known Boards: VS. System
5481    Games: most Vs. games
5482
5483    In MESS: Unsupported, low priority (you should use MAME)
5484
5485*************************************************************/
5486
5487/*************************************************************
5488
5489    Mapper 100
5490
5491    Known Boards: Undocumented / Unused ?!?
5492    Games: ----------
5493
5494    In MESS: ----------
5495
5496*************************************************************/
5497
5498/*************************************************************
5499
5500    Mapper 101
5501
5502    Known Boards: ???
5503    Games: Urusei Yatsura Alt
5504
5505    In MESS: Supported.
5506
5507*************************************************************/
5508
46395509static WRITE8_HANDLER( mapper101_m_w )
46405510{
4641   LOG_MMC(("mapper101_m_w %04x:%02x\n", offset, data));
5511   LOG_MMC(("mapper101_m_w, offset: %04x, data: %02x\n", offset, data));
46425512
46435513   chr8(space->machine, data, CHRROM);
46445514}
46455515
46465516static WRITE8_HANDLER( mapper101_w )
46475517{
4648   LOG_MMC(("mapper101_w %04x:%02x\n", offset, data));
5518   LOG_MMC(("mapper101_w, offset: %04x, data: %02x\n", offset, data));
46495519
46505520   /* ??? */
46515521}
5522
5523/*************************************************************
5524
5525    Mapper 102
5526
5527    Known Boards: Undocumented / Unused ?!?
5528    Games: ----------
5529
5530    In MESS: ----------
5531
5532*************************************************************/
5533
5534/*************************************************************
5535
5536    Mapper 103
5537
5538    Known Boards: Unknown Bootleg Board (2708)
5539    Games: Doki Doki Panic (FDS Conversion)
5540
5541    In MESS: Unsupported. Need reads from 0x6000
5542
5543*************************************************************/
5544
5545/*************************************************************
5546
5547    Mapper 104
5548
5549    Known Boards: Camerica Golden Five
5550    Games: Pegasus 5 in 1
5551
5552    In MESS: Supported.
5553
5554*************************************************************/
5555
5556static WRITE8_HANDLER( mapper104_w )
5557{
5558   LOG_MMC(("mapper104_w, offset: %04x, data: %02x\n", offset, data));
5559
5560   if (offset < 0x4000)
5561   {
5562      if (data & 0x08)
5563      {
5564         mmc_bank_latch1 = ((data & 0x07) << 4) | (mmc_bank_latch1 & 0x0f);
5565         prg16_89ab(space->machine, mmc_bank_latch1);
5566         prg16_cdef(space->machine, ((data & 0x07) << 4) | 0x0f);
5567      }
5568         
5569   }
5570   else
5571   {
5572         mmc_bank_latch1 = (mmc_bank_latch1 & 0x70) | (data & 0x0f);
5573         prg16_89ab(space->machine, mmc_bank_latch1);
5574   }
5575}
5576
5577/*************************************************************
5578
5579    Mapper 105
5580
5581    Known Boards: Custom Board
5582    Games: Nintendo World Championships 1990
5583
5584    In MESS: Unsupported.
5585
5586*************************************************************/
5587
5588/*************************************************************
5589
5590    Mapper 106
5591
5592    Known Boards: Unknown Bootleg Board
5593    Games: Super Mario Bros. 3 Pirate
5594
5595    In MESS: Unsupported.
5596
5597*************************************************************/
5598
5599/*************************************************************
5600
5601    Mapper 107
5602
5603    Known Boards: Bootleg Board by Magic Series
5604    Games: Magic Dragon
5605
5606    Very simple mapper: writes to 0x8000-0xffff set prg32 and chr8
5607    banks
5608
5609    In MESS: Supported.
5610
5611*************************************************************/
5612
46525613static WRITE8_HANDLER( mapper107_w )
46535614{
5615   LOG_MMC(("mapper107_w, offset: %04x, data: %02x\n", offset, data));
5616
46545617   prg32(space->machine, data >> 1);
46555618   chr8(space->machine, data, CHRROM);
46565619}
46575620
5621/*************************************************************
5622
5623    Mapper 108
5624
5625    Known Boards: Bootleg Board by Whirlwind
5626    Games: Meikyuu Jiin Dababa (FDS Conversion)
5627
5628    Simple mapper: reads in 0x6000-0x7fff return wram, writes to
5629          0x8fff set prg8_89 to the bank corresponding to data
5630
5631    In MESS: Unsupported. Needs to read from 0x6000.
5632
5633*************************************************************/
5634
5635/*************************************************************
5636
5637    Mapper 109
5638
5639    Known Boards: Undocumented / Unused ?!?
5640    Games: ----------
5641
5642    In MESS: ----------
5643
5644*************************************************************/
5645
5646/*************************************************************
5647
5648    Mapper 110
5649
5650    Known Boards: Undocumented / Unused ?!?
5651    Games: ----------
5652
5653    In MESS: ----------
5654
5655*************************************************************/
5656
5657/*************************************************************
5658
5659    Mapper 111
5660
5661    Known Boards: ???
5662    Games: Ninja Ryukenden (C)
5663
5664    No info avaliable
5665
5666    In MESS: Unsupported.
5667
5668*************************************************************/
5669
5670/*************************************************************
5671
5672    Mapper 112
5673
5674    Known Boards: Bootleg Board NTDEC ASDER
5675    Games: Cobra Mission, Fighting Hero III, Huang Di, Master
5676          Shooter
5677
5678    In MESS: Supported.
5679
5680*************************************************************/
5681
46585682static WRITE8_HANDLER( mapper112_w )
46595683{
46605684   LOG_MMC(("mapper112_w, offset: %04x, data: %02x\n", offset, data));
r5926r5927
46625686   switch (offset)
46635687   {
46645688   case 0x0000:
4665      MMC1_bank1 = data;
5689      mmc_cmd1 = data & 0x07;
46665690      break;
46675691   case 0x2000:
4668      switch (MMC1_bank1)
5692      switch (mmc_cmd1)
46695693      {
46705694      case 0:
46715695         prg8_89(space->machine, data);
r5926r5927
47035727   }
47045728}
47055729
5730/*************************************************************
5731
5732    Mapper 113
5733
5734    Known Boards: Bootleg Board by HES (also used by others)
5735    Games: AV Hanafuda Club, AV Soccer, Papillon, Sidewinder,
5736          Total Funpack
5737
5738    In MESS: Supported.
5739
5740*************************************************************/
5741
47065742static WRITE8_HANDLER( mapper113_l_w )
47075743{
4708   LOG_MMC(("mapper113_w %04x:%02x\n", offset, data));
5744   LOG_MMC(("mapper113_w, offset: %04x, data: %02x\n", offset, data));
47095745
4710   //I think this is the right value
4711   if(offset>0xFF)
4712      return;
4713   prg32(space->machine, data>>3);
4714   chr8(space->machine, data&7, CHRROM);
5746   if (!(offset & 0x100))
5747   {
5748      prg32(space->machine, data >> 3);
5749      chr8(space->machine, data & 0x07, CHRROM);
5750   }
47155751}
5752
5753/*************************************************************
5754
5755    Mapper 114
5756
5757    Known Boards: Unknown Bootleg Board
5758    Games: The Lion King
5759
5760    MMC3 clone
5761
5762    In MESS: Unsupported.
5763
5764*************************************************************/
5765
5766/*************************************************************
5767
5768    Mapper 115 (formerly 248)
5769
5770    Known Boards: Unknown Bootleg Board by Kasing
5771    Games: AV Jiu Ji Mahjong, Bao Qing Tian, Thunderbolt 2,
5772          Shisen Mahjong 2
5773
5774    MMC3 clone
5775
5776    In MESS: Partally Supported
5777
5778*************************************************************/
5779
5780static void mapper115_set_prg( running_machine *machine )
5781{
5782   if (MMC1_bank4 & 0x80)
5783   {
5784      prg16_89ab(machine, MMC1_bank4 & 0x0f);
5785   }
5786   else
5787   {
5788      prg8_89(machine, MMC1_bank2 & 0x1f);
5789      prg8_ab(machine, MMC1_bank3 & 0x1f);
5790   }
5791}
5792
5793static WRITE8_HANDLER( mapper115_m_w )
5794{
5795   LOG_MMC(("mapper115_m_w, offset: %04x, data: %02x\n", offset, data));
5796
5797   MMC1_bank4 = data;
5798   mapper115_set_prg(space->machine);
5799}
5800
5801static WRITE8_HANDLER( mapper115_w )
5802{
5803   LOG_MMC(("mapper115_w, offset: %04x, data: %02x\n", offset, data));
5804
5805   switch (offset & 0x7001)
5806   {
5807   case 0x0000:
5808      MMC1_bank1 = data;
5809      break;
5810   case 0x0001:
5811      switch (MMC1_bank1 & 0x07)
5812      {
5813      case 0:
5814         chr2_0(space->machine, data >> 1, CHRROM);
5815         break;
5816      case 1:
5817         chr2_2(space->machine, data >> 1, CHRROM);
5818         break;
5819      case 2:
5820         chr1_4(space->machine, data, CHRROM);
5821         break;
5822      case 3:
5823         chr1_5(space->machine, data, CHRROM);
5824         break;
5825      case 4:
5826         chr1_6(space->machine, data, CHRROM);
5827         break;
5828      case 5:
5829         chr1_7(space->machine, data, CHRROM);
5830         break;
5831      case 6:
5832         MMC1_bank2 = data;
5833         mapper115_set_prg(space->machine);
5834         break;
5835      case 7:
5836         MMC1_bank3 = data;
5837         mapper115_set_prg(space->machine);
5838         break;
5839      }
5840      break;
5841   case 0x2000:
5842      set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
5843      break;
5844   case 0x4000:
5845      IRQ_count_latch = data;
5846      break;
5847   case 0x4001:
5848      IRQ_count = IRQ_count_latch;
5849      break;
5850   case 0x6000:
5851      IRQ_enable = 0;
5852      break;
5853   case 0x6001:
5854      IRQ_enable = 1;
5855      break;
5856   }
5857}
5858
5859static void mapper115_irq( const device_config *device, int scanline, int vblank, int blanked )
5860{
5861   if ((scanline < PPU_BOTTOM_VISIBLE_SCANLINE) /*|| (scanline == ppu_scanlines_per_frame-1)*/)
5862   {
5863      int priorCount = IRQ_count;
5864      if ((IRQ_count == 0) || IRQ_reload)
5865      {
5866         IRQ_count = IRQ_count_latch;
5867         IRQ_reload = 0;
5868      }
5869      else
5870         IRQ_count --;
5871
5872      if (IRQ_enable && !blanked && (IRQ_count == 0) && priorCount)
5873      {
5874         LOG_MMC(("irq fired, scanline: %d (MAME %d, beam pos: %d)\n", scanline,
5875               video_screen_get_vpos(device->machine->primary_screen), video_screen_get_hpos(device->machine->primary_screen)));
5876         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
5877      }
5878   }
5879}
5880
5881/*************************************************************
5882
5883    Mapper 116
5884
5885    Known Boards: Unknown Bootleg Board (Someri?!?)
5886    Games: AV Mei Shao Nv Zhan Shi, Chuugoku Taitei
5887
5888    In MESS: Unsupported.
5889
5890*************************************************************/
5891
5892/*************************************************************
5893
5894    Mapper 117
5895
5896    Known Boards: Bootleg Board by Future Media
5897    Games: Crayon Shin-chan (C), San Guo Zhi 4 - Chi Bi Feng Yun
5898
5899    In MESS: Unsupported.
5900
5901*************************************************************/
5902
5903/*************************************************************
5904
5905    Mapper 118
5906
5907    Known Boards: TKSROM, TLSROM
5908    Games: Armadillo, Play Action Football, Pro Hockey, RPG
5909          Jinsei Game, Y's 3
5910
5911    In MESS: Supported. It also uses mapper4_irq.
5912
5913*************************************************************/
5914
5915static WRITE8_HANDLER( mapper118_w )
5916{
5917   static UINT8 last_bank = 0xff;
5918   LOG_MMC(("mapper118_w, offset: %04x, data: %02x\n", offset, data));
5919
5920   //uses just bits 14, 13, and 0
5921   switch (offset & 0x6001)
5922   {
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      }
5964      case 0x2000: /* $a000 */
5965         LOG_MMC(("     mapper 118 mirroring: %02x\n", data));
5966         switch (data & 0x02)
5967         {
5968            case 0x00: set_nt_mirroring(PPU_MIRROR_LOW); break;
5969            case 0x01: set_nt_mirroring(PPU_MIRROR_LOW); break;
5970         }
5971         break;
5972
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
5978      case 0x4000: /* $c000 - IRQ scanline counter */
5979         IRQ_count = data;
5980         LOG_MMC(("     MMC3 set irq count: %02x\n", data));
5981         break;
5982
5983      case 0x4001: /* $c001 - IRQ scanline latch */
5984         IRQ_count_latch = data;
5985         LOG_MMC(("     MMC3 set irq count latch: %02x\n", data));
5986         break;
5987
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
5999      default:
6000         logerror("mapper4_w uncaught: %04x value: %02x\n", offset + 0x8000, data);
6001         break;
6002   }
6003}
6004
6005/*************************************************************
6006
6007    Mapper 119
6008
6009    Known Boards: TQROM
6010    Games: Pin Bot, High Speed
6011
6012    In MESS: Supported. It also uses mapper4_irq.
6013
6014*************************************************************/
6015
6016static void mapper119_set_chr( running_machine *machine )
6017{
6018   UINT8 chr_page = (MMC3_cmd & 0x80) >> 5;
6019
6020   if (MMC3_chr[0] & 0x40)
6021      chr2_x(machine, chr_page ^ 0, (MMC3_chr[0] >> 1) & 0x03, CHRRAM);
6022   else
6023      chr2_x(machine, chr_page ^ 0, ((MMC3_chr[0] & 0x3f) >> 1), CHRROM);
6024
6025   if (MMC3_chr[1] & 0x40)
6026      chr2_x(machine, chr_page ^ 2, (MMC3_chr[1] >> 1) & 0x03, CHRRAM);
6027   else
6028      chr2_x(machine, chr_page ^ 2, ((MMC3_chr[1] & 0x3f) >> 1), CHRROM);
6029
6030   if (MMC3_chr[2] & 0x40)
6031      chr1_x(machine, chr_page ^ 4, MMC3_chr[2] & 0x07, CHRRAM);
6032   else
6033      chr1_x(machine, chr_page ^ 4, MMC3_chr[2] & 0x3f, CHRROM);
6034
6035   if (MMC3_chr[3] & 0x40)
6036      chr1_x(machine, chr_page ^ 5, MMC3_chr[3] & 0x07, CHRRAM);
6037   else
6038      chr1_x(machine, chr_page ^ 5, MMC3_chr[3] & 0x3f, CHRROM);
6039
6040   if (MMC3_chr[4] & 0x40)
6041      chr1_x(machine, chr_page ^ 6, MMC3_chr[4] & 0x07, CHRRAM);
6042   else
6043      chr1_x(machine, chr_page ^ 6, MMC3_chr[4] & 0x3f, CHRROM);
6044
6045   if (MMC3_chr[5] & 0x40)
6046      chr1_x(machine, chr_page ^ 7, MMC3_chr[5] & 0x07, CHRRAM);
6047   else
6048      chr1_x(machine, chr_page ^ 7, MMC3_chr[5] & 0x3f, CHRROM);
6049}
6050
6051static WRITE8_HANDLER( mapper119_w )
6052{
6053   static UINT8 last_bank = 0xff;
6054   LOG_MMC(("mapper119_w, offset: %04x, data: %02x\n", offset, data));
6055
6056   //only bits 14,13, and 0 matter for offset!
6057   switch (offset & 0x6001)
6058   {
6059      case 0x0000: /* $8000 */
6060         MMC3_cmd = data;
6061
6062         /* Toggle between switching $8000 and $c000 */
6063         if (last_bank != (data & 0xc0))
6064         {
6065            /* Reset the banks */
6066            mapper4_set_prg(space->machine);
6067            mapper119_set_chr(space->machine);
6068            LOG_MMC(("     MMC3 reset banks\n"));
6069         }
6070         last_bank = data & 0xc0;
6071         break;
6072
6073      case 0x0001: /* $8001 */
6074      {
6075         UINT8 cmd = MMC3_cmd & 0x07;
6076         switch (cmd)
6077         {
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
6084            case 2: case 3: case 4: case 5:
6085               MMC3_chr[cmd] = data;
6086               mapper119_set_chr(space->machine);
6087               LOG_MMC(("     MMC3 set vram %d: %d\n", cmd, data));
6088               break;
6089
6090            case 6:
6091               MMC3_prg0 = data;
6092               mapper4_set_prg(space->machine);
6093               break;
6094
6095            case 7:
6096               MMC3_prg1 = data;
6097               mapper4_set_prg(space->machine);
6098               break;
6099         }
6100         break;
6101      }
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
6139      default:
6140         logerror("mapper119_w uncaught: %04x value: %02x\n", offset + 0x8000, data);
6141         break;
6142   }
6143}
6144
6145/*************************************************************
6146
6147    Mapper 120
6148
6149    Known Boards: Unknown Bootleg Board
6150    Games: Tobidase Daisakusen (FDS Conversion)
6151
6152    In MESS: Unsupported.
6153
6154*************************************************************/
6155
6156/*************************************************************
6157
6158    Mapper 121
6159
6160    Known Boards: Bootleg Board
6161    Games: The Panda Prince
6162
6163    MMC3 clone
6164
6165    In MESS: Unsupported.
6166
6167*************************************************************/
6168
6169/*************************************************************
6170
6171    Mapper 122
6172
6173    Known Boards: Undocumented / Unused ?!?
6174    Games: ----------
6175
6176    In MESS: ----------
6177
6178*************************************************************/
6179
6180/*************************************************************
6181
6182    Mapper 123
6183
6184    Known Boards: Bootleg Board ???
6185    Games: [no games in nes.hsi]
6186
6187    In MESS: Unsupported.
6188
6189*************************************************************/
6190
6191/*************************************************************
6192
6193    Mapper 124
6194
6195    Known Boards: Undocumented / Unused ?!?
6196    Games: ----------
6197
6198    In MESS: ----------
6199
6200*************************************************************/
6201
6202/*************************************************************
6203
6204    Mapper 125
6205
6206    Known Boards: Undocumented / Unused ?!?
6207    Games: ----------
6208
6209    In MESS: ----------
6210
6211*************************************************************/
6212
6213/*************************************************************
6214
6215    Mapper 126
6216
6217    Known Boards: Unknown Multigame Bootleg Board
6218    Games: [no games in nes.hsi]
6219
6220    In MESS: Unsupported.
6221
6222*************************************************************/
6223
6224/*************************************************************
6225
6226    Mapper 127
6227
6228    Known Boards: Undocumented / Unused ?!?
6229    Games: ----------
6230
6231    In MESS: ----------
6232
6233*************************************************************/
6234
6235/*************************************************************
6236
6237    Mapper 128
6238
6239    Known Boards: Undocumented / Unused ?!?
6240    Games: ----------
6241
6242    In MESS: ----------
6243
6244*************************************************************/
6245
6246/*************************************************************
6247
6248    Mapper 129
6249
6250    Known Boards: Undocumented / Unused ?!?
6251    Games: ----------
6252
6253    In MESS: ----------
6254
6255*************************************************************/
6256
6257/*************************************************************
6258
6259    Mapper 130
6260
6261    Known Boards: Undocumented / Unused ?!?
6262    Games: ----------
6263
6264    In MESS: ----------
6265
6266*************************************************************/
6267
6268/*************************************************************
6269
6270    Mapper 131
6271
6272    Known Boards: Undocumented / Unused ?!?
6273    Games: ----------
6274
6275    In MESS: ----------
6276
6277*************************************************************/
6278
6279/*************************************************************
6280
6281    Mapper 132
6282
6283    Known Boards: Bootleg Board by TXC (T22211A)
6284    Games: Creatom
6285
6286    Info from NEStopia: this mapper features write to four
6287    registers (0x4100-0x4103). The third one is used to select
6288    PRG and CHR banks.
6289
6290    In MESS: Supported.
6291
6292*************************************************************/
6293
6294UINT8 txc_reg[4]; // also used by mappers 172 & 173
6295
6296static WRITE8_HANDLER( mapper132_l_w )
6297{
6298   LOG_MMC(("mapper132_l_w, offset: %04x, data: %02x\n", offset, data));
6299
6300   if (offset < 4)
6301      txc_reg[offset & 0x03] = data;
6302}
6303
6304static READ8_HANDLER( mapper132_l_r )
6305{
6306   LOG_MMC(("mapper132_l_r, offset: %04x\n", offset));
6307
6308   if (offset == 0x0000)
6309      return (txc_reg[1] ^ txc_reg[2]) | 0x40;
6310
6311   else
6312      return 0x00;
6313}
6314
6315static WRITE8_HANDLER( mapper132_w )
6316{
6317   LOG_MMC(("mapper132_w, offset: %04x, data: %02x\n", offset, data));
6318
6319   prg32(space->machine, txc_reg[2] >> 2);
6320   chr8(space->machine, txc_reg[2], CHRROM);
6321}
6322
6323/*************************************************************
6324
6325    Mapper 133
6326
6327    Known Boards: Bootleg Board by Sachen (SA72008)
6328    Games: Jovial Race, Qi Wang
6329
6330    In MESS: Supported.
6331
6332*************************************************************/
6333
47166334static WRITE8_HANDLER( mapper133_l_w )
47176335{
4718   LOG_MMC(("mapper133_w %04x:%02x\n", offset, data));
6336   LOG_MMC(("mapper133_l_w %04x:%02x\n", offset, data));
47196337
4720   //I think this is the right value
4721   if(offset!=0x20)
4722      return;
47236338   prg32(space->machine, data >> 2);
4724   chr8(space->machine, data & 3, CHRROM);
6339   chr8(space->machine, data, CHRROM);
47256340}
47266341
6342/*************************************************************
6343
6344    Mapper 134
6345
6346    Known Boards: Unknown Multigame Bootleg Board (4646B)
6347    Games: 2 in 1 - Family Camp & Aladdin 4
6348
6349    MMC3 clone
6350
6351    In MESS: Unsupported.
6352
6353*************************************************************/
6354
6355/*************************************************************
6356
6357    Mapper 135
6358
6359    Known Boards: Undocumented / Unused ?!?
6360    Games: ----------
6361
6362    In MESS: ----------
6363
6364*************************************************************/
6365
6366/*************************************************************
6367
6368    Mapper 136
6369
6370    Known Boards: Bootleg Board by Sachen (TCU02)
6371    Games: Mei Loi Siu Ji
6372
6373    In MESS: Supported.
6374
6375*************************************************************/
6376
6377static WRITE8_HANDLER( mapper136_l_w )
6378{
6379   LOG_MMC(("mapper136_l_w, offset: %04x, data: %02x\n", offset, data));
6380
6381   if ((offset & 0x103) == 0x002)
6382   {
6383      mmc_cmd1 = (data & 0x30) | ((data + 3) & 0x0f);
6384      chr8(space->machine, mmc_cmd1, CHRROM);
6385   }
6386}
6387
6388static READ8_HANDLER( mapper136_l_r )
6389{
6390   LOG_MMC(("mapper136_l_r, offset: %04x\n", offset));
6391
6392   if ((offset & 0x103) == 0x000)
6393      return mmc_cmd1 | 0x40;
6394   else
6395      return 0x00;
6396}
6397
6398/*************************************************************
6399
6400    Mapper 137
6401
6402    Known Boards: Bootleg Board by Sachen (8259D)
6403    Games: The Great Wall
6404
6405    In MESS: Supported.
6406
6407*************************************************************/
6408
6409UINT8 sachen_regs[8]; // used by mappers 137, 138, 139, 141
6410
6411static void sachen_set_mirror( UINT8 nt ) // used by mappers 137, 138, 139, 141
6412{
6413   switch (nt)
6414   {
6415   case 0:
6416   case 1:
6417      set_nt_mirroring(nt ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
6418      break;
6419   case 2:
6420      set_nt_page(0, CIRAM, 0, 1);
6421      set_nt_page(1, CIRAM, 1, 1);
6422      set_nt_page(2, CIRAM, 1, 1);
6423      set_nt_page(3, CIRAM, 1, 1);
6424      break;
6425   case 3:
6426      set_nt_mirroring(PPU_MIRROR_LOW);
6427      break;
6428   default:
6429      LOG_MMC(("Mapper set NT to invalid value %02x", nt));
6430      break;
6431   }
6432}
6433
6434static WRITE8_HANDLER( mapper137_l_w )
6435{
6436   LOG_MMC(("mapper137_l_w, offset: %04x, data: %02x\n", offset, data));
6437
6438   /* write happens only if we are at 0x4100 + k * 0x200,
6439   but 0x4100 is offset = 0 */
6440   if (!(offset & 0x100))
6441   {
6442      if (!(offset & 0x01))
6443         mmc_cmd1 = data & 0x07;
6444      else
6445      {
6446         sachen_regs[mmc_cmd1] = data;
6447
6448         switch (mmc_cmd1)
6449         {
6450         case 0x05:
6451            prg32(space->machine, data);
6452            break;
6453         case 0x07:
6454            sachen_set_mirror((data & 0x01) ? 0 : (data >> 1) & 0x03);
6455            break;
6456         default:
6457            if (mmc_chr_source == CHRROM)
6458            {
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);
6463            }
6464            break;
6465         }
6466      }
6467   }
6468}
6469
6470static WRITE8_HANDLER( mapper137_m_w )
6471{
6472   LOG_MMC(("mapper137_m_w, offset: %04x, data: %02x\n", offset, data));
6473
6474   mapper137_l_w(space, (offset + 0x100) & 0x01, data);
6475}
6476
6477/*************************************************************
6478
6479    Mapper 138
6480
6481    Known Boards: Bootleg Board by Sachen (8259B)
6482    Games: Silver Eagle
6483
6484    In MESS: Supported.
6485
6486*************************************************************/
6487
6488static WRITE8_HANDLER( mapper138_l_w )
6489{
6490   UINT8 bank_helper1 = 0, bank_helper2 = 0;
6491   LOG_MMC(("mapper138_l_w, offset: %04x, data: %02x\n", offset, data));
6492
6493   /* write happens only if we are at 0x4100 + k * 0x200,
6494   but 0x4100 is offset = 0 */
6495   if (!(offset & 0x100))
6496   {
6497      if (!(offset & 0x01))
6498         mmc_cmd1 = data & 0x07;
6499      else
6500      {
6501         sachen_regs[mmc_cmd1] = data;
6502   
6503         switch (mmc_cmd1)
6504         {
6505         case 0x05:
6506            prg32(space->machine, data);
6507            break;
6508         case 0x07:
6509            sachen_set_mirror((data & 0x01) ? 0 : (data >> 1) & 0x03);
6510            break;
6511         default:
6512            if (mmc_chr_source == CHRROM)
6513            {
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);
6520            }
6521            break;
6522         }
6523      }
6524   }
6525}
6526
6527static WRITE8_HANDLER( mapper138_m_w )
6528{
6529   LOG_MMC(("mapper138_m_w, offset: %04x, data: %02x\n", offset, data));
6530
6531   mapper138_l_w(space, offset & 0x01, data);
6532}
6533
6534/*************************************************************
6535
6536    Mapper 139
6537
6538    Known Boards: Bootleg Board by Sachen (8259C)
6539    Games: Final Combat, Hell Fighter, Mahjong Companion,
6540
6541    In MESS: Supported.
6542
6543*************************************************************/
6544
6545static WRITE8_HANDLER( mapper139_l_w )
6546{
6547   UINT8 bank_helper1 = 0, bank_helper2 = 0;
6548   LOG_MMC(("mapper139_l_w, offset: %04x, data: %02x\n", offset, data));
6549
6550   /* write happens only if we are at 0x4100 + k * 0x200,
6551   but 0x4100 is offset = 0 */
6552   if (!(offset & 0x100))
6553   {
6554      if (!(offset & 0x01))
6555         mmc_cmd1 = data & 0x07;
6556      else
6557      {
6558         sachen_regs[mmc_cmd1] = data;
6559   
6560         switch (mmc_cmd1)
6561         {
6562         case 0x05:
6563            prg32(space->machine, data);
6564            break;
6565         case 0x07:
6566            sachen_set_mirror((data & 0x01) ? 0 : (data >> 1) & 0x03);
6567            break;
6568         default:
6569            if (mmc_chr_source == CHRROM)
6570            {
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);
6577            }
6578            break;
6579         }
6580      }
6581   }
6582}
6583
6584static WRITE8_HANDLER( mapper139_m_w )
6585{
6586   LOG_MMC(("mapper139_m_w, offset: %04x, data: %02x\n", offset, data));
6587
6588   mapper139_l_w(space, (offset + 0x100) & 0x01, data);
6589}
6590
6591/*************************************************************
6592
6593    Mapper 140
6594
6595    Known Boards: Jaleco JF11, JF12, JF14
6596    Games: Bio Senshi Dan, Mississippi Satsujin Jiken
6597
6598    Writes to 0x6000-0x7fff set both prg32 and chr8 banks
6599
6600    In MESS: Supported.
6601
6602*************************************************************/
6603
47276604static WRITE8_HANDLER( mapper_140_m_w )
47286605{
4729       chr8(space->machine, data&0x0f, CHRROM);
6606       chr8(space->machine, data & 0x0f, CHRROM);
47306607       prg32(space->machine, (data >> 4) & 0x03);
47316608}
47326609
6610/*************************************************************
6611
6612    Mapper 141
6613
6614    Known Boards: Bootleg Board by Sachen (8259A)
6615    Games: Po Po Team, Poker Mahjong, Q Boy, Rockball,
6616          Super Cartridge (several versions), Super Pang (1 & 2)
6617
6618    In MESS: Supported.
6619
6620*************************************************************/
6621
6622static WRITE8_HANDLER( mapper141_l_w )
6623{
6624   UINT8 bank_helper1 = 0, bank_helper2 = 0;
6625   LOG_MMC(("mapper141_l_w, offset: %04x, data: %02x\n", offset, data));
6626
6627   /* write happens only if we are at 0x4100 + k * 0x200,
6628   but 0x4100 is offset = 0 */
6629   if (!(offset & 0x100))
6630   {
6631      if (!(offset & 0x01))
6632         mmc_cmd1 = data & 0x07;
6633      else
6634      {
6635         sachen_regs[mmc_cmd1] = data;
6636
6637         switch (mmc_cmd1)
6638         {
6639         case 0x05:
6640            prg32(space->machine, data);
6641            break;
6642         case 0x07:
6643            sachen_set_mirror((data & 0x01) ? 0 : (data >> 1) & 0x03);
6644            break;
6645         default:
6646            if (mmc_chr_source == CHRROM)
6647            {
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);
6654            }
6655            break;
6656         }
6657      }
6658   }
6659}
6660
6661static WRITE8_HANDLER( mapper141_m_w )
6662{
6663   LOG_MMC(("mapper141_m_w, offset: %04x, data: %02x\n", offset, data));
6664
6665   mapper141_l_w(space, (offset + 0x100) & 0x01, data);
6666}
6667
6668/*************************************************************
6669
6670    Mapper 142
6671
6672    Known Boards: Bootleg Board by Kaiser (KS7032)
6673    Games: Super Mario Bros. 2 (by Kaiser), Pipe 5 (by Sachen?)
6674
6675    In MESS: Unsupported. Requires reads from 0x6000-0x7fff.
6676
6677*************************************************************/
6678
6679/*************************************************************
6680
6681    Mapper 143
6682
6683    Known Boards: Bootleg Board by Sachen (TCA01)
6684    Games: Dancing Blocks, Magic Mathematic
6685
6686    In MESS: Supported.
6687
6688*************************************************************/
6689
6690static READ8_HANDLER( mapper143_l_r )
6691{
6692   LOG_MMC(("mapper143_l_r, offset: %04x\n", offset));
6693
6694   /* the address is read only if we are at 0x4100 + k * 0x200,
6695   but 0x4100 is offset = 0 */
6696   if (!(offset & 0x100))
6697      return (~offset & 0x3f) | 0x40;
6698   else
6699      return 0x00;
6700}
6701
6702/*************************************************************
6703
6704    Mapper 144
6705
6706    Known Boards: Bootleg Board by AGCI (50282)
6707    Games: Death Race
6708
6709    Just like mapper 11, except bit 0 taken from ROM and 0x8000
6710    ignored?
6711
6712    In MESS: Supported.
6713
6714*************************************************************/
6715
47336716static WRITE8_HANDLER( mapper144_w )
47346717{
4735   LOG_MMC(("* Mapper 144 switch, data: %02x\n", data));
6718   LOG_MMC(("mapper144_w, offset: %04x, data: %02x\n", offset, data));
47366719
4737   //just like mapper 11, except bit 0 taken from ROM
4738   //and 0x8000 ignored?
4739
47406720   if ((offset & 0x7fff) == 0)
47416721      return;
47426722
r5926r5927
47496729   prg32(space->machine, data & 0x07);
47506730}
47516731
6732/*************************************************************
6733
6734    Mapper 145
6735
6736    Known Boards: Bootleg Board by Sachen (SA72007)
6737    Games: Sidewinder
6738
6739    Simple mapper: writes to 0x4100 set chr8 banks.
6740
6741    In MESS: Supported.
6742
6743*************************************************************/
6744
6745static WRITE8_HANDLER( mapper145_l_w )
6746{
6747   LOG_MMC(("mapper145_l_w %04x:%02x\n", offset, data));
6748
6749   /* only if we are at 0x4100 + k * 0x200, but 0x4100 is offset = 0 */
6750   if (!(offset & 0x100))
6751      chr8(space->machine, data >> 7, CHRROM);
6752}
6753
6754/*************************************************************
6755
6756    Mapper 146
6757
6758    Known Boards: Bootleg Board by Sachen (SA0161M)
6759    Games: Galactic Crusader, Lucky 777, Metal Fighter,
6760          Millionaire, Pyramid II
6761
6762    This is basically the same as Nina-006 (Mapper 79)
6763
6764    In MESS: Supported. It shares the handler with mapper 79
6765
6766*************************************************************/
6767
6768/*************************************************************
6769
6770    Mapper 147
6771
6772    Known Boards: Bootleg Board by Sachen (TCU01)
6773    Games: Challenge of the Dragon, Chinese Kungfu
6774
6775    Simple mapper: writes to 0x4102 set pgr32 and chr8 banks.
6776
6777    In MESS: Supported.
6778
6779*************************************************************/
6780
6781static WRITE8_HANDLER( mapper147_l_w )
6782{
6783   LOG_MMC(("mapper147_l_w, offset: %04x, data: %02x\n", offset, data));
6784
6785   if ((offset & 0x103) == 0x002)
6786   {
6787      prg32(space->machine, ((data >> 6) & 0x02) | ((data >> 2) & 0x01));
6788      chr8(space->machine, data >> 3, CHRROM);
6789   }
6790}
6791
6792static WRITE8_HANDLER( mapper147_m_w )
6793{
6794   LOG_MMC(("mapper147_m_w, offset: %04x, data: %02x\n", offset, data));
6795
6796   mapper147_l_w(space, offset & 0x01, data);
6797}
6798
6799static WRITE8_HANDLER( mapper147_w )
6800{
6801   LOG_MMC(("mapper147_w, offset: %04x, data: %02x\n", offset, data));
6802
6803   mapper147_l_w(space, (offset + 0x100) & 0x01, data);
6804}
6805
6806/*************************************************************
6807
6808    Mapper 148
6809
6810    Known Boards: Bootleg Board by Sachen (SA0037)
6811    Games: Mahjong World, Shisen Mahjong
6812
6813    Very simple mapper: writes to 0x8000-0xffff set pgr32 and chr8
6814        banks
6815
6816    In MESS: Supported.
6817
6818*************************************************************/
6819
6820static WRITE8_HANDLER( mapper148_w )
6821{
6822   LOG_MMC(("mapper148_w, offset: %04x, data: %02x\n", offset, data));
6823
6824   prg32(space->machine, data >> 3 & 0x01);
6825   chr8(space->machine, data & 0x07, CHRROM);
6826}
6827
6828/*************************************************************
6829
6830    Mapper 149
6831
6832    Known Boards: Bootleg Board by Sachen (SA0036)
6833    Games: Taiwan Mahjong 16
6834
6835    Very simple mapper: writes to 0x8000-0xffff set chr8 banks
6836
6837    In MESS: Supported.
6838
6839*************************************************************/
6840
6841static WRITE8_HANDLER( mapper149_w )
6842{
6843   LOG_MMC(("mapper149_w, offset: %04x, data: %02x\n", offset, data));
6844
6845   chr8(space->machine, data >> 7, CHRROM);
6846}
6847
6848/*************************************************************
6849
6850    Mapper 150
6851
6852    Known Boards: Bootleg Board by Sachen (74SL374B)
6853    Games: Chess Academy, Chinese Checkers Jpn, Mahjong Academy,
6854          Olympic IQ, Poker II, Tasac
6855
6856    Still investigating this mapper...
6857
6858    In MESS: Preliminary Support.
6859
6860*************************************************************/
6861
6862static WRITE8_HANDLER( mapper150_l_w )
6863{
6864   LOG_MMC(("mapper150_l_w, offset: %04x, data: %02x\n", offset, data));
6865
6866   /* write happens only if we are at 0x4100 + k * 0x200,
6867   but 0x4100 is offset = 0 */
6868   if (!(offset & 0x100))
6869   {
6870      if (!(offset & 0x01))
6871         mmc_cmd1 = data & 0x07;
6872      else
6873      {
6874         switch (mmc_cmd1)
6875         {
6876         case 0x02:
6877            prg32(space->machine, data & 0x01);
6878            chr8(space->machine, (mmc_bank_latch1 & ~0x08) | ((data << 3) & 0x08), CHRROM);
6879            break;
6880         case 0x04:
6881            chr8(space->machine, (mmc_bank_latch1 & ~0x04) | ((data << 2) & 0x04), CHRROM);
6882            break;
6883         case 0x05:
6884            prg32(space->machine, data & 0x07);
6885            break;
6886         case 0x06:
6887            chr8(space->machine, (mmc_bank_latch1 & ~0x03) | (data << 0 & 0x03), CHRROM);
6888            break;
6889         case 0x07:
6890            sachen_set_mirror((data >> 1) & 0x03);
6891            break;
6892         default:
6893            break;
6894         }
6895      }
6896   }
6897}
6898
6899static READ8_HANDLER( mapper150_l_r )
6900{
6901   LOG_MMC(("mapper150_l_r, offset: %04x", offset));
6902
6903   /* read  happens only if we are at 0x4100 + k * 0x200,
6904   but 0x4100 is offset = 0 */
6905   if (!(offset & 0x100))
6906      return (~mmc_cmd1 & 0x3f) /* ^ dips*/;   // we would need to check the Dips here
6907   else
6908      return 0;
6909}
6910
6911static WRITE8_HANDLER( mapper150_m_w )
6912{
6913   LOG_MMC(("mapper150_m_w, offset: %04x, data: %02x\n", offset, data));
6914
6915   mapper150_l_w(space, (offset + 0x100) & 0x01, data);
6916}
6917
6918/*************************************************************
6919
6920    Mapper 151
6921
6922    Known Boards: Konami VS System
6923    Games: Goonies VS, VS TKO Boxing
6924
6925    In MESS: Unsupported, low priority (you should use MAME)
6926
6927*************************************************************/
6928
6929/*************************************************************
6930
6931    Mapper 152
6932
6933    Known Boards: Discrete Logic Mapper
6934    Games: Arkanoid 2, Gegege no Kitarou 2, Pocket Zaurus
6935
6936    In MESS: Supported.
6937
6938*************************************************************/
6939
6940static WRITE8_HANDLER( mapper152_w )
6941{
6942   LOG_MMC(("mapper152_w, offset: %04x, data: %02x\n", offset, data));
6943
6944   // we lack bus emulation
6945   set_nt_mirroring((data & 0x80) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
6946   prg16_89ab(space->machine, (data >> 4) & 0x07);
6947   chr8(space->machine, data, CHRROM);
6948}
6949
6950/*************************************************************
6951
6952    Mapper 153
6953
6954    Known Boards: Bandai Board
6955    Games: Dragon Ball, Dragon Ball 3, Famicom Jump, Famicom
6956          Jump II
6957
6958    In MESS: Unsupported.
6959
6960*************************************************************/
6961
6962/*************************************************************
6963
6964    Mapper 154
6965
6966    Known Boards: Namcot 34xx
6967    Games: Devil Man
6968
6969    Acts like mapper 88, but writes to 0x8000 set NT mirroring
6970
6971    In MESS: Supported.
6972
6973*************************************************************/
6974
47526975static WRITE8_HANDLER( mapper154_w )
47536976{
6977   LOG_MMC(("mapper154_w, offset: %04x, data: %02x\n", offset, data));
47546978   switch (offset & 1)
47556979   {
47566980   case 0:
47576981      {
4758         (data & 0x40) ? set_nt_mirroring(PPU_MIRROR_HIGH) : set_nt_mirroring(PPU_MIRROR_LOW);
4759         mapper154_reg = data & 7;
6982         set_nt_mirroring((data & 0x40) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
6983         mmc_cmd1 = data & 7;
47606984         break;
47616985      }
47626986   case 1:
47636987      {
4764         switch (mapper154_reg)
6988         switch (mmc_cmd1)
47656989         {
47666990            case 0: chr2_0(space->machine, data >> 1, CHRROM); break;
47676991            case 1: chr2_2(space->machine, data >> 1, CHRROM); break;
r5926r5927
47777001   }
47787002}
47797003
7004/*************************************************************
7005
7006    Mapper 155
7007
7008    Known Boards: ???
7009    Games: Tatakae!! Rahmen Man - Sakuretsu Choujin 102 Gei
7010
7011    In MESS: Unsupported.
7012
7013*************************************************************/
7014
7015/*************************************************************
7016
7017    Mapper 156
7018
7019    Known Boards: Bootleg Board by Open Corp (DAOU306)
7020    Games: Metal Force (K)?
7021
7022    In MESS: Supported.
7023
7024*************************************************************/
7025
7026static WRITE8_HANDLER( mapper156_w )
7027{
7028   LOG_MMC(("mapper156_w, offset: %04x, data: %02x\n", offset, data));
7029
7030   switch (offset)
7031   {
7032   case 0x4000:
7033      chr1_0(space->machine, data, CHRROM);
7034      break;
7035   case 0x4001:
7036      chr1_1(space->machine, data, CHRROM);
7037      break;
7038   case 0x4002:
7039      chr1_2(space->machine, data, CHRROM);
7040      break;
7041   case 0x4003:
7042      chr1_3(space->machine, data, CHRROM);
7043      break;
7044   case 0x4008:
7045      chr1_4(space->machine, data, CHRROM);
7046      break;
7047   case 0x4009:
7048      chr1_5(space->machine, data, CHRROM);
7049      break;
7050   case 0x400a:
7051      chr1_6(space->machine, data, CHRROM);
7052      break;
7053   case 0x400b:
7054      chr1_7(space->machine, data, CHRROM);
7055      break;
7056   case 0x4010:
7057      prg16_89ab(space->machine, data);
7058      break;
7059   }
7060}
7061
7062/*************************************************************
7063
7064    Mapper 157
7065
7066    Known Boards: Bandai Datach Board
7067    Games: Datach Games
7068
7069    In MESS: Unsupported. Needs reads from 0x6000-0x7fff for the
7070      Datach barcode reader
7071
7072*************************************************************/
7073
7074/*************************************************************
7075
7076    Mapper 158
7077
7078    Known Boards: Tengen 800037
7079    Games: Alien Syndrome
7080
7081    In MESS: Unsupported.
7082
7083*************************************************************/
7084
7085/*************************************************************
7086
7087    Mapper 159
7088
7089    Known Boards: Bandai Board
7090    Games: Dragon Ball Z, Magical Taruruuto-kun, SD Gundam Gaiden
7091
7092    In MESS: Unsupported.
7093
7094*************************************************************/
7095
7096/*************************************************************
7097
7098    Mapper 160
7099
7100    Known Boards: Undocumented / Unused ?!?
7101    Games: ----------
7102
7103    In MESS: ----------
7104
7105*************************************************************/
7106
7107/*************************************************************
7108
7109    Mapper 161
7110
7111    Known Boards: Undocumented / Unused ?!?
7112    Games: ----------
7113
7114    In MESS: ----------
7115
7116*************************************************************/
7117
7118/*************************************************************
7119
7120    Mapper 162
7121
7122    Known Boards: Undocumented / Unused ?!?
7123    Games: ----------
7124
7125    In MESS: ----------
7126
7127*************************************************************/
7128
7129/*************************************************************
7130
7131    Mapper 163
7132
7133    Known Boards: Bootleg Board by Nanjing
7134    Games: Diablo, Final Fantasy VII, Harvest Moon, He Xin Wei
7135          Ji, Yu-Gi-Oh, Zelda - Shen Qi De Mao Zi and other
7136
7137    In MESS: Unsupported.
7138
7139*************************************************************/
7140
7141/*************************************************************
7142
7143    Mapper 164
7144
7145    Known Boards: Bootleg Board by Waixing
7146    Games: Darkseed, Digital Dragon, Final Fantasy V, Pocket
7147          Monster Red
7148
7149    In MESS: Supported.
7150
7151*************************************************************/
7152
47807153static WRITE8_HANDLER( mapper164_l_w )
47817154{
7155   LOG_MMC(("mapper164_l_w, offset: %04x, data: %02x\n", offset, data));
47827156   offset += 0x4100; /* the checks work better on addresses */
7157
47837158   if (0x5000 == (offset & 0x7300))
47847159      prg32(space->machine, data);
47857160}
47867161
47877162static WRITE8_HANDLER( mapper164_w )
47887163{
7164   LOG_MMC(("mapper164_w, offset: %04x, data: %02x\n", offset, data));
47897165   if ((offset & 0x7300) == 0x5000)
47907166      prg32(space->machine, data);
47917167}
47927168
4793static WRITE8_HANDLER( mapper88_w )
7169/*************************************************************
7170
7171    Mapper 165
7172
7173    Known Boards: Bootleg Board by Waixing
7174    Games: Fire Emblem (C), Fire Emblem Gaiden (C)
7175
7176    MMC3 clone
7177
7178    In MESS: Unsupported.
7179
7180*************************************************************/
7181
7182/*************************************************************
7183
7184    Mapper 166
7185
7186    Known Boards: Bootleg Board by Subor (Type 1)
7187    Games: Subor v1.0 (R)
7188
7189    In MESS: Supported.
7190
7191*************************************************************/
7192
7193UINT8 subor_reg[4];   // used also by 167 below
7194
7195static WRITE8_HANDLER( mapper166_w )
47947196{
4795   switch (offset & 1)
7197   UINT8 map166_helper1, map166_helper2;
7198   LOG_MMC(("mapper166_w, offset: %04x, data: %02x\n", offset, data));
7199
7200   subor_reg[(offset >> 13) & 0x03] = data;
7201   map166_helper1 = ((subor_reg[0] ^ subor_reg[1]) << 1) & 0x20;
7202   map166_helper2 = ((subor_reg[2] ^ subor_reg[3]) << 0) & 0x1f;
7203
7204   if (subor_reg[1] & 0x08)
47967205   {
4797   case 0:
4798      {
4799         //(data & 0x40) ? set_nt_mirroring(PPU_MIRROR_HIGH) : set_nt_mirroring(PPU_MIRROR_LOW);
4800         mapper154_reg = data & 7;
4801         break;
4802      }
4803   case 1:
4804      {
4805         switch (mapper154_reg)
4806         {
4807            case 0: chr2_0(space->machine, (data & 0x3f) >> 1, CHRROM); break;
4808            case 1: chr2_2(space->machine, (data & 0x3f) >> 1, CHRROM); break;
4809            case 2: chr1_4(space->machine, (data & 0x3f) | 0x40, CHRROM); break;
4810            case 3: chr1_5(space->machine, (data & 0x3f) | 0x40, CHRROM); break;
4811            case 4: chr1_6(space->machine, (data & 0x3f) | 0x40, CHRROM); break;
4812            case 5: chr1_7(space->machine, (data & 0x3f) | 0x40, CHRROM); break;
4813            case 6: prg8_89(space->machine,data); break;
4814            case 7: prg8_ab(space->machine,data); break;
7206      map166_helper1 += map166_helper2 & 0xfe;
7207      map166_helper2 = map166_helper1;
7208      map166_helper2 += 1;
7209   }
7210   else if (subor_reg[1] & 0x04)
7211   {
7212      map166_helper2 += map166_helper1;
7213      map166_helper1 = 0x1f;
7214   }
7215   else
7216   {
7217      map166_helper1 += map166_helper2;
7218      map166_helper2 = 0x07;
7219   }
48157220
4816         }
4817         break;
4818      }
7221   prg16_89ab(space->machine, map166_helper1);
7222   prg16_cdef(space->machine, map166_helper2);
7223}
7224
7225/*************************************************************
7226
7227    Mapper 167
7228
7229    Known Boards: Bootleg Board by Subor (Type 0)
7230    Games: Subor v4.0 (C), English Word Blaster
7231
7232    Basically the same as 166, except for the initial prg
7233    bank and a couple of bits in the choice of prg banks
7234
7235    In MESS: Supported.
7236
7237*************************************************************/
7238
7239static WRITE8_HANDLER( mapper167_w )
7240{
7241   UINT8 map167_helper1, map167_helper2;
7242   LOG_MMC(("mapper167_w, offset: %04x, data: %02x\n", offset, data));
7243
7244   subor_reg[(offset >> 13) & 0x03] = data;
7245   map167_helper1 = ((subor_reg[0] ^ subor_reg[1]) << 1) & 0x20;
7246   map167_helper2 = ((subor_reg[2] ^ subor_reg[3]) << 0) & 0x1f;
7247
7248   if (subor_reg[1] & 0x08)
7249   {
7250      map167_helper1 += map167_helper2 & 0xfe;
7251      map167_helper2 = map167_helper1;
7252      map167_helper1 += 1;
48197253   }
7254   else if (subor_reg[1] & 0x04)
7255   {
7256      map167_helper2 += map167_helper1;
7257      map167_helper1 = 0x1f;
7258   }
7259   else
7260   {
7261      map167_helper1 += map167_helper2;
7262      map167_helper2 = 0x20;
7263   }
7264
7265   prg16_89ab(space->machine, map167_helper1);
7266   prg16_cdef(space->machine, map167_helper2);
48207267}
7268
7269/*************************************************************
7270
7271    Mapper 168
7272
7273    Known Boards: ???
7274    Games: Racermate Challenger II
7275
7276    No info at all are available.
7277
7278    In MESS: Unsupported.
7279
7280*************************************************************/
7281
7282/*************************************************************
7283
7284    Mapper 169
7285
7286    Known Boards: Undocumented / Unused ?!?
7287    Games: ----------
7288
7289    In MESS: ----------
7290
7291*************************************************************/
7292
7293/*************************************************************
7294
7295    Mapper 170
7296
7297    Known Boards: Bootleg Board by Fujiya
7298    Games: [no games in nes.hsi]
7299
7300    In MESS: Unsupported.
7301
7302*************************************************************/
7303
7304/*************************************************************
7305
7306    Mapper 171
7307
7308    Known Boards: Bootleg Board by Kaiser (KS7058)
7309    Games: Tui Do Woo Ma Jeung
7310
7311    Writes to 0xf000-0xffff set 4k chr banks. Namely, if
7312    offset&0x80 is 0 the lower 4k are set, if it is 1 the
7313    upper 4k are set.
7314
7315    In MESS: Supported.
7316
7317*************************************************************/
7318
7319static WRITE8_HANDLER( mapper171_w )
7320{
7321   LOG_MMC(("mapper171_w, offset: %04x, data: %02x\n", offset, data));
7322
7323   switch (offset & 0x7080)
7324   {
7325   case 0x7000:
7326      chr4_0(space->machine, data, CHRROM);
7327      break;
7328   case 0x7080:
7329      chr4_4(space->machine, data, CHRROM);
7330      break;
7331   }
7332}
7333
7334/*************************************************************
7335
7336    Mapper 172
7337
7338    Known Boards: Bootleg Board by TXC (T22211B)
7339    Games: 1991 Du Ma Racing
7340
7341    This mapper is basically the same as 132. Only difference is
7342    in the way CHR banks are selected (see below)
7343
7344    In MESS: Supported. It shares low handlers with board T22211A
7345      (mapper 132)
7346
7347*************************************************************/
7348
7349static WRITE8_HANDLER( mapper172_w )
7350{
7351   LOG_MMC(("mapper172_w, offset: %04x, data: %02x\n", offset, data));
7352
7353   prg32(space->machine, txc_reg[2] >> 2);
7354   chr8(space->machine, (((data ^ txc_reg[2]) >> 3) & 0x02) | (((data ^ txc_reg[2]) >> 5) & 0x01), CHRROM);
7355}
7356
7357/*************************************************************
7358
7359    Mapper 173
7360
7361    Known Boards: Bootleg Board by TXC (T22211C)
7362    Games: Mahjong Block, Xiao Ma Li
7363
7364    This mapper is basically the same as 132 too. Only difference is
7365    in 0x4100 reads which expect also bit 0 to be set
7366
7367    In MESS: Supported. It shares write handlers with board T22211A
7368      (mapper 132)
7369
7370*************************************************************/
7371
7372static READ8_HANDLER( mapper173_l_r )
7373{
7374   LOG_MMC(("mapper173_l_r, offset: %04x\n", offset));
7375
7376   if (offset == 0x0000)
7377      return (txc_reg[1] ^ txc_reg[2]) | 0x41;
7378   else
7379      return 0x00;
7380}
7381
7382/*************************************************************
7383
7384    Mapper 174
7385
7386    Known Boards: Undocumented / Unused ?!?
7387    Games: ----------
7388
7389    In MESS: ----------
7390
7391*************************************************************/
7392
7393/*************************************************************
7394
7395    Mapper 175
7396
7397    Known Boards: Bootleg Board by Kaiser (KS7022)
7398    Games: 15 in 1
7399
7400    In MESS: Unsupported. Requires reads from 0xfffc (according to
7401      NEStopia).
7402
7403*************************************************************/
7404
7405/*************************************************************
7406
7407    Mapper 176
7408
7409    Known Boards: Unknown Bootleg Board
7410    Games: Shu Qi Yu - Zhi Li Xiao Zhuan Yuan
7411
7412    Very simple mapper: writes to 0x5ff1 set prg32 (to data>>1),
7413    while writes to 0x5ff2 set chr8
7414
7415    In MESS: Supported.
7416
7417*************************************************************/
7418
7419static WRITE8_HANDLER( mapper176_l_w )
7420{
7421   LOG_MMC(("mapper176_l_w, offset: %04x, data: %02x\n", offset, data));
7422
7423   switch (offset)
7424   {
7425   case 0x1ef1:   /* 0x5ff1 */
7426      prg32(space->machine, data >> 1);
7427      break;
7428   case 0x1ef2:   /* 0x5ff2 */
7429      chr8(space->machine, data, CHRROM);
7430      break;
7431   }
7432}
7433
7434/*************************************************************
7435
7436    Mapper 177
7437
7438    Known Boards: Bootleg Board by Henggedianzi
7439    Games: Mei Guo Fu Hao, Shang Gu Shen Jian , Wang Zi Fu
7440          Chou Ji, Xing He Zhan Shi
7441
7442    Writes to 0x8000-0xffff set prg32. Moreover, data&0x20 sets
7443    NT mirroring.
7444
7445    In MESS: Supported.
7446
7447*************************************************************/
7448
7449static WRITE8_HANDLER( mapper177_w )
7450{
7451   LOG_MMC(("mapper177_w, offset: %04x, data: %02x\n", offset, data));
7452
7453   prg32(space->machine, data);
7454   set_nt_mirroring(((data & 0x20) >> 5) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
7455}
7456
7457/*************************************************************
7458
7459    Mapper 178
7460
7461    Known Boards: Bootleg Board by Waixing
7462    Games: Fan Kong Jing Ying, San Guo Zhong Lie Zhuan, Xing
7463          Ji Zheng Ba
7464
7465    In MESS: Supported.
7466
7467*************************************************************/
7468
7469static WRITE8_HANDLER( mapper178_l_w )
7470{
7471   LOG_MMC(("mapper178_l_w, offset: %04x, data: %02x\n", offset, data));
7472
7473   switch (offset)
7474   {
7475   case 0x700:
7476      set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
7477      break;
7478   case 0x701:
7479      mmc_cmd1 = (mmc_cmd1 & 0x0c) | ((data >> 1) & 0x03);
7480      prg32(space->machine, mmc_cmd1);
7481      break;
7482   case 0x702:
7483      mmc_cmd1 = (mmc_cmd1 & 0x03) | ((data << 2) & 0x0c);
7484      break;
7485   }
7486}
7487
7488/*************************************************************
7489
7490    Mapper 179
7491
7492    Known Boards: Bootleg Board by Henggedianzi
7493    Games: Xing He Zhan Shi
7494
7495    Writes to 0x5000-0x5fff set prg32 banks, writes to 0x8000-
7496    0xffff set NT mirroring
7497
7498    In MESS: Supported.
7499
7500*************************************************************/
7501
7502static WRITE8_HANDLER( mapper179_l_w )
7503{
7504   LOG_MMC(("mapper179_l_w, offset: %04x, data: %02x\n", offset, data));
7505
7506   if ((offset - 0x100) & 0x1000)
7507      prg32(space->machine, data >> 1);
7508}
7509
7510static WRITE8_HANDLER( mapper179_w )
7511{
7512   LOG_MMC(("mapper179_w, offset: %04x, data: %02x\n", offset, data));
7513
7514   set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
7515}
7516
7517/*************************************************************
7518
7519    Mapper 180
7520
7521    Known Boards: Nihon Bussan UNROM
7522    Games: Crazy Climber Jpn
7523
7524    Very simple mapper: prg16_89ab is always set to bank 0,
7525    while prg16_cdef is set by writes to 0x8000-0xffff. The game
7526    uses a custim controller.
7527
7528    In MESS: Supported.
7529
7530*************************************************************/
7531
48217532static WRITE8_HANDLER( mapper180_w )
48227533{
4823   LOG_MMC(("* Mapper 180 switch, data: %02x\n", data));
7534   LOG_MMC(("mapper180_w, offset: %04x, data: %02x\n", offset, data));
48247535
4825   prg16_cdef(space->machine, data&7);
7536   prg16_cdef(space->machine, data & 0x07);
48267537}
48277538
7539/*************************************************************
7540
7541    Mapper 181
7542
7543    Known Boards: Undocumented / Unused ?!?
7544    Games: ----------
7545
7546    In MESS: ----------
7547
7548*************************************************************/
7549
7550/*************************************************************
7551
7552    Mapper 182
7553
7554    Known Boards: Bootleg Board by Hosenkan
7555    Games: Pocahontas, Super Donkey Kong
7556
7557    In MESS: Supported.
7558
7559*************************************************************/
7560
48287561static WRITE8_HANDLER( mapper182_w )
48297562{
48307563   LOG_MMC(("mapper182_w, offset: %04x, data: %02x\n", offset, data));
r5926r5927
48357568      set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
48367569      break;
48377570   case 0x2000:
4838      MMC1_bank1 = data;
7571      mmc_bank_latch1 = data;
48397572      break;
48407573   case 0x4000:
4841      switch (MMC1_bank1)
7574      switch (mmc_bank_latch1)
48427575      {
48437576      case 0:
48447577         chr2_0(space->machine, data >> 1, CHRROM);
r5926r5927
48887621
48897622      if (IRQ_enable && !blanked && (IRQ_count == 0) && priorCount)
48907623      {
4891         logerror("irq fired, scanline: %d (MAME %d, beam pos: %d)\n", scanline, video_screen_get_vpos(device->machine->primary_screen), video_screen_get_hpos(device->machine->primary_screen));
7624         LOG_MMC(("irq fired, scanline: %d (MAME %d, beam pos: %d)\n", scanline,
7625               video_screen_get_vpos(device->machine->primary_screen), video_screen_get_hpos(device->machine->primary_screen)));
48927626         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
48937627      }
48947628   }
48957629}
48967630
7631/*************************************************************
7632
7633    Mapper 183
7634
7635    Known Boards: Unknown Bootleg Board
7636    Games: Shui Guan Pipe
7637
7638    In MESS: Unsupported.
7639
7640*************************************************************/
7641
7642/*************************************************************
7643
7644    Mapper 184
7645
7646    Known Boards: Sunsoft 1
7647    Games: Atlantis no Nazo, Kanshakudama Nage Kantarou no
7648          Toukaidou Gojuusan Tsugi, Wing of Madoola
7649
7650    Very simple mapper: writes to 0x6000-0x7fff set chr banks
7651    (lower bits set chr4_0, higher ones set chr4_4)
7652
7653    In MESS: Supported.
7654
7655*************************************************************/
7656
48977657static WRITE8_HANDLER( mapper184_m_w )
48987658{
4899   LOG_MMC(("* Mapper 184 switch, data: %02x\n", data));
7659   LOG_MMC(("mapper184_m_w, offset: %04x, data: %02x\n", offset, data));
49007660
4901   if(0==offset)
4902   {
4903      chr4_0(space->machine, data & 0x0f, CHRROM);
4904      chr4_4(space->machine, data >> 4, CHRROM);
4905   }
7661   chr4_0(space->machine, data & 0x0f, CHRROM);
7662   chr4_4(space->machine, data >> 4, CHRROM);
49067663}
49077664
7665/*************************************************************
7666
7667    Mapper 185
7668
7669    Known Boards: CNROM
7670    Games: B-Wings, Mighty Bomb Jack, Seicross, Spy vs. Spy
7671
7672    In MESS: Unsupported.
7673
7674*************************************************************/
7675
7676/*************************************************************
7677
7678    Mapper 186
7679
7680    Known Boards: Bootleg Board by Fukutake
7681    Games: Study Box
7682
7683    In MESS: Unsupported. Needs reads from 0x6000-0x7fff.
7684
7685*************************************************************/
7686
7687/*************************************************************
7688
7689    Mapper 187
7690
7691    Known Boards: Unknown Bootleg Board
7692    Games: The King of Fighters 96, Sonic 3D Blast 6, Street
7693          Fighter Zero 2
7694
7695    MMC3 clone
7696
7697    In MESS: Unsupported.
7698
7699*************************************************************/
7700
7701/*************************************************************
7702
7703    Mapper 188
7704
7705    Known Boards: Bandai Karaoke Board
7706    Games: Karaoke Studio
7707
7708    In MESS: Partially Supported (missing mic support)
7709
7710*************************************************************/
7711
49087712static WRITE8_HANDLER( mapper188_w )
49097713{
49107714   LOG_MMC(("mapper188_w, offset: %04x, data: %02x\n", offset, data));
r5926r5927
49127716   prg16_89ab(space->machine, data ^ 0x08);
49137717}
49147718
7719/*************************************************************
7720
7721    Mapper 189
7722
7723    Known Boards: Bootleg Board by TXC
7724    Games: Master Fighter II, Master Fighter 3, Thunder Warrior
7725
7726    MMC3 clone
7727
7728    In MESS: Unsupported.
7729
7730*************************************************************/
7731
7732/*************************************************************
7733
7734    Mapper 190
7735
7736    Known Boards: Undocumented / Unused ?!?
7737    Games: ----------
7738
7739    In MESS: ----------
7740
7741*************************************************************/
7742
7743/*************************************************************
7744
7745    Mapper 191
7746
7747    Known Boards: Type B by Waixing
7748    Games: Sugoro Quest (C)
7749
7750    MMC3 clone
7751
7752    In MESS: Unsupported.
7753
7754*************************************************************/
7755
7756/*************************************************************
7757
7758    Mapper 192
7759
7760    Known Boards: Type C by Waixing
7761    Games: Ying Lie Qun Xia Zhuan, Young Chivalry
7762
7763    MMC3 clone
7764
7765    In MESS: Unsupported.
7766
7767*************************************************************/
7768
7769/*************************************************************
7770
7771    Mapper 193
7772
7773    Known Boards: Bootleg Board by NTDEC
7774    Games: Fighting Hero
7775
7776    Very simple mapper: writes to 0x6000-0x7fff swap PRG and
7777    CHR banks.
7778
7779    In MESS: Supported.
7780
7781*************************************************************/
7782
49157783static WRITE8_HANDLER( mapper193_m_w )
49167784{
49177785   LOG_MMC(("mapper193_m_w, offset: %04x, data: %02x\n", offset, data));
r5926r5927
49337801   }
49347802}
49357803
7804/*************************************************************
7805
7806    Mapper 194
7807
7808    Known Boards: Type D by Waixing
7809    Games: Super Robot Taisen (C)
7810
7811    MMC3 clone
7812
7813    In MESS: Unsupported.
7814
7815*************************************************************/
7816
7817/*************************************************************
7818
7819    Mapper 195
7820
7821    Known Boards: Type E by Waixing
7822    Games: Captain Tsubasa Vol. II (C), Chaos World, God
7823          Slayer (C), Zu Qiu Xiao Jiang
7824
7825    MMC3 clone
7826
7827    In MESS: Unsupported.
7828
7829*************************************************************/
7830
7831/*************************************************************
7832
7833    Mapper 196
7834
7835    Known Boards: Unknown Bootleg Board
7836    Games: Super Mario Bros. 11, Super Mario Bros. 17
7837
7838    This acts basically like a MMC3 with different use of write
7839    address.
7840
7841    In MESS: Supported.
7842
7843*************************************************************/
7844
7845static WRITE8_HANDLER( mapper196_w )
7846{
7847   LOG_MMC(("mapper196_w, offset: %04x, data: %02x\n", offset, data));
7848
7849   switch (offset & 0x6004)
7850   {
7851   case 0x0000:
7852      mapper4_w(space, 0x0000, data);
7853      break;
7854   case 0x0004:
7855      mapper4_w(space, 0x0001, data);
7856      break;
7857   case 0x2000:
7858      set_nt_mirroring(data & 0x01 ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);   // diff with MMC3: not check for data & 0x40
7859      break;
7860   case 0x2004:
7861      mapper4_w(space, 0x2001, data);
7862      break;
7863   case 0x4000:
7864      mapper4_w(space, 0x4000, data);
7865      break;
7866   case 0x4004:
7867      mapper4_w(space, 0x4001, data);
7868      break;
7869   case 0x6000:
7870      mapper4_w(space, 0x6000, data);
7871      break;
7872   case 0x6004:
7873      mapper4_w(space, 0x6001, data);
7874      break;
7875   default:
7876      break;
7877   }
7878}
7879
7880/*************************************************************
7881
7882    Mapper 197
7883
7884    Known Boards: Unknown Bootleg Board
7885    Games: Super Fighter III
7886
7887    MMC3 clone
7888
7889    In MESS: Unsupported.
7890
7891*************************************************************/
7892
7893/*************************************************************
7894
7895    Mapper 198
7896
7897    Known Boards: Type F by Waixing
7898    Games: Tenchi wo Kurau II (C)
7899
7900    MMC3 clone
7901
7902    In MESS: Unsupported.
7903
7904*************************************************************/
7905
7906/*************************************************************
7907
7908    Mapper 199
7909
7910    Known Boards: Type G by Waixing
7911    Games: San Guo Zhi 2, Dragon Ball Z Gaiden (C), Dragon
7912          Ball Z II (C)
7913
7914    MMC3 clone
7915
7916    In MESS: Unsupported.
7917
7918*************************************************************/
7919
7920/*************************************************************
7921
7922    Mapper 200
7923
7924    Known Boards: Unknown Bootleg Multigame Board
7925    Games: 36 in 1, 1200 in 1
7926
7927    In MESS: Supported.
7928
7929*************************************************************/
7930
49367931static WRITE8_HANDLER( mapper200_w )
49377932{
49387933   LOG_MMC(("mapper200_w, offset: %04x, data: %02x\n", offset, data));
r5926r5927
49447939   set_nt_mirroring((offset & 0x08) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
49457940}
49467941
7942/*************************************************************
7943
7944    Mapper 201
7945
7946    Known Boards: Unknown Bootleg Multigame Board
7947    Games: 8 in 1, 21 in 1
7948
7949    In MESS: Supported.
7950
7951*************************************************************/
7952
49477953static WRITE8_HANDLER( mapper201_w )
49487954{
49497955   LOG_MMC(("mapper201_w, offset: %04x, data: %02x\n", offset, data));
49507956
4951   if (offset & 0x08)
4952   {
4953      prg32(space->machine, offset & 0x03);
4954      chr8(space->machine, offset & 0x03, CHRROM);
4955   }
4956   else
4957   {
4958      prg32(space->machine, 0);
4959      chr8(space->machine, 0, CHRROM);
4960   }
7957   prg32(space->machine, offset & 0x03);
7958   chr8(space->machine, offset & 0x03, CHRROM);
49617959}
49627960
7961/*************************************************************
7962
7963    Mapper 202
7964
7965    Known Boards: Unknown Bootleg Multigame Board
7966    Games: 150 in 1
7967
7968    In MESS: Supported.
7969
7970*************************************************************/
7971
49637972static WRITE8_HANDLER( mapper202_w )
49647973{
4965   int   bank = (offset >> 1) & 0x07;
7974   int bank = (offset >> 1) & 0x07;
49667975
49677976   LOG_MMC(("mapper202_w, offset: %04x, data: %02x\n", offset, data));
49687977
r5926r5927
49737982   set_nt_mirroring((offset & 0x01) ? PPU_MIRROR_HORZ: PPU_MIRROR_VERT);
49747983}
49757984
7985/*************************************************************
7986
7987    Mapper 203
7988
7989    Known Boards: Unknown Bootleg Multigame Board
7990    Games: 35 in 1
7991
7992    In MESS: Supported.
7993
7994*************************************************************/
7995
49767996static WRITE8_HANDLER( mapper203_w )
49777997{
49787998   LOG_MMC(("mapper203_w, offset: %04x, data: %02x\n", offset, data));
r5926r5927
49828002   chr8(space->machine, data & 0x03, CHRROM);
49838003}
49848004
8005/*************************************************************
8006
8007    Mapper 204
8008
8009    Known Boards: Unknown Bootleg Multigame Board
8010    Games: 64 in 1
8011
8012    In MESS: Supported.
8013
8014*************************************************************/
8015
8016static WRITE8_HANDLER( mapper204_w )
8017{
8018   int bank = (offset >> 1) & (offset >> 2) & 0x01;
8019
8020   LOG_MMC(("mapper204_w, offset: %04x, data: %02x\n", offset, data));
8021
8022   prg16_89ab(space->machine, offset & ~bank);
8023   prg16_cdef(space->machine, offset | bank);
8024   chr8(space->machine, offset & ~bank, CHRROM);
8025
8026   set_nt_mirroring((offset & 0x10) ? PPU_MIRROR_HORZ: PPU_MIRROR_VERT);
8027}
8028
8029/*************************************************************
8030
8031    Mapper 205
8032
8033    Known Boards: Unknown Bootleg Multigame Board
8034    Games: 3 in 1, 15 in 1
8035
8036    MMC3 clone
8037
8038    In MESS: Unsupported.
8039
8040*************************************************************/
8041
8042/*************************************************************
8043
8044    Mapper 206
8045
8046    Known Boards: Namcot 34x3 boards, DEROM, DE1ROM, DRROM and
8047          Tengen 800002, 800004, 800030 boards
8048    Games: Babel no Tou, Dragon Buster II, Family Circuit,
8049          Family Tennis, Fantasy Zone, Gauntlet, Karnov,
8050          Mappy Land, Pac-Mania, R.B.I. Baseball, Super Sprint
8051
8052    In MESS: Supported.
8053
8054*************************************************************/
8055
49858056static WRITE8_HANDLER( mapper206_w )
49868057{
49878058   if ((offset & 0x6001) == 0x2000)
r5926r5927
49908061   mapper4_w(space, offset, data);
49918062}
49928063
8064/*************************************************************
8065
8066    Mapper 207
8067
8068    Known Boards: Taito X1-005 Ver. B
8069    Games: Fudou Myouou Den
8070
8071    Very similar to mapper 80, but with a very particular NT
8072    mirroring procedure (see below)
8073
8074    In MESS: Supported.
8075
8076*************************************************************/
8077
8078static WRITE8_HANDLER( mapper207_m_w )
8079{
8080   LOG_MMC(("mapper207_m_w, offset: %04x, data: %02x\n", offset, data));
8081
8082   switch (offset)
8083   {
8084      case 0x1ef0:
8085         set_nt_page(0, CIRAM, (data & 0x80) ? 1 : 0, 1);
8086         set_nt_page(1, CIRAM, (data & 0x80) ? 1 : 0, 1);
8087         /* Switch 2k VROM at $0000 */
8088         chr2_0(space->machine, (data & 0x7f) >> 1, CHRROM);
8089         break;
8090      case 0x1ef1:
8091         set_nt_page(2, CIRAM, (data & 0x80) ? 1 : 0, 1);
8092         set_nt_page(3, CIRAM, (data & 0x80) ? 1 : 0, 1);
8093         /* Switch 2k VROM at $0000 */
8094         chr2_2(space->machine, (data & 0x7f) >> 1, CHRROM);
8095         break;
8096      case 0x1ef2:
8097         /* Switch 1k VROM at $1000 */
8098         chr1_4(space->machine, data, CHRROM);
8099         break;
8100      case 0x1ef3:
8101         /* Switch 1k VROM at $1400 */
8102         chr1_5(space->machine, data, CHRROM);
8103         break;
8104      case 0x1ef4:
8105         /* Switch 1k VROM at $1800 */
8106         chr1_6(space->machine, data, CHRROM);
8107         break;
8108      case 0x1ef5:
8109         /* Switch 1k VROM at $1c00 */
8110         chr1_7(space->machine, data, CHRROM);
8111         break;
8112      case 0x1efa:
8113      case 0x1efb:
8114         /* Switch 8k ROM at $8000 */
8115         prg8_89(space->machine, data);
8116         break;
8117      case 0x1efc:
8118      case 0x1efd:
8119         /* Switch 8k ROM at $a000 */
8120         prg8_ab(space->machine, data);
8121         break;
8122      case 0x1efe:
8123      case 0x1eff:
8124         /* Switch 8k ROM at $c000 */
8125         prg8_cd(space->machine, data);
8126         break;
8127      default:
8128         logerror("mapper207_m_w uncaught addr: %04x, value: %02x\n", offset + 0x6000, data);
8129         break;
8130   }
8131}
8132
8133/*************************************************************
8134
8135    Mapper 208
8136
8137    Known Boards: 37017 (?) by Gouder
8138    Games: Street Fighter IV
8139
8140    MMC3 clone. It also requires reads from 0x5000-0x7fff.
8141
8142    In MESS: Unsupported.
8143
8144*************************************************************/
8145
8146/*************************************************************
8147
8148    Mapper 209
8149
8150    Known Boards: Type B by J.Y. Company
8151    Games: Power Rangers 3, Power Rangers 4, Shin Samurai
8152          Spirits 2
8153
8154    In MESS: Unsupported.
8155
8156*************************************************************/
8157
8158/*************************************************************
8159
8160    Mapper 210
8161
8162    Known Boards: Undocumented / Unused ?!?
8163    Games: ----------
8164
8165    In MESS: ----------
8166
8167*************************************************************/
8168
8169/*************************************************************
8170
8171    Mapper 211
8172
8173    Known Boards: Type C by J.Y. Company
8174    Games: Tiny Toon Adventures 6, Donkey Kong Country 4
8175
8176    In MESS: Unsupported.
8177
8178*************************************************************/
8179
8180/*************************************************************
8181
8182    Mapper 212
8183
8184    Known Boards: Unknown Bootleg Multigame Board
8185    Games: 100000 in 1, Super HIK 300 in 1, 1997 in 1
8186
8187    In MESS: Supported.
8188
8189*************************************************************/
8190
8191static WRITE8_HANDLER( mapper212_w )
8192{
8193   LOG_MMC(("mapper212_w, offset: %04x, data: %02x\n", offset, data));
8194
8195   set_nt_mirroring((offset & 0x08) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
8196   chr8(space->machine, offset, CHRROM);
8197
8198   if (offset < 0x4000)
8199   {
8200      prg16_89ab(space->machine, offset);
8201      prg16_cdef(space->machine, offset);
8202   }
8203   else
8204      prg32(space->machine, offset >> 1);
8205}
8206
8207/*************************************************************
8208
8209    Mapper 213
8210
8211    Known Boards: Unknown Bootleg Multigame Board
8212    Games: 9999999 in 1
8213
8214    In MESS: Supported.
8215
8216*************************************************************/
8217
8218static WRITE8_HANDLER( mapper213_w )
8219{
8220   LOG_MMC(("mapper213_w, offset: %04x, data: %02x\n", offset, data));
8221
8222   prg32(space->machine, offset >> 1);
8223   chr8(space->machine, offset >> 3, CHRROM);
8224}
8225
8226/*************************************************************
8227
8228    Mapper 214
8229
8230    Known Boards: Unknown Bootleg Multigame Board
8231    Games: Super Gun 20 in 1
8232
8233    In MESS: Supported.
8234
8235*************************************************************/
8236
8237static WRITE8_HANDLER( mapper214_w )
8238{
8239   LOG_MMC(("mapper214_w, offset: %04x, data: %02x\n", offset, data));
8240
8241   prg16_89ab(space->machine, offset >> 2);
8242   prg16_cdef(space->machine, offset >> 2);
8243   chr8(space->machine, offset, CHRROM);
8244}
8245
8246/*************************************************************
8247
8248    Mapper 215
8249
8250    Known Boards: Unknown Bootleg Board by Super Game
8251    Games: Boogerman, Mortal Kombat III
8252
8253    MMC3 clone. Also, it probably needs a hack to support both
8254    variants (Boogerman & MK3).
8255
8256    In MESS: Unsupported.
8257
8258*************************************************************/
8259
8260/*************************************************************
8261
8262    Mapper 216
8263
8264    Known Boards: Unknown Bootleg Board by RCM
8265    Games: Bonza, Magic Jewelry 2
8266
8267    Very simple mapper: writes to 0x8000-0xffff sets prg32
8268    to offset and chr8 to offset>>1 (when chrrom is present)
8269
8270    In MESS: Supported.
8271
8272*************************************************************/
8273
8274static WRITE8_HANDLER( mapper216_w )
8275{
8276   LOG_MMC(("mapper216_w, offset: %04x, data: %02x\n", offset, data));
8277
8278   prg32(space->machine, offset);
8279   chr8(space->machine, offset >> 1, mmc_chr_source);
8280}
8281
8282/*************************************************************
8283
8284    Mapper 217
8285
8286    Known Boards: Unknown Bootleg Multigame Board
8287    Games: Golden Card 6 in 1
8288
8289    MMC3 clone
8290
8291    In MESS: Unsupported.
8292
8293*************************************************************/
8294
8295/*************************************************************
8296
8297    Mapper 218
8298
8299    Known Boards: Undocumented / Unused ?!?
8300    Games: ----------
8301
8302    In MESS: ----------
8303
8304*************************************************************/
8305
8306/*************************************************************
8307
8308    Mapper 219
8309
8310    Known Boards: A9746??
8311    Games: [no games in nes.hsi]
8312
8313    MMC3 clone according to NEStopia
8314
8315    In MESS: Unsupported.
8316
8317*************************************************************/
8318
8319/*************************************************************
8320
8321    Mapper 220
8322
8323    Known Boards: ???
8324    Games: Summer Carnival '92 - Recca US ?? (MMC3 for nestopia)
8325
8326    In MESS: Unsupported.
8327
8328*************************************************************/
8329
8330/*************************************************************
8331
8332    Mapper 221
8333
8334    Known Boards: Unknown Bootleg Board, N625092
8335    Games: 400 in 1, 700 in 1, 1000 in 1
8336
8337    In MESS: Supported.
8338
8339*************************************************************/
8340
8341static void mapper221_set_prg( running_machine *machine, UINT8 reg1, UINT8 reg2 )
8342{
8343   UINT8 map221_helper1, map221_helper2;
8344
8345   map221_helper1 = !(reg1 & 0x01) ? reg2 :
8346            (reg1 & 0x80) ? reg2 : (reg2 & 0x06) | 0x00;
8347   map221_helper2 = !(reg1 & 0x01) ? reg2 :
8348            (reg1 & 0x80) ? 0x07 : (reg2 & 0x06) | 0x01;
8349
8350   prg16_89ab(machine, map221_helper1 | ((reg1 & 0x70) >> 1));
8351   prg16_cdef(machine, map221_helper2 | ((reg1 & 0x70) >> 1));
8352}
8353
8354static WRITE8_HANDLER( mapper221_w )
8355{
8356   LOG_MMC(("mapper221_w, offset: %04x, data: %02x\n", offset, data));
8357
8358   if (offset < 0x4000)
8359   {
8360      set_nt_mirroring(offset & 0x01 ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
8361      offset = (offset >> 1) & 0xff;
8362
8363      if (mmc_cmd1 != offset)
8364      {
8365         mmc_cmd1 = offset;
8366         mapper221_set_prg(space->machine, mmc_cmd1, mmc_cmd2);
8367      }
8368   }
8369   else
8370   {
8371      offset &= 0x07;
8372
8373      if (mmc_cmd2 != offset)
8374      {
8375         mmc_cmd2 = offset;
8376         mapper221_set_prg(space->machine, mmc_cmd1, mmc_cmd2);
8377      }
8378   }
8379}
8380
8381/*************************************************************
8382
8383    Mapper 222
8384
8385    Known Boards: Unknown Bootleg Board
8386    Games: Dragon Ninja (Bootleg), Super Mario Bros. 8
8387
8388    In MESS: Unsupported.
8389
8390*************************************************************/
8391
8392/*************************************************************
8393
8394    Mapper 223
8395
8396    Known Boards: Type I by Waixing
8397    Games: [no games in nes.hsi] Tang Mu Li Xian Ji?
8398
8399    MMC3 clone according to NEStopia
8400
8401    In MESS: Unsupported.
8402
8403*************************************************************/
8404
8405/*************************************************************
8406
8407    Mapper 224
8408
8409    Known Boards: Type J by Waixing
8410    Games: [no games in nes.hsi] Ying Xiong Chuan Qi?
8411
8412    MMC3 clone according to NEStopia
8413
8414    In MESS: Unsupported.
8415
8416*************************************************************/
8417
8418/*************************************************************
8419
8420    Mapper 225
8421
8422    Known Boards: Unknown Bootleg Multigame Board
8423    Games: 72 in 1, 115 in 1 and other multigame carts
8424
8425    In MESS: Supported.
8426
8427*************************************************************/
8428
49938429static WRITE8_HANDLER( mapper225_w )
49948430{
49958431   int hi_bank;
r5926r5927
49988434
49998435   LOG_MMC(("mapper225_w, offset: %04x, data: %02x\n", offset, data));
50008436
5001   chr8(space->machine, offset & 0x3f, CHRROM);
8437   chr8(space->machine, offset, CHRROM);
8438   set_nt_mirroring((offset & 0x2000) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
8439
50028440   hi_bank = offset & 0x40;
50038441   size_16 = offset & 0x1000;
50048442   bank = (offset & 0xf80) >> 7;
r5926r5927
50138451   }
50148452   else
50158453      prg32(space->machine, bank);
5016
5017   if (offset & 0x2000)
5018      set_nt_mirroring(PPU_MIRROR_HORZ);
5019   else
5020      set_nt_mirroring(PPU_MIRROR_VERT);
50218454}
50228455
8456/*************************************************************
8457
8458    Mapper 226
8459
8460    Known Boards: Unknown Bootleg Multigame Board
8461    Games: 76 in 1, Super 42 in 1
8462
8463    In MESS: Supported.
8464
8465*************************************************************/
8466
50238467static WRITE8_HANDLER( mapper226_w )
50248468{
50258469   int hi_bank;
50268470   int size_16;
50278471   int bank;
5028   static int reg0, reg1;
50298472
50308473   LOG_MMC(("mapper226_w, offset: %04x, data: %02x\n", offset, data));
50318474
50328475   if (offset & 0x01)
50338476   {
5034      reg1 = data;
8477      mmc_cmd2 = data;
50358478   }
50368479   else
50378480   {
5038      reg0 = data;
8481      mmc_cmd1 = data;
50398482   }
50408483
5041   hi_bank = reg0 & 0x01;
5042   size_16 = reg0 & 0x20;
5043   if (reg0 & 0x40)
5044      set_nt_mirroring(PPU_MIRROR_HORZ);
5045   else
5046      set_nt_mirroring(PPU_MIRROR_VERT);
8484   set_nt_mirroring((mmc_cmd1 & 0x40) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
50478485
5048   bank = ((reg0 & 0x1e) >> 1) | ((reg1 & 0x01) << 4);
8486   hi_bank = mmc_cmd1 & 0x01;
8487   size_16 = mmc_cmd1 & 0x20;
8488   bank = ((mmc_cmd1 & 0x1e) >> 1) | ((mmc_cmd1 & 0x80) >> 3) | ((mmc_cmd2 & 0x01) << 5);
50498489
50508490   if (size_16)
50518491   {
r5926r5927
50608500      prg32(space->machine, bank);
50618501}
50628502
8503/*************************************************************
8504
8505    Mapper 227
8506
8507    Known Boards: Unknown Bootleg Multigame Board
8508    Games: 1200 in 1, 295 in 1, 76 in 1
8509
8510    In MESS: Supported.
8511
8512*************************************************************/
8513
50638514static WRITE8_HANDLER( mapper227_w )
50648515{
50658516   int hi_bank;
r5926r5927
50868537   if (!(offset & 0x80))
50878538   {
50888539      if (offset & 0x200)
5089         prg16_cdef(space->machine, (bank >> 2) + 7);
8540         prg16_cdef(space->machine, ((bank << 1) & 0x38) + 7);
50908541      else
5091         prg16_cdef(space->machine, bank >> 2);
8542         prg16_cdef(space->machine, ((bank << 1) & 0x38));
50928543   }
50938544
5094   if (offset & 0x02)
5095      set_nt_mirroring(PPU_MIRROR_HORZ);
5096   else
5097      set_nt_mirroring(PPU_MIRROR_VERT);
8545   set_nt_mirroring((offset & 0x02) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
50988546}
50998547
8548/*************************************************************
8549
8550    Mapper 228
8551
8552    Known Boards: Bootleg Board by Active Enterprise
8553    Games: Action 52, Cheetah Men II
8554
8555    In MESS: Only Partially Supported.
8556
8557*************************************************************/
8558
51008559static WRITE8_HANDLER( mapper228_w )
51018560{
51028561   /* The address lines double as data */
r5926r5927
51508609   chr8(space->machine, chr, CHRROM);
51518610}
51528611
8612/*************************************************************
8613
8614    Mapper 229
8615
8616    Known Boards: Unknown Bootleg Multigame Board
8617    Games: 31 in 1
8618
8619    In MESS: Supported.
8620
8621*************************************************************/
8622
51538623static WRITE8_HANDLER( mapper229_w )
51548624{
51558625   LOG_MMC(("mapper229_w, offset: %04x, data: %02x\n", offset, data));
51568626
5157   if (offset & 0x20)
5158      set_nt_mirroring(PPU_MIRROR_HORZ);
5159   else
5160      set_nt_mirroring(PPU_MIRROR_VERT);
8627   set_nt_mirroring((offset & 0x20) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
8628   chr8(space->machine, offset, CHRROM);
51618629
51628630   if ((offset & 0x1e) == 0)
51638631   {
5164      prg32(space->machine, 0);
5165      chr8(space->machine, 0, CHRROM);
8632      prg16_89ab(space->machine, 0);
8633      prg16_89ab(space->machine, 1);
51668634   }
51678635   else
51688636   {
51698637      prg16_89ab(space->machine, offset & 0x1f);
51708638      prg16_89ab(space->machine, offset & 0x1f);
5171      chr8(space->machine, offset, CHRROM);
51728639   }
51738640}
51748641
8642/*************************************************************
8643
8644    Mapper 230
8645
8646    Known Boards: Unknown Bootleg Multigame Board
8647    Games: 22 in 1
8648
8649    In MESS: Supported. Needs a reset to work (not possible yet)
8650
8651*************************************************************/
8652
51758653static WRITE8_HANDLER( mapper230_w )
51768654{
51778655   LOG_MMC(("mapper230_w, offset: %04x, data: %02x\n", offset, data));
51788656
5179   if (1)
8657   if (1)   // this should flip at reset
51808658   {
5181      prg16_89ab(space->machine, 7);
8659      prg16_89ab(space->machine, data & 0x07);
51828660   }
51838661   else
51848662   {
r5926r5927
51898667      }
51908668      else
51918669      {
5192         prg32(space->machine, ((data & 0x1e) >> 1) + 4);
8670         prg16_89ab(space->machine, (data & 0x1f) + 8);
8671         prg16_cdef(space->machine, (data & 0x1f) + 9);
51938672      }
5194      set_nt_mirroring((data & 0x40) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
8673      set_nt_mirroring((data & 0x40) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
51958674   }
51968675}
51978676
8677/*************************************************************
8678
8679    Mapper 231
8680
8681    Known Boards: Unknown Bootleg Multigame Board
8682    Games: 20 in 1
8683
8684    In MESS: Supported.
8685
8686*************************************************************/
8687
51988688static WRITE8_HANDLER( mapper231_w )
51998689{
5200   int bank;
5201
52028690   LOG_MMC(("mapper231_w, offset: %04x, data: %02x\n", offset, data));
52038691
5204   bank = (data & 0x03) | ((data & 0x80) >> 5);
5205   prg32(space->machine, bank);
5206   chr8(space->machine, (data & 0x70) >> 4, CHRROM);
8692   set_nt_mirroring((offset & 0x80) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
8693
8694   prg16_89ab(space->machine, (offset & 0x1e));
8695   prg16_cdef(space->machine, (offset & 0x1e) + (data & 0x20) ? 1 : 0);
52078696}
52088697
8698/*************************************************************
8699
8700    Mapper 232
8701
8702    Known Boards: Camerica BF9096 & ALGQV11 Boards
8703    Games: Quattro Adventure, Quattro Arcade, Quattro Sports
8704
8705    Writes to 0x8000-0x9fff set prg block to (data&0x18)>>1,
8706    writes to 0xa000-0xbfff set prg page to data&3. selected
8707    prg are: prg16_89ab = block|page, prg_cdef = 3|page.
8708    For more info on the hardware to bypass the NES lockout, see
8709    Kevtris' Camerica Mappers documentation.
8710
8711    In MESS: Supported.
8712
8713*************************************************************/
8714
52098715static void mapper232_set_prg( running_machine *machine )
52108716{
5211   prg16_89ab(machine, (MMC1_bank2 & 0x03) | ((MMC1_bank1 & 0x18) >> 1));
5212   prg16_cdef(machine, 0x03 | ((MMC1_bank1 & 0x18) >> 1));
8717   prg16_89ab(machine, (mmc_cmd2 & 0x03) | ((mmc_cmd1 & 0x18) >> 1));
8718   prg16_cdef(machine, 0x03 | ((mmc_cmd1 & 0x18) >> 1));
52138719}
52148720
52158721static WRITE8_HANDLER( mapper232_w )
r5926r5927
52178723   LOG_MMC(("mapper232_w, offset: %04x, data: %02x\n", offset, data));
52188724
52198725   if (offset < 0x2000)
5220      MMC1_bank1 = data;
8726      mmc_cmd1 = data;
52218727   else
5222      MMC1_bank2 = data;
8728      mmc_cmd2 = data;
8729
8730   mapper232_set_prg(space->machine);
52238731}
52248732
8733/*************************************************************
8734
8735    Mapper 233
8736
8737    Known Boards: Unknown Bootleg Multigame Board
8738    Games: Super 22 in 1
8739
8740    In MESS: Unsupported. Banking depends on dipswitch, so we
8741      need to implement these...
8742
8743*************************************************************/
8744
8745/*************************************************************
8746
8747    Mapper 234
8748
8749    Known Boards: Bootleg Board by AVE (D1012)
8750    Games: Maxi 15 Eur
8751
8752    In MESS: Unsupported. Needs to read from 0xff80-0xffff.
8753
8754*************************************************************/
8755
8756/*************************************************************
8757
8758    Mapper 235
8759
8760    Known Boards: Unknown Bootleg Board by Golden Game
8761    Games: 260 in 1, 150 in 1
8762
8763    In MESS: Unsupported.
8764
8765*************************************************************/
8766
8767/*************************************************************
8768
8769    Mapper 236
8770
8771    Known Boards: Unknown Bootleg Multigame Board
8772    Games: a 800 in 1 multigame cart present in NEStopia db.
8773
8774    No info available.
8775
8776    In MESS: Unsupported.
8777
8778*************************************************************/
8779
8780/*************************************************************
8781
8782    Mapper 237
8783
8784    Known Boards: Undocumented / Unused ?!?
8785    Games: ----------
8786
8787    In MESS: ----------
8788
8789*************************************************************/
8790
8791/*************************************************************
8792
8793    Mapper 238
8794
8795    Known Boards: Unknown Bootleg Board, 6035052
8796    Games: Contra Fighter
8797
8798    MMC3 simple clone.
8799
8800    In MESS: Unsupported. Needs to read from 0x6000-0x7fff (for
8801          protection). It also needs to read in 0x4020-0x40ff.
8802
8803*************************************************************/
8804
8805/*************************************************************
8806
8807    Mapper 239
8808
8809    Known Boards: Undocumented / Unused ?!?
8810    Games: ----------
8811
8812    In MESS: ----------
8813
8814*************************************************************/
8815
8816/*************************************************************
8817
8818    Mapper 240
8819
8820    Known Boards: Bootleg Board by C&E
8821    Games: Jing Ke Xin Zhuan, Sheng Huo Lie Zhuan
8822
8823    Simple Mapper: writes to 0x4020-0x5fff sets prg32 to
8824         data>>4 and chr8 to data&f. We currently do not map
8825         writes to 0x4020-0x40ff (to do: verify if this produces
8826         issues)
8827
8828    In MESS: Supported.
8829
8830*************************************************************/
8831
52258832static WRITE8_HANDLER( mapper240_l_w )
52268833{
52278834   LOG_MMC(("mapper240_l_w, offset: %04x, data: %02x\n", offset, data));
r5926r5927
52308837   chr8(space->machine, data & 0x0f, CHRROM);
52318838}
52328839
8840/*************************************************************
8841
8842    Mapper 241
8843
8844    Known Boards: Bootleg Board by TXC
8845    Games: Commandos, Journey to the West, Ma Bu Mi Zhen &
8846           Qu Wei Cheng Yu Wu, Si Lu Chuan Qi
8847
8848    Simple Mapper: writes to 0x8000-0xffff sets the prg32 bank.
8849    Not sure if returning 0x50 for reads in 0x4100-0x5000 is correct.
8850
8851    In MESS: Supported.
8852
8853*************************************************************/
8854
52338855static READ8_HANDLER( mapper241_l_r )
52348856{
52358857   return 0x50;
r5926r5927
52428864   prg32(space->machine, data);
52438865}
52448866
8867/*************************************************************
8868
8869    Mapper 242
8870
8871    Known Boards: Bootleg Board by Waixing
8872    Games: Wai Xing Zhan Shi, Dragon Quest VIII
8873
8874    Simple mapper: writes to 0x8000-0xffff sets prg32 banks to
8875        (offset>>3)&f. written data&3 sets the mirroring (with
8876        switched high/low compared to the standard one). However,
8877        a second variant DQ7 and requires no NT mirroring.
8878        Currently, we do not support this variant.
8879
8880    In MESS: Partial Support.
8881
8882*************************************************************/
8883
52458884static WRITE8_HANDLER( mapper242_w )
52468885{
52478886   LOG_MMC(("mapper242_w, offset: %04x, data: %02x\n", offset, data));
52488887
52498888   prg32(space->machine, (offset >> 3) & 0x0f);
52508889
5251   switch (data & 0x03)
8890   waixing_set_mirror(data & 0x03);
8891}
8892
8893/*************************************************************
8894
8895    Mapper 243
8896
8897    Known Boards: Bootleg Board by Sachen (74SL374A)
8898    Games: Poker III
8899
8900    Conflicting info about this. Still investigating. The board is similar
8901    to the one of mapper 150.
8902
8903    In MESS: Supported.
8904
8905*************************************************************/
8906
8907static WRITE8_HANDLER( mapper243_l_w )
8908{
8909   LOG_MMC(("mapper243_l_w, offset: %04x, data: %02x\n", offset, data));
8910
8911   /* write happens only if we are at 0x4100 + k * 0x200,
8912   but 0x4100 is offset = 0 */
8913   if (!(offset & 0x100))
52528914   {
5253   case 0:
5254      set_nt_mirroring(PPU_MIRROR_VERT);
5255      break;
5256   case 1:
5257      set_nt_mirroring(PPU_MIRROR_HORZ);
5258      break;
5259   case 2:
5260      set_nt_mirroring(PPU_MIRROR_LOW);
5261      break;
5262   case 3:
5263      set_nt_mirroring(PPU_MIRROR_HIGH);
5264      break;
8915      if (!(offset & 0x01))
8916         mmc_cmd1 = data;
8917      else
8918      {
8919         switch (mmc_cmd1 & 0x07)
8920         {
8921         case 0x00:
8922            prg32(space->machine, 0);
8923            chr8(space->machine, 3, CHRROM);
8924            break;
8925         case 0x02:
8926            chr8(space->machine, (mmc_bank_latch1 & ~0x08) | (data << 3 & 0x08), CHRROM);   // Nestopia
8927            break;
8928         case 0x04:
8929            chr8(space->machine, (mmc_bank_latch1 & ~0x01) | (data << 0 & 0x01), CHRROM);   // Nestopia
8930            break;
8931         case 0x05:
8932            prg32(space->machine, data & 0x01);
8933            break;
8934         case 0x06:
8935            chr8(space->machine, (mmc_bank_latch1 & ~0x06) | (data << 1 & 0x06), CHRROM);   // Nestopia
8936            break;
8937         case 0x07:
8938            set_nt_mirroring(data & 0x01 ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
8939            break;
8940         default:
8941            break;
8942         }
8943      }
52658944   }
52668945}
52678946
8947/*************************************************************
8948
8949    Mapper 244
8950
8951    Known Boards: Unknown Bootleg Board by C&E
8952    Games: Decathlon
8953
8954    Pretty simple mapper: writes to 0x8065-0x80a4 set prg32 to
8955    data & 3; writes to 0x80a5-0x80e4 set chr8 to data & 7
8956
8957    In MESS: Supported.
8958
8959*************************************************************/
8960
52688961static WRITE8_HANDLER( mapper244_w )
52698962{
52708963   LOG_MMC(("mapper244_w, offset: %04x, data: %02x\n", offset, data));
r5926r5927
52828975   }
52838976}
52848977
8978/*************************************************************
8979
8980    Mapper 245
8981
8982    Known Boards: Type H by Waixing
8983    Games: Ying Xiong Yuan Yi Jing Chuan Qi
8984
8985    MMC3 clone. More info to come.
8986
8987    In MESS: Unsupported.
8988
8989*************************************************************/
8990
8991/*************************************************************
8992
8993    Mapper 246
8994
8995    Known Boards: Unknown Bootleg Board by C&E
8996    Games: Fong Shen Bang - Zhu Lu Zhi Zhan
8997
8998    Simple mapper: writes to 0x6000-0x67ff set PRG and CHR banks.
8999    Namely, 0x6000->0x6003 select resp. prg8_89, prg8_ab, prg8_cd
9000    and prg8_ef. 0x6004->0x6007 select resp. crh2_0, chr2_2,
9001    chr2_4 and chr2_6. In 0x6800-0x7fff lies WRAM.
9002
9003    In MESS: Supported.
9004
9005*************************************************************/
9006
52859007static WRITE8_HANDLER( mapper246_m_w )
52869008{
5287   LOG_MMC(("mapper256_m_w, offset: %04x, data: %02x\n", offset, data));
9009   LOG_MMC(("mapper246_m_w, offset: %04x, data: %02x\n", offset, data));
52889010
52899011   if (offset < 0x0800)
52909012   {
r5926r5927
53209042      nes.wram[offset] = data;
53219043}
53229044
5323static void mapper248_set_prg( running_machine *machine )
5324{
5325   if (MMC1_bank4 & 0x80)
5326   {
5327      prg16_89ab(machine, MMC1_bank4 & 0x0f);
5328   }
5329   else
5330   {
5331      prg8_89(machine, MMC1_bank2 & 0x1f);
5332      prg8_ab(machine, MMC1_bank3 & 0x1f);
5333   }
5334}
9045/*************************************************************
53359046
5336static WRITE8_HANDLER( mapper248_m_w )
5337{
5338   LOG_MMC(("mapper248_m_w, offset: %04x, data: %02x\n", offset, data));
9047    Mapper 247
53399048
5340   MMC1_bank4 = data;
5341   mapper248_set_prg(space->machine);
5342}
9049    Known Boards: Undocumented / Unused ?!?
9050    Games: ----------
53439051
5344static WRITE8_HANDLER( mapper248_w )
9052    In MESS: ----------
9053
9054*************************************************************/
9055
9056/*************************************************************
9057
9058    Mapper 248
9059
9060    Known Boards: Undocumented / Unused ?!?
9061    Games: ----------
9062
9063    In MESS: ----------
9064
9065*************************************************************/
9066
9067/*************************************************************
9068
9069    Mapper 249
9070
9071    Known Boards: Waixing Security 0 & 1
9072    Games: Duo Bao Xiao Ying Hao - Guang Ming yu An Hei Chuan Shuo,
9073           Myth Struggle, San Shi Liu Ji, Shui Hu Zhuan
9074
9075    MMC3 clone
9076
9077    In MESS: Unsupported.
9078
9079*************************************************************/
9080
9081/*************************************************************
9082
9083    Mapper 250
9084
9085    Known Boards: Unknown Bootleg Board by Nitra
9086    Games: Time Diver Avenger
9087
9088    This acts basically like a MMC3 with different use of write
9089    address. According to NEStopia, there is also a slightly
9090    different way to set NT mirroring (see below).
9091
9092    In MESS: Supported.
9093
9094*************************************************************/
9095
9096static WRITE8_HANDLER( mapper250_w )
53459097{
5346   LOG_MMC(("mapper248_w, offset: %04x, data: %02x\n", offset, data));
9098   LOG_MMC(("mapper250_w, offset: %04x, data: %02x\n", offset, data));
53479099
5348   switch (offset & 0x7001)
9100   switch (offset & 0x6001)
53499101   {
5350   case 0x0000:
5351      MMC1_bank1 = data;
5352      break;
5353   case 0x0001:
5354      switch (MMC1_bank1 & 0x07)
5355      {
5356      case 0:
5357         chr2_0(space->machine, data >> 1, CHRROM);
5358         break;
5359      case 1:
5360         chr2_2(space->machine, data >> 1, CHRROM);
5361         break;
5362      case 2:
5363         chr1_4(space->machine, data, CHRROM);
5364         break;
5365      case 3:
5366         chr1_5(space->machine, data, CHRROM);
5367         break;
5368      case 4:
5369         chr1_6(space->machine, data, CHRROM);
5370         break;
5371      case 5:
5372         chr1_7(space->machine, data, CHRROM);
5373         break;
5374      case 6:
5375         MMC1_bank2 = data;
5376         mapper248_set_prg(space->machine);
5377         break;
5378      case 7:
5379         MMC1_bank3 = data;
5380         mapper248_set_prg(space->machine);
5381         break;
5382      }
5383      break;
53849102   case 0x2000:
5385      set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9103      set_nt_mirroring(data & 0x01 ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);   // diff with MMC3: not check for data & 0x40
53869104      break;
5387   case 0x4000:
5388      IRQ_count_latch = data;
9105   default:
9106      mapper4_w(space, (offset & 0x6000) | ((offset & 0x400) >> 10), offset & 0xff);
53899107      break;
5390   case 0x4001:
5391      IRQ_count = IRQ_count_latch;
5392      break;
5393   case 0x6000:
5394      IRQ_enable = 0;
5395      break;
5396   case 0x6001:
5397      IRQ_enable = 1;
5398      break;
53999108   }
54009109}
54019110
5402static void mapper248_irq( const device_config *device, int scanline, int vblank, int blanked )
9111/*************************************************************
9112
9113    Mapper 251
9114
9115    Known Boards: Undocumented
9116    Games: Super 8-in-1 99 King Fighter
9117
9118    In MESS: Unsupported.
9119
9120*************************************************************/
9121
9122/*************************************************************
9123
9124    Mapper 252
9125
9126    Known Boards: Unknown Bootleg Board by Waixing
9127    Games: San Guo Zhi
9128
9129    In MESS: Unsupported.
9130
9131*************************************************************/
9132
9133/*************************************************************
9134
9135    Mapper 253
9136
9137    Known Boards: Undocumented
9138    Games: Shen Hua Jian Yun III ?
9139
9140    In MESS: Unsupported.
9141
9142*************************************************************/
9143
9144/*************************************************************
9145
9146    Mapper 254
9147
9148    Known Boards: Unknown Bootleg Board
9149    Games: Pikachu Y2K
9150
9151    MMC3 simple clone.
9152
9153    In MESS: Unsupported. Needs to read from 0x6000-0x7fff (for
9154          protection).
9155
9156*************************************************************/
9157
9158/*************************************************************
9159
9160    Mapper 255
9161
9162    Known Boards: Unknown Bootleg Board
9163    Games: 110 in 1
9164
9165    In MESS: Unsupported.
9166
9167*************************************************************/
9168
9169static WRITE8_HANDLER( mapper255_w )
54039170{
5404   if ((scanline < PPU_BOTTOM_VISIBLE_SCANLINE) /*|| (scanline == ppu_scanlines_per_frame-1)*/)
9171   UINT8 map255_helper1 = (offset >> 12) ? 0 : 1;
9172   UINT8 map255_helper2 = ((offset >> 8) & 0x40) | ((offset >> 6) & 0x3f);
9173
9174   LOG_MMC(("mapper255_w, offset: %04x, data: %02x\n", offset, data));
9175
9176   set_nt_mirroring((offset & 0x2000) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9177   prg16_89ab(space->machine, map255_helper1 & ~map255_helper2);
9178   prg16_cdef(space->machine, map255_helper1 | map255_helper2);
9179   chr8(space->machine, ((offset >> 8) & 0x40) | (offset & 0x3f), CHRROM);
9180}
9181
9182
9183
9184/*************************************************************
9185
9186    mmc_list
9187
9188    Supported mappers and corresponding handlers
9189
9190*************************************************************/
9191
9192static const mmc mmc_list[] =
9193{
9194/*  INES   DESC                     LOW_W, LOW_R, MED_W, HIGH_W, PPU_latch, scanline CB, hblank CB */
9195   {  0, "No Mapper",            NULL, NULL, NULL, NULL, NULL, NULL, NULL },
9196   {  1, "MMC1",                 NULL, NULL, NULL, mapper1_w, NULL, NULL, NULL },
9197   {  2, "74161/32 ROM sw",      NULL, NULL, NULL, mapper2_w, NULL, NULL, NULL },
9198   {  3, "74161/32 VROM sw",     NULL, NULL, NULL, mapper3_w, NULL, NULL, NULL },
9199   {  4, "MMC3",                 NULL, NULL, NULL, mapper4_w, NULL, NULL, mapper4_irq },
9200   {  5, "MMC5",                 mapper5_l_w, mapper5_l_r, NULL, mapper5_w, NULL, NULL, mapper5_irq },
9201   {  7, "ROM Switch",           NULL, NULL, NULL, mapper7_w, NULL, NULL, NULL },
9202   {  8, "FFE F3xxxx",           NULL, NULL, NULL, mapper8_w, NULL, NULL, NULL },
9203   {  9, "MMC2",                 NULL, NULL, NULL, mapper9_w, mapper9_latch, NULL, NULL},
9204   { 10, "MMC4",                 NULL, NULL, NULL, mapper10_w, mapper9_latch, NULL, NULL },
9205   { 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
9207   { 15, "100-in-1",             NULL, NULL, NULL, mapper15_w, NULL, NULL, NULL },
9208   { 16, "Bandai",               NULL, NULL, mapper16_m_w, mapper16_w, NULL,NULL,  bandai_irq },
9209   { 17, "FFE F8xxx",            mapper17_l_w, NULL, NULL, NULL, NULL, NULL, mapper4_irq },
9210   { 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 },
9212   { 20, "Famicom Disk System",  NULL, NULL, NULL, NULL, NULL, NULL, fds_irq },
9213   { 21, "Konami VRC 4",         NULL, NULL, NULL, konami_vrc4_w, NULL, NULL, konami_irq },
9214   { 22, "Konami VRC 2a",        NULL, NULL, NULL, konami_vrc2a_w, NULL, NULL, NULL },
9215   { 23, "Konami VRC 2b",        NULL, NULL, NULL, konami_vrc2b_w, NULL, NULL, konami_irq },
9216   { 24, "Konami VRC 6a",        NULL, NULL, NULL, konami_vrc6a_w, NULL, NULL, konami_irq },
9217   { 25, "Konami VRC 4",         NULL, NULL, NULL, konami_vrc4_w, NULL, NULL, konami_irq },
9218   { 26, "Konami VRC 6b",        NULL, NULL, NULL, konami_vrc6b_w, NULL, NULL, konami_irq },
9219   { 32, "Irem G-101",           NULL, NULL, NULL, mapper32_w, NULL, NULL, NULL },
9220   { 33, "Taito TC0190",         NULL, NULL, NULL, mapper33_w, NULL, NULL, NULL },
9221   { 34, "Nina-1",               NULL, NULL, mapper34_m_w, mapper34_w, NULL, NULL, NULL },
9222   { 36, "TXC Policeman",        NULL, NULL, NULL, mapper36_w, NULL, NULL, NULL },
9223   { 38, "Crime Buster",         NULL, NULL, mapper38_m_w, NULL, NULL, NULL, NULL },
9224   { 39, "Subor Study n Game",   NULL, NULL, NULL, mapper39_w, NULL, NULL, NULL },
9225   { 40, "SMB2j (bootleg)",      NULL, NULL, NULL, mapper40_w, NULL, NULL, mapper40_irq },
9226   { 41, "Caltron 6-in-1",       NULL, NULL, mapper41_m_w, mapper41_w, NULL, NULL, NULL },
9227   { 42, "Mario Baby",           NULL, NULL, NULL, mapper42_w, NULL, NULL, NULL },
9228   { 43, "150-in-1",             NULL, NULL, NULL, mapper43_w, NULL, NULL, NULL },
9229   { 44, "7-in-1 MMC3",          NULL, NULL, NULL, mapper44_w, NULL, NULL, mapper4_irq },
9230   { 45, "X-in-1 MMC3",          NULL, NULL, mapper45_m_w, mapper4_w, NULL, NULL, mapper4_irq },
9231   { 46, "15-in-1 Color Dreams", NULL, NULL, mapper46_m_w, mapper46_w, NULL, NULL, NULL },
9232   { 47, "2-in-1 MMC3",          NULL, NULL, mapper47_m_w, mapper4_w, NULL, NULL, mapper4_irq },
9233   { 49, "4-in-1 MMC3",          NULL, NULL, mapper49_m_w, mapper4_w, NULL, NULL, mapper4_irq },
9234   { 51, "11-in-1",              NULL, NULL, mapper51_m_w, mapper51_w, NULL, NULL, NULL },
9235   { 57, "6-in-1",               NULL, NULL, NULL, mapper57_w, NULL, NULL, NULL },
9236   { 58, "X-in-1",               NULL, NULL, NULL, mapper58_w, NULL, NULL, NULL },
9237   { 61, "20-in-1",              NULL, NULL, NULL, mapper61_w, NULL, NULL, NULL },
9238   { 62, "X-in-1",               NULL, NULL, NULL, mapper62_w, NULL, NULL, NULL },
9239   { 64, "Tengen",               NULL, NULL, mapper64_m_w, mapper64_w, NULL, NULL, mapper4_irq },
9240   { 65, "Irem H3001",           NULL, NULL, NULL, mapper65_w, NULL, NULL, irem_irq },
9241   { 66, "74161/32 Jaleco",      NULL, NULL, NULL, mapper66_w, NULL, NULL, NULL },
9242   { 67, "SunSoft 3",            NULL, NULL, NULL, mapper67_w, NULL, NULL, mapper4_irq },
9243   { 68, "SunSoft 4",            NULL, NULL, NULL, mapper68_w, NULL, NULL, NULL },
9244   { 69, "SunSoft 5",            NULL, NULL, NULL, mapper69_w, NULL, NULL, sunsoft_irq },
9245   { 70, "74161/32 Bandai",      NULL, NULL, NULL, mapper70_w, NULL, NULL, NULL },
9246   { 71, "Camerica",             NULL, NULL, mapper71_m_w, mapper71_w, NULL, NULL, NULL },
9247   { 72, "74161/32 Jaleco",      NULL, NULL, NULL, mapper72_w, NULL, NULL, NULL },
9248   { 73, "Konami VRC 3",         NULL, NULL, NULL, mapper73_w, NULL, NULL, konami_irq },
9249   { 74, "Waixing Type A",       NULL, NULL, NULL, mapper74_w, NULL, NULL, mapper4_irq },
9250   { 75, "Konami VRC 1",         NULL, NULL, NULL, mapper75_w, NULL, NULL, NULL },
9251   { 76, "Namco 109",            NULL, NULL, NULL, mapper76_w, NULL, NULL, NULL },
9252   { 77, "74161/32 ?",           NULL, NULL, NULL, mapper77_w, NULL, NULL, NULL },
9253   { 78, "74161/32 Irem",        NULL, NULL, NULL, mapper78_w, NULL, NULL, NULL },
9254   { 79, "Nina-3 (AVE)",         mapper79_l_w, NULL, NULL, NULL, NULL, NULL, NULL },
9255   { 80, "Taito X1-005 Ver. A",  NULL, NULL, mapper80_m_w, NULL, NULL, NULL, NULL },
9256   { 82, "Taito C075",           NULL, NULL, mapper82_m_w, NULL, NULL, NULL, NULL },
9257   { 83, "Cony",                 mapper83_l_w, mapper83_l_r, NULL, mapper83_w, NULL, NULL, NULL },
9258   { 84, "Pasofami",             NULL, NULL, NULL, NULL, NULL, NULL, NULL },
9259   { 85, "Konami VRC 7",         NULL, NULL, NULL, konami_vrc7_w, NULL, NULL, konami_irq },
9260   { 86, "Jaleco Early Mapper 2",NULL, NULL, mapper86_m_w, NULL, NULL, NULL, NULL },
9261   { 87, "74161/32 VROM sw-a",   NULL, NULL, mapper87_m_w, NULL, NULL, NULL, NULL },
9262   { 88, "Namco 118",            NULL, NULL, NULL, mapper88_w, NULL, NULL, NULL },
9263   { 89, "Sunsoft Early",        NULL, NULL, NULL, mapper89_w, NULL, NULL, NULL },
9264// 90 - pirate mapper
9265   { 91, "HK-SF3 (bootleg)",     NULL, NULL, mapper91_m_w, NULL, NULL, NULL, NULL },
9266   { 92, "Jaleco Early Mapper 1",NULL, NULL, NULL, mapper92_w, NULL, NULL, NULL },
9267   { 93, "Sunsoft LS161",        NULL, NULL, NULL, mapper93_w, NULL, NULL, NULL },
9268   { 94, "Capcom LS161",         NULL, NULL, NULL, mapper94_w, NULL, NULL, NULL },
9269   { 95, "Namco ??",             NULL, NULL, NULL, mapper95_w, NULL, NULL, NULL },
9270   { 96, "74161/32",             NULL, NULL, NULL, mapper96_w, NULL, NULL, NULL },
9271   { 97, "Irem - PRG HI",        NULL, NULL, NULL, mapper97_w, NULL, NULL, NULL },
9272// 99 - vs. system
9273// 100 - images hacked to work with nesticle
9274   { 101, "?? LS161",            NULL, NULL, mapper101_m_w, mapper101_w, NULL, NULL, NULL },
9275   { 104, "Golden Five",         NULL, NULL, NULL, mapper104_w, NULL, NULL, NULL },
9276   { 107, "Magic Dragon",        NULL, NULL, NULL, mapper107_w, NULL, NULL, NULL },
9277   { 112, "Asper",               NULL, NULL, NULL, mapper112_w, NULL, NULL, NULL },
9278   { 113, "Sachen/Hacker/Nina",  mapper113_l_w, NULL, NULL, NULL, NULL, NULL, NULL },
9279   { 115, "Bao Qing Tian",       NULL, NULL, mapper115_m_w, mapper115_w, NULL, NULL, mapper115_irq },
9280   { 118, "MMC3?",               NULL, NULL, NULL, mapper118_w, NULL, NULL, mapper4_irq },
9281   { 119, "MMC3 - Pinbot",       NULL, NULL, NULL, mapper119_w, NULL, NULL, mapper4_irq },
9282   { 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 },
9284   { 136, "Sachen TCU01",        mapper136_l_w, mapper136_l_r, NULL, NULL, NULL, NULL, NULL },
9285   { 137, "Sachen 8259D",        mapper137_l_w, NULL, mapper137_m_w, NULL, NULL, NULL, NULL },
9286   { 138, "Sachen 8259B",        mapper138_l_w, NULL, mapper138_m_w, NULL, NULL, NULL, NULL },
9287   { 139, "Sachen 8259C",        mapper139_l_w, NULL, mapper139_m_w, NULL, NULL, NULL, NULL },
9288   { 140, "Jaleco",              NULL, NULL, mapper_140_m_w, NULL, NULL, NULL, NULL },
9289   { 141, "Sachen 8259A",        mapper141_l_w, NULL, mapper141_m_w, NULL, NULL, NULL, NULL },
9290   { 143, "Sachen TCA01",        NULL, mapper143_l_r, NULL, NULL, NULL, NULL, NULL },
9291   { 144, "AGCI 50282",          NULL, NULL, NULL, mapper144_w, NULL, NULL, NULL }, //Death Race only
9292   { 145, "Sachen SA72007",      mapper145_l_w, NULL, NULL, NULL, NULL, NULL, NULL },
9293   { 146, "Sachen SA0161M",      mapper79_l_w, NULL, NULL, NULL, NULL, NULL, NULL }, // basically same as Mapper 79 (Nina006)
9294   { 147, "Sachen TCU02",        mapper147_l_w, NULL, mapper147_m_w, mapper147_w, NULL, NULL, NULL },
9295   { 148, "Sachen SA0037",       NULL, NULL, NULL, mapper148_w, NULL, NULL, NULL },
9296   { 149, "Sachen SA0036",       NULL, NULL, NULL, mapper149_w, NULL, NULL, NULL },
9297   { 150, "Sachen 74LS374B",     mapper150_l_w, mapper150_l_r, mapper150_m_w, NULL, NULL, NULL, NULL },
9298   { 152, "Taito Discrete",      NULL, NULL, NULL, mapper152_w, NULL, NULL, NULL },
9299   { 154, "Devil Man",           NULL, NULL, NULL, mapper154_w, NULL, NULL, NULL },
9300   { 156, "Open Corp. DAOU36",   NULL, NULL, NULL, mapper156_w, NULL, NULL, NULL },
9301   { 164, "Final Fantasy V",     mapper164_l_w, NULL, NULL, mapper164_w, NULL, NULL, NULL },
9302   { 166, "Subor Board Type 1",  NULL, NULL, NULL, mapper166_w, NULL, NULL, NULL },
9303   { 167, "Subor Board Type 2",  NULL, NULL, NULL, mapper167_w, NULL, NULL, NULL },
9304   { 171, "Kaiser KS7058",       NULL, NULL, NULL, mapper171_w, NULL, NULL, NULL },
9305   { 172, "TXC T22211B",         mapper132_l_w, mapper132_l_r, NULL, mapper172_w, NULL, NULL, NULL },
9306   { 173, "TXC T22211C",         mapper132_l_w, mapper173_l_r, NULL, mapper132_w, NULL, NULL, NULL },
9307   { 176, "Zhi Li Xiao Zhuan Yuan",mapper176_l_w, NULL, NULL, NULL, NULL, NULL, NULL },
9308   { 177, "Henggedianzi Board",  NULL, NULL, NULL, mapper177_w, NULL, NULL, NULL },
9309   { 178, "San Guo Zhong Lie Zhuan",mapper178_l_w, NULL, NULL, NULL, NULL, NULL, NULL },
9310   { 179, "Xing He Zhan Shi",    mapper179_l_w, NULL, NULL, mapper179_w, NULL, NULL, NULL },
9311   { 180, "Nihon Bussan - PRG HI",NULL, NULL, NULL, mapper180_w, NULL, NULL, NULL },
9312   { 182, "Super games",         NULL, NULL, NULL, mapper182_w, NULL, NULL, mapper182_irq },
9313   { 184, "Sunsoft VROM/4K",     NULL, NULL, mapper184_m_w, NULL, NULL, NULL, NULL },
9314   { 188, "UNROM reversed",      NULL, NULL, NULL, mapper188_w, NULL, NULL, NULL },
9315   { 193, "Fighting Hero",       NULL, NULL, mapper193_m_w, NULL, NULL, NULL, NULL },
9316   { 196, "Super Mario Bros. 11",NULL, NULL, NULL, mapper196_w, NULL, NULL, mapper4_irq },
9317   { 200, "X-in-1",              NULL, NULL, NULL, mapper200_w, NULL, NULL, NULL },
9318   { 201, "X-in-1",              NULL, NULL, NULL, mapper201_w, NULL, NULL, NULL },
9319   { 202, "150-in-1",            NULL, NULL, NULL, mapper202_w, NULL, NULL, NULL },
9320   { 203, "35-in-1",             NULL, NULL, NULL, mapper203_w, NULL, NULL, NULL },
9321   { 204, "64-in-1",             NULL, NULL, NULL, mapper204_w, NULL, NULL, NULL },
9322   { 206, "MIMIC-1",             NULL, NULL, NULL, mapper206_w, NULL, NULL, mapper4_irq },
9323   { 207, "Taito X1-005 Ver. B", NULL, NULL, mapper207_m_w, NULL, NULL, NULL, NULL },
9324   { 212, "Super HIK 300-in-1",  NULL, NULL, NULL, mapper212_w, NULL, NULL, NULL },
9325   { 213, "9999999-in-1",        NULL, NULL, NULL, mapper213_w, NULL, NULL, NULL },
9326   { 214, "Super Gun 20-in-1",   NULL, NULL, NULL, mapper214_w, NULL, NULL, NULL },
9327   { 216, "RCM GS2015",          NULL, NULL, NULL, mapper216_w, NULL, NULL, NULL },
9328   { 221, "X-in-1 (N625092)",    NULL, NULL, NULL, mapper221_w, NULL, NULL, NULL },
9329   { 225, "72-in-1 bootleg",     NULL, NULL, NULL, mapper225_w, NULL, NULL, NULL },
9330   { 226, "76-in-1 bootleg",     NULL, NULL, NULL, mapper226_w, NULL, NULL, NULL },
9331   { 227, "1200-in-1 bootleg",   NULL, NULL, NULL, mapper227_w, NULL, NULL, NULL },
9332   { 228, "Action 52",           NULL, NULL, NULL, mapper228_w, NULL, NULL, NULL },
9333   { 229, "31-in-1",             NULL, NULL, NULL, mapper229_w, NULL, NULL, NULL },
9334   { 230, "22-in-1",             NULL, NULL, NULL, mapper230_w, NULL, NULL, NULL },
9335   { 231, "Nina-7 (AVE)",        NULL, NULL, NULL, mapper231_w, NULL, NULL, NULL },
9336   { 232, "Quattro",             NULL, NULL, mapper232_w, mapper232_w, NULL, NULL, NULL },
9337// 234 - maxi-15
9338   { 240, "Jing Ke Xin Zhuan",   mapper240_l_w, NULL, NULL, NULL, NULL, NULL, NULL },
9339   { 241, "Education 18-in-1",   NULL, mapper241_l_r, NULL, mapper241_w, NULL, NULL, NULL },
9340   { 242, "Wai Xing Zhan Shi",   NULL, NULL, NULL, mapper242_w, NULL, NULL, NULL },
9341   { 243, "Sachen 74LS374A",     mapper243_l_w, NULL, NULL, NULL, NULL, NULL, NULL },
9342   { 244, "Decathlon",           NULL, NULL, NULL, mapper244_w, NULL, NULL, NULL },
9343   { 246, "Fong Shen Bang",      NULL, NULL, mapper246_m_w, NULL, NULL, NULL, NULL },
9344   { 250, "Time Diver Avenger",  NULL, NULL, NULL, mapper250_w, NULL, NULL, mapper4_irq },
9345   { 255, "X-in-1",              NULL, NULL, NULL, mapper255_w, NULL, NULL, NULL },
9346};
9347
9348
9349const mmc *nes_mapper_lookup( int mapper )
9350{
9351   int i;
9352   for (i = 0; i < sizeof(mmc_list) / sizeof(mmc_list[0]); i++)
54059353   {
5406      int priorCount = IRQ_count;
5407      if ((IRQ_count == 0) || IRQ_reload)
5408      {
5409         IRQ_count = IRQ_count_latch;
5410         IRQ_reload = 0;
5411      }
5412      else
5413         IRQ_count --;
5414
5415      if (IRQ_enable && !blanked && (IRQ_count == 0) && priorCount)
5416      {
5417         logerror("irq fired, scanline: %d (MAME %d, beam pos: %d)\n", scanline, video_screen_get_vpos(device->machine->primary_screen), video_screen_get_hpos(device->machine->primary_screen));
5418         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
5419      }
9354      if (mmc_list[i].iNesMapper == nes.mapper)
9355         return &mmc_list[i];
54209356   }
9357   return NULL;
54219358}
54229359
5423/*
5424// mapper_reset
5425//
5426// Resets the mapper bankswitch areas to their defaults. It returns a value "err"
5427// that indicates if it was successful. Possible values for err are:
5428//
5429// 0 = success
5430// 1 = no mapper found
5431// 2 = mapper not supported
5432*/
5433int mapper_reset( running_machine *machine, int mapperNum )
9360/*************************************************************
9361
9362    mapper_reset
9363
9364    Resets the mapper bankswitch areas to their defaults.
9365    It returns a value "err" that indicates if it was
9366    successful. Possible values for err are:
9367
9368    0 = success
9369    1 = no mapper found
9370    2 = mapper not supported
9371
9372*************************************************************/
9373
9374int mapper_reset( running_machine *machine, int mmc_num )
54349375{
54359376   const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
54369377   nes_state *state = machine->driver_data;
54379378   int err = 0;
54389379   const mmc *mapper;
54399380
5440   if(nes.chr_chunks==0)
9381   if (nes.chr_chunks == 0)
54419382      chr8(machine, 0,CHRRAM);
5442   else chr8(machine, 0,CHRROM);
9383   else
9384      chr8(machine, 0,CHRROM);
54439385
54449386   /* Set the mapper irq callback */
5445   mapper = nes_mapper_lookup(mapperNum);
9387   mapper = nes_mapper_lookup(mmc_num);
54469388
5447   if(mapper == NULL)
9389   if (mapper == NULL)
54489390      fatalerror("Unimplemented Mapper");
54499391
54509392   ppu2c0x_set_scanline_callback(state->ppu, mapper ? mapper->mmc_scanline : NULL);
r5926r5927
54609402   MMC5_vram_control = 0;
54619403
54629404   /* Point the WRAM/battery area to the first RAM bank */
5463   if (mapperNum != 20 && mapperNum != 40)
9405   if (mmc_num != 20 && mmc_num != 40)
54649406      memory_set_bankptr(space->machine, 5, &nes.wram[0x0000]);
54659407
5466   switch (mapperNum)
9408   switch (mmc_num)
54679409   {
54689410      case 0:
54699411         err = 1; /* No mapper found */
r5926r5927
55189460         prg32(space->machine, 0);
55199461         break;
55209462      case 4:
9463      case 74:
55219464      case 206:
55229465         /* Only MMC3 and clones seem to use 4-screen! */
55239466
r5926r5927
55319474            set_nt_page(2, CART_NTRAM, 2, 1);
55329475            set_nt_page(3, CART_NTRAM, 3, 1);
55339476         }
5534
55359477      case 118:
55369478      case 119:
9479      case 196:
9480      case 250:
55379481         /* Can switch 8k prg banks */
55389482         IRQ_enable = 0;
55399483         IRQ_count = IRQ_count_latch = 0;
r5926r5927
55459489         MMC3_prg_mask = (nes.prg_chunks << 1) - 1;
55469490         MMC3_chr_base = 0;
55479491         MMC3_chr_mask = (nes.chr_chunks << 3) - 1;
5548         MMC3_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
9492         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
55499493         mapper4_set_prg(space->machine);
5550         mapper4_set_chr(space->machine, MMC3_chr_source);
9494         mapper4_set_chr(space->machine, mmc_chr_source);
55519495         break;
55529496      case 5:
55539497         /* Can switch 8k prg banks, but they are saved as 16k in size */
r5926r5927
55929536         prg16_89ab(space->machine, 0);
55939537         prg16_cdef(space->machine, nes.prg_chunks - 1);
55949538         break;
5595      case 11:
5596         /* Switches 32k banks, 1st 32k bank loaded on reset (?) May be more like mapper 7... */
9539      case 11:   /* Switches 32k banks, 1st 32k bank loaded on reset (?) May be more like mapper 7... */
55979540         prg32(space->machine, 0);
55989541         break;
5599      case 15:
5600         /* Can switch 8k prg banks */
9542      case 15:   /* Can switch 8k prg banks */
9543         set_nt_mirroring(PPU_MIRROR_VERT);
56019544         prg32(space->machine, 0);
56029545         break;
56039546      case 16:
r5926r5927
56249567         /* fall through */
56259568      case 22:
56269569      case 23:
5627      case 32:
56289570      case 33:
56299571         prg16_89ab(space->machine, 0);
56309572         prg16_cdef(space->machine, nes.prg_chunks - 1);
56319573         break;
9574      case 32:
9575         mmc_cmd1 = 0;
9576         prg16_89ab(space->machine, 0);
9577         prg16_cdef(space->machine, nes.prg_chunks - 1);
9578//         set_nt_mirroring(PPU_MIRROR_HIGH);   // this would be needed for Major League
9579         break;
56329580      case 24:
56339581      case 26:
56349582      case 73:
r5926r5927
56469594         IRQ_enable = 0;
56479595         IRQ_count = 0;
56489596         /* Who's your daddy? */
5649         memcpy(&nes.rom[0x6000], &nes.rom[6 * 0x2000 + 0x10000], 0x2000);
5650         prg8_89(space->machine, 4);
5651         prg8_ab(space->machine, 5);
5652         prg8_cd(space->machine, 6);
5653         prg8_ef(space->machine, 7);
9597         memcpy(&nes.rom[0x6000], &nes.rom[((nes.prg_chunks << 1) - 2) * 0x2000 + 0x10000], 0x2000);
9598         //ugly hack to deal with iNES header usage of chunk count.
9599         prg8_89(space->machine, (nes.prg_chunks << 1) - 4);
9600         prg8_ab(space->machine, (nes.prg_chunks << 1) - 3);
9601         prg8_cd(space->machine, 0);
9602         prg8_ef(space->machine, (nes.prg_chunks << 1) - 1);
56549603         break;
5655      case 64:
5656         /* Can switch 3 8k prg banks */
5657         prg16_89ab(space->machine, nes.prg_chunks - 1);
5658         prg16_cdef(space->machine, nes.prg_chunks - 1);
5659         break;
5660      case 65:
5661         IRQ_enable = 0;
5662         IRQ_count = 0;
5663         prg16_89ab(space->machine, 0);
5664         prg16_cdef(space->machine, nes.prg_chunks - 1);
5665         break;
56669604      case 41:
5667      case 66:
5668         /* Can switch 32k prgm banks */
9605         mmc_cmd1 = 0;
56699606         prg32(space->machine, 0);
56709607         break;
56719608      case 42:
5672         /* Switch in the last 32KB */
5673         prg32(space->machine, 0xff);
9609         prg32(space->machine, nes.prg_chunks - 1);
56749610         break;
56759611      case 43:
56769612         prg32(space->machine, 0);
r5926r5927
56899625         MMC3_prg_mask = 0x0f;
56909626         MMC3_chr_base = 0;
56919627         MMC3_chr_mask = 0x7f;
5692         MMC3_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
9628         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
56939629         mapper4_set_prg(space->machine);
5694         mapper4_set_chr(space->machine, MMC3_chr_source);
9630         mapper4_set_chr(space->machine, mmc_chr_source);
56959631         break;
56969632      case 45:
56979633         IRQ_enable = 0;
r5926r5927
57049640         MMC3_prg_mask = 0x0f;
57059641         MMC3_chr_base = 0;
57069642         MMC3_chr_mask = 0x7f;
5707         MMC3_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
9643         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
57089644         mapper45_cmd = 0;
57099645         mapper45_data[0] = mapper45_data[1] = mapper45_data[2] = mapper45_data[3] = 0;
57109646         mapper4_set_prg(space->machine);
5711         mapper4_set_chr(space->machine, MMC3_chr_source);
9647         mapper4_set_chr(space->machine, mmc_chr_source);
57129648         memory_set_bankptr(space->machine, 5, nes.wram);
57139649         break;
57149650      case 46:
5715         /* Reuseing some MMC1 variables here */
5716         MMC1_bank1 = 0;
5717         MMC1_bank2 = 0;
5718         prg32(space->machine, MMC1_bank1);
5719         chr8(space->machine, MMC1_bank2, CHRROM);
9651         mmc_bank_latch1 = 0;
9652         mmc_bank_latch2 = 0;
9653         prg32(space->machine, 0);
9654         chr8(space->machine, 0, CHRROM);
57209655         break;
57219656      case 51:
57229657         MMC1_bank1 = 0x01;
r5926r5927
57379672         break;
57389673      case 61:
57399674      case 62:
9675      case 86:
57409676         prg32(space->machine, 0);
57419677         break;
5742      case 70:
5743//      case 86:
5744         prg16_89ab(space->machine, nes.prg_chunks - 2);
9678      case 64:
9679         /* Can switch 3 8k prg banks */
9680         prg16_89ab(space->machine, nes.prg_chunks - 1);
57459681         prg16_cdef(space->machine, nes.prg_chunks - 1);
57469682         break;
9683      case 65:
9684         IRQ_enable = 0;
9685         IRQ_count = 0;
9686         prg16_89ab(space->machine, 0);
9687         prg16_cdef(space->machine, nes.prg_chunks - 1);
9688         break;
57479689      case 67:
57489690      case 68:
57499691      case 69:
57509692      case 71:
57519693      case 72:
5752      case 77:
57539694      case 78:
57549695      case 92:
57559696         IRQ_enable = IRQ_enable_latch = 0;
r5926r5927
57579698         prg16_89ab(space->machine, 0);
57589699         prg16_cdef(space->machine, nes.prg_chunks - 1);
57599700         break;
9701      case 70:
9702         prg16_89ab(space->machine, nes.prg_chunks - 2);
9703         prg16_cdef(space->machine, nes.prg_chunks - 1);
9704         break;
57609705      case 76:
57619706         prg8_89(space->machine, 0);
57629707         prg8_ab(space->machine, 1);
r5926r5927
57669711         chr2_2(space->machine, 1, CHRROM);
57679712         chr2_4(space->machine, 2, CHRROM);
57689713         chr2_6(space->machine, 3, CHRROM);
9714         mmc_cmd1 = 0;
57699715         break;
9716      case 77:
9717         prg32(space->machine, 0);
9718         chr2_2(space->machine, 0, CHRROM);
9719         chr2_4(space->machine, 1, CHRROM);
9720         chr2_6(space->machine, 2, CHRROM);
9721         break;
57709722      case 79:
9723      case 146:
57719724         /* Mirroring always horizontal...? */
57729725//          Mirroring = 1;
9726         set_nt_mirroring(PPU_MIRROR_HORZ);
9727         chr8(space->machine, 0, CHRROM);
57739728         prg32(space->machine, 0);
57749729         break;
57759730      case 80:
9731      case 207:
57769732      case 82:
57779733      case 85:
5778      case 86:
5779      case 207:
9734         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
57809735         prg16_89ab(space->machine, 0);
57819736         prg16_cdef(space->machine, nes.prg_chunks - 1);
57829737         break;
r5926r5927
58029757         prg16_cdef(space->machine, nes.prg_chunks - 1);
58039758         set_nt_mirroring(PPU_MIRROR_LOW);
58049759         break;
5805
58069760      case 91:
58079761         set_nt_mirroring(PPU_MIRROR_VERT);
58089762         prg16_89ab(space->machine, nes.prg_chunks - 1);
r5926r5927
58209774         prg16_cdef(space->machine, nes.prg_chunks - 1);
58219775         break;
58229776      case 112:
5823         prg16_89ab(space->machine, nes.prg_chunks - 1);
9777         mmc_cmd1 = 0;
9778         prg16_89ab(space->machine, 0);
58249779         prg16_cdef(space->machine, nes.prg_chunks - 1);
58259780         break;
9781      case 36:
9782      case 38:
9783      case 39:
9784      case 66:
58269785      case 107:
58279786      case 113:
5828      case 133:
5829         prg32(space->machine, 0);
5830         break;
9787      case 177:
9788      case 179:
58319789      case 184:
58329790      case 140:
58339791      case 144:
9792      case 240:
9793      case 241:
9794      case 242:
9795      case 244:
58349796         prg32(space->machine, 0);
58359797         break;
9798      case 104:
9799         mmc_bank_latch1 = 0;
9800         prg16_89ab(space->machine, 0x00);
9801         prg16_cdef(space->machine, 0x0f);
9802         break;
9803      case 132:
9804      case 172:
9805      case 173:
9806         txc_reg[0] = txc_reg[1] = txc_reg[2] = txc_reg[3] = 0;
9807         prg32(space->machine, 0);
9808         break;
9809      case 166:
9810         subor_reg[0] = subor_reg[1] = subor_reg[2] = subor_reg[3] = 0;
9811         prg16_89ab(space->machine, 0);
9812         prg16_cdef(space->machine, 0x07);
9813         break;
9814      case 167:
9815         subor_reg[0] = subor_reg[1] = subor_reg[2] = subor_reg[3] = 0;
9816         prg16_89ab(space->machine, 0);
9817         prg16_cdef(space->machine, 0x20);
9818         break;
9819      case 136:
9820         mmc_cmd1 = 0;
9821         prg32(space->machine, 0);
9822         break;
9823      case 137:
9824         mmc_cmd1 = 0;
9825         prg32(space->machine, 0);
9826         chr8(space->machine, nes.chr_chunks - 1, CHRROM);
9827         set_nt_mirroring(PPU_MIRROR_VERT);
9828         break;
9829      case 138:
9830      case 139:
9831      case 141:
9832         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
9833         mmc_cmd1 = 0;
9834         prg32(space->machine, 0);
9835         chr8(space->machine, 0, mmc_chr_source);
9836         set_nt_mirroring(PPU_MIRROR_VERT);
9837         break;
9838      case 143:
9839         prg16_89ab(space->machine, 0);
9840         prg16_cdef(space->machine, 1);
9841         chr8(space->machine, 0, CHRROM);
9842         break;
9843      case 133:
9844      case 145:
9845      case 147:
9846      case 148:
9847      case 149:
9848      case 171:
9849         prg32(space->machine, 0);
9850         chr8(space->machine, 0, CHRROM);
9851         break;
9852      case 150:
9853         mmc_bank_latch1 = 0;
9854         mmc_cmd1 = 0;
9855         prg32(space->machine, 0);
9856         chr8(space->machine, 0, CHRROM);
9857         set_nt_mirroring(PPU_MIRROR_VERT);
9858         break;
9859      case 152:
9860         prg16_89ab(space->machine, 0);
9861         prg16_cdef(space->machine, nes.prg_chunks - 1);
9862         chr8(space->machine, 0, CHRROM);
9863         break;
58369864      case 154:
58379865         prg16_89ab(space->machine, nes.prg_chunks - 2);
58389866         prg16_cdef(space->machine, nes.prg_chunks - 1);
58399867         break;
9868      case 156:
9869         prg16_89ab(space->machine, nes.prg_chunks - 2);
9870         prg16_cdef(space->machine, nes.prg_chunks - 1);
9871         set_nt_mirroring(PPU_MIRROR_LOW);
9872         break;
58409873      case 164:
5841         prg32(space->machine, 0xFF);
9874         prg32(space->machine, 0xff);
58429875         nes.mid_ram_enable = 1;
58439876         break;
9877      case 176:
9878         prg32(space->machine, (nes.prg_chunks - 1) >> 1);
9879         break;
9880      case 178:
9881         mmc_cmd1 = 0;
9882         prg32(space->machine, 0);
9883         break;
58449884      case 180:
58459885         prg16_89ab(space->machine, 0);
58469886         prg16_cdef(space->machine, 0);
r5926r5927
58639903         prg16_cdef(space->machine, nes.prg_chunks - 1);
58649904         break;
58659905      case 201:
9906      case 213:
58669907         prg32(space->machine, 0);
58679908         chr8(space->machine, 0, CHRROM);
58689909         break;
58699910      case 202:
58709911      case 203:
9912      case 204:
9913      case 214:
58719914         prg16_89ab(space->machine, 0);
58729915         prg16_cdef(space->machine, 0);
58739916         chr8(space->machine, 0, CHRROM);
58749917         break;
9918      case 212:
9919         chr8(space->machine, 0xff, CHRROM);
9920         prg32(space->machine, 0xff);
9921         break;
9922      case 216:
9923         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
9924         prg32(space->machine, 0);
9925         chr8(space->machine, 0, mmc_chr_source);
9926         break;
9927      case 221:
9928         mmc_cmd1 = 0;
9929         mmc_cmd2 = 0;
9930         prg16_89ab(space->machine, 0);
9931         prg16_cdef(space->machine, 0);
9932         break;
58759933      case 225:
9934         prg32(space->machine, 0);
9935         break;
58769936      case 226:
9937         mmc_cmd1 = 0;
9938         mmc_cmd2 = 0;
9939         prg32(space->machine, 0);
9940         break;
58779941      case 227:
5878      case 229:
58799942         prg16_89ab(space->machine, 0);
58809943         prg16_cdef(space->machine, 0);
58819944         break;
9945      case 229:
9946      case 255:
9947         prg16_89ab(space->machine, 0);
9948         prg16_cdef(space->machine, 1);
9949         chr8(space->machine, 0, CHRROM);
9950         set_nt_mirroring(PPU_MIRROR_VERT);
9951         break;
58829952      case 230:
58839953         prg16_89ab(space->machine, 0);
58849954         prg16_cdef(space->machine, 7);
58859955         break;
58869956      case 231:
5887         prg16_89ab(space->machine, nes.prg_chunks - 2);
5888         prg16_cdef(space->machine, nes.prg_chunks - 1);
9957         prg16_89ab(space->machine, 0);
9958         prg16_cdef(space->machine, 0);
9959         set_nt_mirroring(PPU_MIRROR_VERT);
58899960         break;
58909961      case 232:
5891         MMC1_bank1 = 0x18;
5892         MMC1_bank2 = 0x00;
9962         mmc_cmd1 = 0x18;
9963         mmc_cmd2 = 0x00;
58939964         mapper232_set_prg(space->machine);
58949965         break;
5895      case 240:
5896      case 241:
5897      case 242:
5898      case 244:
9966      case 243:
9967         mmc_bank_latch1 = 3;
9968         mmc_cmd1 = 0;
9969         chr8(space->machine, 3, CHRROM);
58999970         prg32(space->machine, 0);
9971         set_nt_mirroring(PPU_MIRROR_VERT);
59009972         break;
59019973      case 246:
59029974         prg32(space->machine, 0xff);
r5926r5927
59139985   return err;
59149986}
59159987
9988/* VERY preliminary UNIF code - to be split afterwords! */
59169989
9990/*************************************************************
59179991
5918static const mmc mmc_list[] =
5919{
5920/*  INES   DESC                     LOW_W, LOW_R, MED_W, HIGH_W, PPU_latch, scanline CB, hblank CB */
5921   { 0, "No Mapper",            NULL, NULL, NULL, NULL, NULL, NULL, NULL },
5922   { 1, "MMC1",               NULL, NULL, NULL, mapper1_w, NULL, NULL, NULL },
5923   { 2, "74161/32 ROM sw",         NULL, NULL, NULL, mapper2_w, NULL, NULL, NULL },
5924   { 3, "74161/32 VROM sw",      NULL, NULL, NULL, mapper3_w, NULL, NULL, NULL },
5925   { 4, "MMC3",               NULL, NULL, NULL, mapper4_w, NULL, NULL, mapper4_irq },
5926   { 5, "MMC5",               mapper5_l_w, mapper5_l_r, NULL, mapper5_w, NULL, NULL, mapper5_irq },
5927   { 7, "ROM Switch",            NULL, NULL, NULL, mapper7_w, NULL, NULL, NULL },
5928   { 8, "FFE F3xxxx",            NULL, NULL, NULL, mapper8_w, NULL, NULL, NULL },
5929   { 9, "MMC2",               NULL, NULL, NULL, mapper9_w, mapper9_latch, NULL, NULL},
5930   { 10, "MMC4",               NULL, NULL, NULL, mapper10_w, mapper10_latch, NULL, NULL },
5931   { 11, "Color Dreams Mapper",   NULL, NULL, NULL, mapper11_w, NULL, NULL, NULL },
5932   { 13, "CP-ROM",               NULL, NULL,   NULL, mapper13_w, NULL, NULL, NULL }, //needs CHR-RAM hooked up
5933   { 15, "100-in-1",            NULL, NULL, NULL, mapper15_w, NULL, NULL, NULL },
5934   { 16, "Bandai",               NULL, NULL, mapper16_w, mapper16_w, NULL,NULL,  bandai_irq },
5935   { 17, "FFE F8xxx",            mapper17_l_w, NULL, NULL, NULL, NULL, NULL, mapper4_irq },
5936   { 18, "Jaleco",               NULL, NULL, NULL, mapper18_w, NULL, NULL, jaleco_irq },
5937   { 19, "Namco 106",            mapper19_l_w, NULL, NULL, mapper19_w, NULL, NULL, namcot_irq },
5938   { 20, "Famicom Disk System",   NULL, NULL, NULL, NULL, NULL, NULL, fds_irq },
5939   { 21, "Konami VRC 4",         NULL, NULL, NULL, konami_vrc4_w, NULL, NULL, konami_irq },
5940   { 22, "Konami VRC 2a",         NULL, NULL, NULL, konami_vrc2a_w, NULL, NULL, konami_irq },
5941   { 23, "Konami VRC 2b",         NULL, NULL, NULL, konami_vrc2b_w, NULL, NULL, konami_irq },
5942   { 24, "Konami VRC 6a",         NULL, NULL, NULL, konami_vrc6a_w, NULL, NULL, konami_irq },
5943   { 25, "Konami VRC 4",         NULL, NULL, NULL, konami_vrc4_w, NULL, NULL, konami_irq },
5944   { 26, "Konami VRC 6b",         NULL, NULL, NULL, konami_vrc6b_w, NULL, NULL, konami_irq },
5945   { 32, "Irem G-101",            NULL, NULL, NULL, mapper32_w, NULL, NULL, NULL },
5946   { 33, "Taito TC0190",         NULL, NULL, NULL, mapper33_w, NULL, NULL, NULL },
5947   { 34, "Nina-1",               NULL, NULL, mapper34_m_w, mapper34_w, NULL, NULL, NULL },
5948   { 40, "SMB2j (bootleg)",      NULL, NULL, NULL, mapper40_w, NULL, NULL, mapper40_irq },
5949   { 41, "Caltron 6-in-1",         NULL, NULL, mapper41_m_w, mapper41_w, NULL, NULL, NULL },
5950   { 42, "Mario Baby",            NULL, NULL, NULL, mapper42_w, NULL, NULL, NULL },
5951   { 43, "150-in-1",            NULL, NULL, NULL, mapper43_w, NULL, NULL, NULL },
5952   { 44, "7-in-1 MMC3",         NULL, NULL, NULL, mapper44_w, NULL, NULL, mapper4_irq },
5953   { 45, "X-in-1 MMC3",         NULL, NULL, mapper45_m_w, mapper4_w, NULL, NULL, mapper4_irq },
5954   { 46, "15-in-1 Color Dreams",   NULL, NULL, mapper46_m_w, mapper46_w, NULL, NULL, NULL },
5955   { 47, "2-in-1 MMC3",         NULL, NULL, mapper47_m_w, mapper4_w, NULL, NULL, mapper4_irq },
5956   { 49, "4-in-1 MMC3",         NULL, NULL, mapper49_m_w, mapper4_w, NULL, NULL, mapper4_irq },
5957   { 51, "11-in-1",            NULL, NULL, mapper51_m_w, mapper51_w, NULL, NULL, NULL },
5958   { 57, "6-in-1",               NULL, NULL, NULL, mapper57_w, NULL, NULL, NULL },
5959   { 58, "X-in-1",               NULL, NULL, NULL, mapper58_w, NULL, NULL, NULL },
5960   { 61, "20-in-1",            NULL, NULL, NULL, mapper61_w, NULL, NULL, NULL },
5961   { 62, "X-in-1",               NULL, NULL, NULL, mapper62_w, NULL, NULL, NULL },
5962   { 64, "Tengen",               NULL, NULL, mapper64_m_w, mapper64_w, NULL, NULL, mapper4_irq },
5963   { 65, "Irem H3001",            NULL, NULL, NULL, mapper65_w, NULL, NULL, irem_irq },
5964   { 66, "74161/32 Jaleco",      NULL, NULL, NULL, mapper66_w, NULL, NULL, NULL },
5965   { 67, "SunSoft 3",            NULL, NULL, NULL, mapper67_w, NULL, NULL, mapper4_irq },
5966   { 68, "SunSoft 4",            NULL, NULL, NULL, mapper68_w, NULL, NULL, NULL },
5967   { 69, "SunSoft 5",            NULL, NULL, NULL, mapper69_w, NULL, NULL, sunsoft_irq },
5968   { 70, "74161/32 Bandai",      NULL, NULL, NULL, mapper70_w, NULL, NULL, NULL },
5969   { 71, "Camerica",            NULL, NULL, mapper71_m_w, mapper71_w, NULL, NULL, NULL },
5970   { 72, "74161/32 Jaleco",      NULL, NULL, NULL, mapper72_w, NULL, NULL, NULL },
5971   { 73, "Konami VRC 3",         NULL, NULL, NULL, mapper73_w, NULL, NULL, konami_irq },
5972   { 75, "Konami VRC 1",         NULL, NULL, NULL, mapper75_w, NULL, NULL, NULL },
5973   { 76, "Namco 109",            NULL, NULL, NULL, mapper76_w, NULL, NULL, NULL },
5974   { 77, "74161/32 ?",            NULL, NULL, NULL, mapper77_w, NULL, NULL, NULL },
5975   { 78, "74161/32 Irem",         NULL, NULL, NULL, mapper78_w, NULL, NULL, NULL },
5976   { 79, "Nina-3 (AVE)",         mapper79_l_w, NULL, mapper79_w, mapper79_w, NULL, NULL, NULL },
5977   { 80, "Taito X1-005",         NULL, NULL, mapper80_m_w, NULL, NULL, NULL, NULL },
5978   { 82, "Taito C075",            NULL, NULL, mapper82_m_w, NULL, NULL, NULL, NULL },
5979   { 83, "Cony",               mapper83_l_w, mapper83_l_r, NULL, mapper83_w, NULL, NULL, NULL },
5980   { 84, "Pasofami",            NULL, NULL, NULL, NULL, NULL, NULL, NULL },
5981   { 85, "Konami VRC 7",         NULL, NULL, NULL, konami_vrc7_w, NULL, NULL, konami_irq },
5982   { 86, "Jaleco Early Mapper 2",   NULL, NULL, NULL, mapper86_w, NULL, NULL, NULL },
5983   { 87, "74161/32 VROM sw-a",      NULL, NULL, mapper87_m_w, NULL, NULL, NULL, NULL },
5984   { 88, "Namco 118",            NULL, NULL, NULL, mapper88_w, NULL, NULL, NULL },
5985   { 89, "Sunsoft Early",         NULL, NULL, NULL, mapper89_w, NULL, NULL, NULL },
5986// 90 - pirate mapper
5987   { 91, "HK-SF3 (bootleg)",      NULL, NULL, mapper91_m_w, NULL, NULL, NULL, NULL },
5988   { 92, "Jaleco Early Mapper 1",   NULL, NULL, NULL, mapper92_w, NULL, NULL, NULL },
5989   { 93, "Sunsoft LS161",         NULL, NULL, mapper93_m_w, mapper93_w, NULL, NULL, NULL },
5990   { 94, "Capcom LS161",         NULL, NULL, NULL, mapper94_w, NULL, NULL, NULL },
5991   { 95, "Namco ??",            NULL, NULL, NULL, mapper95_w, NULL, NULL, NULL },
5992   { 96, "74161/32",            NULL, NULL, NULL, mapper96_w, NULL, NULL, NULL },
5993   { 97, "Irem - PRG HI",         NULL, NULL, NULL, mapper97_w, NULL, NULL, NULL },
5994// 99 - vs. system
5995// 100 - images hacked to work with nesticle
5996   { 101, "?? LS161",            NULL, NULL, mapper101_m_w, mapper101_w, NULL, NULL, NULL },
5997   { 107, "Magic Dragon",         NULL, NULL, NULL, mapper107_w, NULL, NULL, NULL },
5998   { 112, "Asper",               NULL, NULL, NULL, mapper112_w, NULL, NULL, NULL },
5999   { 113, "Sachen/Hacker/Nina",   mapper113_l_w, NULL, NULL, NULL, NULL, NULL, NULL },
6000   { 118, "MMC3?",               NULL, NULL, NULL, mapper118_w, NULL, NULL, mapper4_irq },
6001   { 119, "MMC3 - Pinbot",               NULL, NULL, NULL, mapper119_w, NULL, NULL, mapper4_irq },
6002   { 133, "Sachen",            mapper133_l_w, NULL, NULL, NULL, NULL, NULL, NULL },
6003   { 140, "Jaleco",                        NULL, NULL, mapper_140_m_w, NULL, NULL, NULL, NULL },
6004   { 144, "AGCI 50282",         NULL, NULL, NULL, mapper144_w, NULL, NULL, NULL }, //Death Race only
6005   { 154, "Devil Man",            NULL, NULL, NULL, mapper154_w, NULL, NULL, NULL },
6006   { 164, "Final Fantasy V",            mapper164_l_w, NULL, NULL, mapper164_w, NULL, NULL, NULL },
6007   { 180, "Nihon Bussan - PRG HI",   NULL, NULL, NULL, mapper180_w, NULL, NULL, NULL },
6008   { 182, "Super games",         NULL, NULL, NULL, mapper182_w, NULL, NULL, mapper182_irq },
6009   { 184, "Sunsoft VROM/4K",      NULL, NULL, mapper184_m_w, NULL, NULL, NULL, NULL },
6010   { 188, "UNROM reversed",      NULL, NULL, NULL, mapper188_w, NULL, NULL, NULL },
6011   { 193, "Fighting Hero",         NULL, NULL, mapper193_m_w, NULL, NULL, NULL, NULL },
6012   { 200, "X-in-1",            NULL, NULL, NULL, mapper200_w, NULL, NULL, NULL },
6013   { 201, "X-in-1",            NULL, NULL, NULL, mapper201_w, NULL, NULL, NULL },
6014   { 202, "150-in-1",            NULL, NULL, NULL, mapper202_w, NULL, NULL, NULL },
6015   { 203, "35-in-1",            NULL, NULL, NULL, mapper203_w, NULL, NULL, NULL },
6016   { 206, "MIMIC-1",            NULL, NULL, NULL, mapper206_w, NULL, NULL, mapper4_irq },
6017   { 207, "Fudou Myouou Den",      NULL, NULL, mapper207_m_w, NULL, NULL, NULL, NULL },
6018   { 225, "72-in-1 bootleg",      NULL, NULL, NULL, mapper225_w, NULL, NULL, NULL },
6019   { 226, "76-in-1 bootleg",      NULL, NULL, NULL, mapper226_w, NULL, NULL, NULL },
6020   { 227, "1200-in-1 bootleg",      NULL, NULL, NULL, mapper227_w, NULL, NULL, NULL },
6021   { 228, "Action 52",            NULL, NULL, NULL, mapper228_w, NULL, NULL, NULL },
6022   { 229, "31-in-1",            NULL, NULL, NULL, mapper229_w, NULL, NULL, NULL },
6023   { 230, "22-in-1",            NULL, NULL, NULL, mapper230_w, NULL, NULL, NULL },
6024   { 231, "Nina-7 (AVE)",         NULL, NULL, NULL, mapper231_w, NULL, NULL, NULL },
6025   { 232, "Quattro",            NULL, NULL, mapper232_w, mapper232_w, NULL, NULL, NULL },
6026// 234 - maxi-15
6027   { 240, "Jing Ke Xin Zhuan",      mapper240_l_w, NULL, NULL, NULL, NULL, NULL, NULL },
6028   { 241, "Education 18-in-1",      NULL, mapper241_l_r, NULL, mapper241_w, NULL, NULL, NULL },
6029   { 242, "Wai Xing Zhan Shi",      NULL, NULL, NULL, mapper242_w, NULL, NULL, NULL },
6030   { 244, "Decathlon",            NULL, NULL, NULL, mapper244_w, NULL, NULL, NULL },
6031   { 246, "Fong Shen Bang",      NULL, NULL, mapper246_m_w, NULL, NULL, NULL, NULL },
6032   { 248, "Bao Qing Tian",         NULL, NULL, mapper248_m_w, mapper248_w, NULL, NULL, mapper248_irq },
6033};
9992    unif_list
60349993
9994    Supported UNIF boards and corresponding handlers
60359995
9996*************************************************************/
60369997
6037const mmc *nes_mapper_lookup(int mapper)
9998static const unif unif_list[] =
60389999{
10000/*       UNIF                       LOW_W, LOW_R, MED_W, HIGH_W, PPU_latch, scanline CB, hblank CB */
10001   { "UNL-Sachen-8259A",         mapper141_l_w, NULL, mapper141_m_w, NULL, NULL, NULL, NULL },
10002};
10003
10004const unif *nes_unif_lookup( const char *board )
10005{
603910006   int i;
6040   for (i = 0; i < sizeof(mmc_list) / sizeof(mmc_list[0]); i++)
10007   for (i = 0; i < sizeof(unif_list) / sizeof(unif_list[0]); i++)
604110008   {
6042      if (mmc_list[i].iNesMapper == nes.mapper)
6043         return &mmc_list[i];
10009      if (unif_list[i].board == board)
10010         return &unif_list[i];
604410011   }
604510012   return NULL;
604610013}
6047
src/mess/machine/nes_mmc.h
r5926r5927
1616
1717const mmc *nes_mapper_lookup(int mapper);
1818
19typedef struct __unif
20{
21   const char *board; /* UNIF board */
22   write8_space_func mmc_write_low; /* $4100-$5fff write routine */
23   read8_space_func mmc_read_low; /* $4100-$5fff read routine */
24   write8_space_func mmc_write_mid; /* $6000-$7fff write routine */
25   write8_space_func mmc_write; /* $8000-$ffff write routine */
26   void (*ppu_latch)(const device_config *device, offs_t offset);
27   ppu2c0x_scanline_cb      mmc_scanline;
28   ppu2c0x_hblank_cb      mmc_hblank;
29} unif;
30
31const unif *nes_unif_lookup(const char *board);
32
1933extern int MMC1_extended; /* 0 = normal MMC1 cart, 1 = 512k MMC1, 2 = 1024k MMC1 */
2034
2135#define MMC5_VRAM
src/mess/drivers/nes.c
r5926r5927
218218   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.90)
219219   
220220   MDRV_CARTSLOT_ADD("cart")
221   MDRV_CARTSLOT_EXTENSION_LIST("nes")
221   MDRV_CARTSLOT_EXTENSION_LIST("nes,unf")
222222   MDRV_CARTSLOT_MANDATORY
223223   MDRV_CARTSLOT_LOAD(nes_cart)
224224   MDRV_CARTSLOT_PARTIALHASH(nes_partialhash)
r5926r5927
270270   MDRV_IMPORT_FROM( nes )
271271   
272272   MDRV_CARTSLOT_MODIFY("cart")
273   MDRV_CARTSLOT_EXTENSION_LIST("nes")
273   MDRV_CARTSLOT_EXTENSION_LIST("nes,unf")
274274   MDRV_CARTSLOT_NOT_MANDATORY
275275   MDRV_CARTSLOT_LOAD(nes_cart)
276276   MDRV_CARTSLOT_PARTIALHASH(nes_partialhash)
r5926r5927
412412
413413***************************************************************************/
414414
415/* Since 0.130u4, most of the games do not show graphics correctly. Conversion of PPU to a device showed some of the
416limitations of the previous implementation. Systems regressed to GAME_NOT_WORKING status until a proper fix is found */
417
418415/*     YEAR  NAME      PARENT  COMPAT MACHINE   INPUT    INIT   CONFIG   COMPANY       FULLNAME */
419416CONS( 1985, nes,       0,      0,     nes,      nes,     0,     0,       "Nintendo",  "Nintendo Entertainment System / Famicom (NTSC)", GAME_IMPERFECT_GRAPHICS )
420417CONS( 1987, nespal,    nes,    0,     nespal,   nes,     0,     0,       "Nintendo",  "Nintendo Entertainment System (PAL)", GAME_IMPERFECT_GRAPHICS )

Previous 15994 Revisions Next


© 1998-2018 The MESS Team