Previous 15994 Revisions Next

r5998 Wednesday 7th October, 2009 at 15:26:21 UTC by Fabio Priuli
[NES] fixed lots of problems and added new mappers
[hash]nes.hsi
[src/mess/includes]nes.h
[src/mess/machine]nes.c nes_mmc.c nes_mmc.h

hash/nes.hsi
r5997r5998
1834918349   </hash>
1835018350   <hash crc32="30f9bb46" sha1="5d9d519b84e245891928f3482a42a071e4402b6c" name="Dragon Quest VIII (ES-1077) (Ch)">
1835118351      <status>GoodNES Verified Image</status>
18352      <extrainfo>242 2 32 0</extrainfo>
18352      <extrainfo>242 130 32 0</extrainfo>
1835318353
1835418354   </hash>
1835518355   <hash crc32="ac9895cc" sha1="bb1967b0947989ffd9fcf6b10b81ae036110491a" name="Dragon Scroll - Yomigaerishi Maryuu (J)">
r5997r5998
2037520375   </hash>
2037620376   <hash crc32="3f15d20d" sha1="1d7417d31e19b590afceb6a8a6e7b9cab9f9b475" name="Famicom Jump II - Saikyou no 7 Nin (J)">
2037720377      <status>GoodNES Verified Image</status>
20378      <extrainfo>153 2 32 0</extrainfo>
20378      <extrainfo>153 130 32 0</extrainfo>
2037920379
2038020380   </hash>
2038120381   <hash crc32="f76aa523" sha1="7348a4530054205925f3182aa5f12dd4d8a19410" name="Famicom Jump II - Saikyou no 7 Nin (J)">
r5997r5998
2715527155
2715627156   </hash>
2715727157   <hash crc32="5e36d3be" sha1="9bddfd1440e001b2f5b70657266a118fc6478c80" name="HES 6-in-1 (HES)">
27158      <extrainfo>113 0 16 16</extrainfo>
27158      <extrainfo>113 128 16 16</extrainfo>
2715927159
2716027160   </hash>
2716127161   <hash crc32="2930bb11" sha1="fcb775693f5bfe463100f62c648e98356a477156" name="Hi! Mario by Excel (SMB1 Hack)">
r5997r5998
2985929859   </hash>
2986029860   <hash crc32="92a3d007" sha1="68315afb344108cb0d43e119ba0353d5a44bd489" name="Impossible Mission II (U)">
2986129861      <status>GoodNES Verified Image</status>
29862      <extrainfo>34 1 4 8</extrainfo>
29862      <extrainfo>34 129 4 8</extrainfo>
2986329863
2986429864   </hash>
2986529865   <hash crc32="685705ac" sha1="1dde911681ce8461f19376e04c2581c3f3914ed4" name="Impossible Mission II (U)">
2986629866      <status>Known Bad Image</status>
29867      <extrainfo>34 1 4 8</extrainfo>
29867      <extrainfo>34 129 4 8</extrainfo>
2986829868
2986929869   </hash>
2987029870   <hash crc32="0ba9f385" sha1="2032bdda5ec067130584be6e7e8fb83d235a23f8" name="Impossible Mission II (U)">
2987129871      <status>Overdumped Image</status>
29872      <extrainfo>34 1 4 8</extrainfo>
29872      <extrainfo>34 129 4 8</extrainfo>
2987329873
2987429874   </hash>
2987529875   <hash crc32="c8228b54" sha1="6429ff0427ac2d614d553a356d48b66d06d1bddf" name="Incredible Crash Dummies, The (E)">
r5997r5998
3624936249
3625036250   </hash>
3625136251   <hash crc32="243a8735" sha1="7e4180432726a433c46ba2206d9e13b32761c11e" name="Major League (J)">
36252      <extrainfo>32 0 8 16</extrainfo>
36252      <extrainfo>32 128 8 16</extrainfo>
3625336253
3625436254   </hash>
3625536255   <hash crc32="a03a422b" sha1="a2eb5fb422a88a1f38a9e7236164f9f251d32c24" name="Major League Baseball (U) (PRG0)">
r5997r5998
5284752847
5284852848   </hash>
5284952849   <hash crc32="cd373baa" sha1="d94b55c600975751a0bf8333029aecd076de3e3a" name="Samurai Spirits (Rex Soft)">
52850      <extrainfo>116 0 16 64</extrainfo>
52850      <extrainfo>14 0 16 64</extrainfo>
5285152851
5285252852   </hash>
5285352853   <hash crc32="9ba5251c" sha1="078a4be73464ef248594be767a447f2cee9fbae2" name="Samus Super Metroid Look by Grond (Metroid Hack)">
r5997r5998
6936969369   </hash>
6937069370   <hash crc32="695cb142" sha1="9edb84ad6eac88bd220d4ac75a157d9e14af97c6" name="Uchuusen - Cosmo Carrier (J)">
6937169371      <status>Known Bad Image</status>
69372      <extrainfo>78 8 8 16</extrainfo>
69372      <extrainfo>78 136 8 16</extrainfo>
6937369373
6937469374   </hash>
6937569375   <hash crc32="fc7371a2" sha1="62238ccecc24ca41f131aa8b3e0669b5df06721a" name="Uchuusen - Cosmo Carrier (J) [hFFE][T+Eng0.25_Gil Galad]">
r5997r5998
6938169381
6938269382   </hash>
6938369383   <hash crc32="3d1c3137" sha1="23d302b901c2b6c1e969bab7b2a45c392c06fb5b" name="Uchuusen - Cosmo Carrier (J)">
69384      <extrainfo>78 8 8 16</extrainfo>
69384      <extrainfo>78 136 8 16</extrainfo>
6938569385
6938669386   </hash>
6938769387   <hash crc32="8b57ad40" sha1="01707d94f3f00ca887a6abdc42191bde94ba1f68" name="Udx Vs Donkey Kong (Donkey Kong PRG1 Hack)">
r5997r5998
7286972869   </hash>
7287072870   <hash crc32="260d32e0" sha1="2d03f3105af3149cc070f7a72b868660cd905304" name="Yong Zhe Dou E Long - Dragon Quest VII (Ch)">
7287172871      <status>Known Bad Image</status>
72872      <extrainfo>4 2 64 0</extrainfo>
72872      <extrainfo>245 2 64 0</extrainfo>
7287372873
7287472874   </hash>
7287572875   <hash crc32="345ee51a" sha1="9c801071d1aac7b280468c38bf1b61fde99b5fd0" name="Yong Zhe Dou E Long - Dragon Quest VII (Ch)">
72876      <extrainfo>4 2 64 0</extrainfo>
72876      <extrainfo>245 2 64 0</extrainfo>
7287772877
7287872878   </hash>
7287972879   <hash crc32="e7ead93b" sha1="4e48695ed4ef4db19fbb3806d25397c371a479cd" name="Yoshi (U)">
src/mess/includes/nes.h
r5997r5998
1414    CONSTANTS
1515***************************************************************************/
1616
17#define NTSC_CLOCK      N2A03_DEFAULTCLOCK   /* 1.789772 MHz */
18#define PAL_CLOCK      (26601712.0/16)      /* 1.662607 MHz */
17#define NTSC_CLOCK           N2A03_DEFAULTCLOCK     /* 1.789772 MHz */
18#define PAL_CLOCK              (26601712.0/16)        /* 1.662607 MHz */
1919
2020
2121/***************************************************************************
r5997r5998
4646   UINT8 prg_chunks;
4747   UINT8 chr_chunks;
4848
49   UINT8 format;   // 1 = iNES, 2 = UNIF
50
4951   /* system variables which don't change at run-time */
50   UINT16 mapper;
52   UINT16 mapper;      // for iNES
53   const char *board;   // for UNIF
5154   UINT8 four_screen_vram;
5255   UINT8 hard_mirroring;
5356   UINT8 slow_banking;
57   UINT8 crc_hack;   // this is needed to detect different boards sharing the same Mappers (shame on .nes format)
5458
5559   UINT8 *rom;
5660   UINT8 *vrom;
src/mess/machine/nes.c
r5997r5998
7575   nes.wram = memory_region(machine, "user1");
7676
7777   /* Brutal hack put in as a consequence of the new memory system; we really
78     * need to fix the NES code */
78      need to fix the NES code */
7979   memory_install_read8_handler(space, 0x0000, 0x07ff, 0, 0x1800, SMH_BANK(10));
8080   memory_install_write8_handler(space, 0x0000, 0x07ff, 0, 0x1800, SMH_BANK(10));
8181
r5997r5998
8787   nes_battery_ram = nes.wram;
8888
8989   /* Set up the memory handlers for the mapper */
90   //if (nes.format == 1)
9091   switch (nes.mapper)
9192   {
9293      case 20:
r5997r5998
106107         memory_set_bankptr(machine, 1, &nes.rom[0xe000]);
107108         memory_set_bankptr(machine, 2, nes_fds.data );
108109         break;
109      case 40:
110         nes.slow_banking = 1;
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);
119
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 */
125         memory_install_write8_handler(space, 0x6000, 0x7fff, 0, 0, nes_mid_mapper_w);
126         memory_install_write8_handler(space, 0x8000, 0xffff, 0, 0, nes_mapper_w);
127         break;
110      case 50:
111         memory_install_write8_handler(space, 0x4020, 0x403f, 0, 0, mapper50_add_w);
112         memory_install_write8_handler(space, 0x40a0, 0x40bf, 0, 0, mapper50_add_w);
128113      default:
129114         nes.slow_banking = 0;
130115         memory_install_read8_handler(space, 0x6000, 0x7fff, 0, 0, SMH_BANK(5));
r5997r5998
165150      }
166151   }
167152
153   //else if (nes.format == 2)
154   //TODO: we have to set up memory banking for unif board as in the mapper case
155
168156   /* Load a battery file, but only if there's no trainer since they share */
169157   /* overlapping memory. */
170158   if (nes.trainer)
r5997r5998
202190   nes.mid_ram_enable = 1;
203191
204192   /* Reset the mapper variables. Will also mark the char-gen ram as dirty */
193   //if (nes.format == 1)
205194   mapper_reset(machine, nes.mapper);
206195
196   //if (nes.format == 2)
197   //unif_reset(machine, nes.board);
198
207199   /* Reset the serial input ports */
208200   in_0.shift = 0;
209201   in_1.shift = 0;
r5997r5998
451443
452444   if (!mame_stricmp(filetype, "nes"))
453445   {
446      nes.format = 1;   // TODO: use this to select between mapper_reset / unif_reset
454447      /* Verify the file is in iNES format */
455448      memset(magic, '\0', sizeof(magic));
456449      image_fread(image, magic, 4);
r5997r5998
468461         if (4 == sscanf(mapinfo,"%d %d %d %d", &mapint1, &mapint2, &mapint3, &mapint4))
469462         {
470463            nes.mapper = mapint1;
471            local_options = mapint2;
464            local_options = mapint2 & 0x0f;
465            nes.crc_hack = mapint2 & 0xf0;   // this is used to differentiate among variants of the same Mapper (see nes_mmc.c)
472466            nes.prg_chunks = mapint3;
473467            nes.chr_chunks = mapint4;
474468            logerror("NES.HSI info: %d %d %d %d\n", mapint1, mapint2, mapint3, mapint4);
r5997r5998
636630      UINT32 size = image_length(image);
637631      const unif *unif_board;
638632
633      nes.format = 2;   // TODO: use this to select between mapper_reset / unif_reset
639634      /* Verify the file is in iNES format */
640635      memset(magic, '\0', sizeof(magic));
641636      image_fread(image, magic, 4);
src/mess/machine/nes_mmc.c
r5997r5998
1010    You can find the latest version of the doc at http://www.romhacking.net/docs/362/
1111
1212
13    Missing components:
14    * Currently, we are not emulating 4-screen mirroring (only 3 games use it)
15    * We need a better way to implement CPU cycle based IRQ. Currently we update their counter once every scanline
16      but, with this approach, every time 114 clocks have passed and for certain games it is too much!
17    * We need to emulate additional sound hardware in mappers 019, 024, 026, 069, 085 (and possibly other ones)
18    * We need to emulate EEPROM in mapper 016 and 159
19    * Barcode World (mapper 069) and Datach games (mapper 157) need Barcode Reader emulation
20      Notice that for mapper 157, the barcode reader enters in the irq, so glitches may be related to this!
21    * Karaoke Studio (mapper 188) misses input devices
22
1323    Known issues on specific mappers:
1424
25    * 000 F1 Race requires more precise PPU timing. It currently has plenty of 1-line glitches.
1526    * 001 AD&D Hillsfar and Bill & Ted are broken. We need to ignore the case of writes happening on 2
1627          consecutive CPU cycles because these games use dirty tricks to reset counters (see note in mapper1_w)
1728    * 001, 155 We don't handle (yet) WRAM enable/disable bit
18    * 002, 003 Bus conflict?
19    * 005 has some issues (e.g. Just Breed is not working), RAM banking needs hardware flags to determine size
29    * 002, 003, 094, 097, 152 Bus conflict?
30    * 005 has issues (see e.g. Just Breed or Metal Slader Glory), RAM banking needs hardware flags to determine size
31    * 014 in-game graphics is glitched
2032    * 015 Shanghai Tycoon has corrupted graphics
21    * 016 some graphics problem (e.g. Rokudenashi Blues misses some element of graphics)
22    * 018 Pizza Pop and Plasma Ball shows graphics issues for this mapper
23    * 024, 026, 085 Registers of the additional sound hardware are not emulated
24    * 032 Major League is not properly working: check missing windows or field graphics in top view screens
25          (it requires one hack to support both boards using this mapper)
2633    * 033 has still some graphics problem (e.g. missing text in Akira)
27    * 034 Impossible Mission 2 is not working
34    * 034 Impossible Mission II does not show graphics
2835    * 038 seems to miss inputs. separate reads?
2936    * 039 Study n Game 32 in 1 misses keyboard and starts differently than in NEStopia
30    * 040 is not dealing correctly 0x6000-0x7fff (this got broken long ago)
3137    * 042 Ai Senshi Nicol has broken graphics (our Mapper 42 implementation does not handle CHR banks)
3238    * 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
39    * 064 has many IRQ problems (due to the way we implement CPU based IRQ) - see Skull & Crossbones.
40          Klax has problems as well (even if it uses scanline based IRQ, according to Disch's docs).
41    * 067 some 1-line glitches that cannot be solved without a better implementation for cycle-based IRQs
3642    * 071 Fire Hawk is not properly working (it requires one hack to support both boards using this mapper)
3743    * 072, 086, 092 lack samples support (maybe others as well)
44    * 073 16 bit IRQ mode is not implemented
3845    * 077 Requires 4-screen mirroring. Currently, it is very glitchy
39    * 078 Cosmo Carrier is not working (it requires one hack to support both boards using this mapper).
40          also, we lack NT mirroring
41    * 082 has chr-rom banking problems. Also mapper is in the middle of sram, which is unemulated.
4246    * 083 has serious glitches
43    * 091 lacks IRQ needed by MK2
44    * 094 Bus conflict?
45    * 096 is preliminary (no correct chr switch in connection to NT)
46    * 097 Bus conflict?
47    * 096 is preliminary (no correct chr switch in connection to PPU)
4748    * 104 Not all the games work
4849    * 107 Are the scrolling glitches (check status bar) correct? NEStopia behaves similarly
4950    * 112 Master Shooter is not working and misses some graphics
50    * 113 is not following docs (missing NT mirroring and high CHR bit)
51    * 115 (formerly 248) is preliminary
52    * 118 mirroring is a guess, chr-rom banking is likely different
53    * 143 are dancing block borders (in the intro) correct?
54    * 146 Pyramid 2 does not work
55    * 150 some problems (Magic Cubes, Mahjong Academy, others?), maybe mirroring related
56    * 152 Bus conflict?
51    * 117 In-game glitches
52    * 119 Pin Bot has glitches when the ball is in the upper half of the screen
53    * 133 Qi Wang starts with corrupted graphics (ingame seems better)
54    * 143 are Dancing Block borders (in the intro) correct?
55    * 153 Famicom Jump II variant is not working, for some reason
56    * 158 In addition to IRQ problems (same as 64), mirroring was just a guess (wrong?). info needed!
5757    * 164 preliminary - no sprites?
5858    * 176 has some graphics problem
5959    * 178 Fan Kong Jin Ying is not working (but not even in NEStopia)
6060    * 180 Crazy Climber controller?
61    * 185 we emulate it like plain Mapper 3, but it's not: Mighty BombJack and Seicross don't work
62    * 187, 198, 208, 215 have some PRG banking issues - preliminary!
6163    * 188 needs mic input (reads from 0x6000-0x7fff)
64    * 197 Super Fighter 3 has some glitch in-game (maybe mirroring?)
65    * 222 is only preliminar (wrong IRQ, mirroring or CHR banking?)
6266    * 225 115-in-1 has glitches in the menu (games seem fine)
6367    * 228 seems wrong. e.g. Action52 starts with a game rather than in the menu
6468    * 229 is preliminary
6569    * 230 not working yet (needs a value to flip at reset)
66    * 231 not working yet
6770    * 232 has graphics glitches
6871    * 241 Commandos is not working (but not even in NEStopia)
69    * 242 DQ7 is not working (it requires one hack to support both boards using this mapper)
70    * 243 has glitches in Sachen logo
72    * 242 In Dragon Quest VIII graphics of the main character is not drawn (it seems similar to Shanghai Tycoon [map15]
73          because in place of the missing graphics we get glitches in the left border)
74    * 249 only half of the games work (and Du Bao Ying Hao seems to suffer the same problem as DQ8 and Shanghai Tycoon)
75    * 252 shows logo, but doesn't reach the game
7176    * 255 does not really select game (same in NEStopia apparently)
7277
78    A few Mappers suffer of hardware conflict: original dumpers have used the same mapper number for more than
79    a kind of boards. In these cases (and only in these cases) we exploit nes.hsi to set up accordingly
80    emulation. Games which requires this hack are the following:
81    * 032 - Major League needs hardwired mirroring (missing windows and glitched field in top view, otherwise)
82    * 034 - Impossible Mission II is not like BxROM games (it writes to 0x7ffd-0x7fff, instead of 0x8000). It is still
83          unplayable though (see above)
84    * 078 - Cosmo Carrier needs a different mirroring than Holy Diver
85    * 113 - HES 6-in-1 requires mirroring (check Bookyman playfield), while other games break with this (check AV Soccer)
86    * 153 - Famicom Jump II uses a different board (or the same in a very different way)
87    * 242 - DQ8 has no mirroring (missing graphics is due to other reasons though)
88
7389    Details to investigate:
7490    * 034 writes to 0x8000-0xffff should not be used for NINA-001 and BNROM, only unlicensed BxROM...
7591    * 144 we ignore writes to 0x8000 while NEStopia does not. is it a problem?
7692    * 240 we do not map writes to 0x4020-0x40ff. is this a problem?
93    * some other emus uses mapper 210 for mapper 019 games without additional sound hardware and mirroring capabilities
94      (in 210 mirroring is hardwired). However, simply initializing mirroring to Vertical in 019 seems to fix all glitches
95      in 210 games, so there seems to be no reason to have this duplicate mapper
7796
97    Some mappers copy PRG rom in SRAM region. Below is a list of those which does it (in MESS) to further
98    investigate if we are supporting them in the right way (e.g. do any of the following have conflicts with SRAM?):
99    * 065 (Gimmick! breaks badly without it)
100    * 040, 042, 050
101
78102    Remember that the MMC # does not equal the mapper #. In particular, Mapper 4 is
79103    in fact MMC3, Mapper 9 is MMC2 and Mapper 10 is MMC4. Makes perfect sense, right?
80104
r5997r5998
134158static name_table nt_page[4];  //quick banking structure for a maximum of 4K of RAM/ROM/ExRAM
135159
136160static int IRQ_enable, IRQ_enable_latch;
137static UINT16 IRQ_count, IRQ_count_latch, IRQ_reload;
161static UINT16 IRQ_count, IRQ_count_latch;
162static UINT8 IRQ_toggle;
163static UINT8 IRQ_reset;
138164static UINT8 IRQ_status;
139165static UINT8 IRQ_mode;
140166
r5997r5998
155181static UINT8 mmc_cmd1, mmc_cmd2;   // These represent registers where the mapper writes important values
156182static UINT8 mmc_count;         // This is used as counter in mappers like 1 and 45
157183
158static int prg_bank[4];         // Many mappers writes only some bits of the selected bank (for both PRG and CHR),
159static int vrom_bank[16];      // hence these are handy to latch bank values.
184static int mmc_prg_base, mmc_prg_mask;   // MMC3 based multigame carts select a block of banks by using these (and then act like normal MMC3),
185static int mmc_chr_base, mmc_chr_mask;   // while MMC3 and clones (mapper 118 & 119) simply set them as 0 and 0xff resp.
160186
187static UINT8 prg_bank[4];         // Many mappers writes only some bits of the selected bank (for both PRG and CHR),
188static UINT8 vrom_bank[16];         // hence these are handy to latch bank values.
161189
190
162191// FIXME: mapper specific variables should be unified as much as possible to make easier future implementation of save states
163192/* Local variables (a few more are defined just before handlers that use them...) */
164193
r5997r5998
166195
167196static UINT8 MMC2_regs[4];   // these replace bank0/bank0_hi/bank1/bank1_hi
168197
169static int MMC3_cmd;
170198UINT8* extended_ntram;
171199
172static int mmc_prg_base, mmc_prg_mask;   // MMC3 based multigame carts select a block of banks by using these (and then act like normal MMC3),
173static int mmc_chr_base, mmc_chr_mask;   // while MMC3 and clones (mapper 118 & 119) simply set them as 0 and 0xff resp.
174200
175201static int MMC5_rom_bank_mode;
176202static int MMC5_vrom_bank_mode;
r5997r5998
181207UINT8 MMC5_vram[0x400];
182208int MMC5_vram_control;
183209
210// these might be unified in single mmc_reg[] array, together with mmc_cmd1 & mmc_cmd2
211// but be careful that MMC3 clones often use mmc_cmd1/mmc_cmd2 (from base MMC3) AND additional regs below!
184212static UINT8 mapper45_reg[4];
185213static UINT8 mapper51_reg[3];
186static UINT8 mapper64_reg[11];
187214static UINT8 mapper83_reg[10];
188215static UINT8 mapper83_low_reg[4];
189216static UINT8 mapper95_reg[4];
r5997r5998
194221static UINT8 mapper12_reg;
195222static UINT8 map52_reg_written;
196223static UINT8 map114_reg, map114_reg_enabled;
224static UINT8 map215_reg[4];
225static UINT8 map217_reg[4];
226static UINT8 map249_reg;
227static UINT8 map14_reg[2];
228static UINT8 mapper121_reg[3];
229static UINT8 mapper187_reg[4];
230static UINT8 map208_reg[5];
197231
232
233static UINT8 extra_bank[16];   // some MMC3 clone have 2 series of PRG/CHR banks...
234               // we collect them all here: first 4 elements PRG banks, then 6/8 CHR banks
235
236// mapper 68 needs these for NT mirroring!
237static int m68_mirror;
238static int m0, m1;
239
240
241// FDS / mapper 20 need these for disks (to be added to fds struct?)
242static int fds_last_side;
243static int fds_count;
244
245// Famicom Jump II is identified as Mapper 153, but it works in a completely different way.
246// in particular, it requires these (not needed by other Mapper 153 games)
247static UINT8 map153_reg[8];
248static UINT8 map153_bank_latch;
249
198250static int mapper_warning;
199251
200252static emu_timer   *nes_irq_timer;
r5997r5998
217269    - nes_mid_mapper_r/w take care of accesses to 0x6000-0x7fff
218270    - nes_mapper_w takes care of writes to 0x8000-0xffff
219271    some mappers may access 0x4018-0x4100: this must be taken
220    care separately in init_nes_core (see e.g. mapper 40)
272    care separately in init_nes_core
221273
222274*************************************************************/
223275
r5997r5998
326378   else
327379   {
328380      logerror("Unimplemented mapper write, offset: %04x, data: %02x\n", offset, data);
329#if 1
381#ifdef MAME_DEBUG
330382      if (!mapper_warning)
331383      {
332384         logerror("This game is writing to the mapper area but no mapper is set. You may get better results by switching to a valid mapper.\n");
333385         mapper_warning = 1;
334386      }
335
336      switch (offset)
337      {
338         /* Hacked mapper for the 24-in-1 NES_ROM. */
339         /* It's really 35-in-1, and it's mostly different versions of Battle City. Unfortunately, the vrom dumps are bad */
340         case 0x7fde:
341            data &= (nes.prg_chunks - 1);
342            memory_set_bankptr(space->machine, 3, &nes.rom[data * 0x4000 + 0x10000]);
343            memory_set_bankptr(space->machine, 4, &nes.rom[data * 0x4000 + 0x12000]);
344            break;
345      }
346387#endif
347388   }
348389}
r5997r5998
437478      memory_set_bankptr(machine, 4, &nes.rom[bank * 0x2000 + 0x10000]);
438479}
439480
481/* We define an additional helper to map PRG-ROM to 0x6000-0x7000 */
482// TODO: are we implementing this correctly in the mappers which uses it? check!
483
484static void prg8_67( running_machine *machine, int bank )
485{
486   /* assumes that bank references an 8k chunk */
487   bank &= ((nes.prg_chunks << 1) - 1);
488   memory_set_bankptr(machine, 5, &nes.rom[bank * 0x2000 + 0x10000]);
489}
490
440491/* CHR ROM in 1K, 2K, 4K or 8K blocks */
441492
442493static void chr8( running_machine *machine, int bank, int source )
r5997r5998
866917  operate like a common MMC3 board on that specific block. To emulate this
867918  we use the concept of bases and masks. Original MMC3 boards simply
868919  set base = 0 and mask = 0xff at start and never change them */
920/* Notice that, atm, there is no way to directly handle MMC3 clone mappers
921  which use custom routines to set PRG/CHR. For these mappers we have to
922  re-define the 0x8000-0xffff handler at least for offsets 0 & 1 (i.e. the
923  offsets where are used set_prg/set_chr) by using the mapper-specific routines,
924  and then we can fall back to mapper4_w for the remaining offsets */
869925
870926static void mapper4_set_prg( running_machine *machine, int prg_base, int prg_mask )
871927{
872   int prg0_bank = prg_base | (prg_bank[0] & prg_mask);
873   int prg1_bank = prg_base | (prg_bank[1] & prg_mask);
874   int last_bank = prg_base | prg_mask;
928   UINT8 prg_flip = (mmc_cmd1 & 0x40) ? 2 : 0;
875929
876   if (MMC3_cmd & 0x40)
877   {
878      prg8_89(machine, last_bank - 1);
879      prg8_cd(machine, prg0_bank);
880   }
881   else
882   {
883      prg8_89(machine, prg0_bank);
884      prg8_cd(machine, last_bank - 1);
885   }
886
887   prg8_ab(machine, prg1_bank);
888   prg8_ef(machine, last_bank);
930   prg8_89(machine, prg_base | (prg_bank[0 ^ prg_flip] & prg_mask));
931   prg8_ab(machine, prg_base | (prg_bank[1] & prg_mask));
932   prg8_cd(machine, prg_base | (prg_bank[2 ^ prg_flip] & prg_mask));
933   prg8_ef(machine, prg_base | (prg_bank[3] & prg_mask));
889934}
890935
891936static void mapper4_set_chr( running_machine *machine, UINT8 chr, int chr_base, int chr_mask )
892937{
893   UINT8 chr_page = (MMC3_cmd & 0x80) >> 5;
938   UINT8 chr_page = (mmc_cmd1 & 0x80) >> 5;
894939
895940   chr1_x(machine, chr_page ^ 0, chr_base | ((vrom_bank[0] & ~0x01) & chr_mask), chr);
896941   chr1_x(machine, chr_page ^ 1, chr_base | ((vrom_bank[0] |  0x01) & chr_mask), chr);
r5997r5998
902947   chr1_x(machine, chr_page ^ 7, chr_base | (vrom_bank[5] & chr_mask), chr);
903948}
904949
950/* Here, IRQ counter decrements every scanline. */
905951static void mapper4_irq( const device_config *device, int scanline, int vblank, int blanked )
906952{
907   if ((scanline < PPU_BOTTOM_VISIBLE_SCANLINE) /*|| (scanline == ppu_scanlines_per_frame-1)*/)
953   if (scanline < PPU_BOTTOM_VISIBLE_SCANLINE)
908954   {
909955      int priorCount = IRQ_count;
910956      if ((IRQ_count == 0))
r5997r5998
932978   switch (offset & 0x6001)
933979   {
934980      case 0x0000:
935         MMC3_helper = MMC3_cmd ^ data;
936         MMC3_cmd = data;
981         MMC3_helper = mmc_cmd1 ^ data;
982         mmc_cmd1 = data;
937983
938984         /* Has PRG Mode changed? */
939985         if (MMC3_helper & 0x40)
r5997r5998
945991         break;
946992
947993      case 0x0001:
948         cmd = MMC3_cmd & 0x07;
994         cmd = mmc_cmd1 & 0x07;
949995         switch (cmd)
950996         {
951            case 0: case 1:   // these do not need to be separated because we shift banks in set_chr!
997            case 0: case 1:   // these do not need to be separated: we take care of them in set_chr!
952998            case 2: case 3: case 4: case 5:
953999               vrom_bank[cmd] = data;
9541000               mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
r5997r5998
9711017         nes.mid_ram_enable = data;
9721018         break;
9731019
974      case 0x4000: /* IRQ scanline counter */
1020      case 0x4000:
9751021         IRQ_count_latch = data;
9761022         break;
9771023
978      case 0x4001: /* IRQ scanline latch */
1024      case 0x4001: /* some sources state that here we must have IRQ_count = IRQ_count_latch */
9791025         IRQ_count = 0;
9801026         break;
9811027
982      case 0x6000: /* Disable IRQs */
1028      case 0x6000:
9831029         IRQ_enable = 0;
9841030         break;
9851031
986      case 0x6001: /* Enable IRQs */
1032      case 0x6001:
9871033         IRQ_enable = 1;
9881034         break;
9891035
r5997r5998
11001146   /* Send $5000-$5015 to the sound chip */
11011147   if ((offset >= 0xf00) && (offset <= 0xf15))
11021148   {
1103      nes_psg_w (state->sound, offset & 0x1f, data);
1149      nes_psg_w(state->sound, offset & 0x1f, data);
11041150      return;
11051151   }
11061152
r5997r5998
11531199
11541200      /* tile data for MMC5 flood-fill NT mode */
11551201      case 0x1006:
1156         MMC5_floodtile=data;
1202         MMC5_floodtile = data;
11571203         break;
11581204
11591205      /* attr data for MMC5 flood-fill NT mode */
r5997r5998
12881334               vrom_bank[0] = data;
12891335//                  mapper5_sync_vrom(0);
12901336               chr1_0(space->machine, vrom_bank[0], CHRROM);
1291//                  ppu2c0x_set_videorom_bank(state->ppu, 0, 1, vrom_bank[0], 64);
12921337//                  nes_vram_sprite[0] = vrom_bank[0] * 64;
12931338//                  vrom_next[0] = 4;
12941339//                  vrom_page_a = 1;
r5997r5998
13091354               vrom_bank[1] = data;
13101355//                  mapper5_sync_vrom(0);
13111356               chr1_1(space->machine, vrom_bank[1], CHRROM);
1312               //ppu2c0x_set_videorom_bank(state->ppu, 1, 1, vrom_bank[1], 64);
13131357//                  nes_vram_sprite[1] = vrom_bank[0] * 64;
13141358//                  vrom_next[1] = 5;
13151359//                  vrom_page_a = 1;
r5997r5998
13261370               vrom_bank[2] = data;
13271371//                  mapper5_sync_vrom(0);
13281372               chr1_2(space->machine, vrom_bank[2], CHRROM);
1329//                  ppu2c0x_set_videorom_bank(state->ppu, 2, 1, vrom_bank[2], 64);
13301373//                  nes_vram_sprite[2] = vrom_bank[0] * 64;
13311374//                  vrom_next[2] = 6;
13321375//                  vrom_page_a = 1;
r5997r5998
13501393               vrom_bank[3] = data;
13511394//                  mapper5_sync_vrom(0);
13521395               chr1_3(space->machine, vrom_bank[3], CHRROM);
1353//                  ppu2c0x_set_videorom_bank(state->ppu, 3, 1, vrom_bank[3], 64);
13541396//                  nes_vram_sprite[3] = vrom_bank[0] * 64;
13551397//                  vrom_next[3] = 7;
13561398//                  vrom_page_a = 1;
r5997r5998
13671409               vrom_bank[4] = data;
13681410//                  mapper5_sync_vrom(0);
13691411               chr1_4(space->machine, vrom_bank[4], CHRROM);
1370//                  ppu2c0x_set_videorom_bank(state->ppu, 4, 1, vrom_bank[4], 64);
13711412//                  nes_vram_sprite[4] = vrom_bank[0] * 64;
13721413//                  vrom_next[0] = 0;
13731414//                  vrom_page_a = 0;
r5997r5998
13881429               vrom_bank[5] = data;
13891430//                  mapper5_sync_vrom(0);
13901431               chr1_5(space->machine, vrom_bank[5], CHRROM);
1391//                  ppu2c0x_set_videorom_bank(state->ppu, 5, 1, vrom_bank[5], 64);
13921432//                  nes_vram_sprite[5] = vrom_bank[0] * 64;
13931433//                  vrom_next[1] = 1;
13941434//                  vrom_page_a = 0;
r5997r5998
14051445               vrom_bank[6] = data;
14061446//                  mapper5_sync_vrom(0);
14071447               chr1_6(space->machine, vrom_bank[6], CHRROM);
1408//                  ppu2c0x_set_videorom_bank(state->ppu, 6, 1, vrom_bank[6], 64);
14091448//                  nes_vram_sprite[6] = vrom_bank[0] * 64;
14101449//                  vrom_next[2] = 2;
14111450//                  vrom_page_a = 0;
r5997r5998
14341473               vrom_bank[7] = data;
14351474//                  mapper5_sync_vrom(0);
14361475               chr1_7(space->machine, vrom_bank[7], CHRROM);
1437//                  ppu2c0x_set_videorom_bank(state->ppu, 7, 1, vrom_bank[7], 64);
14381476//                  nes_vram_sprite[7] = vrom_bank[0] * 64;
14391477//                  vrom_next[3] = 3;
14401478//                  vrom_page_a = 0;
r5997r5998
14531491//                  nes_vram[0 + (vrom_page_a*4)] = data * 64;
14541492//                  nes_vram[0] = data * 64;
14551493               chr1_4(space->machine, data, CHRROM);
1456//                  ppu2c0x_set_videorom_bank(state->ppu, 4, 1, data, 64);
14571494//                  mapper5_sync_vrom(1);
14581495               if (!vrom_page_b)
14591496               {
r5997r5998
14791516//                  nes_vram[1 + (vrom_page_a*4)] = data * 64;
14801517//                  nes_vram[1] = data * 64;
14811518               chr1_5(space->machine, data, CHRROM);
1482//                  ppu2c0x_set_videorom_bank(state->ppu, 5, 1, data, 64);
14831519//                  mapper5_sync_vrom(1);
14841520               if (!vrom_page_b)
14851521               {
r5997r5998
15001536//                  nes_vram[2 + (vrom_page_a*4)] = data * 64;
15011537//                  nes_vram[2] = data * 64;
15021538               chr1_6(space->machine, data, CHRROM);
1503//                  ppu2c0x_set_videorom_bank(state->ppu, 6, 1, data, 64);
15041539//                  mapper5_sync_vrom(1);
15051540               if (!vrom_page_b)
15061541               {
r5997r5998
15371572//                  nes_vram[3 + (vrom_page_a*4)] = data * 64;
15381573//                  nes_vram[3] = data * 64;
15391574               chr1_7(space->machine, data, CHRROM);
1540//                  ppu2c0x_set_videorom_bank(state->ppu, 7, 1, data, 64);
15411575//                  mapper5_sync_vrom(1);
15421576               if (!vrom_page_b)
15431577               {
r5997r5998
15821616    Known Boards: FFE4 Copier Board
15831617    Games: Hacked versions of games
15841618
1585    In MESS: Unsupported, low priority
1619    In MESS: Supported? Not sure if we could also have ExRAM or not...
1620       However, priority is pretty low for this mapper.
15861621
15871622*************************************************************/
15881623
1624/* Here, IRQ counter decrements every CPU cycle. Since we update it every scanline,
1625we need to decrement it by 114 (Each scanline consists of 341 dots and, on NTSC,
1626there are 3 dots to every 1 CPU cycle, hence 114 is the number of cycles per scanline ) */
1627static void ffe_irq( const device_config *device, int scanline, int vblank, int blanked )
1628{
1629   /* 114 is the number of cycles per scanline */
1630   /* TODO: change to reflect the actual number of cycles spent */
1631   if (IRQ_enable)
1632   {
1633      if ((0xffff - IRQ_count) < 114)
1634      {
1635         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
1636         IRQ_count = 0xffff;
1637         IRQ_enable = 0;
1638      }
1639      IRQ_count -= 114;
1640   }
1641}
1642
1643static WRITE8_HANDLER( mapper6_l_w )
1644{
1645   LOG_MMC(("mapper6_l_w, offset: %04x, data: %02x\n", offset, data));
1646
1647   switch (offset)
1648   {
1649      case 0x1fe:
1650         mmc_cmd1 = data & 0x80;
1651         set_nt_mirroring((data & 0x10) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
1652         break;
1653      case 0x1ff:
1654         set_nt_mirroring((data & 0x10) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
1655         break;
1656
1657      case 0x401:
1658         IRQ_enable = data & 0x01;
1659         break;
1660      case 0x402:
1661         IRQ_count = (IRQ_count & 0xff00) | data;
1662         break;
1663      case 0x403:
1664         IRQ_enable = 1;
1665         IRQ_count = (IRQ_count & 0x00ff) | (data << 8);
1666         break;
1667   }
1668}
1669
1670static WRITE8_HANDLER( mapper6_w )
1671{
1672   LOG_MMC(("mapper6_w, offset: %04x, data: %02x\n", offset, data));
1673
1674   if (!mmc_cmd1)   // when in "FFE mode" we are forced to use CHRRAM/EXRAM bank?
1675   {
1676      prg16_89ab(space->machine, data >> 2);
1677      // chr8(space->machine, data & 0x03, ???);
1678      // due to lack of info on the exact behavior, we simply act as if mmc_cmd=1
1679      if (mmc_chr_source == CHRROM)
1680         chr8(space->machine, data & 0x03, CHRROM);
1681   }
1682   else if (mmc_chr_source == CHRROM)         // otherwise, we can use CHRROM (when present)
1683      chr8(space->machine, data, CHRROM);
1684}
1685
15891686/*************************************************************
15901687
15911688    Mapper 7
r5997r5998
16131710    Known Boards: FFE3 Copier Board
16141711    Games: Hacked versions of games
16151712
1616    In MESS: Supported
1713    In MESS: Supported? (I have no games to test this)
16171714
16181715*************************************************************/
16191716
r5997r5998
16221719   LOG_MMC(("mapper8_w, offset: %04x, data: %02x\n", offset, data));
16231720
16241721   chr8(space->machine, data & 0x07, CHRROM);
1625   data = (data >> 3) & (nes.prg_chunks - 1);
1626   memory_set_bankptr(space->machine, 1, &nes.rom[data * 0x4000 + 0x10000]);
1627   memory_set_bankptr(space->machine, 2, &nes.rom[data * 0x4000 + 0x12000]);
1722   prg16_89ab(space->machine, data >> 3);
16281723}
16291724
1630
16311725/*************************************************************
16321726
16331727    Mapper 9
r5997r5998
16691763
16701764static WRITE8_HANDLER( mapper9_w )
16711765{
1766   LOG_MMC(("mapper9_w, offset: %04x, data: %02x\n", offset, data));
16721767   switch (offset & 0x7000)
16731768   {
16741769      case 0x2000:
r5997r5998
16781773         MMC2_regs[0] = data;
16791774         if (mmc_cmd1 == 0xfd)
16801775            chr4_0(space->machine, MMC2_regs[0], CHRROM);
1681         LOG_MMC(("MMC2 VROM switch #1 (low): %02x\n", MMC2_regs[0]));
16821776         break;
16831777      case 0x4000:
16841778         MMC2_regs[1] = data;
16851779         if (mmc_cmd1 == 0xfe)
16861780            chr4_0(space->machine, MMC2_regs[1], CHRROM);
1687         LOG_MMC(("MMC2 VROM switch #1 (high): %02x\n", MMC2_regs[1]));
16881781         break;
16891782      case 0x5000:
16901783         MMC2_regs[2] = data;
16911784         if (mmc_cmd2 == 0xfd)
16921785            chr4_4(space->machine, MMC2_regs[2], CHRROM);
1693         LOG_MMC(("MMC2 VROM switch #2 (low): %02x\n", data));
16941786         break;
16951787      case 0x6000:
16961788         MMC2_regs[3] = data;
16971789         if (mmc_cmd2 == 0xfe)
16981790            chr4_4(space->machine, MMC2_regs[3], CHRROM);
1699         LOG_MMC(("MMC2 VROM switch #2 (high): %02x\n", data));
17001791         break;
17011792      case 0x7000:
17021793         set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
r5997r5998
17481839{
17491840   LOG_MMC(("mapper11_w, offset: %04x, data: %02x\n", offset, data));
17501841
1751   chr8(space->machine, data >> 4, CHRROM);
1842   chr8(space->machine, data >> 4, mmc_chr_source);
17521843   prg32(space->machine, data & 0x0f);
17531844}
17541845
r5997r5998
17811872
17821873static void mapper12_set_chr( running_machine *machine )
17831874{
1784   UINT8 chr_page = (MMC3_cmd & 0x80) >> 5;
1875   UINT8 chr_page = (mmc_cmd1 & 0x80) >> 5;
17851876
17861877   chr1_x(machine, chr_page ^ 0, ((mapper12_reg & 0x01) << 8) | (vrom_bank[0] & ~0x01), CHRROM);
17871878   chr1_x(machine, chr_page ^ 1, ((mapper12_reg & 0x01) << 8) | (vrom_bank[0] |  0x01), CHRROM);
r5997r5998
18011892   switch (offset & 0x6001)
18021893   {
18031894   case 0x0000:
1804      MMC3_helper = MMC3_cmd ^ data;
1805      MMC3_cmd = data;
1895      MMC3_helper = mmc_cmd1 ^ data;
1896      mmc_cmd1 = data;
18061897
18071898      /* Has PRG Mode changed? */
18081899      if (MMC3_helper & 0x40)
r5997r5998
18141905      break;
18151906
18161907   case 0x0001:
1817      cmd = MMC3_cmd & 0x07;
1908      cmd = mmc_cmd1 & 0x07;
18181909      switch (cmd)
18191910      {
1820      case 0: case 1:   // these do not need to be separated because we shift banks in set_chr!
1911      case 0: case 1:   // these do not need to be separated: we take care of them in set_chr!
18211912      case 2: case 3: case 4: case 5:
18221913         vrom_bank[cmd] = data;
18231914         mapper12_set_chr(space->machine);
r5997r5998
18581949    Mapper 14
18591950
18601951    Known Boards: Bootleg Board by Rex Soft (SL1632)
1861    Games: [no games in nes.hsi]
1952    Games: Samurai Spirits
18621953
18631954    MMC3 clone
18641955
1865    In MESS: Unsupported
1956    In MESS: Supported
18661957
18671958*************************************************************/
18681959
1960static void mapper14_set_prg( running_machine *machine, int prg_base, int prg_mask )
1961{
1962   if (map14_reg[0] & 0x02)
1963   {
1964      mapper4_set_prg(machine, prg_base, prg_mask);
1965   }
1966   else
1967   {
1968      prg8_89(machine, extra_bank[0]);
1969      prg8_ab(machine, extra_bank[1]);
1970      prg8_cd(machine, extra_bank[2]);
1971      prg8_ef(machine, extra_bank[3]);
1972   }
1973}
1974
1975static void mapper14_set_chr( running_machine *machine, UINT8 chr, int chr_base, int chr_mask )
1976{
1977   static const UINT8 conv_table[8] = {5, 5, 5, 5, 3, 3, 1, 1};
1978   UINT8 chr_page = (mmc_cmd1 & 0x80) >> 5;
1979   UINT8 bank[8];
1980   UINT8 chr_base2[8];
1981   int i;
1982
1983   if (map14_reg[0] & 0x02)
1984   {
1985      for(i = 0; i < 8; i++)
1986      {
1987         bank[i] = vrom_bank[i];
1988         chr_base2[i] = chr_base | ((map14_reg[0] << conv_table[i]) & 0x100);
1989      }
1990   }
1991   else
1992   {
1993      for(i = 0; i < 8; i++)
1994      {
1995         bank[i] = extra_bank[i + 4];   // first 4 extra_banks are PRG
1996         chr_base2[i] = chr_base;
1997      }
1998   }
1999
2000   chr1_x(machine, chr_page ^ 0, chr_base2[0] | (bank[0] & chr_mask), chr);
2001   chr1_x(machine, chr_page ^ 1, chr_base2[1] | (bank[1] & chr_mask), chr);
2002   chr1_x(machine, chr_page ^ 2, chr_base2[2] | (bank[2] & chr_mask), chr);
2003   chr1_x(machine, chr_page ^ 3, chr_base2[3] | (bank[3] & chr_mask), chr);
2004   chr1_x(machine, chr_page ^ 4, chr_base2[4] | (bank[4] & chr_mask), chr);
2005   chr1_x(machine, chr_page ^ 5, chr_base2[5] | (bank[5] & chr_mask), chr);
2006   chr1_x(machine, chr_page ^ 6, chr_base2[6] | (bank[6] & chr_mask), chr);
2007   chr1_x(machine, chr_page ^ 7, chr_base2[7] | (bank[7] & chr_mask), chr);
2008}
2009
2010static WRITE8_HANDLER( mapper14_w )
2011{
2012   UINT8 map14_helper1, map14_helper2, MMC3_helper, cmd;
2013   LOG_MMC(("mapper14_w, offset: %04x, data: %02x\n", offset, data));
2014
2015   if (offset == 0x2131)
2016   {
2017      map14_reg[0] = data;
2018      mapper14_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
2019      mapper14_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
2020
2021      if (!(map14_reg[0] & 0x02))
2022         set_nt_mirroring(map14_reg[1] & 0x01 ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
2023   }
2024
2025   if (map14_reg[0] & 0x02)
2026   {
2027      switch (offset & 0x6001)
2028      {
2029      case 0x0000:
2030         MMC3_helper = mmc_cmd1 ^ data;
2031         mmc_cmd1 = data;
2032
2033         /* Has PRG Mode changed? */
2034         if (MMC3_helper & 0x40)
2035            mapper14_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
2036
2037         /* Has CHR Mode changed? */
2038         if (MMC3_helper & 0x80)
2039            mapper14_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
2040         break;
2041
2042      case 0x0001:
2043         cmd = mmc_cmd1 & 0x07;
2044         switch (cmd)
2045         {
2046            case 0: case 1:   // these have to be changed due to the different way mapper14_set_chr works (it handles 1k banks)!
2047               vrom_bank[2 * cmd] = data;
2048               vrom_bank[2 * cmd + 1] = data;
2049               mapper14_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
2050               break;
2051            case 2: case 3: case 4: case 5:
2052               vrom_bank[cmd + 2] = data;
2053               mapper14_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
2054               break;
2055            case 6:
2056            case 7:
2057               prg_bank[cmd - 6] = data;
2058               mapper14_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
2059               break;
2060         }
2061         break;
2062
2063      case 0x2000:
2064         set_nt_mirroring(map14_reg[1] & 0x01 ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
2065         break;
2066
2067      default:
2068         mapper4_w(space, offset, data);
2069         break;
2070      }
2071   }
2072   else if (offset >= 0x3000 && offset <= 0x6003 )
2073   {
2074      map14_helper1 = (offset & 0x01) << 2;
2075      offset = ((offset & 0x02) | (offset >> 10)) >> 1;
2076      map14_helper2 = ((offset + 2) & 0x07) + 4; // '+4' because first 4 extra_banks are for PRG!
2077      extra_bank[map14_helper2] = (extra_bank[map14_helper2] & (0xf0 >> map14_helper1)) | ((data & 0x0f) << map14_helper1);
2078      mapper14_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
2079   }
2080   else
2081   {
2082      switch (offset & 0x7003)
2083      {
2084      case 0x0000:
2085      case 0x2000:
2086         extra_bank[offset >> 13] = data;
2087         mapper14_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
2088         break;
2089
2090      case 0x1000:
2091         map14_reg[1] = data;
2092         set_nt_mirroring(map14_reg[1] & 0x01 ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
2093         break;
2094      }
2095   }
2096}
2097
18692098/*************************************************************
18702099
18712100    Mapper 15
r5997r5998
18992128         prg8_89(space->machine, map15_helper);
19002129         prg8_ab(space->machine, map15_helper + 1);
19012130         prg8_cd(space->machine, map15_helper + 1);
1902         prg8_ef(space->machine, map15_helper);
2131         prg8_ef(space->machine, map15_helper + 1);
19032132         break;
19042133      case 0x002:
19052134         map15_helper |= map15_flip;
r5997r5998
19132142         prg8_89(space->machine, map15_helper);
19142143         prg8_ab(space->machine, map15_helper + 1);
19152144         prg8_cd(space->machine, map15_helper);
1916         prg8_ef(space->machine, map15_helper);
2145         prg8_ef(space->machine, map15_helper + 1);
19172146         break;
19182147   }
19192148}
r5997r5998
19272156          Dragon Ball Z II & III, Rokudenashi Blues, SD Gundam
19282157          Gaiden - KGM2
19292158
2159    At the moment, we don't support EEPROM I/O
2160
19302161    In MESS: Supported
19312162
19322163*************************************************************/
19332164
2165/* Here, IRQ counter decrements every CPU cycle. Since we update it every scanline,
2166we need to decrement it by 114 (Each scanline consists of 341 dots and, on NTSC,
2167there are 3 dots to every 1 CPU cycle, hence 114 is the number of cycles per scanline ) */
19342168static void bandai_irq( const device_config *device, int scanline, int vblank, int blanked )
19352169{
19362170   /* 114 is the number of cycles per scanline */
19372171   /* TODO: change to reflect the actual number of cycles spent */
1938
19392172   if (IRQ_enable)
19402173   {
19412174      if (IRQ_count <= 114)
19422175      {
19432176         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
2177         IRQ_count = (0xffff - 114 + IRQ_count);    // wrap around the 16 bits counter
19442178      }
19452179      IRQ_count -= 114;
19462180   }
r5997r5998
19562190      case 2: case 3:
19572191      case 4: case 5:
19582192      case 6: case 7:
1959         chr1_x(space->machine, offset & 0x07, data, CHRROM);
2193         chr1_x(space->machine, offset & 0x07, data, mmc_chr_source);
19602194         break;
19612195      case 8:
19622196         prg16_89ab(space->machine, data);
r5997r5998
19642198      case 9:
19652199         switch (data & 0x03)
19662200         {
1967            case 0: set_nt_mirroring(PPU_MIRROR_HORZ); break;
1968            case 1: set_nt_mirroring(PPU_MIRROR_VERT); break;
2201            case 0: set_nt_mirroring(PPU_MIRROR_VERT); break;
2202            case 1: set_nt_mirroring(PPU_MIRROR_HORZ); break;
19692203            case 2: set_nt_mirroring(PPU_MIRROR_LOW); break;
19702204            case 3: set_nt_mirroring(PPU_MIRROR_HIGH); break;
19712205         }
r5997r5998
19742208         IRQ_enable = data & 0x01;
19752209         break;
19762210      case 0x0b:
1977         IRQ_count &= 0xff00;
1978         IRQ_count |= data;
2211         IRQ_count = (IRQ_count & 0xff00) | data;
19792212         break;
19802213      case 0x0c:
1981         IRQ_count &= 0x00ff;
1982         IRQ_count |= (data << 8);
2214         IRQ_count = (IRQ_count & 0x00ff) | (data << 8);
19832215         break;
19842216      default:
19852217         logerror("** uncaught mapper 16 write, offset: %04x, data: %02x\n", offset, data);
r5997r5998
20012233    Known Boards: FFE8 Copier Board
20022234    Games: Hacked versions of games
20032235
2004    In MESS: Supported. it also uses mapper4_irq.
2236    In MESS: Supported?. IRQ support is just a guess (used to
2237      use MMC3 IRQ but it was wrong and it never enabled it)
20052238
20062239*************************************************************/
20072240
r5997r5998
20112244
20122245   switch (offset)
20132246   {
2014      /* $42fe - mirroring */
20152247      case 0x1fe:
2016         if (data & 0x10)
2017            set_nt_mirroring(PPU_MIRROR_LOW);
2018         else
2019            set_nt_mirroring(PPU_MIRROR_HIGH);
2248         set_nt_mirroring((data & 0x10) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
20202249         break;
2021      /* $42ff - mirroring */
20222250      case 0x1ff:
2023         if (data & 0x10)
2024            set_nt_mirroring(PPU_MIRROR_HORZ);
2025         else
2026            set_nt_mirroring(PPU_MIRROR_VERT);
2251         set_nt_mirroring((data & 0x10) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
20272252         break;
2028      /* $4501 - $4503 */
2029//      case 0x401:
2030//      case 0x402:
2031//      case 0x403:
2032         /* IRQ control */
2033//          break;
2034      /* $4504 - $4507 : 8k PRG-Rom switch */
2253
2254      case 0x401:
2255         IRQ_enable = data & 0x01;
2256         break;
2257      case 0x402:
2258         IRQ_count = (IRQ_count & 0xff00) | data;
2259         break;
2260      case 0x403:
2261         IRQ_enable = 1;
2262         IRQ_count = (IRQ_count & 0x00ff) | (data << 8);
2263         break;
2264
20352265      case 0x404:
2266         prg8_89(space->machine, data);
2267         break;
20362268      case 0x405:
2269         prg8_ab(space->machine, data);
2270         break;
20372271      case 0x406:
2272         prg8_cd(space->machine, data);
2273         break;
20382274      case 0x407:
2039         data &= ((nes.prg_chunks << 1) - 1);
2040//          LOG_MMC(("Mapper 17 bank switch, bank: %02x, data: %02x\n", offset & 0x03, data));
2041         memory_set_bankptr(space->machine, (offset & 0x03) + 1, &nes.rom[0x2000 * (data) + 0x10000]);
2275         prg8_ef(space->machine, data);
20422276         break;
2043      /* $4510 - $4517 : 1k CHR-Rom switch */
2277
20442278      case 0x410:
20452279      case 0x411:
20462280      case 0x412:
r5997r5998
20492283      case 0x415:
20502284      case 0x416:
20512285      case 0x417:
2052         chr1_x(space->machine, offset&7, data&((nes.chr_chunks << 3) - 1), CHRROM);
2053//          ppu2c0x_set_videorom_bank(state->ppu, offset & 0x07, 1, data, 64);
2286         chr1_x(space->machine, offset & 7, data, CHRROM);
20542287         break;
2055      default:
2056         logerror("** uncaught mapper 17 write, offset: %04x, data: %02x\n", offset, data);
2057         break;
20582288   }
20592289}
20602290
r5997r5998
20702300    In MESS: Supported
20712301
20722302*************************************************************/
2073
2303/* Here, IRQ counter decrements every CPU cycle. Since we update it every scanline,
2304we need to decrement it by 114 (Each scanline consists of 341 dots and, on NTSC,
2305there are 3 dots to every 1 CPU cycle, hence 114 is the number of cycles per scanline ) */
20742306static void jaleco_irq( const device_config *device, int scanline, int vblank, int blanked )
20752307{
2076   if (scanline <= PPU_BOTTOM_VISIBLE_SCANLINE)
2308   /* Increment & check the IRQ scanline counter */
2309   if (IRQ_enable)
20772310   {
2078      /* Increment & check the IRQ scanline counter */
2079      if (IRQ_enable)
2311      LOG_MMC(("scanline: %d, irq count: %04x\n", scanline, IRQ_count));
2312      if (IRQ_mode & 0x08)
20802313      {
2081         IRQ_count -= 0x100;
2082
2083         LOG_MMC(("scanline: %d, irq count: %04x\n", scanline, IRQ_count));
2084         if (IRQ_mode & 0x08)
2314         if ((IRQ_count & 0x000f) < 114)   // always true, but we only update the IRQ once per scanlines so we cannot be more precise :(
20852315         {
2086            if ((IRQ_count & 0x0f) == 0x00)
2087               /* rollover every 0x10 */
2088               cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
2316            cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
2317            IRQ_count = (IRQ_count & ~0x000f) | (0x0f - (114 & 0x0f) + (IRQ_count & 0x000f)); // sort of wrap around the counter
20892318         }
2090         else if (IRQ_mode & 0x04)
2319         // decrements should not affect upper bits, so we don't do anything here (114 > 0x0f)
2320      }
2321      else if (IRQ_mode & 0x04)
2322      {
2323         if ((IRQ_count & 0x00ff) < 114)
20912324         {
2092            if ((IRQ_count & 0x0ff) == 0x00)
2093               /* rollover every 0x100 */
2094               cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
2325            cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
2326            IRQ_count = (IRQ_count & ~0x00ff) | (0xff - 114 + (IRQ_count & 0x00ff));    // wrap around the 8 bits counter
20952327         }
2096         else if (IRQ_mode & 0x02)
2328         else
2329            IRQ_count -= 114;
2330      }
2331      else if (IRQ_mode & 0x02)
2332      {
2333         if ((IRQ_count & 0x0fff)  < 114)
20972334         {
2098            if ((IRQ_count & 0x0fff) == 0x000)
2099               /* rollover every 0x1000 */
2100               cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
2335            cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
2336            IRQ_count = (IRQ_count & ~0x0fff) | (0xfff - 114 + (IRQ_count & 0x0fff));    // wrap around the 12 bits counter
21012337         }
2102         else if (IRQ_count == 0)
2103            /* rollover at 0x10000 */
2104            cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
2338         else
2339            IRQ_count -= 114;
21052340      }
2341      else if (IRQ_count < 114)
2342      {
2343         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
2344         IRQ_count = (0xffff - 114 + IRQ_count);    // wrap around the 16 bits counter
2345      }
2346      else
2347         IRQ_count -= 114;
21062348   }
2107   else
2108   {
2109      IRQ_count = IRQ_count_latch;
2110   }
21112349}
21122350
2113
21142351static WRITE8_HANDLER( mapper18_w )
21152352{
21162353   UINT8 bank;
r5997r5998
21192356   switch (offset & 0x7003)
21202357   {
21212358      case 0x0000:
2122         /* Switch 8k bank at $8000 - low 4 bits */
21232359         prg_bank[0] = (prg_bank[0] & 0xf0) | (data & 0x0f);
21242360         prg8_89(space->machine, prg_bank[0]);
21252361         break;
21262362      case 0x0001:
2127         /* Switch 8k bank at $8000 - high 4 bits */
21282363         prg_bank[0] = (prg_bank[0] & 0x0f) | (data << 4);
21292364         prg8_89(space->machine, prg_bank[0]);
21302365         break;
21312366      case 0x0002:
2132         /* Switch 8k bank at $a000 - low 4 bits */
21332367         prg_bank[1] = (prg_bank[1] & 0xf0) | (data & 0x0f);
21342368         prg8_ab(space->machine, prg_bank[1]);
21352369         break;
21362370      case 0x0003:
2137         /* Switch 8k bank at $a000 - high 4 bits */
21382371         prg_bank[1] = (prg_bank[1] & 0x0f) | (data << 4);
21392372         prg8_ab(space->machine, prg_bank[1]);
21402373         break;
21412374      case 0x1000:
2142         /* Switch 8k bank at $c000 - low 4 bits */
21432375         prg_bank[2] = (prg_bank[2] & 0xf0) | (data & 0x0f);
21442376         prg8_cd(space->machine, prg_bank[2]);
21452377         break;
21462378      case 0x1001:
2147         /* Switch 8k bank at $c000 - high 4 bits */
21482379         prg_bank[2] = (prg_bank[2] & 0x0f) | (data << 4);
21492380         prg8_cd(space->machine, prg_bank[2]);
21502381         break;
r5997r5998
21522383      /* $9002, 3 (1002, 3) uncaught = Jaleco Baseball writes 0 */
21532384      /* believe it's related to battery-backed ram enable/disable */
21542385
2155      case 0x2000:
2156      case 0x2001:
2157      case 0x2002:
2158      case 0x2003:
2159      case 0x3000:
2160      case 0x3001:
2161      case 0x3002:
2162      case 0x3003:
2163      case 0x4000:
2164      case 0x4001:
2165      case 0x4002:
2166      case 0x4003:
2167      case 0x5000:
2168      case 0x5001:
2169      case 0x5002:
2170      case 0x5003:
2171         bank = ((offset & 0x7000) - 0x2000) / 0x0400 + ((offset & 0x0002) >> 1);
2386      case 0x2000: case 0x2001: case 0x2002: case 0x2003:
2387      case 0x3000: case 0x3001: case 0x3002: case 0x3003:
2388      case 0x4000: case 0x4001: case 0x4002: case 0x4003:
2389      case 0x5000: case 0x5001: case 0x5002: case 0x5003:
2390         bank = ((offset & 0x7000) - 0x2000) / 0x0800 + ((offset & 0x0002) >> 1);
21722391         if (offset & 0x0001)
2173            vrom_bank[bank] = (vrom_bank[bank] & 0x0f) | (data << 4);
2392            vrom_bank[bank] = (vrom_bank[bank] & 0x0f) | ((data & 0x0f)<< 4);
21742393         else
21752394            vrom_bank[bank] = (vrom_bank[bank] & 0xf0) | (data & 0x0f);
21762395
21772396         chr1_x(space->machine, bank, vrom_bank[bank], CHRROM);
21782397         break;
21792398
2180/* LBO - these are unverified */
2181
2182      case 0x6000: /* IRQ scanline counter - low byte, low nibble */
2399      case 0x6000:
21832400         IRQ_count_latch = (IRQ_count_latch & 0xfff0) | (data & 0x0f);
2184         LOG_MMC(("     Mapper 18 copy/set irq latch (l-l): %02x\n", data));
21852401         break;
2186      case 0x6001: /* IRQ scanline counter - low byte, high nibble */
2402      case 0x6001:
21872403         IRQ_count_latch = (IRQ_count_latch & 0xff0f) | ((data & 0x0f) << 4);
2188         LOG_MMC(("     Mapper 18 copy/set irq latch (l-h): %02x\n", data));
21892404         break;
21902405      case 0x6002:
2191         IRQ_count_latch = (IRQ_count_latch & 0xf0ff) | ((data & 0x0f) << 9);
2192         LOG_MMC(("     Mapper 18 copy/set irq latch (h-l): %02x\n", data));
2406         IRQ_count_latch = (IRQ_count_latch & 0xf0ff) | ((data & 0x0f) << 8);
21932407         break;
21942408      case 0x6003:
2195         IRQ_count_latch = (IRQ_count_latch & 0x0fff) | ((data & 0x0f) << 13);
2196         LOG_MMC(("     Mapper 18 copy/set irq latch (h-h): %02x\n", data));
2409         IRQ_count_latch = (IRQ_count_latch & 0x0fff) | ((data & 0x0f) << 12);
21972410         break;
21982411
2199/* LBO - these 2 are likely wrong */
2200
2201      case 0x7000: /* IRQ Control 0 */
2202         if (data & 0x01)
2203         {
2204//              IRQ_enable = 1;
2205            IRQ_count = IRQ_count_latch;
2206         }
2207         LOG_MMC(("     Mapper 18 IRQ Control 0: %02x\n", data));
2412      case 0x7000:
2413         IRQ_count = IRQ_count_latch;
22082414         break;
2209      case 0x7001: /* IRQ Control 1 */
2415      case 0x7001:
22102416         IRQ_enable = data & 0x01;
22112417         IRQ_mode = data & 0x0e;
2212         LOG_MMC(("     Mapper 18 IRQ Control 1: %02x\n", data));
22132418         break;
22142419
2215      case 0x7002: /* Misc */
2420      case 0x7002:
22162421         switch (data & 0x03)
22172422         {
2218            case 0: set_nt_mirroring(PPU_MIRROR_LOW); break;
2219            case 1: set_nt_mirroring(PPU_MIRROR_HIGH); break;
2220            case 2: set_nt_mirroring(PPU_MIRROR_VERT); break;
2221            case 3: set_nt_mirroring(PPU_MIRROR_HORZ); break;
2423            case 0: set_nt_mirroring(PPU_MIRROR_HORZ); break;
2424            case 1: set_nt_mirroring(PPU_MIRROR_VERT); break;
2425            case 2: set_nt_mirroring(PPU_MIRROR_LOW); break;
2426            case 3: set_nt_mirroring(PPU_MIRROR_HIGH); break;
22222427         }
22232428         break;
22242429
2225/* $f003 uncaught, writes 0(start) & various(ingame) */
2226//      case 0x7003:
2227//          IRQ_count = data;
2228//          break;
2229
22302430      default:
22312431         logerror("Mapper 18 uncaught addr: %04x value: %02x\n", offset + 0x8000, data);
22322432         break;
r5997r5998
22452445
22462446*************************************************************/
22472447
2448/* Here, IRQ counter decrements every CPU cycle. Since we update it every scanline,
2449we need to decrement it by 114 (Each scanline consists of 341 dots and, on NTSC,
2450there are 3 dots to every 1 CPU cycle, hence 114 is the number of cycles per scanline ) */
22482451static void namcot_irq( const device_config *device, int scanline, int vblank, int blanked )
22492452{
22502453   if (IRQ_enable)
22512454   {
2252      if (IRQ_count == 0x7fff)
2455      if (IRQ_count >= (0x7fff - 114))
2456      {
22532457         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
2458         IRQ_count = 0;
2459      }
22542460      else
2255         IRQ_count++;
2461         IRQ_count += 114;
22562462   }
22572463}
22582464
22592465static WRITE8_HANDLER( mapper19_l_w )
22602466{
22612467   LOG_MMC(("mapper19_l_w, offset: %04x, data: %02x\n", offset, data));
2468   offset += 0x100;
22622469
22632470   switch (offset & 0x1800)
22642471   {
r5997r5998
22782485static READ8_HANDLER( mapper19_l_r )
22792486{
22802487   LOG_MMC(("mapper19_l_r, offset: %04x\n", offset));
2488   offset += 0x100;
22812489
22822490   switch (offset & 0x1800)
22832491   {
r5997r5998
22902498   }
22912499}
22922500
2501static void mapper19_set_mirror( UINT8 page, UINT8 data )
2502{
2503   if (!(data < 0xe0))
2504      set_nt_page(page, CIRAM, data & 0x01, 1);
2505   else
2506      set_nt_page(page, ROM, data, 0);
2507}
2508
22932509static WRITE8_HANDLER( mapper19_w )
22942510{
22952511   LOG_MMC(("mapper19_w, offset: %04x, data: %02x\n", offset, data));
r5997r5998
23022518         chr1_x(space->machine, offset / 0x800, data, CHRROM);
23032519         break;
23042520      case 0x4000:
2305         set_nt_page(0, CIRAM, data & 0x01, 1);
2521         mapper19_set_mirror(0, data);
23062522         break;
23072523      case 0x4800:
2308         set_nt_page(1, CIRAM, data & 0x01, 1);
2524         mapper19_set_mirror(1, data);
23092525         break;
23102526      case 0x5000:
2311         set_nt_page(2, CIRAM, data & 0x01, 1);
2527         mapper19_set_mirror(2, data);
23122528         break;
23132529      case 0x5800:
2314         set_nt_page(3, CIRAM, data & 0x01, 1);
2530         mapper19_set_mirror(3, data);
23152531         break;
23162532      case 0x6000:
2317         prg8_89(space->machine, data);
2533         prg8_89(space->machine, data & 0x3f);
23182534         break;
23192535      case 0x6800:
2320         prg8_ab(space->machine, data);
2536         mmc_cmd1 = data & 0xc0;      // this should enable High CHRRAM, but we still have to properly implement it!
2537         prg8_ab(space->machine, data & 0x3f);
23212538         break;
23222539      case 0x7000:
2323         prg8_cd(space->machine, data);
2540         prg8_cd(space->machine, data & 0x3f);
23242541         break;
2542      case 0x7800:
2543         LOG_MMC(("Mapper 19 sound address write, data: %02x\n", data));
2544         break;
23252545   }
23262546}
23272547
r5997r5998
23412561   if (IRQ_enable_latch)
23422562      cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
23432563
2344   /* Increment & check the IRQ scanline counter */
23452564   if (IRQ_enable)
23462565   {
23472566      if (IRQ_count <= 114)
r5997r5998
23572576
23582577READ8_HANDLER( fds_r )
23592578{
2360   int ret = 0x00;
2361   static int last_side = 0;
2362   static int count = 0;
2363
2579   UINT8 ret = 0x00;
23642580   LOG_MMC(("fds_r, offset: %04x\n", offset));
23652581
23662582   switch (offset)
r5997r5998
23832599         /* return "no disk" status if disk is unloaded */
23842600         if (nes_fds.data == NULL)
23852601            ret = 1;
2386         else if (last_side != nes_fds.current_side)
2602         else if (fds_last_side != nes_fds.current_side)
23872603         {
23882604            /* If we've switched disks, report "no disk" for a few reads */
23892605            ret = 1;
2390            count ++;
2391            if (count == 50)
2606            fds_count ++;
2607            if (fds_count == 50)
23922608            {
2393               last_side = nes_fds.current_side;
2394               count = 0;
2609               fds_last_side = nes_fds.current_side;
2610               fds_count = 0;
23952611            }
23962612         }
23972613         else
r5997r5998
24162632
24172633   switch (offset)
24182634   {
2419      case 0x00: /* $4020 */
2420         IRQ_count_latch &= ~0xff;
2421         IRQ_count_latch |= data;
2635      case 0x00:
2636         IRQ_count = (IRQ_count & 0xff00) | data;
24222637         break;
2423      case 0x01: /* $4021 */
2424         IRQ_count_latch &= ~0xff00;
2425         IRQ_count_latch |= (data << 8);
2638      case 0x01:
2639         IRQ_count = (IRQ_count & 0x00ff) | (data << 8);
24262640         break;
2427      case 0x02: /* $4022 */
2641      case 0x02:
24282642         IRQ_count = IRQ_count_latch;
24292643         IRQ_enable = data;
24302644         break;
2431      case 0x03: /* $4023 */
2645      case 0x03:
24322646         // d0 = sound io (1 = enable)
24332647         // d1 = disk io (1 = enable)
24342648         break;
2435      case 0x04: /* $4024 */
2649      case 0x04:
24362650         /* write data out to disk */
24372651         break;
2438      case 0x05: /* $4025 */
2652      case 0x05:
2653         nes_fds.write_reg = data;
2654
24392655         nes_fds.motor_on = data & 0x01;
2440         if (data & 0x02) nes_fds.head_position = 0;
2656         if (data & 0x02)
2657            nes_fds.head_position = 0;
24412658         nes_fds.read_mode = data & 0x04;
2442         if (data & 0x08)
2443            set_nt_mirroring(PPU_MIRROR_HORZ);
2444         else
2445            set_nt_mirroring(PPU_MIRROR_VERT);
2659         set_nt_mirroring((data & 0x08) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
24462660         if ((!(data & 0x40)) && (nes_fds.write_reg & 0x40))
24472661            nes_fds.head_position -= 2; // ???
24482662         IRQ_enable_latch = data & 0x80;
2449
2450         nes_fds.write_reg = data;
24512663         break;
24522664   }
24532665
r5997r5998
25022714         prg8_ab(space->machine, data);
25032715         break;
25042716      case 0x3000:
2505         /* Switch 1k vrom at $0000 - low 4 bits */
25062717         vrom_bank[0] = (vrom_bank[0] & 0xf0) | (data & 0x0f);
25072718         chr1_0(space->machine, vrom_bank[0], CHRROM);
25082719         break;
25092720      case 0x3002:
2510         /* Switch 1k vrom at $0000 - high 4 bits */
25112721         vrom_bank[0] = (vrom_bank[0] & 0x0f) | (data << 4);
25122722         chr1_0(space->machine, vrom_bank[0], CHRROM);
25132723         break;
25142724      case 0x3001:
25152725      case 0x3004:
2516         /* Switch 1k vrom at $0400 - low 4 bits */
25172726         vrom_bank[1] = (vrom_bank[1] & 0xf0) | (data & 0x0f);
25182727         chr1_1(space->machine, vrom_bank[1], CHRROM);
25192728         break;
25202729      case 0x3003:
25212730      case 0x3006:
2522         /* Switch 1k vrom at $0400 - high 4 bits */
25232731         vrom_bank[1] = (vrom_bank[1] & 0x0f) | (data << 4);
25242732         chr1_1(space->machine, vrom_bank[1], CHRROM);
25252733         break;
25262734      case 0x4000:
2527         /* Switch 1k vrom at $0800 - low 4 bits */
25282735         vrom_bank[2] = (vrom_bank[2] & 0xf0) | (data & 0x0f);
25292736         chr1_2(space->machine, vrom_bank[2], CHRROM);
25302737         break;
25312738      case 0x4002:
2532         /* Switch 1k vrom at $0800 - high 4 bits */
25332739         vrom_bank[2] = (vrom_bank[2] & 0x0f) | (data << 4);
25342740         chr1_2(space->machine, vrom_bank[2], CHRROM);
25352741         break;
25362742      case 0x4001:
25372743      case 0x4004:
2538         /* Switch 1k vrom at $0c00 - low 4 bits */
25392744         vrom_bank[3] = (vrom_bank[3] & 0xf0) | (data & 0x0f);
25402745         chr1_3(space->machine, vrom_bank[3], CHRROM);
25412746         break;
25422747      case 0x4003:
25432748      case 0x4006:
2544         /* Switch 1k vrom at $0c00 - high 4 bits */
25452749         vrom_bank[3] = (vrom_bank[3] & 0x0f) | (data << 4);
25462750         chr1_3(space->machine, vrom_bank[3], CHRROM);
25472751         break;
25482752      case 0x5000:
2549         /* Switch 1k vrom at $1000 - low 4 bits */
25502753         vrom_bank[4] = (vrom_bank[4] & 0xf0) | (data & 0x0f);
25512754         chr1_4(space->machine, vrom_bank[4], CHRROM);
25522755         break;
25532756      case 0x5002:
2554         /* Switch 1k vrom at $1000 - high 4 bits */
25552757         vrom_bank[4] = (vrom_bank[4] & 0x0f) | (data << 4);
25562758         chr1_4(space->machine, vrom_bank[4], CHRROM);
25572759         break;
25582760      case 0x5001:
25592761      case 0x5004:
2560         /* Switch 1k vrom at $1400 - low 4 bits */
25612762         vrom_bank[5] = (vrom_bank[5] & 0xf0) | (data & 0x0f);
25622763         chr1_5(space->machine, vrom_bank[5], CHRROM);
25632764         break;
25642765      case 0x5003:
25652766      case 0x5006:
2566         /* Switch 1k vrom at $1400 - high 4 bits */
25672767         vrom_bank[5] = (vrom_bank[5] & 0x0f) | (data << 4);
25682768         chr1_5(space->machine, vrom_bank[5], CHRROM);
25692769         break;
25702770      case 0x6000:
2571         /* Switch 1k vrom at $1800 - low 4 bits */
25722771         vrom_bank[6] = (vrom_bank[6] & 0xf0) | (data & 0x0f);
25732772         chr1_6(space->machine, vrom_bank[6], CHRROM);
25742773         break;
25752774      case 0x6002:
2576         /* Switch 1k vrom at $1800 - high 4 bits */
25772775         vrom_bank[6] = (vrom_bank[6] & 0x0f) | (data << 4);
25782776         chr1_6(space->machine, vrom_bank[6], CHRROM);
25792777         break;
25802778      case 0x6001:
25812779      case 0x6004:
2582         /* Switch 1k vrom at $1c00 - low 4 bits */
25832780         vrom_bank[7] = (vrom_bank[7] & 0xf0) | (data & 0x0f);
25842781         chr1_7(space->machine, vrom_bank[7], CHRROM);
25852782         break;
25862783      case 0x6003:
25872784      case 0x6006:
2588         /* Switch 1k vrom at $1c00 - high 4 bits */
25892785         vrom_bank[7] = (vrom_bank[7] & 0x0f) | (data << 4);
25902786         chr1_7(space->machine, vrom_bank[7], CHRROM);
25912787         break;
2788
25922789      case 0x7000:
2593         /* Set low 4 bits of latch */
2594         IRQ_count_latch &= ~0x0f;
2595         IRQ_count_latch |= data & 0x0f;
2596//          LOG_MMC(("konami_vrc4 irq_latch low: %02x\n", IRQ_count_latch));
2790         IRQ_count_latch = (IRQ_count_latch & 0xf0) | (data & 0x0f);
25972791         break;
25982792      case 0x7002:
25992793      case 0x7040:
2600         /* Set high 4 bits of latch */
2601         IRQ_count_latch &= ~0xf0;
2602         IRQ_count_latch |= (data << 4) & 0xf0;
2603//          LOG_MMC(("konami_vrc4 irq_latch high: %02x\n", IRQ_count_latch));
2794         IRQ_count_latch = (IRQ_count_latch & 0x0f) | ((data & 0x0f) << 4 );
26042795         break;
26052796      case 0x7004:
26062797      case 0x7001:
26072798      case 0x7080:
2799         IRQ_mode = data & 0x04;   // currently not implemented: 0 = prescaler mode / 1 = CPU mode
26082800         IRQ_enable = data & 0x02;
26092801         IRQ_enable_latch = data & 0x01;
26102802         if (data & 0x02)
26112803            IRQ_count = IRQ_count_latch;
2612//          LOG_MMC(("konami_vrc4 irq_count set: %02x\n", IRQ_count));
2613//          LOG_MMC(("konami_vrc4 enable: %02x\n", IRQ_enable));
2614//          LOG_MMC(("konami_vrc4 enable latch: %02x\n", IRQ_enable_latch));
26152804         break;
26162805      case 0x7006:
26172806      case 0x7003:
26182807      case 0x70c0:
26192808         IRQ_enable = IRQ_enable_latch;
2620//          LOG_MMC(("konami_vrc4 enable copy: %02x\n", IRQ_enable));
26212809         break;
26222810      default:
26232811         LOG_MMC(("konami_vrc4_w uncaught offset: %04x value: %02x\n", offset, data));
r5997r5998
26562844      }
26572845      break;
26582846   case 0x2000:
2659      /* Switch 8k bank at $a000 */
26602847      prg8_ab(space->machine, data);
26612848      break;
26622849   case 0x3000:
26632850   case 0x4000:
26642851   case 0x5000:
26652852   case 0x6000:
2666      /* switch 1k vrom at $0000-$1c00 */
26672853      bank = ((offset & 0x7000) - 0x3000) / 0x0800 + (offset & 0x0001);
26682854      /* Notice that we store the banks as in other VRC, but then we take vrom_bank>>1 because it's VRC2A!*/
26692855      if (offset & 0x0002)
r5997r5998
27512937      else
27522938         vrom_bank[bank] = (vrom_bank[bank] & 0xf0) | (data & 0x0f);
27532939
2754      chr1_x(space->machine, bank, vrom_bank[bank], CHRROM);
2940      chr1_x(space->machine, bank, vrom_bank[bank], mmc_chr_source);
27552941      break;
27562942   case 0x7000:
2757      /* Set low 4 bits of latch */
27582943      IRQ_count_latch &= ~0x0f;
27592944      IRQ_count_latch |= data & 0x0f;
27602945      break;
27612946   case 0x7001:
2762      /* Set high 4 bits of latch */
27632947      IRQ_count_latch &= ~0xf0;
27642948      IRQ_count_latch |= (data << 4) & 0xf0;
27652949      break;
27662950   case 0x7002:
2951      IRQ_mode = data & 0x04;   // currently not implemented: 0 = prescaler mode / 1 = CPU mode
27672952      IRQ_enable = data & 0x02;
27682953      IRQ_enable_latch = data & 0x01;
27692954      if (data & 0x02)
r5997r5998
28363021         IRQ_count_latch = data;
28373022         break;
28383023      case 0x7001:
3024         IRQ_mode = data & 0x04;   // currently not implemented: 0 = prescaler mode / 1 = CPU mode
28393025         IRQ_enable = data & 0x02;
28403026         IRQ_enable_latch = data & 0x01;
28413027         if (data & 0x02)
r5997r5998
29083094         IRQ_enable = IRQ_enable_latch;
29093095         break;
29103096      case 0x7002:
3097         IRQ_mode = data & 0x04;   // currently not implemented: 0 = prescaler mode / 1 = CPU mode
29113098         IRQ_enable = data & 0x02;
29123099         IRQ_enable_latch = data & 0x01;
29133100         if (data & 0x02)
r5997r5998
29833170    Games: Ai Sensei no Oshiete, Image Fight, Kaiketsu
29843171          Yanchamaru 2, Maikyuu Shima, Paaman, Paaman 2
29853172
3173    A crc check is required to support Major League (which uses
3174    a slightly different board)
3175
29863176    In MESS: Supported.
29873177
29883178*************************************************************/
r5997r5998
29983188         break;
29993189      case 0x1000:
30003190         mmc_cmd1 = data & 0x02;
3001         set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
3191         if (!nes.crc_hack)   // Major League has hardwired mirroring (it would have required a separate mapper)
3192            set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
30023193         break;
30033194      case 0x2000:
30043195         prg8_ab(space->machine, data);
r5997r5998
30293220{
30303221   LOG_MMC(("mapper33_w, offset: %04x, data: %02x\n", offset, data));
30313222
3032   switch (offset & 0x7003)
3223   switch (offset & 0x6003)
30333224   {
30343225      case 0x0000:
30353226         set_nt_mirroring((data & 0x40) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
r5997r5998
30673258    Games: Deadly Tower, Impossible Mission II, Titanic 1912,
30683259          Dance Xtreme
30693260
3261    There actually exist TWO different kind of boards using
3262    this mapper. NINA-001 is not compatible with the other
3263    kind of board, so Impossible Mission II requires a crc check
3264    to be supported.
3265
30703266    In MESS: Supported.
30713267
30723268*************************************************************/
r5997r5998
30753271{
30763272   LOG_MMC(("mapper34_m_w, offset: %04x, data: %02x\n", offset, data));
30773273
3078   switch (offset)
3274   if (nes.crc_hack)   // is it AVE Nina-01?
30793275   {
3276      switch (offset)
3277      {
30803278      case 0x1ffd:
30813279         prg32(space->machine, data);
30823280         break;
r5997r5998
30863284      case 0x1fff:
30873285         chr4_4(space->machine, data, CHRROM);
30883286         break;
3287      }
30893288   }
30903289}
30913290
r5997r5998
30953294   /* Deadly Towers is really a Mapper 34 game - the demo screens look wrong using mapper 7. */
30963295   LOG_MMC(("mapper34_w, offset: %04x, data: %02x\n", offset, data));
30973296
3098   prg32(space->machine, data);
3297   if (!nes.crc_hack)    // is it plain BxROM?
3298      prg32(space->machine, data);
30993299}
31003300
31013301/*************************************************************
r5997r5998
32013401    Mapper 40
32023402
32033403    Known Boards: Unknown Bootleg Board
3204    Games: Super Mario Bros. 2 Lost Levels Pirate
3404    Games: Super Mario Bros. 2 Pirate (Jpn version of SMB2)
32053405
32063406    In MESS: Supported.
32073407
r5997r5998
32093409
32103410static void mapper40_irq( const device_config *device, int scanline, int vblank, int blanked )
32113411{
3212   /* Decrement & check the IRQ scanline counter */
32133412   if (IRQ_enable)
32143413   {
3215      if (--IRQ_count == 0)
3414      if ((0xfff - IRQ_count) <= 114)
32163415      {
3416         IRQ_count = (IRQ_count + 1) & 0xfff;
3417         IRQ_enable = 0;
32173418         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
32183419      }
3420      else
3421         IRQ_count += 114;
32193422   }
32203423}
32213424
r5997r5998
32273430   {
32283431      case 0x0000:
32293432         IRQ_enable = 0;
3230         IRQ_count = 37; /* Hardcoded scanline scroll */
3433         IRQ_count = 0;
32313434         break;
32323435      case 0x2000:
32333436         IRQ_enable = 1;
32343437         break;
32353438      case 0x6000:
3236         /* Game runs code between banks, use slow but sure method */
32373439         prg8_cd(space->machine, data);
32383440         break;
32393441   }
r5997r5998
32873489      switch(offset & 0x03)
32883490      {
32893491      case 0x00:
3290         memory_set_bankptr(space->machine, 5, &nes.rom[(data & ((nes.prg_chunks << 1) - 1)) * 0x2000 + 0x10000]);
3492         prg8_67(space->machine, data);
32913493         break;
32923494      case 0x01:
32933495         set_nt_mirroring((data & 0x08) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
r5997r5998
33163518    Known Boards: Unknown Bootleg Board
33173519    Games: Super Mario Bros. 2 Pirate (LF36)
33183520
3319    In MESS: Supported.
3521    In MESS: Supported? The only image I found is not working
3522       (not even in NEStopia).
33203523
33213524*************************************************************/
33223525
r5997r5998
34573660    Known Boards: Rumblestation Board
34583661    Games: Rumblestation 15 in 1
34593662
3460    In MESS: Partially Supported.
3663    In MESS: Supported.
34613664
34623665*************************************************************/
34633666
r5997r5998
35123715    Games: Bakushou!! Jinsei Gekijou 3, Bubble Bobble 2,
35133716          Captain Saver, Don Doko Don 2, Flintstones, Jetsons
35143717
3515    In MESS: Unsupported.
3718    This is basically Mapper 33 + IRQ. Notably, IRQ works the
3719    same as MMC3 irq, BUT latch values are "inverted" (XOR'ed
3720    with 0xff) and there is a little delay (not implemented yet)
3721    We simply use MMC3 IRQ and XOR the value written in the
3722    register 0xc000 below
35163723
3724    In MESS: Supported.
3725
35173726*************************************************************/
35183727
3728static WRITE8_HANDLER( mapper48_w )
3729{
3730   LOG_MMC(("mapper48_w, offset: %04x, data: %02x\n", offset, data));
3731
3732   switch (offset & 0x6003)
3733   {
3734      case 0x0000:
3735         prg8_89(space->machine, data);
3736         break;
3737      case 0x0001:
3738         prg8_ab(space->machine, data);
3739         break;
3740      case 0x0002:
3741         chr2_0(space->machine, data, CHRROM);
3742         break;
3743      case 0x0003:
3744         chr2_2(space->machine, data, CHRROM);
3745         break;
3746      case 0x2000:
3747         chr1_4(space->machine, data, CHRROM);
3748         break;
3749      case 0x2001:
3750         chr1_5(space->machine, data, CHRROM);
3751         break;
3752      case 0x2002:
3753         chr1_6(space->machine, data, CHRROM);
3754         break;
3755      case 0x2003:
3756         chr1_7(space->machine, data, CHRROM);
3757         break;
3758      case 0x4000:
3759         IRQ_count_latch = (0x100 - data) & 0xff;
3760         break;
3761      case 0x4001:
3762         IRQ_count = IRQ_count_latch;
3763         break;
3764      case 0x4002:
3765         IRQ_enable = 1;
3766         break;
3767      case 0x4003:
3768         IRQ_enable = 0;
3769         break;
3770      case 0x6000:
3771         set_nt_mirroring((data & 0x40) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
3772         break;
3773   }
3774}
3775
35193776/*************************************************************
35203777
35213778    Mapper 49
r5997r5998
35563813    Mapper 50
35573814
35583815    Known Boards: Unknown Bootleg Board
3559    Games: Super Mario Bros. Pirate Alt. Levels
3816    Games: Super Mario Bros. 2 Pirate (Jpn version of SMB2)
35603817
3561    In MESS: Unsupported.
3818    This was marked as Alt. Levels. is it true?
35623819
3820    In MESS: Supported.
3821
35633822*************************************************************/
35643823
3824static void mapper50_irq( const device_config *device, int scanline, int vblank, int blanked )
3825{
3826   if (IRQ_enable)
3827   {
3828      if (IRQ_count < 0x1000)
3829      {
3830         if ((0x1000 - IRQ_count) <= 114)
3831            cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
3832         else
3833            IRQ_count += 114;
3834      }
3835      else
3836         IRQ_count += 114;
3837
3838      IRQ_count &= 0xffff;   // according to docs is 16bit counter -> it wraps only after 0xffff
3839   }
3840}
3841
3842static WRITE8_HANDLER( mapper50_l_w )
3843{
3844   UINT8 prg;
3845   LOG_MMC(("mapper50_l_w, offset: %04x, data: %02x\n", offset, data));
3846   offset += 0x100;
3847
3848   switch (offset & 0x160)
3849   {
3850   case 0x020:
3851      prg = (data & 0x08) | ((data & 0x06) >> 1) | ((data & 0x01) << 2);
3852      prg8_cd(space->machine, prg);
3853      break;
3854   case 0x120:
3855      IRQ_enable = data & 0x01;
3856      break;
3857   }
3858}
3859
3860/* This goes to 0x4020-0x403f */
3861WRITE8_HANDLER( mapper50_add_w )
3862{
3863   UINT8 prg;
3864   LOG_MMC(("mapper50_add_w, offset: %04x, data: %02x\n", offset, data));
3865
3866   prg = (data & 0x08) | ((data & 0x06) >> 1) | ((data & 0x01) << 2);
3867   prg8_cd(space->machine, prg);
3868}
3869
35653870/*************************************************************
35663871
35673872    Mapper 51
r5997r5998
35693874    Known Boards: Unknown Multigame Bootleg Board
35703875    Games: 11 in 1 Ball Games
35713876
3572    In MESS: Supported.
3877    In MESS: Partially Supported.
35733878
35743879*************************************************************/
35753880
r5997r5998
35833888   }
35843889   else
35853890   {
3586      prg16_cdef(machine, (mapper51_reg[1] * 2) + 1);
3587      prg16_89ab(machine, mapper51_reg[2] * 2);
3891      prg16_89ab(machine, (mapper51_reg[1] << 1) | (mapper51_reg[0] >> 1));
3892      prg16_cdef(machine, (mapper51_reg[1] << 1) | 0x07);
35883893   }
35893894}
35903895
r5997r5998
36003905{
36013906   LOG_MMC(("mapper51_w, offset: %04x, data: %02x\n", offset, data));
36023907
3603   if (offset & 0x4000)
3604      mapper51_reg[2] = data;
3605   else
3606      mapper51_reg[1] = data;
3607
3608   mapper51_set_banks(space->machine);
3908   switch (offset & 0x6000)
3909   {
3910   case 0x4000:   // here we also update reg[0] upper bit
3911      mapper51_reg[0] = (mapper51_reg[0] & 0x01) | ((data >> 3) & 0x02);
3912   case 0x0000:
3913   case 0x2000:
3914   case 0x6000:
3915      mapper51_reg[1] = data & 0x0f;
3916      mapper51_set_banks(space->machine);
3917      break;
3918   }
36093919}
36103920
36113921/*************************************************************
r5997r5998
36343944      map52_helper1 = (data & 0x08);
36353945      map52_helper2 = (data & 0x40);
36363946
3637      mmc_prg_base = map52_helper1 ? ((data & 0x06) << 4) : ((data & 0x07) << 4);
3947      mmc_prg_base = map52_helper1 ? ((data & 0x07) << 4) : ((data & 0x06) << 4);
36383948      mmc_prg_mask = map52_helper1 ? 0x0f : 0x1f;
36393949      mmc_chr_base = ((data & 0x20) << 4) | ((data & 0x04) << 6) | (map52_helper2 ? ((data & 0x10) << 3) : 0);
36403950      mmc_chr_mask = map52_helper2 ? 0x7f : 0xff;
r5997r5998
36543964    Known Boards: Unknown Multigame Bootleg Board
36553965    Games: Supervision 16 in 1
36563966
3657    In MESS: Unsupported.
3967    In MESS: Unsupported (SRAM banks can go in mid-regions).
36583968
36593969*************************************************************/
36603970
r5997r5998
37704080    Known Boards: Unknown Multigame Bootleg Board
37714081    Games: 4 in 1, 35 in 1
37724082
3773    In MESS: Unsupported.
4083    In MESS: Unsupported (these are reset-based and have dips).
37744084
37754085*************************************************************/
37764086
r5997r5998
38594169    Games: Klax, Road Runner, Rolling Thunder, Shinobi, Skulls
38604170          & Croosbones, Xybots
38614171
3862    In MESS: Supported. It also uses mapper4_irq.
4172    In MESS: Partially Supported. It also uses mapper4_irq.
38634173
38644174*************************************************************/
38654175
3866static void mapper64_set_banks( running_machine *machine )
4176static void mapper64_irq( const device_config *device, int scanline, int vblank, int blanked )
38674177{
3868   if (mmc_cmd1 & 0x20)
4178   if (!IRQ_mode)   // we are in scanline mode!
38694179   {
3870      chr1_0(machine, mapper64_reg[0], CHRROM);
3871      chr1_2(machine, mapper64_reg[1], CHRROM);
3872      chr1_1(machine, mapper64_reg[8], CHRROM);
3873      chr1_3(machine, mapper64_reg[9], CHRROM);
4180      if (scanline < PPU_BOTTOM_VISIBLE_SCANLINE)
4181      {
4182         if (!IRQ_reset)
4183         {
4184            if (!IRQ_count)
4185               IRQ_count = IRQ_count_latch;
4186            else
4187            {
4188               IRQ_count--;
4189               if (IRQ_enable && !blanked && !IRQ_count)
4190               {
4191                  LOG_MMC(("irq fired, scanline: %d (MAME %d, beam pos: %d)\n", scanline,
4192                        video_screen_get_vpos(device->machine->primary_screen), video_screen_get_hpos(device->machine->primary_screen)));
4193                  cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
4194               }
4195            }
4196         }
4197         else
4198         {
4199            IRQ_reset = 0;
4200            IRQ_count = IRQ_count_latch + 1;
4201         }
4202      }
38744203   }
4204   /* otherwise, we are in CPU cycles mode --> decrement count of 114 every scanline
4205     --> in the meanwhile anything can have happened to IRQ_reset and we would not know
4206     --> Skulls and Crossbones does not show anything!! */
38754207   else
38764208   {
3877      chr1_0(machine, mapper64_reg[0] & 0xfe, CHRROM);
3878      chr1_1(machine, (mapper64_reg[0] & 0xfe) | 1, CHRROM);
3879      chr1_2(machine, mapper64_reg[1] & 0xfe, CHRROM);
3880      chr1_3(machine, (mapper64_reg[1] & 0xfe) | 1, CHRROM);
4209//      if (!IRQ_reset)
4210      {
4211         if (IRQ_count <= 114)
4212            IRQ_count = IRQ_count_latch;
4213         else
4214         {
4215            IRQ_count -= 114;
4216            if (IRQ_enable && !blanked && (IRQ_count <= 114))
4217            {
4218               LOG_MMC(("irq fired, scanline: %d (MAME %d, beam pos: %d)\n", scanline,
4219                     video_screen_get_vpos(device->machine->primary_screen), video_screen_get_hpos(device->machine->primary_screen)));
4220               cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
4221            }
4222         }
4223      }
4224//      else
4225//      {
4226//          IRQ_reset = 0;
4227//          IRQ_count = IRQ_count_latch + 1;
4228//      }
38814229   }
4230}
38824231
3883   chr1_4(machine, mapper64_reg[2], CHRROM);
3884   chr1_5(machine, mapper64_reg[3], CHRROM);
3885   chr1_6(machine, mapper64_reg[4], CHRROM);
3886   chr1_7(machine, mapper64_reg[5], CHRROM);
4232static void mapper64_set_prg( running_machine *machine )
4233{
4234   UINT8 prg_mode = mmc_cmd1 & 0x40;
38874235
3888   prg8_89(machine, mapper64_reg[6]);
3889   prg8_ab(machine, mapper64_reg[7]);
3890   prg8_cd(machine, mapper64_reg[10]);
4236   prg8_89(machine, prg_bank[prg_mode ? 2: 0]);
4237   prg8_ab(machine, prg_bank[prg_mode ? 0: 1]);
4238   prg8_cd(machine, prg_bank[prg_mode ? 1: 2]);
38914239}
38924240
3893static WRITE8_HANDLER( mapper64_m_w )
4241static void mapper64_set_chr( running_machine *machine )
38944242{
3895   LOG_MMC(("mapper64_m_w, offset: %04x, data: %02x\n", offset, data));
4243   UINT8 chr_page = (mmc_cmd1 & 0x80) >> 5;
4244
4245   if (mmc_cmd1 & 0x20)
4246   {
4247      chr1_x(machine, 0 ^ chr_page, vrom_bank[0], CHRROM);
4248      chr1_x(machine, 1 ^ chr_page, vrom_bank[8], CHRROM);
4249      chr1_x(machine, 2 ^ chr_page, vrom_bank[1], CHRROM);
4250      chr1_x(machine, 3 ^ chr_page, vrom_bank[9], CHRROM);
4251   }
4252   else
4253   {
4254      chr1_x(machine, 0 ^ chr_page, vrom_bank[0] & ~0x01, CHRROM);
4255      chr1_x(machine, 1 ^ chr_page, vrom_bank[0] |  0x01, CHRROM);
4256      chr1_x(machine, 2 ^ chr_page, vrom_bank[1] & ~0x01, CHRROM);
4257      chr1_x(machine, 3 ^ chr_page, vrom_bank[1] |  0x01, CHRROM);
4258   }
4259
4260   chr1_x(machine, 4 ^ chr_page, vrom_bank[2], CHRROM);
4261   chr1_x(machine, 5 ^ chr_page, vrom_bank[3], CHRROM);
4262   chr1_x(machine, 6 ^ chr_page, vrom_bank[4], CHRROM);
4263   chr1_x(machine, 7 ^ chr_page, vrom_bank[5], CHRROM);
38964264}
38974265
38984266static WRITE8_HANDLER( mapper64_w )
38994267{
3900/* TODO: something in the IRQ handling hoses Skull & Crossbones */
4268   UINT8 map64_helper, cmd;
4269   LOG_MMC(("mapper64_w offset: %04x, data: %02x\n", offset, data));
39014270
3902//  LOG_MMC(("mapper64_w offset: %04x, data: %02x, scanline: %d\n", offset, data, current_scanline));
3903
3904   switch (offset & 0x7001)
4271   switch (offset & 0x6001)
39054272   {
39064273      case 0x0000:
4274         map64_helper = mmc_cmd1 ^ data;
39074275         mmc_cmd1 = data;
4276
4277         /* Has PRG Mode changed? */
4278         if (map64_helper & 0x40)
4279            mapper64_set_prg(space->machine);
4280
4281         /* Has CHR Mode changed? */
4282         if (map64_helper & 0xa0)
4283            mapper64_set_chr(space->machine);
39084284         break;
4285
39094286      case 0x0001:
3910         if ((mmc_cmd1 & 0x0f) < 10)
3911            mapper64_reg[mmc_cmd1 & 0x0f] = data;
3912         if ((mmc_cmd1 & 0x0f) == 0x0f)
3913            mapper64_reg[10] = data;
4287         cmd = mmc_cmd1 & 0x0f;
4288         switch (cmd)
4289         {
4290            case 0: case 1:
4291            case 2: case 3:
4292            case 4: case 5:
4293               vrom_bank[cmd] = data;
4294               mapper64_set_chr(space->machine);
4295               break;
4296            case 6: case 7:
4297               prg_bank[cmd - 6] = data;
4298               mapper64_set_prg(space->machine);
4299               break;
4300            case 8: case 9:
4301               vrom_bank[cmd - 2] = data;
4302               mapper64_set_chr(space->machine);
4303               break;
4304            case 0x0f:
4305               prg_bank[2] = data;
4306               mapper64_set_prg(space->machine);
4307               break;
4308         }
4309         break;
39144310
3915         mapper64_set_banks(space->machine);
3916         break;
39174311      case 0x2000:
3918         /* Not sure if the one-screen mirroring applies to this mapper */
3919         if (data & 0x40)
3920            set_nt_mirroring(PPU_MIRROR_HIGH);
3921         else
3922            set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
4312         set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
39234313         break;
3924      case 0x4000: /* $c000 - IRQ scanline counter */
4314
4315      case 0x4000:
39254316         IRQ_count_latch = data;
3926         if (0)
3927            IRQ_count = IRQ_count_latch;
3928
3929         LOG_MMC(("     MMC3 copy/set irq latch: %02x\n", data));
39304317         break;
39314318
39324319      case 0x4001: /* $c001 - IRQ scanline latch */
3933         IRQ_count = IRQ_count_latch;
39344320         IRQ_mode = data & 0x01;
3935         LOG_MMC(("     MMC3 set latch: %02x\n", data));
4321         IRQ_reset = 1;
39364322         break;
39374323
3938      case 0x6000: /* $e000 - Disable IRQs */
4324      case 0x6000:
39394325         IRQ_enable = 0;
3940         if (0)
3941            IRQ_count = IRQ_count_latch;
3942
3943         LOG_MMC(("     MMC3 disable irqs: %02x\n", data));
39444326         break;
39454327
3946      case 0x6001: /* $e001 - Enable IRQs */
4328      case 0x6001:
39474329         IRQ_enable = 1;
3948         if (0)
3949            IRQ_count = IRQ_count_latch;
3950
3951         LOG_MMC(("     MMC3 enable irqs: %02x\n", data));
39524330         break;
39534331
39544332      default:
r5997r5998
39694347
39704348*************************************************************/
39714349
4350/* Here, IRQ counter decrements every CPU cycle. Since we update it every scanline,
4351we need to decrement it by 114 (Each scanline consists of 341 dots and, on NTSC,
4352there are 3 dots to every 1 CPU cycle, hence 114 is the number of cycles per scanline ) */
39724353static void irem_irq( const device_config *device, int scanline, int vblank, int blanked )
39734354{
3974   /* Increment & check the IRQ scanline counter */
39754355   if (IRQ_enable)
39764356   {
3977      if (--IRQ_count == 0)
4357      IRQ_count -= 114;
4358
4359      if (IRQ_count <= 114)
4360      {
4361         IRQ_enable = 0;
39784362         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
4363      }
39794364   }
39804365}
39814366
r5997r5998
39834368{
39844369   LOG_MMC(("mapper65_w, offset %04x, data: %02x\n", offset, data));
39854370
3986   switch (offset & 0x7007)
4371   switch (offset & 0x7fff)
39874372   {
39884373      case 0x0000:
39894374         prg8_89(space->machine, data);
3990         LOG_MMC(("     Mapper 65 switch ($8000) value: %02x\n", data));
39914375         break;
4376
39924377      case 0x1001:
3993         if (data & 0x80)
3994            set_nt_mirroring(PPU_MIRROR_HORZ);
3995         else
3996            set_nt_mirroring(PPU_MIRROR_VERT);
4378         set_nt_mirroring((data & 0x80) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
39974379         break;
4380
4381      case 0x1003:
4382         IRQ_enable = data & 0x80;
4383         break;
4384
4385      case 0x1004:
4386         IRQ_count = IRQ_count_latch;
4387         break;
4388
39984389      case 0x1005:
3999         IRQ_count = data << 1;
4390         IRQ_count_latch = (IRQ_count_latch & 0x00ff) | (data << 8);
40004391         break;
4392
40014393      case 0x1006:
4002         IRQ_enable = IRQ_count;
4394         IRQ_count_latch = (IRQ_count_latch & 0xff00) | data;
40034395         break;
40044396
40054397      case 0x2000:
40064398         prg8_ab(space->machine, data);
4007         LOG_MMC(("     Mapper 65 switch ($a000) value: %02x\n", data));
40084399         break;
40094400
40104401      case 0x3000:
r5997r5998
40154406      case 0x3005:
40164407      case 0x3006:
40174408      case 0x3007:
4018         /* Switch 1k VROM at $0000-$1c00 */
40194409         chr1_x(space->machine, offset & 0x07, data, CHRROM);
40204410         break;
40214411
40224412      case 0x4000:
40234413         prg8_cd(space->machine, data);
4024         LOG_MMC(("     Mapper 65 switch ($c000) value: %02x\n", data));
40254414         break;
40264415
40274416      default:
4028         LOG_MMC(("Mapper 65 addr: %04x value: %02x\n", offset + 0x8000, data));
40294417         break;
40304418   }
40314419}
r5997r5998
40574445    Known Boards: Sunsoft 3
40584446    Games: Fantasy Zone 2, Mito Koumon
40594447
4060    In MESS: Supported. It also uses mapper4_irq.
4448    In MESS: Supported.
40614449
40624450*************************************************************/
40634451
4452/* Here, IRQ counter decrements every CPU cycle. Since we update it every scanline,
4453we need to decrement it by 114 (Each scanline consists of 341 dots and, on NTSC,
4454there are 3 dots to every 1 CPU cycle, hence 114 is the number of cycles per scanline ) */
4455static void mapper67_irq( const device_config *device, int scanline, int vblank, int blanked )
4456{
4457   /* TODO: change to reflect the actual number of cycles spent: both using 114 or cycling 114,114,113
4458    produces a 1-line glitch in Fantasy Zone 2: it really requires the counter to be updated each CPU cycle! */
4459   if (IRQ_enable)
4460   {
4461      if (IRQ_count <= 114)
4462      {
4463         IRQ_enable = 0;
4464         IRQ_count = 0xffff;
4465         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
4466      }
4467      else
4468         IRQ_count -= 114;
4469   }
4470}
4471
40644472static WRITE8_HANDLER( mapper67_w )
40654473{
40664474   LOG_MMC(("mapper67_w, offset %04x, data: %02x\n", offset, data));
4067   switch (offset & 0x7801)
4475   switch (offset & 0x7800)
40684476   {
4069//      case 0x0000: /* IRQ acknowledge */
4070//          IRQ_enable = 0;
4071//          break;
4072      case 0x0800:
4073         chr2_0(space->machine, data, CHRROM);
4074         break;
4075      case 0x1800:
4076         chr2_2(space->machine, data, CHRROM);
4077         break;
4078      case 0x2800:
4079         chr2_4(space->machine, data, CHRROM);
4080         break;
4081      case 0x3800:
4082         chr2_6(space->machine, data, CHRROM);
4083         break;
4084      case 0x4800:
4085//          nes_vram[5] = data * 64;
4086//          break;
4087      case 0x4801:
4088         /* IRQ count? */
4089         IRQ_count = IRQ_count_latch;
4090         IRQ_count_latch = data;
4091         break;
4092      case 0x5800:
4093//          chr4_0(space->machine, data);
4094//          break;
4095      case 0x5801:
4096         IRQ_enable = data;
4097         break;
4098      case 0x6800:
4099      case 0x6801:
4100         switch (data & 3)
4101         {
4102            case 0x00: set_nt_mirroring(PPU_MIRROR_VERT); break;
4103            case 0x01: set_nt_mirroring(PPU_MIRROR_HORZ); break;
4104            case 0x02: set_nt_mirroring(PPU_MIRROR_LOW); break;
4105            case 0x03: set_nt_mirroring(PPU_MIRROR_HIGH); break;
4106         }
4107         break;
4108      case 0x7800:
4109      case 0x7801:
4110         prg16_89ab(space->machine, data);
4111         break;
4112      default:
4113         LOG_MMC(("mapper67_w uncaught offset: %04x, data: %02x\n", offset, data));
4114         break;
4115
4477   case 0x0800:
4478      chr2_0(space->machine, data, CHRROM);
4479      break;
4480   case 0x1800:
4481      chr2_2(space->machine, data, CHRROM);
4482      break;
4483   case 0x2800:
4484      chr2_4(space->machine, data, CHRROM);
4485      break;
4486   case 0x3800:
4487      chr2_6(space->machine, data, CHRROM);
4488      break;
4489   case 0x4000:
4490   case 0x4800:
4491      IRQ_toggle ^= 1;
4492      if (IRQ_toggle)
4493         IRQ_count = (IRQ_count & 0x00ff) | (data << 8);
4494      else
4495         IRQ_count = (IRQ_count & 0xff00) | data;
4496      break;
4497   case 0x5800:
4498      IRQ_enable = data & 0x10;
4499      IRQ_toggle = 0;
4500      break;
4501   case 0x6800:
4502      switch (data & 3)
4503      {
4504         case 0x00: set_nt_mirroring(PPU_MIRROR_VERT); break;
4505         case 0x01: set_nt_mirroring(PPU_MIRROR_HORZ); break;
4506         case 0x02: set_nt_mirroring(PPU_MIRROR_LOW); break;
4507         case 0x03: set_nt_mirroring(PPU_MIRROR_HIGH); break;
4508      }
4509      break;
4510   case 0x7800:
4511      prg16_89ab(space->machine, data);
4512      break;
4513   default:
4514      LOG_MMC(("mapper67_w uncaught offset: %04x, data: %02x\n", offset, data));
4515      break;
41164516   }
41174517}
41184518
r5997r5998
41294529
41304530static void mapper68_mirror( running_machine *machine, int m68_mirror, int m0, int m1 )
41314531{
4132   /* The 0x20000 (128k) offset is a magic number */
4133   #define M68_OFFSET 0x20000
4134
41354532   switch (m68_mirror)
41364533   {
41374534      case 0x00:
r5997r5998
41474544         set_nt_mirroring(PPU_MIRROR_HIGH);
41484545         break;
41494546      case 0x10:
4150         set_nt_page(0, ROM, m0 | 0x80, 0);   //(m0 << 10) + M68_OFFSET);
4151         set_nt_page(1, ROM, m1 | 0x80, 0);   //(m1 << 10) + M68_OFFSET);
4152         set_nt_page(2, ROM, m0 | 0x80, 0);   //(m0 << 10) + M68_OFFSET);
4153         set_nt_page(3, ROM, m1 | 0x80, 0);   //(m1 << 10) + M68_OFFSET);
4547         set_nt_page(0, ROM, m0 | 0x80, 0);
4548         set_nt_page(1, ROM, m1 | 0x80, 0);
4549         set_nt_page(2, ROM, m0 | 0x80, 0);
4550         set_nt_page(3, ROM, m1 | 0x80, 0);
41544551         break;
41554552      case 0x11:
4156         set_nt_page(0, ROM, m0 | 0x80, 0);   //(m0 << 10) + M68_OFFSET);
4157         set_nt_page(1, ROM, m0 | 0x80, 0);   //(m0 << 10) + M68_OFFSET);
4158         set_nt_page(2, ROM, m1 | 0x80, 0);   //(m1 << 10) + M68_OFFSET);
4159         set_nt_page(3, ROM, m1 | 0x80, 0);   //(m1 << 10) + M68_OFFSET);
4553         set_nt_page(0, ROM, m0 | 0x80, 0);
4554         set_nt_page(1, ROM, m0 | 0x80, 0);
4555         set_nt_page(2, ROM, m1 | 0x80, 0);
4556         set_nt_page(3, ROM, m1 | 0x80, 0);
41604557         break;
41614558      case 0x12:
4162         set_nt_page(0, ROM, m0 | 0x80, 0);   //(m0 << 10) + M68_OFFSET);
4163         set_nt_page(1, ROM, m0 | 0x80, 0);   //(m0 << 10) + M68_OFFSET);
4164         set_nt_page(2, ROM, m0 | 0x80, 0);   //(m0 << 10) + M68_OFFSET);
4165         set_nt_page(3, ROM, m0 | 0x80, 0);   //(m0 << 10) + M68_OFFSET);
4559         set_nt_page(0, ROM, m0 | 0x80, 0);
4560         set_nt_page(1, ROM, m0 | 0x80, 0);
4561         set_nt_page(2, ROM, m0 | 0x80, 0);
4562         set_nt_page(3, ROM, m0 | 0x80, 0);
41664563         break;
41674564      case 0x13:
4168         set_nt_page(0, ROM, m1 | 0x80, 0);   //(m1 << 10) + M68_OFFSET);
4169         set_nt_page(1, ROM, m1 | 0x80, 0);   //(m1 << 10) + M68_OFFSET);
4170         set_nt_page(2, ROM, m1 | 0x80, 0);   //(m1 << 10) + M68_OFFSET);
4171         set_nt_page(3, ROM, m1 | 0x80, 0);   //(m1 << 10) + M68_OFFSET);
4565         set_nt_page(0, ROM, m1 | 0x80, 0);
4566         set_nt_page(1, ROM, m1 | 0x80, 0);
4567         set_nt_page(2, ROM, m1 | 0x80, 0);
4568         set_nt_page(3, ROM, m1 | 0x80, 0);
41724569         break;
41734570   }
41744571}
41754572
41764573static WRITE8_HANDLER( mapper68_w )
41774574{
4178   static int m68_mirror;
4179   static int m0, m1;
4180
41814575   LOG_MMC(("mapper68_w, offset %04x, data: %02x\n", offset, data));
41824576
41834577   switch (offset & 0x7000)
41844578   {
41854579      case 0x0000:
4186         /* Switch 2k VROM at $0000 */
41874580         chr2_0(space->machine, data, CHRROM);
41884581         break;
41894582      case 0x1000:
4190         /* Switch 2k VROM at $0800 */
41914583         chr2_2(space->machine, data, CHRROM);
41924584         break;
41934585      case 0x2000:
4194         /* Switch 2k VROM at $1000 */
41954586         chr2_4(space->machine, data, CHRROM);
41964587         break;
41974588      case 0x3000:
4198         /* Switch 2k VROM at $1800 */
41994589         chr2_6(space->machine, data, CHRROM);
42004590         break;
42014591      case 0x4000:
r5997r5998
42254615
42264616    Known Boards: JLROM, JSROM, Sunsoft 5B, Sunsoft FME7 and
42274617         Custom
4228    Games: Barcode World, Batman - Return of the Joker, Gimmick!,
4229          Splatter House - Wanpaku Graffiti
4618    Games: Barcode World, Batman - Return of the Joker, Gimmick!
42304619
42314620    In MESS: Supported.
42324621
42334622*************************************************************/
42344623
4235/* should this be used for Mapper 67 as well?!? */
4236static void sunsoft_irq( const device_config *device, int scanline, int vblank, int blanked )
4624/* Here, IRQ counter decrements every CPU cycle. Since we update it every scanline,
4625we need to decrement it by 114 (Each scanline consists of 341 dots and, on NTSC,
4626there are 3 dots to every 1 CPU cycle, hence 114 is the number of cycles per scanline ) */
4627static void mapper69_irq( const device_config *device, int scanline, int vblank, int blanked )
42374628{
4238   /* 114 is the number of cycles per scanline */
42394629   /* TODO: change to reflect the actual number of cycles spent */
4240
4241   if (IRQ_enable)
4630   if ((IRQ_enable & 0x80) && (IRQ_enable & 0x01))
42424631   {
42434632      if (IRQ_count <= 114)
42444633      {
4634         IRQ_count = 0xffff;
42454635         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
42464636      }
4247      IRQ_count -= 114;
4637      else
4638         IRQ_count -= 114;
42484639   }
4640   else if (IRQ_enable & 0x01)   // if enable bit is not set, only decrement the counter!
4641   {
4642      if (IRQ_count <= 114)
4643         IRQ_count = 0xffff;
4644      else
4645         IRQ_count -= 114;
4646   }
42494647}
42504648
42514649static WRITE8_HANDLER( mapper69_w )
42524650{
4253   static int cmd = 0;
42544651   LOG_MMC(("mapper69_w, offset %04x, data: %02x\n", offset, data));
42554652
4256   switch (offset & 0x7000)
4653   switch (offset & 0x6000)
42574654   {
42584655      case 0x0000:
4259         cmd = data & 0x0f;
4656         mmc_cmd1 = data & 0x0f;
42604657         break;
42614658
42624659      case 0x2000:
4263         switch (cmd)
4660         switch (mmc_cmd1)
42644661         {
42654662            case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
4266               chr1_x(space->machine, cmd, data, CHRROM);
4267               //ppu2c0x_set_videorom_bank(state->ppu, cmd, 1, data, 64);
4663               chr1_x(space->machine, mmc_cmd1, data, CHRROM);
42684664               break;
42694665
4270            /* TODO: deal with bankswitching/write-protecting the mid-mapper area */
4666            /* TODO: deal properly with bankswitching/write-protecting the mid-mapper area */
42714667            case 8:
4272#if 0
42734668               if (!(data & 0x40))
4274               {
4275                  memory_set_bankptr(space->machine, 5, &nes.rom[(data & 0x3f) * 0x2000 + 0x10000]);
4276               }
4277               else
4278#endif
4279                  LOG_MMC(("mapper69_w, cmd 8, data: %02x\n", data));
4669                  prg8_67(space->machine, data & 0x3f);
4670               else if (data & 0x80)
4671                  memory_set_bankptr(space->machine, 5, &nes.wram[(data & 0x3f) * 0x2000]);
42804672               break;
42814673
42824674            case 9:
42834675               prg8_89(space->machine, data);
42844676               break;
4285            case 10:
4677            case 0x0a:
42864678               prg8_ab(space->machine, data);
42874679               break;
4288            case 11:
4680            case 0x0b:
42894681               prg8_cd(space->machine, data);
42904682               break;
4291            case 12:
4683            case 0x0c:
42924684               switch (data & 0x03)
42934685               {
42944686                  case 0x00: set_nt_mirroring(PPU_MIRROR_VERT); break;
r5997r5998
42974689                  case 0x03: set_nt_mirroring(PPU_MIRROR_HIGH); break;
42984690               }
42994691               break;
4300            case 13:
4692            case 0x0d:
43014693               IRQ_enable = data;
43024694               break;
4303            case 14:
4695            case 0x0e:
43044696               IRQ_count = (IRQ_count & 0xff00) | data;
43054697               break;
4306            case 15:
4698            case 0x0f:
43074699               IRQ_count = (IRQ_count & 0x00ff) | (data << 8);
43084700               break;
43094701         }
43104702         break;
43114703
4704      /* Here we would have sound command for Sunsoft 5b variant */
4705//      case 0x4000:
4706//      case 0x6000:
4707
43124708      default:
43134709         logerror("mapper69_w uncaught %04x value: %02x\n", offset + 0x8000, data);
43144710         break;
r5997r5998
44734869
44744870static void mapper74_set_chr( running_machine *machine, int chr_base, int chr_mask )
44754871{
4476   UINT8 chr_page = (MMC3_cmd & 0x80) >> 5;
4872   UINT8 chr_page = (mmc_cmd1 & 0x80) >> 5;
44774873   UINT8 chr_src[6];
44784874   int i;
44794875
r5997r5998
44984894   switch (offset & 0x6001)
44994895   {
45004896   case 0x0000:
4501      MMC3_helper = MMC3_cmd ^ data;
4502      MMC3_cmd = data;
4897      MMC3_helper = mmc_cmd1 ^ data;
4898      mmc_cmd1 = data;
45034899
45044900      /* Has PRG Mode changed? */
45054901      if (MMC3_helper & 0x40)
r5997r5998
45114907      break;
45124908
45134909   case 0x0001:
4514      cmd = MMC3_cmd & 0x07;
4910      cmd = mmc_cmd1 & 0x07;
45154911      switch (cmd)
45164912      {
4517      case 0: case 1:   // these do not need to be separated because we shift banks in set_chr!
4913      case 0: case 1:   // these do not need to be separated: we take care of them in set_chr!
45184914      case 2: case 3: case 4: case 5:
45194915         vrom_bank[cmd] = data;
45204916         mapper74_set_chr(space->machine, mmc_chr_base, mmc_chr_mask);
r5997r5998
46355031    Known Boards: Irem LROG017
46365032    Games: Napoleon Senki
46375033
4638    In MESS: Supported.
5034    In MESS: Partially Supported (it needs 4-screen mirroring).
46395035
46405036*************************************************************/
46415037
r5997r5998
46555051    Games: Holy Diver, Portopia Renzoku Satsujin Jiken,
46565052          Uchuusen - Cosmo Carrier
46575053
4658    In MESS: Partially Supported.
5054    A crc check is required to support Cosmo Carrier (which uses
5055    a slightly different board)
46595056
5057    In MESS: Supported.
5058
46605059*************************************************************/
46615060
46625061static WRITE8_HANDLER( mapper78_w )
46635062{
46645063   LOG_MMC(("mapper78_w, offset: %04x, data: %02x\n", offset, data));
4665   /* Switch 8k VROM bank */
5064
5065   if (nes.crc_hack)      // Jaleco JF16 board has different mirroring even if uses same mapper number :(
5066      set_nt_mirroring((data & 0x08) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
5067   else
5068      set_nt_mirroring((data & 0x08) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
5069
46665070   chr8(space->machine, (data & 0xf0) >> 4, CHRROM);
4667
4668   /* Switch 16k ROM bank */
4669   prg16_89ab(space->machine, data & 0x0f);
5071   prg16_89ab(space->machine, data & 0x07);
46705072}
46715073
46725074/*************************************************************
r5997r5998
47155117   switch (offset)
47165118   {
47175119      case 0x1ef0:
4718         /* Switch 2k VROM at $0000 */
47195120         chr2_0(space->machine, (data & 0x7f) >> 1, CHRROM);
47205121         break;
47215122      case 0x1ef1:
4722         /* Switch 2k VROM at $0000 */
47235123         chr2_2(space->machine, (data & 0x7f) >> 1, CHRROM);
47245124         break;
47255125      case 0x1ef2:
4726         /* Switch 1k VROM at $1000 */
47275126         chr1_4(space->machine, data, CHRROM);
47285127         break;
47295128      case 0x1ef3:
4730         /* Switch 1k VROM at $1400 */
47315129         chr1_5(space->machine, data, CHRROM);
47325130         break;
47335131      case 0x1ef4:
4734         /* Switch 1k VROM at $1800 */
47355132         chr1_6(space->machine, data, CHRROM);
47365133         break;
47375134      case 0x1ef5:
4738         /* Switch 1k VROM at $1c00 */
47395135         chr1_7(space->machine, data, CHRROM);
47405136         break;
47415137      case 0x1ef6:
r5997r5998
47435139         break;
47445140      case 0x1efa:
47455141      case 0x1efb:
4746         /* Switch 8k ROM at $8000 */
47475142         prg8_89(space->machine, data);
47485143         break;
47495144      case 0x1efc:
47505145      case 0x1efd:
4751         /* Switch 8k ROM at $a000 */
47525146         prg8_ab(space->machine, data);
47535147         break;
47545148      case 0x1efe:
47555149      case 0x1eff:
4756         /* Switch 8k ROM at $c000 */
47575150         prg8_cd(space->machine, data);
47585151         break;
47595152      default:
r5997r5998
47775170
47785171    Mapper 82
47795172
4780    Known Boards: Taito X1017
5173    Known Boards: Taito X1-017
47815174    Games: Kyuukyoku Harikiri Koushien, Kyuukyoku Harikiri
47825175          Stadium, SD Keiji - Blader
47835176
r5997r5998
47875180
47885181static WRITE8_HANDLER( mapper82_m_w )
47895182{
4790   static int vrom_switch;
4791
4792   /* This mapper has problems */
4793
47945183   LOG_MMC(("mapper82_m_w, offset: %04x, data: %02x\n", offset, data));
47955184
47965185   switch (offset)
47975186   {
47985187      case 0x1ef0:
4799         if (vrom_switch)
4800            chr2_4(space->machine, data, CHRROM);
5188         if (mmc_cmd1)
5189            chr2_4(space->machine, data >> 1, CHRROM);
48015190         else
4802            chr2_0(space->machine, data, CHRROM);
5191            chr2_0(space->machine, data >> 1, CHRROM);
48035192         break;
48045193      case 0x1ef1:
4805         if (vrom_switch)
5194         if (mmc_cmd1)
48065195            chr2_6(space->machine, data, CHRROM);
48075196         else
48085197            chr2_2(space->machine, data, CHRROM);
48095198         break;
48105199      case 0x1ef2:
4811         chr1_x(space->machine, 4 ^ vrom_switch, data, CHRROM);
5200         chr1_x(space->machine, 4 ^ mmc_cmd1, data, CHRROM);
48125201         break;
48135202      case 0x1ef3:
4814         chr1_x(space->machine, 5 ^ vrom_switch, data, CHRROM);
5203         chr1_x(space->machine, 5 ^ mmc_cmd1, data, CHRROM);
48155204         break;
48165205      case 0x1ef4:
4817         chr1_x(space->machine, 6 ^ vrom_switch, data, CHRROM);
5206         chr1_x(space->machine, 6 ^ mmc_cmd1, data, CHRROM);
48185207         break;
48195208      case 0x1ef5:
4820         chr1_x(space->machine, 7 ^ vrom_switch, data, CHRROM);
5209         chr1_x(space->machine, 7 ^ mmc_cmd1, data, CHRROM);
48215210         break;
48225211      case 0x1ef6:
4823         set_nt_mirroring((data & 0x1) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
4824         //doc says 1= swapped. Causes in-game issues, but mostly fixes title screen
4825         vrom_switch = ((data & 0x02) << 1);
5212         set_nt_mirroring((data & 0x01) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
5213         mmc_cmd1 = ((data & 0x02) << 1);
48265214         break;
48275215
48285216      case 0x1efa:
r5997r5998
49755363   switch (offset & 0x7018)
49765364   {
49775365      case 0x0000:
4978         /* Switch 8k bank at $8000 */
49795366         prg8_89(space->machine, data);
49805367         break;
49815368      case 0x0008:
49825369      case 0x0010:
49835370      case 0x0018:
4984         /* Switch 8k bank at $a000 */
49855371         prg8_ab(space->machine, data);
49865372         break;
49875373
49885374      case 0x1000:
4989         /* Switch 8k bank at $c000 */
49905375         prg8_cd(space->machine, data);
49915376         break;
49925377
r5997r5998
50255410         IRQ_count_latch = data;
50265411         break;
50275412      case 0x7000:
5413         IRQ_mode = data & 0x04;   // currently not implemented: 0 = prescaler mode / 1 = CPU mode
50285414         IRQ_enable = data & 0x02;
50295415         IRQ_enable_latch = data & 0x01;
50305416         if (data & 0x02)
r5997r5998
51605546    Games: Mortal Kombat II, Street Fighter III, Super Mario
51615547          Kart Rider
51625548
5163    In MESS: Partially supported.
5549    This board uses an IRQ system very similar to MMC3. We indeed
5550    use mapper4_irq, but there is some small glitch!
51645551
5552    In MESS: Supported.
5553
51655554*************************************************************/
51665555
51675556static WRITE8_HANDLER( mapper91_m_w )
51685557{
51695558   LOG_MMC(("mapper91_m_w, offset: %04x, data: %02x\n", offset, data));
51705559
5171   switch (offset & 0x7000)
5560   switch (offset & 0x1000)
51725561   {
51735562      case 0x0000:
51745563         switch (offset & 0x03)
r5997r5998
51805569         }
51815570         break;
51825571      case 0x1000:
5183         switch (offset & 0x01)
5572         switch (offset & 0x03)
51845573         {
51855574            case 0x00: prg8_89(space->machine, data); break;
51865575            case 0x01: prg8_ab(space->machine, data); break;
5576            case 0x02: IRQ_enable = 0; IRQ_count = 0; break;
5577            case 0x03: IRQ_enable = 1; IRQ_count = 7; break;
51875578         }
51885579         break;
51895580      default:
r5997r5998
54875878    Known Boards: Unknown Bootleg Board
54885879    Games: Super Mario Bros. 3 Pirate
54895880
5490    In MESS: Unsupported.
5881    In MESS: Supported.
54915882
54925883*************************************************************/
54935884
5885static void mapper106_irq( const device_config *device, int scanline, int vblank, int blanked )
5886{
5887   if (IRQ_enable)
5888   {
5889      if ((0xffff - IRQ_count) < 114)
5890      {
5891         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
5892         IRQ_enable = 0;
5893      }
5894
5895      IRQ_count = (IRQ_count + 114) & 0xffff;
5896   }
5897}
5898
5899static WRITE8_HANDLER( mapper106_w )
5900{
5901   LOG_MMC(("mapper106_w, offset: %04x, data: %02x\n", offset, data));
5902   switch (offset & 0x0f)
5903   {
5904   case 0x00:
5905   case 0x02:
5906      chr1_x(space->machine, offset & 0x07, data & 0xfe, CHRROM);
5907      break;
5908   case 0x01:
5909   case 0x03:
5910      chr1_x(space->machine, offset & 0x07, data | 0x01, CHRROM);
5911      break;
5912   case 0x04: case 0x05:
5913   case 0x06: case 0x07:
5914      chr1_x(space->machine, offset & 0x07, data, CHRROM);
5915      break;
5916   case 0x08:
5917      prg8_89(space->machine, data | 0x10);
5918      break;
5919   case 0x09:
5920      prg8_ab(space->machine, data);
5921      break;
5922   case 0x0a:
5923      prg8_cd(space->machine, data);
5924      break;
5925   case 0x0b:
5926      prg8_ef(space->machine, data | 0x10);
5927      break;
5928   case 0x0c:
5929      set_nt_mirroring((data & 0x01) ?  PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
5930      break;
5931   case 0x0d:
5932      IRQ_count = 0;
5933      IRQ_enable = 0;
5934      break;
5935   case 0x0e:
5936      IRQ_count = (IRQ_count & 0xff00) | data;
5937      break;
5938   case 0x0f:
5939      IRQ_count = (IRQ_count & 0x00ff) | (data << 8);
5940      IRQ_enable = 1;
5941      break;
5942   }
5943}
5944
54945945/*************************************************************
54955946
54965947    Mapper 107
r5997r5998
56406091
56416092   if (!(offset & 0x100))
56426093   {
5643      prg32(space->machine, data >> 3);
5644      chr8(space->machine, data & 0x07, CHRROM);
6094      prg32(space->machine, (data & 0x38) >> 3);
6095      chr8(space->machine, (data & 0x07) | ((data & 0x40) >> 3), CHRROM);
6096      if (nes.crc_hack)   // this breaks AV Soccer but it is needed by HES 6-in-1!
6097         set_nt_mirroring((data & 0x80) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
56456098   }
56466099}
56476100
r5997r5998
57266179
57276180    MMC3 clone
57286181
5729    In MESS: Partally Supported
6182    In MESS: Supported
57306183
57316184*************************************************************/
57326185
5733static void mapper115_set_prg( running_machine *machine )
6186static void mapper115_set_prg( running_machine *machine, int prg_base, int prg_mask )
57346187{
5735   if (mapper115_reg[3] & 0x80)
5736   {
5737      prg16_89ab(machine, mapper115_reg[3] & 0x0f);
5738   }
6188   if (mapper115_reg[0] & 0x80)
6189      prg32(machine, mapper115_reg[0] >> 1);
57396190   else
5740   {
5741      prg8_89(machine, mapper115_reg[1] & 0x1f);
5742      prg8_ab(machine, mapper115_reg[2] & 0x1f);
5743   }
6191      mapper4_set_prg(machine, prg_base, prg_mask);
57446192}
57456193
57466194static WRITE8_HANDLER( mapper115_m_w )
57476195{
57486196   LOG_MMC(("mapper115_m_w, offset: %04x, data: %02x\n", offset, data));
57496197
5750   mapper115_reg[3] = data;
5751   mapper115_set_prg(space->machine);
6198   switch (offset & 0x01)
6199   {
6200   case 0x00:
6201      mapper115_reg[0] = data;
6202      mapper115_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
6203      break;
6204   case 0x01:
6205      mmc_chr_base = (data & 0x01) ? 0x100 : 0x000;
6206      mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
6207      break;
6208   }
57526209}
57536210
57546211static WRITE8_HANDLER( mapper115_w )
57556212{
6213   UINT8 map115_helper, cmd;
57566214   LOG_MMC(("mapper115_w, offset: %04x, data: %02x\n", offset, data));
57576215
5758   switch (offset & 0x7001)
6216   switch (offset & 0x6001)
57596217   {
5760   case 0x0000:
5761      mapper115_reg[0] = data;
5762      break;
5763   case 0x0001:
5764      switch (mapper115_reg[0] & 0x07)
5765      {
5766      case 0:
5767         chr2_0(space->machine, data >> 1, CHRROM);
6218      case 0x0000:
6219         map115_helper = mmc_cmd1 ^ data;
6220         mmc_cmd1 = data;
6221
6222         /* Has PRG Mode changed? */
6223         if (map115_helper & 0x40)
6224            mapper115_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
6225
6226         /* Has CHR Mode changed? */
6227         if (map115_helper & 0x80)
6228            mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
57686229         break;
5769      case 1:
5770         chr2_2(space->machine, data >> 1, CHRROM);
6230
6231      case 0x0001:
6232         cmd = mmc_cmd1 & 0x07;
6233         switch (cmd)
6234         {
6235            case 0: case 1:   // these do not need to be separated: we take care of them in set_chr!
6236            case 2: case 3: case 4: case 5:
6237               vrom_bank[cmd] = data;
6238               mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
6239               break;
6240            case 6:
6241            case 7:
6242               prg_bank[cmd - 6] = data;
6243               mapper115_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
6244               break;
6245         }
57716246         break;
5772      case 2:
5773         chr1_4(space->machine, data, CHRROM);
6247
6248      default:
6249         mapper4_w(space, offset, data);
57746250         break;
5775      case 3:
5776         chr1_5(space->machine, data, CHRROM);
5777         break;
5778      case 4:
5779         chr1_6(space->machine, data, CHRROM);
5780         break;
5781      case 5:
5782         chr1_7(space->machine, data, CHRROM);
5783         break;
5784      case 6:
5785         mapper115_reg[1] = data;
5786         mapper115_set_prg(space->machine);
5787         break;
5788      case 7:
5789         mapper115_reg[2] = data;
5790         mapper115_set_prg(space->machine);
5791         break;
5792      }
5793      break;
5794   case 0x2000:
5795      set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
5796      break;
5797   case 0x4000:
5798      IRQ_count_latch = data;
5799      break;
5800   case 0x4001:
5801      IRQ_count = IRQ_count_latch;
5802      break;
5803   case 0x6000:
5804      IRQ_enable = 0;
5805      break;
5806   case 0x6001:
5807      IRQ_enable = 1;
5808      break;
58096251   }
58106252}
58116253
5812static void mapper115_irq( const device_config *device, int scanline, int vblank, int blanked )
5813{
5814   if ((scanline < PPU_BOTTOM_VISIBLE_SCANLINE) /*|| (scanline == ppu_scanlines_per_frame-1)*/)
5815   {
5816      int priorCount = IRQ_count;
5817      if ((IRQ_count == 0) || IRQ_reload)
5818      {
5819         IRQ_count = IRQ_count_latch;
5820         IRQ_reload = 0;
5821      }
5822      else
5823         IRQ_count --;
5824
5825      if (IRQ_enable && !blanked && (IRQ_count == 0) && priorCount)
5826      {
5827         LOG_MMC(("irq fired, scanline: %d (MAME %d, beam pos: %d)\n", scanline,
5828               video_screen_get_vpos(device->machine->primary_screen), video_screen_get_hpos(device->machine->primary_screen)));
5829         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
5830      }
5831   }
5832}
5833
58346254/*************************************************************
58356255
58366256    Mapper 116
r5997r5998
58536273
58546274*************************************************************/
58556275
6276static void mapper117_irq( const device_config *device, int scanline, int vblank, int blanked )
6277{
6278//  if (scanline < PPU_BOTTOM_VISIBLE_SCANLINE)
6279   {
6280      if (IRQ_enable && IRQ_count)
6281      {
6282         IRQ_count--;
6283         if (!IRQ_count)
6284            cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
6285      }
6286   }
6287}
6288
6289static WRITE8_HANDLER( mapper117_w )
6290{
6291   LOG_MMC(("mapper117_w, offset: %04x, data: %02x\n", offset, data));
6292
6293   switch (offset)
6294   {
6295   case 0x0000:
6296      prg8_89(space->machine, data);
6297      break;
6298   case 0x0001:
6299      prg8_ab(space->machine, data);
6300      break;
6301   case 0x0002:
6302      prg8_cd(space->machine, data);
6303      break;
6304   case 0x0003:
6305      prg8_ef(space->machine, data);
6306      break;
6307   case 0x2000:
6308   case 0x2001:
6309   case 0x2002:
6310   case 0x2003:
6311   case 0x2004:
6312   case 0x2005:
6313   case 0x2006:
6314   case 0x2007:
6315      chr1_x(space->machine, offset & 0x07, data, CHRROM);
6316      break;
6317
6318   case 0x5000:
6319      set_nt_mirroring((data & 0x01) ?  PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
6320      break;
6321
6322   case 0x4001:
6323      IRQ_count_latch = data;
6324      break;
6325   case 0x4002:
6326      // IRQ cleared
6327      break;
6328   case 0x4003:
6329      IRQ_count = IRQ_count_latch;
6330      break;
6331   case 0x6000:
6332      IRQ_enable = data & 0x01;
6333      break;
6334   }
6335}
6336
58566337/*************************************************************
58576338
58586339    Mapper 118
r5997r5998
58656346
58666347*************************************************************/
58676348
6349static void mapper118_set_mirror( void )
6350{
6351   if (mmc_cmd1 & 0x80)
6352   {
6353      set_nt_page(0, CIRAM, (vrom_bank[2] & 0x80) >> 7, 1);
6354      set_nt_page(1, CIRAM, (vrom_bank[3] & 0x80) >> 7, 1);
6355      set_nt_page(2, CIRAM, (vrom_bank[4] & 0x80) >> 7, 1);
6356      set_nt_page(3, CIRAM, (vrom_bank[5] & 0x80) >> 7, 1);
6357   }
6358   else
6359   {
6360      set_nt_page(0, CIRAM, (vrom_bank[0] & 0x80) >> 7, 1);
6361      set_nt_page(1, CIRAM, (vrom_bank[0] & 0x80) >> 7, 1);
6362      set_nt_page(2, CIRAM, (vrom_bank[1] & 0x80) >> 7, 1);
6363      set_nt_page(3, CIRAM, (vrom_bank[1] & 0x80) >> 7, 1);
6364   }
6365}
6366
58686367static WRITE8_HANDLER( mapper118_w )
58696368{
6369   UINT8 MMC3_helper, cmd;
58706370   LOG_MMC(("mapper118_w, offset: %04x, data: %02x\n", offset, data));
58716371
58726372   switch (offset & 0x6001)
58736373   {
5874      case 0x2000: /* $a000 */
5875         LOG_MMC(("     mapper 118 mirroring: %02x\n", data));
5876         switch (data & 0x02)
6374      case 0x0000:
6375         MMC3_helper = mmc_cmd1 ^ data;
6376         mmc_cmd1 = data;
6377
6378         /* Has PRG Mode changed? */
6379         if (MMC3_helper & 0x40)
6380            mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
6381
6382         /* Has CHR Mode changed? */
6383         if (MMC3_helper & 0x80)
58776384         {
5878            case 0x00: set_nt_mirroring(PPU_MIRROR_LOW); break;
5879            case 0x01: set_nt_mirroring(PPU_MIRROR_LOW); break;
6385            mapper118_set_mirror();
6386            mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
58806387         }
58816388         break;
58826389
5883      case 0x4000: /* $c000 - IRQ scanline counter */
5884         IRQ_count = data;
6390      case 0x0001:
6391         cmd = mmc_cmd1 & 0x07;
6392         switch (cmd)
6393         {
6394            case 0: case 1:
6395            case 2: case 3: case 4: case 5:
6396               vrom_bank[cmd] = data;
6397               mapper118_set_mirror();
6398               mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
6399               break;
6400            case 6:
6401            case 7:
6402               prg_bank[cmd - 6] = data;
6403               mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
6404               break;
6405         }
58856406         break;
58866407
5887      case 0x4001: /* $c001 - IRQ scanline latch */
5888         IRQ_count_latch = data;
6408      case 0x2000:
58896409         break;
58906410
58916411      default:
r5997r5998
59076427
59086428static void mapper119_set_chr( running_machine *machine )
59096429{
5910   UINT8 chr_page = (MMC3_cmd & 0x80) >> 5;
6430   UINT8 chr_page = (mmc_cmd1 & 0x80) >> 5;
6431   UINT8 chr_src[6], chr_mask[6];
6432   int i;
59116433
5912   if (vrom_bank[0] & 0x40)
5913      chr2_x(machine, chr_page ^ 0, (vrom_bank[0] >> 1) & 0x03, CHRRAM);
5914   else
5915      chr2_x(machine, chr_page ^ 0, ((vrom_bank[0] & 0x3f) >> 1), CHRROM);
6434   for (i = 0; i < 6; i++)
6435   {
6436      chr_src[i] = (vrom_bank[i] & 0x40) ? CHRRAM : CHRROM;
6437      chr_mask[i] =  (vrom_bank[i] & 0x40) ? 0x07 : 0x3f;
6438   }
59166439
5917   if (vrom_bank[1] & 0x40)
5918      chr2_x(machine, chr_page ^ 2, (vrom_bank[1] >> 1) & 0x03, CHRRAM);
5919   else
5920      chr2_x(machine, chr_page ^ 2, ((vrom_bank[1] & 0x3f) >> 1), CHRROM);
5921
5922   if (vrom_bank[2] & 0x40)
5923      chr1_x(machine, chr_page ^ 4, vrom_bank[2] & 0x07, CHRRAM);
5924   else
5925      chr1_x(machine, chr_page ^ 4, vrom_bank[2] & 0x3f, CHRROM);
5926
5927   if (vrom_bank[3] & 0x40)
5928      chr1_x(machine, chr_page ^ 5, vrom_bank[3] & 0x07, CHRRAM);
5929   else
5930      chr1_x(machine, chr_page ^ 5, vrom_bank[3] & 0x3f, CHRROM);
5931
5932   if (vrom_bank[4] & 0x40)
5933      chr1_x(machine, chr_page ^ 6, vrom_bank[4] & 0x07, CHRRAM);
5934   else
5935      chr1_x(machine, chr_page ^ 6, vrom_bank[4] & 0x3f, CHRROM);
5936
5937   if (vrom_bank[5] & 0x40)
5938      chr1_x(machine, chr_page ^ 7, vrom_bank[5] & 0x07, CHRRAM);
5939   else
5940      chr1_x(machine, chr_page ^ 7, vrom_bank[5] & 0x3f, CHRROM);
6440   chr1_x(machine, chr_page ^ 0, ((vrom_bank[0] & ~0x01) & chr_mask[0]), chr_src[0]);
6441   chr1_x(machine, chr_page ^ 1, ((vrom_bank[0] |  0x01) & chr_mask[0]), chr_src[0]);
6442   chr1_x(machine, chr_page ^ 2, ((vrom_bank[1] & ~0x01) & chr_mask[1]), chr_src[1]);
6443   chr1_x(machine, chr_page ^ 3, ((vrom_bank[1] |  0x01) & chr_mask[1]), chr_src[1]);
6444   chr1_x(machine, chr_page ^ 4, (vrom_bank[2] & chr_mask[2]), chr_src[2]);
6445   chr1_x(machine, chr_page ^ 5, (vrom_bank[3] & chr_mask[3]), chr_src[3]);
6446   chr1_x(machine, chr_page ^ 6, (vrom_bank[4] & chr_mask[4]), chr_src[4]);
6447   chr1_x(machine, chr_page ^ 7, (vrom_bank[5] & chr_mask[5]), chr_src[5]);
59416448}
59426449
59436450static WRITE8_HANDLER( mapper119_w )
59446451{
5945   static UINT8 last_bank = 0xff;
6452   UINT8 MMC3_helper, cmd;
59466453   LOG_MMC(("mapper119_w, offset: %04x, data: %02x\n", offset, data));
59476454
59486455   switch (offset & 0x6001)
59496456   {
5950      case 0x0000: /* $8000 */
5951         MMC3_cmd = data;
6457      case 0x0000:
6458         MMC3_helper = mmc_cmd1 ^ data;
6459         mmc_cmd1 = data;
59526460
5953         /* Toggle between switching $8000 and $c000 */
5954         if (last_bank != (data & 0xc0))
5955         {
5956            /* Reset the banks */
6461         /* Has PRG Mode changed? */
6462         if (MMC3_helper & 0x40)
59576463            mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
6464
6465         /* Has CHR Mode changed? */
6466         if (MMC3_helper & 0x80)
59586467            mapper119_set_chr(space->machine);
5959            LOG_MMC(("     MMC3 reset banks\n"));
5960         }
5961         last_bank = data & 0xc0;
59626468         break;
5963
59646469      case 0x0001: /* $8001 */
5965      {
5966         UINT8 cmd = MMC3_cmd & 0x07;
6470         cmd = mmc_cmd1 & 0x07;
59676471         switch (cmd)
59686472         {
5969            case 0: case 1:   // these do not need to be separated because we shift banks in set_chr!
6473            case 0: case 1:   // these do not need to be separated: we take care of them in set_chr!
59706474            case 2: case 3: case 4: case 5:
59716475               vrom_bank[cmd] = data;
59726476               mapper119_set_chr(space->machine);
r5997r5998
59786482               break;
59796483         }
59806484         break;
5981      }
6485
59826486      default:
59836487         mapper4_w(space, offset, data);
59846488         break;
r5997r5998
60056509
60066510    MMC3 clone
60076511
6008    In MESS: Unsupported.
6512    In MESS: Supported.
60096513
60106514*************************************************************/
60116515
6516static WRITE8_HANDLER( mapper121_l_w )
6517{
6518   LOG_MMC(("mapper12_l_w, offset: %04x, data: %02x\n", offset, data));
6519   offset += 0x100;
6520
6521   if (!(offset < 0x1000))
6522   {
6523      switch (data & 0x03)
6524      {
6525      case 0x00:
6526      case 0x03:
6527         mapper121_reg[2] = 0x00;
6528         break;
6529      case 0x01:
6530         mapper121_reg[2] = 0x83;
6531         break;
6532      case 0x02:
6533         mapper121_reg[2] = 0x42;
6534         break;
6535      }
6536   }
6537}
6538
6539static READ8_HANDLER( mapper121_l_r )
6540{
6541   LOG_MMC(("mapper12_l_r, offset: %04x\n", offset));
6542   offset += 0x100;
6543
6544   if (!(offset < 0x1000))
6545      return mapper121_reg[2];
6546   else
6547      return 0;
6548}
6549
6550static void mapper121_set_prg( running_machine *machine, int prg_base, int prg_mask )
6551{
6552   UINT8 prg_flip = (mmc_cmd1 & 0x40) ? 2 : 0;
6553   UINT8 new_bank2, new_bank3;
6554
6555   new_bank2 = mapper121_reg[0] ? mapper121_reg[0] : prg_bank[2 ^ prg_flip];
6556   new_bank3 = mapper121_reg[1] ? mapper121_reg[1] : prg_bank[3];
6557
6558   prg8_89(machine, prg_base | (prg_bank[0 ^ prg_flip] & prg_mask));
6559   prg8_ab(machine, prg_base | (prg_bank[1] & prg_mask));
6560   prg8_cd(machine, prg_base | (new_bank2 & prg_mask));
6561   prg8_ef(machine, prg_base | (new_bank3 & prg_mask));
6562}
6563
6564static WRITE8_HANDLER( mapper121_w )
6565{
6566   UINT8 MMC3_helper, cmd;
6567   LOG_MMC(("mapper121_w, offset: %04x, data: %02x\n", offset, data));
6568
6569   if ((offset < 0x2000) && (offset & 0x03) == 0x03)
6570   {
6571      switch (data)
6572      {
6573      case 0x20:
6574         mapper121_reg[1] = 0x13;
6575         break;
6576      case 0x26:
6577         mapper121_reg[1] = 0x08;
6578         break;
6579      case 0x28:
6580         mapper121_reg[0] = 0x0c;
6581         break;
6582      case 0x29:
6583         mapper121_reg[1] = 0x1b;
6584         break;
6585      case 0xab:
6586         mapper121_reg[1] = 0x07;
6587         break;
6588      case 0xec:
6589      case 0xef:
6590         mapper121_reg[1] = 0x0d;
6591         break;
6592      case 0xff:
6593         mapper121_reg[1] = 0x09;
6594         break;
6595      default:
6596         mapper121_reg[0] = 0x0;
6597         mapper121_reg[1] = 0x0;
6598         break;
6599      }
6600   }
6601   else
6602   {
6603      switch (offset & 0x6001)
6604      {
6605      case 0x0000:
6606         MMC3_helper = mmc_cmd1 ^ data;
6607         mmc_cmd1 = data;
6608
6609         /* Has PRG Mode changed? */
6610         if (MMC3_helper & 0x40)
6611            mapper121_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
6612
6613         /* Has CHR Mode changed? */
6614         if (MMC3_helper & 0x80)
6615            mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
6616         break;
6617
6618      case 0x0001:
6619         cmd = mmc_cmd1 & 0x07;
6620         switch (cmd)
6621         {
6622         case 0: case 1:
6623         case 2: case 3: case 4: case 5:
6624            vrom_bank[cmd] = data;
6625            mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
6626            break;
6627         case 6:
6628         case 7:
6629            prg_bank[cmd - 6] = data;
6630            mapper121_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
6631            break;
6632         }
6633         break;
6634
6635      default:
6636         mapper4_w(space, offset, data);
6637         break;
6638      }
6639   }
6640   mapper121_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
6641}
6642
60126643/*************************************************************
60136644
60146645    Mapper 122
r5997r5998
61836814{
61846815   LOG_MMC(("mapper133_l_w %04x:%02x\n", offset, data));
61856816
6186   if (offset == 0)
6187{
6188   prg32(space->machine, data >> 2);
6189   chr8(space->machine, data, CHRROM);}
6817   mapper133_l_w(space, offset & 0xff, data);   // offset does not really count for this mapper
61906818}
61916819
61926820/*************************************************************
r5997r5998
61946822    Mapper 134
61956823
61966824    Known Boards: Unknown Multigame Bootleg Board (4646B)
6197    Games: 2 in 1 - Family Camp & Aladdin 4
6825    Games: 2 in 1 - Family Kid & Aladdin 4
61986826
61996827    MMC3 clone
62006828
6201    In MESS: Unsupported.
6829    In MESS: Supported.
62026830
62036831*************************************************************/
62046832
6833static WRITE8_HANDLER( mapper134_m_w )
6834{
6835   LOG_MMC(("mapper134_m_w, offset: %04x, data: %02x\n", offset, data));
6836
6837   if (offset == 0x01)
6838   {
6839      mmc_prg_base = (data & 0x02) << 4;
6840      mmc_prg_mask = 0x1f;
6841      mmc_chr_base = (data & 0x20) << 3;
6842      mmc_chr_mask = 0xff;
6843      mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
6844      mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
6845   }
6846}
6847
62056848/*************************************************************
62066849
62076850    Mapper 135
r5997r5998
62836926{
62846927   LOG_MMC(("mapper137_l_w, offset: %04x, data: %02x\n", offset, data));
62856928
6286   /* write happens only if we are at 0x4100 + k * 0x200,
6287    but 0x4100 is offset = 0 */
6929   /* write happens only if we are at 0x4100 + k * 0x200, but 0x4100 is offset = 0 */
62886930   if (!(offset & 0x100))
62896931   {
62906932      if (!(offset & 0x01))
r5997r5998
63196961{
63206962   LOG_MMC(("mapper137_m_w, offset: %04x, data: %02x\n", offset, data));
63216963
6322   mapper137_l_w(space, offset + 0x100, data);
6964   mapper137_l_w(space, (offset + 0x100) & 0xfff, data);
63236965}
63246966
63256967/*************************************************************
r5997r5998
63386980   UINT8 bank_helper1 = 0, bank_helper2 = 0;
63396981   LOG_MMC(("mapper138_l_w, offset: %04x, data: %02x\n", offset, data));
63406982
6341   /* write happens only if we are at 0x4100 + k * 0x200,
6342    but 0x4100 is offset = 0 */
6983   /* write happens only if we are at 0x4100 + k * 0x200, but 0x4100 is offset = 0 */
63436984   if (!(offset & 0x100))
63446985   {
63456986      if (!(offset & 0x01))
r5997r5998
63767017{
63777018   LOG_MMC(("mapper138_m_w, offset: %04x, data: %02x\n", offset, data));
63787019
6379   mapper138_l_w(space, offset + 0x100, data);
7020   mapper138_l_w(space, (offset + 0x100) & 0xfff, data);
63807021}
63817022
63827023/*************************************************************
r5997r5998
63957036   UINT8 bank_helper1 = 0, bank_helper2 = 0;
63967037   LOG_MMC(("mapper139_l_w, offset: %04x, data: %02x\n", offset, data));
63977038
6398   /* write happens only if we are at 0x4100 + k * 0x200,
6399    but 0x4100 is offset = 0 */
7039   /* write happens only if we are at 0x4100 + k * 0x200, but 0x4100 is offset = 0 */
64007040   if (!(offset & 0x100))
64017041   {
64027042      if (!(offset & 0x01))
r5997r5998
64337073{
64347074   LOG_MMC(("mapper139_m_w, offset: %04x, data: %02x\n", offset, data));
64357075
6436   mapper139_l_w(space, offset + 0x100, data);
7076   mapper139_l_w(space, (offset + 0x100) & 0xfff, data);
64377077}
64387078
64397079/*************************************************************
r5997r5998
64727112   UINT8 bank_helper1 = 0, bank_helper2 = 0;
64737113   LOG_MMC(("mapper141_l_w, offset: %04x, data: %02x\n", offset, data));
64747114
6475   /* write happens only if we are at 0x4100 + k * 0x200,
6476    but 0x4100 is offset = 0 */
7115   /* write happens only if we are at 0x4100 + k * 0x200, but 0x4100 is offset = 0 */
64777116   if (!(offset & 0x100))
64787117   {
64797118      if (!(offset & 0x01))
r5997r5998
65107149{
65117150   LOG_MMC(("mapper141_m_w, offset: %04x, data: %02x\n", offset, data));
65127151
6513   mapper141_l_w(space, offset + 0x100, data);
7152   mapper141_l_w(space, (offset + 0x100) & 0xfff, data);
65147153}
65157154
65167155/*************************************************************
r5997r5998
65397178{
65407179   LOG_MMC(("mapper143_l_r, offset: %04x\n", offset));
65417180
6542   /* the address is read only if we are at 0x4100 + k * 0x200,
6543    but 0x4100 is offset = 0 */
7181   /* the address is read only if we are at 0x4100 + k * 0x200, but 0x4100 is offset = 0 */
65447182   if (!(offset & 0x100))
65457183      return (~offset & 0x3f) | 0x40;
65467184   else
r5997r5998
65687206   if ((offset & 0x7fff) == 0)
65697207      return;
65707208
6571   data = data |(memory_read_byte(space, offset) & 1);
7209   data = data | (memory_read_byte(space, offset) & 1);
65727210
65737211   chr8(space->machine, data >> 4, CHRROM);
65747212   prg32(space->machine, data & 0x07);
r5997r5998
66387276{
66397277   LOG_MMC(("mapper147_m_w, offset: %04x, data: %02x\n", offset, data));
66407278
6641   mapper147_l_w(space, offset + 0x100, data);
7279   mapper147_l_w(space, (offset + 0x100) & 0xfff, data);
66427280}
66437281
66447282static WRITE8_HANDLER( mapper147_w )
66457283{
66467284   LOG_MMC(("mapper147_w, offset: %04x, data: %02x\n", offset, data));
66477285
6648   mapper147_l_w(space, offset + 0x100, data);
7286   mapper147_l_w(space, (offset + 0x100) & 0xfff, data);
66497287}
66507288
66517289/*************************************************************
r5997r5998
67067344{
67077345   LOG_MMC(("mapper150_l_w, offset: %04x, data: %02x\n", offset, data));
67087346
6709   /* write happens only if we are at 0x4100 + k * 0x200,
6710    but 0x4100 is offset = 0 */
7347   /* write happens only if we are at 0x4100 + k * 0x200, but 0x4100 is offset = 0 */
67117348   if (!(offset & 0x100))
67127349   {
67137350      if (!(offset & 0x01))
r5997r5998
67577394{
67587395   LOG_MMC(("mapper150_m_w, offset: %04x, data: %02x\n", offset, data));
67597396
6760   mapper150_l_w(space, offset + 0x100, data);
7397   mapper150_l_w(space, (offset + 0x100) & 0xfff, data);
67617398}
67627399
67637400/*************************************************************
r5997r5998
68007437    Games: Dragon Ball, Dragon Ball 3, Famicom Jump, Famicom
68017438          Jump II
68027439
6803    In MESS: Unsupported.
7440    This mapper should be exactly like Mapper 16, but with
7441    SRAM in place of EEPROM. Hence, writes to 0x6000-0x7fff
7442    go to SRAM (not sure if there exist boards with no SRAM
7443    and no EEPROM... investigate!)
7444    Famicom Jump II uses a different board (or uses the same
7445    board in a very different way)
68047446
7447    In MESS: Supported.
7448
68057449*************************************************************/
68067450
7451static void mapper153_set_prg( running_machine *machine )
7452{
7453   UINT8 mmc_helper = 0;
7454   int i;
7455
7456   for (i = 0; i < 8; i++)
7457      mmc_helper |= ((map153_reg[i] & 0x01) << 4);
7458
7459   map153_bank_latch = mmc_helper | (map153_bank_latch & 0x0f);
7460
7461   prg16_89ab(machine, map153_bank_latch);
7462   prg16_cdef(machine, mmc_helper | 0x0f);
7463}
7464
7465static WRITE8_HANDLER( mapper153_m_w )
7466{
7467   LOG_MMC(("mapper153_m_w, offset: %04x, data: %02x\n", offset, data));
7468
7469   if (nes.crc_hack)      // Famicom Jump II uses a different board
7470   {
7471      switch (offset & 0x0f)   // there is no CHRROM and prg banking works differently
7472      {
7473      case 0: case 1:
7474      case 2: case 3:
7475      case 4: case 5:
7476      case 6: case 7:
7477         map153_reg[offset & 0x07] = data;
7478         mapper153_set_prg(space->machine);
7479         break;
7480      case 8:
7481         map153_bank_latch = (data & 0x0f) | (map153_bank_latch & 0x10);
7482         prg16_89ab(space->machine, map153_bank_latch);
7483         break;
7484      default:
7485         mapper16_m_w(space, offset & 0x0f, data);
7486         break;
7487      }
7488   }
7489   else
7490      mapper16_m_w(space, offset, data);
7491}
7492
7493static WRITE8_HANDLER( mapper153_w )
7494{
7495   LOG_MMC(("mapper153_w, offset: %04x, data: %02x\n", offset, data));
7496
7497   mapper153_w(space, offset, data);
7498}
7499
68077500/*************************************************************
68087501
68097502    Mapper 154
r5997r5998
68237516   switch (offset & 1)
68247517   {
68257518   case 0:
6826      {
6827         set_nt_mirroring((data & 0x40) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
6828         mmc_cmd1 = data & 7;
6829         break;
6830      }
7519      set_nt_mirroring((data & 0x40) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
7520      mmc_cmd1 = data & 7;
7521      break;
68317522   case 1:
7523      switch (mmc_cmd1)
68327524      {
6833         switch (mmc_cmd1)
6834         {
6835            case 0: chr2_0(space->machine, data >> 1, CHRROM); break;
6836            case 1: chr2_2(space->machine, data >> 1, CHRROM); break;
6837            case 2: chr1_4(space->machine, data | 0x40, CHRROM); break;
6838            case 3: chr1_5(space->machine, data | 0x40, CHRROM); break;
6839            case 4: chr1_6(space->machine, data | 0x40, CHRROM); break;
6840            case 5: chr1_7(space->machine, data | 0x40, CHRROM); break;
6841            case 6: prg8_89(space->machine, data); break;
6842            case 7: prg8_ab(space->machine, data); break;
6843         }
6844         break;
7525         case 0: chr2_0(space->machine, data >> 1, CHRROM); break;
7526         case 1: chr2_2(space->machine, data >> 1, CHRROM); break;
7527         case 2: chr1_4(space->machine, data | 0x40, CHRROM); break;
7528         case 3: chr1_5(space->machine, data | 0x40, CHRROM); break;
7529         case 4: chr1_6(space->machine, data | 0x40, CHRROM); break;
7530         case 5: chr1_7(space->machine, data | 0x40, CHRROM); break;
7531         case 6: prg8_89(space->machine, data); break;
7532         case 7: prg8_ab(space->machine, data); break;
68457533      }
7534      break;
68467535   }
68477536}
68487537
r5997r5998
69157604    Known Boards: Bandai Datach Board
69167605    Games: Datach Games
69177606
6918    In MESS: Unsupported. Needs reads from 0x6000-0x7fff for the
6919      Datach barcode reader
7607    This mapper is basically Mapper 16 + Datach reader. We
7608    currently do not support the Barcode reader.
69207609
7610    In MESS: Partially supported. Needs reads from 0x6000-0x7fff
7611      for the Datach barcode reader
7612
69217613*************************************************************/
69227614
69237615/*************************************************************
r5997r5998
69277619    Known Boards: Tengen 800037
69287620    Games: Alien Syndrome
69297621
6930    In MESS: Unsupported.
7622    In MESS: Very preliminary support.
69317623
69327624*************************************************************/
69337625
7626// probably wrong...
7627static void mapper158_set_mirror( running_machine *machine )
7628{
7629   UINT8 nt_mode = mmc_cmd1 & 0x80;
7630
7631   set_nt_page(0, ROM, vrom_bank[nt_mode ? 2 : 0], 0);
7632   set_nt_page(1, ROM, vrom_bank[nt_mode ? 3 : 0], 0);
7633   set_nt_page(2, ROM, vrom_bank[nt_mode ? 4 : 1], 0);
7634   set_nt_page(3, ROM, vrom_bank[nt_mode ? 5 : 1], 0);
7635}
7636
7637static WRITE8_HANDLER( mapper158_w )
7638{
7639   UINT8 map158_helper, cmd;
7640   LOG_MMC(("mapper158_w offset: %04x, data: %02x\n", offset, data));
7641
7642   switch (offset & 0x6001)
7643   {
7644      case 0x0000:
7645         map158_helper = mmc_cmd1 ^ data;
7646         mmc_cmd1 = data;
7647
7648         /* Has PRG Mode changed? */
7649         if (map158_helper & 0x40)
7650            mapper64_set_prg(space->machine);
7651
7652         /* Has CHR Mode changed? */
7653         if (map158_helper & 0xa0)
7654         {
7655            mapper64_set_chr(space->machine);
7656            mapper158_set_mirror(space->machine);
7657         }
7658         break;
7659
7660      case 0x0001:
7661         cmd = mmc_cmd1 & 0x0f;
7662         switch (cmd)
7663         {
7664            case 0: case 1:
7665            case 2: case 3:
7666            case 4: case 5:
7667               vrom_bank[cmd] = data;
7668               mapper64_set_chr(space->machine);
7669               mapper158_set_mirror(space->machine);
7670               break;
7671            case 6: case 7:
7672               prg_bank[cmd - 6] = data;
7673               mapper64_set_prg(space->machine);
7674               break;
7675            case 8: case 9:
7676               vrom_bank[cmd - 2] = data;
7677               mapper64_set_chr(space->machine);
7678               mapper158_set_mirror(space->machine);
7679               break;
7680            case 0x0f:
7681               prg_bank[2] = data;
7682               mapper64_set_prg(space->machine);
7683               break;
7684         }
7685         break;
7686
7687      case 0x2000:
7688         break;
7689
7690      default:
7691         mapper64_w(space, offset, data);
7692         break;
7693   }
7694}
7695
69347696/*************************************************************
69357697
69367698    Mapper 159
r5997r5998
69387700    Known Boards: Bandai Board
69397701    Games: Dragon Ball Z, Magical Taruruuto-kun, SD Gundam Gaiden
69407702
6941    In MESS: Unsupported.
7703    This is exactly like Mapper 16, but with different EEPROM I/O.
7704    At the moment we don't support EEPROM in either mapper.
69427705
7706    In MESS: Supported.
7707
69437708*************************************************************/
69447709
69457710/*************************************************************
r5997r5998
73498114static WRITE8_HANDLER( mapper179_l_w )
73508115{
73518116   LOG_MMC(("mapper179_l_w, offset: %04x, data: %02x\n", offset, data));
8117   offset += 0x4100;
73528118
7353   if ((offset - 0x100) & 0x1000)
8119   if (offset & 0x5000)
73548120      prg32(space->machine, data >> 1);
73558121}
73568122
r5997r5998
74478213      }
74488214      break;
74498215   case 0x6003:
7450      IRQ_count = data;
7451      IRQ_enable = 1;
7452      break;
7453   }
7454}
7455
7456static void mapper182_irq( const device_config *device, int scanline, int vblank, int blanked )
7457{
7458   if ((scanline < PPU_BOTTOM_VISIBLE_SCANLINE) /*|| (scanline == ppu_scanlines_per_frame-1)*/)
7459   {
7460      int priorCount = IRQ_count;
7461      if ((IRQ_count == 0) || IRQ_reload)
8216      if (data)
74628217      {
7463         IRQ_count = IRQ_count_latch;
7464         IRQ_reload = 0;
8218         IRQ_count = data;
8219         IRQ_enable = 1;
74658220      }
74668221      else
7467         IRQ_count --;
7468
7469      if (IRQ_enable && !blanked && (IRQ_count == 0) && priorCount)
7470      {
7471         LOG_MMC(("irq fired, scanline: %d (MAME %d, beam pos: %d)\n", scanline,
7472               video_screen_get_vpos(device->machine->primary_screen), video_screen_get_hpos(device->machine->primary_screen)));
7473         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
7474      }
8222         IRQ_enable = 0;
8223      break;
74758224   }
74768225}
74778226
r5997r5998
75168265    Known Boards: CNROM
75178266    Games: B-Wings, Mighty Bomb Jack, Seicross, Spy vs. Spy
75188267
7519    In MESS: Unsupported.
8268    In MESS: Very Preliminar Support. We act like it is mapper 3
8269    but we need to emulate the read back from 0x8000-0xfff!
75208270
75218271*************************************************************/
75228272
8273static WRITE8_HANDLER( mapper185_w )
8274{
8275   LOG_MMC(("mapper3_w offset: %04x, data: %02x\n", offset, data));
8276
8277   chr8(space->machine, data, CHRROM);
8278}
8279
75238280/*************************************************************
75248281
75258282    Mapper 186
r5997r5998
75418298
75428299    MMC3 clone
75438300
7544    In MESS: Unsupported.
8301    In MESS: Preliminary Support.
75458302
75468303*************************************************************/
75478304
8305static void mapper187_set_prg( running_machine *machine, int prg_base, int prg_mask )
8306{
8307   UINT8 prg_flip = (mmc_cmd1 & 0x40) ? 2 : 0;
8308
8309   if (!(mapper187_reg[0] & 0x80))
8310   {
8311      prg8_89(machine, prg_base | (prg_bank[0 ^ prg_flip] & prg_mask));
8312      prg8_ab(machine, prg_base | (prg_bank[1] & prg_mask));
8313      prg8_cd(machine, prg_base | (prg_bank[2 ^ prg_flip] & prg_mask));
8314      prg8_ef(machine, prg_base | (prg_bank[3] & prg_mask));
8315   }
8316}
8317
8318static void mapper187_set_chr( running_machine *machine, UINT8 chr, int chr_base, int chr_mask )
8319{
8320   UINT8 chr_page = (mmc_cmd1 & 0x80) >> 5;
8321   UINT8 new_base[8];
8322   int i;
8323
8324   for (i = 0; i < 8; i++)
8325      new_base[i] = ((i & 0x04) == chr_page)? (chr_base | 0x100) : chr_base;
8326
8327   chr1_x(machine, chr_page ^ 0, new_base[0] | ((vrom_bank[0] & ~0x01) & chr_mask), chr);
8328   chr1_x(machine, chr_page ^ 1, new_base[1] | ((vrom_bank[0] |  0x01) & chr_mask), chr);
8329   chr1_x(machine, chr_page ^ 2, new_base[2] | ((vrom_bank[1] & ~0x01) & chr_mask), chr);
8330   chr1_x(machine, chr_page ^ 3, new_base[3] | ((vrom_bank[1] |  0x01) & chr_mask), chr);
8331   chr1_x(machine, chr_page ^ 4, new_base[4] | (vrom_bank[2] & chr_mask), chr);
8332   chr1_x(machine, chr_page ^ 5, new_base[5] | (vrom_bank[3] & chr_mask), chr);
8333   chr1_x(machine, chr_page ^ 6, new_base[6] | (vrom_bank[4] & chr_mask), chr);
8334   chr1_x(machine, chr_page ^ 7, new_base[7] | (vrom_bank[5] & chr_mask), chr);
8335}
8336
8337static WRITE8_HANDLER( mapper187_l_w )
8338{
8339   UINT8 new_bank;
8340   LOG_MMC(("mapper187_l_w, offset: %04x, data: %02x\n", offset, data));
8341   offset += 0x100;
8342
8343   if (offset == 0x1000)
8344   {
8345      switch (data & 0x03)
8346      {
8347      case 0x00:
8348      case 0x01:
8349         mapper187_reg[1] = 0x83;
8350         break;
8351      case 0x02:
8352         mapper187_reg[1] = 0x42;
8353         break;
8354      case 0x03:
8355         mapper187_reg[1] = 0x00;
8356         break;
8357      }
8358   }
8359
8360   if (!(offset <= 0x1000))
8361   {
8362      mapper187_reg[0] = data;
8363
8364      if (mapper187_reg[0] & 0x80)
8365      {
8366         new_bank = (mapper187_reg[0] & 0x1f);
8367
8368         if (mapper187_reg[0] & 0x20)
8369            prg32(space->machine, new_bank >> 2);
8370         else
8371         {
8372            prg16_89ab(space->machine, new_bank);
8373            prg16_cdef(space->machine, new_bank);
8374         }
8375      }
8376      else
8377         mapper187_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
8378   }
8379}
8380
8381static READ8_HANDLER( mapper187_l_r )
8382{
8383   LOG_MMC(("mapper187_l_r, offset: %04x\n", offset));
8384   offset += 0x100;
8385
8386   if (!(offset < 0x1000))
8387      return mapper187_reg[1];
8388   else
8389      return 0;
8390}
8391
8392static WRITE8_HANDLER( mapper187_w )
8393{
8394   UINT8 MMC3_helper, cmd;
8395   LOG_MMC(("mapper187_w, offset: %04x, data: %02x\n", offset, data));
8396
8397   switch (offset & 0x6003)
8398   {
8399   case 0x0000:
8400      mapper187_reg[2] = 1;
8401      MMC3_helper = mmc_cmd1 ^ data;
8402      mmc_cmd1 = data;
8403
8404      /* Has PRG Mode changed? */
8405      if (MMC3_helper & 0x40)
8406         mapper187_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
8407
8408      /* Has CHR Mode changed? */
8409      if (MMC3_helper & 0x80)
8410         mapper187_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
8411      break;
8412
8413   case 0x0001:
8414      if (mapper187_reg[2])
8415      {
8416         cmd = mmc_cmd1 & 0x07;
8417         switch (cmd)
8418         {
8419         case 0: case 1:
8420         case 2: case 3: case 4: case 5:
8421            vrom_bank[cmd] = data;
8422            mapper187_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
8423            break;
8424         case 6:
8425         case 7:
8426            prg_bank[cmd - 6] = data;
8427            mapper187_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
8428            break;
8429         }
8430      }
8431      break;
8432
8433   case 0x0002:
8434      break;
8435
8436   case 0x0003:
8437      mapper187_reg[2] = 0;
8438
8439      if (data == 0x28)
8440         prg8_cd(space->machine, 0x17);
8441      else if (data == 0x2a)
8442         prg8_ab(space->machine, 0x0f);
8443      break;
8444
8445   default:
8446      mapper4_w(space, offset, data);
8447      break;
8448   }
8449}
8450
75488451/*************************************************************
75498452
75508453    Mapper 188
r5997r5998
75728475
75738476    MMC3 clone
75748477
7575    In MESS: Unsupported.
8478    In MESS: Supported.
75768479
75778480*************************************************************/
75788481
8482static WRITE8_HANDLER( mapper189_l_w )
8483{
8484   LOG_MMC(("mapper189_l_w, offset: %04x, data: %02x\n", offset, data));
8485
8486   prg32(space->machine, (data >> 4) | data);
8487}
8488
8489static WRITE8_HANDLER( mapper189_m_w )
8490{
8491   LOG_MMC(("mapper189_m_w, offset: %04x, data: %04x\n", offset, data));
8492
8493   mapper189_l_w(space, offset & 0xff, data);   // offset does not really count for this mapper
8494}
8495
8496/* This is like mapper4 but with no PRG bankswitch (beacuse it is handled by low writes) */
8497static WRITE8_HANDLER( mapper189_w )
8498{
8499   UINT8 MMC3_helper, cmd;
8500   LOG_MMC(("mapper189_w, offset: %04x, data: %02x\n", offset, data));
8501
8502   switch (offset & 0x6001)
8503   {
8504   case 0x0000:
8505      MMC3_helper = mmc_cmd1 ^ data;
8506      mmc_cmd1 = data;
8507
8508      /* Has CHR Mode changed? */
8509      if (MMC3_helper & 0x80)
8510         mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
8511      break;
8512
8513   case 0x0001:
8514      cmd = mmc_cmd1 & 0x07;
8515      switch (cmd)
8516      {
8517      case 0: case 1:
8518      case 2: case 3: case 4: case 5:
8519         vrom_bank[cmd] = data;
8520         mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
8521         break;
8522      }
8523      break;
8524
8525   default:
8526      mapper4_w(space, offset, data);
8527      break;
8528   }
8529}
8530
75798531/*************************************************************
75808532
75818533    Mapper 190
r5997r5998
75948546    Known Boards: Type B by Waixing
75958547    Games: Sugoro Quest (C)
75968548
7597    MMC3 clone
8549    MMC3 clone. This is a minor modification of Mapper 74,
8550    in the sense that it is the same board except for the
8551    CHRRAM pages.
75988552
7599    In MESS: Unsupported.
8553    In MESS: Supported.
76008554
76018555*************************************************************/
76028556
8557static void mapper191_set_chr( running_machine *machine, int chr_base, int chr_mask )
8558{
8559   UINT8 chr_page = (mmc_cmd1 & 0x80) >> 5;
8560   UINT8 chr_src[6];
8561   int i;
8562
8563   for (i = 0; i < 6; i++)
8564      chr_src[i] = (vrom_bank[i] & 0x80) ? CHRRAM : CHRROM;
8565
8566   chr1_x(machine, chr_page ^ 0, chr_base | ((vrom_bank[0] & ~0x01) & chr_mask), chr_src[0]);
8567   chr1_x(machine, chr_page ^ 1, chr_base | ((vrom_bank[0] |  0x01) & chr_mask), chr_src[0]);
8568   chr1_x(machine, chr_page ^ 2, chr_base | ((vrom_bank[1] & ~0x01) & chr_mask), chr_src[1]);
8569   chr1_x(machine, chr_page ^ 3, chr_base | ((vrom_bank[1] |  0x01) & chr_mask), chr_src[1]);
8570   chr1_x(machine, chr_page ^ 4, chr_base | (vrom_bank[2] & chr_mask), chr_src[2]);
8571   chr1_x(machine, chr_page ^ 5, chr_base | (vrom_bank[3] & chr_mask), chr_src[3]);
8572   chr1_x(machine, chr_page ^ 6, chr_base | (vrom_bank[4] & chr_mask), chr_src[4]);
8573   chr1_x(machine, chr_page ^ 7, chr_base | (vrom_bank[5] & chr_mask), chr_src[5]);
8574}
8575
8576static WRITE8_HANDLER( mapper191_w )
8577{
8578   UINT8 MMC3_helper, cmd;
8579   LOG_MMC(("mapper191_w, offset: %04x, data: %02x\n", offset, data));
8580
8581   switch (offset & 0x6001)
8582   {
8583   case 0x0000:
8584      MMC3_helper = mmc_cmd1 ^ data;
8585      mmc_cmd1 = data;
8586
8587      /* Has PRG Mode changed? */
8588      if (MMC3_helper & 0x40)
8589         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
8590
8591      /* Has CHR Mode changed? */
8592      if (MMC3_helper & 0x80)
8593         mapper191_set_chr(space->machine, mmc_chr_base, mmc_chr_mask);
8594      break;
8595
8596   case 0x0001:
8597      cmd = mmc_cmd1 & 0x07;
8598      switch (cmd)
8599      {
8600      case 0: case 1:   // these do not need to be separated: we take care of them in set_chr!
8601      case 2: case 3: case 4: case 5:
8602         vrom_bank[cmd] = data;
8603         mapper191_set_chr(space->machine, mmc_chr_base, mmc_chr_mask);
8604         break;
8605      case 6:
8606      case 7:
8607         prg_bank[cmd - 6] = data;
8608         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
8609         break;
8610      }
8611      break;
8612
8613   default:
8614      mapper74_w(space, offset, data);
8615      break;
8616   }
8617}
8618
76038619/*************************************************************
76048620
76058621    Mapper 192
r5997r5998
76078623    Known Boards: Type C by Waixing
76088624    Games: Ying Lie Qun Xia Zhuan, Young Chivalry
76098625
7610    MMC3 clone
8626    MMC3 clone. This is a minor modification of Mapper 74,
8627    in the sense that it is the same board except for the
8628    CHRRAM pages.
76118629
7612    In MESS: Unsupported.
8630    In MESS: Supported.
76138631
76148632*************************************************************/
76158633
8634static void mapper192_set_chr( running_machine *machine, int chr_base, int chr_mask )
8635{
8636   UINT8 chr_page = (mmc_cmd1 & 0x80) >> 5;
8637   UINT8 chr_src[6];
8638   int i;
8639
8640   for (i = 0; i < 6; i++)
8641      chr_src[i] = ((vrom_bank[i] == 0x08) || (vrom_bank[i] == 0x09) || (vrom_bank[i] == 0x0a) || (vrom_bank[i] == 0x0b)) ? CHRRAM : CHRROM;
8642
8643   chr1_x(machine, chr_page ^ 0, chr_base | ((vrom_bank[0] & ~0x01) & chr_mask), chr_src[0]);
8644   chr1_x(machine, chr_page ^ 1, chr_base | ((vrom_bank[0] |  0x01) & chr_mask), chr_src[0]);
8645   chr1_x(machine, chr_page ^ 2, chr_base | ((vrom_bank[1] & ~0x01) & chr_mask), chr_src[1]);
8646   chr1_x(machine, chr_page ^ 3, chr_base | ((vrom_bank[1] |  0x01) & chr_mask), chr_src[1]);
8647   chr1_x(machine, chr_page ^ 4, chr_base | (vrom_bank[2] & chr_mask), chr_src[2]);
8648   chr1_x(machine, chr_page ^ 5, chr_base | (vrom_bank[3] & chr_mask), chr_src[3]);
8649   chr1_x(machine, chr_page ^ 6, chr_base | (vrom_bank[4] & chr_mask), chr_src[4]);
8650   chr1_x(machine, chr_page ^ 7, chr_base | (vrom_bank[5] & chr_mask), chr_src[5]);
8651}
8652
8653static WRITE8_HANDLER( mapper192_w )
8654{
8655   UINT8 MMC3_helper, cmd;
8656   LOG_MMC(("mapper192_w, offset: %04x, data: %02x\n", offset, data));
8657
8658   switch (offset & 0x6001)
8659   {
8660   case 0x0000:
8661      MMC3_helper = mmc_cmd1 ^ data;
8662      mmc_cmd1 = data;
8663
8664      /* Has PRG Mode changed? */
8665      if (MMC3_helper & 0x40)
8666         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
8667
8668      /* Has CHR Mode changed? */
8669      if (MMC3_helper & 0x80)
8670         mapper192_set_chr(space->machine, mmc_chr_base, mmc_chr_mask);
8671      break;
8672
8673   case 0x0001:
8674      cmd = mmc_cmd1 & 0x07;
8675      switch (cmd)
8676      {
8677      case 0: case 1:   // these do not need to be separated: we take care of them in set_chr!
8678      case 2: case 3: case 4: case 5:
8679         vrom_bank[cmd] = data;
8680         mapper192_set_chr(space->machine, mmc_chr_base, mmc_chr_mask);
8681         break;
8682      case 6:
8683      case 7:
8684         prg_bank[cmd - 6] = data;
8685         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
8686         break;
8687      }
8688      break;
8689
8690   default:
8691      mapper74_w(space, offset, data);
8692      break;
8693   }
8694}
8695
76168696/*************************************************************
76178697
76188698    Mapper 193
r5997r5998
76558735    Known Boards: Type D by Waixing
76568736    Games: Super Robot Taisen (C)
76578737
7658    MMC3 clone
8738    MMC3 clone. This is a minor modification of Mapper 74,
8739    in the sense that it is the same board except for the
8740    CHRRAM pages.
76598741
7660    In MESS: Unsupported.
8742    In MESS: Supported.
76618743
76628744*************************************************************/
76638745
8746static void mapper194_set_chr( running_machine *machine, int chr_base, int chr_mask )
8747{
8748   UINT8 chr_page = (mmc_cmd1 & 0x80) >> 5;
8749   UINT8 chr_src[6];
8750   int i;
8751
8752   for (i = 0; i < 6; i++)
8753      chr_src[i] = (vrom_bank[i] < 0x02) ? CHRRAM : CHRROM;
8754
8755   chr1_x(machine, chr_page ^ 0, chr_base | ((vrom_bank[0] & ~0x01) & chr_mask), chr_src[0]);
8756   chr1_x(machine, chr_page ^ 1, chr_base | ((vrom_bank[0] |  0x01) & chr_mask), chr_src[0]);
8757   chr1_x(machine, chr_page ^ 2, chr_base | ((vrom_bank[1] & ~0x01) & chr_mask), chr_src[1]);
8758   chr1_x(machine, chr_page ^ 3, chr_base | ((vrom_bank[1] |  0x01) & chr_mask), chr_src[1]);
8759   chr1_x(machine, chr_page ^ 4, chr_base | (vrom_bank[2] & chr_mask), chr_src[2]);
8760   chr1_x(machine, chr_page ^ 5, chr_base | (vrom_bank[3] & chr_mask), chr_src[3]);
8761   chr1_x(machine, chr_page ^ 6, chr_base | (vrom_bank[4] & chr_mask), chr_src[4]);
8762   chr1_x(machine, chr_page ^ 7, chr_base | (vrom_bank[5] & chr_mask), chr_src[5]);
8763}
8764
8765static WRITE8_HANDLER( mapper194_w )
8766{
8767   UINT8 MMC3_helper, cmd;
8768   LOG_MMC(("mapper194_w, offset: %04x, data: %02x\n", offset, data));
8769
8770   switch (offset & 0x6001)
8771   {
8772   case 0x0000:
8773      MMC3_helper = mmc_cmd1 ^ data;
8774      mmc_cmd1 = data;
8775
8776      /* Has PRG Mode changed? */
8777      if (MMC3_helper & 0x40)
8778         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
8779
8780      /* Has CHR Mode changed? */
8781      if (MMC3_helper & 0x80)
8782         mapper194_set_chr(space->machine, mmc_chr_base, mmc_chr_mask);
8783      break;
8784
8785   case 0x0001:
8786      cmd = mmc_cmd1 & 0x07;
8787      switch (cmd)
8788      {
8789      case 0: case 1:   // these do not need to be separated: we take care of them in set_chr!
8790      case 2: case 3: case 4: case 5:
8791         vrom_bank[cmd] = data;
8792         mapper194_set_chr(space->machine, mmc_chr_base, mmc_chr_mask);
8793         break;
8794      case 6:
8795      case 7:
8796         prg_bank[cmd - 6] = data;
8797         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
8798         break;
8799      }
8800      break;
8801
8802   default:
8803      mapper74_w(space, offset, data);
8804      break;
8805   }
8806}
8807
76648808/*************************************************************
76658809
76668810    Mapper 195
r5997r5998
76698813    Games: Captain Tsubasa Vol. II (C), Chaos World, God
76708814          Slayer (C), Zu Qiu Xiao Jiang
76718815
7672    MMC3 clone
8816    MMC3 clone. This is a minor modification of Mapper 74,
8817    in the sense that it is the same board except for the
8818    CHRRAM pages.
76738819
7674    In MESS: Unsupported.
8820    In MESS: Supported.
76758821
76768822*************************************************************/
76778823
8824static void mapper195_set_chr( running_machine *machine, int chr_base, int chr_mask )
8825{
8826   UINT8 chr_page = (mmc_cmd1 & 0x80) >> 5;
8827   UINT8 chr_src[6];
8828   int i;
8829
8830   for (i = 0; i < 6; i++)
8831      chr_src[i] = (vrom_bank[i] < 0x04) ? CHRRAM : CHRROM;
8832
8833   chr1_x(machine, chr_page ^ 0, chr_base | ((vrom_bank[0] & ~0x01) & chr_mask), chr_src[0]);
8834   chr1_x(machine, chr_page ^ 1, chr_base | ((vrom_bank[0] |  0x01) & chr_mask), chr_src[0]);
8835   chr1_x(machine, chr_page ^ 2, chr_base | ((vrom_bank[1] & ~0x01) & chr_mask), chr_src[1]);
8836   chr1_x(machine, chr_page ^ 3, chr_base | ((vrom_bank[1] |  0x01) & chr_mask), chr_src[1]);
8837   chr1_x(machine, chr_page ^ 4, chr_base | (vrom_bank[2] & chr_mask), chr_src[2]);
8838   chr1_x(machine, chr_page ^ 5, chr_base | (vrom_bank[3] & chr_mask), chr_src[3]);
8839   chr1_x(machine, chr_page ^ 6, chr_base | (vrom_bank[4] & chr_mask), chr_src[4]);
8840   chr1_x(machine, chr_page ^ 7, chr_base | (vrom_bank[5] & chr_mask), chr_src[5]);
8841}
8842
8843static WRITE8_HANDLER( mapper195_w )
8844{
8845   UINT8 MMC3_helper, cmd;
8846   LOG_MMC(("mapper195_w, offset: %04x, data: %02x\n", offset, data));
8847
8848   switch (offset & 0x6001)
8849   {
8850   case 0x0000:
8851      MMC3_helper = mmc_cmd1 ^ data;
8852      mmc_cmd1 = data;
8853
8854      /* Has PRG Mode changed? */
8855      if (MMC3_helper & 0x40)
8856         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
8857
8858      /* Has CHR Mode changed? */
8859      if (MMC3_helper & 0x80)
8860         mapper195_set_chr(space->machine, mmc_chr_base, mmc_chr_mask);
8861      break;
8862
8863   case 0x0001:
8864      cmd = mmc_cmd1 & 0x07;
8865      switch (cmd)
8866      {
8867      case 0: case 1:   // these do not need to be separated: we take care of them in set_chr!
8868      case 2: case 3: case 4: case 5:
8869         vrom_bank[cmd] = data;
8870         mapper195_set_chr(space->machine, mmc_chr_base, mmc_chr_mask);
8871         break;
8872      case 6:
8873      case 7:
8874         prg_bank[cmd - 6] = data;
8875         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
8876         break;
8877      }
8878      break;
8879
8880   default:
8881      mapper74_w(space, offset, data);
8882      break;
8883   }
8884}
8885
76788886/*************************************************************
76798887
76808888    Mapper 196
r5997r5998
76938901{
76948902   LOG_MMC(("mapper196_w, offset: %04x, data: %02x\n", offset, data));
76958903
7696   switch (offset & 0x6004)
7697   {
7698   case 0x0000:
7699      mapper4_w(space, 0x0000, data);
7700      break;
7701   case 0x0004:
7702      mapper4_w(space, 0x0001, data);
7703      break;
7704   case 0x2000:
7705      set_nt_mirroring(data & 0x01 ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);   // diff with MMC3: not check for data & 0x40
7706      break;
7707   case 0x2004:
7708      mapper4_w(space, 0x2001, data);
7709      break;
7710   case 0x4000:
7711      mapper4_w(space, 0x4000, data);
7712      break;
7713   case 0x4004:
7714      mapper4_w(space, 0x4001, data);
7715      break;
7716   case 0x6000:
7717      mapper4_w(space, 0x6000, data);
7718      break;
7719   case 0x6004:
7720      mapper4_w(space, 0x6001, data);
7721      break;
7722   default:
7723      break;
7724   }
8904   mapper4_w(space, (offset & 0x6000) | ((offset & 0x04) >> 2), data);
77258905}
77268906
77278907/*************************************************************
r5997r5998
77338913
77348914    MMC3 clone
77358915
7736    In MESS: Unsupported.
8916    In MESS: Supported.
77378917
77388918*************************************************************/
77398919
8920static void mapper197_set_chr( running_machine *machine, UINT8 chr_source, int chr_base, int chr_mask )
8921{
8922   chr4_0(machine, chr_base | ((vrom_bank[0] >> 1) & chr_mask), chr_source);
8923   chr2_4(machine, chr_base | (vrom_bank[1] & chr_mask), chr_source);
8924   chr2_6(machine, chr_base | (vrom_bank[2] & chr_mask), chr_source);
8925}
8926
8927static WRITE8_HANDLER( mapper197_w )
8928{
8929   UINT8 MMC3_helper, cmd;
8930   LOG_MMC(("mapper197_w, offset: %04x, data: %02x\n", offset, data));
8931
8932   switch (offset & 0x6001)
8933   {
8934   case 0x0000:
8935      MMC3_helper = mmc_cmd1 ^ data;
8936      mmc_cmd1 = data;
8937
8938      /* Has PRG Mode changed? */
8939      if (MMC3_helper & 0x40)
8940         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
8941
8942      /* Has CHR Mode changed? */
8943      if (MMC3_helper & 0x80)
8944         mapper197_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
8945      break;
8946
8947   case 0x0001:
8948      cmd = mmc_cmd1 & 0x0f;
8949      switch (cmd)
8950      {
8951      case 0: case 2: case 4:
8952         vrom_bank[cmd >> 1] = data;
8953         mapper197_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
8954         break;
8955      case 6:
8956      case 7:
8957         prg_bank[cmd - 6] = data;
8958         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
8959         break;
8960      }
8961      break;
8962
8963   default:
8964      mapper4_w(space, offset, data);
8965      break;
8966   }
8967}
8968
77408969/*************************************************************
77418970
77428971    Mapper 198
r5997r5998
77448973    Known Boards: Type F by Waixing
77458974    Games: Tenchi wo Kurau II (C)
77468975
7747    MMC3 clone
8976    MMC3 clone.
77488977
7749    In MESS: Unsupported.
8978    In MESS: Preliminary support.
77508979
77518980*************************************************************/
77528981
8982static void mapper198_set_prg( running_machine *machine, int prg_base, int prg_mask )
8983{
8984   UINT8 prg_flip = (mmc_cmd1 & 0x40) ? 2 : 0;
8985
8986   prg8_89(machine, prg_base | (prg_bank[0 ^ prg_flip] & prg_mask));
8987   prg8_ab(machine, prg_base | (prg_bank[1] & prg_mask));
8988   prg8_cd(machine, prg_base | (prg_bank[2 ^ prg_flip] & prg_mask));
8989   prg8_ef(machine, prg_base | (prg_bank[3] & prg_mask));
8990}
8991
8992static WRITE8_HANDLER( mapper198_w )
8993{
8994   UINT8 MMC3_helper, cmd;
8995   LOG_MMC(("mapper198_w, offset: %04x, data: %02x\n", offset, data));
8996
8997   switch (offset & 0x6001)
8998   {
8999   case 0x0000:
9000      MMC3_helper = mmc_cmd1 ^ data;
9001      mmc_cmd1 = data;
9002
9003      /* Has PRG Mode changed? */
9004      if (MMC3_helper & 0x40)
9005         mapper198_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
9006
9007      /* Has CHR Mode changed? */
9008      if (MMC3_helper & 0x80)
9009         mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
9010      break;
9011
9012   case 0x0001:
9013      cmd = mmc_cmd1 & 0x07;
9014      switch (cmd)
9015      {
9016      case 0: case 1:   // these do not need to be separated: we take care of them in set_chr!
9017      case 2: case 3: case 4: case 5:
9018         vrom_bank[cmd] = data;
9019         mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
9020         break;
9021      case 6:
9022      case 7:
9023         prg_bank[cmd - 6] = data & ((data > 0x3f) ? 0x4f : 0x3f);
9024         mapper198_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
9025         break;
9026      }
9027      break;
9028
9029   default:
9030      mapper74_w(space, offset, data);
9031      break;
9032   }
9033}
9034
77539035/*************************************************************
77549036
77559037    Mapper 199
r5997r5998
77609042
77619043    MMC3 clone
77629044
7763    In MESS: Unsupported.
9045    In MESS: Supported.
77649046
77659047*************************************************************/
77669048
9049static void mapper199_set_chr( running_machine *machine, int chr_base, int chr_mask )
9050{
9051   UINT8 chr_page = (mmc_cmd1 & 0x80) >> 5;
9052   UINT8 chr_src[8];
9053   int i;
9054
9055   for (i = 0; i < 8; i++)
9056      chr_src[i] = (vrom_bank[i] < 0x08) ? CHRRAM : CHRROM;
9057
9058   chr1_x(machine, chr_page ^ 0, chr_base | (vrom_bank[0] & chr_mask), chr_src[0]);
9059   chr1_x(machine, chr_page ^ 1, chr_base | (vrom_bank[6] & chr_mask), chr_src[6]);
9060   chr1_x(machine, chr_page ^ 2, chr_base | (vrom_bank[1] & chr_mask), chr_src[1]);
9061   chr1_x(machine, chr_page ^ 3, chr_base | (vrom_bank[7] & chr_mask), chr_src[7]);
9062   chr1_x(machine, chr_page ^ 4, chr_base | (vrom_bank[2] & chr_mask), chr_src[2]);
9063   chr1_x(machine, chr_page ^ 5, chr_base | (vrom_bank[3] & chr_mask), chr_src[3]);
9064   chr1_x(machine, chr_page ^ 6, chr_base | (vrom_bank[4] & chr_mask), chr_src[4]);
9065   chr1_x(machine, chr_page ^ 7, chr_base | (vrom_bank[5] & chr_mask), chr_src[5]);
9066}
9067
9068static WRITE8_HANDLER( mapper199_w )
9069{
9070   UINT8 MMC3_helper, cmd;
9071   LOG_MMC(("mapper199_w, offset: %04x, data: %02x\n", offset, data));
9072
9073   switch (offset & 0x6001)
9074   {
9075   case 0x0000:
9076      MMC3_helper = mmc_cmd1 ^ data;
9077      mmc_cmd1 = data;
9078
9079      /* Has PRG Mode changed? */
9080      if (MMC3_helper & 0x40)
9081         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
9082
9083      /* Has CHR Mode changed? */
9084      if (MMC3_helper & 0x80)
9085         mapper199_set_chr(space->machine, mmc_chr_base, mmc_chr_mask);
9086      break;
9087
9088   case 0x0001:
9089      cmd = mmc_cmd1 & 0x0f;
9090      switch (cmd)
9091      {
9092      case 0: case 1:   // these do not need to be separated: we take care of them in set_chr!
9093      case 2: case 3: case 4: case 5:
9094         vrom_bank[cmd] = data;
9095         mapper199_set_chr(space->machine, mmc_chr_base, mmc_chr_mask);
9096         break;
9097      case 6:
9098      case 7:
9099      case 8:
9100      case 9:
9101         prg_bank[cmd - 6] = data;
9102         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
9103         break;
9104      case 0x0a: case 0x0b:
9105         vrom_bank[cmd - 4] = data;
9106         mapper199_set_chr(space->machine, mmc_chr_base, mmc_chr_mask);
9107         break;
9108      }
9109      break;
9110
9111   default:
9112      mapper4_w(space, offset, data);
9113      break;
9114   }
9115}
9116
77679117/*************************************************************
77689118
77699119    Mapper 200
r5997r5998
78829232
78839233    MMC3 clone
78849234
7885    In MESS: Unsupported.
9235    In MESS: Supported.
78869236
78879237*************************************************************/
78889238
9239static WRITE8_HANDLER( mapper205_m_w )
9240{
9241   LOG_MMC(("mapper205_m_w, offset: %04x, data: %02x\n", offset, data));
9242
9243   if (offset & 0x0800)
9244   {
9245      mmc_prg_base = (data & 0x03) << 4;
9246      mmc_prg_mask = (data & 0x02) ? 0x0f : 0x1f;
9247      mmc_chr_base = (data & 0x03) << 7;
9248      mmc_chr_mask = (data & 0x02) ? 0x7f : 0xff;
9249      mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
9250      mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
9251   }
9252}
9253
78899254/*************************************************************
78909255
78919256    Mapper 206
r5997r5998
79869351
79879352    MMC3 clone. It also requires reads from 0x5000-0x7fff.
79889353
7989    In MESS: Unsupported.
9354    In MESS: Preliminary Support.
79909355
79919356*************************************************************/
79929357
9358static WRITE8_HANDLER( mapper208_l_w )
9359{
9360   static const UINT8 conv_table[256] =
9361   {
9362      0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x49,0x19,0x09,0x59,0x49,0x19,0x09,
9363      0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x51,0x41,0x11,0x01,0x51,0x41,0x11,0x01,
9364      0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x49,0x19,0x09,0x59,0x49,0x19,0x09,
9365      0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x51,0x41,0x11,0x01,0x51,0x41,0x11,0x01,
9366      0x00,0x10,0x40,0x50,0x00,0x10,0x40,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
9367      0x08,0x18,0x48,0x58,0x08,0x18,0x48,0x58,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
9368      0x00,0x10,0x40,0x50,0x00,0x10,0x40,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
9369      0x08,0x18,0x48,0x58,0x08,0x18,0x48,0x58,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
9370      0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x58,0x48,0x18,0x08,0x58,0x48,0x18,0x08,
9371      0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x50,0x40,0x10,0x00,0x50,0x40,0x10,0x00,
9372      0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x58,0x48,0x18,0x08,0x58,0x48,0x18,0x08,
9373      0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x50,0x40,0x10,0x00,0x50,0x40,0x10,0x00,
9374      0x01,0x11,0x41,0x51,0x01,0x11,0x41,0x51,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
9375      0x09,0x19,0x49,0x59,0x09,0x19,0x49,0x59,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
9376      0x01,0x11,0x41,0x51,0x01,0x11,0x41,0x51,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
9377      0x09,0x19,0x49,0x59,0x09,0x19,0x49,0x59,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
9378   };
9379
9380   LOG_MMC(("mapper208_l_w, offset: %04x, data: %02x\n", offset, data));
9381
9382   if (!(offset < 0x1700))
9383      map208_reg[offset & 0x03] = data ^ conv_table[map208_reg[4]];
9384   else if (!(offset < 0xf00))
9385      map208_reg[4] = data;
9386   else if (!(offset < 0x700))
9387      prg32(space->machine, ((data >> 3) & 0x02) | (data & 0x01));
9388}
9389
9390static READ8_HANDLER( mapper208_l_r )
9391{
9392   LOG_MMC(("mapper208_l_r, offset: %04x\n", offset));
9393
9394   if (!(offset < 0x1700))
9395      return map208_reg[offset & 0x03];
9396
9397   return 0x00;
9398}
9399
9400/* This is like mapper4 but with no PRG bankswitch (beacuse it is handled by low writes) */
9401// replace with map189_w... they are the same!!
9402static WRITE8_HANDLER( mapper208_w )
9403{
9404   UINT8 MMC3_helper, cmd;
9405   LOG_MMC(("mapper208_w, offset: %04x, data: %02x\n", offset, data));
9406
9407   switch (offset & 0x6001)
9408   {
9409   case 0x0000:
9410      MMC3_helper = mmc_cmd1 ^ data;
9411      mmc_cmd1 = data;
9412
9413      /* Has CHR Mode changed? */
9414      if (MMC3_helper & 0x80)
9415         mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
9416      break;
9417
9418   case 0x0001:
9419      cmd = mmc_cmd1 & 0x07;
9420      switch (cmd)
9421      {
9422      case 0: case 1:
9423      case 2: case 3: case 4: case 5:
9424         vrom_bank[cmd] = data;
9425         mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
9426         break;
9427      }
9428      break;
9429
9430   default:
9431      mapper4_w(space, offset, data);
9432      break;
9433   }
9434}
9435
79939436/*************************************************************
79949437
79959438    Mapper 209
r5997r5998
80099452    Known Boards: Undocumented / Unused ?!?
80109453    Games: ----------
80119454
9455    For some emulators, this is the same as Mapper 19 but it
9456    has hardwired mirroring and no additional sound hardware.
9457    Initializing Mirroring to Vertical in Mapper 19 seems to
9458    fix all glitches in 'so-called' Mapper 210 games, so there
9459    seems to be no reason to have this duplicate mapper (at
9460    least until we emulate additional sound hardware... if sound
9461    writes would create conflicts, we might consider to split the
9462    mapper in two variants)
9463
80129464    In MESS: ----------
80139465
80149466*************************************************************/
r5997r5998
81009552    MMC3 clone. Also, it probably needs a hack to support both
81019553    variants (Boogerman & MK3).
81029554
8103    In MESS: Unsupported.
9555    In MESS: Preliminary support.
81049556
81059557*************************************************************/
81069558
9559// remove mask & base parameters!
9560static void mapper215_set_prg( running_machine *machine, int prg_base, int prg_mask )
9561{
9562   if (map215_reg[0] & 0x80)
9563   {
9564      prg16_89ab(machine, (map215_reg[0] & 0xf0) | (map215_reg[1] & 0x10));
9565      prg16_cdef(machine, (map215_reg[0] & 0xf0) | (map215_reg[1] & 0x10));
9566   }
9567   else
9568   {
9569      mmc_prg_base = (map215_reg[1] & 0x08) ? 0x20 : (map215_reg[1] & 0x10);
9570      mmc_prg_mask = (map215_reg[1] & 0x08) ? 0x1f : 0x0f;
9571
9572      mapper4_set_prg(machine, mmc_prg_base, mmc_prg_mask);
9573   }
9574}
9575
9576static void mapper215_set_chr( running_machine *machine, UINT8 chr )
9577{
9578   UINT8 chr_page = (mmc_cmd1 & 0x80) >> 5;
9579   int chr_base = (map215_reg[1] & 0x04) ? 0x100 : ((map215_reg[1] & 0x10) << 3);
9580   int chr_mask = (map215_reg[1] & 0x04) ? 0xff : 0x7f;
9581
9582   chr1_x(machine, chr_page ^ 0, chr_base | ((vrom_bank[0] & ~0x01) & chr_mask), chr);
9583   chr1_x(machine, chr_page ^ 1, chr_base | ((vrom_bank[0] |  0x01) & chr_mask), chr);
9584   chr1_x(machine, chr_page ^ 2, chr_base | ((vrom_bank[1] & ~0x01) & chr_mask), chr);
9585   chr1_x(machine, chr_page ^ 3, chr_base | ((vrom_bank[1] |  0x01) & chr_mask), chr);
9586   chr1_x(machine, chr_page ^ 4, chr_base | (vrom_bank[2] & chr_mask), chr);
9587   chr1_x(machine, chr_page ^ 5, chr_base | (vrom_bank[3] & chr_mask), chr);
9588   chr1_x(machine, chr_page ^ 6, chr_base | (vrom_bank[4] & chr_mask), chr);
9589   chr1_x(machine, chr_page ^ 7, chr_base | (vrom_bank[5] & chr_mask), chr);
9590}
9591
9592static WRITE8_HANDLER( mapper215_l_w )
9593{
9594   LOG_MMC(("mapper215_l_w, offset: %04x, data: %02x\n", offset, data));
9595   offset += 0x100;
9596
9597   if (offset == 0x1000)
9598   {
9599      map215_reg[0] = data;
9600      mapper215_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
9601   }
9602   else if (offset == 0x1001)
9603   {
9604      map215_reg[1] = data;
9605      mapper215_set_chr(space->machine, mmc_chr_source);
9606   }
9607   else if (offset == 0x1007)
9608   {
9609      mmc_cmd1 = 0;
9610      map215_reg[2] = data;
9611      mapper215_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
9612      mapper215_set_chr(space->machine, mmc_chr_source);
9613   }
9614}
9615
9616static WRITE8_HANDLER( mapper215_w )
9617{
9618   UINT8 MMC3_helper, cmd;
9619   static const UINT8 conv_table[8] = {0,2,5,3,6,1,7,4};
9620   LOG_MMC(("mapper215_w, offset: %04x, data: %02x\n", offset, data));
9621
9622   if (!map215_reg[2]) // in this case we act like MMC3, only with alt prg/chr handlers
9623   {
9624      switch (offset & 0x6001)
9625      {
9626      case 0x0000:
9627         MMC3_helper = mmc_cmd1 ^ data;
9628         mmc_cmd1 = data;
9629
9630         /* Has PRG Mode changed? */
9631         if (MMC3_helper & 0x40)
9632            mapper215_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
9633
9634         /* Has CHR Mode changed? */
9635         if (MMC3_helper & 0x80)
9636            mapper215_set_chr(space->machine, mmc_chr_source);
9637         break;
9638
9639      case 0x0001:
9640         cmd = mmc_cmd1 & 0x07;
9641         switch (cmd)
9642         {
9643         case 0: case 1:   // these do not need to be separated: we take care of them in set_chr!
9644         case 2: case 3: case 4: case 5:
9645            vrom_bank[cmd] = data;
9646            mapper215_set_chr(space->machine, mmc_chr_source);
9647            break;
9648         case 6:
9649         case 7:
9650            prg_bank[cmd - 6] = data;
9651            mapper215_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
9652            break;
9653         }
9654         break;
9655
9656      default:
9657         mapper4_w(space, offset, data);
9658         break;
9659      }
9660   }
9661   else
9662   {
9663      switch (offset & 0x6001)
9664      {
9665      case 0x0000:
9666         break;
9667
9668      case 0x0001:
9669         cmd = mmc_cmd1 & 0x07;
9670         if (map215_reg[3] && ((map215_reg[0] & 0x80) == 0 || cmd < 6))   // if we use the prg16 banks and cmd=6,7 DON'T enter!
9671         {
9672            map215_reg[3] = 0;
9673            switch (cmd)
9674            {
9675            case 0: case 1:   // these do not need to be separated: we take care of them in set_chr!
9676            case 2: case 3: case 4: case 5:
9677               vrom_bank[cmd] = data;
9678               mapper215_set_chr(space->machine, mmc_chr_source);
9679               break;
9680            case 6:
9681            case 7:
9682               prg_bank[cmd - 6] = data;
9683               mapper215_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
9684               break;
9685            }
9686         }
9687         break;
9688
9689      case 0x2000:
9690         data = (data & 0xc0) | conv_table[data & 0x07];
9691         MMC3_helper = mmc_cmd1 ^ data;
9692         mmc_cmd1 = data;
9693
9694         /* Has PRG Mode changed? */
9695         if (MMC3_helper & 0x40)
9696            mapper215_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
9697
9698         /* Has CHR Mode changed? */
9699         if (MMC3_helper & 0x80)
9700            mapper215_set_chr(space->machine, mmc_chr_source);
9701
9702         map215_reg[3] = 1;
9703         break;
9704
9705//      case 0x2001:
9706//          mapper4_w(space, 0x4001, data);
9707//          break;
9708
9709      case 0x4000:
9710         set_nt_mirroring(((data >> 7) | data) & 0x01 ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9711         break;
9712
9713      case 0x4001:
9714         mapper4_w(space, 0x6001, data);
9715         break;
9716
9717//      case 0x6000:
9718//          mapper4_w(space, 0x6000, data);
9719//          break;
9720
9721      case 0x6001:
9722         mapper4_w(space, 0x4000, data);
9723         mapper4_w(space, 0x4001, data);
9724         break;
9725
9726      default:
9727         mapper4_w(space, offset, data);
9728         break;
9729      }
9730   }
9731}
9732
81079733/*************************************************************
81089734
81099735    Mapper 216
r5997r5998
81359761
81369762    MMC3 clone
81379763
8138    In MESS: Unsupported.
9764    In MESS: Supported.
81399765
81409766*************************************************************/
81419767
9768// remove mask & base parameters!
9769static void mapper217_set_prg( running_machine *machine, int prg_base, int prg_mask )
9770{
9771   mmc_prg_base = (map217_reg[1] & 0x08) ? 0 : (map217_reg[1] & 0x10);
9772   mmc_prg_mask = (map217_reg[1] & 0x08) ? 0x1f : 0x0f;
9773
9774   mmc_prg_base |= ((map217_reg[1] & 0x03) << 5);
9775
9776   mapper4_set_prg(machine, mmc_prg_base, mmc_prg_mask);
9777}
9778
9779static void mapper217_set_chr( running_machine *machine, UINT8 chr )
9780{
9781   UINT8 chr_page = (mmc_cmd1 & 0x80) >> 5;
9782   int chr_base = (map217_reg[1] & 0x08) ? 0x00 : ((map217_reg[1] & 0x10) << 3);
9783   int chr_mask = (map217_reg[1] & 0x08) ? 0xff : 0x7f;
9784
9785   chr_base |= ((map217_reg[1] & 0x03) << 8);
9786
9787   chr1_x(machine, chr_page ^ 0, chr_base | ((vrom_bank[0] & ~0x01) & chr_mask), chr);
9788   chr1_x(machine, chr_page ^ 1, chr_base | ((vrom_bank[0] |  0x01) & chr_mask), chr);
9789   chr1_x(machine, chr_page ^ 2, chr_base | ((vrom_bank[1] & ~0x01) & chr_mask), chr);
9790   chr1_x(machine, chr_page ^ 3, chr_base | ((vrom_bank[1] |  0x01) & chr_mask), chr);
9791   chr1_x(machine, chr_page ^ 4, chr_base | (vrom_bank[2] & chr_mask), chr);
9792   chr1_x(machine, chr_page ^ 5, chr_base | (vrom_bank[3] & chr_mask), chr);
9793   chr1_x(machine, chr_page ^ 6, chr_base | (vrom_bank[4] & chr_mask), chr);
9794   chr1_x(machine, chr_page ^ 7, chr_base | (vrom_bank[5] & chr_mask), chr);
9795}
9796
9797static WRITE8_HANDLER( mapper217_l_w )
9798{
9799   UINT8 bank;
9800   LOG_MMC(("mapper217_l_w, offset: %04x, data: %02x\n", offset, data));
9801   offset += 0x100;
9802
9803   if (offset == 0x1000)
9804   {
9805      map217_reg[0] = data;
9806      if (data & 0x80)
9807      {
9808         bank = (data & 0x0f) | ((map217_reg[1] & 0x03) << 4);
9809         prg16_89ab(space->machine, bank);
9810         prg16_cdef(space->machine, bank);
9811      }
9812      else
9813         mapper217_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
9814   }
9815   else if (offset == 0x1001)
9816   {
9817      map217_reg[1] = data;
9818      mapper217_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
9819   }
9820   else if (offset == 0x1007)
9821   {
9822      map217_reg[2] = data;
9823   }
9824}
9825
9826static WRITE8_HANDLER( mapper217_w )
9827{
9828   UINT8 MMC3_helper, cmd;
9829   static const UINT8 conv_table[8] = {0, 6, 3, 7, 5, 2, 4, 1};
9830   LOG_MMC(("mapper217_w, offset: %04x, data: %02x\n", offset, data));
9831
9832   if (!map217_reg[2]) // in this case we act like MMC3, only with alt prg/chr handlers
9833   {
9834      switch (offset & 0x6001)
9835      {
9836      case 0x0000:
9837         MMC3_helper = mmc_cmd1 ^ data;
9838         mmc_cmd1 = data;
9839
9840         /* Has PRG Mode changed? */
9841         if (MMC3_helper & 0x40)
9842            mapper217_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
9843
9844         /* Has CHR Mode changed? */
9845         if (MMC3_helper & 0x80)
9846            mapper217_set_chr(space->machine, mmc_chr_source);
9847         break;
9848
9849      case 0x0001:
9850         cmd = mmc_cmd1 & 0x07;
9851         switch (cmd)
9852         {
9853         case 0: case 1:   // these do not need to be separated: we take care of them in set_chr!
9854         case 2: case 3: case 4: case 5:
9855            vrom_bank[cmd] = data;
9856            mapper217_set_chr(space->machine, mmc_chr_source);
9857            break;
9858         case 6:
9859         case 7:
9860            prg_bank[cmd - 6] = data;
9861            mapper217_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
9862            break;
9863         }
9864         break;
9865
9866      default:
9867         mapper4_w(space, offset, data);
9868         break;
9869      }
9870   }
9871   else
9872   {
9873      switch (offset & 0x6001)
9874      {
9875      case 0x0000:
9876         mapper4_w(space, 0xc000, data);
9877         break;
9878
9879      case 0x0001:
9880         data = (data & 0xc0) | conv_table[data & 0x07];
9881         MMC3_helper = mmc_cmd1 ^ data;
9882         mmc_cmd1 = data;
9883
9884         /* Has PRG Mode changed? */
9885         if (MMC3_helper & 0x40)
9886            mapper217_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
9887
9888         /* Has CHR Mode changed? */
9889         if (MMC3_helper & 0x80)
9890            mapper217_set_chr(space->machine, mmc_chr_source);
9891
9892         map217_reg[3] = 1;
9893         break;
9894
9895      case 0x2000:
9896         cmd = mmc_cmd1 & 0x07;
9897         if (map217_reg[3])
9898         {
9899            map217_reg[3] = 0;
9900            switch (cmd)
9901            {
9902            case 0: case 1:   // these do not need to be separated: we take care of them in set_chr!
9903            case 2: case 3: case 4: case 5:
9904               vrom_bank[cmd] = data;
9905               mapper217_set_chr(space->machine, mmc_chr_source);
9906               break;
9907            case 6:
9908            case 7:
9909               prg_bank[cmd - 6] = data;
9910               mapper217_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
9911               break;
9912            }
9913         }
9914         break;
9915
9916
9917      case 0x2001:
9918         set_nt_mirroring(data & 0x01 ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9919         break;
9920
9921      default:
9922         mapper4_w(space, offset, data);
9923         break;
9924      }
9925   }
9926}
9927
81429928/*************************************************************
81439929
81449930    Mapper 218
r5997r5998
823610022
823710023*************************************************************/
823810024
10025/* Scanline based IRQ ? */
10026static void mapper222_irq( const device_config *device, int scanline, int vblank, int blanked )
10027{
10028   if (scanline < PPU_BOTTOM_VISIBLE_SCANLINE)
10029   {
10030      if (!IRQ_count || ++IRQ_count < 240)
10031         return;
10032
10033      IRQ_count = 0;
10034      LOG_MMC(("irq fired, scanline: %d (MAME %d, beam pos: %d)\n", scanline,
10035            video_screen_get_vpos(device->machine->primary_screen), video_screen_get_hpos(device->machine->primary_screen)));
10036      cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
10037   }
10038}
10039
10040static WRITE8_HANDLER( mapper222_w )
10041{
10042   UINT8 bank;
10043   LOG_MMC(("mapper222_w, offset: %04x, data: %02x\n", offset, data));
10044
10045   switch (offset & 0x7003)
10046   {
10047   case 0x0000:
10048      prg8_89(space->machine, data);
10049      break;
10050   case 0x1000:
10051      set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
10052      break;
10053   case 0x2000:
10054      prg8_ab(space->machine, data);
10055      break;
10056   case 0x3000:
10057   case 0x3002:
10058   case 0x4000:
10059   case 0x4002:
10060   case 0x5000:
10061   case 0x5002:
10062   case 0x6000:
10063   case 0x6002:
10064      bank = ((offset & 0x7000) - 0x3000) / 0x0800 + ((offset & 0x0002) >> 3);
10065      chr1_x(space->machine, bank, data, CHRROM);
10066      break;
10067   case 0x7000:
10068      IRQ_count = data;
10069      break;
10070   }
10071}
10072
823910073/*************************************************************
824010074
824110075    Mapper 223
r5997r5998
839910233    Known Boards: Bootleg Board by Active Enterprise
840010234    Games: Action 52, Cheetah Men II
840110235
8402    In MESS: Only Partially Supported.
10236    In MESS: Partially Supported.
840310237
840410238*************************************************************/
840510239
840610240static WRITE8_HANDLER( mapper228_w )
840710241{
8408   /* The address lines double as data */
8409   /* --mPPppppPP-cccc */
8410   int bank;
8411   int chr;
8412
10242   int prg_bank, prg_chip, chr_bank;
10243   UINT8 prg_mode;
841310244   LOG_MMC(("mapper228_w, offset: %04x, data: %02x\n", offset, data));
841410245
8415   /* Determine low 4 bits of program bank */
8416   bank = (offset & 0x780) >> 7;
10246   set_nt_mirroring((offset & 0x2000) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
841710247
8418#if 1
8419   /* Determine high 2 bits of program bank */
8420   switch (offset & 0x1800)
10248   chr_bank = (data & 0x03) | ((offset & 0x0f) << 2);
10249   chr8(space->machine, chr_bank, CHRROM);
10250
10251   prg_bank = (offset & 0x7c0) >> 6;
10252   prg_chip = (offset & 0x1800) >> 11;
10253   prg_mode = offset & 0x20;
10254
10255   switch (prg_chip)
842110256   {
8422      case 0x0800:
8423         bank |= 0x10;
8424         break;
8425      case 0x1800:
8426         bank |= 0x20;
8427         break;
10257      case 0: break;         // we are already at the correct bank
10258      case 1: prg_bank |= 0x10; break;   // chip 1 starts at block 16
10259      case 2: break;         // chip 2 was an empty socket
10260      case 3: prg_bank |= 0x20; break;   // chip 3 starts at block 32
842810261   }
8429#else
8430   bank |= (offset & 0x1800) >> 7;
8431#endif
843210262
8433   /* see if the bank value is 16k or 32k */
8434   if (offset & 0x20)
10263   if (prg_mode)
843510264   {
8436      /* 16k bank value, adjust */
8437      bank <<= 1;
8438      if (offset & 0x40)
8439         bank ++;
8440
8441      prg16_89ab(space->machine, bank);
8442      prg16_cdef(space->machine, bank);
10265      prg16_89ab(space->machine, prg_bank);
10266      prg16_cdef(space->machine, prg_bank);
844310267   }
844410268   else
8445   {
8446      prg32(space->machine, bank);
8447   }
8448
8449   if (offset & 0x2000)
8450      set_nt_mirroring(PPU_MIRROR_HORZ);
8451   else
8452      set_nt_mirroring(PPU_MIRROR_VERT);
8453
8454   /* Now handle vrom banking */
8455   chr = (data & 0x03) + ((offset & 0x0f) << 2);
8456   chr8(space->machine, chr, CHRROM);
10269      prg32(space->machine, prg_bank >> 1);
845710270}
845810271
845910272/*************************************************************
r5997r5998
849310306    Known Boards: Unknown Bootleg Multigame Board
849410307    Games: 22 in 1
849510308
8496    In MESS: Supported. Needs a reset to work (not possible yet)
10309    In MESS: Partially Supported. It would need a reset
10310       to work (not possible yet)
849710311
849810312*************************************************************/
849910313
r5997r5998
853910353   set_nt_mirroring((offset & 0x80) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
854010354
854110355   prg16_89ab(space->machine, (offset & 0x1e));
8542   prg16_cdef(space->machine, (offset & 0x1e) + (data & 0x20) ? 1 : 0);
10356   prg16_cdef(space->machine, (offset & 0x1e) | ((offset & 0x20) ? 1 : 0));
854310357}
854410358
854510359/*************************************************************
r5997r5998
872110535    Simple mapper: writes to 0x8000-0xffff sets prg32 banks to
872210536        (offset>>3)&f. written data&3 sets the mirroring (with
872310537        switched high/low compared to the standard one). However,
8724        a second variant DQ7 and requires no NT mirroring.
8725        Currently, we do not support this variant.
10538        a second variant DQ8 and requires no NT mirroring.
872610539
8727    In MESS: Partial Support.
10540    A crc check is required to support Dragon Quest VIII (which
10541    uses a slightly different board)
872810542
10543    In MESS: Supported.
10544
872910545*************************************************************/
873010546
873110547static WRITE8_HANDLER( mapper242_w )
873210548{
873310549   LOG_MMC(("mapper242_w, offset: %04x, data: %02x\n", offset, data));
873410550
8735   prg32(space->machine, (offset >> 3) & 0x0f);
10551   prg32(space->machine, offset >> 3);
873610552
8737   waixing_set_mirror(data & 0x03);
10553   if (!nes.crc_hack)   // DQ8 board does not have this / Zan Shi does
10554   {
10555      switch (data & 0x03)
10556      {
10557         case 0: set_nt_mirroring(PPU_MIRROR_VERT); break;
10558         case 1: set_nt_mirroring(PPU_MIRROR_HORZ); break;
10559         case 2: set_nt_mirroring(PPU_MIRROR_LOW); break;
10560         case 3: set_nt_mirroring(PPU_MIRROR_HIGH); break;
10561      }
10562   }
873810563}
873910564
874010565/*************************************************************
r5997r5998
875410579{
875510580   LOG_MMC(("mapper243_l_w, offset: %04x, data: %02x\n", offset, data));
875610581
8757   /* write happens only if we are at 0x4100 + k * 0x200,
8758    but 0x4100 is offset = 0 */
10582   /* write happens only if we are at 0x4100 + k * 0x200, but 0x4100 is offset = 0 */
875910583   if (!(offset & 0x100))
876010584   {
876110585      if (!(offset & 0x01))
r5997r5998
882910653    Mapper 245
883010654
883110655    Known Boards: Type H by Waixing
8832    Games: Ying Xiong Yuan Yi Jing Chuan Qi
10656    Games: Ying Xiong Yuan Yi Jing Chuan Qi, Yong Zhe Dou E
10657         Long - Dragon Quest VII
883310658
883410659    MMC3 clone. More info to come.
883510660
8836    In MESS: Unsupported.
10661    In MESS: Supported.
883710662
883810663*************************************************************/
883910664
10665static WRITE8_HANDLER( mapper245_w )
10666{
10667   UINT8 cmd, map245_helper;
10668   LOG_MMC(("mapper245_w, offset: %04x, data: %02x\n", offset, data));
10669
10670   switch (offset & 0x6001)
10671   {
10672   case 0x0001:
10673      cmd = mmc_cmd1 & 0x0f;
10674      switch (cmd)
10675      {
10676      case 0:    // in this case we set prg_base in addition to vrom_bank!
10677         mmc_prg_base = (data << 5) & 0x40;
10678         mmc_prg_mask = 0x3f;
10679         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
10680      case 1: case 2: case 3: case 4: case 5:
10681         vrom_bank[cmd] = data;
10682         if (nes.chr_chunks > 0)
10683            mapper4_set_chr(space->machine, CHRROM, mmc_chr_base, mmc_chr_mask);
10684         else   // according to Disch's docs, mmc_cmd1&0x80 swaps 4k CHRRAM banks
10685         {
10686            map245_helper = /*(mmc_cmd1 & 0x80) ? 1 : */0;
10687            chr4_0(space->machine, 0 ^ map245_helper, CHRRAM);
10688            chr4_4(space->machine, 1 ^ map245_helper, CHRRAM);
10689         }
10690         break;
10691      case 6:
10692      case 7:
10693         prg_bank[cmd - 6] = data;
10694         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
10695         break;
10696      }
10697      break;
10698
10699   case 0x2001:
10700      break;
10701
10702   default:
10703      mapper4_w(space, offset, data);
10704      break;
10705   }
10706}
10707
884010708/*************************************************************
884110709
884210710    Mapper 246
r5997r5998
891710785
891810786    Mapper 249
891910787
8920    Known Boards: Waixing Security 0 & 1
10788    Known Boards: Waixing with Security Chip
892110789    Games: Duo Bao Xiao Ying Hao - Guang Ming yu An Hei Chuan Shuo,
892210790           Myth Struggle, San Shi Liu Ji, Shui Hu Zhuan
892310791
892410792    MMC3 clone
892510793
8926    In MESS: Unsupported.
10794    In MESS: Partially Supported.
892710795
892810796*************************************************************/
892910797
10798static void mapper249_set_prg( running_machine *machine, int prg_base, int prg_mask )
10799{
10800   int i;
10801
10802   if (map249_reg)
10803   {
10804      for (i = 0; i < 4; i ++)   // should this apply only to bank[0],bank[1]?
10805      {
10806         prg_bank[i] = ((prg_bank[i] & 0x01)) | ((prg_bank[i] >> 3) & 0x02) |
10807               ((prg_bank[i] >> 1) & 0x04) | ((prg_bank[i] << 2) & 0x18);
10808      }
10809   }
10810
10811   mapper4_set_prg(machine, prg_base, prg_mask);
10812}
10813
10814static void mapper249_set_chr( running_machine *machine, int chr_base, int chr_mask )
10815{
10816   UINT8 chr_page = (mmc_cmd1 & 0x80) >> 5;
10817   int i;
10818
10819   if (map249_reg)
10820   {
10821      for (i = 0; i < 6; i ++)
10822      {
10823         vrom_bank[i] = ((vrom_bank[i] & 0x03)) | ((vrom_bank[i] >> 1) & 0x04) |
10824                  ((vrom_bank[i] >> 4) & 0x08) | ((vrom_bank[i] >> 2) & 0x10) |
10825                  ((vrom_bank[i] << 3) & 0x20) | ((vrom_bank[i] << 2) & 0xc0);
10826      }
10827   }
10828
10829   chr1_x(machine, chr_page ^ 0, chr_base | ((vrom_bank[0] & ~0x01) & chr_mask), mmc_chr_source);
10830   chr1_x(machine, chr_page ^ 1, chr_base | ((vrom_bank[0] |  0x01) & chr_mask), mmc_chr_source);
10831   chr1_x(machine, chr_page ^ 2, chr_base | ((vrom_bank[1] & ~0x01) & chr_mask), mmc_chr_source);
10832   chr1_x(machine, chr_page ^ 3, chr_base | ((vrom_bank[1] |  0x01) & chr_mask), mmc_chr_source);
10833   chr1_x(machine, chr_page ^ 4, chr_base | (vrom_bank[2] & chr_mask), mmc_chr_source);
10834   chr1_x(machine, chr_page ^ 5, chr_base | (vrom_bank[3] & chr_mask), mmc_chr_source);
10835   chr1_x(machine, chr_page ^ 6, chr_base | (vrom_bank[4] & chr_mask), mmc_chr_source);
10836   chr1_x(machine, chr_page ^ 7, chr_base | (vrom_bank[5] & chr_mask), mmc_chr_source);
10837}
10838
10839static WRITE8_HANDLER( mapper249_l_w )
10840{
10841   LOG_MMC(("mapper249_l_w, offset: %04x, data: %02x\n", offset, data));
10842
10843   offset += 0x100;
10844
10845   if (offset == 0x1000)
10846   {
10847      map249_reg = data & 0x02;
10848      mapper249_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
10849      mapper249_set_chr(space->machine, mmc_prg_base, mmc_prg_mask);
10850   }
10851}
10852
10853static WRITE8_HANDLER( mapper249_w )
10854{
10855   UINT8 MMC3_helper, cmd;
10856   LOG_MMC(("mapper249_w, offset: %04x, data: %02x\n", offset, data));
10857
10858   switch (offset & 0x6001)
10859   {
10860   case 0x0000:
10861      MMC3_helper = mmc_cmd1 ^ data;
10862      mmc_cmd1 = data;
10863
10864      /* Has PRG Mode changed? */
10865      if (MMC3_helper & 0x40)
10866         mapper249_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
10867
10868      /* Has CHR Mode changed? */
10869      if (MMC3_helper & 0x80)
10870         mapper249_set_chr(space->machine, mmc_chr_base, mmc_chr_mask);
10871      break;
10872
10873   case 0x0001:
10874      cmd = mmc_cmd1 & 0x07;
10875      switch (cmd)
10876      {
10877      case 0: case 1:   // these do not need to be separated: we take care of them in set_chr!
10878      case 2: case 3: case 4: case 5:
10879         vrom_bank[cmd] = data;
10880         mapper249_set_chr(space->machine, mmc_chr_base, mmc_chr_mask);
10881         break;
10882      case 6:
10883      case 7:
10884         prg_bank[cmd - 6] = data;
10885         mapper249_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
10886         break;
10887      }
10888      break;
10889
10890   default:
10891      mapper4_w(space, offset, data);
10892      break;
10893   }
10894}
10895
893010896/*************************************************************
893110897
893210898    Mapper 250
r5997r5998
893510901    Games: Time Diver Avenger
893610902
893710903    This acts basically like a MMC3 with different use of write
8938    address. According to NEStopia, there is also a slightly
8939    different way to set NT mirroring (see below).
10904    address.
894010905
894110906    In MESS: Supported.
894210907
r5997r5998
894610911{
894710912   LOG_MMC(("mapper250_w, offset: %04x, data: %02x\n", offset, data));
894810913
8949   switch (offset & 0x6001)
8950   {
8951   case 0x2000:
8952      set_nt_mirroring(data & 0x01 ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);   // diff with MMC3: not check for data & 0x40
8953      break;
8954   default:
8955      mapper4_w(space, (offset & 0x6000) | ((offset & 0x400) >> 10), offset & 0xff);
8956      break;
8957   }
10914   mapper4_w(space, (offset & 0x6000) | ((offset & 0x400) >> 10), offset & 0xff);
895810915}
895910916
896010917/*************************************************************
r5997r5998
897510932    Known Boards: Unknown Bootleg Board by Waixing
897610933    Games: San Guo Zhi
897710934
10935    This board uses Konami IRQ
10936
897810937    In MESS: Unsupported.
897910938
898010939*************************************************************/
898110940
10941static WRITE8_HANDLER( mapper252_w )
10942{
10943   UINT8 mmc_helper, bank;
10944   LOG_MMC(("mapper252_w, offset: %04x, data: %02x\n", offset, data));
10945
10946   switch (offset & 0x7000)
10947   {
10948   case 0x0000:
10949      prg8_89(space->machine, data);
10950      break;
10951   case 0x2000:
10952      prg8_ab(space->machine, data);
10953      break;
10954   case 0x3000:
10955   case 0x4000:
10956   case 0x5000:
10957   case 0x6000:
10958      bank = ((offset & 0x7000) - 0x3000) / 0x0800 + ((offset & 0x0008) >> 3);
10959      mmc_helper = offset & 0x04;
10960      if (mmc_helper)
10961         vrom_bank[bank] = (vrom_bank[bank] & 0x0f) | ((data & 0x0f) << 4);
10962      else
10963         vrom_bank[bank] = (vrom_bank[bank] & 0xf0) | (data & 0x0f);
10964      chr1_x(space->machine, bank, vrom_bank[bank], CHRROM);
10965      break;
10966   case 0xf000:
10967      switch (offset & 0x0c)
10968      {
10969      case 0x00:
10970         IRQ_count_latch = (IRQ_count_latch & 0xf0) | (data & 0x0f);
10971         break;
10972      case 0x04:
10973         IRQ_count_latch = (IRQ_count_latch & 0x0f) | ((data & 0x0f) << 4);
10974         break;
10975      case 0x08:
10976         IRQ_enable = data & 0x02;
10977         IRQ_enable_latch = data & 0x01;
10978         if (data & 0x02)
10979            IRQ_count = IRQ_count_latch;
10980         break;
10981      case 0x0c:
10982         IRQ_enable = IRQ_enable_latch;
10983         break;
10984      }
10985      break;
10986   }
10987}
10988
898210989/*************************************************************
898310990
898410991    Mapper 253
r5997r5998
901111018    Known Boards: Unknown Bootleg Board
901211019    Games: 110 in 1
901311020
9014    In MESS: Unsupported.
11021    In MESS: Preliminary support.
901511022
901611023*************************************************************/
901711024
r5997r5998
904011047
904111048static const mmc mmc_list[] =
904211049{
9043/*  INES   DESC                     LOW_W, LOW_R, MED_W, HIGH_W, PPU_latch, scanline CB, hblank CB */
9044   {  0, "No Mapper",            NULL, NULL, NULL, NULL, NULL, NULL, NULL },
9045   {  1, "MMC1",                 NULL, NULL, NULL, mapper1_w, NULL, NULL, NULL },
9046   {  2, "74161/32 ROM sw",      NULL, NULL, NULL, mapper2_w, NULL, NULL, NULL },
9047   {  3, "74161/32 VROM sw",     NULL, NULL, NULL, mapper3_w, NULL, NULL, NULL },
9048   {  4, "MMC3",                 NULL, NULL, NULL, mapper4_w, NULL, NULL, mapper4_irq },
9049   {  5, "MMC5",                 mapper5_l_w, mapper5_l_r, NULL, mapper5_w, NULL, NULL, mapper5_irq },
9050   {  7, "ROM Switch",           NULL, NULL, NULL, mapper7_w, NULL, NULL, NULL },
9051   {  8, "FFE F3xxxx",           NULL, NULL, NULL, mapper8_w, NULL, NULL, NULL },
9052   {  9, "MMC2",                 NULL, NULL, NULL, mapper9_w, mapper9_latch, NULL, NULL},
9053   { 10, "MMC4",                 NULL, NULL, NULL, mapper10_w, mapper9_latch, NULL, NULL },
9054   { 11, "Color Dreams Mapper",  NULL, NULL, NULL, mapper11_w, NULL, NULL, NULL },
9055   { 12, "Rex Soft DBZ5",        mapper12_l_w, mapper12_l_r, NULL, mapper12_w, NULL, NULL, mapper4_irq },
9056   { 13, "CP-ROM",               NULL, NULL,   NULL, mapper13_w, NULL, NULL, NULL },
9057   { 15, "100-in-1",             NULL, NULL, NULL, mapper15_w, NULL, NULL, NULL },
9058   { 16, "Bandai",               NULL, NULL, mapper16_m_w, mapper16_w, NULL,NULL,  bandai_irq },
9059   { 17, "FFE F8xxx",            mapper17_l_w, NULL, NULL, NULL, NULL, NULL, mapper4_irq },
9060   { 18, "Jaleco",               NULL, NULL, NULL, mapper18_w, NULL, NULL, jaleco_irq },
9061   { 19, "Namco 106",            mapper19_l_w, mapper19_l_r, NULL, mapper19_w, NULL, NULL, namcot_irq },
9062   { 20, "Famicom Disk System",  NULL, NULL, NULL, NULL, NULL, NULL, fds_irq },
9063   { 21, "Konami VRC 4",         NULL, NULL, NULL, konami_vrc4_w, NULL, NULL, konami_irq },
9064   { 22, "Konami VRC 2a",        NULL, NULL, NULL, konami_vrc2a_w, NULL, NULL, NULL },
9065   { 23, "Konami VRC 2b",        NULL, NULL, NULL, konami_vrc2b_w, NULL, NULL, konami_irq },
9066   { 24, "Konami VRC 6a",        NULL, NULL, NULL, konami_vrc6a_w, NULL, NULL, konami_irq },
9067   { 25, "Konami VRC 4",         NULL, NULL, NULL, konami_vrc4_w, NULL, NULL, konami_irq },
9068   { 26, "Konami VRC 6b",        NULL, NULL, NULL, konami_vrc6b_w, NULL, NULL, konami_irq },
9069   { 32, "Irem G-101",           NULL, NULL, NULL, mapper32_w, NULL, NULL, NULL },
9070   { 33, "Taito TC0190",         NULL, NULL, NULL, mapper33_w, NULL, NULL, NULL },
9071   { 34, "Nina-1",               NULL, NULL, mapper34_m_w, mapper34_w, NULL, NULL, NULL },
9072   { 36, "TXC Policeman",        NULL, NULL, NULL, mapper36_w, NULL, NULL, NULL },
9073   { 37, "ZZ Board",             NULL, NULL, mapper37_m_w, mapper4_w, NULL, NULL, mapper4_irq },
9074   { 38, "Crime Buster",         NULL, NULL, mapper38_m_w, NULL, NULL, NULL, NULL },
9075   { 39, "Subor Study n Game",   NULL, NULL, NULL, mapper39_w, NULL, NULL, NULL },
9076   { 40, "SMB2j (bootleg)",      NULL, NULL, NULL, mapper40_w, NULL, NULL, mapper40_irq },
9077   { 41, "Caltron 6-in-1",       NULL, NULL, mapper41_m_w, mapper41_w, NULL, NULL, NULL },
9078   { 42, "Mario Baby",           NULL, NULL, NULL, mapper42_w, NULL, NULL, NULL },
9079   { 43, "150-in-1",             NULL, NULL, NULL, mapper43_w, NULL, NULL, NULL },
9080   { 44, "7-in-1 MMC3",          NULL, NULL, NULL, mapper44_w, NULL, NULL, mapper4_irq },
9081   { 45, "X-in-1 MMC3",          NULL, NULL, mapper45_m_w, mapper4_w, NULL, NULL, mapper4_irq },
9082   { 46, "15-in-1 Color Dreams", NULL, NULL, mapper46_m_w, mapper46_w, NULL, NULL, NULL },
9083   { 47, "2-in-1 MMC3",          NULL, NULL, mapper47_m_w, mapper4_w, NULL, NULL, mapper4_irq },
9084   { 49, "4-in-1 MMC3",          NULL, NULL, mapper49_m_w, mapper4_w, NULL, NULL, mapper4_irq },
9085   { 51, "11-in-1",              NULL, NULL, mapper51_m_w, mapper51_w, NULL, NULL, NULL },
9086   { 52, "Mario 7-in-1",         NULL, NULL, mapper52_m_w, mapper4_w, NULL, NULL, mapper4_irq },
9087   { 57, "6-in-1",               NULL, NULL, NULL, mapper57_w, NULL, NULL, NULL },
9088   { 58, "X-in-1",               NULL, NULL, NULL, mapper58_w, NULL, NULL, NULL },
9089   { 61, "20-in-1",              NULL, NULL, NULL, mapper61_w, NULL, NULL, NULL },
9090   { 62, "X-in-1",               NULL, NULL, NULL, mapper62_w, NULL, NULL, NULL },
9091   { 64, "Tengen",               NULL, NULL, mapper64_m_w, mapper64_w, NULL, NULL, mapper4_irq },
9092   { 65, "Irem H3001",           NULL, NULL, NULL, mapper65_w, NULL, NULL, irem_irq },
9093   { 66, "74161/32 Jaleco",      NULL, NULL, NULL, mapper66_w, NULL, NULL, NULL },
9094   { 67, "SunSoft 3",            NULL, NULL, NULL, mapper67_w, NULL, NULL, mapper4_irq },
9095   { 68, "SunSoft 4",            NULL, NULL, NULL, mapper68_w, NULL, NULL, NULL },
9096   { 69, "SunSoft 5",            NULL, NULL, NULL, mapper69_w, NULL, NULL, sunsoft_irq },
9097   { 70, "74161/32 Bandai",      NULL, NULL, NULL, mapper70_w, NULL, NULL, NULL },
9098   { 71, "Camerica",             NULL, NULL, mapper71_m_w, mapper71_w, NULL, NULL, NULL },
9099   { 72, "74161/32 Jaleco",      NULL, NULL, NULL, mapper72_w, NULL, NULL, NULL },
9100   { 73, "Konami VRC 3",         NULL, NULL, NULL, mapper73_w, NULL, NULL, konami_irq },
9101   { 74, "Waixing Type A",       NULL, NULL, NULL, mapper74_w, NULL, NULL, mapper4_irq },
9102   { 75, "Konami VRC 1",         NULL, NULL, NULL, mapper75_w, NULL, NULL, NULL },
9103   { 76, "Namco 109",            NULL, NULL, NULL, mapper76_w, NULL, NULL, NULL },
9104   { 77, "74161/32 ?",           NULL, NULL, NULL, mapper77_w, NULL, NULL, NULL },
9105   { 78, "74161/32 Irem",        NULL, NULL, NULL, mapper78_w, NULL, NULL, NULL },
9106   { 79, "Nina-3 (AVE)",         mapper79_l_w, NULL, NULL, NULL, NULL, NULL, NULL },
9107   { 80, "Taito X1-005 Ver. A",  NULL, NULL, mapper80_m_w, NULL, NULL, NULL, NULL },
9108   { 82, "Taito C075",           NULL, NULL, mapper82_m_w, NULL, NULL, NULL, NULL },
9109   { 83, "Cony",                 mapper83_l_w, mapper83_l_r, NULL, mapper83_w, NULL, NULL, NULL },
9110   { 84, "Pasofami",             NULL, NULL, NULL, NULL, NULL, NULL, NULL },
9111   { 85, "Konami VRC 7",         NULL, NULL, NULL, konami_vrc7_w, NULL, NULL, konami_irq },
9112   { 86, "Jaleco Early Mapper 2",NULL, NULL, mapper86_m_w, NULL, NULL, NULL, NULL },
9113   { 87, "74161/32 VROM sw-a",   NULL, NULL, mapper87_m_w, NULL, NULL, NULL, NULL },
9114   { 88, "Namco 118",            NULL, NULL, NULL, mapper88_w, NULL, NULL, NULL },
9115   { 89, "Sunsoft Early",        NULL, NULL, NULL, mapper89_w, NULL, NULL, NULL },
9116// 90 - pirate mapper
9117   { 91, "HK-SF3 (bootleg)",     NULL, NULL, mapper91_m_w, NULL, NULL, NULL, NULL },
9118   { 92, "Jaleco Early Mapper 1",NULL, NULL, NULL, mapper92_w, NULL, NULL, NULL },
9119   { 93, "Sunsoft LS161",        NULL, NULL, NULL, mapper93_w, NULL, NULL, NULL },
9120   { 94, "Capcom LS161",         NULL, NULL, NULL, mapper94_w, NULL, NULL, NULL },
9121   { 95, "Namco ??",             NULL, NULL, NULL, mapper95_w, NULL, NULL, NULL },
9122   { 96, "74161/32",             NULL, NULL, NULL, mapper96_w, NULL, NULL, NULL },
9123   { 97, "Irem - PRG HI",        NULL, NULL, NULL, mapper97_w, NULL, NULL, NULL },
9124// 99 - vs. system
9125// 100 - images hacked to work with nesticle
9126   { 101, "?? LS161",            NULL, NULL, mapper101_m_w, mapper101_w, NULL, NULL, NULL },
9127   { 104, "Golden Five",         NULL, NULL, NULL, mapper104_w, NULL, NULL, NULL },
9128   { 107, "Magic Dragon",        NULL, NULL, NULL, mapper107_w, NULL, NULL, NULL },
9129   { 112, "Asper",               NULL, NULL, NULL, mapper112_w, NULL, NULL, NULL },
9130   { 113, "Sachen/Hacker/Nina",  mapper113_l_w, NULL, NULL, NULL, NULL, NULL, NULL },
9131   { 114, "The Lion King",       NULL, NULL, mapper114_m_w, mapper114_w, NULL, NULL, mapper4_irq },
9132   { 115, "Bao Qing Tian",       NULL, NULL, mapper115_m_w, mapper115_w, NULL, NULL, mapper115_irq },
9133   { 118, "MMC3?",               NULL, NULL, NULL, mapper118_w, NULL, NULL, mapper4_irq },
9134   { 119, "MMC3 - Pinbot",       NULL, NULL, NULL, mapper119_w, NULL, NULL, mapper4_irq },
9135   { 132, "TXC T22211A",         mapper132_l_w, mapper132_l_r, NULL, mapper132_w, NULL, NULL, NULL },
9136   { 133, "Sachen SA72008",      mapper133_l_w, NULL, mapper133_m_w, NULL, NULL, NULL, NULL },
9137   { 136, "Sachen TCU01",        mapper136_l_w, mapper136_l_r, NULL, NULL, NULL, NULL, NULL },
9138   { 137, "Sachen 8259D",        mapper137_l_w, NULL, mapper137_m_w, NULL, NULL, NULL, NULL },
9139   { 138, "Sachen 8259B",        mapper138_l_w, NULL, mapper138_m_w, NULL, NULL, NULL, NULL },
9140   { 139, "Sachen 8259C",        mapper139_l_w, NULL, mapper139_m_w, NULL, NULL, NULL, NULL },
9141   { 140, "Jaleco",              NULL, NULL, mapper_140_m_w, NULL, NULL, NULL, NULL },
9142   { 141, "Sachen 8259A",        mapper141_l_w, NULL, mapper141_m_w, NULL, NULL, NULL, NULL },
9143   { 143, "Sachen TCA01",        NULL, mapper143_l_r, NULL, NULL, NULL, NULL, NULL },
9144   { 144, "AGCI 50282",          NULL, NULL, NULL, mapper144_w, NULL, NULL, NULL }, //Death Race only
9145   { 145, "Sachen SA72007",      mapper145_l_w, NULL, NULL, NULL, NULL, NULL, NULL },
9146   { 146, "Sachen SA0161M",      mapper79_l_w, NULL, NULL, NULL, NULL, NULL, NULL }, // basically same as Mapper 79 (Nina006)
9147   { 147, "Sachen TCU02",        mapper147_l_w, NULL, mapper147_m_w, mapper147_w, NULL, NULL, NULL },
9148   { 148, "Sachen SA0037",       NULL, NULL, NULL, mapper148_w, NULL, NULL, NULL },
9149   { 149, "Sachen SA0036",       NULL, NULL, NULL, mapper149_w, NULL, NULL, NULL },
9150   { 150, "Sachen 74LS374B",     mapper150_l_w, mapper150_l_r, mapper150_m_w, NULL, NULL, NULL, NULL },
9151   { 152, "Taito Discrete",      NULL, NULL, NULL, mapper152_w, NULL, NULL, NULL },
9152   { 154, "Devil Man",           NULL, NULL, NULL, mapper154_w, NULL, NULL, NULL },
9153   { 155, "Devil Man",           NULL, NULL, NULL, mapper1_w, NULL, NULL, NULL }, // diff compared to MMC1 concern WRAM (unsupported for MMC1 as well, atm)
9154   { 156, "Open Corp. DAOU36",   NULL, NULL, NULL, mapper156_w, NULL, NULL, NULL },
9155   { 164, "Final Fantasy V",     mapper164_l_w, NULL, NULL, mapper164_w, NULL, NULL, NULL },
9156   { 166, "Subor Board Type 1",  NULL, NULL, NULL, mapper166_w, NULL, NULL, NULL },
9157   { 167, "Subor Board Type 2",  NULL, NULL, NULL, mapper167_w, NULL, NULL, NULL },
9158   { 171, "Kaiser KS7058",       NULL, NULL, NULL, mapper171_w, NULL, NULL, NULL },
9159   { 172, "TXC T22211B",         mapper132_l_w, mapper132_l_r, NULL, mapper172_w, NULL, NULL, NULL },
9160   { 173, "TXC T22211C",         mapper132_l_w, mapper173_l_r, NULL, mapper132_w, NULL, NULL, NULL },
9161   { 176, "Zhi Li Xiao Zhuan Yuan",mapper176_l_w, NULL, NULL, NULL, NULL, NULL, NULL },
9162   { 177, "Henggedianzi Board",  NULL, NULL, NULL, mapper177_w, NULL, NULL, NULL },
9163   { 178, "San Guo Zhong Lie Zhuan",mapper178_l_w, NULL, NULL, NULL, NULL, NULL, NULL },
9164   { 179, "Xing He Zhan Shi",    mapper179_l_w, NULL, NULL, mapper179_w, NULL, NULL, NULL },
9165   { 180, "Nihon Bussan - PRG HI",NULL, NULL, NULL, mapper180_w, NULL, NULL, NULL },
9166   { 182, "Super games",         NULL, NULL, NULL, mapper182_w, NULL, NULL, mapper182_irq },
9167   { 184, "Sunsoft VROM/4K",     NULL, NULL, mapper184_m_w, NULL, NULL, NULL, NULL },
9168   { 188, "UNROM reversed",      NULL, NULL, NULL, mapper188_w, NULL, NULL, NULL },
9169   { 193, "Fighting Hero",       NULL, NULL, mapper193_m_w, NULL, NULL, NULL, NULL },
9170   { 196, "Super Mario Bros. 11",NULL, NULL, NULL, mapper196_w, NULL, NULL, mapper4_irq },
9171   { 200, "X-in-1",              NULL, NULL, NULL, mapper200_w, NULL, NULL, NULL },
9172   { 201, "X-in-1",              NULL, NULL, NULL, mapper201_w, NULL, NULL, NULL },
9173   { 202, "150-in-1",            NULL, NULL, NULL, mapper202_w, NULL, NULL, NULL },
9174   { 203, "35-in-1",             NULL, NULL, NULL, mapper203_w, NULL, NULL, NULL },
9175   { 204, "64-in-1",             NULL, NULL, NULL, mapper204_w, NULL, NULL, NULL },
9176   { 206, "MIMIC-1",             NULL, NULL, NULL, mapper206_w, NULL, NULL, mapper4_irq },
9177   { 207, "Taito X1-005 Ver. B", NULL, NULL, mapper207_m_w, NULL, NULL, NULL, NULL },
9178   { 212, "Super HIK 300-in-1",  NULL, NULL, NULL, mapper212_w, NULL, NULL, NULL },
9179   { 213, "9999999-in-1",        NULL, NULL, NULL, mapper213_w, NULL, NULL, NULL },
9180   { 214, "Super Gun 20-in-1",   NULL, NULL, NULL, mapper214_w, NULL, NULL, NULL },
9181   { 216, "RCM GS2015",          NULL, NULL, NULL, mapper216_w, NULL, NULL, NULL },
9182   { 221, "X-in-1 (N625092)",    NULL, NULL, NULL, mapper221_w, NULL, NULL, NULL },
9183   { 225, "72-in-1 bootleg",     NULL, NULL, NULL, mapper225_w, NULL, NULL, NULL },
9184   { 226, "76-in-1 bootleg",     NULL, NULL, NULL, mapper226_w, NULL, NULL, NULL },
9185   { 227, "1200-in-1 bootleg",   NULL, NULL, NULL, mapper227_w, NULL, NULL, NULL },
9186   { 228, "Action 52",           NULL, NULL, NULL, mapper228_w, NULL, NULL, NULL },
9187   { 229, "31-in-1",             NULL, NULL, NULL, mapper229_w, NULL, NULL, NULL },
9188   { 230, "22-in-1",             NULL, NULL, NULL, mapper230_w, NULL, NULL, NULL },
9189   { 231, "Nina-7 (AVE)",        NULL, NULL, NULL, mapper231_w, NULL, NULL, NULL },
9190   { 232, "Quattro",             NULL, NULL, mapper232_w, mapper232_w, NULL, NULL, NULL },
9191// 234 - maxi-15
9192   { 240, "Jing Ke Xin Zhuan",   mapper240_l_w, NULL, NULL, NULL, NULL, NULL, NULL },
9193   { 241, "Education 18-in-1",   NULL, mapper241_l_r, NULL, mapper241_w, NULL, NULL, NULL },
9194   { 242, "Wai Xing Zhan Shi",   NULL, NULL, NULL, mapper242_w, NULL, NULL, NULL },
9195   { 243, "Sachen 74LS374A",     mapper243_l_w, NULL, NULL, NULL, NULL, NULL, NULL },
9196   { 244, "Decathlon",           NULL, NULL, NULL, mapper244_w, NULL, NULL, NULL },
9197   { 246, "Fong Shen Bang",      NULL, NULL, mapper246_m_w, NULL, NULL, NULL, NULL },
9198   { 250, "Time Diver Avenger",  NULL, NULL, NULL, mapper250_w, NULL, NULL, mapper4_irq },
9199   { 255, "X-in-1",              NULL, NULL, NULL, mapper255_w, NULL, NULL, NULL },
11050/*  INES   DESC                          LOW_W, LOW_R, MED_W, HIGH_W, PPU_latch, scanline CB, hblank CB */
11051   {  0, "No Mapper",                 NULL, NULL, NULL, NULL, NULL, NULL, NULL },
11052   {  1, "MMC1",                      NULL, NULL, NULL, mapper1_w, NULL, NULL, NULL },
11053   {  2, "Ux-ROM",                    NULL, NULL, NULL, mapper2_w, NULL, NULL, NULL },
11054   {  3, "Cx-ROM",                    NULL, NULL, NULL, mapper3_w, NULL, NULL, NULL },
11055   {  4, "MMC3",                      NULL, NULL, NULL, mapper4_w, NULL, NULL, mapper4_irq },
11056   {  5, "MMC5",                      mapper5_l_w, mapper5_l_r, NULL, mapper5_w, NULL, NULL, mapper5_irq },
11057   {  6, "FFE F4xxxx",                mapper6_l_w, NULL, NULL, mapper6_w, NULL, NULL, ffe_irq },
11058   {  7, "Ax-ROM",                    NULL, NULL, NULL, mapper7_w, NULL, NULL, NULL },
11059   {  8, "FFE F3xxxx",                NULL, NULL, NULL, mapper8_w, NULL, NULL, NULL },
11060   {  9, "MMC2",                      NULL, NULL, NULL, mapper9_w, mapper9_latch, NULL, NULL},
11061   { 10, "MMC4",                      NULL, NULL, NULL, mapper10_w, mapper9_latch, NULL, NULL },
11062   { 11, "Color Dreams",              NULL, NULL, NULL, mapper11_w, NULL, NULL, NULL },
11063   { 12, "Rex Soft DBZ5",             mapper12_l_w, mapper12_l_r, NULL, mapper12_w, NULL, NULL, mapper4_irq },
11064   { 13, "CP-ROM",                    NULL, NULL,   NULL, mapper13_w, NULL, NULL, NULL },
11065   { 14, "Rex Soft SL1632",           NULL, NULL, NULL, mapper14_w, NULL, NULL, mapper4_irq },
11066   { 15, "100-in-1",                  NULL, NULL, NULL, mapper15_w, NULL, NULL, NULL },
11067   { 16, "Bandai LZ93D50 - 24C02",    NULL, NULL, mapper16_m_w, mapper16_w, NULL,NULL,  bandai_irq },
11068   { 17, "FFE F8xxx",                 mapper17_l_w, NULL, NULL, NULL, NULL, NULL, ffe_irq },
11069   { 18, "Jaleco SS88006",            NULL, NULL, NULL, mapper18_w, NULL, NULL, jaleco_irq },
11070   { 19, "Namcot 106 + N106",         mapper19_l_w, mapper19_l_r, NULL, mapper19_w, NULL, NULL, namcot_irq },
11071   { 20, "Famicom Disk System",       NULL, NULL, NULL, NULL, NULL, NULL, fds_irq },
11072   { 21, "Konami VRC 4",              NULL, NULL, NULL, konami_vrc4_w, NULL, NULL, konami_irq },
11073   { 22, "Konami VRC 2a",             NULL, NULL, NULL, konami_vrc2a_w, NULL, NULL, NULL },
11074   { 23, "Konami VRC 2b",             NULL, NULL, NULL, konami_vrc2b_w, NULL, NULL, konami_irq },
11075   { 24, "Konami VRC 6a",             NULL, NULL, NULL, konami_vrc6a_w, NULL, NULL, konami_irq },
11076   { 25, "Konami VRC 4",              NULL, NULL, NULL, konami_vrc4_w, NULL, NULL, konami_irq },
11077   { 26, "Konami VRC 6b",             NULL, NULL, NULL, konami_vrc6b_w, NULL, NULL, konami_irq },
11078// 27 World Hero
11079// 28, 29, 30, 31 Unused
11080   { 32, "Irem G-101",                NULL, NULL, NULL, mapper32_w, NULL, NULL, NULL },
11081   { 33, "Taito TC0190FMC",           NULL, NULL, NULL, mapper33_w, NULL, NULL, NULL },
11082   { 34, "Nina-001",                  NULL, NULL, mapper34_m_w, mapper34_w, NULL, NULL, NULL },
11083// 35 Unused
11084   { 36, "TXC Policeman",             NULL, NULL, NULL, mapper36_w, NULL, NULL, NULL },
11085   { 37, "ZZ Board",                  NULL, NULL, mapper37_m_w, mapper4_w, NULL, NULL, mapper4_irq },
11086   { 38, "Crime Buster",              NULL, NULL, mapper38_m_w, NULL, NULL, NULL, NULL },
11087   { 39, "Subor Study n Game",        NULL, NULL, NULL, mapper39_w, NULL, NULL, NULL },
11088   { 40, "SMB2 JPN (bootleg)",        NULL, NULL, NULL, mapper40_w, NULL, NULL, mapper40_irq },
11089   { 41, "Caltron 6-in-1",            NULL, NULL, mapper41_m_w, mapper41_w, NULL, NULL, NULL },
11090   { 42, "Mario Baby",                NULL, NULL, NULL, mapper42_w, NULL, NULL, NULL },
11091   { 43, "150-in-1",                  NULL, NULL, NULL, mapper43_w, NULL, NULL, NULL },
11092   { 44, "SuperBig 7-in-1",           NULL, NULL, NULL, mapper44_w, NULL, NULL, mapper4_irq },
11093   { 45, "X-in-1 MMC3",               NULL, NULL, mapper45_m_w, mapper4_w, NULL, NULL, mapper4_irq },
11094   { 46, "Rumblestation",             NULL, NULL, mapper46_m_w, mapper46_w, NULL, NULL, NULL },
11095   { 47, "QJ Board",                  NULL, NULL, mapper47_m_w, mapper4_w, NULL, NULL, mapper4_irq },
11096   { 48, "Taito TC0190FMC PAL16R4",   NULL, NULL, NULL, mapper48_w, NULL, NULL, mapper4_irq },
11097   { 49, "Super HIK 4-in-1",          NULL, NULL, mapper49_m_w, mapper4_w, NULL, NULL, mapper4_irq },
11098   { 50, "SMB2 JPN (bootleg 2)",      mapper50_l_w, NULL, NULL, NULL, NULL, NULL, mapper50_irq },
11099   { 51, "Ballgames 11-in-1",         NULL, NULL, mapper51_m_w, mapper51_w, NULL, NULL, NULL },
11100   { 52, "Mario 7-in-1",              NULL, NULL, mapper52_m_w, mapper4_w, NULL, NULL, mapper4_irq },
11101// 53 Supervision 16-in-1
11102// 54 Novel Diamond X-in-1
11103// 55 Genius SMB
11104// 56 Kaiser KS202
11105   { 57, "GKA 6-in-1",                NULL, NULL, NULL, mapper57_w, NULL, NULL, NULL },
11106   { 58, "GKB X-in-1",                NULL, NULL, NULL, mapper58_w, NULL, NULL, NULL },
11107// 59 Unused
11108// 60 4-in-1 Reset based
11109   { 61, "Tetris Family 20-in-1",     NULL, NULL, NULL, mapper61_w, NULL, NULL, NULL },
11110   { 62, "Super 700-in-1",            NULL, NULL, NULL, mapper62_w, NULL, NULL, NULL },
11111// 63 CH001 X-in-1
11112   { 64, "Tengen 800032",             NULL, NULL, NULL, mapper64_w, NULL, NULL, mapper64_irq },
11113   { 65, "Irem H3001",                NULL, NULL, NULL, mapper65_w, NULL, NULL, irem_irq },
11114   { 66, "Gx-ROM",                    NULL, NULL, NULL, mapper66_w, NULL, NULL, NULL },
11115   { 67, "SunSoft 3",                 NULL, NULL, NULL, mapper67_w, NULL, NULL, mapper67_irq },
11116   { 68, "SunSoft 4",                 NULL, NULL, NULL, mapper68_w, NULL, NULL, NULL },
11117   { 69, "SunSoft FME",               NULL, NULL, NULL, mapper69_w, NULL, NULL, mapper69_irq },
11118   { 70, "74161/32 Bandai",           NULL, NULL, NULL, mapper70_w, NULL, NULL, NULL },
11119   { 71, "Camerica",                  NULL, NULL, mapper71_m_w, mapper71_w, NULL, NULL, NULL },
11120   { 72, "74161/32 Jaleco",           NULL, NULL, NULL, mapper72_w, NULL, NULL, NULL },
11121   { 73, "Konami VRC 3",              NULL, NULL, NULL, mapper73_w, NULL, NULL, konami_irq },
11122   { 74, "Waixing Type A",            NULL, NULL, NULL, mapper74_w, NULL, NULL, mapper4_irq },
11123   { 75, "Konami VRC 1",              NULL, NULL, NULL, mapper75_w, NULL, NULL, NULL },
11124   { 76, "Namco 3446",                NULL, NULL, NULL, mapper76_w, NULL, NULL, NULL },
11125   { 77, "Irem LROG017",              NULL, NULL, NULL, mapper77_w, NULL, NULL, NULL },
11126   { 78, "Irem Holy Diver",           NULL, NULL, NULL, mapper78_w, NULL, NULL, NULL },
11127   { 79, "Nina-03",                   mapper79_l_w, NULL, NULL, NULL, NULL, NULL, NULL },
11128   { 80, "Taito X1-005 Ver. A",       NULL, NULL, mapper80_m_w, NULL, NULL, NULL, NULL },
11129// 81 Unused
11130   { 82, "Taito X1-017",              NULL, NULL, mapper82_m_w, NULL, NULL, NULL, NULL },
11131   { 83, "Cony",                      mapper83_l_w, mapper83_l_r, NULL, mapper83_w, NULL, NULL, NULL },
11132   { 84, "Pasofami hacked images?",   NULL, NULL, NULL, NULL, NULL, NULL, NULL },
11133   { 85, "Konami VRC 7",              NULL, NULL, NULL, konami_vrc7_w, NULL, NULL, konami_irq },
11134   { 86, "Jaleco JF13",               NULL, NULL, mapper86_m_w, NULL, NULL, NULL, NULL },
11135   { 87, "74139/74",                  NULL, NULL, mapper87_m_w, NULL, NULL, NULL, NULL },
11136   { 88, "Namcot 34x3",               NULL, NULL, NULL, mapper88_w, NULL, NULL, NULL },
11137   { 89, "Sunsoft 2b",                NULL, NULL, NULL, mapper89_w, NULL, NULL, NULL },
11138// 90 JY Company Type A
11139   { 91, "HK-SF3 (bootleg)",          NULL, NULL, mapper91_m_w, NULL, NULL, NULL, mapper4_irq },
11140   { 92, "Jaleco JF19 / JF21",        NULL, NULL, NULL, mapper92_w, NULL, NULL, NULL },
11141   { 93, "Sunsoft 2A",                NULL, NULL, NULL, mapper93_w, NULL, NULL, NULL },
11142   { 94, "Capcom LS161",              NULL, NULL, NULL, mapper94_w, NULL, NULL, NULL },
11143   { 95, "Namcot 3425",               NULL, NULL, NULL, mapper95_w, NULL, NULL, NULL },
11144   { 96, "Bandai OekaKids",           NULL, NULL, NULL, mapper96_w, NULL, NULL, NULL },
11145   { 97, "Irem Kaiketsu",             NULL, NULL, NULL, mapper97_w, NULL, NULL, NULL },
11146// 98 Unused
11147// 99 VS. system
11148// 100 images hacked to work with nesticle?
11149   { 101, "Jaleco?? LS161",           NULL, NULL, mapper101_m_w, mapper101_w, NULL, NULL, NULL },
11150// 102 Unused
11151// 103 Bootleg cart 2708
11152   { 104, "Golden Five",              NULL, NULL, NULL, mapper104_w, NULL, NULL, NULL },
11153// 105 Nintendo World Championship
11154   { 106, "SMB3 (bootleg)",           NULL, NULL, NULL, mapper106_w, NULL, NULL, mapper106_irq },
11155   { 107, "Magic Dragon",             NULL, NULL, NULL, mapper107_w, NULL, NULL, NULL },
11156// 108 Whirlwind
11157// 109, 110 Unused
11158// 111 Ninja Ryuukenden Chinese?
11159   { 112, "Asder",                    NULL, NULL, NULL, mapper112_w, NULL, NULL, NULL },
11160   { 113, "Sachen/Hacker/Nina",       mapper113_l_w, NULL, NULL, NULL, NULL, NULL, NULL },
11161   { 114, "The Lion King",            NULL, NULL, mapper114_m_w, mapper114_w, NULL, NULL, mapper4_irq },
11162   { 115, "Kasing",                   NULL, NULL, mapper115_m_w, mapper115_w, NULL, NULL, mapper4_irq },
11163// 116 Someri Team
11164   { 117, "Future Media",             NULL, NULL, NULL, mapper117_w, NULL, NULL, mapper117_irq },
11165   { 118, "TKS-ROM / TLS-ROM",        NULL, NULL, NULL, mapper118_w, NULL, NULL, mapper4_irq },
11166   { 119, "TQ-ROM",                   NULL, NULL, NULL, mapper119_w, NULL, NULL, mapper4_irq },
11167// 120 FDS bootleg
11168   { 121, "K - Panda Prince",         mapper121_l_w, mapper121_l_r, NULL, mapper121_w, NULL, NULL, mapper4_irq },
11169// 122 Unused
11170// 123 K H2288
11171// 124, 125 Unused
11172// 126 Powerjoy 84-in-1
11173// 127, 128, 129, 130, 131 Unused
11174   { 132, "TXC T22211A",              mapper132_l_w, mapper132_l_r, NULL, mapper132_w, NULL, NULL, NULL },
11175   { 133, "Sachen SA72008",           mapper133_l_w, NULL, mapper133_m_w, NULL, NULL, NULL, NULL },
11176   { 134, "Family 4646B",             NULL, NULL, mapper134_m_w, mapper4_w, NULL, NULL, mapper4_irq },
11177// 135 Unused
11178   { 136, "Sachen TCU01",             mapper136_l_w, mapper136_l_r, NULL, NULL, NULL, NULL, NULL },
11179   { 137, "Sachen 8259D",             mapper137_l_w, NULL, mapper137_m_w, NULL, NULL, NULL, NULL },
11180   { 138, "Sachen 8259B",             mapper138_l_w, NULL, mapper138_m_w, NULL, NULL, NULL, NULL },
11181   { 139, "Sachen 8259C",             mapper139_l_w, NULL, mapper139_m_w, NULL, NULL, NULL, NULL },
11182   { 140, "Jaleco JF11",              NULL, NULL, mapper_140_m_w, NULL, NULL, NULL, NULL },
11183   { 141, "Sachen 8259A",             mapper141_l_w, NULL, mapper141_m_w, NULL, NULL, NULL, NULL },
11184// 142 Kaiser KS7032
11185   { 143, "Sachen TCA01",             NULL, mapper143_l_r, NULL, NULL, NULL, NULL, NULL },
11186   { 144, "AGCI 50282",               NULL, NULL, NULL, mapper144_w, NULL, NULL, NULL }, //Death Race only
11187   { 145, "Sachen SA72007",           mapper145_l_w, NULL, NULL, NULL, NULL, NULL, NULL },
11188   { 146, "Sachen SA0161M",           mapper79_l_w, NULL, NULL, NULL, NULL, NULL, NULL }, // basically same as Mapper 79 (Nina006)
11189   { 147, "Sachen TCU02",             mapper147_l_w, NULL, mapper147_m_w, mapper147_w, NULL, NULL, NULL },
11190   { 148, "Sachen SA0037",            NULL, NULL, NULL, mapper148_w, NULL, NULL, NULL },
11191   { 149, "Sachen SA0036",            NULL, NULL, NULL, mapper149_w, NULL, NULL, NULL },
11192   { 150, "Sachen 74LS374B",          mapper150_l_w, mapper150_l_r, mapper150_m_w, NULL, NULL, NULL, NULL },
11193// 151 Konami VS. system
11194   { 152, "Taito 74161/161",          NULL, NULL, NULL, mapper152_w, NULL, NULL, NULL },
11195   { 153, "Bandai LZ93D50",           NULL, NULL, mapper153_m_w, mapper153_w, NULL,NULL,  bandai_irq },
11196   { 154, "Namcot 34xx",              NULL, NULL, NULL, mapper154_w, NULL, NULL, NULL },
11197   { 155, "SK-ROM",                   NULL, NULL, NULL, mapper1_w, NULL, NULL, NULL }, // diff compared to MMC1 concern WRAM (unsupported for MMC1 as well, atm)
11198   { 156, "Open Corp. DAOU36",        NULL, NULL, NULL, mapper156_w, NULL, NULL, NULL },
11199   { 157, "Bandai Datach Board",      NULL, NULL, mapper16_m_w, mapper16_w, NULL,NULL,  bandai_irq },   // no Datach Reader -> we fall back to mapper 16
11200   { 158, "Tengen T800037",           NULL, NULL, NULL, mapper158_w, NULL, NULL, mapper64_irq },
11201   { 159, "Bandai LZ93D50 - 24C01",   NULL, NULL, mapper16_m_w, mapper16_w, NULL,NULL,  bandai_irq },
11202// 160, 161, 162 Unused
11203// 163 Nanjing
11204   { 164, "Final Fantasy V",          mapper164_l_w, NULL, NULL, mapper164_w, NULL, NULL, NULL },
11205// 165 Waixing SH2
11206   { 166, "Subor Board Type 1",       NULL, NULL, NULL, mapper166_w, NULL, NULL, NULL },
11207   { 167, "Subor Board Type 2",       NULL, NULL, NULL, mapper167_w, NULL, NULL, NULL },
11208// 168 Racermate Challenger II
11209// 169 Unused
11210// 170 Fujiya
11211   { 171, "Kaiser KS7058",            NULL, NULL, NULL, mapper171_w, NULL, NULL, NULL },
11212   { 172, "TXC T22211B",              mapper132_l_w, mapper132_l_r, NULL, mapper172_w, NULL, NULL, NULL },
11213   { 173, "TXC T22211C",              mapper132_l_w, mapper173_l_r, NULL, mapper132_w, NULL, NULL, NULL },
11214// 174 Unused
11215// 175 Kaiser KS7022
11216   { 176, "Zhi Li Xiao Zhuan Yuan",   mapper176_l_w, NULL, NULL, NULL, NULL, NULL, NULL },
11217   { 177, "Henggedianzi Board",       NULL, NULL, NULL, mapper177_w, NULL, NULL, NULL },
11218   { 178, "San Guo Zhong Lie Zhuan",  mapper178_l_w, NULL, NULL, NULL, NULL, NULL, NULL },
11219   { 179, "Xing He Zhan Shi",         mapper179_l_w, NULL, NULL, mapper179_w, NULL, NULL, NULL },
11220   { 180, "Nihon Bussan UN-ROM",      NULL, NULL, NULL, mapper180_w, NULL, NULL, NULL },
11221// 181 Unused
11222   { 182, "Hosenkan",                 NULL, NULL, NULL, mapper182_w, NULL, NULL, mapper4_irq },
11223// 183 FDS bootleg
11224   { 184, "Sunsoft 1",                NULL, NULL, mapper184_m_w, NULL, NULL, NULL, NULL },
11225   { 185, "CN-ROM",                   NULL, NULL, NULL, mapper185_w, NULL, NULL, NULL },
11226// 186 Fukutake
11227   { 187, "King of Fighters 96",      mapper187_l_w, mapper187_l_r, NULL, mapper187_w, NULL, NULL, mapper4_irq },
11228   { 188, "Bandai Karaoke",           NULL, NULL, NULL, mapper188_w, NULL, NULL, NULL },
11229   { 189, "TXC TW Board",             mapper189_l_w, NULL, mapper189_m_w, mapper189_w, NULL, NULL, mapper4_irq },
11230// 190 Unused
11231   { 191, "Waixing Type B",           NULL, NULL, NULL, mapper191_w, NULL, NULL, mapper4_irq },
11232   { 192, "Waixing Type C",           NULL, NULL, NULL, mapper192_w, NULL, NULL, mapper4_irq },
11233   { 193, "Fighting Hero",            NULL, NULL, mapper193_m_w, NULL, NULL, NULL, NULL },
11234   { 194, "Waixing Type D",           NULL, NULL, NULL, mapper194_w, NULL, NULL, mapper4_irq },
11235   { 195, "Waixing Type E",           NULL, NULL, NULL, mapper195_w, NULL, NULL, mapper4_irq },
11236   { 196, "Super Mario Bros. 11",     NULL, NULL, NULL, mapper196_w, NULL, NULL, mapper4_irq },
11237   { 197, "Super Fighter 3",          NULL, NULL, NULL, mapper197_w, NULL, NULL, mapper4_irq },
11238   { 198, "Waixing Type F",           NULL, NULL, NULL, mapper198_w, NULL, NULL, mapper4_irq },
11239   { 199, "Waixing Type G",           NULL, NULL, NULL, mapper199_w, NULL, NULL, mapper4_irq },
11240   { 200, "36-in-1",                  NULL, NULL, NULL, mapper200_w, NULL, NULL, NULL },
11241   { 201, "21-in-1",                  NULL, NULL, NULL, mapper201_w, NULL, NULL, NULL },
11242   { 202, "150-in-1",                 NULL, NULL, NULL, mapper202_w, NULL, NULL, NULL },
11243   { 203, "35-in-1",                  NULL, NULL, NULL, mapper203_w, NULL, NULL, NULL },
11244   { 204, "64-in-1",                  NULL, NULL, NULL, mapper204_w, NULL, NULL, NULL },
11245   { 205, "15-in-1",                  NULL, NULL, mapper205_m_w, mapper4_w, NULL, NULL, mapper4_irq },
11246   { 206, "MIMIC-1",                  NULL, NULL, NULL, mapper206_w, NULL, NULL, mapper4_irq },
11247   { 207, "Taito X1-005 Ver. B",      NULL, NULL, mapper207_m_w, NULL, NULL, NULL, NULL },
11248   { 208, "Gouder G3717",             mapper208_l_w, mapper208_l_r, NULL, mapper208_w, NULL, NULL, mapper4_irq },
11249// 209 JY Company Type B
11250// 210 Some emu uses this as Mapper 19 without some features
11251// 211 JY Company Type C
11252   { 212, "Super HIK 300-in-1",       NULL, NULL, NULL, mapper212_w, NULL, NULL, NULL },
11253   { 213, "9999999-in-1",             NULL, NULL, NULL, mapper213_w, NULL, NULL, NULL },
11254   { 214, "Super Gun 20-in-1",        NULL, NULL, NULL, mapper214_w, NULL, NULL, NULL },
11255   { 215, "Super Game Boogerman",     mapper215_l_w, NULL, NULL, mapper215_w, NULL, NULL, mapper4_irq },
11256   { 216, "RCM GS2015",               NULL, NULL, NULL, mapper216_w, NULL, NULL, NULL },
11257   { 217, "Golden Card 6-in-1",       mapper217_l_w, NULL, NULL, mapper217_w, NULL, NULL, mapper4_irq },
11258// 218 Unused
11259// 219 Bootleg a9746
11260// 220 Summer Carnival '92??
11261   { 221, "X-in-1 (N625092)",         NULL, NULL, NULL, mapper221_w, NULL, NULL, NULL },
11262   { 222, "Dragonninja Bootleg",      NULL, NULL, NULL, mapper222_w, NULL, NULL, mapper222_irq },
11263// 223 Waixing Type I
11264// 224 Waixing Type J
11265   { 225, "72-in-1 bootleg",          NULL, NULL, NULL, mapper225_w, NULL, NULL, NULL },
11266   { 226, "76-in-1 bootleg",          NULL, NULL, NULL, mapper226_w, NULL, NULL, NULL },
11267   { 227, "1200-in-1 bootleg",        NULL, NULL, NULL, mapper227_w, NULL, NULL, NULL },
11268   { 228, "Action 52",                NULL, NULL, NULL, mapper228_w, NULL, NULL, NULL },
11269   { 229, "31-in-1",                  NULL, NULL, NULL, mapper229_w, NULL, NULL, NULL },
11270   { 230, "22-in-1",                  NULL, NULL, NULL, mapper230_w, NULL, NULL, NULL },
11271   { 231, "20-in-1",                  NULL, NULL, NULL, mapper231_w, NULL, NULL, NULL },
11272   { 232, "Quattro",                  NULL, NULL, mapper232_w, mapper232_w, NULL, NULL, NULL },
11273// 233 Super 22 Games
11274// 234 AVE Maxi 15
11275// 235 Golden Game x-in-1
11276// 236 Game 800-in-1
11277// 237 Unused
11278// 238 Bootleg 6035052
11279// 239 Unused
11280   { 240, "Jing Ke Xin Zhuan",        mapper240_l_w, NULL, NULL, NULL, NULL, NULL, NULL },
11281   { 241, "Education 18-in-1",        NULL, mapper241_l_r, NULL, mapper241_w, NULL, NULL, NULL },
11282   { 242, "Wai Xing Zhan Shi",        NULL, NULL, NULL, mapper242_w, NULL, NULL, NULL },
11283   { 243, "Sachen 74LS374A",          mapper243_l_w, NULL, NULL, NULL, NULL, NULL, NULL },
11284   { 244, "Decathlon",                NULL, NULL, NULL, mapper244_w, NULL, NULL, NULL },
11285   { 245, "Waixing Type H",           NULL, NULL, NULL, mapper245_w, NULL, NULL, mapper4_irq },
11286   { 246, "Fong Shen Bang",           NULL, NULL, mapper246_m_w, NULL, NULL, NULL, NULL },
11287// 247, 248 Unused
11288   { 249, "Waixing Security Board",   mapper249_l_w, NULL, NULL, mapper249_w, NULL, NULL, mapper4_irq },
11289   { 250, "Time Diver Avenger",       NULL, NULL, NULL, mapper250_w, NULL, NULL, mapper4_irq },
11290// 251 Shen Hua Jian Yun III??
11291   { 252, "Waixing San Guo Zhi",      NULL, NULL, NULL, mapper252_w, NULL, NULL, konami_irq },
11292// 253 Super 8-in-1 99 King Fighter??
11293// 254 Pikachu Y2K
11294   { 255, "110-in-1",                 NULL, NULL, NULL, mapper255_w, NULL, NULL, NULL },
920011295};
920111296
920211297
r5997r5998
925511350
925611351   MMC5_vram_control = 0;
925711352
11353   /* Point the WRAM/battery area to the first RAM bank */
11354   if (mmc_num != 20)
11355      memory_set_bankptr(space->machine, 5, &nes.wram[0x0000]);
11356
925811357   /* Here, we init a few helpers: 4 prg banks and 16 chr banks - some mappers use them */
925911358   for (i = 0; i < 4; i++)
9260   {
926111359      prg_bank[i] = 0;
9262      vrom_bank[4 * i + 0] = 0;
9263      vrom_bank[4 * i + 1] = 0;
9264      vrom_bank[4 * i + 2] = 0;
9265      vrom_bank[4 * i + 3] = 0;
9266   }
11360   for (i = 0; i < 16; i++)
11361      vrom_bank[i] = 0;
11362   for (i = 0; i < 16; i++)
11363      extra_bank[i] = 0;
926711364
9268   /* Point the WRAM/battery area to the first RAM bank */
9269   if (mmc_num != 20 && mmc_num != 40)
9270      memory_set_bankptr(space->machine, 5, &nes.wram[0x0000]);
11365   /* Finally, we init IRQ-related quantities. */
11366   IRQ_enable = IRQ_enable_latch = 0;
11367   IRQ_count = IRQ_count_latch = 0;
11368   IRQ_toggle = 0;
927111369
927211370   switch (mmc_num)
927311371   {
r5997r5998
929611394         prg32(space->machine, 0);
929711395         break;
929811396      case 3:
9299         /* Doesn't bank-switch */
11397      case 185:
930011398         prg32(space->machine, 0);
930111399         break;
930211400      case 4:
9303      case 74:
930411401      case 206:
930511402         /* Only MMC3 and clones seem to use 4-screen! */
9306
930711403         /* hardware uses an 8K RAM chip, but can't address the high 4K! */
930811404         /* that much is documented for Nintendo Gauntlet boards */
930911405         if(nes.four_screen_vram)
r5997r5998
931511411            set_nt_page(3, CART_NTRAM, 3, 1);
931611412         }
931711413      case 12:
11414      case 74:
931811415      case 118:
931911416      case 119:
11417      case 191:
11418      case 192:
11419      case 194:
11420      case 195:
932011421      case 196:
11422      case 245:
932111423      case 250:
9322         /* Can switch 8k prg banks */
9323         IRQ_enable = 0;
9324         IRQ_count = IRQ_count_latch = 0;
9325         IRQ_reload = 0;
9326         prg_bank[0] = 0xfe;
9327         prg_bank[1] = 0xff;
9328         MMC3_cmd = 0;
11424         prg_bank[0] = prg_bank[2] = 0xfe;   // prg_bank[2] & prg_bank[3] remain always the same in most MMC3 variants
11425         prg_bank[1] = prg_bank[3] = 0xff;   // but some pirate clone mappers change them after writing certain registers
11426         mmc_cmd1 = 0;
932911427         mmc_cmd2 = 0x80;
933011428         mmc_prg_base = mmc_chr_base = 0;
9331         mmc_prg_mask = mmc_chr_mask = 0xff;
11429         mmc_prg_mask = mmc_chr_mask = 0xff;   // these could be init'ed as xxx_chunks-1 and they would work the same
933211430         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
933311431         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
933411432         mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
r5997r5998
933811436         MMC5_rom_bank_mode = 3;
933911437         MMC5_vrom_bank_mode = 0;
934011438         MMC5_vram_protect = 0;
9341         IRQ_enable = 0;
9342         IRQ_count = 0;
934311439         nes.mid_ram_enable = 0;
934411440         prg16_89ab(space->machine, nes.prg_chunks - 2);
934511441         prg16_cdef(space->machine, nes.prg_chunks - 1);
934611442         break;
11443      case 6:
11444         mmc_cmd1 = 0;
11445         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
11446         prg16_89ab(space->machine, 0);
11447         prg16_cdef(space->machine, 7);
11448         break;
934711449      case 7:
934811450         /* Bankswitches 32k at a time */
934911451         set_nt_mirroring(PPU_MIRROR_LOW);
935011452         prg16_89ab(space->machine, 0);
935111453         prg16_cdef(space->machine, nes.prg_chunks - 1);
935211454         break;
11455      case 8:
935311456      case 96:
9354      case 8:
9355         /* Switches 16k banks at $8000, 1st 2 16k banks loaded on reset */
935611457         prg32(space->machine, 0);
935711458         break;
935811459      case 9:
9359         /* Can switch 8k prg banks */
9360         /* Note that the iNES header defines the number of banks as 8k in size, rather than 16k */
9361         /* Reset VROM latches */
936211460         MMC2_regs[0] = MMC2_regs[2] = 0;
936311461         MMC2_regs[1] = MMC2_regs[3] = 0;
936411462         mmc_cmd1 = mmc_cmd2 = 0xfe;
r5997r5998
937611474         prg16_89ab(space->machine, 0);
937711475         prg16_cdef(space->machine, nes.prg_chunks - 1);
937811476         break;
9379      case 11:   /* Switches 32k banks, 1st 32k bank loaded on reset (?) May be more like mapper 7... */
11477      case 11:
11478         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;   // NINA-07 has no CHRROM
938011479         prg32(space->machine, 0);
938111480         break;
9382      case 15:   /* Can switch 8k prg banks */
11481      case 14:
11482         extra_bank[2] = 0xfe;
11483         extra_bank[3] = 0xff;
11484         extra_bank[0] = extra_bank[1] = extra_bank[4] = extra_bank[5] = extra_bank[6] = 0;
11485         extra_bank[7] = extra_bank[8] = extra_bank[9] = extra_bank[0xa] = extra_bank[0xb] = 0;
11486         map14_reg[0] = map14_reg[1] = 0;
11487         prg_bank[0] = prg_bank[2] = 0xfe;
11488         prg_bank[1] = prg_bank[3] = 0xff;
11489         mmc_cmd1 = 0;
11490         mmc_cmd2 = 0x80;
11491         mmc_prg_base = mmc_chr_base = 0;
11492         mmc_prg_mask = mmc_chr_mask = 0xff;
11493         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
11494         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
11495         mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
11496         break;
11497      case 15:
938311498         set_nt_mirroring(PPU_MIRROR_VERT);
938411499         prg32(space->machine, 0);
938511500         break;
938611501      case 16:
938711502      case 17:
938811503      case 18:
11504      case 157:
11505      case 159:
11506         mmc_cmd1 = 0;
11507         prg16_89ab(space->machine, 0);
11508         prg16_cdef(space->machine, nes.prg_chunks - 1);
11509         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
11510         break;
938911511      case 19:
11512         mmc_cmd1 = 0;
939011513         prg16_89ab(space->machine, 0);
939111514         prg16_cdef(space->machine, nes.prg_chunks - 1);
11515         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
11516         set_nt_mirroring(PPU_MIRROR_VERT);
939211517         break;
939311518      case 20:
9394         IRQ_enable = IRQ_enable_latch = 0;
9395         IRQ_count = IRQ_count_latch = 0;
11519         fds_last_side = 0;
11520         fds_count = 0;
939611521         nes_fds.motor_on = 0;
939711522         nes_fds.door_closed = 0;
939811523         nes_fds.current_side = 1;
r5997r5998
940111526         nes_fds.read_mode = nes_fds.write_reg = 0;
940211527         break;
940311528      case 21:
9404      case 25:
9405         IRQ_enable = IRQ_enable_latch = 0;
9406         IRQ_count = IRQ_count_latch = 0;
9407         /* fall through */
940811529      case 22:
940911530      case 23:
11531      case 24:
11532      case 25:
11533      case 26:
941011534      case 33:
11535      case 48:
11536      case 73:
11537      case 75:
11538      case 80:
11539      case 82:
11540      case 85:
11541      case 87:
11542      case 117:
11543      case 207:
11544      case 222:
11545      case 252:
11546         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
941111547         prg16_89ab(space->machine, 0);
941211548         prg16_cdef(space->machine, nes.prg_chunks - 1);
941311549         break;
r5997r5998
941511551         mmc_cmd1 = 0;
941611552         prg16_89ab(space->machine, 0);
941711553         prg16_cdef(space->machine, nes.prg_chunks - 1);
9418//          set_nt_mirroring(PPU_MIRROR_HIGH);  // this would be needed for Major League
11554         if (nes.crc_hack)
11555            set_nt_mirroring(PPU_MIRROR_HIGH);  // needed by Major League
941911556         break;
9420      case 24:
9421      case 26:
9422      case 73:
9423      case 75:
9424         IRQ_enable = IRQ_enable_latch = 0;
9425         IRQ_count = IRQ_count_latch = 0;
9426         prg16_89ab(space->machine, 0);
9427         prg16_cdef(space->machine, nes.prg_chunks - 1);
9428         break;
942911557      case 34:
9430         /* Can switch 32k prg banks */
943111558         prg32(space->machine, 0);
943211559         break;
943311560      case 37:
9434         IRQ_enable = 0;
9435         IRQ_count = IRQ_count_latch = 0;
9436         IRQ_reload = 0;
9437         prg_bank[0] = 0xfe;
9438         prg_bank[1] = 0xff;
9439         MMC3_cmd = 0;
11561         prg_bank[0] = prg_bank[2] = 0xfe;
11562         prg_bank[1] = prg_bank[3] = 0xff;
11563         mmc_cmd1 = 0;
944011564         mmc_cmd2 = 0x80;
944111565         mmc_prg_base = mmc_chr_base = 0;
944211566         mmc_prg_mask = 0x07;
r5997r5998
944611570         mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
944711571         break;
944811572      case 40:
9449         IRQ_enable = 0;
9450         IRQ_count = 0;
9451         /* Who's your daddy? */
9452         memcpy(&nes.rom[0x6000], &nes.rom[((nes.prg_chunks << 1) - 2) * 0x2000 + 0x10000], 0x2000);
9453         //ugly hack to deal with iNES header usage of chunk count.
9454         prg8_89(space->machine, (nes.prg_chunks << 1) - 4);
9455         prg8_ab(space->machine, (nes.prg_chunks << 1) - 3);
9456         prg8_cd(space->machine, 0);
9457         prg8_ef(space->machine, (nes.prg_chunks << 1) - 1);
11573         prg8_67(space->machine, 0xfe);
11574         prg8_89(space->machine, 0xfc);
11575         prg8_ab(space->machine, 0xfd);
11576         prg8_cd(space->machine, 0xfe);
11577         prg8_ef(space->machine, 0xff);
945811578         break;
945911579      case 41:
946011580         mmc_cmd1 = 0;
r5997r5998
947011590      case 44:
947111591      case 47:
947211592      case 49:
9473         IRQ_enable = 0;
9474         IRQ_count = IRQ_count_latch = 0;
9475         IRQ_reload = 0;
9476         prg_bank[0] = 0xfe;
9477         prg_bank[1] = 0xff;
9478         MMC3_cmd = 0;
11593         prg_bank[0] = prg_bank[2] = 0xfe;
11594         prg_bank[1] = prg_bank[3] = 0xff;
11595         mmc_cmd1 = 0;
947911596         mmc_cmd2 = 0x80;
948011597         mmc_prg_base = mmc_chr_base = 0;
948111598         mmc_prg_mask = 0x0f;
r5997r5998
948511602         mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
948611603         break;
948711604      case 45:
9488         IRQ_enable = 0;
9489         IRQ_count = IRQ_count_latch = 0;
9490         IRQ_reload = 0;
9491         prg_bank[0] = 0xfe;
9492         prg_bank[1] = 0xff;
11605         prg_bank[0] = prg_bank[2] = 0xfe;
11606         prg_bank[1] = prg_bank[3] = 0xff;
949311607         mmc_cmd1 = 0;
949411608         mmc_cmd2 = 0x80;
949511609         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
r5997r5998
950611620         prg32(space->machine, 0);
950711621         chr8(space->machine, 0, CHRROM);
950811622         break;
11623      case 50:
11624         prg8_67(space->machine, 0x0f);
11625         prg8_89(space->machine, 0x08);
11626         prg8_ab(space->machine, 0x09);
11627         prg8_cd(space->machine, 0);
11628         prg8_ef(space->machine, 0x0b);
11629         break;
11630      case 51:
11631         mapper51_reg[0] = 0x01;
11632         mapper51_reg[1] = 0x00;
11633         mapper51_set_banks(space->machine);
11634         break;
950911635      case 52:
9510         IRQ_enable = 0;
9511         IRQ_count = IRQ_count_latch = 0;
9512         IRQ_reload = 0;
951311636         prg_bank[0] = 0xfe;
11637         prg_bank[2] = 0xfe;
951411638         prg_bank[1] = 0xff;
11639         prg_bank[3] = 0xff;
951511640         mmc_cmd1 = 0;
951611641         mmc_cmd2 = 0x80;
951711642         map52_reg_written = 0;
r5997r5998
952411649         mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
952511650         memory_set_bankptr(space->machine, 5, nes.wram);
952611651         break;
9527      case 51:
9528         mapper51_reg[0] = 0x01;
9529         mapper51_reg[1] = 0x00;
9530         mapper51_reg[2] = 0x00;
9531         mapper51_set_banks(space->machine);
9532         break;
953311652      case 57:
953411653         mmc_cmd1 = 0x00;
953511654         mmc_cmd2 = 0x00;
r5997r5998
954711666         prg32(space->machine, 0);
954811667         break;
954911668      case 64:
9550         /* Can switch 3 8k prg banks */
11669      case 158:
11670         mmc_cmd1 = 0;
955111671         prg16_89ab(space->machine, nes.prg_chunks - 1);
955211672         prg16_cdef(space->machine, nes.prg_chunks - 1);
955311673         break;
955411674      case 65:
9555         IRQ_enable = 0;
9556         IRQ_count = 0;
9557         prg16_89ab(space->machine, 0);
9558         prg16_cdef(space->machine, nes.prg_chunks - 1);
9559         break;
956011675      case 67:
9561      case 68:
956211676      case 69:
956311677      case 71:
956411678      case 72:
956511679      case 78:
956611680      case 92:
9567         IRQ_enable = IRQ_enable_latch = 0;
9568         IRQ_count = IRQ_count_latch = 0;
956911681         prg16_89ab(space->machine, 0);
957011682         prg16_cdef(space->machine, nes.prg_chunks - 1);
957111683         break;
11684      case 68:
11685         m68_mirror = m0 = m1 = 0;
11686         prg16_89ab(space->machine, 0);
11687         prg16_cdef(space->machine, nes.prg_chunks - 1);
11688         break;
957211689      case 70:
957311690         prg16_89ab(space->machine, nes.prg_chunks - 2);
957411691         prg16_cdef(space->machine, nes.prg_chunks - 1);
r5997r5998
959811715         chr8(space->machine, 0, CHRROM);
959911716         prg32(space->machine, 0);
960011717         break;
9601      case 80:
9602      case 207:
9603      case 82:
9604      case 85:
9605         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
9606         prg16_89ab(space->machine, 0);
9607         prg16_cdef(space->machine, nes.prg_chunks - 1);
9608         break;
9609//      case 70:
9610      case 87:
961111718      case 228:
9612         prg16_89ab(space->machine, 0);
9613         prg16_cdef(space->machine, nes.prg_chunks - 1);
11719         chr8(space->machine, 0, CHRROM);
11720         prg32(space->machine, 0);
961411721         break;
961511722      case 83:
961611723         mapper83_reg[9] = 0x0f;
r5997r5998
967011777         prg16_89ab(space->machine, 0x00);
967111778         prg16_cdef(space->machine, 0x0f);
967211779         break;
11780      case 106:
11781         prg8_89(space->machine, (nes.prg_chunks << 1) - 1);
11782         prg8_ab(space->machine, 0);
11783         prg8_cd(space->machine, 0);
11784         prg8_ef(space->machine, (nes.prg_chunks << 1) - 1);
11785         break;
967311786      case 114:
9674         IRQ_enable = 0;
9675         IRQ_count = IRQ_count_latch = 0;
9676         IRQ_reload = 0;
967711787         map114_reg = map114_reg_enabled = 0;
9678         prg_bank[0] = 0xfe;
9679         prg_bank[1] = 0xff;
9680         MMC3_cmd = 0;
11788         prg_bank[0] = prg_bank[2] = 0xfe;
11789         prg_bank[1] = prg_bank[3] = 0xff;
11790         mmc_cmd1 = 0;
968111791         mmc_cmd2 = 0x80;
968211792         mmc_prg_base = mmc_chr_base = 0;
968311793         mmc_prg_mask = mmc_chr_mask = 0xff;
r5997r5998
968611796         mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
968711797         break;
968811798      case 115:
9689         mapper115_reg[0] = mapper115_reg[1] = mapper115_reg[2] = mapper115_reg[3] = 0;
9690         prg32(space->machine, 0xff);
11799         mapper115_reg[0] = 0;
11800         prg_bank[0] = prg_bank[2] = 0xfe;
11801         prg_bank[1] = prg_bank[3] = 0xff;
11802         mmc_cmd1 = 0;
11803         mmc_cmd2 = 0x80;
11804         mmc_prg_base = mmc_chr_base = 0;
11805         mmc_prg_mask = mmc_chr_mask = 0xff;
11806         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
11807         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
11808         mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
969111809         break;
11810      case 121:
11811         prg_bank[0] = prg_bank[2] = 0xfe;
11812         prg_bank[1] = prg_bank[3] = 0xff;
11813         mapper121_reg[0] = mapper121_reg[1] = mapper121_reg[2] = 0;
11814         mmc_cmd1 = 0;
11815         mmc_cmd2 = 0x80;
11816         mmc_prg_base = mmc_chr_base = 0;
11817         mmc_prg_mask = mmc_chr_mask = 0xff;
11818         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
11819         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
11820         mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
11821         break;
969211822      case 132:
969311823      case 172:
969411824      case 173:
969511825         txc_reg[0] = txc_reg[1] = txc_reg[2] = txc_reg[3] = 0;
969611826         prg32(space->machine, 0);
969711827         break;
11828      case 134:
11829         prg_bank[0] = prg_bank[2] = 0xfe;
11830         prg_bank[1] = prg_bank[3] = 0xff;
11831         mmc_cmd1 = 0;
11832         mmc_cmd2 = 0x80;
11833         mmc_prg_base = mmc_chr_base = 0;
11834         mmc_prg_mask = 0x1f;
11835         mmc_chr_mask = 0xff;
11836         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
11837         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
11838         mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
11839         break;
969811840      case 166:
969911841         subor_reg[0] = subor_reg[1] = subor_reg[2] = subor_reg[3] = 0;
970011842         prg16_89ab(space->machine, 0);
r5997r5998
971811860      case 138:
971911861      case 139:
972011862      case 141:
11863         mmc_cmd1 = 0;
972111864         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
9722         mmc_cmd1 = 0;
972311865         prg32(space->machine, 0);
972411866         chr8(space->machine, 0, mmc_chr_source);
972511867         set_nt_mirroring(PPU_MIRROR_VERT);
r5997r5998
974911891         prg16_cdef(space->machine, nes.prg_chunks - 1);
975011892         chr8(space->machine, 0, CHRROM);
975111893         break;
11894      case 153:
11895         mmc_cmd1 = 0;
11896         prg16_89ab(space->machine, 0);
11897         prg16_cdef(space->machine, nes.prg_chunks - 1);
11898         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
11899         // Famicom Jump II needs also the following!
11900         for (i = 0; i < 8; i++)
11901            map153_reg[i] = 0;
11902
11903         map153_bank_latch = 0;
11904         if (nes.crc_hack)
11905            mapper153_set_prg(space->machine);
11906         break;
975211907      case 154:
975311908         prg16_89ab(space->machine, nes.prg_chunks - 2);
975411909         prg16_cdef(space->machine, nes.prg_chunks - 1);
r5997r5998
977411929         prg16_cdef(space->machine, 0);
977511930         break;
977611931      case 182:
9777         IRQ_enable = 0;
9778         IRQ_count = 0;
977911932         prg32(space->machine, (nes.prg_chunks - 1) >> 1);
978011933         break;
978111934      case 188:
978211935         prg16_89ab(space->machine, 0);
978311936         prg16_cdef(space->machine, (nes.prg_chunks - 1) ^ 0x08);
978411937         break;
11938      case 187:
11939         prg_bank[0] = prg_bank[2] = 0xfe;
11940         prg_bank[1] = prg_bank[3] = 0xff;
11941         mapper187_reg[0] = mapper187_reg[1] = mapper187_reg[2] = mapper187_reg[3] = 0;
11942         mmc_cmd1 = 0;
11943         mmc_cmd2 = 0x80;
11944         mmc_prg_base = mmc_chr_base = 0;
11945         mmc_prg_mask = mmc_chr_mask = 0xff;
11946         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
11947         mapper187_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
11948         mapper187_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
11949         break;
11950      case 189:
11951         mmc_cmd1 = 0;
11952         mmc_cmd2 = 0x80;
11953         mmc_chr_base = 0;
11954         mmc_chr_mask = 0xff;
11955         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
11956         prg32(space->machine, 0);
11957         mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
11958         break;
978511959      case 193:
978611960         prg32(space->machine, (nes.prg_chunks - 1) >> 1);
978711961         set_nt_mirroring(PPU_MIRROR_VERT);
978811962         break;
11963      case 197:
11964         prg_bank[0] = prg_bank[2] = 0xfe;
11965         prg_bank[1] = prg_bank[3] = 0xff;
11966         mmc_cmd1 = 0;
11967         mmc_cmd2 = 0x80;
11968         mmc_prg_base = mmc_chr_base = 0;
11969         mmc_prg_mask = mmc_chr_mask = 0xff;
11970         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
11971         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
11972         mapper197_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
11973         break;
11974      case 198:
11975         prg_bank[0] = 0x00;
11976         prg_bank[1] = 0x01;
11977         prg_bank[2] = 0x4e;
11978         prg_bank[3] = 0x4f;
11979         mmc_cmd1 = 0;
11980         mmc_cmd2 = 0x80;
11981         mmc_prg_base = mmc_chr_base = 0;
11982         mmc_prg_mask = mmc_chr_mask = 0xff;
11983         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
11984         mapper198_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
11985         mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
11986         break;
11987      case 199:
11988         prg_bank[0] = 0x00;
11989         prg_bank[1] = 0x01;
11990         prg_bank[2] = 0x3e;
11991         prg_bank[3] = 0x3f;
11992         mmc_cmd1 = 0;
11993         mmc_cmd2 = 0x80;
11994         mmc_prg_base = mmc_chr_base = 0;
11995         mmc_prg_mask = mmc_chr_mask = 0xff;
11996         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
11997         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
11998         mapper199_set_chr(space->machine, mmc_chr_base, mmc_chr_mask);
11999         break;
978912000      case 200:
979012001         prg16_89ab(space->machine, nes.prg_chunks - 1);
979112002         prg16_cdef(space->machine, nes.prg_chunks - 1);
r5997r5998
980312014         prg16_cdef(space->machine, 0);
980412015         chr8(space->machine, 0, CHRROM);
980512016         break;
12017      case 205:
12018         prg_bank[0] = prg_bank[2] = 0xfe;
12019         prg_bank[1] = prg_bank[3] = 0xff;
12020         mmc_cmd1 = 0;
12021         mmc_cmd2 = 0x80;
12022         mmc_prg_base = 0x10;
12023         mmc_prg_mask = 0x1f;
12024         mmc_chr_base = 0;
12025         mmc_chr_mask = 0xff;
12026         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
12027         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
12028         mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
12029         break;
12030      case 208:
12031         prg_bank[0] = prg_bank[2] = 0xfe;
12032         prg_bank[1] = prg_bank[3] = 0xff;
12033         map208_reg[0] = map208_reg[1] = map208_reg[2] = map208_reg[3] = map208_reg[4] = 0;
12034         mmc_cmd1 = 0;
12035         mmc_cmd2 = 0x80;
12036         mmc_prg_base = mmc_chr_base = 0;
12037         mmc_prg_mask = mmc_chr_mask = 0xff;
12038         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
12039         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
12040         mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
12041         break;
980612042      case 212:
980712043         chr8(space->machine, 0xff, CHRROM);
980812044         prg32(space->machine, 0xff);
980912045         break;
12046      case 215:
12047         prg_bank[0] = 0x00;
12048         prg_bank[2] = 0xfe;
12049         prg_bank[1] = 0x01;
12050         prg_bank[3] = 0xff;
12051         mmc_cmd1 = 0;
12052         mmc_cmd2 = 0x80;
12053         map215_reg[0] = 0x00;
12054         map215_reg[1] = 0xff;
12055         map215_reg[2] = 0x04;
12056         map215_reg[3] = 0;
12057         mmc_prg_base = 0;
12058         mmc_prg_mask = 0x1f;
12059         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
12060         mapper215_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
12061         mapper215_set_chr(space->machine, mmc_chr_source);
12062         break;
981012063      case 216:
981112064         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
981212065         prg32(space->machine, 0);
981312066         chr8(space->machine, 0, mmc_chr_source);
981412067         break;
12068      case 217:
12069         map217_reg[0] = 0x00;
12070         map217_reg[1] = 0xff;
12071         map217_reg[2] = 0x03;
12072         map217_reg[3] = 0;
12073         prg_bank[0] = prg_bank[2] = 0xfe;
12074         prg_bank[1] = prg_bank[3] = 0xff;
12075         mmc_cmd1 = 0;
12076         mmc_cmd2 = 0x80;
12077         mmc_prg_base = mmc_chr_base = 0;
12078         mmc_prg_mask = mmc_chr_mask = 0xff;
12079         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
12080         mapper217_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
12081         mapper217_set_chr(space->machine, mmc_chr_source);
12082         break;
981512083      case 221:
981612084         mmc_cmd1 = 0;
981712085         mmc_cmd2 = 0;
r5997r5998
984312111         break;
984412112      case 231:
984512113         prg16_89ab(space->machine, 0);
9846         prg16_cdef(space->machine, 0);
12114         prg16_cdef(space->machine, nes.prg_chunks - 1);
984712115         set_nt_mirroring(PPU_MIRROR_VERT);
984812116         break;
984912117      case 232:
r5997r5998
986112129      case 246:
986212130         prg32(space->machine, 0xff);
986312131         break;
12132      case 249:
12133         prg_bank[0] = prg_bank[2] = 0xfe;
12134         prg_bank[1] = prg_bank[3] = 0xff;
12135         mmc_cmd1 = 0;
12136         mmc_cmd2 = 0x80;
12137         map249_reg = 0;
12138         mmc_prg_base = mmc_chr_base = 0;
12139         mmc_prg_mask = mmc_chr_mask = 0xff;
12140         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
12141         mapper249_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
12142         mapper249_set_chr(space->machine, mmc_chr_base, mmc_chr_mask);
12143         break;
986412144      default:
986512145         /* Mapper not supported */
986612146         err = 2;
r5997r5998
987912159
988012160*************************************************************/
988112161
12162enum
12163{
12164CHRRAM_0 = 0,
12165CHRRAM_1,
12166CHRRAM_2,
12167CHRRAM_4,
12168CHRRAM_6,
12169CHRRAM_8,
12170CHRRAM_16,
12171CHRRAM_32
12172};
12173
12174enum
12175{
12176NROM = 0,
12177SACHEN_8259A
12178};
12179
988212180static const unif unif_list[] =
988312181{
9884/*       UNIF                       LOW_W, LOW_R, MED_W, HIGH_W, PPU_latch, scanline CB, hblank CB */
9885   { "UNL-Sachen-8259A",         mapper141_l_w, NULL, mapper141_m_w, NULL, NULL, NULL, NULL },
12182/*       UNIF                       LOW_W, LOW_R, MED_W, HIGH_W, PPU_latch, scanline CB, hblank CB     PRG  CHR  NVW  WRAM  CRAM       NMT    IDX*/
12183   { "UNL-SACHEN-8259A",         mapper141_l_w, NULL, mapper141_m_w, NULL, NULL, NULL, NULL,        256, 256,   0,    0, CHRRAM_0,  0,     SACHEN_8259A},
988612184};
988712185
988812186const unif *nes_unif_lookup( const char *board )
r5997r5998
989012188   int i;
989112189   for (i = 0; i < sizeof(unif_list) / sizeof(unif_list[0]); i++)
989212190   {
9893      if (unif_list[i].board == board)
12191      if (!mame_stricmp(unif_list[i].board, board))
989412192         return &unif_list[i];
989512193   }
989612194   return NULL;
989712195}
12196
12197
12198// WIP code - not very satisfactory... we would end up with a lot of duplicate code...
12199int unif_reset( running_machine *machine, const char *board )
12200{
12201   const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
12202   nes_state *state = machine->driver_data;
12203   int err = 0;
12204   const unif *unif_board;
12205
12206   if (nes.chr_chunks == 0)
12207      chr8(machine, 0,CHRRAM);
12208   else
12209      chr8(machine, 0,CHRROM);
12210
12211   /* Set the mapper irq callback */
12212   unif_board = nes_unif_lookup(board);
12213
12214   if (unif_board == NULL)
12215      fatalerror("Unimplemented UNIF Board");
12216
12217   ppu2c0x_set_scanline_callback(state->ppu, unif_board ? unif_board->mmc_scanline : NULL);
12218   ppu2c0x_set_hblank_callback(state->ppu, unif_board ? unif_board->mmc_hblank : NULL);
12219
12220   if (!nes_irq_timer)
12221      nes_irq_timer = timer_alloc(machine, nes_irq_callback, NULL);
12222
12223   /* Point the WRAM/battery area to the first RAM bank */
12224   memory_set_bankptr(space->machine, 5, &nes.wram[0x0000]);
12225
12226   switch (unif_board->board_idx)
12227   {
12228      case SACHEN_8259A:
12229         mmc_cmd1 = 0;
12230         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
12231         prg32(space->machine, 0);
12232         chr8(space->machine, 0, mmc_chr_source);
12233         set_nt_mirroring(PPU_MIRROR_VERT);
12234         break;
12235      default:
12236         /* Mapper not supported */
12237         err = 2;
12238         break;
12239   }
12240   return err;
12241}
12242
src/mess/machine/nes_mmc.h
r5997r5998
44typedef struct __mmc
55{
66   int iNesMapper; /* iNES Mapper # */
7
78   const char *desc;     /* Mapper description */
89   write8_space_func mmc_write_low; /* $4100-$5fff write routine */
910   read8_space_func mmc_read_low; /* $4100-$5fff read routine */
r5997r5998
1920typedef struct __unif
2021{
2122   const char *board; /* UNIF board */
23
2224   write8_space_func mmc_write_low; /* $4100-$5fff write routine */
2325   read8_space_func mmc_read_low; /* $4100-$5fff read routine */
2426   write8_space_func mmc_write_mid; /* $6000-$7fff write routine */
r5997r5998
2628   void (*ppu_latch)(const device_config *device, offs_t offset);
2729   ppu2c0x_scanline_cb      mmc_scanline;
2830   ppu2c0x_hblank_cb      mmc_hblank;
31
32   int prgrom;
33   int chrrom;
34   int nvwram;
35   int wram;
36   int chrram;
37   int nt;
38   int board_idx;
2939} unif;
3040
3141const unif *nes_unif_lookup(const char *board);
r5997r5998
4353extern read8_space_func mmc_read_mid;
4454extern write8_space_func mmc_write;
4555
46int mapper_reset (running_machine *machine, int mapperNum);
56int mapper_reset( running_machine *machine, int mapperNum );
57int unif_reset( running_machine *machine, const char *board );
4758
4859WRITE8_HANDLER( nes_low_mapper_w );
4960READ8_HANDLER( nes_low_mapper_r );
r5997r5998
5768
5869READ8_HANDLER( fds_r );
5970WRITE8_HANDLER( fds_w );
71WRITE8_HANDLER( mapper50_add_w );
6072
6173#endif

Previous 15994 Revisions Next


© 1998-2018 The MESS Team