Previous 15994 Revisions Next

r7958 Sunday 2nd May, 2010 at 11:32:29 UTC by Fabio Priuli
[NES] some more refactoring
[src/mess/drivers]nes.c
[src/mess/includes]nes.h
[src/mess/machine]nes.c nes_ines.c nes_mmc.c

src/mess/includes/nes.h
r7957r7958
8282   int nes_vram_sprite[8]; /* Used only by mmc5 for now */
8383   int last_frame_flip;
8484   double scanlines_per_frame;
85   
85
86   /* misc */
87   write8_space_func   mmc_write_low;
88   read8_space_func    mmc_read_low;
89   write8_space_func   mmc_write_mid;
90   write8_space_func   mmc_write;
91   emu_timer           *irq_timer;
92
8693   /* devices */
87   running_device *ppu;
88   running_device *sound;
89   running_device *cart;
94   running_device      *maincpu;
95   running_device      *ppu;
96   running_device      *sound;
97   running_device      *cart;
9098
9199   /* misc region to be allocated at init */
92100   // variables which don't change at run-time
r7957r7958
165173   /* these are used in the mapper 20 handlers */
166174   int     fds_last_side;
167175   int     fds_count;
168
169   // misc
170   write8_space_func   mmc_write_low;
171   read8_space_func    mmc_read_low;
172   write8_space_func   mmc_write_mid;
173   write8_space_func   mmc_write;
174176};
175177
176178
src/mess/machine/nes.c
r7957r7958
1515/* Set to dump info about the inputs to the errorlog */
1616#define LOG_JOY      0
1717
18/* Set to generate prg (16k) & chr (8k) chunk files when the cart is loaded */
18/* Set to generate prg & chr files when the cart is loaded */
1919#define SPLIT_PRG   0
2020#define SPLIT_CHR   0
2121
r7957r7958
168168{
169169   nes_state *state = (nes_state *)machine->driver_data;
170170
171   state->ppu = devtag_get_device(machine, "ppu");
172   state->sound = devtag_get_device(machine, "nessound");
173   state->cart = devtag_get_device(machine, "cart");
174
175171   /* Some carts have extra RAM and require it on at startup, e.g. Metroid */
176172   state->mid_ram_enable = 1;
177173
r7957r7958
189185   devtag_get_device(machine, "maincpu")->reset();
190186}
191187
192emu_timer   *nes_irq_timer;
193
194188static TIMER_CALLBACK( nes_irq_callback )
195189{
196   cputag_set_input_line(machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
197   timer_adjust_oneshot(nes_irq_timer, attotime_never, 0);
190   nes_state *state = (nes_state *)machine->driver_data;
191   cpu_set_input_line(state->maincpu, M6502_IRQ_LINE, HOLD_LINE);
192   timer_adjust_oneshot(state->irq_timer, attotime_never, 0);
198193}
199194
195static void nes_state_register( running_machine *machine )
196{
197   nes_state *state = (nes_state *)machine->driver_data;
198
199   state_save_register_global(machine, state->MMC5_floodtile);
200   state_save_register_global(machine, state->MMC5_floodattr);
201   state_save_register_global_array(machine, state->mmc5_vram);
202   state_save_register_global(machine, state->mmc5_vram_control);
203
204   state_save_register_global_array(machine, state->nes_vram_sprite);
205   state_save_register_global(machine, state->last_frame_flip);
206   state_save_register_global(machine, state->scanlines_per_frame);
207   state_save_register_global(machine, state->mid_ram_enable);
208
209   // shared mapper variables
210   state_save_register_global(machine, state->IRQ_enable);
211   state_save_register_global(machine, state->IRQ_enable_latch);
212   state_save_register_global(machine, state->IRQ_count);
213   state_save_register_global(machine, state->IRQ_count_latch);
214   state_save_register_global(machine, state->IRQ_toggle);
215   state_save_register_global(machine, state->IRQ_reset);
216   state_save_register_global(machine, state->IRQ_status);
217   state_save_register_global(machine, state->IRQ_mode);
218   state_save_register_global(machine, state->mult1);
219   state_save_register_global(machine, state->mult2);
220   state_save_register_global(machine, state->mmc_chr_source);
221   state_save_register_global(machine, state->mmc_cmd1);
222   state_save_register_global(machine, state->mmc_cmd2);
223   state_save_register_global(machine, state->mmc_count);
224   state_save_register_global(machine, state->mmc_prg_base);
225   state_save_register_global(machine, state->mmc_prg_mask);
226   state_save_register_global(machine, state->mmc_chr_base);
227   state_save_register_global(machine, state->mmc_chr_mask);
228   state_save_register_global_array(machine, state->prg_bank);
229   state_save_register_global_array(machine, state->vrom_bank);
230   state_save_register_global_array(machine, state->extra_bank);
231
232   state_save_register_global(machine, state->fds_motor_on);
233   state_save_register_global(machine, state->fds_door_closed);
234   state_save_register_global(machine, state->fds_current_side);
235   state_save_register_global(machine, state->fds_head_position);
236   state_save_register_global(machine, state->fds_status0);
237   state_save_register_global(machine, state->fds_read_mode);
238   state_save_register_global(machine, state->fds_write_reg);
239   state_save_register_global(machine, state->fds_last_side);
240   state_save_register_global(machine, state->fds_count);
241}
242
200243MACHINE_START( nes )
201244{
245   nes_state *state = (nes_state *)machine->driver_data;
246
202247   init_nes_core(machine);
203248   add_exit_callback(machine, nes_machine_stop);
204249
205   nes_irq_timer = timer_alloc(machine, nes_irq_callback, NULL);
250   state->maincpu = devtag_get_device(machine, "maincpu");
251   state->ppu = devtag_get_device(machine, "ppu");
252   state->sound = devtag_get_device(machine, "nessound");
253   state->cart = devtag_get_device(machine, "cart");
254
255   state->irq_timer = timer_alloc(machine, nes_irq_callback, NULL);
256   nes_state_register(machine);
206257}
207258
208259static void nes_machine_stop( running_machine *machine )
r7957r7958
414465
415466   if (cfg & 0x0f00)
416467      state->in_0.i0 |= (state->in_2.i0 << 8) | (0x08 << 16);
468
417469   if (cfg & 0xf000)
418470      state->in_1.i0 |= (state->in_3.i0 << 8) | (0x04 << 16);
419471}
420472
421473
422
423474WRITE8_HANDLER( nes_IN1_w )
424475{
425476}
426477
427478
428
429479DEVICE_IMAGE_LOAD( nes_cart )
430480{
431481   nes_state *state = (nes_state *)image->machine->driver_data;
r7957r7958
437487   char m;
438488   int i;
439489
440   /* Check first 4 bytes of the image to decide if it is UNIF or iNES */
441      /* Unfortunately, many .unf files have been released as .nes, so we cannot rely on extensions only */
442   memset(magic, '\0', sizeof(magic));
443   image_fread(image, magic, 4);
444
445   if ((magic[0] == 'N') && (magic[1] == 'E') && (magic[2] == 'S'))   /* If header starts with 'NES' it is iNES */
490   if (image_software_entry(image) == NULL)
446491   {
447      state->format = 1;   // we use this to select between mapper_reset / unif_reset
448
449      mapinfo = image_extrainfo(image);
450
451      if (mapinfo)
492      /* Check first 4 bytes of the image to decide if it is UNIF or iNES */
493      /* Unfortunately, many .unf files have been released as .nes, so we cannot rely on extensions only */
494      memset(magic, '\0', sizeof(magic));
495      image_fread(image, magic, 4);
496     
497      if ((magic[0] == 'N') && (magic[1] == 'E') && (magic[2] == 'S'))   /* If header starts with 'NES' it is iNES */
452498      {
453         if (4 == sscanf(mapinfo,"%d %d %d %d", &mapint1, &mapint2, &mapint3, &mapint4))
499         state->format = 1;   // we use this to select between mapper_reset / unif_reset
500         
501         mapinfo = image_extrainfo(image);
502         
503         if (mapinfo)
454504         {
455            state->mapper = mapint1;
456            local_options = mapint2 & 0x0f;
457            state->crc_hack = mapint2 & 0xf0;   // this is used to differentiate among variants of the same Mapper (see nes_mmc.c)
458            state->prg_chunks = mapint3;
459            state->chr_chunks = mapint4;
460            logerror("NES.HSI info: %d %d %d %d\n", mapint1, mapint2, mapint3, mapint4);
461            goodcrcinfo = 1;
505            if (4 == sscanf(mapinfo,"%d %d %d %d", &mapint1, &mapint2, &mapint3, &mapint4))
506            {
507               state->mapper = mapint1;
508               local_options = mapint2 & 0x0f;
509               state->crc_hack = mapint2 & 0xf0;   // this is used to differentiate among variants of the same Mapper (see nes_mmc.c)
510               state->prg_chunks = mapint3;
511               state->chr_chunks = mapint4;
512               logerror("NES.HSI info: %d %d %d %d\n", mapint1, mapint2, mapint3, mapint4);
513               goodcrcinfo = 1;
514            }
515            else
516            {
517               logerror("NES: [%s], Invalid mapinfo found\n", mapinfo);
518            }
462519         }
463520         else
464521         {
465            logerror("NES: [%s], Invalid mapinfo found\n",mapinfo);
522            logerror("NES: No extrainfo found\n");
466523         }
467      }
468      else
469      {
470         logerror("NES: No extrainfo found\n");
471      }
472
473      if (!goodcrcinfo)
474      {
475         // image_extrainfo() resets the file position back to start.
476         // Let's skip past the magic header once again.
477         image_fseek(image, 4, SEEK_SET);
478
479         image_fread(image, &state->prg_chunks, 1);
480         image_fread(image, &state->chr_chunks, 1);
481         /* Read the first ROM option byte (offset 6) */
482         image_fread(image, &m, 1);
483
484         /* Interpret the iNES header flags */
485         state->mapper = (m & 0xf0) >> 4;
486         local_options = m & 0x0f;
487
488         /* Read the second ROM option byte (offset 7) */
489         image_fread(image, &m, 1);
490
491         /* Check for skanky headers */
492         image_fread(image, &skank, 8);
493
494         /* If the header has junk in the unused bytes, assume the extra mapper byte is also invalid */
495         /* We only check the first 4 unused bytes for now */
496         for (i = 0; i < 4; i ++)
524         
525         if (!goodcrcinfo)
497526         {
498            logerror("%02x ", skank[i]);
499            if (skank[i] != 0x00)
527            // image_extrainfo() resets the file position back to start.
528            // Let's skip past the magic header once again.
529            image_fseek(image, 4, SEEK_SET);
530           
531            image_fread(image, &state->prg_chunks, 1);
532            image_fread(image, &state->chr_chunks, 1);
533            /* Read the first ROM option byte (offset 6) */
534            image_fread(image, &m, 1);
535           
536            /* Interpret the iNES header flags */
537            state->mapper = (m & 0xf0) >> 4;
538            local_options = m & 0x0f;
539           
540            /* Read the second ROM option byte (offset 7) */
541            image_fread(image, &m, 1);
542           
543            /* Check for skanky headers */
544            image_fread(image, &skank, 8);
545           
546            /* If the header has junk in the unused bytes, assume the extra mapper byte is also invalid */
547            /* We only check the first 4 unused bytes for now */
548            for (i = 0; i < 4; i ++)
500549            {
501               logerror("(skank: %d)", i);
550               logerror("%02x ", skank[i]);
551               if (skank[i] != 0x00)
552               {
553                  logerror("(skank: %d)", i);
554               }
502555            }
556            logerror("\n");
557           
558            state->mapper = state->mapper | (m & 0xf0);
503559         }
504         logerror("\n");
505
506         state->mapper = state->mapper | (m & 0xf0);
507      }
508
509      state->hard_mirroring = local_options & 0x01;
510      state->battery = local_options & 0x02;
511      state->trainer = local_options & 0x04;
512      state->four_screen_vram = local_options & 0x08;
513
514      if (state->battery)
515         logerror("-- Battery found\n");
516
517      if (state->trainer)
518         logerror("-- Trainer found\n");
519
520      if (state->four_screen_vram)
521         logerror("-- 4-screen VRAM\n");
522
523      /* Free the regions that were allocated by the ROM loader */
524      memory_region_free(image->machine, "maincpu");
525      memory_region_free(image->machine, "gfx1");
526
527      /* Allocate them again with the proper size */
528      memory_region_alloc(image->machine, "maincpu", 0x10000 + (state->prg_chunks + 1) * 0x4000,0);
529      if (state->chr_chunks)
530         memory_region_alloc(image->machine, "gfx1", state->chr_chunks * 0x2000,0);
531
532      state->rom = memory_region(image->machine, "maincpu");
533      state->vrom = memory_region(image->machine, "gfx1");
534      state->vram = memory_region(image->machine, "gfx2");
535      state->wram = memory_region(image->machine, "user1");
536
537      /* Position past the header */
538      image_fseek(image, 16, SEEK_SET);
539
540      /* Load the 0x200 byte trainer at 0x7000 if it exists */
541      if (state->trainer)
542         image_fread(image, &state->wram[0x1000], 0x200);
543
544      /* Read in the program chunks */
545      if (state->prg_chunks == 1)
546      {
547         image_fread(image, &state->rom[0x14000], 0x4000);
548         /* Mirror this bank into $8000 */
549         memcpy(&state->rom[0x10000], &state->rom [0x14000], 0x4000);
550      }
551      else
552         image_fread(image, &state->rom[0x10000], 0x4000 * state->prg_chunks);
553
560         
561         state->hard_mirroring = local_options & 0x01;
562         state->battery = local_options & 0x02;
563         state->trainer = local_options & 0x04;
564         state->four_screen_vram = local_options & 0x08;
565         
566         if (state->battery)
567            logerror("-- Battery found\n");
568         
569         if (state->trainer)
570            logerror("-- Trainer found\n");
571         
572         if (state->four_screen_vram)
573            logerror("-- 4-screen VRAM\n");
574         
575         /* Free the regions that were allocated by the ROM loader */
576         memory_region_free(image->machine, "maincpu");
577         memory_region_free(image->machine, "gfx1");
578         
579         /* Allocate them again with the proper size */
580         memory_region_alloc(image->machine, "maincpu", 0x10000 + (state->prg_chunks + 1) * 0x4000, 0);
581         if (state->chr_chunks)
582            memory_region_alloc(image->machine, "gfx1", state->chr_chunks * 0x2000, 0);
583         
584         state->rom = memory_region(image->machine, "maincpu");
585         state->vrom = memory_region(image->machine, "gfx1");
586         state->vram = memory_region(image->machine, "gfx2");
587         state->wram = memory_region(image->machine, "user1");
588         
589         /* Position past the header */
590         image_fseek(image, 16, SEEK_SET);
591         
592         /* Load the 0x200 byte trainer at 0x7000 if it exists */
593         if (state->trainer)
594            image_fread(image, &state->wram[0x1000], 0x200);
595         
596         /* Read in the program chunks */
597         if (state->prg_chunks == 1)
598         {
599            image_fread(image, &state->rom[0x14000], 0x4000);
600            /* Mirror this bank into $8000 */
601            memcpy(&state->rom[0x10000], &state->rom [0x14000], 0x4000);
602         }
603         else
604            image_fread(image, &state->rom[0x10000], 0x4000 * state->prg_chunks);
605         
554606#if SPLIT_PRG
555      {
556         FILE *prgout;
557         char outname[255];
558
559         for (i = 0; i < state->prg_chunks; i ++)
560607         {
561            sprintf(outname, "%s.p%d", image_filename(image), i);
608            FILE *prgout;
609            char outname[255];
610           
611            sprintf(outname, "%s.prg", image_filename(image));
562612            prgout = fopen(outname, "wb");
563613            if (prgout)
564614            {
565               fwrite(&state->rom[0x10000 + 0x4000 * i], 1, 0x4000, prgout);
566               fclose(prgout);
615               fwrite(&state->rom[0x10000], 1, 0x4000 * state->prg_chunks, prgout);
616               printf("Created PRG chunk\n");
567617            }
618
619            fclose(prgout);
568620         }
569      }
570#endif /* SPLIT_PRG */
571
572      logerror("**\n");
573      logerror("Mapper: %d\n", state->mapper);
574      logerror("PRG chunks: %02x, size: %06x\n", state->prg_chunks, 0x4000 * state->prg_chunks);
575//      printf("Mapper: %d\n", state->mapper);
576//      printf("PRG chunks: %02x, size: %06x\n", state->prg_chunks, 0x4000 * state->prg_chunks);
577
578      /* Read in any chr chunks */
579      if (state->chr_chunks > 0)
580      {
581         image_fread(image, state->vrom, state->chr_chunks * 0x2000);
582         if (state->mapper == 2)
583            logerror("Warning: VROM has been found in VRAM-based mapper. Either the mapper is set wrong or the ROM image is incorrect.\n");
584      }
585
621#endif
622         
623         logerror("**\n");
624         logerror("Mapper: %d\n", state->mapper);
625         logerror("PRG chunks: %02x, size: %06x\n", state->prg_chunks, 0x4000 * state->prg_chunks);
626         // printf("Mapper: %d\n", state->mapper);
627         // printf("PRG chunks: %02x, size: %06x\n", state->prg_chunks, 0x4000 * state->prg_chunks);
628         
629         /* Read in any chr chunks */
630         if (state->chr_chunks > 0)
631         {
632            image_fread(image, state->vrom, state->chr_chunks * 0x2000);
633            if (state->mapper == 2)
634               logerror("Warning: VROM has been found in VRAM-based mapper. Either the mapper is set wrong or the ROM image is incorrect.\n");
635         }
636         
586637#if SPLIT_CHR
587      {
588         FILE *chrout;
589         char outname[255];
590
591         for (i = 0; i < state->chr_chunks; i ++)
592638         {
593            sprintf(outname, "%s.c%d", image_filename(image), i);
639            FILE *chrout;
640            char outname[255];
641           
642            sprintf(outname, "%s.chr", image_filename(image));
594643            chrout= fopen(outname, "wb");
595644            if (chrout)
596645            {
597               fwrite(&state->rom[0x10000 + 0x2000 * i], 1, 0x2000, chrout);
598               fclose(chrout);
646               fwrite(state->vrom, 1, 0x2000 * state->chr_chunks, chrout);
647               printf("Created CHR chunk\n");
599648            }
649            fclose(chrout);
600650         }
651#endif
652         
653         logerror("CHR chunks: %02x, size: %06x\n", state->chr_chunks, 0x4000 * state->chr_chunks);
654         logerror("**\n");
655         // printf("CHR chunks: %02x, size: %06x\n", state->chr_chunks, 0x4000 * state->chr_chunks);
656         // printf("**\n");
657         
658         /* Attempt to load a battery file for this ROM. If successful, we */
659         /* must wait until later to move it to the system memory. */
660         if (state->battery)
661            image_battery_load(image, state->battery_data, NES_BATTERY_SIZE, 0x00);
662         
601663      }
602#endif /* SPLIT_CHR */
603
604      logerror("CHR chunks: %02x, size: %06x\n", state->chr_chunks, 0x4000 * state->chr_chunks);
605      logerror("**\n");
606//      printf("CHR chunks: %02x, size: %06x\n", state->chr_chunks, 0x4000 * state->chr_chunks);
607//      printf("**\n");
608
609      /* Attempt to load a battery file for this ROM. If successful, we */
610      /* must wait until later to move it to the system memory. */
611      if (state->battery)
612         image_battery_load(image, state->battery_data, NES_BATTERY_SIZE, 0x00);
613
614   }
615   else if ((magic[0] == 'U') && (magic[1] == 'N') && (magic[2] == 'I') && (magic[3] == 'F')) /* If header starts with 'UNIF' it is UNIF */
616   {
617      UINT32 unif_ver = 0;
618      char magic2[4];
619      UINT8 buffer[4];
620      UINT32 chunk_length = 0, read_length = 0x20;
621      UINT32 prg_start = 0, chr_start = 0;
622      int prg_left = 0, chr_left = 0;   // used to verify integrity of our unif image
623      char unif_mapr[32];   // here we should store MAPR chunks
624      UINT32 size = image_length(image);
625      const unif *unif_board;
626      int mapr_chunk_found = 0;
627
628      state->format = 2;   // we use this to select between mapper_reset / unif_reset
629
630      image_fread(image, &buffer, 4);
631      unif_ver = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
632      logerror("UNIF file found, version %d\n", unif_ver);
633
634      if (size <= 0x20)
664      else if ((magic[0] == 'U') && (magic[1] == 'N') && (magic[2] == 'I') && (magic[3] == 'F')) /* If header starts with 'UNIF' it is UNIF */
635665      {
636         logerror("%s only contains the UNIF header and no data.\n", image_filename(image));
637         return INIT_FAIL;
638      }
639
640      do
641      {
642         image_fseek(image, read_length, SEEK_SET);
643
644         memset(magic2, '\0', sizeof(magic2));
645         image_fread(image, &magic2, 4);
646
666         UINT32 unif_ver = 0;
667         char magic2[4];
668         UINT8 buffer[4];
669         UINT32 chunk_length = 0, read_length = 0x20;
670         UINT32 prg_start = 0, chr_start = 0;
671         int prg_left = 0, chr_left = 0;   // used to verify integrity of our unif image
672         char unif_mapr[32];   // here we should store MAPR chunks
673         UINT32 size = image_length(image);
674         const unif *unif_board;
675         int mapr_chunk_found = 0;
676         
677         state->format = 2;   // we use this to select between mapper_reset / unif_reset
678         
679         image_fread(image, &buffer, 4);
680         unif_ver = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
681         logerror("UNIF file found, version %d\n", unif_ver);
682         
683         if (size <= 0x20)
684         {
685            logerror("%s only contains the UNIF header and no data.\n", image_filename(image));
686            return INIT_FAIL;
687         }
688         
689         do
690         {
691            image_fseek(image, read_length, SEEK_SET);
692           
693            memset(magic2, '\0', sizeof(magic2));
694            image_fread(image, &magic2, 4);
695           
647696#if 0
648// unfortunately, the MAPR chunk is not always the first chunk (see Super 24-in-1)
649         /* Preliminary checks: the first chunk MUST be MAPR! */
650         if (read_length == 0x20 && ((magic2[0] != 'M') || (magic2[1] != 'A') || (magic2[2] != 'P') || (magic2[3] != 'R')))
651            fatalerror("First chunk of data in UNIF should be [MAPR]. Check if your image has been corrupted\n");
652
653         /* Preliminary checks: multiple MAPR chunks are FORBIDDEN! */
654         if (read_length > 0x20 && ((magic2[0] == 'M') && (magic2[1] == 'A') && (magic2[2] == 'P') && (magic2[3] == 'R')))
655            fatalerror("UNIF should not have multiple [MAPR] chunks. Check if your image has been corrupted\n");
697            // unfortunately, the MAPR chunk is not always the first chunk (see Super 24-in-1)
698            /* Preliminary checks: the first chunk MUST be MAPR! */
699            if (read_length == 0x20 && ((magic2[0] != 'M') || (magic2[1] != 'A') || (magic2[2] != 'P') || (magic2[3] != 'R')))
700               fatalerror("First chunk of data in UNIF should be [MAPR]. Check if your image has been corrupted\n");
701           
702            /* Preliminary checks: multiple MAPR chunks are FORBIDDEN! */
703            if (read_length > 0x20 && ((magic2[0] == 'M') && (magic2[1] == 'A') && (magic2[2] == 'P') && (magic2[3] == 'R')))
704               fatalerror("UNIF should not have multiple [MAPR] chunks. Check if your image has been corrupted\n");
656705#endif
657
658         /* we first run through the whole image to find a [MAPR] chunk */
659         /* when found, we set mapr_chunk_found=1 and we go back to load other chunks! */
660         if (!mapr_chunk_found)
661         {
662            if ((magic2[0] == 'M') && (magic2[1] == 'A') && (magic2[2] == 'P') && (magic2[3] == 'R'))
706           
707            /* we first run through the whole image to find a [MAPR] chunk */
708            /* when found, we set mapr_chunk_found=1 and we go back to load other chunks! */
709            if (!mapr_chunk_found)
663710            {
664               mapr_chunk_found = 1;
665               logerror("[MAPR] chunk found: ");
666               image_fread(image, &buffer, 4);
667               chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
668
669               if (chunk_length <= 0x20)
670                  image_fread(image, &unif_mapr, chunk_length);
671
672               unif_board = nes_unif_lookup(unif_mapr);
673               logerror("%s\n", unif_mapr);
674
675               if (unif_board == NULL)
711               if ((magic2[0] == 'M') && (magic2[1] == 'A') && (magic2[2] == 'P') && (magic2[3] == 'R'))
676712               {
677                  fatalerror("Unsupported UNIF board %s.\n", unif_mapr);
678//                            logerror("Unsupported UNIF board %s.\n", unif_mapr);
713                  mapr_chunk_found = 1;
714                  logerror("[MAPR] chunk found: ");
715                  image_fread(image, &buffer, 4);
716                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
717                 
718                  if (chunk_length <= 0x20)
719                     image_fread(image, &unif_mapr, chunk_length);
720                 
721                  unif_board = nes_unif_lookup(unif_mapr);
722                  logerror("%s\n", unif_mapr);
723                 
724                  if (unif_board == NULL)
725                  {
726                     fatalerror("Unsupported UNIF board %s.\n", unif_mapr);
727                     // logerror("Unsupported UNIF board %s.\n", unif_mapr);
728                  }
729                 
730                  state->mapper = 0;   // this allows us to set up memory handlers without duplicating code (for the moment)
731                  state->board = unif_board->board;
732                  state->prg_chunks = unif_board->prgrom;
733                  state->chr_chunks = unif_board->chrrom;
734                  state->battery = unif_board->wram;   // we should implement WRAM banks...
735                  //                  state->hard_mirroring = unif_board->nt;
736                  //                      state->four_screen_vram = ;
737                 
738                  /* Free the regions that were allocated by the ROM loader */
739                  memory_region_free(image->machine, "maincpu");
740                  memory_region_free(image->machine, "gfx1");
741                 
742                  /* Allocate them again with the proper size */
743                  memory_region_alloc(image->machine, "maincpu", 0x10000 + (state->prg_chunks + 1) * 0x4000, 0);
744                  if (state->chr_chunks)
745                     memory_region_alloc(image->machine, "gfx1", state->chr_chunks * 0x2000, 0);
746                 
747                  state->rom = memory_region(image->machine, "maincpu");
748                  state->vrom = memory_region(image->machine, "gfx1");
749                  state->vram = memory_region(image->machine, "gfx2");
750                  state->wram = memory_region(image->machine, "user1");
751                 
752                  /* for validation purposes */
753                  prg_left = unif_board->prgrom * 0x4000;
754                  chr_left = unif_board->chrrom * 0x2000;
755                 
756                  /* now that we found the MAPR chunk, we can go back to load other chunks */
757                  image_fseek(image, 0x20, SEEK_SET);
758                  read_length = 0x20;
679759               }
680
681               state->mapper = 0;   // this allows us to set up memory handlers without duplicating code (for the moment)
682               state->board = unif_board->board;
683               state->prg_chunks = unif_board->prgrom;
684               state->chr_chunks = unif_board->chrrom;
685               state->battery = unif_board->wram;   // we should implement WRAM banks...
686//                  state->hard_mirroring = unif_board->nt;
687//                      state->four_screen_vram = ;
688
689               /* Free the regions that were allocated by the ROM loader */
690               memory_region_free(image->machine, "maincpu");
691               memory_region_free(image->machine, "gfx1");
692
693               /* Allocate them again with the proper size */
694               memory_region_alloc(image->machine, "maincpu", 0x10000 + (state->prg_chunks + 1) * 0x4000, 0);
695               if (state->chr_chunks)
696                  memory_region_alloc(image->machine, "gfx1", state->chr_chunks * 0x2000, 0);
697
698               state->rom = memory_region(image->machine, "maincpu");
699               state->vrom = memory_region(image->machine, "gfx1");
700               state->vram = memory_region(image->machine, "gfx2");
701               state->wram = memory_region(image->machine, "user1");
702
703               /* for validation purposes */
704               prg_left = unif_board->prgrom * 0x4000;
705               chr_left = unif_board->chrrom * 0x2000;
706
707               /* now that we found the MAPR chunk, we can go back to load other chunks */
708               image_fseek(image, 0x20, SEEK_SET);
709               read_length = 0x20;
760               else
761               {
762                  logerror("Skip this chunk. We need a [MAPR] chunk before anything else.\n");
763                  image_fread(image, &buffer, 4);
764                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
765                 
766                  read_length += (chunk_length + 8);
767               }
710768            }
711769            else
712770            {
713               logerror("Skip this chunk. We need a [MAPR] chunk before anything else.\n");
714               image_fread(image, &buffer, 4);
715               chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
716
717               read_length += (chunk_length + 8);
771               /* What kind of chunk do we have here? */
772               if ((magic2[0] == 'M') && (magic2[1] == 'A') && (magic2[2] == 'P') && (magic2[3] == 'R'))
773               {
774                  /* The [MAPR] chunk has already been read, so we skip it */
775                  /* TO DO: it would be nice to check if more than one MAPR chunk is present */
776                  logerror("[MAPR] chunk found (in the 2nd run). Already loaded.\n");
777                  image_fread(image, &buffer, 4);
778                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
779                 
780                  read_length += (chunk_length + 8);
781               }
782               else if ((magic2[0] == 'R') && (magic2[1] == 'E') && (magic2[2] == 'A') && (magic2[3] == 'D'))
783               {
784                  logerror("[READ] chunk found. No support yet.\n");
785                  image_fread(image, &buffer, 4);
786                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
787                 
788                  read_length += (chunk_length + 8);
789               }
790               else if ((magic2[0] == 'N') && (magic2[1] == 'A') && (magic2[2] == 'M') && (magic2[3] == 'E'))
791               {
792                  logerror("[NAME] chunk found. No support yet.\n");
793                  image_fread(image, &buffer, 4);
794                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
795                 
796                  read_length += (chunk_length + 8);
797               }
798               else if ((magic2[0] == 'W') && (magic2[1] == 'R') && (magic2[2] == 'T') && (magic2[3] == 'R'))
799               {
800                  logerror("[WRTR] chunk found. No support yet.\n");
801                  image_fread(image, &buffer, 4);
802                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
803                 
804                  read_length += (chunk_length + 8);
805               }
806               else if ((magic2[0] == 'T') && (magic2[1] == 'V') && (magic2[2] == 'C') && (magic2[3] == 'I'))
807               {
808                  logerror("[TVCI] chunk found. No support yet.\n");
809                  image_fread(image, &buffer, 4);
810                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
811                 
812                  read_length += (chunk_length + 8);
813               }
814               else if ((magic2[0] == 'D') && (magic2[1] == 'I') && (magic2[2] == 'N') && (magic2[3] == 'F'))
815               {
816                  logerror("[DINF] chunk found. No support yet.\n");
817                  image_fread(image, &buffer, 4);
818                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
819                 
820                  read_length += (chunk_length + 8);
821               }
822               else if ((magic2[0] == 'C') && (magic2[1] == 'T') && (magic2[2] == 'R') && (magic2[3] == 'L'))
823               {
824                  logerror("[CTRL] chunk found. No support yet.\n");
825                  image_fread(image, &buffer, 4);
826                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
827                 
828                  read_length += (chunk_length + 8);
829               }
830               else if ((magic2[0] == 'B') && (magic2[1] == 'A') && (magic2[2] == 'T') && (magic2[3] == 'R'))
831               {
832                  logerror("[BATR] chunk found. No support yet.\n");
833                  image_fread(image, &buffer, 4);
834                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
835                 
836                  read_length += (chunk_length + 8);
837               }
838               else if ((magic2[0] == 'V') && (magic2[1] == 'R') && (magic2[2] == 'O') && (magic2[3] == 'R'))
839               {
840                  logerror("[VROR] chunk found. No support yet.\n");
841                  image_fread(image, &buffer, 4);
842                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
843                 
844                  read_length += (chunk_length + 8);
845               }
846               else if ((magic2[0] == 'M') && (magic2[1] == 'I') && (magic2[2] == 'R') && (magic2[3] == 'R'))
847               {
848                  logerror("[MIRR] chunk found. No support yet.\n");
849                  image_fread(image, &buffer, 4);
850                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
851                 
852                  read_length += (chunk_length + 8);
853               }
854               else if ((magic2[0] == 'P') && (magic2[1] == 'C') && (magic2[2] == 'K'))
855               {
856                  logerror("[PCK%c] chunk found. No support yet.\n", magic2[3]);
857                  image_fread(image, &buffer, 4);
858                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
859                 
860                  read_length += (chunk_length + 8);
861               }
862               else if ((magic2[0] == 'C') && (magic2[1] == 'C') && (magic2[2] == 'K'))
863               {
864                  logerror("[CCK%c] chunk found. No support yet.\n", magic2[3]);
865                  image_fread(image, &buffer, 4);
866                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
867                 
868                  read_length += (chunk_length + 8);
869               }
870               else if ((magic2[0] == 'P') && (magic2[1] == 'R') && (magic2[2] == 'G'))
871               {
872                  logerror("[PRG%c] chunk found. ", magic2[3]);
873                  image_fread(image, &buffer, 4);
874                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
875                 
876                  logerror("It consists of %d 16K-blocks.\n", chunk_length / 0x4000);
877                  /* Validation */
878                  prg_left -= chunk_length;
879                  if (prg_left < 0)
880                     fatalerror("PRG chunks larger than expected by board %s!\n", unif_mapr);
881                 
882                  /* Read in the program chunks */
883                  if (state->prg_chunks == 1)
884                  {
885                     image_fread(image, &state->rom[0x14000], chunk_length);
886                     /* Mirror the only bank into $8000 */
887                     memcpy(&state->rom[0x10000], &state->rom[0x14000], chunk_length);
888                  }
889                  else
890                     image_fread(image, &state->rom[0x10000 + prg_start], chunk_length);
891                 
892                  prg_start += chunk_length;
893                  read_length += (chunk_length + 8);
894               }
895               else if ((magic2[0] == 'C') && (magic2[1] == 'H') && (magic2[2] == 'R'))
896               {
897                  logerror("[CHR%c] chunk found. ", magic2[3]);
898                  image_fread(image, &buffer, 4);
899                  chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
900                 
901                  logerror("It consists of %d 8K-blocks.\n", chunk_length / 0x2000);
902                  /* validation */
903                  chr_left -= chunk_length;
904                  if (chr_left < 0)
905                     fatalerror("CHR chunks larger than expected by board %s!\n", unif_mapr);
906                 
907                  /* Read in the vrom chunks */
908                  image_fread(image, state->vrom + chr_start, chunk_length);
909                 
910                  chr_start += chunk_length;
911                  read_length += (chunk_length + 8);
912               }
913               else
914               {
915                  printf("Unsupported UNIF chunk. Please report the problem at MESS Board.\n");
916                  read_length = size;
917               }
718918            }
719         }
720         else
721         {
722            /* What kind of chunk do we have here? */
723            if ((magic2[0] == 'M') && (magic2[1] == 'A') && (magic2[2] == 'P') && (magic2[3] == 'R'))
724            {
725               /* The [MAPR] chunk has already been read, so we skip it */
726               /* TO DO: it would be nice to check if more than one MAPR chunk is present */
727               logerror("[MAPR] chunk found (in the 2nd run). Already loaded.\n");
728               image_fread(image, &buffer, 4);
729               chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
919         } while (size > read_length);
920         
921         if (!mapr_chunk_found )
922            fatalerror("UNIF should have a [MAPR] chunk to work. Check if your image has been corrupted\n");
923         
924         logerror("UNIF support is only very preliminary.\n");
925      }
926      else
927      {
928         logerror("%s is NOT a file in either iNES or UNIF format.\n", image_filename(image));
929         return INIT_FAIL;
930      }
931   }
932   else
933   {
934      UINT32 prg_size = image_get_software_region_length(image, "prg");
935      UINT32 chr_size = image_get_software_region_length(image, "chr");
730936
731               read_length += (chunk_length + 8);
732            }
733            else if ((magic2[0] == 'R') && (magic2[1] == 'E') && (magic2[2] == 'A') && (magic2[3] == 'D'))
734            {
735               logerror("[READ] chunk found. No support yet.\n");
736               image_fread(image, &buffer, 4);
737               chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
937      /* Free the regions that were allocated by the ROM loader */
938      memory_region_free(image->machine, "maincpu");
939      memory_region_free(image->machine, "gfx1");
738940
739               read_length += (chunk_length + 8);
740            }
741            else if ((magic2[0] == 'N') && (magic2[1] == 'A') && (magic2[2] == 'M') && (magic2[3] == 'E'))
742            {
743               logerror("[NAME] chunk found. No support yet.\n");
744               image_fread(image, &buffer, 4);
745               chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
941      /* Allocate them again with the proper size */
746942
747               read_length += (chunk_length + 8);
748            }
749            else if ((magic2[0] == 'W') && (magic2[1] == 'R') && (magic2[2] == 'T') && (magic2[3] == 'R'))
750            {
751               logerror("[WRTR] chunk found. No support yet.\n");
752               image_fread(image, &buffer, 4);
753               chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
943      // FIXME: here we have a +0x4000 to handle games with a single 16k prg chunk,
944      // but we should simply reload it in the .xml and use here the proper prg_size!!
945      memory_region_alloc(image->machine, "maincpu", 0x10000 + prg_size + 0x4000, 0);
754946
755               read_length += (chunk_length + 8);
756            }
757            else if ((magic2[0] == 'T') && (magic2[1] == 'V') && (magic2[2] == 'C') && (magic2[3] == 'I'))
758            {
759               logerror("[TVCI] chunk found. No support yet.\n");
760               image_fread(image, &buffer, 4);
761               chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
947      if (chr_size)
948         memory_region_alloc(image->machine, "gfx1", chr_size, 0);
949     
950      state->rom = memory_region(image->machine, "maincpu");
951      state->vrom = memory_region(image->machine, "gfx1");
952      state->vram = memory_region(image->machine, "gfx2");
953      state->wram = memory_region(image->machine, "user1");
762954
763               read_length += (chunk_length + 8);
764            }
765            else if ((magic2[0] == 'D') && (magic2[1] == 'I') && (magic2[2] == 'N') && (magic2[3] == 'F'))
766            {
767               logerror("[DINF] chunk found. No support yet.\n");
768               image_fread(image, &buffer, 4);
769               chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
955      memcpy(state->rom + 0x10000, image_get_software_region(image, "prg"), prg_size);
956      // FIXME: as above, we should reload the single prg chunk in the .xml, not copying it here
957      if (prg_size == 0x4000)
958         memcpy(state->rom + 0x14000, image_get_software_region(image, "prg"), prg_size);
770959
771               read_length += (chunk_length + 8);
772            }
773            else if ((magic2[0] == 'C') && (magic2[1] == 'T') && (magic2[2] == 'R') && (magic2[3] == 'L'))
774            {
775               logerror("[CTRL] chunk found. No support yet.\n");
776               image_fread(image, &buffer, 4);
777               chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
960      if (chr_size)
961         memcpy(state->vrom, image_get_software_region(image, "chr"), chr_size);
778962
779               read_length += (chunk_length + 8);
780            }
781            else if ((magic2[0] == 'B') && (magic2[1] == 'A') && (magic2[2] == 'T') && (magic2[3] == 'R'))
782            {
783               logerror("[BATR] chunk found. No support yet.\n");
784               image_fread(image, &buffer, 4);
785               chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
963      state->prg_chunks = prg_size / 0x4000;
964      state->chr_chunks = chr_size / 0x2000;
786965
787               read_length += (chunk_length + 8);
788            }
789            else if ((magic2[0] == 'V') && (magic2[1] == 'R') && (magic2[2] == 'O') && (magic2[3] == 'R'))
790            {
791               logerror("[VROR] chunk found. No support yet.\n");
792               image_fread(image, &buffer, 4);
793               chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
966      state->format = 1; // temporarily treat this as a ines file
967      state->mapper = 4; // this should depend on the 'feature' field of the .xml file
968      // FIXME: we need to handle the remaining variables. on the short term, we might
969      // create a table for the various mappers (based on the 'feature' value in xml),
970      // but on the long term we need to rework the whole emulation to first use the
971      // xml list and have mappers and unif boards to fall back to particular 'feature'
972      // values!
794973
795               read_length += (chunk_length + 8);
796            }
797            else if ((magic2[0] == 'M') && (magic2[1] == 'I') && (magic2[2] == 'R') && (magic2[3] == 'R'))
798            {
799               logerror("[MIRR] chunk found. No support yet.\n");
800               image_fread(image, &buffer, 4);
801               chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
802
803               read_length += (chunk_length + 8);
804            }
805            else if ((magic2[0] == 'P') && (magic2[1] == 'C') && (magic2[2] == 'K'))
806            {
807               logerror("[PCK%c] chunk found. No support yet.\n", magic2[3]);
808               image_fread(image, &buffer, 4);
809               chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
810
811               read_length += (chunk_length + 8);
812            }
813            else if ((magic2[0] == 'C') && (magic2[1] == 'C') && (magic2[2] == 'K'))
814            {
815               logerror("[CCK%c] chunk found. No support yet.\n", magic2[3]);
816                  image_fread(image, &buffer, 4);
817               chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
818
819               read_length += (chunk_length + 8);
820            }
821            else if ((magic2[0] == 'P') && (magic2[1] == 'R') && (magic2[2] == 'G'))
822            {
823               logerror("[PRG%c] chunk found. ", magic2[3]);
824               image_fread(image, &buffer, 4);
825               chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
826
827               logerror("It consists of %d 16K-blocks.\n", chunk_length / 0x4000);
828               /* Validation */
829               prg_left -= chunk_length;
830               if (prg_left < 0)
831                  fatalerror("PRG chunks larger than expected by board %s!\n", unif_mapr);
832
833               /* Read in the program chunks */
834               if (state->prg_chunks == 1)
835               {
836                  image_fread(image, &state->rom[0x14000], chunk_length);
837                  /* Mirror the only bank into $8000 */
838                  memcpy(&state->rom[0x10000], &state->rom[0x14000], chunk_length);
839               }
840               else
841                  image_fread(image, &state->rom[0x10000 + prg_start], chunk_length);
842
843               prg_start += chunk_length;
844               read_length += (chunk_length + 8);
845            }
846            else if ((magic2[0] == 'C') && (magic2[1] == 'H') && (magic2[2] == 'R'))
847            {
848               logerror("[CHR%c] chunk found. ", magic2[3]);
849               image_fread(image, &buffer, 4);
850               chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
851
852               logerror("It consists of %d 8K-blocks.\n", chunk_length / 0x2000);
853               /* validation */
854               chr_left -= chunk_length;
855               if (chr_left < 0)
856                  fatalerror("CHR chunks larger than expected by board %s!\n", unif_mapr);
857
858               /* Read in the vrom chunks */
859               image_fread(image, state->vrom + chr_start, chunk_length);
860
861               chr_start += chunk_length;
862               read_length += (chunk_length + 8);
863            }
864            else
865            {
866               printf("Unsupported UNIF chunk. Please report the problem at MESS Board.\n");
867               read_length = size;
868            }
869         }
870      } while (size > read_length);
871
872   if (!mapr_chunk_found )
873      fatalerror("UNIF should have a [MAPR] chunk to work. Check if your image has been corrupted\n");
874
875   logerror("UNIF support is only very preliminary.\n");
974      //state->crc_hack = ;
975      //state->hard_mirroring = ;
976      //state->battery = ;
977      //state->trainer = ;
978      //state->four_screen_vram = ;
876979   }
877   else
878   {
879      logerror("%s is NOT a file in either iNES or UNIF format.\n", image_filename(image));
880      return INIT_FAIL;
881   }
882
980   
883981   return INIT_PASS;
884982}
885983
r7957r7958
9391037   state->fds_sides = 0;
9401038   state->fds_data = NULL;
9411039
942   floppy_install_load_proc(floppy_get_device(machine,0), nes_load_proc);
943   floppy_install_unload_proc(floppy_get_device(machine,0), nes_unload_proc);
1040   floppy_install_load_proc(floppy_get_device(machine, 0), nes_load_proc);
1041   floppy_install_unload_proc(floppy_get_device(machine, 0), nes_unload_proc);
9441042}
src/mess/machine/nes_mmc.c
r7957r7958
748748         if (state->four_screen_vram)
749749         {
750750            state->extended_ntram = auto_alloc_array(machine, UINT8, 0x2000);
751            state_save_register_global_pointer(machine, state->extended_ntram, 0x2000);
751752            set_nt_page(machine, 0, CART_NTRAM, 0, 1);
752753            set_nt_page(machine, 1, CART_NTRAM, 1, 1);
753754            set_nt_page(machine, 2, CART_NTRAM, 2, 1);
src/mess/machine/nes_ines.c
r7957r7958
258258      {
259259         LOG_MMC(("irq fired, scanline: %d (MAME %d, beam pos: %d)\n", scanline,
260260               video_screen_get_vpos(device->machine->primary_screen), video_screen_get_hpos(device->machine->primary_screen)));
261         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
261         cpu_set_input_line(state->maincpu, M6502_IRQ_LINE, HOLD_LINE);
262262      }
263263   }
264264}
r7957r7958
360360   if (scanline == state->IRQ_count)
361361   {
362362      if (state->IRQ_enable)
363         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
363         cpu_set_input_line(state->maincpu, M6502_IRQ_LINE, HOLD_LINE);
364364
365365      state->IRQ_status = 0xff;
366366   }
r7957r7958
932932   {
933933      if ((0xffff - state->IRQ_count) < 114)
934934      {
935         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
935         cpu_set_input_line(state->maincpu, M6502_IRQ_LINE, HOLD_LINE);
936936         state->IRQ_count = 0xffff;
937937         state->IRQ_enable = 0;
938938      }
r7957r7958
14861486   {
14871487      if (state->IRQ_count <= 114)
14881488      {
1489         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
1489         cpu_set_input_line(state->maincpu, M6502_IRQ_LINE, HOLD_LINE);
14901490         state->IRQ_count = (0xffff - 114 + state->IRQ_count);    // wrap around the 16 bits counter
14911491      }
14921492      state->IRQ_count -= 114;
r7957r7958
16301630      {
16311631         if ((state->IRQ_count & 0x000f) < 114)   // always true, but we only update the IRQ once per scanlines so we cannot be more precise :(
16321632         {
1633            cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
1633            cpu_set_input_line(state->maincpu, M6502_IRQ_LINE, HOLD_LINE);
16341634            state->IRQ_count = (state->IRQ_count & ~0x000f) | (0x0f - (114 & 0x0f) + (state->IRQ_count & 0x000f)); // sort of wrap around the counter
16351635         }
16361636         // decrements should not affect upper bits, so we don't do anything here (114 > 0x0f)
r7957r7958
16391639      {
16401640         if ((state->IRQ_count & 0x00ff) < 114)
16411641         {
1642            cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
1642            cpu_set_input_line(state->maincpu, M6502_IRQ_LINE, HOLD_LINE);
16431643            state->IRQ_count = (state->IRQ_count & ~0x00ff) | (0xff - 114 + (state->IRQ_count & 0x00ff));   // wrap around the 8 bits counter
16441644         }
16451645         else
r7957r7958
16491649      {
16501650         if ((state->IRQ_count & 0x0fff)  < 114)
16511651         {
1652            cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
1652            cpu_set_input_line(state->maincpu, M6502_IRQ_LINE, HOLD_LINE);
16531653            state->IRQ_count = (state->IRQ_count & ~0x0fff) | (0xfff - 114 + (state->IRQ_count & 0x0fff));   // wrap around the 12 bits counter
16541654         }
16551655         else
r7957r7958
16571657      }
16581658      else if (state->IRQ_count < 114)
16591659      {
1660         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
1660         cpu_set_input_line(state->maincpu, M6502_IRQ_LINE, HOLD_LINE);
16611661         state->IRQ_count = (0xffff - 114 + state->IRQ_count);    // wrap around the 16 bits counter
16621662      }
16631663      else
r7957r7958
17741774   {
17751775      if (state->IRQ_count >= (0x7fff - 114))
17761776      {
1777         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
1777         cpu_set_input_line(state->maincpu, M6502_IRQ_LINE, HOLD_LINE);
17781778         state->IRQ_count = 0;
17791779      }
17801780      else
r7957r7958
18841884   nes_state *state = (nes_state *)device->machine->driver_data;
18851885
18861886   if (state->IRQ_enable_latch)
1887      cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
1887      cpu_set_input_line(state->maincpu, M6502_IRQ_LINE, HOLD_LINE);
18881888
18891889   if (state->IRQ_enable)
18901890   {
18911891      if (state->IRQ_count <= 114)
18921892      {
1893         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
1893         cpu_set_input_line(state->maincpu, M6502_IRQ_LINE, HOLD_LINE);
18941894         state->IRQ_enable = 0;
18951895         state->fds_status0 |= 0x01;
18961896      }
r7957r7958
20312031   {
20322032      state->IRQ_count = state->IRQ_count_latch;
20332033      state->IRQ_enable = state->IRQ_enable_latch;
2034      cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
2034      cpu_set_input_line(state->maincpu, M6502_IRQ_LINE, HOLD_LINE);
20352035   }
20362036}
20372037
r7957r7958
28502850      {
28512851         LOG_MMC(("irq fired, scanline: %d (MAME %d, beam pos: %d)\n", scanline,
28522852               video_screen_get_vpos(device->machine->primary_screen), video_screen_get_hpos(device->machine->primary_screen)));
2853         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
2853         cpu_set_input_line(state->maincpu, M6502_IRQ_LINE, HOLD_LINE);
28542854         state->IRQ_enable = 0;
28552855      }
28562856   }
r7957r7958
30083008      {
30093009         state->IRQ_count = (state->IRQ_count + 1) & 0xfff;
30103010         state->IRQ_enable = 0;
3011         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
3011         cpu_set_input_line(state->maincpu, M6502_IRQ_LINE, HOLD_LINE);
30123012      }
30133013      else
30143014         state->IRQ_count += 114;
r7957r7958
30763076
30773077*************************************************************/
30783078
3079extern emu_timer   *nes_irq_timer;
3080
30813079static WRITE8_HANDLER( mapper42_w )
30823080{
30833081   nes_state *state = (nes_state *)space->machine->driver_data;
r7957r7958
30983096         if (!state->IRQ_enable && (data & 0x02))
30993097         {
31003098            state->IRQ_enable = 1;
3101            timer_adjust_oneshot(nes_irq_timer, cputag_clocks_to_attotime(space->machine, "maincpu", 24576), 0);
3099            timer_adjust_oneshot(state->irq_timer, cpu_clocks_to_attotime(state->maincpu, 24576), 0);
31023100         }
31033101         if (!(data & 0x02))
31043102         {
31053103            state->IRQ_enable = 0;
3106            timer_adjust_oneshot(nes_irq_timer, attotime_never, 0);
3104            timer_adjust_oneshot(state->irq_timer, attotime_never, 0);
31073105         }
31083106         break;
31093107      }
r7957r7958
34363434      if (state->IRQ_count < 0x1000)
34373435      {
34383436         if ((0x1000 - state->IRQ_count) <= 114)
3439            cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
3437            cpu_set_input_line(state->maincpu, M6502_IRQ_LINE, HOLD_LINE);
34403438         else
34413439            state->IRQ_count += 114;
34423440      }
r7957r7958
38073805               {
38083806                  LOG_MMC(("irq fired, scanline: %d (MAME %d, beam pos: %d)\n", scanline,
38093807                        video_screen_get_vpos(device->machine->primary_screen), video_screen_get_hpos(device->machine->primary_screen)));
3810                  cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
3808                  cpu_set_input_line(state->maincpu, M6502_IRQ_LINE, HOLD_LINE);
38113809               }
38123810            }
38133811         }
r7957r7958
38343832            {
38353833               LOG_MMC(("irq fired, scanline: %d (MAME %d, beam pos: %d)\n", scanline,
38363834                     video_screen_get_vpos(device->machine->primary_screen), video_screen_get_hpos(device->machine->primary_screen)));
3837               cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
3835               cpu_set_input_line(state->maincpu, M6502_IRQ_LINE, HOLD_LINE);
38383836            }
38393837         }
38403838      }
r7957r7958
39803978      if (state->IRQ_count <= 114)
39813979      {
39823980         state->IRQ_enable = 0;
3983         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
3981         cpu_set_input_line(state->maincpu, M6502_IRQ_LINE, HOLD_LINE);
39843982      }
39853983   }
39863984}
r7957r7958
40864084      {
40874085         state->IRQ_enable = 0;
40884086         state->IRQ_count = 0xffff;
4089         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
4087         cpu_set_input_line(state->maincpu, M6502_IRQ_LINE, HOLD_LINE);
40904088      }
40914089      else
40924090         state->IRQ_count -= 114;
r7957r7958
42604258      if (state->IRQ_count <= 114)
42614259      {
42624260         state->IRQ_count = 0xffff;
4263         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
4261         cpu_set_input_line(state->maincpu, M6502_IRQ_LINE, HOLD_LINE);
42644262      }
42654263      else
42664264         state->IRQ_count -= 114;
r7957r7958
55405538   {
55415539      if ((0xffff - state->IRQ_count) < 114)
55425540      {
5543         cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
5541         cpu_set_input_line(state->maincpu, M6502_IRQ_LINE, HOLD_LINE);
55445542         state->IRQ_enable = 0;
55455543      }
55465544
r7957r7958
59405938      {
59415939         state->IRQ_count--;
59425940         if (!state->IRQ_count)
5943            cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
5941            cpu_set_input_line(state->maincpu, M6502_IRQ_LINE, HOLD_LINE);
59445942      }
59455943   }
59465944}
r7957r7958
97469744      state->IRQ_count = 0;
97479745      LOG_MMC(("irq fired, scanline: %d (MAME %d, beam pos: %d)\n", scanline,
97489746            video_screen_get_vpos(device->machine->primary_screen), video_screen_get_hpos(device->machine->primary_screen)));
9749      cputag_set_input_line(device->machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE);
9747      cpu_set_input_line(state->maincpu, M6502_IRQ_LINE, HOLD_LINE);
97509748   }
97519749}
97529750
src/mess/drivers/nes.c
r7957r7958
234234   MDRV_CARTSLOT_ADD("cart")
235235   MDRV_CARTSLOT_EXTENSION_LIST("nes,unf")
236236   MDRV_CARTSLOT_MANDATORY
237//   MDRV_CARTSLOT_INTERFACE("nes_cart")
237238   MDRV_CARTSLOT_LOAD(nes_cart)
238239   MDRV_CARTSLOT_PARTIALHASH(nes_partialhash)
240//   MDRV_SOFTWARE_LIST_ADD("nes")
239241MACHINE_DRIVER_END
240242
241243static MACHINE_DRIVER_START( nespal )

Previous 15994 Revisions Next


© 1998-2018 The MESS Team