Previous 15994 Revisions Next

r7953 Saturday 1st May, 2010 at 09:32:53 UTC by Fabio Priuli
[NES] moved some variables to driver data class, plus some small cleanup
[src/mess/includes]nes.h
[src/mess/machine]nes.c nes_ines.c nes_mmc.c nes_mmc.h nes_unif.c
[src/mess/video]nes.c

src/mess/video/nes.c
r7952r7953
1515static int last_frame_flip = 0;
1616static double nes_scanlines_per_frame;
1717
18static void nes_vh_reset(running_machine *machine)
18static void nes_vh_reset( running_machine *machine )
1919{
20   nes_state *state = (nes_state *)machine->driver_data;
2021   ppu2c0x_set_vidaccess_callback(devtag_get_device(machine,"ppu"), nes_ppu_vidaccess);
2122   ppu2c0x_set_scanlines_per_frame(devtag_get_device(machine,"ppu"), ceil(nes_scanlines_per_frame));
2223
23   if (nes.four_screen_vram)
24   {
25      set_nt_mirroring(PPU_MIRROR_4SCREEN);
26   }
24   if (state->four_screen_vram)
25      set_nt_mirroring(machine, PPU_MIRROR_4SCREEN);
2726   else
2827   {
29      switch(nes.hard_mirroring)
28      switch(state->hard_mirroring)
3029      {
3130         case 0:
32            set_nt_mirroring(PPU_MIRROR_HORZ);
31            set_nt_mirroring(machine, PPU_MIRROR_HORZ);
3332            break;
3433         case 1:
35            set_nt_mirroring(PPU_MIRROR_VERT);
34            set_nt_mirroring(machine, PPU_MIRROR_VERT);
3635            break;
3736         default:
38            set_nt_mirroring(PPU_MIRROR_NONE );
37            set_nt_mirroring(machine, PPU_MIRROR_NONE);
3938            break;
4039      }
4140   }
r7952r7953
7877   nes_state *state = (nes_state *)screen->machine->driver_data;
7978
8079   /* render the ppu */
81   ppu2c0x_render( state->ppu, bitmap, 0, 0, 0, 0 );
80   ppu2c0x_render(state->ppu, bitmap, 0, 0, 0, 0);
8281
8382   /* if this is a disk system game, check for the flip-disk key */
84   if (nes.mapper == 20)
83   if (state->mapper == 20)
8584   {
8685      // latch this input so it doesn't go at warp speed
8786      if ((input_port_read(screen->machine, "FLIPDISK") & 0x01) && (!last_frame_flip))
8887      {
8988         last_frame_flip = 1;
90         nes_fds.current_side++;
91         if (nes_fds.current_side > nes_fds.sides)
92            nes_fds.current_side = 0;
89         state->fds_current_side++;
90         if (state->fds_current_side > state->fds_sides)
91            state->fds_current_side = 0;
9392
94         if (nes_fds.current_side == 0)
95         {
93         if (state->fds_current_side == 0)
9694            popmessage("No disk inserted.");
97         }
9895         else
99         {
100            popmessage("Disk set to side %d", nes_fds.current_side);
101         }
96            popmessage("Disk set to side %d", state->fds_current_side);
10297      }
10398
10499      if (!(input_port_read(screen->machine, "FLIPDISK") & 0x01))
105      {
106100         last_frame_flip = 0;
107      }
108101   }
109102   return 0;
110103}
src/mess/includes/nes.h
r7952r7953
2929
3030   nes_state(running_machine &machine) { }
3131
32   /* devices */
3233   running_device *ppu;
3334   running_device *sound;
3435   running_device *cart;
35};
36   
37   /***** NES-related *****/
3638
37
38/*----------- defined in machine/nes.c -----------*/
39
40WRITE8_HANDLER ( nes_IN0_w );
41WRITE8_HANDLER ( nes_IN1_w );
42
43extern unsigned char *nes_battery_ram;
44
45struct nes_struct
46{
4739   /* load-time cart variables which remain constant */
4840   UINT8 trainer;
4941   UINT8 battery;
5042   UINT16 prg_chunks;   // a recently dumped multigame cart has 256 chunks of both PRG & CHR!
5143   UINT16 chr_chunks;
52
44   
5345   UINT8 format;   // 1 = iNES, 2 = UNIF
54
46   
5547   /* system variables which don't change at run-time */
5648   UINT16 mapper;      // for iNES
5749   const char *board;   // for UNIF
r7952r7953
5951   UINT8 hard_mirroring;
6052   UINT8 slow_banking;
6153   UINT8 crc_hack;   // this is needed to detect different boards sharing the same Mappers (shame on .nes format)
62
54   
6355   UINT8 *rom;
6456   UINT8 *vrom;
6557   UINT8 *vram;
6658   UINT8 *wram;
6759   UINT8 *ciram; //PPU nametable RAM - external to PPU!
68
60   
6961   /* Variables which can change */
7062   UINT8 mid_ram_enable;
63   
64   
65   
66   /***** FDS-related *****/
67
68   UINT8 *fds_data;
69   UINT8 fds_sides;
70   UINT8 *fds_ram;
71   
72   /* Variables which can change */
73   UINT8 fds_motor_on;
74   UINT8 fds_door_closed;
75   UINT8 fds_current_side;
76   UINT32 fds_head_position;
77   UINT8 fds_status0;
78   UINT8 fds_read_mode;
79   UINT8 fds_write_reg;
7180};
7281
73extern struct nes_struct nes;
7482
75struct fds_struct
76{
77   UINT8 *data;
78   UINT8 sides;
79   UINT8 *ram;
83/*----------- defined in machine/nes.c -----------*/
8084
81   /* Variables which can change */
82   UINT8 motor_on;
83   UINT8 door_closed;
84   UINT8 current_side;
85   UINT32 head_position;
86   UINT8 status0;
87   UINT8 read_mode;
88   UINT8 write_reg;
89};
85WRITE8_HANDLER ( nes_IN0_w );
86WRITE8_HANDLER ( nes_IN1_w );
9087
91extern struct fds_struct nes_fds;
88extern unsigned char *nes_battery_ram;
9289
9390/* protos */
9491
r7952r7953
107104
108105int nes_ppu_vidaccess( running_device *device, int address, int data );
109106
110void nes_partialhash(char *dest, const unsigned char *data,
111   unsigned long length, unsigned int functions);
107void nes_partialhash(char *dest, const unsigned char *data, unsigned long length, unsigned int functions);
112108
113109/*----------- defined in video/nes.c -----------*/
114110
src/mess/machine/nes.c
r7952r7953
4343unsigned char *nes_battery_ram;
4444static UINT8 battery_data[BATTERY_SIZE];
4545
46struct nes_struct nes;
47struct fds_struct nes_fds;
48
4946static nes_input in_0;
5047static nes_input in_1;
5148
r7952r7953
6057    FUNCTIONS
6158***************************************************************************/
6259
63static running_device *cartslot_image( running_machine *machine )
60static void init_nes_core( running_machine *machine )
6461{
6562   nes_state *state = (nes_state *)machine->driver_data;
66   return state->cart;
67}
68
69static void init_nes_core( running_machine *machine )
70{
7163   const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
7264
7365   /* We set these here in case they weren't set in the cart loader */
74   nes.rom = memory_region(machine, "maincpu");
75   nes.vrom = memory_region(machine, "gfx1");
76   nes.vram = memory_region(machine, "gfx2");
77   nes.ciram = memory_region(machine, "gfx3");
78   nes.wram = memory_region(machine, "user1");
66   state->rom = memory_region(machine, "maincpu");
67   state->vrom = memory_region(machine, "gfx1");
68   state->vram = memory_region(machine, "gfx2");
69   state->ciram = memory_region(machine, "gfx3");
70   state->wram = memory_region(machine, "user1");
7971
80   /* Brutal hack put in as a consequence of the new memory system; we really
81       need to fix the NES code */
72   /* Brutal hack put in as a consequence of the new memory system; we really need to fix the NES code */
8273   memory_install_readwrite_bank(space, 0x0000, 0x07ff, 0, 0x1800, "bank10");
8374
8475   memory_install_readwrite8_handler(cpu_get_address_space(devtag_get_device(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0, 0x1fff, 0, 0, nes_chr_r, nes_chr_w);
8576   memory_install_readwrite8_handler(cpu_get_address_space(devtag_get_device(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0x2000, 0x3eff, 0, 0, nes_nt_r, nes_nt_w);
8677
87   memory_set_bankptr(machine, "bank10", nes.rom);
78   memory_set_bankptr(machine, "bank10", state->rom);
8879
89   nes_battery_ram = nes.wram;
80   nes_battery_ram = state->wram;
9081
9182   /* Set up the memory handlers for the mapper */
92   switch (nes.mapper)
83   switch (state->mapper)
9384   {
9485      case 20:
95         nes.slow_banking = 0;
96         /* If we are loading a disk we have already filled nes_fds.data and we don't want to overwrite it,
86         state->slow_banking = 0;
87         /* If we are loading a disk we have already filled state->fds_data and we don't want to overwrite it,
9788            if we are loading a cart image identified as mapper 20 (probably wrong mapper...) we need to alloc
9889            memory for the bank 2 pointer */
99         if (nes_fds.data == NULL)
100            nes_fds.data = auto_alloc_array(machine, UINT8, 0x8000 );
90         if (state->fds_data == NULL)
91            state->fds_data = auto_alloc_array(machine, UINT8, 0x8000);
10192         memory_install_read8_handler(space, 0x4030, 0x403f, 0, 0, nes_fds_r);
10293         memory_install_read_bank(space, 0x6000, 0xdfff, 0, 0, "bank2");
10394         memory_install_read_bank(space, 0xe000, 0xffff, 0, 0, "bank1");
r7952r7953
10596         memory_install_write8_handler(space, 0x4020, 0x402f, 0, 0, nes_fds_w);
10697         memory_install_write_bank(space, 0x6000, 0xdfff, 0, 0, "bank2");
10798
108         memory_set_bankptr(machine, "bank1", &nes.rom[0xe000]);
109         memory_set_bankptr(machine, "bank2", nes_fds.data );
99         memory_set_bankptr(machine, "bank1", &state->rom[0xe000]);
100         memory_set_bankptr(machine, "bank2", state->fds_data);
110101         break;
111102      case 50:
112103         memory_install_write8_handler(space, 0x4020, 0x403f, 0, 0, nes_mapper50_add_w);
113104         memory_install_write8_handler(space, 0x40a0, 0x40bf, 0, 0, nes_mapper50_add_w);
114105      default:
115         nes.slow_banking = 0;
106         state->slow_banking = 0;
116107         memory_install_read_bank(space, 0x6000, 0x7fff, 0, 0, "bank5");
117108         memory_install_read_bank(space, 0x8000, 0x9fff, 0, 0, "bank1");
118109         memory_install_read_bank(space, 0xa000, 0xbfff, 0, 0, "bank2");
r7952r7953
130121   }
131122
132123   /* Set up the mapper callbacks */
133   if (nes.format == 1)
124   if (state->format == 1)
134125   {
135126      mmc_intf intf = { 0 };
136127      const mmc *mapper;
137128
138      mapper = nes_mapper_lookup(nes.mapper);
129      mapper = nes_mapper_lookup(state->mapper);
139130      if (mapper)
140131      {
141132         intf.mmc_write_low = mapper->mmc_write_low;
r7952r7953
147138      }
148139      else
149140      {
150         logerror("Mapper %d is not yet supported, defaulting to no mapper.\n",nes.mapper);
141         logerror("Mapper %d is not yet supported, defaulting to no mapper.\n",state->mapper);
151142         nes_mapper_init(&intf);
152143      }
153144   }
154   else if (nes.format == 2)
145   else if (state->format == 2)
155146   {
156147      mmc_intf intf = { 0 };
157148      const unif *board;
158149
159      board = nes_unif_lookup(nes.board);
150      board = nes_unif_lookup(state->board);
160151      if (board)
161152      {
162153         intf.mmc_write_low = board->mmc_write_low;
r7952r7953
168159      }
169160      else
170161      {
171         logerror("Board %s is not yet supported, defaulting to no mapper.\n", nes.board);
162         logerror("Board %s is not yet supported, defaulting to no mapper.\n", state->board);
172163         nes_mapper_init(&intf);
173164         ppu_latch = NULL;
174165      }
r7952r7953
176167
177168   /* Load a battery file, but only if there's no trainer since they share */
178169   /* overlapping memory. */
179   if (nes.trainer)
170   if (state->trainer)
180171      return;
181172
182173   /* We need this because battery ram is loaded before the */
r7952r7953
188179
189180int nes_ppu_vidaccess( running_device *device, int address, int data )
190181{
182   nes_state *state = (nes_state *)device->machine->driver_data;
183   
191184   /* TODO: this is a bit of a hack, needed to get Argus, ASO, etc to work */
192185   /* but, B-Wings, submath (j) seem to use this location differently... */
193   if (nes.chr_chunks && (address & 0x3fff) < 0x2000)
186   if (state->chr_chunks && (address & 0x3fff) < 0x2000)
194187   {
195188//      int vrom_loc;
196189//      vrom_loc = (nes_vram[(address & 0x1fff) >> 10] * 16) + (address & 0x3ff);
197//      data = nes.vrom [vrom_loc];
190//      data = state->vrom [vrom_loc];
198191   }
199192   return data;
200193}
r7952r7953
208201   state->cart = devtag_get_device(machine, "cart");
209202
210203   /* Some carts have extra RAM and require it on at startup, e.g. Metroid */
211   nes.mid_ram_enable = 1;
204   state->mid_ram_enable = 1;
212205
213206   /* Reset the mapper variables. Will also mark the char-gen ram as dirty */
214   if (nes.format == 1)
215      nes_mapper_reset(machine, nes.mapper);
207   if (state->format == 1)
208      nes_mapper_reset(machine, state->mapper);
216209
217   if (nes.format == 2)
218      nes_unif_reset(machine, nes.board);
210   if (state->format == 2)
211      nes_unif_reset(machine, state->board);
219212
220213   /* Reset the serial input ports */
221214   in_0.shift = 0;
r7952r7953
242235
243236static void nes_machine_stop( running_machine *machine )
244237{
238   nes_state *state = (nes_state *)machine->driver_data;
239   
245240   /* Write out the battery file if necessary */
246   if (nes.battery)
247      image_battery_save(cartslot_image(machine), nes_battery_ram, BATTERY_SIZE);
241   if (state->battery)
242      image_battery_save(state->cart, nes_battery_ram, BATTERY_SIZE);
248243}
249244
250245
r7952r7953
462457
463458DEVICE_IMAGE_LOAD( nes_cart )
464459{
460   nes_state *state = (nes_state *)image->machine->driver_data;
465461   const char *mapinfo;
466462   int mapint1 = 0, mapint2 = 0, mapint3 = 0, mapint4 = 0, goodcrcinfo = 0;
467463   char magic[4];
r7952r7953
477473
478474   if ((magic[0] == 'N') && (magic[1] == 'E') && (magic[2] == 'S'))   /* If header starts with 'NES' it is iNES */
479475   {
480      nes.format = 1;   // we use this to select between mapper_reset / unif_reset
476      state->format = 1;   // we use this to select between mapper_reset / unif_reset
481477
482478      mapinfo = image_extrainfo(image);
483479
r7952r7953
485481      {
486482         if (4 == sscanf(mapinfo,"%d %d %d %d", &mapint1, &mapint2, &mapint3, &mapint4))
487483         {
488            nes.mapper = mapint1;
484            state->mapper = mapint1;
489485            local_options = mapint2 & 0x0f;
490            nes.crc_hack = mapint2 & 0xf0;   // this is used to differentiate among variants of the same Mapper (see nes_mmc.c)
491            nes.prg_chunks = mapint3;
492            nes.chr_chunks = mapint4;
486            state->crc_hack = mapint2 & 0xf0;   // this is used to differentiate among variants of the same Mapper (see nes_mmc.c)
487            state->prg_chunks = mapint3;
488            state->chr_chunks = mapint4;
493489            logerror("NES.HSI info: %d %d %d %d\n", mapint1, mapint2, mapint3, mapint4);
494490            goodcrcinfo = 1;
495491         }
r7952r7953
509505         // Let's skip past the magic header once again.
510506         image_fseek(image, 4, SEEK_SET);
511507
512         image_fread(image, &nes.prg_chunks, 1);
513         image_fread(image, &nes.chr_chunks, 1);
508         image_fread(image, &state->prg_chunks, 1);
509         image_fread(image, &state->chr_chunks, 1);
514510         /* Read the first ROM option byte (offset 6) */
515511         image_fread(image, &m, 1);
516512
517513         /* Interpret the iNES header flags */
518         nes.mapper = (m & 0xf0) >> 4;
514         state->mapper = (m & 0xf0) >> 4;
519515         local_options = m & 0x0f;
520516
521517         /* Read the second ROM option byte (offset 7) */
r7952r7953
536532         }
537533         logerror("\n");
538534
539         nes.mapper = nes.mapper | (m & 0xf0);
535         state->mapper = state->mapper | (m & 0xf0);
540536      }
541537
542      nes.hard_mirroring = local_options & 0x01;
543      nes.battery = local_options & 0x02;
544      nes.trainer = local_options & 0x04;
545      nes.four_screen_vram = local_options & 0x08;
538      state->hard_mirroring = local_options & 0x01;
539      state->battery = local_options & 0x02;
540      state->trainer = local_options & 0x04;
541      state->four_screen_vram = local_options & 0x08;
546542
547      if (nes.battery)
543      if (state->battery)
548544         logerror("-- Battery found\n");
549545
550      if (nes.trainer)
546      if (state->trainer)
551547         logerror("-- Trainer found\n");
552548
553      if (nes.four_screen_vram)
549      if (state->four_screen_vram)
554550         logerror("-- 4-screen VRAM\n");
555551
556552      /* Free the regions that were allocated by the ROM loader */
r7952r7953
558554      memory_region_free(image->machine, "gfx1");
559555
560556      /* Allocate them again with the proper size */
561      memory_region_alloc(image->machine, "maincpu", 0x10000 + (nes.prg_chunks + 1) * 0x4000,0);
562      if (nes.chr_chunks)
563         memory_region_alloc(image->machine, "gfx1", nes.chr_chunks * 0x2000,0);
557      memory_region_alloc(image->machine, "maincpu", 0x10000 + (state->prg_chunks + 1) * 0x4000,0);
558      if (state->chr_chunks)
559         memory_region_alloc(image->machine, "gfx1", state->chr_chunks * 0x2000,0);
564560
565      nes.rom = memory_region(image->machine, "maincpu");
566      nes.vrom = memory_region(image->machine, "gfx1");
567      nes.vram = memory_region(image->machine, "gfx2");
568      nes.wram = memory_region(image->machine, "user1");
561      state->rom = memory_region(image->machine, "maincpu");
562      state->vrom = memory_region(image->machine, "gfx1");
563      state->vram = memory_region(image->machine, "gfx2");
564      state->wram = memory_region(image->machine, "user1");
569565
570566      /* Position past the header */
571567      image_fseek(image, 16, SEEK_SET);
572568
573569      /* Load the 0x200 byte trainer at 0x7000 if it exists */
574      if (nes.trainer)
575         image_fread(image, &nes.wram[0x1000], 0x200);
570      if (state->trainer)
571         image_fread(image, &state->wram[0x1000], 0x200);
576572
577573      /* Read in the program chunks */
578      if (nes.prg_chunks == 1)
574      if (state->prg_chunks == 1)
579575      {
580         image_fread(image, &nes.rom[0x14000], 0x4000);
576         image_fread(image, &state->rom[0x14000], 0x4000);
581577         /* Mirror this bank into $8000 */
582         memcpy(&nes.rom[0x10000], &nes.rom [0x14000], 0x4000);
578         memcpy(&state->rom[0x10000], &state->rom [0x14000], 0x4000);
583579      }
584580      else
585         image_fread(image, &nes.rom[0x10000], 0x4000 * nes.prg_chunks);
581         image_fread(image, &state->rom[0x10000], 0x4000 * state->prg_chunks);
586582
587583#if SPLIT_PRG
588584      {
589585         FILE *prgout;
590586         char outname[255];
591587
592         for (i = 0; i < nes.prg_chunks; i ++)
588         for (i = 0; i < state->prg_chunks; i ++)
593589         {
594590            sprintf(outname, "%s.p%d", image_filename(image), i);
595591            prgout = fopen(outname, "wb");
596592            if (prgout)
597593            {
598               fwrite(&nes.rom[0x10000 + 0x4000 * i], 1, 0x4000, prgout);
594               fwrite(&state->rom[0x10000 + 0x4000 * i], 1, 0x4000, prgout);
599595               fclose(prgout);
600596            }
601597         }
r7952r7953
603599#endif /* SPLIT_PRG */
604600
605601      logerror("**\n");
606      logerror("Mapper: %d\n", nes.mapper);
607      logerror("PRG chunks: %02x, size: %06x\n", nes.prg_chunks, 0x4000 * nes.prg_chunks);
608//      printf("Mapper: %d\n", nes.mapper);
609//      printf("PRG chunks: %02x, size: %06x\n", nes.prg_chunks, 0x4000 * nes.prg_chunks);
602      logerror("Mapper: %d\n", state->mapper);
603      logerror("PRG chunks: %02x, size: %06x\n", state->prg_chunks, 0x4000 * state->prg_chunks);
604//      printf("Mapper: %d\n", state->mapper);
605//      printf("PRG chunks: %02x, size: %06x\n", state->prg_chunks, 0x4000 * state->prg_chunks);
610606
611607      /* Read in any chr chunks */
612      if (nes.chr_chunks > 0)
608      if (state->chr_chunks > 0)
613609      {
614         image_fread(image, nes.vrom, nes.chr_chunks * 0x2000);
615         if (nes.mapper == 2)
610         image_fread(image, state->vrom, state->chr_chunks * 0x2000);
611         if (state->mapper == 2)
616612            logerror("Warning: VROM has been found in VRAM-based mapper. Either the mapper is set wrong or the ROM image is incorrect.\n");
617613      }
618614
r7952r7953
621617         FILE *chrout;
622618         char outname[255];
623619
624         for (i = 0; i < nes.chr_chunks; i ++)
620         for (i = 0; i < state->chr_chunks; i ++)
625621         {
626622            sprintf(outname, "%s.c%d", image_filename(image), i);
627623            chrout= fopen(outname, "wb");
628624            if (chrout)
629625            {
630               fwrite(&nes.rom[0x10000 + 0x2000 * i], 1, 0x2000, chrout);
626               fwrite(&state->rom[0x10000 + 0x2000 * i], 1, 0x2000, chrout);
631627               fclose(chrout);
632628            }
633629         }
634630      }
635631#endif /* SPLIT_CHR */
636632
637      logerror("CHR chunks: %02x, size: %06x\n", nes.chr_chunks, 0x4000 * nes.chr_chunks);
633      logerror("CHR chunks: %02x, size: %06x\n", state->chr_chunks, 0x4000 * state->chr_chunks);
638634      logerror("**\n");
639//      printf("CHR chunks: %02x, size: %06x\n", nes.chr_chunks, 0x4000 * nes.chr_chunks);
635//      printf("CHR chunks: %02x, size: %06x\n", state->chr_chunks, 0x4000 * state->chr_chunks);
640636//      printf("**\n");
641637
642638      /* Attempt to load a battery file for this ROM. If successful, we */
643639      /* must wait until later to move it to the system memory. */
644      if (nes.battery)
640      if (state->battery)
645641         image_battery_load(image, battery_data, BATTERY_SIZE, 0x00);
646642
647643   }
r7952r7953
658654      const unif *unif_board;
659655      int mapr_chunk_found = 0;
660656
661      nes.format = 2;   // we use this to select between mapper_reset / unif_reset
657      state->format = 2;   // we use this to select between mapper_reset / unif_reset
662658
663659      image_fread(image, &buffer, 4);
664660      unif_ver = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
r7952r7953
711707//                            logerror("Unsupported UNIF board %s.\n", unif_mapr);
712708               }
713709
714               nes.mapper = 0;   // this allows us to set up memory handlers without duplicating code (for the moment)
715               nes.board = unif_board->board;
716               nes.prg_chunks = unif_board->prgrom;
717               nes.chr_chunks = unif_board->chrrom;
718               nes.battery = unif_board->wram;   // we should implement WRAM banks...
719//                  nes.hard_mirroring = unif_board->nt;
720//                      nes.four_screen_vram = ;
710               state->mapper = 0;   // this allows us to set up memory handlers without duplicating code (for the moment)
711               state->board = unif_board->board;
712               state->prg_chunks = unif_board->prgrom;
713               state->chr_chunks = unif_board->chrrom;
714               state->battery = unif_board->wram;   // we should implement WRAM banks...
715//                  state->hard_mirroring = unif_board->nt;
716//                      state->four_screen_vram = ;
721717
722718               /* Free the regions that were allocated by the ROM loader */
723719               memory_region_free(image->machine, "maincpu");
724720               memory_region_free(image->machine, "gfx1");
725721
726722               /* Allocate them again with the proper size */
727               memory_region_alloc(image->machine, "maincpu", 0x10000 + (nes.prg_chunks + 1) * 0x4000, 0);
728               if (nes.chr_chunks)
729                  memory_region_alloc(image->machine, "gfx1", nes.chr_chunks * 0x2000, 0);
723               memory_region_alloc(image->machine, "maincpu", 0x10000 + (state->prg_chunks + 1) * 0x4000, 0);
724               if (state->chr_chunks)
725                  memory_region_alloc(image->machine, "gfx1", state->chr_chunks * 0x2000, 0);
730726
731               nes.rom = memory_region(image->machine, "maincpu");
732               nes.vrom = memory_region(image->machine, "gfx1");
733               nes.vram = memory_region(image->machine, "gfx2");
734               nes.wram = memory_region(image->machine, "user1");
727               state->rom = memory_region(image->machine, "maincpu");
728               state->vrom = memory_region(image->machine, "gfx1");
729               state->vram = memory_region(image->machine, "gfx2");
730               state->wram = memory_region(image->machine, "user1");
735731
736732               /* for validation purposes */
737733               prg_left = unif_board->prgrom * 0x4000;
r7952r7953
864860                  fatalerror("PRG chunks larger than expected by board %s!\n", unif_mapr);
865861
866862               /* Read in the program chunks */
867               if (nes.prg_chunks == 1)
863               if (state->prg_chunks == 1)
868864               {
869                  image_fread(image, &nes.rom[0x14000], chunk_length);
865                  image_fread(image, &state->rom[0x14000], chunk_length);
870866                  /* Mirror the only bank into $8000 */
871                  memcpy(&nes.rom[0x10000], &nes.rom[0x14000], chunk_length);
867                  memcpy(&state->rom[0x10000], &state->rom[0x14000], chunk_length);
872868               }
873869               else
874                  image_fread(image, &nes.rom[0x10000 + prg_start], chunk_length);
870                  image_fread(image, &state->rom[0x10000 + prg_start], chunk_length);
875871
876872               prg_start += chunk_length;
877873               read_length += (chunk_length + 8);
r7952r7953
889885                  fatalerror("CHR chunks larger than expected by board %s!\n", unif_mapr);
890886
891887               /* Read in the vrom chunks */
892               image_fread(image, nes.vrom + chr_start, chunk_length);
888               image_fread(image, state->vrom + chr_start, chunk_length);
893889
894890               chr_start += chunk_length;
895891               read_length += (chunk_length + 8);
r7952r7953
926922}
927923
928924
929static void nes_load_proc(running_device *image)
925static void nes_load_proc( running_device *image )
930926{
927   nes_state *state = (nes_state *)image->machine->driver_data;
931928   int header = 0;
932   nes_fds.sides = 0;
929   state->fds_sides = 0;
933930
934931   if (image_length(image) % 65500)
935932      header = 0x10;
936933
937934   image_fseek(image, 0, SEEK_END);
938   nes_fds.sides = (image_ftell(image) - header) / 65500;
939   nes_fds.data = (UINT8*)image_malloc(image, nes_fds.sides * 65500);
935   state->fds_sides = (image_ftell(image) - header) / 65500;
936   state->fds_data = (UINT8*)image_malloc(image, state->fds_sides * 65500);
940937
941938   /* if there is an header, skip it */
942939   image_fseek(image, header, SEEK_SET);
943940
944   image_fread(image, nes_fds.data, 65500 * nes_fds.sides);
941   image_fread(image, state->fds_data, 65500 * state->fds_sides);
945942   return;
946943}
947944
948static void nes_unload_proc(running_device *image)
945static void nes_unload_proc( running_device *image )
949946{
947   nes_state *state = (nes_state *)image->machine->driver_data;
948
950949   /* TODO: should write out changes here as well */
951   nes_fds.sides =  0;
950   state->fds_sides =  0;
952951}
953952
954953DRIVER_INIT( famicom )
955954{
955   nes_state *state = (nes_state *)machine->driver_data;
956
956957   /* clear some of the cart variables we don't use */
957   nes.trainer = 0;
958   nes.battery = 0;
959   nes.prg_chunks = nes.chr_chunks = 0;
958   state->trainer = 0;
959   state->battery = 0;
960   state->prg_chunks = state->chr_chunks = 0;
960961
961962   /* initialize the system as if using a mapper 20 cart */
962   nes.format = 1;
963   nes.mapper = 20;
964   nes.four_screen_vram = 0;
965   nes.hard_mirroring = 0;
963   state->format = 1;
964   state->mapper = 20;
965   state->four_screen_vram = 0;
966   state->hard_mirroring = 0;
966967
967   nes_fds.sides = 0;
968   nes_fds.data = NULL;
968   state->fds_sides = 0;
969   state->fds_data = NULL;
969970
970971   floppy_install_load_proc(floppy_get_device(machine,0), nes_load_proc);
971972   floppy_install_unload_proc(floppy_get_device(machine,0), nes_unload_proc);
src/mess/machine/nes_unif.c
r7952r7953
5757      break;
5858   }
5959   if (offset == 0x1000)   /* reg[0] also sets mirroring */
60      set_nt_mirroring((data & 0x20) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
60      set_nt_mirroring(space->machine, BIT(data, 5) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
6161}
6262
6363static WRITE8_HANDLER( bmc_64in1nr_w )
r7952r7953
8181{
8282   LOG_MMC(("bmc_190in1_w offset: %04x, data: %02x\n", offset, data));
8383
84   set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
84   set_nt_mirroring(space->machine, BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
8585   data >>= 2;
8686   prg16_89ab(space->machine, data);
8787   prg16_cdef(space->machine, data);
r7952r7953
104104   LOG_MMC(("bmc_a65as_w offset: %04x, data: %02x\n", offset, data));
105105
106106   if (data & 0x80)
107      set_nt_mirroring((data & 0x20) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
107      set_nt_mirroring(space->machine, BIT(data, 5) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
108108   else
109      set_nt_mirroring((data & 0x08) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
109      set_nt_mirroring(space->machine, BIT(data, 3) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
110110
111111   if (data & 0x40)
112112      prg32(space->machine, data >> 1);
r7952r7953
286286   else
287287   {
288288      mmc_cmd2 = 1;
289      set_nt_mirroring((offset & 0x02) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
289      set_nt_mirroring(space->machine, BIT(data, 1) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
290290      mmc_helper = ((offset >> 3) & 0x20) | ((offset >> 2) & 0x18);
291291      mmc_cmd1 = mmc_helper | (mmc_cmd1 & 0x07);
292292      prg16_89ab(space->machine, mmc_cmd1);
r7952r7953
317317         if (!mmc_cmd1)
318318         {
319319            mmc_cmd1 = data & 0x20;
320            set_nt_mirroring((data & 0x10) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
320            set_nt_mirroring(space->machine, BIT(data, 4) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
321321            mmc_helper = (~data & 0x08) >> 3;
322322            prg16_89ab(space->machine, data & ~mmc_helper);
323323            prg16_cdef(space->machine, data |  mmc_helper);
r7952r7953
473473
474474      case 0x0000:
475475      case 0x1000:
476         set_nt_mirroring((data | (data >> 7)) & 0x01 ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
476         set_nt_mirroring(space->machine, (data | (data >> 7)) & 0x01 ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
477477         break;
478478
479479      case 0x6000:
r7952r7953
515515      unl_ax5705_set_prg(space->machine);
516516      break;
517517   case 0x0008:
518      set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
518      set_nt_mirroring(space->machine, BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
519519      break;
520520   case 0x2000:
521521      prg_bank[1] = (data & 0x05) | ((data & 0x08) >> 2) | ((data & 0x02) << 2);
r7952r7953
572572{
573573   LOG_MMC(("unl_cc21_w offset: %04x, data: %02x\n", offset, data));
574574
575   set_nt_mirroring((offset & 0x02) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
575   set_nt_mirroring(space->machine, BIT(data, 1) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
576576   chr8(space->machine, (offset & 0x01), CHRROM);
577577}
578578
src/mess/machine/nes_mmc.c
r7952r7953
351351
352352WRITE8_HANDLER( nes_mid_mapper_w )
353353{
354   nes_state *state = (nes_state *)space->machine->driver_data;
355   
354356   if (mmc_write_mid)
355357      (*mmc_write_mid)(space, offset, data);
356   else if (nes.mid_ram_enable)
358   else if (state->mid_ram_enable)
357359      nes_battery_ram[offset] = data;
358360   else
359361   {
r7952r7953
370372
371373READ8_HANDLER( nes_mid_mapper_r )
372374{
373   if ((nes.mid_ram_enable) || (nes.mapper == 5))
375   nes_state *state = (nes_state *)space->machine->driver_data;
376
377   if ((state->mid_ram_enable) || (state->mapper == 5))
374378      return nes_battery_ram[offset];
375379   else
376380      return 0;
r7952r7953
404408
405409static void prg32( running_machine *machine, int bank )
406410{
411   nes_state *state = (nes_state *)machine->driver_data;
412
407413   /* assumes that bank references a 32k chunk */
408   bank &= ((nes.prg_chunks >> 1) - 1);
409   if (nes.slow_banking)
410      memcpy(&nes.rom[0x8000], &nes.rom[bank * 0x8000 + 0x10000], 0x8000);
414   bank &= ((state->prg_chunks >> 1) - 1);
415   if (state->slow_banking)
416      memcpy(&state->rom[0x8000], &state->rom[bank * 0x8000 + 0x10000], 0x8000);
411417   else
412418   {
413      memory_set_bankptr(machine, "bank1", &nes.rom[bank * 0x8000 + 0x10000]);
414      memory_set_bankptr(machine, "bank2", &nes.rom[bank * 0x8000 + 0x12000]);
415      memory_set_bankptr(machine, "bank3", &nes.rom[bank * 0x8000 + 0x14000]);
416      memory_set_bankptr(machine, "bank4", &nes.rom[bank * 0x8000 + 0x16000]);
419      memory_set_bankptr(machine, "bank1", &state->rom[bank * 0x8000 + 0x10000]);
420      memory_set_bankptr(machine, "bank2", &state->rom[bank * 0x8000 + 0x12000]);
421      memory_set_bankptr(machine, "bank3", &state->rom[bank * 0x8000 + 0x14000]);
422      memory_set_bankptr(machine, "bank4", &state->rom[bank * 0x8000 + 0x16000]);
417423   }
418424}
419425
420426static void prg16_89ab( running_machine *machine, int bank )
421427{
428   nes_state *state = (nes_state *)machine->driver_data;
429
422430   /* assumes that bank references a 16k chunk */
423   bank &= (nes.prg_chunks - 1);
424   if (nes.slow_banking)
425      memcpy(&nes.rom[0x8000], &nes.rom[bank * 0x4000 + 0x10000], 0x4000);
431   bank &= (state->prg_chunks - 1);
432   if (state->slow_banking)
433      memcpy(&state->rom[0x8000], &state->rom[bank * 0x4000 + 0x10000], 0x4000);
426434   else
427435   {
428      memory_set_bankptr(machine, "bank1", &nes.rom[bank * 0x4000 + 0x10000]);
429      memory_set_bankptr(machine, "bank2", &nes.rom[bank * 0x4000 + 0x12000]);
436      memory_set_bankptr(machine, "bank1", &state->rom[bank * 0x4000 + 0x10000]);
437      memory_set_bankptr(machine, "bank2", &state->rom[bank * 0x4000 + 0x12000]);
430438   }
431439}
432440
433441static void prg16_cdef( running_machine *machine, int bank )
434442{
443   nes_state *state = (nes_state *)machine->driver_data;
444
435445   /* assumes that bank references a 16k chunk */
436   bank &= (nes.prg_chunks - 1);
437   if (nes.slow_banking)
438      memcpy(&nes.rom[0xc000], &nes.rom[bank * 0x4000 + 0x10000], 0x4000);
446   bank &= (state->prg_chunks - 1);
447   if (state->slow_banking)
448      memcpy(&state->rom[0xc000], &state->rom[bank * 0x4000 + 0x10000], 0x4000);
439449   else
440450   {
441      memory_set_bankptr(machine, "bank3", &nes.rom[bank * 0x4000 + 0x10000]);
442      memory_set_bankptr(machine, "bank4", &nes.rom[bank * 0x4000 + 0x12000]);
451      memory_set_bankptr(machine, "bank3", &state->rom[bank * 0x4000 + 0x10000]);
452      memory_set_bankptr(machine, "bank4", &state->rom[bank * 0x4000 + 0x12000]);
443453   }
444454}
445455
446456static void prg8_89( running_machine *machine, int bank )
447457{
458   nes_state *state = (nes_state *)machine->driver_data;
459
448460   /* assumes that bank references an 8k chunk */
449   bank &= ((nes.prg_chunks << 1) - 1);
450   if (nes.slow_banking)
451      memcpy(&nes.rom[0x8000], &nes.rom[bank * 0x2000 + 0x10000], 0x2000);
461   bank &= ((state->prg_chunks << 1) - 1);
462   if (state->slow_banking)
463      memcpy(&state->rom[0x8000], &state->rom[bank * 0x2000 + 0x10000], 0x2000);
452464   else
453      memory_set_bankptr(machine, "bank1", &nes.rom[bank * 0x2000 + 0x10000]);
465      memory_set_bankptr(machine, "bank1", &state->rom[bank * 0x2000 + 0x10000]);
454466}
455467
456468static void prg8_ab( running_machine *machine, int bank )
457469{
470   nes_state *state = (nes_state *)machine->driver_data;
471
458472   /* assumes that bank references an 8k chunk */
459   bank &= ((nes.prg_chunks << 1) - 1);
460   if (nes.slow_banking)
461      memcpy(&nes.rom[0xa000], &nes.rom[bank * 0x2000 + 0x10000], 0x2000);
473   bank &= ((state->prg_chunks << 1) - 1);
474   if (state->slow_banking)
475      memcpy(&state->rom[0xa000], &state->rom[bank * 0x2000 + 0x10000], 0x2000);
462476   else
463      memory_set_bankptr(machine, "bank2", &nes.rom[bank * 0x2000 + 0x10000]);
477      memory_set_bankptr(machine, "bank2", &state->rom[bank * 0x2000 + 0x10000]);
464478}
465479
466480static void prg8_cd( running_machine *machine, int bank )
467481{
482   nes_state *state = (nes_state *)machine->driver_data;
483
468484   /* assumes that bank references an 8k chunk */
469   bank &= ((nes.prg_chunks << 1) - 1);
470   if (nes.slow_banking)
471      memcpy(&nes.rom[0xc000], &nes.rom[bank * 0x2000 + 0x10000], 0x2000);
485   bank &= ((state->prg_chunks << 1) - 1);
486   if (state->slow_banking)
487      memcpy(&state->rom[0xc000], &state->rom[bank * 0x2000 + 0x10000], 0x2000);
472488   else
473      memory_set_bankptr(machine, "bank3", &nes.rom[bank * 0x2000 + 0x10000]);
489      memory_set_bankptr(machine, "bank3", &state->rom[bank * 0x2000 + 0x10000]);
474490}
475491
476492static void prg8_ef( running_machine *machine, int bank )
477493{
494   nes_state *state = (nes_state *)machine->driver_data;
495
478496   /* assumes that bank references an 8k chunk */
479   bank &= ((nes.prg_chunks << 1) - 1);
480   if (nes.slow_banking)
481      memcpy(&nes.rom[0xe000], &nes.rom[bank * 0x2000 + 0x10000], 0x2000);
497   bank &= ((state->prg_chunks << 1) - 1);
498   if (state->slow_banking)
499      memcpy(&state->rom[0xe000], &state->rom[bank * 0x2000 + 0x10000], 0x2000);
482500   else
483      memory_set_bankptr(machine, "bank4", &nes.rom[bank * 0x2000 + 0x10000]);
501      memory_set_bankptr(machine, "bank4", &state->rom[bank * 0x2000 + 0x10000]);
484502}
485503
486504/* We define an additional helper to map PRG-ROM to 0x6000-0x7000 */
r7952r7953
488506
489507static void prg8_67( running_machine *machine, int bank )
490508{
509   nes_state *state = (nes_state *)machine->driver_data;
510
491511   /* assumes that bank references an 8k chunk */
492   bank &= ((nes.prg_chunks << 1) - 1);
493   memory_set_bankptr(machine, "bank5", &nes.rom[bank * 0x2000 + 0x10000]);
512   bank &= ((state->prg_chunks << 1) - 1);
513   memory_set_bankptr(machine, "bank5", &state->rom[bank * 0x2000 + 0x10000]);
494514}
495515
496516/* CHR ROM in 1K, 2K, 4K or 8K blocks */
497517
498518static void chr8( running_machine *machine, int bank, int source )
499519{
520   nes_state *state = (nes_state *)machine->driver_data;
500521   int i;
501522
502   bank &= (nes.chr_chunks - 1);
523   bank &= (state->chr_chunks - 1);
503524   for (i = 0; i < 8; i++)
504525   {
505526      chr_map[i].source = source;
506527      chr_map[i].origin = (bank * 0x2000) + (i * 0x400); // for save state uses!
507528
508529      if (source == CHRRAM)
509         chr_map[i].access = &nes.vram[chr_map[i].origin];
530         chr_map[i].access = &state->vram[chr_map[i].origin];
510531      else
511         chr_map[i].access = &nes.vrom[chr_map[i].origin];
532         chr_map[i].access = &state->vrom[chr_map[i].origin];
512533   }
513534}
514535
515536static void chr4_x( running_machine *machine, int start, int bank, int source )
516537{
538   nes_state *state = (nes_state *)machine->driver_data;
517539   int i;
518540
519   bank &= ((nes.chr_chunks << 1) - 1);
541   bank &= ((state->chr_chunks << 1) - 1);
520542   for (i = 0; i < 4; i++)
521543   {
522544      chr_map[i + start].source = source;
523545      chr_map[i + start].origin = (bank * 0x1000) + (i * 0x400); // for save state uses!
524546
525547      if (source == CHRRAM)
526         chr_map[i+start].access = &nes.vram[chr_map[i + start].origin];
548         chr_map[i + start].access = &state->vram[chr_map[i + start].origin];
527549      else
528         chr_map[i+start].access = &nes.vrom[chr_map[i + start].origin];
550         chr_map[i + start].access = &state->vrom[chr_map[i + start].origin];
529551   }
530552}
531553
r7952r7953
541563
542564static void chr2_x( running_machine *machine, int start, int bank, int source )
543565{
566   nes_state *state = (nes_state *)machine->driver_data;
544567   int i;
545568
546   bank &= ((nes.chr_chunks << 2) - 1);
569   bank &= ((state->chr_chunks << 2) - 1);
547570   for (i = 0; i < 2; i++)
548571   {
549572      chr_map[i + start].source = source;
550573      chr_map[i + start].origin = (bank * 0x800) + (i * 0x400);
551574
552575      if (source == CHRRAM)
553         chr_map[i + start].access = &nes.vram[chr_map[i + start].origin];
576         chr_map[i + start].access = &state->vram[chr_map[i + start].origin];
554577      else
555         chr_map[i + start].access = &nes.vrom[chr_map[i + start].origin];
578         chr_map[i + start].access = &state->vrom[chr_map[i + start].origin];
556579   }
557580}
558581
r7952r7953
578601
579602static void chr1_x( running_machine *machine, int start, int bank, int source )
580603{
604   nes_state *state = (nes_state *)machine->driver_data;
605
581606   chr_map[start].source = source;
582   bank &= ((nes.chr_chunks << 3) - 1);
607   bank &= ((state->chr_chunks << 3) - 1);
583608   chr_map[start].origin = bank * 0x400;
584609
585610   if (source == CHRRAM)
586      chr_map[start].access = &nes.vram[chr_map[start].origin];
611      chr_map[start].access = &state->vram[chr_map[start].origin];
587612   else
588      chr_map[start].access = &nes.vrom[chr_map[start].origin];
613      chr_map[start].access = &state->vrom[chr_map[start].origin];
589614}
590615
591616static void chr1_0 (running_machine *machine, int bank, int source)
r7952r7953
631656
632657/* NameTable paging and mirroring */
633658
634static void set_nt_page( int page, int source, int bank, int writable )
659static void set_nt_page( running_machine *machine, int page, int source, int bank, int writable )
635660{
661   nes_state *state = (nes_state *)machine->driver_data;
636662   UINT8* base_ptr;
637663
638664   switch (source)
r7952r7953
644670         base_ptr = NULL;
645671         break;
646672      case ROM:
647         base_ptr = nes.vrom;
673         base_ptr = state->vrom;
648674         break;
649675      case EXRAM:
650676         base_ptr = nes_mmc5_vram;
651677         break;
652678      case CIRAM:
653679      default:
654         base_ptr = nes.ciram;
680         base_ptr = state->ciram;
655681         break;
656682   }
657683
r7952r7953
665691   nt_page[page].writable = writable;
666692}
667693
668void set_nt_mirroring( int mirroring )
694void set_nt_mirroring( running_machine *machine, int mirroring )
669695{
670696   /* setup our videomem handlers based on mirroring */
671697   switch (mirroring)
672698   {
673699      case PPU_MIRROR_VERT:
674         set_nt_page(0, CIRAM, 0, 1);
675         set_nt_page(1, CIRAM, 1, 1);
676         set_nt_page(2, CIRAM, 0, 1);
677         set_nt_page(3, CIRAM, 1, 1);
700         set_nt_page(machine, 0, CIRAM, 0, 1);
701         set_nt_page(machine, 1, CIRAM, 1, 1);
702         set_nt_page(machine, 2, CIRAM, 0, 1);
703         set_nt_page(machine, 3, CIRAM, 1, 1);
678704         break;
679705
680706      case PPU_MIRROR_HORZ:
681         set_nt_page(0, CIRAM, 0, 1);
682         set_nt_page(1, CIRAM, 0, 1);
683         set_nt_page(2, CIRAM, 1, 1);
684         set_nt_page(3, CIRAM, 1, 1);
707         set_nt_page(machine, 0, CIRAM, 0, 1);
708         set_nt_page(machine, 1, CIRAM, 0, 1);
709         set_nt_page(machine, 2, CIRAM, 1, 1);
710         set_nt_page(machine, 3, CIRAM, 1, 1);
685711         break;
686712
687713      case PPU_MIRROR_HIGH:
688         set_nt_page(0, CIRAM, 1, 1);
689         set_nt_page(1, CIRAM, 1, 1);
690         set_nt_page(2, CIRAM, 1, 1);
691         set_nt_page(3, CIRAM, 1, 1);
714         set_nt_page(machine, 0, CIRAM, 1, 1);
715         set_nt_page(machine, 1, CIRAM, 1, 1);
716         set_nt_page(machine, 2, CIRAM, 1, 1);
717         set_nt_page(machine, 3, CIRAM, 1, 1);
692718         break;
693719
694720      case PPU_MIRROR_LOW:
695         set_nt_page(0, CIRAM, 0, 1);
696         set_nt_page(1, CIRAM, 0, 1);
697         set_nt_page(2, CIRAM, 0, 1);
698         set_nt_page(3, CIRAM, 0, 1);
721         set_nt_page(machine, 0, CIRAM, 0, 1);
722         set_nt_page(machine, 1, CIRAM, 0, 1);
723         set_nt_page(machine, 2, CIRAM, 0, 1);
724         set_nt_page(machine, 3, CIRAM, 0, 1);
699725         break;
700726
701727      case PPU_MIRROR_NONE:
r7952r7953
707733
708734         logerror("Mapper set 4-screen mirroring without supplying external nametable memory!\n");
709735
710         set_nt_page(0, CIRAM, 0, 1);
711         set_nt_page(1, CIRAM, 0, 1);
712         set_nt_page(2, CIRAM, 1, 1);
713         set_nt_page(3, CIRAM, 1, 1);
736         set_nt_page(machine, 0, CIRAM, 0, 1);
737         set_nt_page(machine, 1, CIRAM, 0, 1);
738         set_nt_page(machine, 2, CIRAM, 1, 1);
739         set_nt_page(machine, 3, CIRAM, 1, 1);
714740         break;
715741   }
716742}
r7952r7953
741767
742768static int mapper_initialize( running_machine *machine, int mmc_num )
743769{
770   nes_state *state = (nes_state *)machine->driver_data;
744771   int err = 0, i;
745772
746773   switch (mmc_num)
r7952r7953
755782         mmc_count = 0;
756783         MMC1_regs[0] = 0x0f;
757784         MMC1_regs[1] = MMC1_regs[2] = MMC1_regs[3] = 0;
758         set_nt_mirroring(PPU_MIRROR_HORZ);
759         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
785         set_nt_mirroring(machine, PPU_MIRROR_HORZ);
786         mmc_chr_source = state->chr_chunks ? CHRROM : CHRRAM;
760787         MMC1_set_chr(machine);
761788         MMC1_set_prg(machine);
762789         break;
763790      case 2:
764791         /* These games don't switch VROM, but some ROMs incorrectly have CHR chunks */
765         nes.chr_chunks = 0;
792         state->chr_chunks = 0;
766793         prg16_89ab(machine, 0);
767         prg16_cdef(machine, nes.prg_chunks - 1);
794         prg16_cdef(machine, state->prg_chunks - 1);
768795         break;
769796      case 13:
770797         chr4_0(machine, 0, CHRRAM);
r7952r7953
779806         /* Only MMC3 and clones seem to use 4-screen! */
780807         /* hardware uses an 8K RAM chip, but can't address the high 4K! */
781808         /* that much is documented for Nintendo Gauntlet boards */
782         if(nes.four_screen_vram)
809         if(state->four_screen_vram)
783810         {
784            extended_ntram=auto_alloc_array(machine, UINT8, 0x2000);
785            set_nt_page(0, CART_NTRAM, 0, 1);
786            set_nt_page(1, CART_NTRAM, 1, 1);
787            set_nt_page(2, CART_NTRAM, 2, 1);
788            set_nt_page(3, CART_NTRAM, 3, 1);
811            extended_ntram = auto_alloc_array(machine, UINT8, 0x2000);
812            set_nt_page(machine, 0, CART_NTRAM, 0, 1);
813            set_nt_page(machine, 1, CART_NTRAM, 1, 1);
814            set_nt_page(machine, 2, CART_NTRAM, 2, 1);
815            set_nt_page(machine, 3, CART_NTRAM, 3, 1);
789816         }
790817      case 12:
791818      case 74:
r7952r7953
804831         mmc_cmd2 = 0x80;
805832         mmc_prg_base = mmc_chr_base = 0;
806833         mmc_prg_mask = mmc_chr_mask = 0xff;   // these could be init'ed as xxx_chunks-1 and they would work the same
807         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
834         mmc_chr_source = state->chr_chunks ? CHRROM : CHRRAM;
808835         mapper4_set_prg(machine, mmc_prg_base, mmc_prg_mask);
809836         mapper4_set_chr(machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
810837         break;
r7952r7953
813840         MMC5_rom_bank_mode = 3;
814841         MMC5_vrom_bank_mode = 0;
815842         MMC5_vram_protect = 0;
816         nes.mid_ram_enable = 0;
817         prg16_89ab(machine, nes.prg_chunks - 2);
818         prg16_cdef(machine, nes.prg_chunks - 1);
843         state->mid_ram_enable = 0;
844         prg16_89ab(machine, state->prg_chunks - 2);
845         prg16_cdef(machine, state->prg_chunks - 1);
819846         break;
820847      case 6:
821848         mmc_cmd1 = 0;
822         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
849         mmc_chr_source = state->chr_chunks ? CHRROM : CHRRAM;
823850         prg16_89ab(machine, 0);
824851         prg16_cdef(machine, 7);
825852         break;
826853      case 7:
827854         /* Bankswitches 32k at a time */
828         set_nt_mirroring(PPU_MIRROR_LOW);
855         set_nt_mirroring(machine, PPU_MIRROR_LOW);
829856         prg16_89ab(machine, 0);
830         prg16_cdef(machine, nes.prg_chunks - 1);
857         prg16_cdef(machine, state->prg_chunks - 1);
831858         break;
832859      case 8:
833860      case 96:
r7952r7953
839866         mmc_cmd1 = mmc_cmd2 = 0xfe;
840867         prg8_89(machine, 0);
841868         //ugly hack to deal with iNES header usage of chunk count.
842         prg8_ab(machine, (nes.prg_chunks << 1) - 3);
843         prg8_cd(machine, (nes.prg_chunks << 1) - 2);
844         prg8_ef(machine, (nes.prg_chunks << 1) - 1);
869         prg8_ab(machine, (state->prg_chunks << 1) - 3);
870         prg8_cd(machine, (state->prg_chunks << 1) - 2);
871         prg8_ef(machine, (state->prg_chunks << 1) - 1);
845872         break;
846873      case 10:
847874         /* Reset VROM latches */
r7952r7953
849876         MMC2_regs[1] = MMC2_regs[3] = 0;
850877         mmc_cmd1 = mmc_cmd2 = 0xfe;
851878         prg16_89ab(machine, 0);
852         prg16_cdef(machine, nes.prg_chunks - 1);
879         prg16_cdef(machine, state->prg_chunks - 1);
853880         break;
854881      case 11:
855         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;   // NINA-07 has no CHRROM
882         mmc_chr_source = state->chr_chunks ? CHRROM : CHRRAM;   // NINA-07 has no CHRROM
856883         prg32(machine, 0);
857884         break;
858885      case 14:
r7952r7953
867894         mmc_cmd2 = 0x80;
868895         mmc_prg_base = mmc_chr_base = 0;
869896         mmc_prg_mask = mmc_chr_mask = 0xff;
870         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
897         mmc_chr_source = state->chr_chunks ? CHRROM : CHRRAM;
871898         mapper4_set_prg(machine, mmc_prg_base, mmc_prg_mask);
872899         mapper4_set_chr(machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
873900         break;
874901      case 15:
875         set_nt_mirroring(PPU_MIRROR_VERT);
902         set_nt_mirroring(machine, PPU_MIRROR_VERT);
876903         prg32(machine, 0);
877904         break;
878905      case 16:
r7952r7953
882909      case 159:
883910         mmc_cmd1 = 0;
884911         prg16_89ab(machine, 0);
885         prg16_cdef(machine, nes.prg_chunks - 1);
886         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
912         prg16_cdef(machine, state->prg_chunks - 1);
913         mmc_chr_source = state->chr_chunks ? CHRROM : CHRRAM;
887914         break;
888915      case 19:
889916         mmc_cmd1 = 0;
890917         prg16_89ab(machine, 0);
891         prg16_cdef(machine, nes.prg_chunks - 1);
892         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
893         set_nt_mirroring(PPU_MIRROR_VERT);
918         prg16_cdef(machine, state->prg_chunks - 1);
919         mmc_chr_source = state->chr_chunks ? CHRROM : CHRRAM;
920         set_nt_mirroring(machine, PPU_MIRROR_VERT);
894921         break;
895922      case 20:
896923         fds_last_side = 0;
897924         fds_count = 0;
898         nes_fds.motor_on = 0;
899         nes_fds.door_closed = 0;
900         nes_fds.current_side = 1;
901         nes_fds.head_position = 0;
902         nes_fds.status0 = 0;
903         nes_fds.read_mode = nes_fds.write_reg = 0;
925         state->fds_motor_on = 0;
926         state->fds_door_closed = 0;
927         state->fds_current_side = 1;
928         state->fds_head_position = 0;
929         state->fds_status0 = 0;
930         state->fds_read_mode = state->fds_write_reg = 0;
904931         break;
905932      case 21:
906933      case 22:
r7952r7953
920947      case 207:
921948      case 222:
922949      case 252:
923         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
950         mmc_chr_source = state->chr_chunks ? CHRROM : CHRRAM;
924951         prg16_89ab(machine, 0);
925         prg16_cdef(machine, nes.prg_chunks - 1);
952         prg16_cdef(machine, state->prg_chunks - 1);
926953         break;
927954      case 32:
928955         mmc_cmd1 = 0;
929956         prg16_89ab(machine, 0);
930         prg16_cdef(machine, nes.prg_chunks - 1);
931         if (nes.crc_hack)
932            set_nt_mirroring(PPU_MIRROR_HIGH);  // needed by Major League
957         prg16_cdef(machine, state->prg_chunks - 1);
958         if (state->crc_hack)
959            set_nt_mirroring(machine, PPU_MIRROR_HIGH);  // needed by Major League
933960         break;
934961      case 34:
935962         prg32(machine, 0);
r7952r7953
945972         mmc_prg_base = mmc_chr_base = 0;
946973         mmc_prg_mask = 0x07;
947974         mmc_chr_mask = 0x7f;
948         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
975         mmc_chr_source = state->chr_chunks ? CHRROM : CHRRAM;
949976         mapper4_set_prg(machine, mmc_prg_base, mmc_prg_mask);
950977         mapper4_set_chr(machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
951978         break;
r7952r7953
961988         prg32(machine, 0);
962989         break;
963990      case 42:
964         prg32(machine, nes.prg_chunks - 1);
991         prg32(machine, state->prg_chunks - 1);
965992         break;
966993      case 43:
967994         prg32(machine, 0);
968         memset(nes.wram, 0x2000, 0xff);
995         memset(state->wram, 0x2000, 0xff);
969996         break;
970997      case 44:
971998      case 47:
r7952r7953
9771004         mmc_prg_base = mmc_chr_base = 0;
9781005         mmc_prg_mask = 0x0f;
9791006         mmc_chr_mask = 0x7f;
980         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
1007         mmc_chr_source = state->chr_chunks ? CHRROM : CHRRAM;
9811008         mapper4_set_prg(machine, mmc_prg_base, mmc_prg_mask);
9821009         mapper4_set_chr(machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
9831010         break;
r7952r7953
9861013         prg_bank[1] = prg_bank[3] = 0xff;
9871014         mmc_cmd1 = 0;
9881015         mmc_cmd2 = 0x80;
989         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
1016         mmc_chr_source = state->chr_chunks ? CHRROM : CHRRAM;
9901017         mapper45_reg[0] = mapper45_reg[1] = mapper45_reg[2] = mapper45_reg[3] = 0;
9911018         mmc_prg_base = 0x30;
9921019         mmc_prg_mask = 0x3f;
r7952r7953
9941021         mmc_chr_mask = 0x7f;
9951022         mapper4_set_prg(machine, mmc_prg_base, mmc_prg_mask);
9961023         mapper4_set_chr(machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
997         memory_set_bankptr(machine, "bank5", nes.wram);
1024         memory_set_bankptr(machine, "bank5", state->wram);
9981025         break;
9991026      case 46:
10001027         prg32(machine, 0);
r7952r7953
10031030      case 54:
10041031         prg32(machine, 0);
10051032         chr8(machine, 0, CHRROM);
1006         set_nt_mirroring(PPU_MIRROR_VERT);
1033         set_nt_mirroring(machine, PPU_MIRROR_VERT);
10071034         break;
10081035      case 50:
10091036         prg8_67(machine, 0x0f);
r7952r7953
10251052         mmc_cmd1 = 0;
10261053         mmc_cmd2 = 0x80;
10271054         map52_reg_written = 0;
1028         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
1055         mmc_chr_source = state->chr_chunks ? CHRROM : CHRRAM;
10291056         mmc_prg_base = 0;
10301057         mmc_prg_mask = 0x1f;
10311058         mmc_chr_base = 0;
10321059         mmc_chr_mask = 0xff;
10331060         mapper4_set_prg(machine, mmc_prg_base, mmc_prg_mask);
10341061         mapper4_set_chr(machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
1035         memory_set_bankptr(machine, "bank5", nes.wram);
1062         memory_set_bankptr(machine, "bank5", state->wram);
10361063         break;
10371064      case 57:
10381065         mmc_cmd1 = 0x00;
r7952r7953
10531080      case 64:
10541081      case 158:
10551082         mmc_cmd1 = 0;
1056         prg16_89ab(machine, nes.prg_chunks - 1);
1057         prg16_cdef(machine, nes.prg_chunks - 1);
1083         prg16_89ab(machine, state->prg_chunks - 1);
1084         prg16_cdef(machine, state->prg_chunks - 1);
10581085         break;
10591086      case 65:
10601087      case 67:
r7952r7953
10631090      case 78:
10641091      case 92:
10651092         prg16_89ab(machine, 0);
1066         prg16_cdef(machine, nes.prg_chunks - 1);
1093         prg16_cdef(machine, state->prg_chunks - 1);
10671094         break;
10681095      case 68:
10691096         m68_mirror = m0 = m1 = 0;
10701097         prg16_89ab(machine, 0);
1071         prg16_cdef(machine, nes.prg_chunks - 1);
1098         prg16_cdef(machine, state->prg_chunks - 1);
10721099         break;
10731100      case 70:
1074         prg16_89ab(machine, nes.prg_chunks - 2);
1075         prg16_cdef(machine, nes.prg_chunks - 1);
1101         prg16_89ab(machine, state->prg_chunks - 2);
1102         prg16_cdef(machine, state->prg_chunks - 1);
10761103         break;
10771104      case 71:
1078         set_nt_mirroring(PPU_MIRROR_HORZ);
1105         set_nt_mirroring(machine, PPU_MIRROR_HORZ);
10791106         prg16_89ab(machine, 0);
1080         prg16_cdef(machine, nes.prg_chunks - 1);
1107         prg16_cdef(machine, state->prg_chunks - 1);
10811108         break;
10821109      case 76:
10831110         prg8_89(machine, 0);
10841111         prg8_ab(machine, 1);
10851112         //cd is bankable, but this should init all banks just fine.
1086         prg16_cdef(machine, nes.prg_chunks - 1);
1113         prg16_cdef(machine, state->prg_chunks - 1);
10871114         chr2_0(machine, 0, CHRROM);
10881115         chr2_2(machine, 1, CHRROM);
10891116         chr2_4(machine, 2, CHRROM);
r7952r7953
11001127      case 146:
11011128         /* Mirroring always horizontal...? */
11021129//          Mirroring = 1;
1103         set_nt_mirroring(PPU_MIRROR_HORZ);
1130         set_nt_mirroring(machine, PPU_MIRROR_HORZ);
11041131         chr8(machine, 0, CHRROM);
11051132         prg32(machine, 0);
11061133         break;
r7952r7953
11211148         break;
11221149      case 89:
11231150         prg16_89ab(machine, 0);
1124         prg16_cdef(machine, nes.prg_chunks - 1);
1125         set_nt_mirroring(PPU_MIRROR_LOW);
1151         prg16_cdef(machine, state->prg_chunks - 1);
1152         set_nt_mirroring(machine, PPU_MIRROR_LOW);
11261153         break;
11271154      case 91:
1128         set_nt_mirroring(PPU_MIRROR_VERT);
1129         prg16_89ab(machine, nes.prg_chunks - 1);
1130         prg16_cdef(machine, nes.prg_chunks - 1);
1155         set_nt_mirroring(machine, PPU_MIRROR_VERT);
1156         prg16_89ab(machine, state->prg_chunks - 1);
1157         prg16_cdef(machine, state->prg_chunks - 1);
11311158         break;
11321159      case 93:
11331160      case 94:
11341161      case 95:
11351162      case 101:
11361163         prg16_89ab(machine, 0);
1137         prg16_cdef(machine, nes.prg_chunks - 1);
1164         prg16_cdef(machine, state->prg_chunks - 1);
11381165         break;
11391166      case 97:
1140         prg16_89ab(machine, nes.prg_chunks - 1);
1141         prg16_cdef(machine, nes.prg_chunks - 1);
1167         prg16_89ab(machine, state->prg_chunks - 1);
1168         prg16_cdef(machine, state->prg_chunks - 1);
11421169         break;
11431170      case 112:
11441171         mmc_cmd1 = 0;
11451172         prg16_89ab(machine, 0);
1146         prg16_cdef(machine, nes.prg_chunks - 1);
1173         prg16_cdef(machine, state->prg_chunks - 1);
11471174         break;
11481175      case 36:
11491176      case 38:
r7952r7953
11671194         prg16_cdef(machine, 0x0f);
11681195         break;
11691196      case 106:
1170         prg8_89(machine, (nes.prg_chunks << 1) - 1);
1197         prg8_89(machine, (state->prg_chunks << 1) - 1);
11711198         prg8_ab(machine, 0);
11721199         prg8_cd(machine, 0);
1173         prg8_ef(machine, (nes.prg_chunks << 1) - 1);
1200         prg8_ef(machine, (state->prg_chunks << 1) - 1);
11741201         break;
11751202      case 114:
11761203         map114_reg = map114_reg_enabled = 0;
r7952r7953
11801207         mmc_cmd2 = 0x80;
11811208         mmc_prg_base = mmc_chr_base = 0;
11821209         mmc_prg_mask = mmc_chr_mask = 0xff;
1183         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
1210         mmc_chr_source = state->chr_chunks ? CHRROM : CHRRAM;
11841211         mapper4_set_prg(machine, mmc_prg_base, mmc_prg_mask);
11851212         mapper4_set_chr(machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
11861213         break;
r7952r7953
11921219         mmc_cmd2 = 0x80;
11931220         mmc_prg_base = mmc_chr_base = 0;
11941221         mmc_prg_mask = mmc_chr_mask = 0xff;
1195         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
1222         mmc_chr_source = state->chr_chunks ? CHRROM : CHRRAM;
11961223         mapper4_set_prg(machine, mmc_prg_base, mmc_prg_mask);
11971224         mapper4_set_chr(machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
11981225         break;
r7952r7953
12041231         mmc_cmd2 = 0x80;
12051232         mmc_prg_base = mmc_chr_base = 0;
12061233         mmc_prg_mask = mmc_chr_mask = 0xff;
1207         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
1234         mmc_chr_source = state->chr_chunks ? CHRROM : CHRRAM;
12081235         mapper4_set_prg(machine, mmc_prg_base, mmc_prg_mask);
12091236         mapper4_set_chr(machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
12101237         break;
r7952r7953
12221249         mmc_prg_base = mmc_chr_base = 0;
12231250         mmc_prg_mask = 0x1f;
12241251         mmc_chr_mask = 0xff;
1225         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
1252         mmc_chr_source = state->chr_chunks ? CHRROM : CHRRAM;
12261253         mapper4_set_prg(machine, mmc_prg_base, mmc_prg_mask);
12271254         mapper4_set_chr(machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
12281255         break;
r7952r7953
12431270      case 137:
12441271         mmc_cmd1 = 0;
12451272         prg32(machine, 0);
1246         chr8(machine, nes.chr_chunks - 1, CHRROM);
1247         set_nt_mirroring(PPU_MIRROR_VERT);
1273         chr8(machine, state->chr_chunks - 1, CHRROM);
1274         set_nt_mirroring(machine, PPU_MIRROR_VERT);
12481275         break;
12491276      case 138:
12501277      case 139:
12511278      case 141:
12521279         mmc_cmd1 = 0;
1253         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
1280         mmc_chr_source = state->chr_chunks ? CHRROM : CHRRAM;
12541281         prg32(machine, 0);
12551282         chr8(machine, 0, mmc_chr_source);
1256         set_nt_mirroring(PPU_MIRROR_VERT);
1283         set_nt_mirroring(machine, PPU_MIRROR_VERT);
12571284         break;
12581285      case 143:
12591286         prg16_89ab(machine, 0);
r7952r7953
12731300         mmc_cmd1 = 0;
12741301         prg32(machine, 0);
12751302         chr8(machine, 0, CHRROM);
1276         set_nt_mirroring(PPU_MIRROR_VERT);
1303         set_nt_mirroring(machine, PPU_MIRROR_VERT);
12771304         break;
12781305      case 152:
12791306         prg16_89ab(machine, 0);
1280         prg16_cdef(machine, nes.prg_chunks - 1);
1307         prg16_cdef(machine, state->prg_chunks - 1);
12811308         chr8(machine, 0, CHRROM);
12821309         break;
12831310      case 153:
12841311         mmc_cmd1 = 0;
12851312         prg16_89ab(machine, 0);
1286         prg16_cdef(machine, nes.prg_chunks - 1);
1287         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
1313         prg16_cdef(machine, state->prg_chunks - 1);
1314         mmc_chr_source = state->chr_chunks ? CHRROM : CHRRAM;
12881315         // Famicom Jump II needs also the following!
12891316         for (i = 0; i < 8; i++)
12901317            map153_reg[i] = 0;
12911318
12921319         map153_bank_latch = 0;
1293         if (nes.crc_hack)
1320         if (state->crc_hack)
12941321            mapper153_set_prg(machine);
12951322         break;
12961323      case 154:
1297         prg16_89ab(machine, nes.prg_chunks - 2);
1298         prg16_cdef(machine, nes.prg_chunks - 1);
1324         prg16_89ab(machine, state->prg_chunks - 2);
1325         prg16_cdef(machine, state->prg_chunks - 1);
12991326         break;
13001327      case 156:
1301         prg16_89ab(machine, nes.prg_chunks - 2);
1302         prg16_cdef(machine, nes.prg_chunks - 1);
1303         set_nt_mirroring(PPU_MIRROR_LOW);
1328         prg16_89ab(machine, state->prg_chunks - 2);
1329         prg16_cdef(machine, state->prg_chunks - 1);
1330         set_nt_mirroring(machine, PPU_MIRROR_LOW);
13041331         break;
13051332      case 164:
13061333         prg32(machine, 0xff);
1307         nes.mid_ram_enable = 1;
1334         state->mid_ram_enable = 1;
13081335         break;
13091336      case 176:
1310         prg32(machine, (nes.prg_chunks - 1) >> 1);
1337         prg32(machine, (state->prg_chunks - 1) >> 1);
13111338         break;
13121339      case 178:
13131340         mmc_cmd1 = 0;
r7952r7953
13181345         prg16_cdef(machine, 0);
13191346         break;
13201347      case 182:
1321         prg32(machine, (nes.prg_chunks - 1) >> 1);
1348         prg32(machine, (state->prg_chunks - 1) >> 1);
13221349         break;
13231350      case 188:
13241351         prg16_89ab(machine, 0);
1325         prg16_cdef(machine, (nes.prg_chunks - 1) ^ 0x08);
1352         prg16_cdef(machine, (state->prg_chunks - 1) ^ 0x08);
13261353         break;
13271354      case 187:
13281355         prg_bank[0] = prg_bank[2] = 0xfe;
r7952r7953
13321359         mmc_cmd2 = 0x80;
13331360         mmc_prg_base = mmc_chr_base = 0;
13341361         mmc_prg_mask = mmc_chr_mask = 0xff;
1335         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
1362         mmc_chr_source = state->chr_chunks ? CHRROM : CHRRAM;
13361363         mapper187_set_prg(machine, mmc_prg_base, mmc_prg_mask);
13371364         mapper187_set_chr(machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
13381365         break;
r7952r7953
13411368         mmc_cmd2 = 0x80;
13421369         mmc_chr_base = 0;
13431370         mmc_chr_mask = 0xff;
1344         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
1371         mmc_chr_source = state->chr_chunks ? CHRROM : CHRRAM;
13451372         prg32(machine, 0);
13461373         mapper4_set_chr(machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
13471374         break;
13481375      case 193:
1349         prg32(machine, (nes.prg_chunks - 1) >> 1);
1350         set_nt_mirroring(PPU_MIRROR_VERT);
1376         prg32(machine, (state->prg_chunks - 1) >> 1);
1377         set_nt_mirroring(machine, PPU_MIRROR_VERT);
13511378         break;
13521379      case 197:
13531380         prg_bank[0] = prg_bank[2] = 0xfe;
r7952r7953
13561383         mmc_cmd2 = 0x80;
13571384         mmc_prg_base = mmc_chr_base = 0;
13581385         mmc_prg_mask = mmc_chr_mask = 0xff;
1359         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
1386         mmc_chr_source = state->chr_chunks ? CHRROM : CHRRAM;
13601387         mapper4_set_prg(machine, mmc_prg_base, mmc_prg_mask);
13611388         mapper197_set_chr(machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
13621389         break;
r7952r7953
13691396         mmc_cmd2 = 0x80;
13701397         mmc_prg_base = mmc_chr_base = 0;
13711398         mmc_prg_mask = mmc_chr_mask = 0xff;
1372         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
1399         mmc_chr_source = state->chr_chunks ? CHRROM : CHRRAM;
13731400         mapper198_set_prg(machine, mmc_prg_base, mmc_prg_mask);
13741401         mapper4_set_chr(machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
13751402         break;
r7952r7953
13821409         mmc_cmd2 = 0x80;
13831410         mmc_prg_base = mmc_chr_base = 0;
13841411         mmc_prg_mask = mmc_chr_mask = 0xff;
1385         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
1412         mmc_chr_source = state->chr_chunks ? CHRROM : CHRRAM;
13861413         mapper4_set_prg(machine, mmc_prg_base, mmc_prg_mask);
13871414         mapper199_set_chr(machine, mmc_chr_base, mmc_chr_mask);
13881415         break;
13891416      case 200:
1390         prg16_89ab(machine, nes.prg_chunks - 1);
1391         prg16_cdef(machine, nes.prg_chunks - 1);
1417         prg16_89ab(machine, state->prg_chunks - 1);
1418         prg16_cdef(machine, state->prg_chunks - 1);
13921419         break;
13931420      case 201:
13941421      case 213:
r7952r7953
14121439         mmc_prg_mask = 0x1f;
14131440         mmc_chr_base = 0;
14141441         mmc_chr_mask = 0xff;
1415         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
1442         mmc_chr_source = state->chr_chunks ? CHRROM : CHRRAM;
14161443         mapper4_set_prg(machine, mmc_prg_base, mmc_prg_mask);
14171444         mapper4_set_chr(machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
14181445         break;
r7952r7953
14241451         mmc_cmd2 = 0x80;
14251452         mmc_prg_base = mmc_chr_base = 0;
14261453         mmc_prg_mask = mmc_chr_mask = 0xff;
1427         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
1454         mmc_chr_source = state->chr_chunks ? CHRROM : CHRRAM;
14281455         mapper4_set_prg(machine, mmc_prg_base, mmc_prg_mask);
14291456         mapper4_set_chr(machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
14301457         break;
r7952r7953
14451472         map215_reg[3] = 0;
14461473         mmc_prg_base = 0;
14471474         mmc_prg_mask = 0x1f;
1448         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
1475         mmc_chr_source = state->chr_chunks ? CHRROM : CHRRAM;
14491476         mapper215_set_prg(machine, mmc_prg_base, mmc_prg_mask);
14501477         mapper215_set_chr(machine, mmc_chr_source);
14511478         break;
14521479      case 216:
1453         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
1480         mmc_chr_source = state->chr_chunks ? CHRROM : CHRRAM;
14541481         prg32(machine, 0);
14551482         chr8(machine, 0, mmc_chr_source);
14561483         break;
r7952r7953
14651492         mmc_cmd2 = 0x80;
14661493         mmc_prg_base = mmc_chr_base = 0;
14671494         mmc_prg_mask = mmc_chr_mask = 0xff;
1468         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
1495         mmc_chr_source = state->chr_chunks ? CHRROM : CHRRAM;
14691496         mapper217_set_prg(machine, mmc_prg_base, mmc_prg_mask);
14701497         mapper217_set_chr(machine, mmc_chr_source);
14711498         break;
r7952r7953
14921519         prg16_89ab(machine, 0);
14931520         prg16_cdef(machine, 1);
14941521         chr8(machine, 0, CHRROM);
1495         set_nt_mirroring(PPU_MIRROR_VERT);
1522         set_nt_mirroring(machine, PPU_MIRROR_VERT);
14961523         break;
14971524      case 230:
14981525         prg16_89ab(machine, 0);
r7952r7953
15001527         break;
15011528      case 231:
15021529         prg16_89ab(machine, 0);
1503         prg16_cdef(machine, nes.prg_chunks - 1);
1504         set_nt_mirroring(PPU_MIRROR_VERT);
1530         prg16_cdef(machine, state->prg_chunks - 1);
1531         set_nt_mirroring(machine, PPU_MIRROR_VERT);
15051532         break;
15061533      case 232:
15071534         mmc_cmd1 = 0x18;
r7952r7953
15131540         mmc_cmd1 = 0;
15141541         chr8(machine, 3, CHRROM);
15151542         prg32(machine, 0);
1516         set_nt_mirroring(PPU_MIRROR_VERT);
1543         set_nt_mirroring(machine, PPU_MIRROR_VERT);
15171544         break;
15181545      case 246:
15191546         prg32(machine, 0xff);
r7952r7953
15261553         map249_reg = 0;
15271554         mmc_prg_base = mmc_chr_base = 0;
15281555         mmc_prg_mask = mmc_chr_mask = 0xff;
1529         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
1556         mmc_chr_source = state->chr_chunks ? CHRROM : CHRRAM;
15301557         mapper249_set_prg(machine, mmc_prg_base, mmc_prg_mask);
15311558         mapper249_set_chr(machine, mmc_chr_base, mmc_chr_mask);
15321559         break;
r7952r7953
15591586   int err = 0, i;
15601587   const mmc *mapper;
15611588
1562   if (nes.chr_chunks == 0)
1589   if (state->chr_chunks == 0)
15631590      chr8(machine, 0,CHRRAM);
15641591   else
15651592      chr8(machine, 0,CHRROM);
r7952r7953
15811608
15821609   /* Point the WRAM/battery area to the first RAM bank */
15831610   if (mmc_num != 20)
1584      memory_set_bankptr(machine, "bank5", &nes.wram[0x0000]);
1611      memory_set_bankptr(machine, "bank5", &state->wram[0x0000]);
15851612
15861613   /* Here, we init a few helpers: 4 prg banks and 16 chr banks - some mappers use them */
15871614   for (i = 0; i < 4; i++)
r7952r7953
16251652   int err = 0;
16261653   const unif *unif_board;
16271654
1628   if (nes.chr_chunks == 0)
1655   if (state->chr_chunks == 0)
16291656      chr8(machine, 0,CHRRAM);
16301657   else
16311658      chr8(machine, 0,CHRROM);
r7952r7953
16411668
16421669
16431670   /* Point the WRAM/battery area to the first RAM bank */
1644   memory_set_bankptr(machine, "bank5", &nes.wram[0x0000]);
1671   memory_set_bankptr(machine, "bank5", &state->wram[0x0000]);
16451672
16461673   switch (unif_board->board_idx)
16471674   {
r7952r7953
16501677         bmc_64in1nr_reg[1] = 0x43;
16511678         bmc_64in1nr_reg[2] = bmc_64in1nr_reg[3] = 0;
16521679         bmc_64in1nr_set_prg(machine);
1653         set_nt_mirroring(PPU_MIRROR_VERT);
1680         set_nt_mirroring(machine, PPU_MIRROR_VERT);
16541681         chr8(machine, 0, CHRROM);
16551682         break;
16561683      case BMC_190IN1:
r7952r7953
16611688      case BMC_A65AS:
16621689         prg16_89ab(machine, 0);
16631690         prg16_cdef(machine, 7);
1664         set_nt_mirroring(PPU_MIRROR_VERT);
1691         set_nt_mirroring(machine, PPU_MIRROR_VERT);
16651692         break;
16661693      case BMC_GS2004:
16671694      case BMC_GS2013:
r7952r7953
17231750         mapper_initialize(machine, 4);
17241751         break;
17251752      case UNL_T230:
1726         mmc_chr_source = nes.chr_chunks ? CHRROM : CHRRAM;
1753         mmc_chr_source = state->chr_chunks ? CHRROM : CHRRAM;
17271754         prg16_89ab(machine, 0);
1728         prg16_cdef(machine, nes.prg_chunks - 1);
1755         prg16_cdef(machine, state->prg_chunks - 1);
17291756         break;
17301757      /* For the Boards corresponding to a Mapper, fall back to the mapper init */
17311758      case STD_NROM:
r7952r7953
19021929         mapper_initialize(machine, 71);
19031930         break;
19041931      case CAMERICA_9097:
1905         nes.crc_hack = 0xf0;
1932         state->crc_hack = 0xf0;
19061933         mapper_initialize(machine, 71);
19071934         break;
19081935      case JALECO_JF17:
src/mess/machine/nes_mmc.h
r7952r7953
8383#define PPU_MIRROR_LOW      4
8484#define PPU_MIRROR_4SCREEN   5   // Same effect as NONE, but signals that we should never mirror
8585
86void set_nt_mirroring(int mirroring);
86void set_nt_mirroring(running_machine *machine, int mirroring);
8787
8888
8989#endif
src/mess/machine/nes_ines.c
r7952r7953
120120
121121         switch (MMC1_regs[0] & 0x03)
122122         {
123            case 0: set_nt_mirroring(PPU_MIRROR_LOW); break;
124            case 1: set_nt_mirroring(PPU_MIRROR_HIGH); break;
125            case 2: set_nt_mirroring(PPU_MIRROR_VERT); break;
126            case 3: set_nt_mirroring(PPU_MIRROR_HORZ); break;
123            case 0: set_nt_mirroring(space->machine, PPU_MIRROR_LOW); break;
124            case 1: set_nt_mirroring(space->machine, PPU_MIRROR_HIGH); break;
125            case 2: set_nt_mirroring(space->machine, PPU_MIRROR_VERT); break;
126            case 3: set_nt_mirroring(space->machine, PPU_MIRROR_HORZ); break;
127127         }
128128         MMC1_set_chr(space->machine);
129129         MMC1_set_prg(space->machine);
r7952r7953
259259
260260static WRITE8_HANDLER( mapper4_w )
261261{
262   nes_state *state = (nes_state *)space->machine->driver_data;
262263   UINT8 MMC3_helper, cmd;
263264
264265   LOG_MMC(("mapper4_w offset: %04x, data: %02x\n", offset, data));
r7952r7953
296297         break;
297298
298299      case 0x2000:
299         set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
300         set_nt_mirroring(space->machine, BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
300301         break;
301302
302303      case 0x2001: /* extra RAM enable/disable */
303304         mmc_cmd2 = data;   /* This actually is made of two parts: data&0x80 = WRAM enabled and data&0x40 = WRAM readonly!  */
304305                  /* We save this twice because we will need mmc_cmd2 in some clone mapper */
305         nes.mid_ram_enable = data;
306         state->mid_ram_enable = data;
306307         break;
307308
308309      case 0x4000:
r7952r7953
357358   }
358359}
359360
360static void ppu_mirror_MMC5( int page, int src )
361static void ppu_mirror_MMC5( running_machine *machine, int page, int src )
361362{
362363   switch (src)
363364   {
364365   case 0:   /* CIRAM0 */
365      set_nt_page(page, CIRAM, 0, 1);
366      set_nt_page(machine, page, CIRAM, 0, 1);
366367      break;
367368   case 1:   /* CIRAM1 */
368      set_nt_page(page, CIRAM, 1, 1);
369      set_nt_page(machine, page, CIRAM, 1, 1);
369370      break;
370371   case 2:   /* ExRAM */
371      set_nt_page(page, EXRAM, 0, 1);   // actually only works during rendering.
372      set_nt_page(machine, page, EXRAM, 0, 1);   // actually only works during rendering.
372373      break;
373374   case 3: /* Fill Registers */
374      set_nt_page(page, MMC5FILL, 0, 0);
375      set_nt_page(machine, page, MMC5FILL, 0, 0);
375376      break;
376377   default:
377378      fatalerror("This should never happen");
r7952r7953
479480         break;
480481
481482      case 0x1005: /* $5105 */
482         ppu_mirror_MMC5(0, data & 0x03);
483         ppu_mirror_MMC5(1, (data & 0x0c) >> 2);
484         ppu_mirror_MMC5(2, (data & 0x30) >> 4);
485         ppu_mirror_MMC5(3, (data & 0xc0) >> 6);
483         ppu_mirror_MMC5(space->machine, 0, data & 0x03);
484         ppu_mirror_MMC5(space->machine, 1, (data & 0x0c) >> 2);
485         ppu_mirror_MMC5(space->machine, 2, (data & 0x30) >> 4);
486         ppu_mirror_MMC5(space->machine, 3, (data & 0xc0) >> 6);
486487         break;
487488
488489      /* tile data for MMC5 flood-fill NT mode */
r7952r7953
504505
505506      case 0x1013: /* $5113 */
506507         LOG_MMC(("MMC5 mid RAM bank select: %02x\n", data & 0x07));
507         memory_set_bankptr(space->machine, "bank5", &nes.wram[data * 0x2000]);
508         memory_set_bankptr(space->machine, "bank5", &state->wram[data * 0x2000]);
508509         /* The & 4 is a hack that'll tide us over for now */
509         nes_battery_ram = &nes.wram[(data & 4) * 0x2000];
510         nes_battery_ram = &state->wram[(data & 4) * 0x2000];
510511         break;
511512
512513      case 0x1014: /* $5114 */
r7952r7953
519520               {
520521                  /* ROM */
521522                  LOG_MMC(("\tROM bank select (8k, $8000): %02x\n", data));
522                  data &= ((nes.prg_chunks << 1) - 1);
523                  memory_set_bankptr(space->machine, "bank1", &nes.rom[data * 0x2000 + 0x10000]);
523                  data &= ((state->prg_chunks << 1) - 1);
524                  memory_set_bankptr(space->machine, "bank1", &state->rom[data * 0x2000 + 0x10000]);
524525               }
525526               else
526527               {
527528                  /* RAM */
528529                  LOG_MMC(("\tRAM bank select (8k, $8000): %02x\n", data & 0x07));
529530                  /* The & 4 is a hack that'll tide us over for now */
530                  memory_set_bankptr(space->machine, "bank1", &nes.wram[(data & 4) * 0x2000]);
531                  memory_set_bankptr(space->machine, "bank1", &state->wram[(data & 4) * 0x2000]);
531532               }
532533               break;
533534         }
r7952r7953
548549                  /* RAM */
549550                  LOG_MMC(("\tRAM bank select (16k, $8000): %02x\n", data & 0x07));
550551                  /* The & 4 is a hack that'll tide us over for now */
551                  memory_set_bankptr(space->machine, "bank1", &nes.wram[((data & 4) >> 1) * 0x4000]);
552                  memory_set_bankptr(space->machine, "bank2", &nes.wram[((data & 4) >> 1) * 0x4000 + 0x2000]);
552                  memory_set_bankptr(space->machine, "bank1", &state->wram[((data & 4) >> 1) * 0x4000]);
553                  memory_set_bankptr(space->machine, "bank2", &state->wram[((data & 4) >> 1) * 0x4000 + 0x2000]);
553554               }
554555               break;
555556            case 0x03:
r7952r7953
557558               if (data & 0x80)
558559               {
559560                  /* ROM */
560                  data &= ((nes.prg_chunks << 1) - 1);
561                  memory_set_bankptr(space->machine, "bank2", &nes.rom[data * 0x2000 + 0x10000]);
561                  data &= ((state->prg_chunks << 1) - 1);
562                  memory_set_bankptr(space->machine, "bank2", &state->rom[data * 0x2000 + 0x10000]);
562563               }
563564               else
564565               {
565566                  /* RAM */
566567                  LOG_MMC(("\tRAM bank select (8k, $a000): %02x\n", data & 0x07));
567568                  /* The & 4 is a hack that'll tide us over for now */
568                  memory_set_bankptr(space->machine, "bank2", &nes.wram[(data & 4) * 0x2000]);
569                  memory_set_bankptr(space->machine, "bank2", &state->wram[(data & 4) * 0x2000]);
569570               }
570571               break;
571572         }
r7952r7953
580581               if (data & 0x80)
581582               {
582583                  /* ROM */
583                  data &= ((nes.prg_chunks << 1) - 1);
584                  memory_set_bankptr(space->machine, "bank3", &nes.rom[data * 0x2000 + 0x10000]);
584                  data &= ((state->prg_chunks << 1) - 1);
585                  memory_set_bankptr(space->machine, "bank3", &state->rom[data * 0x2000 + 0x10000]);
585586               }
586587               else
587588               {
588589                  /* RAM */
589590                  LOG_MMC(("\tRAM bank select (8k, $c000): %02x\n", data & 0x07));
590591                  /* The & 4 is a hack that'll tide us over for now */
591                  memory_set_bankptr(space->machine, "bank3", &nes.wram[(data & 4)* 0x2000]);
592                  memory_set_bankptr(space->machine, "bank3", &state->wram[(data & 4)* 0x2000]);
592593               }
593594               break;
594595         }
r7952r7953
608609            case 0x02:
609610            case 0x03:
610611               /* 8k switch */
611               data &= ((nes.prg_chunks << 1) - 1);
612               memory_set_bankptr(space->machine, "bank4", &nes.rom[data * 0x2000 + 0x10000]);
612               data &= ((state->prg_chunks << 1) - 1);
613               memory_set_bankptr(space->machine, "bank4", &state->rom[data * 0x2000 + 0x10000]);
613614               break;
614615         }
615616         break;
r7952r7953
936937   {
937938      case 0x1fe:
938939         mmc_cmd1 = data & 0x80;
939         set_nt_mirroring((data & 0x10) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
940         set_nt_mirroring(space->machine, BIT(data, 4) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
940941         break;
941942      case 0x1ff:
942         set_nt_mirroring((data & 0x10) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
943         set_nt_mirroring(space->machine, BIT(data, 4) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
943944         break;
944945
945946      case 0x401:
r7952r7953
987988{
988989   LOG_MMC(("mapper7_w, offset: %04x, data: %02x\n", offset, data));
989990
990   set_nt_mirroring((data & 0x10) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
991   set_nt_mirroring(space->machine, BIT(data, 4) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
991992   prg32(space->machine, data);
992993}
993994
r7952r7953
10781079            chr4_4(space->machine, MMC2_regs[3], CHRROM);
10791080         break;
10801081      case 0x7000:
1081         set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
1082         set_nt_mirroring(space->machine, BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
10821083         break;
10831084      default:
10841085         LOG_MMC(("MMC2 uncaught w: %04x:%02x\n", offset, data));
r7952r7953
13071308      mapper14_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
13081309
13091310      if (!(map14_reg[0] & 0x02))
1310         set_nt_mirroring(map14_reg[1] & 0x01 ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
1311         set_nt_mirroring(space->machine, BIT(map14_reg[1], 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
13111312   }
13121313
13131314   if (map14_reg[0] & 0x02)
r7952r7953
13491350         break;
13501351
13511352      case 0x2000:
1352         set_nt_mirroring(map14_reg[1] & 0x01 ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
1353         set_nt_mirroring(space->machine, BIT(map14_reg[1], 0) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
13531354         break;
13541355
13551356      default:
r7952r7953
13771378
13781379      case 0x1000:
13791380         map14_reg[1] = data;
1380         set_nt_mirroring(map14_reg[1] & 0x01 ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
1381         set_nt_mirroring(space->machine, BIT(map14_reg[1], 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
13811382         break;
13821383      }
13831384   }
r7952r7953
14011402
14021403   LOG_MMC(("mapper15_w, offset: %04x, data: %02x\n", offset, data));
14031404
1404   set_nt_mirroring((data & 0x40) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
1405   set_nt_mirroring(space->machine, BIT(data, 6) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
14051406
14061407   switch (offset & 0x0fff)
14071408   {
r7952r7953
14861487      case 9:
14871488         switch (data & 0x03)
14881489         {
1489            case 0: set_nt_mirroring(PPU_MIRROR_VERT); break;
1490            case 1: set_nt_mirroring(PPU_MIRROR_HORZ); break;
1491            case 2: set_nt_mirroring(PPU_MIRROR_LOW); break;
1492            case 3: set_nt_mirroring(PPU_MIRROR_HIGH); break;
1490            case 0: set_nt_mirroring(space->machine, PPU_MIRROR_VERT); break;
1491            case 1: set_nt_mirroring(space->machine, PPU_MIRROR_HORZ); break;
1492            case 2: set_nt_mirroring(space->machine, PPU_MIRROR_LOW); break;
1493            case 3: set_nt_mirroring(space->machine, PPU_MIRROR_HIGH); break;
14931494         }
14941495         break;
14951496      case 0x0a:
r7952r7953
15331534   switch (offset)
15341535   {
15351536      case 0x1fe:
1536         set_nt_mirroring((data & 0x10) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
1537         set_nt_mirroring(space->machine, BIT(data, 4) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
15371538         break;
15381539      case 0x1ff:
1539         set_nt_mirroring((data & 0x10) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
1540         set_nt_mirroring(space->machine, BIT(data, 4) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
15401541         break;
15411542
15421543      case 0x401:
r7952r7953
17081709      case 0x7002:
17091710         switch (data & 0x03)
17101711         {
1711            case 0: set_nt_mirroring(PPU_MIRROR_HORZ); break;
1712            case 1: set_nt_mirroring(PPU_MIRROR_VERT); break;
1713            case 2: set_nt_mirroring(PPU_MIRROR_LOW); break;
1714            case 3: set_nt_mirroring(PPU_MIRROR_HIGH); break;
1712            case 0: set_nt_mirroring(space->machine, PPU_MIRROR_HORZ); break;
1713            case 1: set_nt_mirroring(space->machine, PPU_MIRROR_VERT); break;
1714            case 2: set_nt_mirroring(space->machine, PPU_MIRROR_LOW); break;
1715            case 3: set_nt_mirroring(space->machine, PPU_MIRROR_HIGH); break;
17151716         }
17161717         break;
17171718
r7952r7953
17861787   }
17871788}
17881789
1789static void mapper19_set_mirror( UINT8 page, UINT8 data )
1790static void mapper19_set_mirror( running_machine *machine, UINT8 page, UINT8 data )
17901791{
17911792   if (!(data < 0xe0))
1792      set_nt_page(page, CIRAM, data & 0x01, 1);
1793      set_nt_page(machine, page, CIRAM, data & 0x01, 1);
17931794   else
1794      set_nt_page(page, ROM, data, 0);
1795      set_nt_page(machine, page, ROM, data, 0);
17951796}
17961797
17971798static WRITE8_HANDLER( mapper19_w )
r7952r7953
18061807         chr1_x(space->machine, offset / 0x800, data, CHRROM);
18071808         break;
18081809      case 0x4000:
1809         mapper19_set_mirror(0, data);
1810         mapper19_set_mirror(space->machine, 0, data);
18101811         break;
18111812      case 0x4800:
1812         mapper19_set_mirror(1, data);
1813         mapper19_set_mirror(space->machine, 1, data);
18131814         break;
18141815      case 0x5000:
1815         mapper19_set_mirror(2, data);
1816         mapper19_set_mirror(space->machine, 2, data);
18161817         break;
18171818      case 0x5800:
1818         mapper19_set_mirror(3, data);
1819         mapper19_set_mirror(space->machine, 3, data);
18191820         break;
18201821      case 0x6000:
18211822         prg8_89(space->machine, data & 0x3f);
r7952r7953
18461847
18471848static void fds_irq( running_device *device, int scanline, int vblank, int blanked )
18481849{
1850   nes_state *state = (nes_state *)device->machine->driver_data;
1851
18491852   if (IRQ_enable_latch)
18501853      cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
18511854
r7952r7953
18551858      {
18561859         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
18571860         IRQ_enable = 0;
1858         nes_fds.status0 |= 0x01;
1861         state->fds_status0 |= 0x01;
18591862      }
18601863      else
18611864         IRQ_count -= 114;
r7952r7953
18641867
18651868READ8_HANDLER( nes_fds_r )
18661869{
1870   nes_state *state = (nes_state *)space->machine->driver_data;
18671871   UINT8 ret = 0x00;
18681872   LOG_MMC(("fds_r, offset: %04x\n", offset));
18691873
18701874   switch (offset)
18711875   {
18721876      case 0x00: /* $4030 - disk status 0 */
1873         ret = nes_fds.status0;
1877         ret = state->fds_status0;
18741878         /* clear the disk IRQ detect flag */
1875         nes_fds.status0 &= ~0x01;
1879         state->fds_status0 &= ~0x01;
18761880         break;
18771881      case 0x01: /* $4031 - data latch */
18781882         /* don't read data if disk is unloaded */
1879         if (nes_fds.data == NULL)
1883         if (state->fds_data == NULL)
18801884            ret = 0;
1881         else if (nes_fds.current_side)
1882            ret = nes_fds.data[(nes_fds.current_side-1) * 65500 + nes_fds.head_position++];
1885         else if (state->fds_current_side)
1886            ret = state->fds_data[(state->fds_current_side - 1) * 65500 + state->fds_head_position++];
18831887         else
18841888            ret = 0;
18851889         break;
18861890      case 0x02: /* $4032 - disk status 1 */
18871891         /* return "no disk" status if disk is unloaded */
1888         if (nes_fds.data == NULL)
1892         if (state->fds_data == NULL)
18891893            ret = 1;
1890         else if (fds_last_side != nes_fds.current_side)
1894         else if (fds_last_side != state->fds_current_side)
18911895         {
18921896            /* If we've switched disks, report "no disk" for a few reads */
18931897            ret = 1;
18941898            fds_count ++;
18951899            if (fds_count == 50)
18961900            {
1897               fds_last_side = nes_fds.current_side;
1901               fds_last_side = state->fds_current_side;
18981902               fds_count = 0;
18991903            }
19001904         }
19011905         else
1902            ret = (nes_fds.current_side == 0); /* 0 if a disk is inserted */
1906            ret = (state->fds_current_side == 0); /* 0 if a disk is inserted */
19031907         break;
19041908      case 0x03: /* $4033 */
19051909         ret = 0x80;
r7952r7953
19161920
19171921WRITE8_HANDLER( nes_fds_w )
19181922{
1923   nes_state *state = (nes_state *)space->machine->driver_data;
19191924   LOG_MMC(("fds_w, offset: %04x, data: %02x\n", offset, data));
19201925
19211926   switch (offset)
r7952r7953
19381943         /* write data out to disk */
19391944         break;
19401945      case 0x05:
1941         nes_fds.motor_on = data & 0x01;
1946         state->fds_motor_on = BIT(data, 0);
19421947
1943         if (data & 0x02)
1944            nes_fds.head_position = 0;
1948         if (BIT(data, 1))
1949            state->fds_head_position = 0;
19451950
1946         nes_fds.read_mode = data & 0x04;
1947         set_nt_mirroring((data & 0x08) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
1951         state->fds_read_mode = BIT(data, 2);
1952         set_nt_mirroring(space->machine, BIT(data, 3) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
19481953
1949         if ((!(data & 0x40)) && (nes_fds.write_reg & 0x40))
1950            nes_fds.head_position -= 2; // ???
1954         if ((!(data & 0x40)) && (state->fds_write_reg & 0x40))
1955            state->fds_head_position -= 2; // ???
19511956
1952         IRQ_enable_latch = data & 0x80;
1953         nes_fds.write_reg = data;
1957         IRQ_enable_latch = BIT(data, 7);
1958         state->fds_write_reg = data;
19541959         break;
19551960   }
19561961
r7952r7953
20162021      case 0x1040:
20172022         switch (data & 0x03)
20182023         {
2019            case 0x00: set_nt_mirroring(PPU_MIRROR_VERT); break;
2020            case 0x01: set_nt_mirroring(PPU_MIRROR_HORZ); break;
2021            case 0x02: set_nt_mirroring(PPU_MIRROR_LOW); break;
2022            case 0x03: set_nt_mirroring(PPU_MIRROR_HIGH); break;
2024            case 0x00: set_nt_mirroring(space->machine, PPU_MIRROR_VERT); break;
2025            case 0x01: set_nt_mirroring(space->machine, PPU_MIRROR_HORZ); break;
2026            case 0x02: set_nt_mirroring(space->machine, PPU_MIRROR_LOW); break;
2027            case 0x03: set_nt_mirroring(space->machine, PPU_MIRROR_HIGH); break;
20232028         }
20242029         break;
20252030
r7952r7953
21652170      case 0x1008:
21662171         switch (data & 0x03)
21672172         {
2168            case 0x00: set_nt_mirroring(PPU_MIRROR_VERT); break;
2169            case 0x01: set_nt_mirroring(PPU_MIRROR_HORZ); break;
2170            case 0x02: set_nt_mirroring(PPU_MIRROR_LOW); break;
2171            case 0x03: set_nt_mirroring(PPU_MIRROR_HIGH); break;
2173            case 0x00: set_nt_mirroring(space->machine, PPU_MIRROR_VERT); break;
2174            case 0x01: set_nt_mirroring(space->machine, PPU_MIRROR_HORZ); break;
2175            case 0x02: set_nt_mirroring(space->machine, PPU_MIRROR_LOW); break;
2176            case 0x03: set_nt_mirroring(space->machine, PPU_MIRROR_HIGH); break;
21722177         }
21732178         break;
21742179
r7952r7953
23162321   case 0x1000:
23172322      switch (data & 0x03)
23182323      {
2319         case 0x00: set_nt_mirroring(PPU_MIRROR_VERT); break;
2320         case 0x01: set_nt_mirroring(PPU_MIRROR_HORZ); break;
2321         case 0x02: set_nt_mirroring(PPU_MIRROR_LOW); break;
2322         case 0x03: set_nt_mirroring(PPU_MIRROR_HIGH); break;
2324         case 0x00: set_nt_mirroring(space->machine, PPU_MIRROR_VERT); break;
2325         case 0x01: set_nt_mirroring(space->machine, PPU_MIRROR_HORZ); break;
2326         case 0x02: set_nt_mirroring(space->machine, PPU_MIRROR_LOW); break;
2327         case 0x03: set_nt_mirroring(space->machine, PPU_MIRROR_HIGH); break;
23232328      }
23242329      break;
23252330   case 0x2000:
r7952r7953
23732378         case 0x1000:
23742379            switch (data & 0x03)
23752380            {
2376               case 0x00: set_nt_mirroring(PPU_MIRROR_VERT); break;
2377               case 0x01: set_nt_mirroring(PPU_MIRROR_HORZ); break;
2378               case 0x02: set_nt_mirroring(PPU_MIRROR_LOW); break;
2379               case 0x03: set_nt_mirroring(PPU_MIRROR_HIGH); break;
2381               case 0x00: set_nt_mirroring(space->machine, PPU_MIRROR_VERT); break;
2382               case 0x01: set_nt_mirroring(space->machine, PPU_MIRROR_HORZ); break;
2383               case 0x02: set_nt_mirroring(space->machine, PPU_MIRROR_LOW); break;
2384               case 0x03: set_nt_mirroring(space->machine, PPU_MIRROR_HIGH); break;
23802385            }
23812386            break;
23822387         case 0x2000:
r7952r7953
24722477      case 0x3003:
24732478         switch (data & 0x0c)
24742479         {
2475            case 0x00: set_nt_mirroring(PPU_MIRROR_VERT); break;
2476            case 0x04: set_nt_mirroring(PPU_MIRROR_HORZ); break;
2477            case 0x08: set_nt_mirroring(PPU_MIRROR_LOW); break;
2478            case 0x0c: set_nt_mirroring(PPU_MIRROR_HIGH); break;
2480            case 0x00: set_nt_mirroring(space->machine, PPU_MIRROR_VERT); break;
2481            case 0x04: set_nt_mirroring(space->machine, PPU_MIRROR_HORZ); break;
2482            case 0x08: set_nt_mirroring(space->machine, PPU_MIRROR_LOW); break;
2483            case 0x0c: set_nt_mirroring(space->machine, PPU_MIRROR_HIGH); break;
24792484         }
24802485         break;
24812486      case 0x4000:
r7952r7953
25462551      case 0x3003:
25472552         switch (data & 0x0c)
25482553         {
2549            case 0x00: set_nt_mirroring(PPU_MIRROR_VERT); break;
2550            case 0x04: set_nt_mirroring(PPU_MIRROR_HORZ); break;
2551            case 0x08: set_nt_mirroring(PPU_MIRROR_LOW); break;
2552            case 0x0c: set_nt_mirroring(PPU_MIRROR_HIGH); break;
2554            case 0x00: set_nt_mirroring(space->machine, PPU_MIRROR_VERT); break;
2555            case 0x04: set_nt_mirroring(space->machine, PPU_MIRROR_HORZ); break;
2556            case 0x08: set_nt_mirroring(space->machine, PPU_MIRROR_LOW); break;
2557            case 0x0c: set_nt_mirroring(space->machine, PPU_MIRROR_HIGH); break;
25532558         }
25542559         break;
25552560      case 0x4000: case 0x4001: case 0x4002: case 0x4003:
r7952r7953
26582663
26592664static WRITE8_HANDLER( mapper32_w )
26602665{
2666   nes_state *state = (nes_state *)space->machine->driver_data;
26612667   LOG_MMC(("mapper32_w, offset: %04x, data: %02x\n", offset, data));
26622668
26632669   switch (offset & 0x7000)
r7952r7953
26672673         break;
26682674      case 0x1000:
26692675         mmc_cmd1 = data & 0x02;
2670         if (!nes.crc_hack)   // Major League has hardwired mirroring (it would have required a separate mapper)
2671            set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
2676         if (!state->crc_hack)   // Major League has hardwired mirroring (it would have required a separate mapper)
2677            set_nt_mirroring(space->machine, BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
26722678         break;
26732679      case 0x2000:
26742680         prg8_ab(space->machine, data);
r7952r7953
27022708   switch (offset & 0x6003)
27032709   {
27042710      case 0x0000:
2705         set_nt_mirroring((data & 0x40) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
2711         set_nt_mirroring(space->machine, BIT(data, 6) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
27062712         prg8_89(space->machine, data);
27072713         break;
27082714      case 0x0001:
r7952r7953
27482754
27492755static WRITE8_HANDLER( mapper34_m_w )
27502756{
2757   nes_state *state = (nes_state *)space->machine->driver_data;
27512758   LOG_MMC(("mapper34_m_w, offset: %04x, data: %02x\n", offset, data));
27522759
2753   if (nes.crc_hack)   // is it AVE Nina-01?
2760   if (state->crc_hack)   // is it AVE Nina-01?
27542761   {
27552762      switch (offset)
27562763      {
r7952r7953
27712778{
27722779   /* This portion of the mapper is nearly identical to Mapper 7, except no one-screen mirroring */
27732780   /* Deadly Towers is really a Mapper 34 game - the demo screens look wrong using mapper 7. */
2781   nes_state *state = (nes_state *)space->machine->driver_data;
27742782   LOG_MMC(("mapper34_w, offset: %04x, data: %02x\n", offset, data));
27752783
2776   if (!nes.crc_hack)   // is it plain BxROM?
2784   if (!state->crc_hack)   // is it plain BxROM?
27772785      prg32(space->machine, data);
27782786}
27792787
r7952r7953
28412849      IRQ_count = data;
28422850      break;
28432851   case 0x5001:
2844      set_nt_mirroring(data & 0x01 ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
2852      set_nt_mirroring(space->machine, BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
28452853      break;
28462854   }
28472855}
r7952r7953
29943002   LOG_MMC(("mapper41_m_w, offset: %04x, data: %02x\n", offset, data));
29953003
29963004   mmc_cmd1 = offset & 0xff;
2997   set_nt_mirroring((offset & 0x20) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
3005   set_nt_mirroring(space->machine, BIT(data, 5) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
29983006   prg32(space->machine, offset & 0x07);
29993007}
30003008
r7952r7953
30313039         prg8_67(space->machine, data);
30323040         break;
30333041      case 0x01:
3034         set_nt_mirroring((data & 0x08) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
3042         set_nt_mirroring(space->machine, BIT(data, 3) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
30353043         break;
30363044      case 0x02:
30373045         /* Check if IRQ is being enabled */
r7952r7953
30643072
30653073static WRITE8_HANDLER( mapper43_w )
30663074{
3075   nes_state *state = (nes_state *)space->machine->driver_data;
30673076   int bank = (((offset >> 8) & 0x03) * 0x20) + (offset & 0x1f);
30683077
30693078   LOG_MMC(("mapper43_w, offset: %04x, data: %02x\n", offset, data));
30703079
3071   set_nt_mirroring((offset& 0x2000) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
3080   set_nt_mirroring(space->machine, (offset & 0x2000) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
30723081
30733082   if (offset & 0x0800)
30743083   {
30753084      if (offset & 0x1000)
30763085      {
3077         if (bank * 2 >= nes.prg_chunks)
3086         if (bank * 2 >= state->prg_chunks)
30783087         {
3079            memory_set_bankptr(space->machine, "bank3", nes.wram);
3080            memory_set_bankptr(space->machine, "bank4", nes.wram);
3088            memory_set_bankptr(space->machine, "bank3", state->wram);
3089            memory_set_bankptr(space->machine, "bank4", state->wram);
30813090         }
30823091         else
30833092         {
r7952r7953
30873096      }
30883097      else
30893098      {
3090         if (bank * 2 >= nes.prg_chunks)
3099         if (bank * 2 >= state->prg_chunks)
30913100         {
3092            memory_set_bankptr(space->machine, "bank1", nes.wram);
3093            memory_set_bankptr(space->machine, "bank2", nes.wram);
3101            memory_set_bankptr(space->machine, "bank1", state->wram);
3102            memory_set_bankptr(space->machine, "bank2", state->wram);
30943103         }
30953104         else
30963105         {
r7952r7953
31013110   }
31023111   else
31033112   {
3104      if (bank * 2 >= nes.prg_chunks)
3113      if (bank * 2 >= state->prg_chunks)
31053114      {
3106         memory_set_bankptr(space->machine, "bank1", nes.wram);
3107         memory_set_bankptr(space->machine, "bank2", nes.wram);
3108         memory_set_bankptr(space->machine, "bank3", nes.wram);
3109         memory_set_bankptr(space->machine, "bank4", nes.wram);
3115         memory_set_bankptr(space->machine, "bank1", state->wram);
3116         memory_set_bankptr(space->machine, "bank2", state->wram);
3117         memory_set_bankptr(space->machine, "bank3", state->wram);
3118         memory_set_bankptr(space->machine, "bank4", state->wram);
31103119      }
31113120      else
31123121      {
r7952r7953
31663175
31673176static WRITE8_HANDLER( mapper45_m_w )
31683177{
3178   nes_state *state = (nes_state *)space->machine->driver_data;
31693179   LOG_MMC(("mapper45_m_w, offset: %04x, data: %02x\n", offset, data));
31703180
31713181   /* This bit is the "register lock". Once register are locked, writes go to WRAM
31723182        and there is no way to unlock them (except by resetting the machine) */
31733183   if (mapper45_reg[3] & 0x40)
3174      nes.wram[offset] = data;
3184      state->wram[offset] = data;
31753185   else
31763186   {
31773187      mapper45_reg[mmc_count] = data;
r7952r7953
33073317         IRQ_enable = 0;
33083318         break;
33093319      case 0x6000:
3310         set_nt_mirroring((data & 0x40) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
3320         set_nt_mirroring(space->machine, BIT(data, 6) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
33113321         break;
33123322   }
33133323}
r7952r7953
34193429
34203430static void mapper51_set_banks( running_machine *machine )
34213431{
3422   set_nt_mirroring((mapper51_reg[0] == 3) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
3432   set_nt_mirroring(machine, (mapper51_reg[0] == 3) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
34233433
34243434   if (mapper51_reg[0] & 0x01)
34253435   {
r7952r7953
34723482
34733483static WRITE8_HANDLER( mapper52_m_w )
34743484{
3485   nes_state *state = (nes_state *)space->machine->driver_data;
34753486   UINT8 map52_helper1, map52_helper2;
34763487   LOG_MMC(("mapper52_m_w, offset: %04x, data: %02x\n", offset, data));
34773488
r7952r7953
34933504      map52_reg_written = 1;
34943505   }
34953506   else
3496      nes.wram[offset] = data;
3507      state->wram[offset] = data;
34973508}
34983509
34993510/*************************************************************
r7952r7953
35853596      prg16_cdef(space->machine, (mmc_cmd2 >> 5) & 0x03);
35863597   }
35873598
3588   set_nt_mirroring((mmc_cmd2 & 0x08) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
3599   set_nt_mirroring(space->machine, (mmc_cmd2 & 0x08) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
35893600
35903601   chr8(space->machine, (mmc_cmd1 & 0x03) | (mmc_cmd2 & 0x07) | ((mmc_cmd2 & 0x10) >> 1), CHRROM);
35913602}
r7952r7953
36093620   prg16_89ab(space->machine, offset & ~bank);
36103621   prg16_cdef(space->machine, offset | bank);
36113622   chr8(space->machine, offset >> 3, CHRROM);
3612   set_nt_mirroring((data & 0x80) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
3623   set_nt_mirroring(space->machine, BIT(data, 7) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
36133624}
36143625
36153626/*************************************************************
r7952r7953
36673678      prg16_cdef(space->machine, ((offset & 0x0f) << 1) | ((offset & 0x20) >> 4));
36683679      break;
36693680   }
3670   set_nt_mirroring((offset & 0x80) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
3681   set_nt_mirroring(space->machine, BIT(data, 7) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
36713682}
36723683
36733684/*************************************************************
r7952r7953
36973708      prg32(space->machine, ((offset & 0x40) | ((offset >> 8) & 0x3f)) >> 1);
36983709   }
36993710
3700   set_nt_mirroring((offset & 0x80) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
3711   set_nt_mirroring(space->machine, BIT(data, 7) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
37013712}
37023713
37033714/*************************************************************
r7952r7953
38593870         break;
38603871
38613872      case 0x2000:
3862         set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
3873         set_nt_mirroring(space->machine, BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
38633874         break;
38643875
38653876      case 0x4000:
r7952r7953
39253936         break;
39263937
39273938      case 0x1001:
3928         set_nt_mirroring((data & 0x80) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
3939         set_nt_mirroring(space->machine, BIT(data, 7) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
39293940         break;
39303941
39313942      case 0x1003:
r7952r7953
40514062   case 0x6800:
40524063      switch (data & 3)
40534064      {
4054         case 0x00: set_nt_mirroring(PPU_MIRROR_VERT); break;
4055         case 0x01: set_nt_mirroring(PPU_MIRROR_HORZ); break;
4056         case 0x02: set_nt_mirroring(PPU_MIRROR_LOW); break;
4057         case 0x03: set_nt_mirroring(PPU_MIRROR_HIGH); break;
4065         case 0x00: set_nt_mirroring(space->machine, PPU_MIRROR_VERT); break;
4066         case 0x01: set_nt_mirroring(space->machine, PPU_MIRROR_HORZ); break;
4067         case 0x02: set_nt_mirroring(space->machine, PPU_MIRROR_LOW); break;
4068         case 0x03: set_nt_mirroring(space->machine, PPU_MIRROR_HIGH); break;
40584069      }
40594070      break;
40604071   case 0x7800:
r7952r7953
40824093   switch (mirror)
40834094   {
40844095      case 0x00:
4085         set_nt_mirroring(PPU_MIRROR_HORZ);
4096         set_nt_mirroring(machine, PPU_MIRROR_HORZ);
40864097         break;
40874098      case 0x01:
4088         set_nt_mirroring(PPU_MIRROR_VERT);
4099         set_nt_mirroring(machine, PPU_MIRROR_VERT);
40894100         break;
40904101      case 0x02:
4091         set_nt_mirroring(PPU_MIRROR_LOW);
4102         set_nt_mirroring(machine, PPU_MIRROR_LOW);
40924103         break;
40934104      case 0x03:
4094         set_nt_mirroring(PPU_MIRROR_HIGH);
4105         set_nt_mirroring(machine, PPU_MIRROR_HIGH);
40954106         break;
40964107      case 0x10:
4097         set_nt_page(0, ROM, mirr0 | 0x80, 0);
4098         set_nt_page(1, ROM, mirr1 | 0x80, 0);
4099         set_nt_page(2, ROM, mirr0 | 0x80, 0);
4100         set_nt_page(3, ROM, mirr1 | 0x80, 0);
4108         set_nt_page(machine, 0, ROM, mirr0 | 0x80, 0);
4109         set_nt_page(machine, 1, ROM, mirr1 | 0x80, 0);
4110         set_nt_page(machine, 2, ROM, mirr0 | 0x80, 0);
4111         set_nt_page(machine, 3, ROM, mirr1 | 0x80, 0);
41014112         break;
41024113      case 0x11:
4103         set_nt_page(0, ROM, mirr0 | 0x80, 0);
4104         set_nt_page(1, ROM, mirr0 | 0x80, 0);
4105         set_nt_page(2, ROM, mirr1 | 0x80, 0);
4106         set_nt_page(3, ROM, mirr1 | 0x80, 0);
4114         set_nt_page(machine, 0, ROM, mirr0 | 0x80, 0);
4115         set_nt_page(machine, 1, ROM, mirr0 | 0x80, 0);
4116         set_nt_page(machine, 2, ROM, mirr1 | 0x80, 0);
4117         set_nt_page(machine, 3, ROM, mirr1 | 0x80, 0);
41074118         break;
41084119      case 0x12:
4109         set_nt_page(0, ROM, mirr0 | 0x80, 0);
4110         set_nt_page(1, ROM, mirr0 | 0x80, 0);
4111         set_nt_page(2, ROM, mirr0 | 0x80, 0);
4112         set_nt_page(3, ROM, mirr0 | 0x80, 0);
4120         set_nt_page(machine, 0, ROM, mirr0 | 0x80, 0);
4121         set_nt_page(machine, 1, ROM, mirr0 | 0x80, 0);
4122         set_nt_page(machine, 2, ROM, mirr0 | 0x80, 0);
4123         set_nt_page(machine, 3, ROM, mirr0 | 0x80, 0);
41134124         break;
41144125      case 0x13:
4115         set_nt_page(0, ROM, mirr1 | 0x80, 0);
4116         set_nt_page(1, ROM, mirr1 | 0x80, 0);
4117         set_nt_page(2, ROM, mirr1 | 0x80, 0);
4118         set_nt_page(3, ROM, mirr1 | 0x80, 0);
4126         set_nt_page(machine, 0, ROM, mirr1 | 0x80, 0);
4127         set_nt_page(machine, 1, ROM, mirr1 | 0x80, 0);
4128         set_nt_page(machine, 2, ROM, mirr1 | 0x80, 0);
4129         set_nt_page(machine, 3, ROM, mirr1 | 0x80, 0);
41194130         break;
41204131   }
41214132}
r7952r7953
41984209
41994210static WRITE8_HANDLER( mapper69_w )
42004211{
4212   nes_state *state = (nes_state *)space->machine->driver_data;
42014213   LOG_MMC(("mapper69_w, offset %04x, data: %02x\n", offset, data));
42024214
42034215   switch (offset & 0x6000)
r7952r7953
42184230               if (!(data & 0x40))
42194231                  prg8_67(space->machine, data & 0x3f);
42204232               else if (data & 0x80)
4221                  memory_set_bankptr(space->machine, "bank5", &nes.wram[(data & 0x3f) * 0x2000]);
4233                  memory_set_bankptr(space->machine, "bank5", &state->wram[(data & 0x3f) * 0x2000]);
42224234               break;
42234235
42244236            case 9:
r7952r7953
42334245            case 0x0c:
42344246               switch (data & 0x03)
42354247               {
4236                  case 0x00: set_nt_mirroring(PPU_MIRROR_VERT); break;
4237                  case 0x01: set_nt_mirroring(PPU_MIRROR_HORZ); break;
4238                  case 0x02: set_nt_mirroring(PPU_MIRROR_LOW); break;
4239                  case 0x03: set_nt_mirroring(PPU_MIRROR_HIGH); break;
4248                  case 0x00: set_nt_mirroring(space->machine, PPU_MIRROR_VERT); break;
4249                  case 0x01: set_nt_mirroring(space->machine, PPU_MIRROR_HORZ); break;
4250                  case 0x02: set_nt_mirroring(space->machine, PPU_MIRROR_LOW); break;
4251                  case 0x03: set_nt_mirroring(space->machine, PPU_MIRROR_HIGH); break;
42404252               }
42414253               break;
42424254            case 0x0d:
r7952r7953
43034315
43044316static WRITE8_HANDLER( mapper71_w )
43054317{
4318   nes_state *state = (nes_state *)space->machine->driver_data;
43064319   LOG_MMC(("mapper71_w offset: %04x, data: %02x\n", offset, data));
43074320
43084321   switch (offset & 0x7000)
43094322   {
43104323   case 0x0000:
43114324   case 0x1000:
4312      if (nes.crc_hack)
4313         set_nt_mirroring((data & 0x10) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
4325      if (state->crc_hack)
4326         set_nt_mirroring(space->machine, BIT(data, 4) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
43144327      break;
43154328   case 0x4000:
43164329   case 0x5000:
r7952r7953
44034416*************************************************************/
44044417
44054418/* MIRROR_LOW and MIRROR_HIGH are swapped! */
4406static void waixing_set_mirror( UINT8 nt )
4419static void waixing_set_mirror( running_machine *machine, UINT8 nt )
44074420{
44084421   switch (nt)
44094422   {
44104423   case 0:
44114424   case 1:
4412      set_nt_mirroring(nt ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
4425      set_nt_mirroring(machine, nt ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
44134426      break;
44144427   case 2:
4415      set_nt_mirroring(PPU_MIRROR_LOW);
4428      set_nt_mirroring(machine, PPU_MIRROR_LOW);
44164429      break;
44174430   case 3:
4418      set_nt_mirroring(PPU_MIRROR_HIGH);
4431      set_nt_mirroring(machine, PPU_MIRROR_HIGH);
44194432      break;
44204433   default:
44214434      LOG_MMC(("Mapper set NT to invalid value %02x", nt));
r7952r7953
44804493      break;
44814494
44824495   case 0x2000:
4483      waixing_set_mirror(data);   //maybe data & 0x03?
4496      waixing_set_mirror(space->machine, data);   //maybe data & 0x03?
44844497      break;
44854498
44864499   case 0x2001:
r7952r7953
45134526         prg8_89(space->machine, data);
45144527         break;
45154528      case 0x1000:
4516         set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
4529         set_nt_mirroring(space->machine, (data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
45174530         vrom_bank[0] = (vrom_bank[0] & 0x0f) | ((data & 0x02) << 3);
45184531         vrom_bank[1] = (vrom_bank[1] & 0x0f) | ((data & 0x04) << 2);
45194532         chr4_0(space->machine, vrom_bank[0], CHRROM);
r7952r7953
45724585         }
45734586      }
45744587   case 0x2000:
4575      set_nt_mirroring((data & 1) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
4588      set_nt_mirroring(space->machine, BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
45764589      break;
45774590   default:
45784591      logerror("mapper76 unmapped write, offset: %04x, data: %02x\n", offset, data);
r7952r7953
46164629
46174630static WRITE8_HANDLER( mapper78_w )
46184631{
4632   nes_state *state = (nes_state *)space->machine->driver_data;
46194633   LOG_MMC(("mapper78_w, offset: %04x, data: %02x\n", offset, data));
46204634
4621   if (nes.crc_hack)      // Jaleco JF16 board has different mirroring even if uses same mapper number :(
4622      set_nt_mirroring((data & 0x08) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
4635   if (state->crc_hack)      // Jaleco JF16 board has different mirroring even if uses same mapper number :(
4636      set_nt_mirroring(space->machine, BIT(data, 3) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
46234637   else
4624      set_nt_mirroring((data & 0x08) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
4638      set_nt_mirroring(space->machine, BIT(data, 3) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
46254639
46264640   chr8(space->machine, (data & 0xf0) >> 4, CHRROM);
46274641   prg16_89ab(space->machine, data & 0x07);
r7952r7953
46914705         chr1_7(space->machine, data, CHRROM);
46924706         break;
46934707      case 0x1ef6:
4694         set_nt_mirroring((data & 0x01) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
4708         set_nt_mirroring(space->machine, BIT(data, 0) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
46954709         break;
46964710      case 0x1efa:
46974711      case 0x1efb:
r7952r7953
47654779         chr1_x(space->machine, 7 ^ mmc_cmd1, data, CHRROM);
47664780         break;
47674781      case 0x1ef6:
4768         set_nt_mirroring((data & 0x01) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
4782         set_nt_mirroring(space->machine, BIT(data, 0) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
47694783         mmc_cmd1 = ((data & 0x02) << 1);
47704784         break;
47714785
r7952r7953
48424856      switch (data & 0x03)
48434857      {
48444858      case 0:
4845         set_nt_mirroring(PPU_MIRROR_VERT);
4859         set_nt_mirroring(space->machine, PPU_MIRROR_VERT);
48464860         break;
48474861      case 1:
4848         set_nt_mirroring(PPU_MIRROR_HORZ);
4862         set_nt_mirroring(space->machine, PPU_MIRROR_HORZ);
48494863         break;
48504864      case 2:
4851         set_nt_mirroring(PPU_MIRROR_LOW);
4865         set_nt_mirroring(space->machine, PPU_MIRROR_LOW);
48524866         break;
48534867      case 3:
4854         set_nt_mirroring(PPU_MIRROR_HIGH);
4868         set_nt_mirroring(space->machine, PPU_MIRROR_HIGH);
48554869         break;
48564870      }
48574871      break;
r7952r7953
49564970      case 0x6000:
49574971         switch (data & 0x03)
49584972         {
4959            case 0x00: set_nt_mirroring(PPU_MIRROR_VERT); break;
4960            case 0x01: set_nt_mirroring(PPU_MIRROR_HORZ); break;
4961            case 0x02: set_nt_mirroring(PPU_MIRROR_LOW); break;
4962            case 0x03: set_nt_mirroring(PPU_MIRROR_HIGH); break;
4973            case 0x00: set_nt_mirroring(space->machine, PPU_MIRROR_VERT); break;
4974            case 0x01: set_nt_mirroring(space->machine, PPU_MIRROR_HORZ); break;
4975            case 0x02: set_nt_mirroring(space->machine, PPU_MIRROR_LOW); break;
4976            case 0x03: set_nt_mirroring(space->machine, PPU_MIRROR_HIGH); break;
49634977         }
49644978         break;
49654979      case 0x6008: case 0x6010: case 0x6018:
r7952r7953
50805094
50815095   prg16_89ab(space->machine, (data >> 4) & 0x07);
50825096   chr8(space->machine, map89_helper, CHRROM);
5083   set_nt_mirroring((data & 0x08) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
5097   set_nt_mirroring(space->machine, BIT(data, 3) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
50845098}
50855099
50865100/*************************************************************
r7952r7953
52435257               mapper95_reg[mmc_cmd1 - 2] = data & 0x20;
52445258               if (!(mmc_cmd1 & 0x80))
52455259               {
5246                  set_nt_page(0, CIRAM, mapper95_reg[0] ? 1 : 0, 1);
5247                  set_nt_page(1, CIRAM, mapper95_reg[1] ? 1 : 0, 1);
5248                  set_nt_page(2, CIRAM, mapper95_reg[2] ? 1 : 0, 1);
5249                  set_nt_page(3, CIRAM, mapper95_reg[3] ? 1 : 0, 1);
5260                  set_nt_page(space->machine, 0, CIRAM, mapper95_reg[0] ? 1 : 0, 1);
5261                  set_nt_page(space->machine, 1, CIRAM, mapper95_reg[1] ? 1 : 0, 1);
5262                  set_nt_page(space->machine, 2, CIRAM, mapper95_reg[2] ? 1 : 0, 1);
5263                  set_nt_page(space->machine, 3, CIRAM, mapper95_reg[3] ? 1 : 0, 1);
52505264               }
52515265               else
5252                  set_nt_mirroring(PPU_MIRROR_HORZ);
5266                  set_nt_mirroring(space->machine, PPU_MIRROR_HORZ);
52535267               break;
52545268            case 6:
52555269               prg8_89(space->machine,data & 0x1f);
r7952r7953
52995313
53005314   if (offset < 0x4000)
53015315   {
5302      set_nt_mirroring((data & 0x80) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
5316      set_nt_mirroring(space->machine, BIT(data, 7) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
53035317      prg16_cdef(space->machine, data & 0x0f);
53045318   }
53055319}
r7952r7953
54825496      prg8_ef(space->machine, data | 0x10);
54835497      break;
54845498   case 0x0c:
5485      set_nt_mirroring((data & 0x01) ?  PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
5499      set_nt_mirroring(space->machine, BIT(data, 0) ?  PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
54865500      break;
54875501   case 0x0d:
54885502      IRQ_count = 0;
r7952r7953
56245638      }
56255639      break;
56265640   case 0x6000:
5627      set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
5641      set_nt_mirroring(space->machine, BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
56285642      break;
56295643   }
56305644}
r7952r7953
56435657
56445658static WRITE8_HANDLER( mapper113_l_w )
56455659{
5660   nes_state *state = (nes_state *)space->machine->driver_data;
56465661   LOG_MMC(("mapper113_w, offset: %04x, data: %02x\n", offset, data));
56475662
56485663   if (!(offset & 0x100))
56495664   {
56505665      prg32(space->machine, (data & 0x38) >> 3);
56515666      chr8(space->machine, (data & 0x07) | ((data & 0x40) >> 3), CHRROM);
5652      if (nes.crc_hack)   // this breaks AV Soccer but it is needed by HES 6-in-1!
5653         set_nt_mirroring((data & 0x80) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
5667      if (state->crc_hack)   // this breaks AV Soccer but it is needed by HES 6-in-1!
5668         set_nt_mirroring(space->machine, BIT(data, 7) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
56545669   }
56555670}
56565671
r7952r7953
56935708      switch (offset & 0x6000)
56945709      {
56955710      case 0x0000:
5696         set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
5711         set_nt_mirroring(space->machine, BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
56975712         break;
56985713      case 0x2000:
56995714         map114_reg_enabled = 1;
r7952r7953
58725887      break;
58735888
58745889   case 0x5000:
5875      set_nt_mirroring((data & 0x01) ?  PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
5890      set_nt_mirroring(space->machine, BIT(data, 0) ?  PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
58765891      break;
58775892
58785893   case 0x4001:
r7952r7953
59025917
59035918*************************************************************/
59045919
5905static void mapper118_set_mirror( void )
5920static void mapper118_set_mirror( running_machine *machine )
59065921{
59075922   if (mmc_cmd1 & 0x80)
59085923   {
5909      set_nt_page(0, CIRAM, (vrom_bank[2] & 0x80) >> 7, 1);
5910      set_nt_page(1, CIRAM, (vrom_bank[3] & 0x80) >> 7, 1);
5911      set_nt_page(2, CIRAM, (vrom_bank[4] & 0x80) >> 7, 1);
5912      set_nt_page(3, CIRAM, (vrom_bank[5] & 0x80) >> 7, 1);
5924      set_nt_page(machine, 0, CIRAM, (vrom_bank[2] & 0x80) >> 7, 1);
5925      set_nt_page(machine, 1, CIRAM, (vrom_bank[3] & 0x80) >> 7, 1);
5926      set_nt_page(machine, 2, CIRAM, (vrom_bank[4] & 0x80) >> 7, 1);
5927      set_nt_page(machine, 3, CIRAM, (vrom_bank[5] & 0x80) >> 7, 1);
59135928   }
59145929   else
59155930   {
5916      set_nt_page(0, CIRAM, (vrom_bank[0] & 0x80) >> 7, 1);
5917      set_nt_page(1, CIRAM, (vrom_bank[0] & 0x80) >> 7, 1);
5918      set_nt_page(2, CIRAM, (vrom_bank[1] & 0x80) >> 7, 1);
5919      set_nt_page(3, CIRAM, (vrom_bank[1] & 0x80) >> 7, 1);
5931      set_nt_page(machine, 0, CIRAM, (vrom_bank[0] & 0x80) >> 7, 1);
5932      set_nt_page(machine, 1, CIRAM, (vrom_bank[0] & 0x80) >> 7, 1);
5933      set_nt_page(machine, 2, CIRAM, (vrom_bank[1] & 0x80) >> 7, 1);
5934      set_nt_page(machine, 3, CIRAM, (vrom_bank[1] & 0x80) >> 7, 1);
59205935   }
59215936}
59225937
r7952r7953
59385953         /* Has CHR Mode changed? */
59395954         if (MMC3_helper & 0x80)
59405955         {
5941            mapper118_set_mirror();
5956            mapper118_set_mirror(space->machine);
59425957            mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
59435958         }
59445959         break;
r7952r7953
59505965            case 0: case 1:
59515966            case 2: case 3: case 4: case 5:
59525967               vrom_bank[cmd] = data;
5953               mapper118_set_mirror();
5968               mapper118_set_mirror(space->machine);
59545969               mapper4_set_chr(space->machine, mmc_chr_source, mmc_chr_base, mmc_chr_mask);
59555970               break;
59565971            case 6:
r7952r7953
62126227    Mapper 123
62136228
62146229    Known Boards: Bootleg Board ???
6215    Games: [no games in nes.hsi]
6230    Games: [no games in state->hsi]
62166231
62176232    In MESS: Unsupported.
62186233
r7952r7953
62456260    Mapper 126
62466261
62476262    Known Boards: Unknown Multigame Bootleg Board
6248    Games: [no games in nes.hsi]
6263    Games: [no games in state->hsi]
62496264
62506265    In MESS: Unsupported.
62516266
r7952r7953
64556470
64566471*************************************************************/
64576472
6458static void sachen_set_mirror( UINT8 nt ) // used by mappers 137, 138, 139, 141
6473static void sachen_set_mirror( running_machine *machine, UINT8 nt ) // used by mappers 137, 138, 139, 141
64596474{
64606475   switch (nt)
64616476   {
64626477   case 0:
64636478   case 1:
6464      set_nt_mirroring(nt ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
6479      set_nt_mirroring(machine, nt ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
64656480      break;
64666481   case 2:
6467      set_nt_page(0, CIRAM, 0, 1);
6468      set_nt_page(1, CIRAM, 1, 1);
6469      set_nt_page(2, CIRAM, 1, 1);
6470      set_nt_page(3, CIRAM, 1, 1);
6482      set_nt_page(machine, 0, CIRAM, 0, 1);
6483      set_nt_page(machine, 1, CIRAM, 1, 1);
6484      set_nt_page(machine, 2, CIRAM, 1, 1);
6485      set_nt_page(machine, 3, CIRAM, 1, 1);
64716486      break;
64726487   case 3:
6473      set_nt_mirroring(PPU_MIRROR_LOW);
6488      set_nt_mirroring(machine, PPU_MIRROR_LOW);
64746489      break;
64756490   default:
64766491      LOG_MMC(("Mapper set NT to invalid value %02x", nt));
r7952r7953
64976512            prg32(space->machine, data);
64986513            break;
64996514         case 0x07:
6500            sachen_set_mirror((data & 0x01) ? 0 : (data >> 1) & 0x03);
6515            sachen_set_mirror(space->machine, BIT(data, 0) ? 0 : (data >> 1) & 0x03);
65016516            break;
65026517         default:
65036518            if (mmc_chr_source == CHRROM)
r7952r7953
65516566            prg32(space->machine, data);
65526567            break;
65536568         case 0x07:
6554            sachen_set_mirror((data & 0x01) ? 0 : (data >> 1) & 0x03);
6569            sachen_set_mirror(space->machine, BIT(data, 0) ? 0 : (data >> 1) & 0x03);
65556570            break;
65566571         default:
65576572            if (mmc_chr_source == CHRROM)
r7952r7953
66076622            prg32(space->machine, data);
66086623            break;
66096624         case 0x07:
6610            sachen_set_mirror((data & 0x01) ? 0 : (data >> 1) & 0x03);
6625            sachen_set_mirror(space->machine, BIT(data, 0) ? 0 : (data >> 1) & 0x03);
66116626            break;
66126627         default:
66136628            if (mmc_chr_source == CHRROM)
r7952r7953
66836698            prg32(space->machine, data);
66846699            break;
66856700         case 0x07:
6686            sachen_set_mirror((data & 0x01) ? 0 : (data >> 1) & 0x03);
6701            sachen_set_mirror(space->machine, BIT(data, 0) ? 0 : (data >> 1) & 0x03);
66876702            break;
66886703         default:
66896704            if (mmc_chr_source == CHRROM)
r7952r7953
69266941            chr8(space->machine, vrom_bank[0], CHRROM);
69276942            break;
69286943         case 0x07:
6929            sachen_set_mirror((data >> 1) & 0x03);
6944            sachen_set_mirror(space->machine, (data >> 1) & 0x03);
69306945            break;
69316946         default:
69326947            break;
r7952r7953
69806995   LOG_MMC(("mapper152_w, offset: %04x, data: %02x\n", offset, data));
69816996
69826997   // we lack bus emulation
6983   set_nt_mirroring((data & 0x80) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
6998   set_nt_mirroring(space->machine, BIT(data, 7) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
69846999   prg16_89ab(space->machine, (data >> 4) & 0x07);
69857000   chr8(space->machine, data, CHRROM);
69867001}
r7952r7953
70207035
70217036static WRITE8_HANDLER( mapper153_m_w )
70227037{
7038   nes_state *state = (nes_state *)space->machine->driver_data;
70237039   LOG_MMC(("mapper153_m_w, offset: %04x, data: %02x\n", offset, data));
70247040
7025   if (nes.crc_hack)      // Famicom Jump II uses a different board
7041   if (state->crc_hack)      // Famicom Jump II uses a different board
70267042   {
70277043      switch (offset & 0x0f)   // there is no CHRROM and prg banking works differently
70287044      {
r7952r7953
70727088   switch (offset & 1)
70737089   {
70747090   case 0:
7075      set_nt_mirroring((data & 0x40) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
7091      set_nt_mirroring(space->machine, BIT(data, 6) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW);
70767092      mmc_cmd1 = data & 7;
70777093      break;
70787094   case 1:
r7952r7953
71847200{
71857201   UINT8 nt_mode = mmc_cmd1 & 0x80;
71867202
7187   set_nt_page(0, ROM, vrom_bank[nt_mode ? 2 : 0], 0);
7188   set_nt_page(1, ROM, vrom_bank[nt_mode ? 3 : 0], 0);
7189   set_nt_page(2, ROM, vrom_bank[nt_mode ? 4 : 1], 0);
7190   set_nt_page(3, ROM, vrom_bank[nt_mode ? 5 : 1], 0);
7203   set_nt_page(machine, 0, ROM, vrom_bank[nt_mode ? 2 : 0], 0);
7204   set_nt_page(machine, 1, ROM, vrom_bank[nt_mode ? 3 : 0], 0);
7205   set_nt_page(machine, 2, ROM, vrom_bank[nt_mode ? 4 : 1], 0);
7206   set_nt_page(machine, 3, ROM, vrom_bank[nt_mode ? 5 : 1], 0);
71917207}
71927208
71937209static WRITE8_HANDLER( mapper158_w )
r7952r7953
76197635   LOG_MMC(("mapper177_w, offset: %04x, data: %02x\n", offset, data));
76207636
76217637   prg32(space->machine, data);
7622   set_nt_mirroring(((data & 0x20) >> 5) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
7638   set_nt_mirroring(space->machine, BIT(data, 5) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
76237639}
76247640
76257641/*************************************************************
r7952r7953
76417657   switch (offset)
76427658   {
76437659   case 0x700:
7644      set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
7660      set_nt_mirroring(space->machine, BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
76457661      break;
76467662   case 0x701:
76477663      mmc_cmd1 = (mmc_cmd1 & 0x0c) | ((data >> 1) & 0x03);
r7952r7953
76807696{
76817697   LOG_MMC(("mapper179_w, offset: %04x, data: %02x\n", offset, data));
76827698
7683   set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
7699   set_nt_mirroring(space->machine, BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
76847700}
76857701
76867702/*************************************************************
r7952r7953
77347750   switch (offset & 0x7003)
77357751   {
77367752   case 0x0001:
7737      set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
7753      set_nt_mirroring(space->machine, BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
77387754      break;
77397755   case 0x2000:
77407756      mmc_cmd1 = data;
r7952r7953
86898705   prg16_cdef(space->machine, offset & 0x07);
86908706   chr8(space->machine, offset & 0x07, CHRROM);
86918707
8692   set_nt_mirroring((offset & 0x08) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
8708   set_nt_mirroring(space->machine, BIT(data, 3) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
86938709}
86948710
86958711/*************************************************************
r7952r7953
87328748   prg16_cdef(space->machine, bank + (((bank & 0x06) == 0x06) ? 1 : 0));
87338749   chr8(space->machine, bank, CHRROM);
87348750
8735   set_nt_mirroring((offset & 0x01) ? PPU_MIRROR_HORZ: PPU_MIRROR_VERT);
8751   set_nt_mirroring(space->machine, BIT(data, 0) ? PPU_MIRROR_HORZ: PPU_MIRROR_VERT);
87368752}
87378753
87388754/*************************************************************
r7952r7953
87768792   prg16_cdef(space->machine, offset | bank);
87778793   chr8(space->machine, offset & ~bank, CHRROM);
87788794
8779   set_nt_mirroring((offset & 0x10) ? PPU_MIRROR_HORZ: PPU_MIRROR_VERT);
8795   set_nt_mirroring(space->machine, BIT(data, 4) ? PPU_MIRROR_HORZ: PPU_MIRROR_VERT);
87808796}
87818797
87828798/*************************************************************
r7952r7953
88508866   switch (offset)
88518867   {
88528868      case 0x1ef0:
8853         set_nt_page(0, CIRAM, (data & 0x80) ? 1 : 0, 1);
8854         set_nt_page(1, CIRAM, (data & 0x80) ? 1 : 0, 1);
8869         set_nt_page(space->machine, 0, CIRAM, (data & 0x80) ? 1 : 0, 1);
8870         set_nt_page(space->machine, 1, CIRAM, (data & 0x80) ? 1 : 0, 1);
88558871         /* Switch 2k VROM at $0000 */
88568872         chr2_0(space->machine, (data & 0x7f) >> 1, CHRROM);
88578873         break;
88588874      case 0x1ef1:
8859         set_nt_page(2, CIRAM, (data & 0x80) ? 1 : 0, 1);
8860         set_nt_page(3, CIRAM, (data & 0x80) ? 1 : 0, 1);
8875         set_nt_page(space->machine, 2, CIRAM, (data & 0x80) ? 1 : 0, 1);
8876         set_nt_page(space->machine, 3, CIRAM, (data & 0x80) ? 1 : 0, 1);
88618877         /* Switch 2k VROM at $0000 */
88628878         chr2_2(space->machine, (data & 0x7f) >> 1, CHRROM);
88638879         break;
r7952r7953
90479063{
90489064   LOG_MMC(("mapper212_w, offset: %04x, data: %02x\n", offset, data));
90499065
9050   set_nt_mirroring((offset & 0x08) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9066   set_nt_mirroring(space->machine, BIT(data, 3) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
90519067   chr8(space->machine, offset, CHRROM);
90529068
90539069   if (offset < 0x4000)
r7952r7953
92639279//          break;
92649280
92659281      case 0x4000:
9266         set_nt_mirroring(((data >> 7) | data) & 0x01 ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9282         set_nt_mirroring(space->machine, ((data >> 7) | data) & 0x01 ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
92679283         break;
92689284
92699285      case 0x4001:
r7952r7953
94719487
94729488
94739489      case 0x2001:
9474         set_nt_mirroring(data & 0x01 ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9490         set_nt_mirroring(space->machine, BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
94759491         break;
94769492
94779493      default:
r7952r7953
95469562
95479563   if (offset < 0x4000)
95489564   {
9549      set_nt_mirroring(offset & 0x01 ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9565      set_nt_mirroring(space->machine, BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
95509566      offset = (offset >> 1) & 0xff;
95519567
95529568      if (mmc_cmd1 != offset)
r7952r7953
96049620      prg8_89(space->machine, data);
96059621      break;
96069622   case 0x1000:
9607      set_nt_mirroring((data & 0x01) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9623      set_nt_mirroring(space->machine, BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
96089624      break;
96099625   case 0x2000:
96109626      prg8_ab(space->machine, data);
r7952r7953
96729688   LOG_MMC(("mapper225_w, offset: %04x, data: %02x\n", offset, data));
96739689
96749690   chr8(space->machine, offset, CHRROM);
9675   set_nt_mirroring((offset & 0x2000) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9691   set_nt_mirroring(space->machine, (offset & 0x2000) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
96769692
96779693   hi_bank = offset & 0x40;
96789694   size_16 = offset & 0x1000;
r7952r7953
97189734      mmc_cmd1 = data;
97199735   }
97209736
9721   set_nt_mirroring((mmc_cmd1 & 0x40) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9737   set_nt_mirroring(space->machine, BIT(mmc_cmd1, 6) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
97229738
97239739   hi_bank = mmc_cmd1 & 0x01;
97249740   size_16 = mmc_cmd1 & 0x20;
r7952r7953
97799795         prg16_cdef(space->machine, ((bank << 1) & 0x38));
97809796   }
97819797
9782   set_nt_mirroring((offset & 0x02) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9798   set_nt_mirroring(space->machine, BIT(data, 1) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
97839799}
97849800
97859801/*************************************************************
r7952r7953
97999815   UINT8 pmode;
98009816   LOG_MMC(("mapper228_w, offset: %04x, data: %02x\n", offset, data));
98019817
9802   set_nt_mirroring((offset & 0x2000) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9818   set_nt_mirroring(space->machine, (offset & 0x2000) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
98039819
98049820   cbank = (data & 0x03) | ((offset & 0x0f) << 2);
98059821   chr8(space->machine, cbank, CHRROM);
r7952r7953
98409856{
98419857   LOG_MMC(("mapper229_w, offset: %04x, data: %02x\n", offset, data));
98429858
9843   set_nt_mirroring((offset & 0x20) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9859   set_nt_mirroring(space->machine, BIT(data, 5) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
98449860   chr8(space->machine, offset, CHRROM);
98459861
98469862   if ((offset & 0x1e) == 0)
r7952r7953
98879903         prg16_89ab(space->machine, (data & 0x1f) + 8);
98889904         prg16_cdef(space->machine, (data & 0x1f) + 9);
98899905      }
9890      set_nt_mirroring((data & 0x40) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
9906      set_nt_mirroring(space->machine, BIT(data, 6) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
98919907   }
98929908}
98939909
r7952r7953
99069922{
99079923   LOG_MMC(("mapper231_w, offset: %04x, data: %02x\n", offset, data));
99089924
9909   set_nt_mirroring((offset & 0x80) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
9925   set_nt_mirroring(space->machine, BIT(data, 7) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
99109926
99119927   prg16_89ab(space->machine, (offset & 0x1e));
99129928   prg16_cdef(space->machine, (offset & 0x1e) | ((offset & 0x20) ? 1 : 0));
r7952r7953
1010210118
1010310119static WRITE8_HANDLER( mapper242_w )
1010410120{
10121   nes_state *state = (nes_state *)space->machine->driver_data;
1010510122   LOG_MMC(("mapper242_w, offset: %04x, data: %02x\n", offset, data));
1010610123
1010710124   prg32(space->machine, offset >> 3);
1010810125
10109   if (!nes.crc_hack)   // DQ8 board does not have this / Zan Shi does
10126   if (!state->crc_hack)   // DQ8 board does not have this / Zan Shi does
1011010127   {
1011110128      switch (data & 0x03)
1011210129      {
10113         case 0: set_nt_mirroring(PPU_MIRROR_VERT); break;
10114         case 1: set_nt_mirroring(PPU_MIRROR_HORZ); break;
10115         case 2: set_nt_mirroring(PPU_MIRROR_LOW); break;
10116         case 3: set_nt_mirroring(PPU_MIRROR_HIGH); break;
10130         case 0: set_nt_mirroring(space->machine, PPU_MIRROR_VERT); break;
10131         case 1: set_nt_mirroring(space->machine, PPU_MIRROR_HORZ); break;
10132         case 2: set_nt_mirroring(space->machine, PPU_MIRROR_LOW); break;
10133         case 3: set_nt_mirroring(space->machine, PPU_MIRROR_HIGH); break;
1011710134      }
1011810135   }
1011910136}
r7952r7953
1016410181            chr8(space->machine, vrom_bank[0], CHRROM);
1016510182            break;
1016610183         case 0x07:
10167            set_nt_mirroring(data & 0x01 ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
10184            set_nt_mirroring(space->machine, BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
1016810185            break;
1016910186         default:
1017010187            break;
r7952r7953
1022010237
1022110238static WRITE8_HANDLER( mapper245_w )
1022210239{
10240   nes_state *state = (nes_state *)space->machine->driver_data;
1022310241   UINT8 cmd, map245_helper;
1022410242   LOG_MMC(("mapper245_w, offset: %04x, data: %02x\n", offset, data));
1022510243
r7952r7953
1023510253         mapper4_set_prg(space->machine, mmc_prg_base, mmc_prg_mask);
1023610254      case 1: case 2: case 3: case 4: case 5:
1023710255         vrom_bank[cmd] = data;
10238         if (nes.chr_chunks > 0)
10256         if (state->chr_chunks > 0)
1023910257            mapper4_set_chr(space->machine, CHRROM, mmc_chr_base, mmc_chr_mask);
1024010258         else   // according to Disch's docs, mmc_cmd1&0x80 swaps 4k CHRRAM banks
1024110259         {
r7952r7953
1027910297
1028010298static WRITE8_HANDLER( mapper246_m_w )
1028110299{
10300   nes_state *state = (nes_state *)space->machine->driver_data;
1028210301   LOG_MMC(("mapper246_m_w, offset: %04x, data: %02x\n", offset, data));
1028310302
1028410303   if (offset < 0x0800)
r7952r7953
1031210331      }
1031310332   }
1031410333   else
10315      nes.wram[offset] = data;
10334      state->wram[offset] = data;
1031610335}
1031710336
1031810337/*************************************************************
r7952r7953
1058510604
1058610605   LOG_MMC(("mapper255_w, offset: %04x, data: %02x\n", offset, data));
1058710606
10588   set_nt_mirroring((offset & 0x2000) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
10607   set_nt_mirroring(space->machine, (offset & 0x2000) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
1058910608   prg16_89ab(space->machine, map255_helper1 & ~map255_helper2);
1059010609   prg16_cdef(space->machine, map255_helper1 | map255_helper2);
1059110610   chr8(space->machine, ((offset >> 8) & 0x40) | (offset & 0x3f), CHRROM);
r7952r7953
1085510874const mmc *nes_mapper_lookup( int mapper )
1085610875{
1085710876   int i;
10877
1085810878   for (i = 0; i < ARRAY_LENGTH(mmc_list); i++)
1085910879   {
10860      if (mmc_list[i].iNesMapper == nes.mapper)
10880      if (mmc_list[i].iNesMapper == mapper)
1086110881         return &mmc_list[i];
1086210882   }
10883
1086310884   return NULL;
1086410885}

Previous 15994 Revisions Next


© 1998-2018 The MESS Team