Previous 15994 Revisions Next

r5326 Friday 31st July, 2009 at 09:35:40 UTC by Fabio Priuli
Added Heretical_One's latest patch (and sync'ed MAME files)

Also, made error logging more precise when the image header is missing
[src/mame/drivers]cham24.c multigam.c playch10.c vsnes.c
[src/mame/includes]playch10.h vsnes.h
[src/mame/machine]playch10.c vsnes.c
[src/mame/video]ppu2c0x.c
[src/mess/machine]nes.c

src/mame/machine/playch10.c
r5325r5326
33#include "machine/rp5h01.h"
44#include "includes/playch10.h"
55
6/* prototypes */
7void pc10_set_mirroring( int mirroring );
8WRITE8_HANDLER( pc10_nt_w );
9READ8_HANDLER( pc10_nt_r );
10WRITE8_HANDLER( pc10_chr_w );
11READ8_HANDLER( pc10_chr_r );
12void pc10_set_videorom_bank( running_machine *machine, int first, int count, int bank, int size );
13void set_videoram_bank( running_machine *machine, int first, int count, int bank, int size );
14
15typedef struct
16{
17   int writable;   // 1 for RAM, 0 for ROM
18   UINT8* chr;      // direct access to the memory
19} chr_bank;
20
21
622/* Globals */
723int pc10_sdcs;         /* ShareD Chip Select */
824int pc10_dispmask;      /* Display Mask */
r5325r5326
2137
2238static int MMC2_bank[4], MMC2_bank_latch[2];
2339
40static UINT8* vrom;            // used for games with cart gfx loaded (a,c,e,f,g,h)
41static UINT8* vram = NULL;      // used for boards h, b, d, i, k (Presumably, 8K. 16K didn't work in MESS)
42static UINT8* nametable[4];      // For non-mirroring boards, this can be moved to a direct mapping
43static UINT8* nt_ram = NULL;   // Per-board size! Some boards clearly need 4K. Some MAY use 2K. Research needed.
44static chr_bank chr_page[8];   // Simple wrapper for ROM/RAM, since we could be banking either (Hboard)
45
2446/*************************************
2547 *
2648 *  Init machine
2749 *
2850 *************************************/
51
2952MACHINE_RESET( pc10 )
3053{
31   const device_config *ppu = devtag_get_device(machine, "ppu");
3254   const device_config *rp5h01 = devtag_get_device(machine, "rp5h01");
3355
3456   /* initialize latches and flip-flops */
r5325r5326
5173   rp5h01_reset_w(rp5h01, 0, 1);
5274   rp5h01_enable_w(rp5h01, 0, 1);
5375
54   ppu2c0x_set_mirroring( ppu, mirroring );
76   pc10_set_mirroring(mirroring);
5577}
5678
79MACHINE_START( pc10 )
80{
81   vrom = memory_region(machine, "gfx2");
82
83   /* allocate 4K of nametable ram here */
84   /* move to individual boards as documentation of actual boards allows */
85   nt_ram = auto_alloc_array(machine, UINT8, 0x1000);
86
87   memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0, 0x1fff, 0, 0, pc10_chr_r, pc10_chr_w);
88   memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0x2000, 0x3eff, 0, 0, pc10_nt_r, pc10_nt_w);
89
90   if (NULL != vram)
91      set_videoram_bank(machine, 0, 8, 0, 8);
92   else pc10_set_videorom_bank(machine, 0, 8, 0, 8);
93
94}
95
96MACHINE_START( playch10_hboard )
97{
98   vrom = memory_region(machine, "gfx2");
99
100   /* allocate 4K of nametable ram here */
101   /* move to individual boards as documentation of actual boards allows */
102   nt_ram = auto_alloc_array(machine, UINT8, 0x1000);
103   /* allocate vram */
104
105   vram = auto_alloc_array(machine, UINT8, 0x2000);
106
107   memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0, 0x1fff, 0, 0, pc10_chr_r, pc10_chr_w);
108   memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0x2000, 0x3eff, 0, 0, pc10_nt_r, pc10_nt_w);
109}
110
57111/*************************************
58112 *
59113 *  BIOS ports handling
r5325r5326
103157
104158WRITE8_HANDLER( pc10_GAMERES_w )
105159{
106   cputag_set_input_line(space->machine, "cart", INPUT_LINE_RESET, ( data & 1 ) ? CLEAR_LINE : ASSERT_LINE );
160   cputag_set_input_line(space->machine, "cart", INPUT_LINE_RESET, (data & 1) ? CLEAR_LINE : ASSERT_LINE );
107161}
108162
109163WRITE8_HANDLER( pc10_GAMESTOP_w )
110164{
111   cputag_set_input_line(space->machine, "cart", INPUT_LINE_HALT, ( data & 1 ) ? CLEAR_LINE : ASSERT_LINE );
165   cputag_set_input_line(space->machine, "cart", INPUT_LINE_HALT, (data & 1) ? CLEAR_LINE : ASSERT_LINE );
112166}
113167
114168WRITE8_HANDLER( pc10_PPURES_w )
115169{
116   if ( data & 1 )
170   if (data & 1)
117171      devtag_reset(space->machine, "ppu");
118172}
119173
r5325r5326
126180
127181WRITE8_HANDLER( pc10_CARTSEL_w )
128182{
129   cart_sel &= ~( 1 << offset );
130   cart_sel |= ( data & 1 ) << offset;
183   cart_sel &= ~(1 << offset);
184   cart_sel |= (data & 1) << offset;
131185}
132186
133187
r5325r5326
136190 *  RP5H01 handling
137191 *
138192 *************************************/
193
139194READ8_HANDLER( pc10_prot_r )
140195{
141196   const device_config *rp5h01 = devtag_get_device(space->machine, "rp5h01");
r5325r5326
179234 *  Input Ports
180235 *
181236 *************************************/
237
182238WRITE8_HANDLER( pc10_in0_w )
183239{
184240   /* Toggling bit 0 high then low resets both controllers */
185   if ( data & 1 )
241   if (data & 1)
186242      return;
187243
188244   /* load up the latches */
r5325r5326
190246   input_latch[1] = input_port_read(space->machine, "P2");
191247
192248   /* apply any masking from the BIOS */
193   if ( cntrl_mask )
249   if (cntrl_mask)
194250   {
195251      /* mask out select and start */
196252      input_latch[0] &= ~0x0c;
r5325r5326
199255
200256READ8_HANDLER( pc10_in0_r )
201257{
202   int ret = ( input_latch[0] ) & 1;
258   int ret = (input_latch[0]) & 1;
203259
204260   /* shift */
205261   input_latch[0] >>= 1;
r5325r5326
213269
214270READ8_HANDLER( pc10_in1_r )
215271{
216   int ret = ( input_latch[1] ) & 1;
272   int ret = (input_latch[1]) & 1;
217273
218274   /* shift */
219275   input_latch[1] >>= 1;
220276
221277   /* do the gun thing */
222   if ( pc10_gun_controller )
278   if (pc10_gun_controller)
223279   {
224280      const device_config *ppu = devtag_get_device(space->machine, "ppu");
225281      int trigger = input_port_read(space->machine, "P1");
r5325r5326
231287      ret |= 0x08;
232288
233289      /* get the pixel at the gun position */
234      pix = ppu2c0x_get_pixel( ppu, x, y );
290      pix = ppu2c0x_get_pixel(ppu, x, y);
235291
236292      /* get the color base from the ppu */
237      color_base = ppu2c0x_get_colorbase( ppu );
293      color_base = ppu2c0x_get_colorbase(ppu);
238294
239295      /* look at the screen and see if the cursor is over a bright pixel */
240      if ( ( pix == color_base+0x20 ) || ( pix == color_base+0x30 ) ||
241          ( pix == color_base+0x33 ) || ( pix == color_base+0x34 ) )
296      if ((pix == color_base + 0x20) || (pix == color_base + 0x30) ||
297         (pix == color_base + 0x33) || (pix == color_base + 0x34))
242298      {
243299         ret &= ~0x08; /* sprite hit */
244300      }
245301
246302      /* now, add the trigger if not masked */
247      if ( !cntrl_mask )
303      if (!cntrl_mask)
248304      {
249         ret |= ( trigger & 2 ) << 3;
305         ret |= (trigger & 2) << 3;
250306      }
251307   }
252308
r5325r5326
256312
257313   return ret;
258314}
315/*************************************
316 *
317 *  PPU External bus handlers
318 *
319 *************************************/
259320
321WRITE8_HANDLER( pc10_nt_w )
322{
323   int page = ((offset & 0xc00) >> 10);
324   nametable[page][offset & 0x3ff] = data;
325}
260326
327READ8_HANDLER( pc10_nt_r )
328{
329   int page = ((offset & 0xc00) >> 10);
330   return nametable[page][offset & 0x3ff];
331}
332
333WRITE8_HANDLER( pc10_chr_w )
334{
335   int bank = offset >> 10;
336   if (chr_page[bank].writable)
337   {
338      chr_page[bank].chr[offset & 0x3ff] = data;
339   }
340}
341
342READ8_HANDLER( pc10_chr_r )
343{
344   int bank = offset >> 10;
345   return chr_page[bank].chr[offset & 0x3ff];
346}
347
348
349void pc10_set_mirroring( int mirroring )
350{
351   switch (mirroring)
352   {
353   case PPU_MIRROR_LOW:
354      nametable[0] = nametable[1] = nametable[2] = nametable[3] = nt_ram;
355      break;
356   case PPU_MIRROR_HIGH:
357      nametable[0] = nametable[1] = nametable[2] = nametable[3] = nt_ram + 0x400;
358      break;
359   case PPU_MIRROR_HORZ:
360      nametable[0] = nt_ram;
361      nametable[1] = nt_ram;
362      nametable[2] = nt_ram + 0x400;
363      nametable[3] = nt_ram + 0x400;
364      break;
365   case PPU_MIRROR_VERT:
366      nametable[0] = nt_ram;
367      nametable[1] = nt_ram + 0x400;
368      nametable[2] = nt_ram;
369      nametable[3] = nt_ram + 0x400;
370      break;
371   case PPU_MIRROR_NONE:
372   default:
373      nametable[0] = nt_ram;
374      nametable[1] = nt_ram + 0x400;
375      nametable[2] = nt_ram + 0x800;
376      nametable[3] = nt_ram + 0xc00;
377      break;
378   }
379}
380
381/* SIZE MAPPINGS *\
382 * old       new *
383 * 512         8 *
384 * 256         4 *
385 * 128         2 *
386 *  64         1 *
387\*****************/
388
389void pc10_set_videorom_bank( running_machine *machine, int first, int count, int bank, int size )
390{
391   int i, len;
392   /* first = first bank to map */
393   /* count = number of 1K banks to map */
394   /* bank = index of the bank */
395   /* size = size of indexed banks (in KB) */
396   /* note that this follows the original PPU banking and might be overly complex */
397
398   /* yeah, this is probably a horrible assumption to make.*/
399   /* but the driver is 100% consistant */
400   
401   len = memory_region_length(machine, "gfx2");
402   len /= 0x400;   // convert to KB
403   len /= size;   // convert to bank resolution
404   len--;         // convert to mask
405   bank &= len;   // should be the right mask
406   
407   for (i = 0; i < count; i++)
408   {
409      chr_page[i + first].writable = 0;
410      chr_page[i + first].chr=vrom + (i * 0x400) + (bank * size * 0x400);
411   }
412}
413
414void set_videoram_bank( running_machine *machine, int first, int count, int bank, int size )
415{
416   int i;
417   /* first = first bank to map */
418   /* count = number of 1K banks to map */
419   /* bank = index of the bank */
420   /* size = size of indexed banks (in KB) */
421   /* note that this follows the original PPU banking and might be overly complex */
422
423   /* assumes 8K of vram */
424   /* need 8K to fill address space */
425   /* only pinbot (8k) banks at all */
426     
427   for (i = 0; i < count; i++)
428   {
429      chr_page[i + first].writable = 1;
430      chr_page[i + first].chr = vram + (((i * 0x400) + (bank * size * 0x400)) & 0x1fff);
431   }
432}
433
261434/*************************************
262435 *
263436 *  Common init for all games
264437 *
265438 *************************************/
439
266440DRIVER_INIT( playch10 )
267441{
442   vram = NULL;
443
268444   /* set the controller to default */
269445   pc10_gun_controller = 0;
270446
r5325r5326
285461   /* common init */
286462   DRIVER_INIT_CALL(playch10);
287463
464   /* we have no vram, make sure switching games doesn't point to an old allocation */
465   vram = NULL;
466
288467   /* set the control type */
289468   pc10_gun_controller = 1;
290469}
r5325r5326
312491   /* basically, a MMC1 mapper from the nes */
313492   static int size16k, switchlow, vrom4k;
314493
315   int reg = ( offset >> 13 );
494   int reg = (offset >> 13);
316495
317496   /* reset mapper */
318   if ( data & 0x80 )
497   if (data & 0x80)
319498   {
320499      mmc1_shiftreg = mmc1_shiftcount = 0;
321500
r5325r5326
327506   }
328507
329508   /* see if we need to clock in data */
330   if ( mmc1_shiftcount < 5 )
509   if (mmc1_shiftcount < 5)
331510   {
332511      mmc1_shiftreg >>= 1;
333      mmc1_shiftreg |= ( data & 1 ) << 4;
512      mmc1_shiftreg |= (data & 1) << 4;
334513      mmc1_shiftcount++;
335514   }
336515
337516   /* are we done shifting? */
338   if ( mmc1_shiftcount == 5 )
517   if (mmc1_shiftcount == 5)
339518   {
340      const device_config *ppu = devtag_get_device(space->machine, "ppu");
341
342519      /* reset count */
343520      mmc1_shiftcount = 0;
344521
345522      /* apply data to registers */
346      switch( reg )
523      switch (reg)
347524      {
348525         case 0:      /* mirroring and options */
349526            {
r5325r5326
353530               size16k = mmc1_shiftreg & 0x08;
354531               switchlow = mmc1_shiftreg & 0x04;
355532
356               switch( mmc1_shiftreg & 3 )
533               switch (mmc1_shiftreg & 3)
357534               {
358535                  case 0:
359536                     _mirroring = PPU_MIRROR_LOW;
r5325r5326
374551               }
375552
376553               /* apply mirroring */
377               ppu2c0x_set_mirroring( ppu, _mirroring );
554               pc10_set_mirroring(_mirroring);
378555            }
379556         break;
380557
381558         case 1:   /* video rom banking - bank 0 - 4k or 8k */
382            ppu2c0x_set_videorom_bank( ppu, 0, ( vrom4k ) ? 4 : 8, ( mmc1_shiftreg & 0x1f ), 256 );
559            pc10_set_videorom_bank(space->machine, 0, (vrom4k) ? 4 : 8, (mmc1_shiftreg & 0x1f), 4);
383560         break;
384561
385562         case 2: /* video rom banking - bank 1 - 4k only */
386            if ( vrom4k )
387               ppu2c0x_set_videorom_bank( ppu, 4, 4, ( mmc1_shiftreg & 0x1f ), 256 );
563            if (vrom4k)
564               pc10_set_videorom_bank(space->machine, 4, 4, (mmc1_shiftreg & 0x1f), 4);
388565         break;
389566
390567         case 3:   /* program banking */
391568            {
392               int bank = ( mmc1_shiftreg & mmc1_rom_mask ) * 0x4000;
393               UINT8 *prg = memory_region( space->machine, "cart" );
569               int bank = (mmc1_shiftreg & mmc1_rom_mask) * 0x4000;
570               UINT8 *prg = memory_region(space->machine, "cart");
394571
395               if ( !size16k )
572               if (!size16k)
396573               {
397574                  /* switch 32k */
398                  memcpy( &prg[0x08000], &prg[0x010000+bank], 0x8000 );
575                  memcpy(&prg[0x08000], &prg[0x010000 + bank], 0x8000);
399576               }
400577               else
401578               {
402579                  /* switch 16k */
403                  if ( switchlow )
580                  if (switchlow)
404581                  {
405582                     /* low */
406                     memcpy( &prg[0x08000], &prg[0x010000+bank], 0x4000 );
583                     memcpy(&prg[0x08000], &prg[0x010000 + bank], 0x4000);
407584                  }
408585                  else
409586                  {
410587                     /* high */
411                     memcpy( &prg[0x0c000], &prg[0x010000+bank], 0x4000 );
588                     memcpy(&prg[0x0c000], &prg[0x010000 + bank], 0x4000);
412589                  }
413590               }
414591            }
r5325r5326
418595}
419596
420597/**********************************************************************************/
421
422598/* A Board games (Track & Field, Gradius) */
423599
424600static WRITE8_HANDLER( aboard_vrom_switch_w )
425601{
426   const device_config *ppu = devtag_get_device(space->machine, "ppu");
427   ppu2c0x_set_videorom_bank( ppu, 0, 8, ( data & 3 ), 512 );
602   pc10_set_videorom_bank(space->machine, 0, 8, (data & 3), 8);
428603}
429604
430605DRIVER_INIT( pcaboard )
r5325r5326
437612
438613   /* set the mirroring here */
439614   mirroring = PPU_MIRROR_VERT;
615
616   /* we have no vram, make sure switching games doesn't point to an old allocation */
617   vram = NULL;
440618}
441619
442620/**********************************************************************************/
443
444621/* B Board games (Contra, Rush N' Attach, Pro Wrestling) */
445622
446623static WRITE8_HANDLER( bboard_rom_switch_w )
447624{
448   int bankoffset = 0x10000 + ( ( data & 7 ) * 0x4000 );
449   UINT8 *prg = memory_region( space->machine, "cart" );
625   int bankoffset = 0x10000 + ((data & 7) * 0x4000);
626   UINT8 *prg = memory_region(space->machine, "cart");
450627
451   memcpy( &prg[0x08000], &prg[bankoffset], 0x4000 );
628   memcpy(&prg[0x08000], &prg[bankoffset], 0x4000);
452629}
453630
454631DRIVER_INIT( pcbboard )
455632{
456   UINT8 *prg = memory_region( machine, "cart" );
633   UINT8 *prg = memory_region(machine, "cart");
457634
458635   /* We do manual banking, in case the code falls through */
459636   /* Copy the initial banks */
460   memcpy( &prg[0x08000], &prg[0x28000], 0x8000 );
637   memcpy(&prg[0x08000], &prg[0x28000], 0x8000);
461638
462639   /* Roms are banked at $8000 to $bfff */
463640   memory_install_write8_handler(cputag_get_address_space(machine, "cart", ADDRESS_SPACE_PROGRAM), 0x8000, 0xffff, 0, 0, bboard_rom_switch_w );
r5325r5326
465642   /* common init */
466643   DRIVER_INIT_CALL(playch10);
467644
645   /* allocate vram */
646   vram = auto_alloc_array(machine, UINT8, 0x2000);
647
468648   /* set the mirroring here */
469649   mirroring = PPU_MIRROR_VERT;
650   /* special init */
651   set_videoram_bank(machine, 0, 8, 0, 8);
470652}
471653
472654/**********************************************************************************/
473
474655/* C Board games (The Goonies) */
475656
476657static WRITE8_HANDLER( cboard_vrom_switch_w )
477658{
478   const device_config *ppu = devtag_get_device(space->machine, "ppu");
479   ppu2c0x_set_videorom_bank( ppu, 0, 8, ( ( data >> 1 ) & 1 ), 512 );
659   pc10_set_videorom_bank(space->machine, 0, 8, ((data >> 1) & 1), 8);
480660}
481661
482662DRIVER_INIT( pccboard )
r5325r5326
484664   /* switches vrom with writes to $6000 */
485665   memory_install_write8_handler(cputag_get_address_space(machine, "cart", ADDRESS_SPACE_PROGRAM), 0x6000, 0x6000, 0, 0, cboard_vrom_switch_w );
486666
667   /* we have no vram, make sure switching games doesn't point to an old allocation */
668   vram = NULL;
669
487670   /* common init */
488671   DRIVER_INIT_CALL(playch10);
489672}
490673
491674/**********************************************************************************/
492
493675/* D Board games (Rad Racer) */
494676
495677DRIVER_INIT( pcdboard )
496678{
497   UINT8 *prg = memory_region( machine, "cart" );
679   UINT8 *prg = memory_region(machine, "cart");
498680
499681   /* We do manual banking, in case the code falls through */
500682   /* Copy the initial banks */
501   memcpy( &prg[0x08000], &prg[0x28000], 0x8000 );
683   memcpy(&prg[0x08000], &prg[0x28000], 0x8000);
502684
503685   mmc1_rom_mask = 0x07;
504686
505687   /* MMC mapper at writes to $8000-$ffff */
506688   memory_install_write8_handler(cputag_get_address_space(machine, "cart", ADDRESS_SPACE_PROGRAM), 0x8000, 0xffff, 0, 0, mmc1_rom_switch_w );
507689
690
508691   /* common init */
509692   DRIVER_INIT_CALL(playch10);
693   /* allocate vram */
694   vram = auto_alloc_array(machine, UINT8, 0x2000);
695   /* special init */
696   set_videoram_bank(machine, 0, 8, 0, 8);
510697}
511698
512699/* D Board games with extra ram (Metroid) */
r5325r5326
519706
520707   /* common init */
521708   DRIVER_INIT_CALL(pcdboard);
709
710   /* allocate vram */
711   vram = auto_alloc_array(machine, UINT8, 0x2000);
712   /* special init */
713   set_videoram_bank(machine, 0, 8, 0, 8);
522714}
523715
524716/**********************************************************************************/
525
526717/* E Board games (Mike Tyson's Punchout) - BROKEN - FIX ME */
527718
528719/* callback for the ppu_latch */
529720static void mapper9_latch( const device_config *ppu, offs_t offset )
530721{
531722
532   if( (offset & 0x1ff0) == 0x0fd0 && MMC2_bank_latch[0] != 0xfd )
723   if((offset & 0x1ff0) == 0x0fd0 && MMC2_bank_latch[0] != 0xfd)
533724   {
534725      MMC2_bank_latch[0] = 0xfd;
535      ppu2c0x_set_videorom_bank( ppu, 0, 4, MMC2_bank[0], 256 );
726      pc10_set_videorom_bank(ppu->space[0]->machine, 0, 4, MMC2_bank[0], 4);
536727   }
537   else if( (offset & 0x1ff0) == 0x0fe0 && MMC2_bank_latch[0] != 0xfe )
728   else if((offset & 0x1ff0) == 0x0fe0 && MMC2_bank_latch[0] != 0xfe)
538729   {
539730      MMC2_bank_latch[0] = 0xfe;
540      ppu2c0x_set_videorom_bank( ppu, 0, 4, MMC2_bank[1], 256 );
731      pc10_set_videorom_bank(ppu->space[0]->machine, 0, 4, MMC2_bank[1], 4);
541732   }
542   else if( (offset & 0x1ff0) == 0x1fd0 && MMC2_bank_latch[1] != 0xfd )
733   else if((offset & 0x1ff0) == 0x1fd0 && MMC2_bank_latch[1] != 0xfd)
543734   {
544735      MMC2_bank_latch[1] = 0xfd;
545      ppu2c0x_set_videorom_bank( ppu, 4, 4, MMC2_bank[2], 256 );
736      pc10_set_videorom_bank(ppu->space[0]->machine, 4, 4, MMC2_bank[2], 4);
546737   }
547   else if( (offset & 0x1ff0) == 0x1fe0 && MMC2_bank_latch[1] != 0xfe )
738   else if((offset & 0x1ff0) == 0x1fe0 && MMC2_bank_latch[1] != 0xfe)
548739   {
549740      MMC2_bank_latch[1] = 0xfe;
550      ppu2c0x_set_videorom_bank( ppu, 4, 4, MMC2_bank[3], 256 );
741      pc10_set_videorom_bank(ppu->space[0]->machine, 4, 4, MMC2_bank[3], 4);
551742   }
552743}
553744
554745static WRITE8_HANDLER( eboard_rom_switch_w )
555746{
556   const device_config *ppu = devtag_get_device(space->machine, "ppu");
557
558747   /* a variation of mapper 9 on a nes */
559   switch( offset & 0x7000 )
748   switch (offset & 0x7000)
560749   {
561750      case 0x2000: /* code bank switching */
562751         {
563            int bankoffset = 0x10000 + ( data & 0x0f ) * 0x2000;
564            UINT8 *prg = memory_region( space->machine, "cart" );
565            memcpy( &prg[0x08000], &prg[bankoffset], 0x2000 );
752            int bankoffset = 0x10000 + (data & 0x0f) * 0x2000;
753            UINT8 *prg = memory_region(space->machine, "cart");
754            memcpy(&prg[0x08000], &prg[bankoffset], 0x2000);
566755         }
567756      break;
568757
569758      case 0x3000: /* gfx bank 0 - 4k */
570759         MMC2_bank[0] = data;
571         if( MMC2_bank_latch[0] == 0xfd )
572            ppu2c0x_set_videorom_bank( ppu, 0, 4, data, 256 );
760         if (MMC2_bank_latch[0] == 0xfd)
761            pc10_set_videorom_bank(space->machine, 0, 4, data, 4);
573762      break;
574763
575764      case 0x4000: /* gfx bank 0 - 4k */
576765         MMC2_bank[1] = data;
577         if( MMC2_bank_latch[0] == 0xfe )
578            ppu2c0x_set_videorom_bank( ppu, 0, 4, data, 256 );
766         if (MMC2_bank_latch[0] == 0xfe)
767            pc10_set_videorom_bank(space->machine, 0, 4, data, 4);
579768      break;
580769
581770      case 0x5000: /* gfx bank 1 - 4k */
582771         MMC2_bank[2] = data;
583         if( MMC2_bank_latch[1] == 0xfd )
584            ppu2c0x_set_videorom_bank( ppu, 4, 4, data, 256 );
772         if (MMC2_bank_latch[1] == 0xfd)
773            pc10_set_videorom_bank(space->machine, 4, 4, data, 4);
585774      break;
586775
587776      case 0x6000: /* gfx bank 1 - 4k */
588777         MMC2_bank[3] = data;
589         if( MMC2_bank_latch[1] == 0xfe )
590            ppu2c0x_set_videorom_bank( ppu, 4, 4, data, 256 );
778         if (MMC2_bank_latch[1] == 0xfe)
779            pc10_set_videorom_bank(space->machine, 4, 4, data, 4);
591780      break;
592781
593782      case 0x7000: /* mirroring */
594         ppu2c0x_set_mirroring( ppu, data ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT );
783         pc10_set_mirroring(data ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
595784
596785      break;
597786   }
r5325r5326
599788
600789DRIVER_INIT( pceboard )
601790{
602   UINT8 *prg = memory_region( machine, "cart" );
791   UINT8 *prg = memory_region(machine, "cart");
603792
793   /* we have no vram, make sure switching games doesn't point to an old allocation */
794   vram = NULL;
795
604796   /* We do manual banking, in case the code falls through */
605797   /* Copy the initial banks */
606   memcpy( &prg[0x08000], &prg[0x28000], 0x8000 );
798   memcpy(&prg[0x08000], &prg[0x28000], 0x8000);
607799
608800   /* basically a mapper 9 on a nes */
609801   memory_install_write8_handler(cputag_get_address_space(machine, "cart", ADDRESS_SPACE_PROGRAM), 0x8000, 0xffff, 0, 0, eboard_rom_switch_w );
r5325r5326
620812}
621813
622814/**********************************************************************************/
623
624815/* F Board games (Ninja Gaiden, Double Dragon) */
625816
626817DRIVER_INIT( pcfboard )
627818{
628   UINT8 *prg = memory_region( machine, "cart" );
819   UINT8 *prg = memory_region(machine, "cart");
629820
821   /* we have no vram, make sure switching games doesn't point to an old allocation */
822   vram = NULL;
823
630824   /* We do manual banking, in case the code falls through */
631825   /* Copy the initial banks */
632   memcpy( &prg[0x08000], &prg[0x28000], 0x8000 );
826   memcpy(&prg[0x08000], &prg[0x28000], 0x8000);
633827
634828   mmc1_rom_mask = 0x07;
635829
r5325r5326
648842   memory_install_readwrite8_handler(cputag_get_address_space(machine, "cart", ADDRESS_SPACE_PROGRAM), 0x6000, 0x6fff, 0, 0, (read8_space_func)SMH_BANK(1), (write8_space_func)SMH_BANK(1) );
649843   memory_set_bankptr(machine, 1, auto_alloc_array(machine, UINT8, 0x1000));
650844
845   vram = NULL;
846
651847   /* common init */
652848   DRIVER_INIT_CALL(pcfboard);
653849}
654850
655851/**********************************************************************************/
656
657852/* G Board games (Super Mario Bros. 3) */
658853
659854static int gboard_scanline_counter;
r5325r5326
665860
666861static void gboard_scanline_cb( const device_config *device, int scanline, int vblank, int blanked )
667862{
668   if ( !vblank && !blanked )
863   if (!vblank && !blanked)
669864   {
670      if ( --gboard_scanline_counter == -1 )
865      if (--gboard_scanline_counter == -1)
671866      {
672867         gboard_scanline_counter = gboard_scanline_latch;
673868         generic_pulse_irq_line(cputag_get_cpu(device->machine, "cart"), 0);
r5325r5326
681876
682877   /* basically, a MMC3 mapper from the nes */
683878
684   switch( offset & 0x7001 )
879   switch (offset & 0x7001)
685880   {
686881      case 0x0000:
687882         gboard_command = data;
688883
689         if ( gboard_last_bank != ( data & 0xc0 ) )
884         if (gboard_last_bank != (data & 0xc0))
690885         {
691886            int bank;
692            UINT8 *prg = memory_region( space->machine, "cart" );
887            UINT8 *prg = memory_region(space->machine, "cart");
693888
694889            /* reset the banks */
695            if ( gboard_command & 0x40 )
890            if (gboard_command & 0x40)
696891            {
697892               /* high bank */
698893               bank = gboard_banks[0] * 0x2000 + 0x10000;
699894
700               memcpy( &prg[0x0c000], &prg[bank], 0x2000 );
701               memcpy( &prg[0x08000], &prg[0x4c000], 0x2000 );
895               memcpy(&prg[0x0c000], &prg[bank], 0x2000);
896               memcpy(&prg[0x08000], &prg[0x4c000], 0x2000);
702897            }
703898            else
704899            {
705900               /* low bank */
706901               bank = gboard_banks[0] * 0x2000 + 0x10000;
707902
708               memcpy( &prg[0x08000], &prg[bank], 0x2000 );
709               memcpy( &prg[0x0c000], &prg[0x4c000], 0x2000 );
903               memcpy(&prg[0x08000], &prg[bank], 0x2000);
904               memcpy(&prg[0x0c000], &prg[0x4c000], 0x2000);
710905            }
711906
712907            /* mid bank */
713908            bank = gboard_banks[1] * 0x2000 + 0x10000;
714            memcpy( &prg[0x0a000], &prg[bank], 0x2000 );
909            memcpy(&prg[0x0a000], &prg[bank], 0x2000);
715910
716911            gboard_last_bank = data & 0xc0;
717912         }
r5325r5326
720915      case 0x0001:
721916         {
722917            UINT8 cmd = gboard_command & 0x07;
723            int page = ( gboard_command & 0x80 ) >> 5;
918            int page = (gboard_command & 0x80) >> 5;
724919            int bank;
725920
726            switch( cmd )
921            switch (cmd)
727922            {
728923               case 0:   /* char banking */
729924               case 1: /* char banking */
730925                  data &= 0xfe;
731                  page ^= ( cmd << 1 );
732                  ppu2c0x_set_videorom_bank( ppu, page, 2, data, 64 );
926                  page ^= (cmd << 1);
927                  pc10_set_videorom_bank(space->machine, page, 2, data, 1);
733928               break;
734929
735930               case 2: /* char banking */
r5325r5326
737932               case 4: /* char banking */
738933               case 5: /* char banking */
739934                  page ^= cmd + 2;
740                  ppu2c0x_set_videorom_bank( ppu, page, 1, data, 64 );
935                  pc10_set_videorom_bank(space->machine, page, 1, data, 1);
741936               break;
742937
743938               case 6: /* program banking */
744939               {
745                  UINT8 *prg = memory_region( space->machine, "cart" );
746                  if ( gboard_command & 0x40 )
940                  UINT8 *prg = memory_region(space->machine, "cart");
941                  if (gboard_command & 0x40)
747942                  {
748943                     /* high bank */
749944                     gboard_banks[0] = data & 0x1f;
750                     bank = ( gboard_banks[0] ) * 0x2000 + 0x10000;
945                     bank = (gboard_banks[0]) * 0x2000 + 0x10000;
751946
752                     memcpy( &prg[0x0c000], &prg[bank], 0x2000 );
753                     memcpy( &prg[0x08000], &prg[0x4c000], 0x2000 );
947                     memcpy(&prg[0x0c000], &prg[bank], 0x2000);
948                     memcpy(&prg[0x08000], &prg[0x4c000], 0x2000);
754949                  }
755950                  else
756951                  {
757952                     /* low bank */
758953                     gboard_banks[0] = data & 0x1f;
759                     bank = ( gboard_banks[0] ) * 0x2000 + 0x10000;
954                     bank = (gboard_banks[0]) * 0x2000 + 0x10000;
760955
761                     memcpy( &prg[0x08000], &prg[bank], 0x2000 );
762                     memcpy( &prg[0x0c000], &prg[0x4c000], 0x2000 );
956                     memcpy(&prg[0x08000], &prg[bank], 0x2000);
957                     memcpy(&prg[0x0c000], &prg[0x4c000], 0x2000);
763958                  }
764959               }
765960               break;
r5325r5326
767962               case 7: /* program banking */
768963                  {
769964                     /* mid bank */
770                     UINT8 *prg = memory_region( space->machine, "cart" );
965                     UINT8 *prg = memory_region(space->machine, "cart");
771966                     gboard_banks[1] = data & 0x1f;
772967                     bank = gboard_banks[1] * 0x2000 + 0x10000;
773968
774                     memcpy( &prg[0x0a000], &prg[bank], 0x2000 );
969                     memcpy(&prg[0x0a000], &prg[bank], 0x2000);
775970                  }
776971               break;
777972            }
r5325r5326
779974      break;
780975
781976      case 0x2000: /* mirroring */
782         if( !gboard_4screen )
977         if (!gboard_4screen)
783978         {
784            if ( data & 0x40 )
785               ppu2c0x_set_mirroring( ppu, PPU_MIRROR_HIGH );
979            if (data & 0x40)
980               pc10_set_mirroring(PPU_MIRROR_HIGH);
786981            else
787               ppu2c0x_set_mirroring( ppu, ( data & 1 ) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT );
982               pc10_set_mirroring((data & 1) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
788983         }
789984      break;
790985
r5325r5326
801996      break;
802997
803998      case 0x6000: /* disable irqs */
804         ppu2c0x_set_scanline_callback( ppu, 0 );
999         ppu2c0x_set_scanline_callback(ppu, 0);
8051000      break;
8061001
8071002      case 0x6001: /* enable irqs */
808         ppu2c0x_set_scanline_callback( ppu, gboard_scanline_cb );
1003         ppu2c0x_set_scanline_callback(ppu, gboard_scanline_cb);
8091004      break;
8101005   }
8111006}
8121007
8131008DRIVER_INIT( pcgboard )
8141009{
815   UINT8 *prg = memory_region( machine, "cart" );
1010   UINT8 *prg = memory_region(machine, "cart");
1011   vram = NULL;
8161012
8171013   /* We do manual banking, in case the code falls through */
8181014   /* Copy the initial banks */
819   memcpy( &prg[0x08000], &prg[0x4c000], 0x4000 );
820   memcpy( &prg[0x0c000], &prg[0x4c000], 0x4000 );
1015   memcpy(&prg[0x08000], &prg[0x4c000], 0x4000);
1016   memcpy(&prg[0x0c000], &prg[0x4c000], 0x4000);
8211017
8221018   /* MMC3 mapper at writes to $8000-$ffff */
8231019   memory_install_write8_handler(cputag_get_address_space(machine, "cart", ADDRESS_SPACE_PROGRAM), 0x8000, 0xffff, 0, 0, gboard_rom_switch_w );
r5325r5326
8381034
8391035DRIVER_INIT( pcgboard_type2 )
8401036{
1037   vram = NULL;
8411038   /* common init */
8421039   DRIVER_INIT_CALL(pcgboard);
8431040
r5325r5326
8461043}
8471044
8481045/**********************************************************************************/
849
8501046/* i Board games (Captain Sky Hawk, Solar Jetman) */
8511047
8521048static WRITE8_HANDLER( iboard_rom_switch_w )
8531049{
8541050   int bank = data & 7;
855   const device_config *ppu = devtag_get_device(space->machine, "ppu");
856   UINT8 *prg = memory_region( space->machine, "cart" );
1051   UINT8 *prg = memory_region(space->machine, "cart");
8571052
858   if ( data & 0x10 )
859      ppu2c0x_set_mirroring( ppu, PPU_MIRROR_HIGH );
1053   if (data & 0x10)
1054      pc10_set_mirroring(PPU_MIRROR_HIGH);
8601055   else
861      ppu2c0x_set_mirroring( ppu, PPU_MIRROR_LOW );
1056      pc10_set_mirroring(PPU_MIRROR_LOW);
8621057
863   memcpy( &prg[0x08000], &prg[bank * 0x8000 + 0x10000], 0x8000 );
1058   memcpy(&prg[0x08000], &prg[bank * 0x8000 + 0x10000], 0x8000);
8641059}
8651060
8661061DRIVER_INIT( pciboard )
8671062{
868   UINT8 *prg = memory_region( machine, "cart" );
1063   UINT8 *prg = memory_region(machine, "cart");
8691064
8701065   /* We do manual banking, in case the code falls through */
8711066   /* Copy the initial banks */
872   memcpy( &prg[0x08000], &prg[0x10000], 0x8000 );
1067   memcpy(&prg[0x08000], &prg[0x10000], 0x8000);
8731068
8741069   /* Roms are banked at $8000 to $bfff */
8751070   memory_install_write8_handler(cputag_get_address_space(machine, "cart", ADDRESS_SPACE_PROGRAM), 0x8000, 0xffff, 0, 0, iboard_rom_switch_w );
8761071
8771072   /* common init */
8781073   DRIVER_INIT_CALL(playch10);
1074
1075   /* allocate vram */
1076   vram = auto_alloc_array(machine, UINT8, 0x2000);
1077   /* special init */
1078   set_videoram_bank(machine, 0, 8, 0, 8);
8791079}
8801080
8811081/**********************************************************************************/
882
8831082/* H Board games (PinBot) */
8841083
8851084static WRITE8_HANDLER( hboard_rom_switch_w )
8861085{
887   const device_config *ppu = devtag_get_device(space->machine, "ppu");
888
889   switch( offset & 0x7001 )
1086   switch (offset & 0x7001)
8901087   {
8911088      case 0x0001:
8921089         {
8931090            UINT8 cmd = gboard_command & 0x07;
894            int page = ( gboard_command & 0x80 ) >> 5;
1091            int page = (gboard_command & 0x80) >> 5;
8951092
896            switch( cmd )
1093            switch (cmd)
8971094            {
8981095               case 0:   /* char banking */
8991096               case 1: /* char banking */
9001097                  data &= 0xfe;
901                  page ^= ( cmd << 1 );
902                  if ( data & 0x20 )
1098                  page ^= (cmd << 1);
1099                  if (data & 0x40)
9031100                  {
904                     ppu2c0x_set_videoram_bank( ppu, page, 2, data, 64 );
1101                     set_videoram_bank(space->machine, page, 2, data, 1);
9051102                  }
9061103                  else
9071104                  {
908                     ppu2c0x_set_videorom_bank( ppu, page, 2, data, 64 );
1105                     pc10_set_videorom_bank(space->machine, page, 2, data, 1);
9091106                  }
9101107               return;
9111108
r5325r5326
9141111               case 4: /* char banking */
9151112               case 5: /* char banking */
9161113                  page ^= cmd + 2;
917                  if ( data & 0x40 )
1114                  if (data & 0x40)
9181115                  {
919                     ppu2c0x_set_videoram_bank( ppu, page, 1, data, 64 );
1116                     set_videoram_bank(space->machine, page, 1, data, 1);
9201117                  }
9211118                  else
9221119                  {
923                     ppu2c0x_set_videorom_bank( ppu, page, 1, data, 64 );
1120                     pc10_set_videorom_bank(space->machine, page, 1, data, 1);
9241121                  }
9251122               return;
9261123            }
r5325r5326
9321129
9331130DRIVER_INIT( pchboard )
9341131{
935   UINT8 *prg = memory_region( machine, "cart" );
936   memcpy( &prg[0x08000], &prg[0x4c000], 0x4000 );
937   memcpy( &prg[0x0c000], &prg[0x4c000], 0x4000 );
1132   UINT8 *prg = memory_region(machine, "cart");
1133   memcpy(&prg[0x08000], &prg[0x4c000], 0x4000);
1134   memcpy(&prg[0x0c000], &prg[0x4c000], 0x4000);
9381135
9391136   /* Roms are banked at $8000 to $bfff */
9401137   memory_install_write8_handler(cputag_get_address_space(machine, "cart", ADDRESS_SPACE_PROGRAM), 0x8000, 0xffff, 0, 0, hboard_rom_switch_w );
r5325r5326
9551152}
9561153
9571154/**********************************************************************************/
958
9591155/* K Board games (Mario Open Golf) */
9601156
9611157DRIVER_INIT( pckboard )
9621158{
963   UINT8 *prg = memory_region( machine, "cart" );
1159   UINT8 *prg = memory_region(machine, "cart");
9641160
9651161   /* We do manual banking, in case the code falls through */
9661162   /* Copy the initial banks */
967   memcpy( &prg[0x08000], &prg[0x48000], 0x8000 );
1163   memcpy(&prg[0x08000], &prg[0x48000], 0x8000);
9681164
9691165   mmc1_rom_mask = 0x0f;
9701166
r5325r5326
9771173
9781174   /* common init */
9791175   DRIVER_INIT_CALL(playch10);
1176
1177   /* allocate vram */
1178   vram = auto_alloc_array(machine, UINT8, 0x2000);
1179   /* special init */
1180   set_videoram_bank(machine, 0, 8, 0, 8);
9801181}
src/mame/machine/vsnes.c
r5325r5326
2222static int sound_fix=0;
2323static UINT8 last_bank;
2424
25/* PPU notes */
26/* nametable is, per Lord Nightmare, always 4K per PPU */
27/* The vsnes system has relatively few banking options for CHR */
28/* Each driver will use ROM or RAM for CHR, never both, and RAM is never banked */
29/* This leads to the memory system being an optimal place to perform banking */
30
31/* need double pointers for vsdual */
32static UINT8* vram = NULL;
33static UINT8* vrom[2];
34static UINT8* nt_ram[2];
35static UINT8* nt_page[2][4]; // because mirroring is used.
36
37/* Prototypes for mapping board components to PPU bus */
38WRITE8_HANDLER( vsnes_nt0_w );
39WRITE8_HANDLER( vsnes_nt1_w );
40READ8_HANDLER( vsnes_nt0_r );
41READ8_HANDLER( vsnes_nt1_r );
42void v_set_videorom_bank( running_machine* machine, int start, int count, int bank, int bank_size_in_kb );
43
2544/*************************************
2645 *
2746 *  Color Mapping
r5325r5326
92111   /* this is the protection. color codes are shuffled around */
93112   /* the ones with value 0xff are unknown */
94113
95   if ( addr >= 0x3f00 )
114   if (addr >= 0x3f00)
96115   {
97      int newdata = remapped_colortable[ data & 0x3f ];
116      int newdata = remapped_colortable[data & 0x3f];
98117
99      if ( newdata != 0xff )
118      if (newdata != 0xff)
100119         data = newdata;
101120
102121      #ifdef MAME_DEBUG
103122      else
104         popmessage( "Unmatched color %02x, at address %04x", data & 0x3f, addr );
123         popmessage("Unmatched color %02x, at address %04x", data & 0x3f, addr);
105124      #endif
106125   }
107126
r5325r5326
113132 *  Input Ports
114133 *
115134 *************************************/
135
116136WRITE8_HANDLER( vsnes_in0_w )
117137{
118138   /* Toggling bit 0 high then low resets both controllers */
119   if ( data & 1 )
139   if (data & 1)
120140   {
121141      /* load up the latches */
122142      input_latch[0] = input_port_read(space->machine, "IN0");
r5325r5326
126146
127147static READ8_HANDLER( gun_in0_r )
128148{
129   int ret = ( input_latch[0] ) & 1;
149   int ret = (input_latch[0]) & 1;
130150
131151   /* shift */
132152   input_latch[0] >>= 1;
133153
134154   ret |= input_port_read(space->machine, "COINS");             /* merge coins, etc */
135   ret |= ( input_port_read(space->machine, "DSW0") & 3 ) << 3; /* merge 2 dipswitches */
155   ret |= (input_port_read(space->machine, "DSW0") & 3) << 3;      /* merge 2 dipswitches */
136156
137157/* The gun games expect a 1 returned on every 5th read after sound_fix is reset*/
138158/* Info Supplied by Ben Parnell <xodnizel@home.com> of FCE Ultra fame */
r5325r5326
148168
149169}
150170
151
152171READ8_HANDLER( vsnes_in0_r )
153172{
154173
155   int ret = ( input_latch[0] ) & 1;
174   int ret = (input_latch[0]) & 1;
156175
157176   /* shift */
158177   input_latch[0] >>= 1;
159178
160179   ret |= input_port_read(space->machine, "COINS");             /* merge coins, etc */
161   ret |= ( input_port_read(space->machine, "DSW0") & 3 ) << 3;   /* merge 2 dipswitches */
180   ret |= (input_port_read(space->machine, "DSW0") & 3) << 3;      /* merge 2 dipswitches */
162181
163182   return ret;
164183
165184}
166185
167
168186READ8_HANDLER( vsnes_in1_r )
169187{
170   int ret = ( input_latch[1] ) & 1;
188   int ret = (input_latch[1]) & 1;
171189
172190   ret |= input_port_read(space->machine, "DSW0") & ~3;         /* merge the rest of the dipswitches */
173191
r5325r5326
180198WRITE8_HANDLER( vsnes_in0_1_w )
181199{
182200   /* Toggling bit 0 high then low resets both controllers */
183   if ( data & 1 )
201   if (data & 1)
184202   {
185203      /* load up the latches */
186204      input_latch[2] = input_port_read(space->machine, "IN2");
r5325r5326
190208
191209READ8_HANDLER( vsnes_in0_1_r )
192210{
193   int ret = ( input_latch[2] ) & 1;
211   int ret = (input_latch[2]) & 1;
194212
195213   /* shift */
196214   input_latch[2] >>= 1;
197215
198216   ret |= input_port_read(space->machine, "COINS2");             /* merge coins, etc */
199   ret |= ( input_port_read(space->machine, "DSW1") & 3 ) << 3;   /* merge 2 dipswitches */
217   ret |= (input_port_read(space->machine, "DSW1") & 3) << 3;      /* merge 2 dipswitches */
200218   return ret;
201219}
202220
203221READ8_HANDLER( vsnes_in1_1_r )
204222{
205   int ret = ( input_latch[3] ) & 1;
223   int ret = (input_latch[3]) & 1;
206224
207225   ret |= input_port_read(space->machine, "DSW1") & ~3;         /* merge the rest of the dipswitches */
208226
r5325r5326
229247   input_latch[2] = input_latch[3] = 0;
230248
231249   /* if we need to remap, install the callback */
232   if ( remapped_colortable )
233      ppu2c0x_set_vidaccess_callback( ppu, remap_colors );
250   if (remapped_colortable)
251      ppu2c0x_set_vidaccess_callback(ppu, remap_colors);
234252}
235253
236254/*************************************
r5325r5326
238256 *  Init machine
239257 *
240258 *************************************/
259
241260MACHINE_RESET( vsdual )
242261{
243262   const device_config *ppu1 = devtag_get_device(machine, "ppu1");
r5325r5326
247266   input_latch[2] = input_latch[3] = 0;
248267
249268   /* if we need to remap, install the callback */
250   if ( remapped_colortable )
269   if (remapped_colortable)
251270   {
252      ppu2c0x_set_vidaccess_callback( ppu1, remap_colors );
253      ppu2c0x_set_vidaccess_callback( ppu2, remap_colors );
271      ppu2c0x_set_vidaccess_callback(ppu1, remap_colors);
272      ppu2c0x_set_vidaccess_callback(ppu2, remap_colors);
254273   }
255274}
256275
257276/*************************************
258277 *
278 *  Machine start functions
279 *
280 *************************************/
281
282MACHINE_START( vsnes )
283{
284   /* establish nametable ram */
285   nt_ram[0] = auto_alloc_array(machine, UINT8, 0x1000);
286   /* set mirroring */
287   nt_page[0][0] = nt_ram[0];
288   nt_page[0][1] = nt_ram[0] + 0x400;
289   nt_page[0][2] = nt_ram[0] + 0x800;
290   nt_page[0][3] = nt_ram[0] + 0xc00;
291
292   memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu1"), ADDRESS_SPACE_PROGRAM), 0x2000, 0x3eff, 0, 0, vsnes_nt0_r, vsnes_nt0_w);
293
294   vrom[0] = memory_region(machine, "gfx1");
295
296   /* establish chr banks */
297   /* bank 1 is used already! */
298   /* DRIVER_INIT is called first - means we can handle this different for VRAM games! */
299   if (NULL != vrom[0])
300   {
301      memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu1"), ADDRESS_SPACE_PROGRAM), 0x0000, 0x03ff, 0, 0, SMH_BANK(2), 0);
302      memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu1"), ADDRESS_SPACE_PROGRAM), 0x0400, 0x07ff, 0, 0, SMH_BANK(3), 0);
303      memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu1"), ADDRESS_SPACE_PROGRAM), 0x0800, 0x0bff, 0, 0, SMH_BANK(4), 0);
304      memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu1"), ADDRESS_SPACE_PROGRAM), 0x0c00, 0x0fff, 0, 0, SMH_BANK(5), 0);
305      memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu1"), ADDRESS_SPACE_PROGRAM), 0x1000, 0x13ff, 0, 0, SMH_BANK(6), 0);
306      memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu1"), ADDRESS_SPACE_PROGRAM), 0x1400, 0x17ff, 0, 0, SMH_BANK(7), 0);
307      memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu1"), ADDRESS_SPACE_PROGRAM), 0x1800, 0x1bff, 0, 0, SMH_BANK(8), 0);
308      memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu1"), ADDRESS_SPACE_PROGRAM), 0x1c00, 0x1fff, 0, 0, SMH_BANK(9), 0);
309      v_set_videorom_bank(machine, 0, 8, 0, 8);
310   }
311   else
312   {
313      memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu1"), ADDRESS_SPACE_PROGRAM), 0x0000, 0x1fff, 0, 0, SMH_BANK(2), SMH_BANK(2));
314      memory_set_bankptr(machine, 2, vram);
315   }
316}
317
318/*************************************
319 *
320 *  Init machine
321 *
322 *************************************/
323
324MACHINE_START( vsdual )
325{
326   vrom[0] = memory_region(machine, "gfx1");
327   vrom[1] = memory_region(machine, "gfx2");
328
329   /* establish nametable ram */
330   nt_ram[0] = auto_alloc_array(machine, UINT8, 0x1000);
331   nt_ram[1] = auto_alloc_array(machine, UINT8, 0x1000);
332   /* set mirroring */
333   nt_page[0][0] = nt_ram[0];
334   nt_page[0][1] = nt_ram[0] + 0x400;
335   nt_page[0][2] = nt_ram[0] + 0x800;
336   nt_page[0][3] = nt_ram[0] + 0xc00;
337   nt_page[1][0] = nt_ram[1];
338   nt_page[1][1] = nt_ram[1] + 0x400;
339   nt_page[1][2] = nt_ram[1] + 0x800;
340   nt_page[1][3] = nt_ram[1] + 0xc00;
341
342   memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu1"), ADDRESS_SPACE_PROGRAM), 0x2000, 0x3eff, 0, 0, vsnes_nt0_r, vsnes_nt0_w);
343   memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu2"), ADDRESS_SPACE_PROGRAM), 0x2000, 0x3eff, 0, 0, vsnes_nt1_r, vsnes_nt1_w);
344   // read only!
345   memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu1"), ADDRESS_SPACE_PROGRAM), 0x0000, 0x1fff, 0, 0, SMH_BANK(2), 0);
346   // read only!
347   memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu2"), ADDRESS_SPACE_PROGRAM), 0x0000, 0x1fff, 0, 0, SMH_BANK(3), 0);
348   memory_set_bankptr(machine, 2, vrom[0]);
349   memory_set_bankptr(machine, 3, vrom[1]);
350}
351
352/*************************************
353 *
354 *  External mappings for PPU bus
355 *
356 *************************************/
357
358WRITE8_HANDLER( vsnes_nt0_w )
359{
360   int page = ((offset & 0xc00) >> 10);
361   nt_page[0][page][offset & 0x3ff] = data;
362
363}
364
365WRITE8_HANDLER( vsnes_nt1_w )
366{
367   int page = ((offset & 0xc00) >> 10);
368   nt_page[1][page][offset & 0x3ff] = data;
369
370}
371
372READ8_HANDLER( vsnes_nt0_r )
373{
374   int page = ((offset&0xc00) >> 10);
375   return nt_page[0][page][offset & 0x3ff];
376}
377
378READ8_HANDLER( vsnes_nt1_r )
379{
380   int page = ((offset & 0xc00) >> 10);
381   return nt_page[1][page][offset & 0x3ff];
382}
383
384void v_set_mirroring( int ppu, int mirroring )
385{
386   switch (mirroring)
387   {
388   case PPU_MIRROR_LOW:
389      nt_page[ppu][0] = nt_page[ppu][1] = nt_page[ppu][2] = nt_page[ppu][3] = nt_ram[ppu];
390      break;
391   case PPU_MIRROR_HIGH:
392      nt_page[ppu][0] = nt_page[ppu][1] = nt_page[ppu][2] = nt_page[ppu][3] = nt_ram[ppu] + 0x400;
393      break;
394   case PPU_MIRROR_HORZ:
395      nt_page[ppu][0] = nt_ram[ppu];
396      nt_page[ppu][1] = nt_ram[ppu];
397      nt_page[ppu][2] = nt_ram[ppu] + 0x400;
398      nt_page[ppu][3] = nt_ram[ppu] + 0x400;
399      break;
400   case PPU_MIRROR_VERT:
401      nt_page[ppu][0] = nt_ram[ppu];
402      nt_page[ppu][1] = nt_ram[ppu] + 0x400;
403      nt_page[ppu][2] = nt_ram[ppu];
404      nt_page[ppu][3] = nt_ram[ppu] + 0x400;
405      break;
406   case PPU_MIRROR_NONE:
407   default:
408      nt_page[ppu][0] = nt_ram[ppu];
409      nt_page[ppu][1] = nt_ram[ppu] + 0x400;
410      nt_page[ppu][2] = nt_ram[ppu] + 0x800;
411      nt_page[ppu][3] = nt_ram[ppu] + 0xc00;
412      break;
413   }
414
415}
416
417void v_set_videorom_bank( running_machine* machine, int start, int count, int bank, int bank_size_in_kb )
418{
419   int i, j;
420   int offset = bank * (bank_size_in_kb * 0x400);
421   /* automatically add 2 to all start values (because the PPU is bank 2) */
422   /* bank_size_in_kb is used to determine how large the "bank" parameter is */
423   /* count determines the size of the area mapped */
424   for (i = 0; i < count; i++, offset += 0x400)
425   {
426      j = i + start + 2;
427      memory_set_bankptr(machine, j, vrom[0] + offset);
428   }
429}
430
431/*************************************
432 *
259433 *  Common init for all games
260434 *
261435 *************************************/
436
262437static void init_vsnes(running_machine *machine)
263438{
264439   /* set the controller to default */
r5325r5326
276451
277452static WRITE8_HANDLER( vsnormal_vrom_banking )
278453{
279   const device_config *ppu1 = devtag_get_device(space->machine, "ppu1");
280
281454   /* switch vrom */
282   ppu2c0x_set_videorom_bank( ppu1, 0, 8, ( data & 4 ) ? 1 : 0, 512 );
455   v_set_videorom_bank(space->machine, 0, 8, (data & 4) ? 1 : 0, 8);
283456
284457   /* bit 1 ( data & 2 ) enables writes to extra ram, we ignore it */
285458
286459   /* move along */
287   vsnes_in0_w( space, offset, data );
460   vsnes_in0_w(space, offset, data);
288461}
289462
290463/* Most games switch VROM Banks in controller 0 write */
r5325r5326
301474
302475   /* This PPU has registers mapped at $2000 and $2001 inverted */
303476   /* and no remapped color */
304   if ( offset == 0 )
477   if (offset == 0)
305478   {
306      ppu2c0x_w( ppu1, 1, data );
479      ppu2c0x_w(ppu1, 1, data);
307480      return;
308481   }
309482
310   ppu2c0x_w( ppu1, 0, data );
483   ppu2c0x_w(ppu1, 0, data);
311484}
312485
313486/**********************************************************************************/
314
315487/* Super Mario Bros. Extra ram at $6000 (NV?) and remapped colors */
316488
317489DRIVER_INIT( suprmrio )
r5325r5326
333505}
334506
335507/**********************************************************************************/
336
337508/* Gun Games - VROM Banking in controller 0 write */
338509
339510static WRITE8_HANDLER( gun_in0_w )
r5325r5326
344515   if (vsnes_do_vrom_bank)
345516   {
346517      /* switch vrom */
347      ppu2c0x_set_videorom_bank( ppu1, 0, 8, ( data & 4 ) ? 1 : 0, 512 );
518      v_set_videorom_bank(space->machine, 0, 8, (data & 4) ? 1 : 0, 8);
348519   }
349520
350521   /* here we do things a little different */
351   if ( data & 1 )
522   if (data & 1)
352523   {
353524
354525      /* load up the latches */
355526      input_latch[0] = input_port_read(space->machine, "IN0");
356527
357528      /* do the gun thing */
358      if ( vsnes_gun_controller )
529      if (vsnes_gun_controller)
359530      {
360531         int x = input_port_read(space->machine, "GUNX");
361532         int y = input_port_read(space->machine, "GUNY");
362533         UINT32 pix, color_base;
363534
364535         /* get the pixel at the gun position */
365         pix = ppu2c0x_get_pixel( ppu1, x, y );
536         pix = ppu2c0x_get_pixel(ppu1, x, y);
366537
367538         /* get the color base from the ppu */
368         color_base = ppu2c0x_get_colorbase( ppu1 );
539         color_base = ppu2c0x_get_colorbase(ppu1);
369540
370541         /* look at the screen and see if the cursor is over a bright pixel */
371         if ( ( pix == color_base+0x20 ) || ( pix == color_base+0x30 ) ||
372             ( pix == color_base+0x33 ) || ( pix == color_base+0x34 ) )
542         if ((pix == color_base + 0x20 ) || (pix == color_base + 0x30) ||
543            (pix == color_base + 0x33 ) || (pix == color_base + 0x34))
373544         {
374545            input_latch[0] |= 0x40;
375546         }
r5325r5326
378549      input_latch[1] = input_port_read(space->machine, "IN1");
379550   }
380551
381    if ( ( zapstore & 1 ) && ( !( data & 1 ) ) )
552    if ((zapstore & 1) && (!(data & 1)))
382553   /* reset sound_fix to keep sound from hanging */
383554    {
384555      sound_fix = 0;
r5325r5326
401572}
402573
403574/**********************************************************************************/
404
405575/* The Goonies, VS Gradius: ROMs bankings at $8000-$ffff */
406576
407577static WRITE8_HANDLER( goonies_rom_banking )
408578{
409   const device_config *ppu1 = devtag_get_device(space->machine, "ppu1");
410   int reg = ( offset >> 12 ) & 0x07;
411   int bankoffset = ( data & 7 ) * 0x2000 + 0x10000;
579   int reg = (offset >> 12) & 0x07;
580   int bankoffset = (data & 7) * 0x2000 + 0x10000;
412581
413   switch( reg )
582   switch (reg)
414583   {
415584      case 0: /* code bank 0 */
416585      case 2: /* code bank 1 */
417586      case 4: /* code bank 2 */
418587      {
419         UINT8 *prg = memory_region( space->machine, "maincpu" );
420         memcpy( &prg[0x08000 + reg*0x1000], &prg[bankoffset], 0x2000 );
588         UINT8 *prg = memory_region(space->machine, "maincpu");
589         memcpy(&prg[0x08000 + reg * 0x1000], &prg[bankoffset], 0x2000);
421590      }
422591      break;
423592
424593      case 6: /* vrom bank 0 */
425         ppu2c0x_set_videorom_bank( ppu1, 0, 4, data, 256 );
594         v_set_videorom_bank(space->machine, 0, 4, data, 4);
426595      break;
427596
428597      case 7: /* vrom bank 1 */
429         ppu2c0x_set_videorom_bank( ppu1, 4, 4, data, 256 );
598         v_set_videorom_bank(space->machine, 4, 4, data, 4);
430599      break;
431600   }
432601}
r5325r5326
435604{
436605   /* We do manual banking, in case the code falls through */
437606   /* Copy the initial banks */
438   UINT8 *prg = memory_region( machine, "maincpu" );
439   memcpy( &prg[0x08000], &prg[0x18000], 0x8000 );
607   UINT8 *prg = memory_region(machine, "maincpu");
608   memcpy(&prg[0x08000], &prg[0x18000], 0x8000);
440609
441610   /* banking is done with writes to the $8000-$ffff area */
442611   memory_install_write8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x8000, 0xffff, 0, 0, goonies_rom_banking );
r5325r5326
452621{
453622   /* We do manual banking, in case the code falls through */
454623   /* Copy the initial banks */
455   UINT8 *prg = memory_region( machine, "maincpu" );
456   memcpy( &prg[0x08000], &prg[0x18000], 0x8000 );
624   UINT8 *prg = memory_region(machine, "maincpu");
625   memcpy(&prg[0x08000], &prg[0x18000], 0x8000);
457626
458627   /* banking is done with writes to the $8000-$ffff area */
459628   memory_install_write8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x8000, 0xffff, 0, 0, goonies_rom_banking );
r5325r5326
496665}
497666
498667/***********************************************************************/
499
500668/* Vs. Gumshoe */
501669
502670static READ8_HANDLER( vsgshoe_security_r )
503671{
504672   /* low part must be 0x1c */
505   return ppu2c0x_r( devtag_get_device(space->machine, "ppu1"), 2 ) | 0x1c;
673   return ppu2c0x_r(devtag_get_device(space->machine, "ppu1"), 2) | 0x1c;
506674}
507675
508676static WRITE8_HANDLER( vsgshoe_gun_in0_w )
r5325r5326
511679   int addr;
512680   if((data & 0x04) != old_bank)
513681   {
514      UINT8 *prg = memory_region( space->machine, "maincpu" );
682      UINT8 *prg = memory_region(space->machine, "maincpu");
515683      old_bank = data & 0x04;
516684      addr = old_bank ? 0x12000: 0x10000;
517      memcpy (&prg[0x08000], &prg[addr], 0x2000);
685      memcpy(&prg[0x08000], &prg[addr], 0x2000);
518686   }
519687
520688   gun_in0_w(space, offset, data);
r5325r5326
523691DRIVER_INIT( vsgshoe )
524692{
525693   /* set up the default bank */
526   UINT8 *prg = memory_region( machine, "maincpu" );
694   UINT8 *prg = memory_region(machine, "maincpu");
527695   memcpy (&prg[0x08000], &prg[0x12000], 0x2000);
528696
529697   /* Protection */
r5325r5326
541709}
542710
543711/**********************************************************************************/
544
545712/* Dr Mario: ROMs bankings at $8000-$ffff */
546713
547714static int drmario_shiftreg;
r5325r5326
549716
550717static WRITE8_HANDLER( drmario_rom_banking )
551718{
552   const device_config *ppu1 = devtag_get_device(space->machine, "ppu1");
553
554719   /* basically, a MMC1 mapper from the nes */
555720   static int size16k, switchlow, vrom4k;
556721
557   int reg = ( offset >> 13 );
722   int reg = (offset >> 13);
558723
559724   /* reset mapper */
560   if ( data & 0x80 )
725   if (data & 0x80)
561726   {
562727      drmario_shiftreg = drmario_shiftcount = 0;
563728
r5325r5326
570735   }
571736
572737   /* see if we need to clock in data */
573   if ( drmario_shiftcount < 5 )
738   if (drmario_shiftcount < 5)
574739   {
575740      drmario_shiftreg >>= 1;
576      drmario_shiftreg |= ( data & 1 ) << 4;
741      drmario_shiftreg |= (data & 1) << 4;
577742      drmario_shiftcount++;
578743   }
579744
580745   /* are we done shifting? */
581   if ( drmario_shiftcount == 5 )
746   if (drmario_shiftcount == 5)
582747   {
583748      /* reset count */
584749      drmario_shiftcount = 0;
585750
586751      /* apply data to registers */
587      switch( reg )
752      switch (reg)
588753      {
589754         case 0:      /* mirroring and options */
590755            {
r5325r5326
594759               size16k = drmario_shiftreg & 0x08;
595760               switchlow = drmario_shiftreg & 0x04;
596761
597               switch( drmario_shiftreg & 3 )
762               switch (drmario_shiftreg & 3)
598763               {
599764                  case 0:
600765                     mirroring = PPU_MIRROR_LOW;
r5325r5326
615780               }
616781
617782               /* apply mirroring */
618               ppu2c0x_set_mirroring( ppu1, mirroring );
783               v_set_mirroring(1, mirroring);
619784            }
620785         break;
621786
622787         case 1:   /* video rom banking - bank 0 - 4k or 8k */
623            ppu2c0x_set_videorom_bank( ppu1, 0, ( vrom4k ) ? 4 : 8, drmario_shiftreg, ( vrom4k ) ? 256 : 512 );
788            v_set_videorom_bank(space->machine, 0, (vrom4k) ? 4 : 8, drmario_shiftreg, (vrom4k) ? 4 : 8);
624789         break;
625790
626791         case 2: /* video rom banking - bank 1 - 4k only */
627            if ( vrom4k )
628               ppu2c0x_set_videorom_bank( ppu1, 4, 4, drmario_shiftreg, 256 );
792            if (vrom4k)
793               v_set_videorom_bank(space->machine, 4, 4, drmario_shiftreg, 4);
629794         break;
630795
631796         case 3:   /* program banking */
632797            {
633               int bank = ( drmario_shiftreg & 0x03 ) * 0x4000;
634               UINT8 *prg = memory_region( space->machine, "maincpu" );
798               int bank = (drmario_shiftreg & 0x03) * 0x4000;
799               UINT8 *prg = memory_region(space->machine, "maincpu");
635800
636               if ( !size16k )
801               if (!size16k)
637802               {
638803                  /* switch 32k */
639                  memcpy( &prg[0x08000], &prg[0x010000+bank], 0x8000 );
804                  memcpy(&prg[0x08000], &prg[0x010000 + bank], 0x8000);
640805               }
641806               else
642807               {
643808                  /* switch 16k */
644                  if ( switchlow )
809                  if (switchlow)
645810                  {
646811                     /* low */
647                     memcpy( &prg[0x08000], &prg[0x010000+bank], 0x4000 );
812                     memcpy(&prg[0x08000], &prg[0x010000 + bank], 0x4000);
648813                  }
649814                  else
650815                  {
651816                     /* high */
652                     memcpy( &prg[0x0c000], &prg[0x010000+bank], 0x4000 );
817                     memcpy(&prg[0x0c000], &prg[0x010000 + bank], 0x4000);
653818                  }
654819               }
655820            }
r5325r5326
664829{
665830   /* We do manual banking, in case the code falls through */
666831   /* Copy the initial banks */
667   UINT8 *prg = memory_region( machine, "maincpu" );
668   memcpy( &prg[0x08000], &prg[0x10000], 0x4000 );
669   memcpy( &prg[0x0c000], &prg[0x1c000], 0x4000 );
832   UINT8 *prg = memory_region(machine, "maincpu");
833   memcpy(&prg[0x08000], &prg[0x10000], 0x4000);
834   memcpy(&prg[0x0c000], &prg[0x1c000], 0x4000);
670835
671836   /* MMC1 mapper at writes to $8000-$ffff */
672837   memory_install_write8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x8000, 0xffff, 0, 0, drmario_rom_banking );
r5325r5326
682847}
683848
684849/***********************************************************************/
685
686850/* Excite Bike */
687851
688852DRIVER_INIT( excitebk )
r5325r5326
714878}
715879
716880/**********************************************************************************/
717
718881/* Mach Rider */
719882
720883DRIVER_INIT( machridr )
r5325r5326
733896}
734897
735898/**********************************************************************************/
736
737899/* VS Slalom */
738900
739901DRIVER_INIT( vsslalom )
r5325r5326
748910}
749911
750912/**********************************************************************************/
751
752913/* Castelvania: ROMs bankings at $8000-$ffff */
753914
754915static WRITE8_HANDLER( castlevania_rom_banking )
755916{
756   int rombank = 0x10000 + ( data & 7 ) * 0x4000;
757   UINT8 *prg = memory_region( space->machine, "maincpu" );
917   int rombank = 0x10000 + (data & 7) * 0x4000;
918   UINT8 *prg = memory_region(space->machine, "maincpu");
758919
759   memcpy( &prg[0x08000], &prg[rombank], 0x4000 );
920   memcpy(&prg[0x08000], &prg[rombank], 0x4000);
760921}
761922
762923DRIVER_INIT( cstlevna )
763924{
764925   /* when starting the game, the 1st 16k and the last 16k are loaded into the 2 banks */
765   UINT8 *prg = memory_region( machine, "maincpu" );
766   memcpy( &prg[0x08000], &prg[0x28000], 0x8000 );
926   UINT8 *prg = memory_region(machine, "maincpu");
927   memcpy(&prg[0x08000], &prg[0x28000], 0x8000);
767928
768929      /* banking is done with writes to the $8000-$ffff area */
769930   memory_install_write8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x8000, 0xffff, 0, 0, castlevania_rom_banking );
r5325r5326
775936   /* we need to remap color tables */
776937   /* this *is* the VS games protection, I guess */
777938   remapped_colortable = rp2c04002_colortable;
939
940   /* allocate vram */
941   vram = auto_alloc_array(machine, UINT8, 0x2000);
778942}
779943
780944/**********************************************************************************/
781
782945/* VS Top Gun: ROMs bankings at $8000-$ffff, plus some protection */
783946
784947static READ8_HANDLER( topgun_security_r )
785948{
786949   /* low part must be 0x1b */
787   return ppu2c0x_r( devtag_get_device(space->machine, "ppu1"), 2 ) | 0x1b;
950   return ppu2c0x_r(devtag_get_device(space->machine, "ppu1"), 2) | 0x1b;
788951}
789952
790953DRIVER_INIT( topgun )
791954{
792955   /* when starting the game, the 1st 16k and the last 16k are loaded into the 2 banks */
793   UINT8 *prg = memory_region( machine, "maincpu" );
794   memcpy( &prg[0x08000], &prg[0x28000], 0x8000 );
956   UINT8 *prg = memory_region(machine, "maincpu");
957   memcpy(&prg[0x08000], &prg[0x28000], 0x8000);
795958
796959      /* banking is done with writes to the $8000-$ffff area */
797960   memory_install_write8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x8000, 0xffff, 0, 0, castlevania_rom_banking );
r5325r5326
802965
803966   /* common init */
804967   init_vsnes(machine);
968
969   /* allocate vram */
970   vram = auto_alloc_array(machine, UINT8, 0x2000);
971
805972}
806973
807974/**********************************************************************************/
r5325r5326
813980
814981static void mapper4_set_prg (const address_space *space)
815982{
816   UINT8 *prg = memory_region( space->machine, "maincpu" );
983   UINT8 *prg = memory_region(space->machine, "maincpu");
817984   MMC3_prg0 &= MMC3_prg_mask;
818985   MMC3_prg1 &= MMC3_prg_mask;
819986
820987   if (MMC3_cmd & 0x40)
821988   {
822      memcpy( &prg[0x8000], &prg[(MMC3_prg_chunks-1) * 0x4000 + 0x10000], 0x2000 );
823      memcpy( &prg[0xc000], &prg[0x2000 * (MMC3_prg0) + 0x10000], 0x2000 );
989      memcpy(&prg[0x8000], &prg[(MMC3_prg_chunks - 1) * 0x4000 + 0x10000], 0x2000);
990      memcpy(&prg[0xc000], &prg[0x2000 * (MMC3_prg0) + 0x10000], 0x2000);
824991   }
825992   else
826993   {
827      memcpy( &prg[0x8000], &prg[0x2000 * (MMC3_prg0) + 0x10000], 0x2000 );
828      memcpy( &prg[0xc000], &prg[(MMC3_prg_chunks-1) * 0x4000 + 0x10000], 0x2000 );
994      memcpy(&prg[0x8000], &prg[0x2000 * (MMC3_prg0) + 0x10000], 0x2000);
995      memcpy(&prg[0xc000], &prg[(MMC3_prg_chunks - 1) * 0x4000 + 0x10000], 0x2000);
829996   }
830   memcpy( &prg[0xa000], &prg[0x2000 * (MMC3_prg1) + 0x10000], 0x2000 );
997   memcpy(&prg[0xa000], &prg[0x2000 * (MMC3_prg1) + 0x10000], 0x2000);
831998}
832999
8331000static void mapper4_set_chr (const address_space *space)
8341001{
835   const device_config *ppu1 = devtag_get_device(space->machine, "ppu1");
8361002   UINT8 chr_page = (MMC3_cmd & 0x80) >> 5;
837   ppu2c0x_set_videorom_bank(ppu1, chr_page ^ 0, 2, MMC3_chr[0], 1);
838   ppu2c0x_set_videorom_bank(ppu1, chr_page ^ 2, 2, MMC3_chr[1], 1);
839   ppu2c0x_set_videorom_bank(ppu1, chr_page ^ 4, 1, MMC3_chr[2], 1);
840   ppu2c0x_set_videorom_bank(ppu1, chr_page ^ 5, 1, MMC3_chr[3], 1);
841   ppu2c0x_set_videorom_bank(ppu1, chr_page ^ 6, 1, MMC3_chr[4], 1);
842   ppu2c0x_set_videorom_bank(ppu1, chr_page ^ 7, 1, MMC3_chr[5], 1);
1003   v_set_videorom_bank(space->machine, chr_page ^ 0, 2, MMC3_chr[0], 1);
1004   v_set_videorom_bank(space->machine, chr_page ^ 2, 2, MMC3_chr[1], 1);
1005   v_set_videorom_bank(space->machine, chr_page ^ 4, 1, MMC3_chr[2], 1);
1006   v_set_videorom_bank(space->machine, chr_page ^ 5, 1, MMC3_chr[3], 1);
1007   v_set_videorom_bank(space->machine, chr_page ^ 6, 1, MMC3_chr[4], 1);
1008   v_set_videorom_bank(space->machine, chr_page ^ 7, 1, MMC3_chr[5], 1);
8431009}
8441010
8451011#define BOTTOM_VISIBLE_SCANLINE   239      /* The bottommost visible scanline */
8461012#define NUM_SCANLINE 262
8471013
848static void mapper4_irq ( const device_config *device, int scanline, int vblank, int blanked )
1014static void mapper4_irq( const device_config *device, int scanline, int vblank, int blanked )
8491015{
850   mame_printf_debug("entra\n");
8511016   if ((scanline < BOTTOM_VISIBLE_SCANLINE) || (scanline == NUM_SCANLINE - 1))
8521017   {
8531018      if ((IRQ_enable) && !blanked)
r5325r5326
8751040         if (last_bank != (data & 0xc0))
8761041         {
8771042            /* Reset the banks */
878            mapper4_set_prg (space);
879            mapper4_set_chr (space);
1043            mapper4_set_prg(space);
1044            mapper4_set_chr(space);
8801045
8811046         }
8821047         last_bank = data & 0xc0;
r5325r5326
8891054         {
8901055            case 0: case 1:
8911056               data &= 0xfe;
892               MMC3_chr[cmd] = data * 64;
893               mapper4_set_chr (space);
1057               MMC3_chr[cmd] = data;
1058               mapper4_set_chr(space);
8941059
8951060               break;
8961061
8971062            case 2: case 3: case 4: case 5:
898               MMC3_chr[cmd] = data * 64;
899               mapper4_set_chr (space);
1063               MMC3_chr[cmd] = data;
1064               mapper4_set_chr(space);
9001065
9011066               break;
9021067
9031068            case 6:
9041069               MMC3_prg0 = data;
905               mapper4_set_prg (space);
1070               mapper4_set_prg(space);
9061071               break;
9071072
9081073            case 7:
9091074               MMC3_prg1 = data;
910               mapper4_set_prg (space);
1075               mapper4_set_prg(space);
9111076               break;
9121077         }
9131078         break;
9141079      }
9151080      case 0x2000: /* $a000 */
9161081         if (data & 0x40)
917            ppu2c0x_set_mirroring(ppu1, PPU_MIRROR_HIGH);
1082            v_set_mirroring(1, PPU_MIRROR_HIGH);
9181083         else
9191084         {
9201085            if (data & 0x01)
921               ppu2c0x_set_mirroring(ppu1, PPU_MIRROR_HORZ);
1086               v_set_mirroring(1, PPU_MIRROR_HORZ);
9221087            else
923               ppu2c0x_set_mirroring(ppu1, PPU_MIRROR_VERT);
1088               v_set_mirroring(1, PPU_MIRROR_VERT);
9241089         }
9251090         break;
9261091
r5325r5326
9631128
9641129DRIVER_INIT( MMC3 )
9651130{
966   UINT8 *prg = memory_region( machine, "maincpu" );
1131   UINT8 *prg = memory_region(machine, "maincpu");
9671132   IRQ_enable = IRQ_count = IRQ_count_latch = 0;
9681133   MMC3_prg0 = 0xfe;
9691134   MMC3_prg1 = 0xff;
r5325r5326
9731138
9741139   MMC3_prg_mask = ((MMC3_prg_chunks << 1) - 1);
9751140
976   memcpy( &prg[0x8000], &prg[(MMC3_prg_chunks-1) * 0x4000 + 0x10000], 0x2000 );
977   memcpy( &prg[0xa000], &prg[(MMC3_prg_chunks-1) * 0x4000 + 0x12000], 0x2000 );
978   memcpy( &prg[0xc000], &prg[(MMC3_prg_chunks-1) * 0x4000 + 0x10000], 0x2000 );
979   memcpy( &prg[0xe000], &prg[(MMC3_prg_chunks-1) * 0x4000 + 0x12000], 0x2000 );
1141   memcpy(&prg[0x8000], &prg[(MMC3_prg_chunks - 1) * 0x4000 + 0x10000], 0x2000);
1142   memcpy(&prg[0xa000], &prg[(MMC3_prg_chunks - 1) * 0x4000 + 0x12000], 0x2000);
1143   memcpy(&prg[0xc000], &prg[(MMC3_prg_chunks - 1) * 0x4000 + 0x10000], 0x2000);
1144   memcpy(&prg[0xe000], &prg[(MMC3_prg_chunks - 1) * 0x4000 + 0x12000], 0x2000);
9801145
9811146   /* MMC3 mapper at writes to $8000-$ffff */
9821147   memory_install_write8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x8000, 0xffff, 0, 0, mapper4_w );
r5325r5326
9911156
9921157/* Vs. RBI Baseball */
9931158
994static READ8_HANDLER( rbi_hack_r)
1159static READ8_HANDLER( rbi_hack_r )
9951160{
9961161   /* Supplied by Ben Parnell <xodnizel@home.com> of FCE Ultra fame */
9971162
r5325r5326
10401205
10411206static READ8_HANDLER( supxevs_read_prot_2_r )
10421207{
1043   if( supxevs_prot_index )
1208   if (supxevs_prot_index)
10441209      return 0;
10451210   else
10461211      return 0x01;
r5325r5326
10481213
10491214static READ8_HANDLER( supxevs_read_prot_3_r )
10501215{
1051   if( supxevs_prot_index )
1216   if (supxevs_prot_index)
10521217      return 0xd1;
10531218   else
10541219      return 0x89;
r5325r5326
10561221
10571222static READ8_HANDLER( supxevs_read_prot_4_r )
10581223{
1059   if( supxevs_prot_index )
1224   if (supxevs_prot_index)
10601225   {
10611226      supxevs_prot_index = 0;
10621227      return 0x3e;
r5325r5326
10941259      0xd4, 0x5c, 0x3e, 0x26, 0x87, 0x83, 0x13, 0x00
10951260   };
10961261
1097   if ( offset == 0 )
1262   if (offset == 0)
10981263   {
10991264      security_counter = 0;
11001265      return 0;
r5325r5326
11361301
11371302static WRITE8_HANDLER( mapper68_rom_banking )
11381303{
1139   const device_config *ppu1 = devtag_get_device(space->machine, "ppu1");
1140
11411304   switch (offset & 0x7000)
11421305   {
11431306      case 0x0000:
1144      ppu2c0x_set_videorom_bank(ppu1,0,2,data,128);
1307      v_set_videorom_bank(space->machine, 0, 2, data, 2);
11451308
11461309      break;
11471310      case 0x1000:
1148      ppu2c0x_set_videorom_bank(ppu1,2,2,data,128);
1311      v_set_videorom_bank(space->machine, 2, 2, data, 2);
11491312
11501313      break;
11511314      case 0x2000:
1152      ppu2c0x_set_videorom_bank(ppu1,4,2,data,128);
1315      v_set_videorom_bank(space->machine, 4, 2, data, 2);
11531316
11541317      break;
11551318      case 0x3000: /* ok? */
1156      ppu2c0x_set_videorom_bank(ppu1,6,2,data,128);
1319      v_set_videorom_bank(space->machine, 6, 2, data, 2);
11571320
11581321      break;
11591322
11601323      case 0x7000:
11611324      {
1162         UINT8 *prg = memory_region( space->machine, "maincpu" );
1163         memcpy( &prg[0x08000], &prg[0x10000 +data*0x4000], 0x4000 );
1325         UINT8 *prg = memory_region(space->machine, "maincpu");
1326         memcpy(&prg[0x08000], &prg[0x10000 + data * 0x4000], 0x4000);
11641327      }
11651328      break;
11661329
r5325r5326
11741337   /* when starting a mapper 68 game  the first 16K ROM bank in the cart is loaded into $8000
11751338    the LAST 16K ROM bank is loaded into $C000. The last 16K of ROM cannot be swapped. */
11761339
1177   UINT8 *prg = memory_region( machine, "maincpu" );
1178   memcpy( &prg[0x08000], &prg[0x10000], 0x4000 );
1179   memcpy( &prg[0x0c000], &prg[0x2c000], 0x4000 );
1340   UINT8 *prg = memory_region(machine, "maincpu");
1341   memcpy(&prg[0x08000], &prg[0x10000], 0x4000);
1342   memcpy(&prg[0x0c000], &prg[0x2c000], 0x4000);
11801343
11811344   memory_install_write8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x8000, 0xffff, 0, 0, mapper68_rom_banking );
11821345
r5325r5326
11901353/* Vs. Raid on Bungeling Bay (Japan) */
11911354
11921355static int ret;
1193static WRITE8_HANDLER ( set_bnglngby_irq_w )
1356static WRITE8_HANDLER( set_bnglngby_irq_w )
11941357{
11951358   ret = data;
1196   cputag_set_input_line(space->machine, "maincpu", 0, ( data & 2 ) ? ASSERT_LINE : CLEAR_LINE );
1359   cputag_set_input_line(space->machine, "maincpu", 0, (data & 2) ? ASSERT_LINE : CLEAR_LINE);
11971360   /* other values ??? */
11981361   /* 0, 4, 84 */
11991362}
12001363
1201static READ8_HANDLER ( set_bnglngby_irq_r )
1364static READ8_HANDLER( set_bnglngby_irq_r )
12021365{
12031366   return ret;
12041367}
r5325r5326
12281391static READ8_HANDLER( jajamaru_security_r )
12291392{
12301393   /* low part must be 0x40 */
1231   return ppu2c0x_r( devtag_get_device(space->machine, "ppu1"), 2 ) | 0x40;
1394   return ppu2c0x_r(devtag_get_device(space->machine, "ppu1"), 2) | 0x40;
12321395}
12331396
12341397DRIVER_INIT( jajamaru )
12351398{
1236   //It executes an illegal opcode: 0x04 at 0x9e67 and 0x9e1c
1237   //At 0x9e5d and 0x9e12 there is a conditional jump to it
1238   //Maybe it should be a DOP (double NOP)
1399   // It executes an illegal opcode: 0x04 at 0x9e67 and 0x9e1c
1400   // At 0x9e5d and 0x9e12 there is a conditional jump to it
1401   // Maybe it should be a DOP (double NOP)
12391402
12401403   /* Protection */
12411404   memory_install_read8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x2002, 0x2002, 0, 0, jajamaru_security_r );
r5325r5326
12491412}
12501413
12511414/***********************************************************************/
1252
12531415/* Vs. Mighty Bomb Jack */
12541416
12551417static READ8_HANDLER( mightybj_security_r )
12561418{
12571419   /* low part must be 0x3d */
1258   return ppu2c0x_r( devtag_get_device(space->machine, "ppu1"), 2 ) | 0x3d;
1420   return ppu2c0x_r(devtag_get_device(space->machine, "ppu1"), 2) | 0x3d;
12591421}
12601422
12611423DRIVER_INIT( mightybj )
r5325r5326
12741436static WRITE8_HANDLER( vstennis_vrom_banking )
12751437{
12761438   const device_config *other_cpu = (space->cpu == cputag_get_cpu(space->machine, "maincpu")) ? cputag_get_cpu(space->machine, "sub") : cputag_get_cpu(space->machine, "maincpu");
1277   const device_config *ppu1 = devtag_get_device(space->machine, "ppu1");
1278   const device_config *ppu2 = devtag_get_device(space->machine, "ppu2");
12791439
12801440   /* switch vrom */
1281   ppu2c0x_set_videorom_bank( (space->cpu == cputag_get_cpu(space->machine, "maincpu")) ? ppu1 : ppu2, 0, 8, ( data & 4 ) ? 1 : 0, 512 );
1441   (space->cpu == cputag_get_cpu(space->machine, "maincpu")) ? memory_set_bankptr(space->machine, 2, (data & 4) ? vrom[0] + 0x2000 : vrom[0]) : memory_set_bankptr(space->machine, 3, (data & 4) ? vrom[1] + 0x2000 : vrom[1]);
12821442
12831443   /* bit 1 ( data & 2 ) triggers irq on the other cpu */
1284   cpu_set_input_line(other_cpu, 0, ( data & 2 ) ? CLEAR_LINE : ASSERT_LINE );
1444   cpu_set_input_line(other_cpu, 0, (data & 2) ? CLEAR_LINE : ASSERT_LINE);
12851445
12861446   /* move along */
12871447   if (space->cpu == cputag_get_cpu(space->machine, "maincpu"))
1288      vsnes_in0_w( space, offset, data );
1448      vsnes_in0_w(space, offset, data);
12891449   else
1290      vsnes_in0_1_w( space, offset, data );
1450      vsnes_in0_1_w(space, offset, data);
12911451}
12921452
12931453DRIVER_INIT( vstennis )
12941454{
1295   UINT8 *prg = memory_region( machine, "maincpu" );
1455   UINT8 *prg = memory_region(machine, "maincpu");
12961456
12971457   /* vrom switching is enabled with bit 2 of $4016 */
12981458   memory_install_write8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x4016, 0x4016, 0, 0, vstennis_vrom_banking );
r5325r5326
13111471DRIVER_INIT( wrecking )
13121472{
13131473   /* only differance between this and vstennis is the colors */
1314
13151474   DRIVER_INIT_CALL(vstennis);
13161475   remapped_colortable = rp2c04002_colortable;
13171476}
r5325r5326
13221481DRIVER_INIT( balonfgt )
13231482{
13241483   /* only differance between this and vstennis is the colors */
1325
13261484   DRIVER_INIT_CALL(vstennis);
13271485
13281486   remapped_colortable = rp2c04003_colortable;
r5325r5326
13351493DRIVER_INIT( vsbball )
13361494{
13371495   /* only differance between this and vstennis is the colors */
1338
13391496   DRIVER_INIT_CALL(vstennis);
13401497
13411498   remapped_colortable = rp2c04001_colortable;
1342
13431499}
13441500
13451501
r5325r5326
13491505DRIVER_INIT( iceclmrj )
13501506{
13511507   /* only differance between this and vstennis is the colors */
1352
13531508   DRIVER_INIT_CALL(vstennis);
13541509
13551510   remapped_colortable = rp2c05004_colortable;
1356
13571511}
13581512
13591513/**********************************************************************/
13601514/* Battle City */
1515
13611516DRIVER_INIT( btlecity )
13621517{
13631518   init_vsnes(machine);
r5325r5326
13671522
13681523/***********************************************************************/
13691524/* Tetris */
1525
13701526DRIVER_INIT( vstetris )
13711527{
13721528   /* extra ram at $6000 is enabled with bit 1 of $4016 */
src/mame/includes/vsnes.h
r5325r5326
1515
1616MACHINE_RESET( vsnes );
1717MACHINE_RESET( vsdual );
18MACHINE_START( vsnes );
19MACHINE_START( vsdual );
1820DRIVER_INIT( suprmrio );
1921DRIVER_INIT( excitebk );
2022DRIVER_INIT( excitbkj );
src/mame/includes/playch10.h
r5325r5326
11/*----------- defined in machine/playch10.c -----------*/
22
33MACHINE_RESET( pc10 );
4MACHINE_START( pc10 );
5MACHINE_START( playch10_hboard );
46DRIVER_INIT( playch10 );   /* standard games */
57DRIVER_INIT( pc_gun );   /* gun games */
68DRIVER_INIT( pc_hrz );   /* horizontal games */
src/mame/video/ppu2c0x.c
r5325r5326
55    Written by Ernesto Corvi.
66    This code is heavily based on Brad Oliver's MESS implementation.
77
8******************************************************************************/
8    2009-04: Changed NES PPU to be a device (Nathan Woods)
9    2009-07: Changed NES PPU to use a device memory map (Robert Bohms)
910
10/******************************************************************************
11    Current known bugs
1112
12Current known bugs
13   General:
1314
14General:
15    * PPU timing is imprecise for updates that happen mid-scanline. Some games
16      may demand more precision.
1517
16* PPU timing is imprecise for updates that happen mid-scanline. Some games
17 may demand more precision.
18    NES-specific:
1819
19NES-specific:
20    * Micro Machines has minor rendering glitches (needs better timing).
21    * Mach Rider has minor road rendering glitches (needs better timing).
2022
21* Micro Machines has minor rendering glitches (needs better timing).
22
23* Mach Rider has minor road rendering glitches (needs better timing).
24
2523******************************************************************************/
2624
2725#include "driver.h"
r5325r5326
125123    PROTOTYPES
126124***************************************************************************/
127125
128static void update_scanline(const device_config *device);
126static void update_scanline( const device_config *device );
129127
130128static TIMER_CALLBACK( scanline_callback );
131129static TIMER_CALLBACK( hblank_callback );
r5325r5326
134132void (*ppu_latch)( const device_config *device, offs_t offset );
135133
136134/* palette handlers */
137WRITE8_HANDLER(ppu2c0x_palette_write);
138READ8_HANDLER(ppu2c0x_palette_read);
135WRITE8_HANDLER( ppu2c0x_palette_write );
136READ8_HANDLER( ppu2c0x_palette_read );
139137/* name and attribute table functions */
140WRITE8_HANDLER(ppu2c0x_name_write);
141READ8_HANDLER(ppu2c0x_name_read);
138WRITE8_HANDLER( ppu2c0x_name_write );
139READ8_HANDLER( ppu2c0x_name_read );
142140/* name and attribute table functions */
143WRITE8_HANDLER(ppu2c0x_chr_write);
144READ8_HANDLER(ppu2c0x_chr_read);
141WRITE8_HANDLER( ppu2c0x_chr_write );
142READ8_HANDLER( ppu2c0x_chr_read );
145143
146144
147145/***************************************************************************
148146    INLINE FUNCTIONS
149147***************************************************************************/
150148
151INLINE ppu2c0x_chip *get_token(const device_config *device)
149INLINE ppu2c0x_chip *get_token( const device_config *device )
152150{
153151   assert(device != NULL);
154152   assert((device->type == PPU_2C02) || (device->type == PPU_2C03B)
r5325r5326
158156}
159157
160158
161INLINE const ppu2c0x_interface *get_interface(const device_config *device)
159INLINE const ppu2c0x_interface *get_interface( const device_config *device )
162160{
163161   assert(device != NULL);
164162   assert((device->type == PPU_2C02) || (device->type == PPU_2C03B)
r5325r5326
181179/* default address map */
182180// make this INTERNAL, default should just be enough to avoid compile errors, print error messages!
183181static ADDRESS_MAP_START( ppu2c0x, 0, 8 )
184   AM_RANGE(0x3F00, 0x3fff) AM_READWRITE (ppu2c0x_palette_read, ppu2c0x_palette_write)
182   AM_RANGE(0x3f00, 0x3fff) AM_READWRITE (ppu2c0x_palette_read, ppu2c0x_palette_write)
185183ADDRESS_MAP_END
186184
187void ppu2c0x_init_palette(running_machine *machine, int first_entry )
185void ppu2c0x_init_palette( running_machine *machine, int first_entry )
188186{
189187
190188   /* This routine builds a palette using a transformation from */
r5325r5326
268266                  break;
269267            }
270268
271            u = sat * cos( rad );
272            v = sat * sin( rad );
269            u = sat * cos(rad);
270            v = sat * sin(rad);
273271
274272            /* Transform to RGB */
275            R = ( y + Kv * v ) * 255.0;
276            G = ( y - ( Kb * Ku * u + Kr * Kv * v) / (1 - Kb - Kr) ) * 255.0;
277            B = ( y + Ku * u ) * 255.0;
273            R = (y + Kv * v) * 255.0;
274            G = (y - (Kb * Ku * u + Kr * Kv * v) / (1 - Kb - Kr)) * 255.0;
275            B = (y + Ku * u) * 255.0;
278276
279277            /* Clipping, in case of saturation */
280            if ( R < 0 )
278            if (R < 0)
281279               R = 0;
282            if ( R > 255 )
280            if (R > 255)
283281               R = 255;
284            if ( G < 0 )
282            if (G < 0)
285283               G = 0;
286            if ( G > 255 )
284            if (G > 255)
287285               G = 255;
288            if ( B < 0 )
286            if (B < 0)
289287               B = 0;
290            if ( B > 255 )
288            if (B > 255)
291289               B = 255;
292290
293291            /* Round, and set the value */
294            palette_set_color_rgb(machine, first_entry++, floor(R+.5), floor(G+.5), floor(B+.5));
292            palette_set_color_rgb(machine, first_entry++, floor(R + .5), floor(G + .5), floor(B + .5));
295293         }
296294      }
297295   }
r5325r5326
302300/* the charlayout we use for the chargen */
303301static const gfx_layout ppu_charlayout =
304302{
305   8,8,   /* 8*8 characters */
303   8, 8,   /* 8*8 characters */
306304   0,
307305   2,      /* 2 bits per pixel */
308306   { 8*8, 0 },   /* the two bitplanes are separated */
r5325r5326
320318static DEVICE_START( ppu2c0x )
321319{
322320   ppu2c0x_chip *chip = get_token(device);
323   //const ppu2c0x_interface *intf = get_interface(device);
321   // const ppu2c0x_interface *intf = get_interface(device);
324322
325323   memset(chip, 0, sizeof(*chip));
326324   chip->scanlines_per_frame = (int) device_get_info_int(device, PPU2C0XINFO_INT_SCANLINES_PER_FRAME);
r5325r5326
334332
335333   /* allocate a screen bitmap, videomem and spriteram, a dirtychar array and the monochromatic colortable */
336334   chip->bitmap = auto_bitmap_alloc(device->machine, VISIBLE_SCREEN_WIDTH, VISIBLE_SCREEN_HEIGHT, video_screen_get_format(device->machine->primary_screen));
337   chip->spriteram = auto_alloc_array_clear(device->machine, UINT8, SPRITERAM_SIZE );
338   chip->colortable = auto_alloc_array(device->machine, pen_t, ARRAY_LENGTH( default_colortable ) );
339   chip->colortable_mono = auto_alloc_array(device->machine, pen_t, ARRAY_LENGTH( default_colortable_mono ) );
335   chip->spriteram = auto_alloc_array_clear(device->machine, UINT8, SPRITERAM_SIZE);
336   chip->colortable = auto_alloc_array(device->machine, pen_t, ARRAY_LENGTH(default_colortable));
337   chip->colortable_mono = auto_alloc_array(device->machine, pen_t, ARRAY_LENGTH(default_colortable_mono));
340338}
341339
342340static TIMER_CALLBACK( hblank_callback )
r5325r5326
345343   ppu2c0x_chip *this_ppu = get_token(device);
346344   int *ppu_regs = &this_ppu->regs[0];
347345
348   int blanked = ( ppu_regs[PPU_CONTROL1] & ( PPU_CONTROL1_BACKGROUND | PPU_CONTROL1_SPRITES ) ) == 0;
349   int vblank = ((this_ppu->scanline >= PPU_VBLANK_FIRST_SCANLINE-1) && (this_ppu->scanline < this_ppu->scanlines_per_frame-1)) ? 1 : 0;
346   int blanked = (ppu_regs[PPU_CONTROL1] & (PPU_CONTROL1_BACKGROUND | PPU_CONTROL1_SPRITES)) == 0;
347   int vblank = ((this_ppu->scanline >= PPU_VBLANK_FIRST_SCANLINE - 1) && (this_ppu->scanline < this_ppu->scanlines_per_frame - 1)) ? 1 : 0;
350348
351//  update_scanline (device);
349//  update_scanline(device);
352350
353351   if (this_ppu->hblank_callback_proc)
354352      (*this_ppu->hblank_callback_proc) (device, this_ppu->scanline, vblank, blanked);
r5325r5326
370368   timer_adjust_oneshot(this_ppu->nmi_timer, attotime_never, 0);
371369}
372370
373static void draw_background(const device_config *device, UINT8 *line_priority )
371static void draw_background( const device_config *device, UINT8 *line_priority )
374372{
375373   const ppu2c0x_interface *intf = get_interface(device);
376374   ppu2c0x_chip *this_ppu = get_token(device);
r5325r5326
383381   const int *nes_vram = &this_ppu->nes_vram[0];
384382   const int tile_page = this_ppu->tile_page;
385383
386   int   start_x = ( this_ppu->x_fine ^ 0x07 ) - 7;
384   int   start_x = (this_ppu->x_fine ^ 0x07) - 7;
387385   UINT16 back_pen;
388386   UINT16 *dest;
389387
r5325r5326
392390
393391   const pen_t *color_table;
394392   const pen_t *paldata;
395   //const UINT8 *sd;
393   // const UINT8 *sd;
396394
397   int tilecount=0;
395   int tilecount = 0;
398396
399397   /* setup the color mask and colortable to use */
400   if ( ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_DISPLAY_MONO )
398   if (ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_DISPLAY_MONO)
401399   {
402400      color_mask = 0xf0;
403401      color_table = this_ppu->colortable_mono;
r5325r5326
409407   }
410408
411409   /* cache the background pen */
412   back_pen = (this_ppu->back_color & color_mask)+intf->color_base;
410   back_pen = (this_ppu->back_color & color_mask) + intf->color_base;
413411
414412   /* determine where in the nametable to start drawing from */
415413   /* based on the current scanline and scroll regs */
416414   scroll_x_coarse = refresh_data & 0x1f;
417   scroll_y_coarse = ( refresh_data & 0x3e0 ) >> 5;
418   scroll_y_fine = ( refresh_data & 0x7000 ) >> 12;
415   scroll_y_coarse = (refresh_data & 0x3e0) >> 5;
416   scroll_y_fine = (refresh_data & 0x7000) >> 12;
419417
420418   x = scroll_x_coarse;
421419
422420   /* get the tile index */
423   tile_index = ( ( refresh_data & 0xc00 ) | 0x2000 ) + scroll_y_coarse * 32;
421   tile_index = ((refresh_data & 0xc00) | 0x2000) + scroll_y_coarse * 32;
424422
425423   /* set up dest */
426424   dest = ((UINT16 *) bitmap->base) + (bitmap->rowpixels * scanline) + start_x;
427425
428426   /* draw the 32 or 33 tiles that make up a line */
429   while ( tilecount <34)
427   while (tilecount < 34)
430428   {
431429      int color_byte;
432430      int color_bits;
r5325r5326
439437      index1 = tile_index + x;
440438
441439
442      //this is attribute table stuff! (actually read 2 in PPUspeak)!
440      // this is attribute table stuff! (actually read 2 in PPUspeak)!
443441      /* Figure out which byte in the color table to use */
444      pos = ( ( index1 & 0x380 ) >> 4 ) | ( ( index1 & 0x1f ) >> 2 );
442      pos = ((index1 & 0x380) >> 4) | ((index1 & 0x1f) >> 2);
445443      page = (index1 & 0x0c00) >> 10;
446444      address = 0x3c0 + pos;
447      color_byte = memory_read_byte(device->space[0], (((page*0x400)+address)&0xfff)+0x2000);
445      color_byte = memory_read_byte(device->space[0], (((page * 0x400) + address) & 0xfff) + 0x2000);
448446
449447      /* figure out which bits in the color table to use */
450      color_bits = ( ( index1 & 0x40 ) >> 4 ) + ( index1 & 0x02 );
448      color_bits = ((index1 & 0x40) >> 4) + (index1 & 0x02);
451449
452      //page2 is the output of the nametable read (this section is the FIRST read per tile!)
450      // page2 is the output of the nametable read (this section is the FIRST read per tile!)
453451      address = index1 & 0x3ff;
454452      page2 = memory_read_byte(device->space[0], index1);
455      index2 = nes_vram[ ( page2 >> 6 ) | tile_page ] + ( page2 & 0x3f );
453      index2 = nes_vram[(page2 >> 6) | tile_page] + (page2 & 0x3f);
456454
457      //27/12/2002
458      if( ppu_latch )
455      // 27/12/2002
456      if (ppu_latch)
459457      {
460         (*ppu_latch)(device, ( tile_page << 10 ) | ( page2 << 4 ));
458         (*ppu_latch)(device, (tile_page << 10) | (page2 << 4));
461459      }
462460
463      if(start_x < VISIBLE_SCREEN_WIDTH )
461      if (start_x < VISIBLE_SCREEN_WIDTH)
464462      {
465         UINT8 plane1, plane2;//use extended size so I can shift!
466         paldata = &color_table[ 4 * ( ( ( color_byte >> color_bits ) & 0x03 ) ) ];
467         //start = scroll_y_fine * line_modulo;
463         UINT8 plane1, plane2;   // use extended size so I can shift!
464         paldata = &color_table[4 * (((color_byte >> color_bits) & 0x03))];
465         // start = scroll_y_fine * line_modulo;
468466
469         //need to read 0x0000 or 0x1000 + 16*nametable data
470         address=((this_ppu->tile_page)?0x1000:0)+(page2*16);
471         //plus something that accounts for y
472         //address-=(scanline%8);
473         address+=scroll_y_fine;
467         // need to read 0x0000 or 0x1000 + 16*nametable data
468         address = ((this_ppu->tile_page) ? 0x1000 : 0) + (page2 * 16);
469         // plus something that accounts for y
470         // address -= (scanline % 8);
471         address += scroll_y_fine;
474472
475         plane1= memory_read_byte(device->space[0], (address&0x1FFF));
476         plane2= memory_read_byte(device->space[0], (address+8)&0x1FFF);
477         //plane2= plane2<<1;
473         plane1 = memory_read_byte(device->space[0], (address & 0x1fff));
474         plane2 = memory_read_byte(device->space[0], (address + 8) & 0x1fff);
475         // plane2 = plane2 << 1;
478476
479//         sd = gfx_element_get_data(device->machine->gfx[gfx_bank], index2 % total_elements) + start;
477//          sd = gfx_element_get_data(device->machine->gfx[gfx_bank], index2 % total_elements) + start;
480478
481479         /* render the pixel */
482         for( i = 0; i < 8; i++ )
480         for (i = 0; i < 8; i++)
483481         {
484482            UINT8 pix;
485            pix=((plane1>>7)&1)|(((plane2>>7)&1)<<1);
486            plane1=plane1<<1;
487            plane2=plane2<<1;
488            if ( ( start_x+i ) >= 0 && ( start_x+i ) < VISIBLE_SCREEN_WIDTH )
483            pix = ((plane1 >> 7) & 1) | (((plane2 >> 7) & 1) << 1);
484            plane1 = plane1 << 1;
485            plane2 = plane2 << 1;
486            if ((start_x + i) >= 0 && (start_x + i) < VISIBLE_SCREEN_WIDTH)
489487            {
490488               
491               if ( pix )
489               if (pix)
492490               {
493491                  pen = paldata[pix];
494                  line_priority[ start_x+i ] |= 0x02;
492                  line_priority[start_x + i] |= 0x02;
495493               }
496494               else
497495               {
r5325r5326
506504
507505         /* move to next tile over and toggle the horizontal name table if necessary */
508506         x++;
509         if ( x > 31 )
507         if (x > 31)
510508         {
511509            x = 0;
512510            tile_index ^= 0x400;
r5325r5326
516514   }
517515
518516   /* if the left 8 pixels for the background are off, blank 'em */
519   if ( !( ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_BACKGROUND_L8 ) )
517   if (!(ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_BACKGROUND_L8))
520518   {
521519      dest = ((UINT16 *) bitmap->base) + (bitmap->rowpixels * scanline);
522      for( i = 0; i < 8; i++ )
520      for (i = 0; i < 8; i++)
523521      {
524522         *(dest++) = back_pen;
525         line_priority[ i ] ^= 0x02;
523         line_priority[i] ^= 0x02;
526524      }
527525   }
528526}
529527
530static void draw_sprites(const device_config *device, UINT8 *line_priority )
528static void draw_sprites( const device_config *device, UINT8 *line_priority )
531529{
532   //const ppu2c0x_interface *intf = get_interface(device);
530   // const ppu2c0x_interface *intf = get_interface(device);
533531   ppu2c0x_chip *this_ppu = get_token(device);
534532
535533   /* cache some values locally */
r5325r5326
553551   int first_pixel;
554552
555553   const pen_t *paldata;
556   //const UINT8 *sd;
554   // const UINT8 *sd;
557555   int pixel;
558556
559557   /* determine if the sprites are 8x8 or 8x16 */
560   size = ( ppu_regs[PPU_CONTROL0] & PPU_CONTROL0_SPRITE_SIZE ) ? 16 : 8;
558   size = (ppu_regs[PPU_CONTROL0] & PPU_CONTROL0_SPRITE_SIZE) ? 16 : 8;
561559
562560   first_pixel = (ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_SPRITES_L8)? 0: 8;
563561
564   for( spriteIndex = 0; spriteIndex < SPRITERAM_SIZE; spriteIndex += 4 )
562   for (spriteIndex = 0; spriteIndex < SPRITERAM_SIZE; spriteIndex += 4)
565563   {
566564      UINT8 plane1;
567565      UINT8 plane2;
568566
569567      spriteYPos = sprite_ram[spriteIndex] + 1;
570      spriteXPos = sprite_ram[spriteIndex+3];
568      spriteXPos = sprite_ram[spriteIndex + 3];
571569
572570      // The sprite collision acts funny on the last pixel of a scanline.
573571      // The various scanline latches update while the last few pixels
r5325r5326
585583      }
586584
587585      /* if the sprite isn't visible, skip it */
588      if ( ( spriteYPos + size <= scanline ) || ( spriteYPos > scanline ) )
586      if ((spriteYPos + size <= scanline) || (spriteYPos > scanline))
589587         continue;
590588
591589      /* clear our drawn flag */
592590      drawn = 0;
593591
594      tile = sprite_ram[spriteIndex+1];
595      color = ( sprite_ram[spriteIndex+2] & 0x03 ) + 4;
596      pri = sprite_ram[spriteIndex+2] & 0x20;
597      flipx = sprite_ram[spriteIndex+2] & 0x40;
598      flipy = sprite_ram[spriteIndex+2] & 0x80;
592      tile = sprite_ram[spriteIndex + 1];
593      color = (sprite_ram[spriteIndex + 2] & 0x03) + 4;
594      pri = sprite_ram[spriteIndex + 2] & 0x20;
595      flipx = sprite_ram[spriteIndex + 2] & 0x40;
596      flipy = sprite_ram[spriteIndex + 2] & 0x80;
599597
600      if ( size == 16 )
598      if (size == 16)
601599      {
602600         /* if it's 8x16 and odd-numbered, draw the other half instead */
603         if ( tile & 0x01 )
601         if (tile & 0x01)
604602         {
605603            tile &= ~0x01;
606604            tile |= 0x100;
r5325r5326
609607         page = tile >> 6;
610608      }
611609      else
612         page = ( tile >> 6 ) | sprite_page;
610         page = (tile >> 6) | sprite_page;
613611
614612
615      //index1 = this_ppu->nes_vram[page] + ( tile & 0x3f );
613      // index1 = this_ppu->nes_vram[page] + (tile & 0x3f);
616614
617      if ( ppu_latch )
618         (*ppu_latch)(device, ( sprite_page << 10 ) | ( (tile & 0xff) << 4 ));
615      if (ppu_latch)
616         (*ppu_latch)(device, (sprite_page << 10) | ((tile & 0xff) << 4));
619617
620618      /* compute the character's line to draw */
621619      sprite_line = scanline - spriteYPos;
622620
623621     
624      if ( flipy )
625         sprite_line = ( size - 1 ) - sprite_line;
622      if (flipy)
623         sprite_line = (size - 1) - sprite_line;
626624
627625      paldata = &color_table[4 * color];
628626
629      if(size==16 && sprite_line > 7)
627      if (size == 16 && sprite_line > 7)
630628      {
631629         tile++;
632         sprite_line -=8;
630         sprite_line -= 8;
633631      }
634     
635632
636      index1=tile*16;
637      if(size==8)
638         index1+=((sprite_page==0)?0:0x1000);
633      index1 = tile * 16;
634      if (size == 8)
635         index1 += ((sprite_page == 0) ? 0 : 0x1000);
639636
640      plane1=memory_read_byte(device->space[0],(index1+sprite_line)&0x1FFF);
641      plane2=memory_read_byte(device->space[0],(index1+sprite_line+8)&0x1FFF);
637      plane1 = memory_read_byte(device->space[0], (index1 + sprite_line) & 0x1fff);
638      plane2 = memory_read_byte(device->space[0], (index1 + sprite_line + 8) & 0x1fff);
642639
643640//      sd = gfx_element_get_data(device->machine->gfx[gfx_bank], index1 % total_elements) + start;
644641//      if (size > 8)
645642//         gfx_element_get_data(device->machine->gfx[gfx_bank], (index1 + 1) % total_elements);
646643
647      if ( pri )
644      if (pri)
648645      {
649646         /* draw the low-priority sprites */
650
651         for ( pixel = 0; pixel < 8; pixel++ )
647         for (pixel = 0; pixel < 8; pixel++)
652648         {
653649//            UINT8 pixelData = flipx ? sd[7-pixel] : sd[pixel];
654650            UINT8 pixelData;
655            if(flipx)
651            if (flipx)
656652            {
657               pixelData=(plane1&1)+((plane2&1)<<1);
658               plane1=plane1>>1;
659               plane2=plane2>>1;
660               //sd[7-pixel]
653               pixelData = (plane1 & 1) + ((plane2 & 1) << 1);
654               plane1 = plane1 >> 1;
655               plane2 = plane2 >> 1;
656               // sd[7 - pixel]
661657            }
662658            else
663659            {
664               pixelData=((plane1>>7)&1)|(((plane2>>7)&1)<<1);
665               plane1=plane1<<1;
666               plane2=plane2<<1;
667
668               //sd[pixel];
660               pixelData = ((plane1 >> 7) & 1) | (((plane2 >> 7) & 1) << 1);
661               plane1 = plane1 << 1;
662               plane2 = plane2 << 1;
663               // sd[pixel];
669664            }
670665
671666            /* is this pixel non-transparent? */
672            if ( spriteXPos + pixel >= first_pixel)
667            if (spriteXPos + pixel >= first_pixel)
673668            {
674669               if (pixelData)
675670               {
676671                  /* has the background (or another sprite) already been drawn here? */
677                  if ( !line_priority[ spriteXPos + pixel ] )
672                  if (!line_priority[spriteXPos + pixel])
678673                  {
679674                     /* no, draw */
680                     if ( ( spriteXPos + pixel ) < VISIBLE_SCREEN_WIDTH )
675                     if ((spriteXPos + pixel) < VISIBLE_SCREEN_WIDTH)
681676                        *BITMAP_ADDR16(bitmap, scanline, spriteXPos + pixel) = paldata[pixelData];
682677                     drawn = 1;
683678                  }
684679                  /* indicate that a sprite was drawn at this location, even if it's not seen */
685                  if ( ( spriteXPos + pixel ) < VISIBLE_SCREEN_WIDTH )
686                     line_priority[ spriteXPos + pixel ] |= 0x01;
680                  if ((spriteXPos + pixel) < VISIBLE_SCREEN_WIDTH)
681                     line_priority[spriteXPos + pixel] |= 0x01;
687682               }
688683
689684               /* set the "sprite 0 hit" flag if appropriate */
690               if ( spriteIndex == 0 && (pixelData & 0x03) && ((spriteXPos + pixel) < 255) && ( line_priority[ spriteXPos + pixel ] & 0x02 ))
685               if (spriteIndex == 0 && (pixelData & 0x03) && ((spriteXPos + pixel) < 255) && (line_priority[spriteXPos + pixel] & 0x02))
691686                  ppu_regs[PPU_STATUS] |= PPU_STATUS_SPRITE0_HIT;
692687            }
693688         }
r5325r5326
695690      else
696691      {
697692         /* draw the high-priority sprites */
698
699         for ( pixel = 0; pixel < 8; pixel++ )
693         for (pixel = 0; pixel < 8; pixel++)
700694         {
701695            UINT8 pixelData;
702            if(flipx)
696            if (flipx)
703697            {
704               pixelData=(plane1&1)+((plane2&1)<<1);
705               plane1=plane1>>1;
706               plane2=plane2>>1;
707               //sd[7-pixel]
698               pixelData = (plane1 & 1) + ((plane2 & 1) << 1);
699               plane1 = plane1 >> 1;
700               plane2 = plane2 >> 1;
701               // sd[7 - pixel]
708702            }
709703            else
710704            {
711               pixelData=((plane1>>7)&1)|(((plane2>>7)&1)<<1);
712               plane1=plane1<<1;
713               plane2=plane2<<1;
714
715               //sd[pixel];
705               pixelData = ((plane1 >> 7) & 1) | (((plane2 >> 7) & 1) << 1);
706               plane1 = plane1 << 1;
707               plane2 = plane2 << 1;
708               // sd[pixel];
716709            }
717710
718
719711            /* is this pixel non-transparent? */
720            if ( spriteXPos + pixel >= first_pixel)
712            if (spriteXPos + pixel >= first_pixel)
721713            {
722714               if (pixelData)
723715               {
724716                  /* has another sprite been drawn here? */
725                  if ( !( line_priority[ spriteXPos + pixel ] & 0x01 ) )
717                  if (!(line_priority[spriteXPos + pixel] & 0x01))
726718                  {
727719                     /* no, draw */
728                     if ( ( spriteXPos + pixel ) < VISIBLE_SCREEN_WIDTH )
720                     if ((spriteXPos + pixel) < VISIBLE_SCREEN_WIDTH)
729721                     {
730722                        *BITMAP_ADDR16(bitmap, scanline, spriteXPos + pixel) = paldata[pixelData];
731                        line_priority[ spriteXPos + pixel ] |= 0x01;
723                        line_priority[spriteXPos + pixel] |= 0x01;
732724                     }
733725                     drawn = 1;
734726                  }
735727               }
736728
737729               /* set the "sprite 0 hit" flag if appropriate */
738               if ( spriteIndex == 0 && (pixelData & 0x03) && ((spriteXPos + pixel) < 255) && ( line_priority[ spriteXPos + pixel ] & 0x02 ))
730               if (spriteIndex == 0 && (pixelData & 0x03) && ((spriteXPos + pixel) < 255) && (line_priority[spriteXPos + pixel] & 0x02))
739731                  ppu_regs[PPU_STATUS] |= PPU_STATUS_SPRITE0_HIT;
740732            }
741733         }
742734      }
743735
744      if ( drawn )
736      if (drawn)
745737      {
746738         /* if there are more than 8 sprites on this line, set the flag */
747739         spriteCount++;
748         if ( spriteCount == 8 )
740         if (spriteCount == 8)
749741         {
750742            ppu_regs[PPU_STATUS] |= PPU_STATUS_8SPRITES;
751743//              logerror ("> 8 sprites, scanline: %d\n", scanline);
r5325r5326
762754 *  Scanline Rendering and Update
763755 *
764756 *************************************/
765static void render_scanline(const device_config *device)
757
758static void render_scanline( const device_config *device )
766759{
767760   ppu2c0x_chip *this_ppu = get_token(device);
768761   const ppu2c0x_interface *intf = get_interface(device);
769   UINT8   line_priority[VISIBLE_SCREEN_WIDTH];
770   int      *ppu_regs = &this_ppu->regs[0];
762   UINT8 line_priority[VISIBLE_SCREEN_WIDTH];
763   int *ppu_regs = &this_ppu->regs[0];
771764
772765   /* lets see how long it takes */
773766   profiler_mark(PROFILER_USER1);
774767
775768   /* clear the line priority for this scanline */
776   memset( line_priority, 0, VISIBLE_SCREEN_WIDTH );
769   memset(line_priority, 0, VISIBLE_SCREEN_WIDTH);
777770
778771   /* clear the sprite count for this line */
779772   ppu_regs[PPU_STATUS] &= ~PPU_STATUS_8SPRITES;
780773
781774   /* see if we need to render the background */
782   if ( ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_BACKGROUND )
783      draw_background(device, line_priority );
775   if (ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_BACKGROUND)
776      draw_background(device, line_priority);
784777   else
785778   {
786779      bitmap_t *bitmap = this_ppu->bitmap;
r5325r5326
790783      int i;
791784
792785      /* setup the color mask and colortable to use */
793      if ( ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_DISPLAY_MONO )
786      if (ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_DISPLAY_MONO)
794787         color_mask = 0xf0;
795788      else
796789         color_mask = 0xff;
797790
798791      /* cache the background pen */
799      back_pen = (this_ppu->back_color & color_mask)+intf->color_base;
792      back_pen = (this_ppu->back_color & color_mask) + intf->color_base;
800793
801794      // Fill this scanline with the background pen.
802      for (i = 0; i < bitmap->width; i ++)
795      for (i = 0; i < bitmap->width; i++)
803796         *BITMAP_ADDR16(bitmap, scanline, i) = back_pen;
804797   }
805798
806799   /* if sprites are on, draw them */
807   if ( ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_SPRITES )
808      draw_sprites( device, line_priority );
800   if (ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_SPRITES)
801      draw_sprites(device, line_priority);
809802
810803    /* done updating, whew */
811804   profiler_mark(PROFILER_END);
812805}
813806
814static void update_scanline(const device_config *device)
807static void update_scanline( const device_config *device )
815808{
816809   ppu2c0x_chip *this_ppu = get_token(device);
817810   const ppu2c0x_interface *intf = get_interface(device);
818811   int scanline = this_ppu->scanline;
819812   int *ppu_regs = &this_ppu->regs[0];
820813
821   if ( scanline <= PPU_BOTTOM_VISIBLE_SCANLINE )
814   if (scanline <= PPU_BOTTOM_VISIBLE_SCANLINE)
822815   {
823816      /* Render this scanline if appropriate */
824      if ( ppu_regs[PPU_CONTROL1] & ( PPU_CONTROL1_BACKGROUND | PPU_CONTROL1_SPRITES ) )
817      if (ppu_regs[PPU_CONTROL1] & (PPU_CONTROL1_BACKGROUND | PPU_CONTROL1_SPRITES))
825818      {
826819         /* If background or sprites are enabled, copy the ppu address latch */
827820         /* Copy only the scroll x-coarse and the x-overflow bit */
828821         this_ppu->refresh_data &= ~0x041f;
829         this_ppu->refresh_data |= ( this_ppu->refresh_latch & 0x041f );
822         this_ppu->refresh_data |= (this_ppu->refresh_latch & 0x041f);
830823
831//logerror("   updating refresh_data: %04x (scanline: %d)\n", this_ppu->refresh_data, this_ppu->scanline);
832         render_scanline( device );
824//          logerror("updating refresh_data: %04x (scanline: %d)\n", this_ppu->refresh_data, this_ppu->scanline);
825         render_scanline(device);
833826      }
834827      else
835828      {
r5325r5326
840833         int i;
841834
842835         /* setup the color mask and colortable to use */
843         if ( ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_DISPLAY_MONO )
836         if (ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_DISPLAY_MONO)
844837            color_mask = 0xf0;
845838         else
846839            color_mask = 0xff;
r5325r5326
862855            back_pen = penNum + intf->color_base;
863856         }
864857         else
865            back_pen = (this_ppu->back_color & color_mask)+intf->color_base;
858            back_pen = (this_ppu->back_color & color_mask) + intf->color_base;
866859
867860         // Fill this scanline with the background pen.
868         for (i = 0; i < bitmap->width; i ++)
861         for (i = 0; i < bitmap->width; i++)
869862            *BITMAP_ADDR16(bitmap, scanline, i) = back_pen;
870863      }
871864
r5325r5326
873866      this_ppu->refresh_data += 0x1000;
874867
875868      /* if it's rolled, increment the coarse y-scroll */
876      if ( this_ppu->refresh_data & 0x8000 )
869      if (this_ppu->refresh_data & 0x8000)
877870      {
878871         UINT16 tmp;
879         tmp = ( this_ppu->refresh_data & 0x03e0 ) + 0x20;
872         tmp = (this_ppu->refresh_data & 0x03e0) + 0x20;
880873         this_ppu->refresh_data &= 0x7c1f;
881874
882875         /* handle bizarro scrolling rollover at the 30th (not 32nd) vertical tile */
883         if ( tmp == 0x03c0 )
876         if (tmp == 0x03c0)
884877            this_ppu->refresh_data ^= 0x0800;
885878         else
886            this_ppu->refresh_data |= ( tmp & 0x03e0 );
879            this_ppu->refresh_data |= (tmp & 0x03e0);
887880
888//logerror("updating refresh_data: %04x\n", this_ppu->refresh_data);
889       }
881//          logerror("updating refresh_data: %04x\n", this_ppu->refresh_data);
882      }
890883   }
891884
892885}
r5325r5326
896889   const device_config *device = (const device_config *)ptr;
897890   ppu2c0x_chip *this_ppu = get_token(device);
898891   int *ppu_regs = &this_ppu->regs[0];
899   int blanked = ( ppu_regs[PPU_CONTROL1] & ( PPU_CONTROL1_BACKGROUND | PPU_CONTROL1_SPRITES ) ) == 0;
900   int vblank = ((this_ppu->scanline >= PPU_VBLANK_FIRST_SCANLINE-1) && (this_ppu->scanline < this_ppu->scanlines_per_frame-1)) ? 1 : 0;
892   int blanked = (ppu_regs[PPU_CONTROL1] & (PPU_CONTROL1_BACKGROUND | PPU_CONTROL1_SPRITES)) == 0;
893   int vblank = ((this_ppu->scanline >= PPU_VBLANK_FIRST_SCANLINE - 1) && (this_ppu->scanline < this_ppu->scanlines_per_frame - 1)) ? 1 : 0;
901894   int next_scanline;
902895
903896   /* if a callback is available, call it */
904   if ( this_ppu->scanline_callback_proc != NULL )
905      (*this_ppu->scanline_callback_proc)( device, this_ppu->scanline, vblank, blanked );
897   if (this_ppu->scanline_callback_proc != NULL)
898      (*this_ppu->scanline_callback_proc)(device, this_ppu->scanline, vblank, blanked);
906899
907900   /* update the scanline that just went by */
908   update_scanline( device );
901   update_scanline(device);
909902
910903   /* increment our scanline count */
911904   this_ppu->scanline++;
912905
913//logerror("starting scanline %d (MAME %d, beam %d)\n", this_ppu->scanline, video_screen_get_vpos(device->machine->primary_screen), video_screen_get_hpos(device->machine->primary_screen));
906//  logerror("starting scanline %d (MAME %d, beam %d)\n", this_ppu->scanline, video_screen_get_vpos(device->machine->primary_screen), video_screen_get_hpos(device->machine->primary_screen));
914907
915908   /* Note: this is called at the _end_ of each scanline */
916909   if (this_ppu->scanline == PPU_VBLANK_FIRST_SCANLINE)
917910   {
918logerror("vlbank starting\n");
911      // logerror("vblank starting\n");
919912      /* We just entered VBLANK */
920913      ppu_regs[PPU_STATUS] |= PPU_STATUS_VBLANK;
921914
r5325r5326
930923      }
931924   }
932925
933   if ( this_ppu->scanline == this_ppu->scanlines_per_frame - 1 )
926   if (this_ppu->scanline == this_ppu->scanlines_per_frame - 1)
934927   {
935logerror("vlbank ending\n");
928      // logerror("vblank ending\n");
936929      /* clear the vblank & sprite hit flag */
937      ppu_regs[PPU_STATUS] &= ~( PPU_STATUS_VBLANK | PPU_STATUS_SPRITE0_HIT );
930      ppu_regs[PPU_STATUS] &= ~(PPU_STATUS_VBLANK | PPU_STATUS_SPRITE0_HIT);
938931   }
939932
940933   /* see if we rolled */
941   else if ( this_ppu->scanline == this_ppu->scanlines_per_frame )
934   else if (this_ppu->scanline == this_ppu->scanlines_per_frame)
942935   {
943936      /* if background or sprites are enabled, copy the ppu address latch */
944      if ( !blanked )
937      if (!blanked)
945938         this_ppu->refresh_data = this_ppu->refresh_latch;
946939
947940      /* reset the scanline count */
948941      this_ppu->scanline = 0;
949//logerror("   sprite 0 x: %d y: %d num: %d\n", this_ppu->spriteram[3], this_ppu->spriteram[0]+1, this_ppu->spriteram[1]);
942//      logerror("sprite 0 x: %d y: %d num: %d\n", this_ppu->spriteram[3], this_ppu->spriteram[0] + 1, this_ppu->spriteram[1]);
950943   }
951944
952   next_scanline = this_ppu->scanline+1;
945   next_scanline = this_ppu->scanline + 1;
953946   if (next_scanline == this_ppu->scanlines_per_frame)
954947      next_scanline = 0;
955948
r5325r5326
991984   this_ppu->scanline_callback_proc = 0;
992985   this_ppu->vidaccess_callback_proc = 0;
993986
994   for( i = 0; i < PPU_MAX_REG; i++ )
987   for (i = 0; i < PPU_MAX_REG; i++)
995988      this_ppu->regs[i] = 0;
996989
997990   /* initialize the rest of the members */
r5325r5326
10111004   {
10121005      int color_base = intf->color_base;
10131006
1014      for( i = 0; i < ARRAY_LENGTH( default_colortable_mono ); i++ )
1007      for (i = 0; i < ARRAY_LENGTH(default_colortable_mono); i++)
10151008      {
10161009         /* monochromatic table */
10171010         this_ppu->colortable_mono[i] = default_colortable_mono[i] + color_base;
r5325r5326
10221015   }
10231016
10241017   /* set the vram bank-switch values to the default */
1025   for( i = 0; i < 8; i++ )
1018   for (i = 0; i < 8; i++)
10261019      this_ppu->nes_vram[i] = i * 64;
10271020
1028   //if ( this_ppu->has_videorom )
1029   //   ppu2c0x_set_videorom_bank( device, 0, 8, 0, 512 );
1021//  if (this_ppu->has_videorom)
1022//      ppu2c0x_set_videorom_bank(device, 0, 8, 0, 512);
10301023}
10311024
10321025/*************************************
r5325r5326
10351028*
10361029*************************************/
10371030
1038WRITE8_HANDLER (ppu2c0x_palette_write)
1031WRITE8_HANDLER( ppu2c0x_palette_write )
10391032{
10401033   ppu2c0x_chip *this_ppu = get_token(space->cpu);
10411034   const ppu2c0x_interface *intf = get_interface(space->cpu);
10421035   int color_base = intf->color_base;
10431036
10441037   int colorEmphasis = (this_ppu->regs[PPU_CONTROL1] & PPU_CONTROL1_COLOR_EMPHASIS) * 2;
1045   //it's a palette
1046   //transparent pens are mirrored!
1047   if(offset&0x3)
1038   // it's a palette
1039   // transparent pens are mirrored!
1040   if (offset & 0x3)
10481041   {
1049      this_ppu->palette_ram[offset&0x1F]=data;
1050      this_ppu->colortable[ offset & 0x1f ] = color_base + data + colorEmphasis;
1042      this_ppu->palette_ram[offset & 0x1f] = data;
1043      this_ppu->colortable[offset & 0x1f] = color_base + data + colorEmphasis;
10511044      this_ppu->colortable_mono[offset & 0x1f] = color_base + (data & 0xf0) + colorEmphasis;
10521045   }
10531046   else
10541047   {
10551048      int i;
1056      this_ppu->back_color = data;
1057      for( i = 0; i < 32; i += 4 )
1049      if (0 == (offset & 0xf))
10581050      {
1059         this_ppu->colortable[ i ] = color_base + data + colorEmphasis;
1060         this_ppu->colortable_mono[i] = color_base + (data & 0xf0) + colorEmphasis;
1051         this_ppu->back_color = data;
1052         for (i = 0; i < 32; i += 4)
1053         {
1054            this_ppu->colortable[i] = color_base + data + colorEmphasis;
1055            this_ppu->colortable_mono[i] = color_base + (data & 0xf0) + colorEmphasis;
1056         }
10611057      }
1062      this_ppu->palette_ram[offset&0xF]=this_ppu->palette_ram[(offset&0xF)+0x10]=data;
1058      this_ppu->palette_ram[offset & 0xf] = this_ppu->palette_ram[(offset & 0xf) + 0x10] = data;
10631059   }
10641060}
10651061
1066READ8_HANDLER (ppu2c0x_palette_read)
1062READ8_HANDLER( ppu2c0x_palette_read )
10671063{
10681064   ppu2c0x_chip *this_ppu = get_token(space->cpu);
10691065   {
1070      //it's a palette
1071      //ERROR: doesn't currently handle monochrome!
1066      // it's a palette
1067      // ERROR: doesn't currently handle monochrome!
10721068      if (this_ppu->regs[PPU_CONTROL1] & PPU_CONTROL1_DISPLAY_MONO)
1073         return (this_ppu->palette_ram[offset&0x1F]&0x30);
1074      else return (this_ppu->palette_ram[offset&0x1F]&0x3F);
1069         return (this_ppu->palette_ram[offset & 0x1f] & 0x30);
1070      else return (this_ppu->palette_ram[offset & 0x1f] & 0x3f);
10751071   }
10761072}
10771073
r5325r5326
10851081{
10861082   ppu2c0x_chip *this_ppu = get_token(device);
10871083
1088   if ( offset >= PPU_MAX_REG )
1084   if (offset >= PPU_MAX_REG)
10891085   {
1090      logerror( "PPU %s(r): Attempting to read past the chip\n", device->tag );
1086      logerror("PPU %s(r): Attempting to read past the chip\n", device->tag);
10911087      offset &= PPU_MAX_REG - 1;
10921088   }
10931089
10941090   // see which register to read
1095   switch( offset & 7 )
1091   switch (offset & 7)
10961092   {
10971093      case PPU_STATUS:
10981094         // The top 3 bits of the status register are the only ones that report data. The
r5325r5326
11121108         break;
11131109
11141110      case PPU_DATA:
1115         if ( ppu_latch )
1116            (*ppu_latch)( device, this_ppu->videomem_addr & 0x3fff );
1111         if (ppu_latch)
1112            (*ppu_latch)(device, this_ppu->videomem_addr & 0x3fff);
11171113
1118         if ( this_ppu->videomem_addr >= 0x3f00  )
1114         if (this_ppu->videomem_addr >= 0x3f00)
11191115         {
11201116            this_ppu->data_latch = memory_read_byte(device->space[0], this_ppu->videomem_addr);
1121            //buffer the mirrored NT data
1122            this_ppu->buffered_data =memory_read_byte(device->space[0], this_ppu->videomem_addr&0x2FFF);
1117            // buffer the mirrored NT data
1118            this_ppu->buffered_data = memory_read_byte(device->space[0], this_ppu->videomem_addr & 0x2fff);
11231119         }
11241120         else
11251121         {
11261122            this_ppu->data_latch = this_ppu->buffered_data;
1127            this_ppu->buffered_data =memory_read_byte(device->space[0], this_ppu->videomem_addr);
1123            this_ppu->buffered_data = memory_read_byte(device->space[0], this_ppu->videomem_addr);
11281124         }
11291125
1130
11311126         this_ppu->videomem_addr += this_ppu->add;
11321127         break;
11331128
r5325r5326
11531148
11541149   color_base = intf->color_base;
11551150
1156   if ( offset >= PPU_MAX_REG )
1151   if (offset >= PPU_MAX_REG)
11571152   {
1158      logerror( "PPU: Attempting to write past the chip\n" );
1153      logerror("PPU: Attempting to write past the chip\n");
11591154      offset &= PPU_MAX_REG - 1;
11601155   }
11611156
r5325r5326
11631158   if (this_ppu->scanline <= PPU_BOTTOM_VISIBLE_SCANLINE)
11641159   {
11651160      const device_config *screen = device->machine->primary_screen;
1166      logerror("  PPU register %d write %02x during non-vblank scanline %d (MAME %d, beam pos: %d)\n", offset, data, this_ppu->scanline, video_screen_get_vpos(screen), video_screen_get_hpos(screen));
1161      logerror("PPU register %d write %02x during non-vblank scanline %d (MAME %d, beam pos: %d)\n", offset, data, this_ppu->scanline, video_screen_get_vpos(screen), video_screen_get_hpos(screen));
11671162   }
11681163#endif
11691164
1170   switch( offset & 7 )
1165   switch (offset & 7)
11711166   {
11721167      case PPU_CONTROL0:
11731168         this_ppu->regs[PPU_CONTROL0] = data;
11741169
11751170         /* update the name table number on our refresh latches */
11761171         this_ppu->refresh_latch &= 0x73ff;
1177         this_ppu->refresh_latch |= ( data & 3 ) << 10;
1172         this_ppu->refresh_latch |= (data & 3) << 10;
11781173
11791174         /* the char ram bank points either 0x0000 or 0x1000 (page 0 or page 4) */
1180         this_ppu->tile_page = ( data & PPU_CONTROL0_CHR_SELECT ) >> 2;
1181         this_ppu->sprite_page = ( data & PPU_CONTROL0_SPR_SELECT ) >> 1;
1175         this_ppu->tile_page = (data & PPU_CONTROL0_CHR_SELECT) >> 2;
1176         this_ppu->sprite_page = (data & PPU_CONTROL0_SPR_SELECT) >> 1;
11821177
1183         this_ppu->add = ( data & PPU_CONTROL0_INC ) ? 32 : 1;
1184//logerror("   control0 write: %02x (scanline: %d)\n", data, this_ppu->scanline);
1178         this_ppu->add = (data & PPU_CONTROL0_INC) ? 32 : 1;
1179//          logerror("control0 write: %02x (scanline: %d)\n", data, this_ppu->scanline);
11851180         break;
11861181
11871182      case PPU_CONTROL1:
11881183         /* if color intensity has changed, change all the color tables to reflect them */
1189         if ( ( data & PPU_CONTROL1_COLOR_EMPHASIS ) != ( this_ppu->regs[PPU_CONTROL1] & PPU_CONTROL1_COLOR_EMPHASIS ) )
1184         if ((data & PPU_CONTROL1_COLOR_EMPHASIS) != (this_ppu->regs[PPU_CONTROL1] & PPU_CONTROL1_COLOR_EMPHASIS))
11901185         {
11911186            int i;
11921187            for (i = 0; i <= 0x1f; i ++)
11931188            {
1194               UINT8 oldColor = this_ppu->videomem[i+0x3f00];
1189               UINT8 oldColor = this_ppu->palette_ram[i];
11951190
1196               this_ppu->colortable[i] = color_base + oldColor + (data & PPU_CONTROL1_COLOR_EMPHASIS)*2;
1191               this_ppu->colortable[i] = color_base + oldColor + (data & PPU_CONTROL1_COLOR_EMPHASIS) * 2;
11971192            }
11981193         }
11991194
1200//logerror("   control1 write: %02x (scanline: %d)\n", data, this_ppu->scanline);
1195//          logerror("control1 write: %02x (scanline: %d)\n", data, this_ppu->scanline);
12011196         this_ppu->regs[PPU_CONTROL1] = data;
12021197         break;
12031198
r5325r5326
12101205         if (this_ppu->scanline <= PPU_BOTTOM_VISIBLE_SCANLINE)
12111206            data = 0xff;
12121207         this_ppu->spriteram[this_ppu->regs[PPU_SPRITE_ADDRESS]] = data;
1213         this_ppu->regs[PPU_SPRITE_ADDRESS] = ( this_ppu->regs[PPU_SPRITE_ADDRESS] + 1 ) & 0xff;
1208         this_ppu->regs[PPU_SPRITE_ADDRESS] = (this_ppu->regs[PPU_SPRITE_ADDRESS] + 1) & 0xff;
12141209         break;
12151210
12161211      case PPU_SCROLL:
1217         if ( this_ppu->toggle )
1212         if (this_ppu->toggle)
12181213         {
12191214            /* second write */
12201215            this_ppu->refresh_latch &= 0x0c1f;
1221            this_ppu->refresh_latch |= ( data & 0xf8 ) << 2;
1222            this_ppu->refresh_latch |= ( data & 0x07 ) << 12;
1223//logerror("   scroll write 2: %d, %04x (scanline: %d)\n", data, this_ppu->refresh_latch, this_ppu->scanline);
1216            this_ppu->refresh_latch |= (data & 0xf8) << 2;
1217            this_ppu->refresh_latch |= (data & 0x07) << 12;
1218//              logerror("scroll write 2: %d, %04x (scanline: %d)\n", data, this_ppu->refresh_latch, this_ppu->scanline);
12241219         }
12251220         else
12261221         {
r5325r5326
12291224            this_ppu->refresh_latch |= (data & 0xf8) >> 3;
12301225
12311226            this_ppu->x_fine = data & 7;
1232//logerror("   scroll write 1: %d, %04x (scanline: %d)\n", data, this_ppu->refresh_latch, this_ppu->scanline);
1227//              logerror("scroll write 1: %d, %04x (scanline: %d)\n", data, this_ppu->refresh_latch, this_ppu->scanline);
12331228         }
12341229
12351230         this_ppu->toggle ^= 1;
12361231         break;
12371232
12381233      case PPU_ADDRESS:
1239         if ( this_ppu->toggle )
1234         if (this_ppu->toggle)
12401235         {
12411236            /* second write */
12421237            this_ppu->refresh_latch &= 0x7f00;
r5325r5326
12441239            this_ppu->refresh_data = this_ppu->refresh_latch;
12451240
12461241            this_ppu->videomem_addr = this_ppu->refresh_latch;
1247//logerror("   vram addr write 2: %02x, %04x (scanline: %d)\n", data, this_ppu->refresh_latch, this_ppu->scanline);
1242//              logerror("vram addr write 2: %02x, %04x (scanline: %d)\n", data, this_ppu->refresh_latch, this_ppu->scanline);
12481243         }
12491244         else
12501245         {
12511246            /* first write */
12521247            this_ppu->refresh_latch &= 0x00ff;
1253            this_ppu->refresh_latch |= ( data & 0x3f ) << 8;
1254//logerror("   vram addr write 1: %02x, %04x (scanline: %d)\n", data, this_ppu->refresh_latch, this_ppu->scanline);
1248            this_ppu->refresh_latch |= (data & 0x3f) << 8;
1249//              logerror("vram addr write 1: %02x, %04x (scanline: %d)\n", data, this_ppu->refresh_latch, this_ppu->scanline);
12551250         }
12561251
12571252         this_ppu->toggle ^= 1;
r5325r5326
12611256         {
12621257            int tempAddr = this_ppu->videomem_addr & 0x3fff;
12631258
1264            if ( ppu_latch )
1265               (*ppu_latch)( device, tempAddr );
1259            if (ppu_latch)
1260               (*ppu_latch)(device, tempAddr);
12661261
12671262            /* if there's a callback, call it now */
1268            if ( this_ppu->vidaccess_callback_proc )
1269               data = (*this_ppu->vidaccess_callback_proc)( device, tempAddr, data );
1263            if (this_ppu->vidaccess_callback_proc)
1264               data = (*this_ppu->vidaccess_callback_proc)(device, tempAddr, data);
12701265
12711266            /* see if it's on the chargen portion */
1272            if ( tempAddr < 0x2000 )
1267            if (tempAddr < 0x2000)
12731268            {
12741269               /* if we have a videorom mapped there, dont write and log the problem */
1275               if ( this_ppu->has_videorom && !this_ppu->has_videoram )
1270               if (this_ppu->has_videorom && !this_ppu->has_videoram)
12761271               {
12771272                  /* if there is a vidaccess callback, assume it coped with it */
1278                  if ( this_ppu->vidaccess_callback_proc == NULL )
1279                     logerror( "PPU: Attempting to write to the chargen when there's a ROM there!\n" );
1273                  if (this_ppu->vidaccess_callback_proc == NULL)
1274                     logerror("PPU: Attempting to write to the chargen when there's a ROM there!\n");
12801275               }
12811276               else
12821277               {
12831278                  /* store the data */
1284                  memory_write_byte(device->space[0], tempAddr,data);
1279                  memory_write_byte(device->space[0], tempAddr, data);
12851280
12861281                  /* mark the char dirty */
1287                  //gfx_element_mark_dirty(device->machine->gfx[intf->gfx_layout_number], tempAddr >> 4);
1282                  // gfx_element_mark_dirty(device->machine->gfx[intf->gfx_layout_number], tempAddr >> 4);
12881283               }
12891284            }
12901285
r5325r5326
13081303 *  Sprite DMA
13091304 *
13101305 *************************************/
1311void ppu2c0x_spriteram_dma (const address_space *space, const device_config *device, const UINT8 page)
1306
1307void ppu2c0x_spriteram_dma( const address_space *space, const device_config *device, const UINT8 page )
13121308{
13131309   int i;
13141310   int address = page << 8;
13151311
1316//logerror("   sprite DMA: %d (scanline: %d)\n", page, this_ppu->scanline);
1312//  logerror("sprite DMA: %d (scanline: %d)\n", page, this_ppu->scanline);
13171313   for (i = 0; i < SPRITERAM_SIZE; i++)
13181314   {
13191315      UINT8 spriteData = memory_read_byte(space, address + i);
13201316      memory_write_byte(space, 0x2004, spriteData);
1321//      ppu2c0x_w (device, PPU_SPRITE_DATA, spriteData);
1317//      ppu2c0x_w(device, PPU_SPRITE_DATA, spriteData);
13221318   }
13231319
13241320   // should last 513 CPU cycles.
r5325r5326
13461342void ppu2c0x_render( const device_config *device, bitmap_t *bitmap, int flipx, int flipy, int sx, int sy )
13471343{
13481344   ppu2c0x_chip *this_ppu = get_token(device);
1349   copybitmap( bitmap, this_ppu->bitmap, flipx, flipy, sx, sy, 0 );
1345   copybitmap(bitmap, this_ppu->bitmap, flipx, flipy, sx, sy, 0);
13501346}
13511347
13521348/*************************************
r5325r5326
13591355{
13601356   ppu2c0x_chip *this_ppu = get_token(device);
13611357
1362   if ( x >= VISIBLE_SCREEN_WIDTH )
1358   if (x >= VISIBLE_SCREEN_WIDTH)
13631359      x = VISIBLE_SCREEN_WIDTH - 1;
13641360
1365   if ( y >= VISIBLE_SCREEN_HEIGHT )
1361   if (y >= VISIBLE_SCREEN_HEIGHT)
13661362      y = VISIBLE_SCREEN_HEIGHT - 1;
13671363
13681364   return *BITMAP_ADDR16(this_ppu->bitmap, y, x);
src/mame/drivers/vsnes.c
r5325r5326
17681768   MDRV_CPU_PROGRAM_MAP(vsnes_cpu1_map)
17691769                        /* some carts also trigger IRQs */
17701770   MDRV_MACHINE_RESET(vsnes)
1771   MDRV_MACHINE_START(vsnes)
17711772
17721773   /* video hardware */
17731774   MDRV_SCREEN_ADD("screen", RASTER)
r5325r5326
18061807   MDRV_CPU_PROGRAM_MAP(vsnes_cpu2_map)
18071808                        /* some carts also trigger IRQs */
18081809   MDRV_MACHINE_RESET(vsdual)
1810   MDRV_MACHINE_START(vsdual)
18091811
18101812   /* video hardware */
18111813   MDRV_PALETTE_LENGTH(2*8*4*16)
r5325r5326
18521854/******************************************************************************/
18531855
18541856
1855ROM_START( suprmrio)
1857ROM_START( suprmrio )
18561858   ROM_REGION( 0x10000,"maincpu", 0 ) /* 6502 memory */
18571859   ROM_LOAD( "mds-sm4.1d",  0x8000, 0x2000, CRC(be4d5436) SHA1(08162a7c987f1939d09bebdb676f596c86abf465) )
18581860   ROM_LOAD( "mds-sm4.1c",  0xa000, 0x2000, CRC(0011fc5a) SHA1(5c2c49938a12affc03e64e5bdab307998be20020) )
r5325r5326
18641866   ROM_LOAD( "mds-sm4.2a",  0x2000, 0x2000, CRC(15506b86) SHA1(69ecf7a3cc8bf719c1581ec7c0d68798817d416f) )
18651867ROM_END
18661868
1867ROM_START( suprmria )
1869ROM_START( suprmrioa )
18681870   ROM_REGION( 0x10000,"maincpu", 0 ) /* 6502 memory */
18691871   ROM_LOAD( "mds-sm4.1d",  0x8000, 0x2000, CRC(be4d5436) SHA1(08162a7c987f1939d09bebdb676f596c86abf465) )
18701872   ROM_LOAD( "mds-sm4.1c",  0xa000, 0x2000, CRC(5e3fb550) SHA1(de4494e4dd52f7f7b04cf1d9019fd89fb90eaca9) ) /* this rom differs by TWO BYTES from the other version in suprmrio. this version has been dumped/observed on two known boards and one anonymous board */
r5325r5326
19001902   ROM_LOAD( "ic-2a",  0x2000, 0x2000, CRC(4ec44fb3) SHA1(676e0ab574dec08df562c6f278e8a9cc7c8afa41) )
19011903ROM_END
19021904
1903ROM_START( iceclmbj )
1905ROM_START( iceclimbj )
19041906   ROM_REGION( 0x10000,"maincpu", 0 ) /* 6502 memory */
19051907   ROM_LOAD( "mds-ic4-4_6d_b.bin",  0x8000, 0x2000, CRC(0ea5f9cb) SHA1(3ba6228ac8011371fc36ce9dde4fc158a81a99a2) )
19061908   ROM_LOAD( "mds-ic4-4_6c_b.bin",  0xa000, 0x2000, CRC(51fe438e) SHA1(f40812d4275dabaac6f9539e1300c08d07992654) )
r5325r5326
20112013   ROM_LOAD( "mds-eb4.2a",  0x2000, 0x2000, CRC(a9b49a05) SHA1(c14706e6a5524f81e79c101e32deef9f3d60de3f) )
20122014ROM_END
20132015
2014ROM_START( excitbkj )
2016ROM_START( excitebkj )
20152017   ROM_REGION( 0x10000,"maincpu", 0 ) /* 6502 memory */
20162018   ROM_LOAD( "mds-eb4-4_6d_a.bin",  0x8000, 0x2000, CRC(6aa87037) SHA1(f3313700955498800a3d59c523ba2a4e0cf443bc) )
20172019   ROM_LOAD( "mds-eb4-4_6c_a.bin",  0xa000, 0x2000, CRC(bdb317db) SHA1(a8b3e8deb1e625d764aaffe86a513bc7ede51a46) )
r5325r5326
20352037   ROM_LOAD( "11.bin",  0x2000, 0x2000, CRC(f0034c04) SHA1(402dcf6ad443baeee3038ecab12db008a1ad2787) )
20362038ROM_END
20372039
2038ROM_START( ladygolf)
2040ROM_START( ladygolf )
20392041   ROM_REGION( 0x10000,"maincpu", 0  ) /* 6502 memory */
20402042   ROM_LOAD( "lg-1d",  0x8000, 0x2000, CRC(8b2ab436) SHA1(145a75f30f1fab5b1babf01ada9ed23f59c2c18d) )
20412043   ROM_LOAD( "lg-1c",  0xa000, 0x2000, CRC(bda6b432) SHA1(c8322f07df0adbd70cb49f2284b046478a3a57c1) )
r5325r5326
20712073   ROM_LOAD( "mr-2a",  0x2000, 0x2000, CRC(685899d8) SHA1(02b6a9bc21367c481d0091fa8a8f2d1b841244bf) )
20722074ROM_END
20732075
2074ROM_START( machridj )
2076ROM_START( machridrj )
20752077   ROM_REGION( 0x10000,"maincpu",0 ) /* 6502 memory */
20762078   ROM_LOAD( "mds-mr4-1_1d_or_6d_a.bin",  0x8000, 0x2000, CRC(ab7e0594) SHA1(fc5982a93791608a20e5ec9e3a4b71d702bda354) )
20772079   ROM_LOAD( "mds-mr4-1_1c_or_6c_a.bin",  0xa000, 0x2000, CRC(d4a341c3) SHA1(c799e40d0ebd1447032d8767fb2caeee6b33f31a) )
r5325r5326
20832085   ROM_LOAD( "mds-mr4-1_2a_or_8a_a.bin",  0x2000, 0x2000, CRC(ccfedc5a) SHA1(3d6321681fbe256d7c71037205d45d22fc264569) )
20842086ROM_END
20852087
2086ROM_START(smgolf)
2088ROM_START( smgolf )
20872089   ROM_REGION( 0x10000,"maincpu",0 ) /* 6502 memory */
20882090   ROM_LOAD( "golf-1d",  0x8000, 0x2000, CRC(a3e286d3) SHA1(ee7539a46e0e062ffd63d84e8b83de29b860a501) )
20892091   ROM_LOAD( "golf-1c",  0xa000, 0x2000, CRC(e477e48b) SHA1(2ebcc548ac8defc521860d2d2f585be0eee6620e) )
r5325r5326
21192121   ROM_LOAD( "pb-8a",  0x2000, 0x2000, CRC(cbe98a28) SHA1(c00c5f15a33611bfe3ad420b93b1cc2cae011c3e) )
21202122ROM_END
21212123
2122ROM_START( vspinblj )
2124ROM_START( vspinbalj )
21232125   ROM_REGION( 0x10000, "maincpu", 0 ) /* 6502 memory */
21242126   ROM_LOAD( "mds-pn3_6d_b.bin",  0x8000, 0x2000, CRC(fd50c42e) SHA1(4a3ea9e85b60caf8b6975fd2798bc59e86ec257f) )
21252127   ROM_LOAD( "mds-pn3_6c_b.bin",  0xa000, 0x2000, CRC(59beb9e5) SHA1(682b31dfbdf1ee44fd5d5d63169ab35409e93546) )
r5325r5326
23592361   ROM_LOAD( "mds-ba_8a_a.bin",  0x2000, 0x2000, CRC(3f7edb00) SHA1(f59d24f15bdb8903187eabc1578dcb60443614ed) )
23602362ROM_END
23612363
2362ROM_START( vsbbalja )
2364ROM_START( vsbballja )
23632365   ROM_REGION( 0x10000,"maincpu", 0 ) /* 6502 memory */
23642366   ROM_LOAD( "mds-ba_1d_a-2.bin",  0x08000, 0x02000, CRC(f3820b70) SHA1(c50d0c2e34f646dd186ee0f2774e94add733f21d) )
23652367   ROM_LOAD( "mds-ba_1c_a-2.bin",  0x0a000, 0x02000, CRC(39fbbf28) SHA1(9941defda548f2c51cf62f0ad62a041ee9a69c37) )
r5325r5326
23812383   ROM_LOAD( "mds-ba_8a_a.bin",  0x2000, 0x2000, CRC(3f7edb00) SHA1(f59d24f15bdb8903187eabc1578dcb60443614ed) )
23822384ROM_END
23832385
2384ROM_START( vsbbaljb )
2386ROM_START( vsbballjb )
23852387   ROM_REGION( 0x10000,"maincpu", 0 ) /* 6502 memory */
23862388   ROM_LOAD( "mds-ba_1d_a-3.bin",  0x08000, 0x02000, CRC(e234d609) SHA1(a148d6b57fbc9d5f91737fa30c2df2c2b66df404) )
23872389   ROM_LOAD( "mds-ba_1c_a-3.bin",  0x0a000, 0x02000, CRC(ca1a9591) SHA1(3544f244c59d3dab40c2745e84775b7c1defaf54) )
r5325r5326
24252427   ROM_LOAD( "mds-te.8a",  0x2000, 0x2000, CRC(d91eb295) SHA1(6b69bcef5421a6bcde89a2d1f514853f9f7992c3) )
24262428ROM_END
24272429
2428ROM_START( vstennij )
2430ROM_START( vstennisj )
24292431   ROM_REGION( 0x10000,"maincpu", 0 ) /* 6502 memory */
24302432   ROM_LOAD( "mds-te_1d_a-3.bin", 0x08000, 0x2000, CRC(8d88fbe5) SHA1(1aa172d02d0d47325edf2f5ea4fc3c1c52f1efbe) )
24312433   ROM_LOAD( "mds-te_1c_a-2.bin", 0x0a000, 0x2000, CRC(5f00c129) SHA1(e9954ebedc037be0a177286bbfc2ecdaa9223d85) )
r5325r5326
25012503GAME( 1990, drmario,  0,        vsnes,   drmario,  drmario,  ROT0, "Nintendo",  "Vs. Dr. Mario", 0 )
25022504GAME( 1985, duckhunt, 0,        vsnes,   duckhunt, duckhunt, ROT0, "Nintendo",  "Vs. Duck Hunt", 0 )
25032505GAME( 1984, excitebk, 0,        vsnes,   excitebk, excitebk, ROT0, "Nintendo",  "Vs. Excitebike", 0 )
2504GAME( 1984, excitbkj, excitebk, vsnes,   excitebk, excitbkj, ROT0, "Nintendo",  "Vs. Excitebike (Japan)", 0 )
2506GAME( 1984, excitebkj,excitebk, vsnes,   excitebk, excitbkj, ROT0, "Nintendo",  "Vs. Excitebike (Japan)", 0 )
25052507GAME( 1986, goonies,  0,        vsnes,   goonies,  goonies,  ROT0, "Konami",    "Vs. The Goonies", 0 )
25062508GAME( 1985, hogalley, 0,        vsnes,   hogalley, hogalley, ROT0, "Nintendo",  "Vs. Hogan's Alley", 0 )
25072509GAME( 1984, iceclimb, 0,        vsnes,   iceclimb, suprmrio, ROT0, "Nintendo",  "Vs. Ice Climber", 0 )
2508GAME( 1984, iceclmbj, iceclimb, vsnes,   iceclmbj, suprmrio, ROT0, "Nintendo",  "Vs. Ice Climber (Japan)", 0 )
2510GAME( 1984, iceclimbj,iceclimb, vsnes,   iceclmbj, suprmrio, ROT0, "Nintendo",  "Vs. Ice Climber (Japan)", 0 )
25092511GAME( 1985, machridr, 0,        vsnes,   machridr, machridr, ROT0, "Nintendo",  "Vs. Mach Rider (Endurance Course Version)", GAME_IMPERFECT_GRAPHICS )
2510GAME( 1985, machridj, machridr, vsnes,   machridj, vspinbal, ROT0, "Nintendo",  "Vs. Mach Rider (Japan, Fighting Course Version)", GAME_IMPERFECT_GRAPHICS )
2512GAME( 1985, machridrj,machridr, vsnes,   machridj, vspinbal, ROT0, "Nintendo",  "Vs. Mach Rider (Japan, Fighting Course Version)", GAME_IMPERFECT_GRAPHICS )
25112513GAME( 1986, rbibb,    0,        vsnes,   rbibb,    rbibb,    ROT0, "Namco",     "Vs. Atari R.B.I. Baseball (set 1)", 0 )
25122514GAME( 1986, rbibba,   rbibb,    vsnes,   rbibb,    rbibb,    ROT0, "Namco",     "Vs. Atari R.B.I. Baseball (set 2)", 0 )
25132515GAME( 1986, suprmrio, 0,        vsnes,   suprmrio, suprmrio, ROT0, "Nintendo",  "Vs. Super Mario Bros.", 0 )
2514GAME( 1986, suprmria, suprmrio, vsnes,   suprmrio, suprmrio, ROT0, "Nintendo",  "Vs. Super Mario Bros. (alt)", 0 )
2516GAME( 1986, suprmrioa,suprmrio, vsnes,   suprmrio, suprmrio, ROT0, "Nintendo",  "Vs. Super Mario Bros. (alt)", 0 )
25152517GAME( 1988, skatekds, suprmrio, vsnes,   suprmrio, suprmrio, ROT0, "hack",      "Vs. Skate Kids. (Graphic hack of Super Mario Bros.)", 0 )
25162518GAME( 1985, vsskykid, 0,        vsnes,   vsskykid, MMC3,     ROT0, "Namco",     "Vs. Super SkyKid" , 0 )
25172519GAME( 1987, tkoboxng, 0,        vsnes,   tkoboxng, tkoboxng, ROT0, "Namco LTD.","Vs. TKO Boxing", GAME_WRONG_COLORS | GAME_IMPERFECT_GRAPHICS )
r5325r5326
25192521GAME( 1984, smgolfj,  smgolf,   vsnes,   golf,     vsnormal, ROT0, "Nintendo",  "Vs. Stroke & Match Golf (Men Version) (Japan)", 0 )
25202522GAME( 1984, ladygolf, smgolf,   vsnes,   golf,     machridr, ROT0, "Nintendo",  "Vs. Stroke & Match Golf (Ladies Version)", 0 )
25212523GAME( 1984, vspinbal, 0,        vsnes,   vspinbal, vspinbal, ROT0, "Nintendo",  "Vs. Pinball", 0 )
2522GAME( 1984, vspinblj, vspinbal, vsnes,   vspinblj, vsnormal, ROT0, "Nintendo",  "Vs. Pinball (Japan)", 0 )
2524GAME( 1984, vspinbalj,vspinbal, vsnes,   vspinblj, vsnormal, ROT0, "Nintendo",  "Vs. Pinball (Japan)", 0 )
25232525GAME( 1986, vsslalom, 0,        vsnes,   vsslalom, vsslalom, ROT0, "Rare LTD.", "Vs. Slalom", GAME_IMPERFECT_GRAPHICS )
25242526GAME( 1985, vssoccer, 0,        vsnes,   vssoccer, excitebk, ROT0, "Nintendo",  "Vs. Soccer", 0 )
25252527GAME( 1986, vsgradus, 0,        vsnes,   vsgradus, vsgradus, ROT0, "Konami",    "Vs. Gradius", 0 )
r5325r5326
25352537
25362538/* Dual games */
25372539GAME( 1984, vstennis, 0,        vsdual,  vstennis, vstennis, ROT0, "Nintendo",  "Vs. Tennis" , 0 )
2538GAME( 1984, vstennij, vstennis, vsdual,  vstennis, vstennis, ROT0, "Nintendo",  "Vs. Tennis (Japan)" , 0 )
2540GAME( 1984, vstennisj,vstennis, vsdual,  vstennis, vstennis, ROT0, "Nintendo",  "Vs. Tennis (Japan)" , 0 )
25392541GAME( 1984, wrecking, 0,        vsdual,  wrecking, wrecking, ROT0, "Nintendo",  "Vs. Wrecking Crew", 0 )
25402542GAME( 1984, balonfgt, 0,        vsdual,  balonfgt, balonfgt, ROT0, "Nintendo",  "Vs. Balloon Fight", 0 )
25412543GAME( 1984, vsmahjng, 0,        vsdual,  vsmahjng, vstennis, ROT0, "Nintendo",  "Vs. Mahjang (Japan)" , 0 )
25422544GAME( 1984, vsbball,  0,        vsdual,  vsbball,  vsbball,  ROT0, "Nintendo of America",  "Vs. BaseBall", 0 )
25432545GAME( 1984, vsbballj, vsbball,  vsdual,  vsbballj, vsbball,  ROT0, "Nintendo of America",  "Vs. BaseBall (Japan set 1)", 0 )
2544GAME( 1984, vsbbalja, vsbball,  vsdual,  vsbballj, vsbball,  ROT0, "Nintendo of America",  "Vs. BaseBall (Japan set 2)", 0 )
2546GAME( 1984, vsbballja,vsbball,  vsdual,  vsbballj, vsbball,  ROT0, "Nintendo of America",  "Vs. BaseBall (Japan set 2)", 0 )
25452547GAME( 1984, iceclmrj, 0,        vsdual,  iceclmrj, iceclmrj, ROT0, "Nintendo",  "Vs. Ice Climber Dual (Japan)" , 0 )
25462548
25472549/* Not Working (bad dumps) */
25482550GAME( 1985, smgolfb,  smgolf,   vsnes,   golf,     machridr, ROT0, "Nintendo",   "Vs. Stroke & Match Golf (Men Version, set 2)", GAME_NOT_WORKING )
2549GAME( 1984, vsbbaljb, vsbball,  vsdual,  vsbballj, vsbball,  ROT0, "Nintendo of America",  "Vs. BaseBall (Japan set 3)", GAME_NOT_WORKING )
2551GAME( 1984, vsbballjb,vsbball,  vsdual,  vsbballj, vsbball,  ROT0, "Nintendo of America",  "Vs. BaseBall (Japan set 3)", GAME_NOT_WORKING )
src/mame/drivers/multigam.c
r5325r5326
4747
4848/******************************************************
4949
50   PPU external bus interface
51
52*******************************************************/
53static UINT8* nt_ram;
54static UINT8* nt_page[4];
55
56void set_mirroring(int mirroring)
57{
58   switch(mirroring)
59   {
60   case PPU_MIRROR_LOW:
61      nt_page[0] = nt_page[1] = nt_page[2] = nt_page[3] = nt_ram;
62      break;
63   case PPU_MIRROR_HIGH:
64      nt_page[0] = nt_page[1] = nt_page[2] = nt_page[3] = nt_ram + 0x400;
65      break;
66   case PPU_MIRROR_HORZ:
67      nt_page[0] = nt_ram;
68      nt_page[1] = nt_ram;
69      nt_page[2] = nt_ram + 0x400;
70      nt_page[3] = nt_ram + 0x400;
71      break;
72   case PPU_MIRROR_VERT:
73      nt_page[0] = nt_ram;
74      nt_page[1] = nt_ram + 0x400;
75      nt_page[2] = nt_ram;
76      nt_page[3] = nt_ram + 0x400;
77      break;
78   case PPU_MIRROR_NONE:
79   default:
80      nt_page[0] = nt_ram;
81      nt_page[1] = nt_ram + 0x400;
82      nt_page[2] = nt_ram + 0x800;
83      nt_page[3] = nt_ram + 0xc00;
84      break;
85   }
86}
87static WRITE8_HANDLER (multigam_nt_w)
88{
89   int page = ((offset & 0xc00) >> 10);
90   nt_page[page][offset & 0x3ff] = data;
91}
92static READ8_HANDLER (multigam_nt_r)
93{
94   int page = ((offset & 0xc00) >> 10);
95   return nt_page[page][offset & 0x3ff];
96}
97
98void set_videorom_bank(running_machine* machine, int start, int count, int bank, int bank_size_in_kb)
99{
100   int i, j;
101   int offset = bank * (bank_size_in_kb * 0x400);
102   /* bank_size_in_kb is used to determine how large the "bank" parameter is */
103   /* count determines the size of the area mapped in KB */
104   for (i = 0; i < count; i++)
105   {
106      j = i + start + 1;
107      memory_set_bankptr(machine, j, memory_region(machine, "gfx1") + offset);
108   }
109}
110
111/******************************************************
112
50113   NES interface
51114
52115*******************************************************/
53116
54117static WRITE8_HANDLER( sprite_dma_w )
55118{
56   int source = ( data & 7 );
57   ppu2c0x_spriteram_dma( space, devtag_get_device(space->machine, "ppu"), source );
119   int source = (data & 7);
120   ppu2c0x_spriteram_dma(space, devtag_get_device(space->machine, "ppu"), source);
58121}
59122
60123static READ8_DEVICE_HANDLER( psg_4015_r )
r5325r5326
92155
93156static WRITE8_HANDLER( multigam_IN0_w )
94157{
95   if ( data & 0x01 )
158   if (data & 0x01)
96159   {
97160      return;
98161   }
r5325r5326
131194static WRITE8_HANDLER(multigam_switch_prg_rom)
132195{
133196   /* switch PRG rom */
134   UINT8* dst = memory_region( space->machine, "maincpu" );
135   UINT8* src = memory_region( space->machine, "user1" );
197   UINT8* dst = memory_region(space->machine, "maincpu");
198   UINT8* src = memory_region(space->machine, "user1");
136199
137   if ( data & 0x80 )
200   if (data & 0x80)
138201   {
139      if ( data & 0x01 )
202      if (data & 0x01)
140203      {
141204         data &= ~0x01;
142205      }
143      memcpy( &dst[0x8000], &src[(data & 0x7f) * 0x4000], 0x8000 );
206      memcpy(&dst[0x8000], &src[(data & 0x7f) * 0x4000], 0x8000);
144207   }
145208   else
146209   {
147      memcpy( &dst[0x8000], &src[data*0x4000], 0x4000 );
148      memcpy( &dst[0xc000], &src[data*0x4000], 0x4000 );
210      memcpy(&dst[0x8000], &src[data*0x4000], 0x4000);
211      memcpy(&dst[0xc000], &src[data*0x4000], 0x4000);
149212   }
150213};
151214
152215static WRITE8_HANDLER(multigam_switch_gfx_rom)
153216{
154   const device_config *ppu = devtag_get_device(space->machine, "ppu");
155   ppu2c0x_set_videorom_bank( ppu, 0, 8, data /*& 0x3f*/, 512 );
156   ppu2c0x_set_mirroring( ppu, data & 0x40 ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT );
217   memory_set_bankptr(space->machine, 1, memory_region(space->machine, "gfx1") + (0x2000 * data));
218   set_mirroring(data & 0x40 ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
157219   multigam_game_gfx_bank = data;
158220};
159221
160222
161223static WRITE8_HANDLER(multigam_mapper2_w)
162224{
163   if ( multigam_game_gfx_bank & 0x80 )
225   if (multigam_game_gfx_bank & 0x80)
164226   {
165      const device_config *ppu = devtag_get_device(space->machine, "ppu");
166      ppu2c0x_set_videorom_bank( ppu, 0, 8, multigam_game_gfx_bank + (data & 0xf), 512 );
227      memory_set_bankptr(space->machine, 1, memory_region(space->machine, "gfx1") + (0x2000 * ((data & 0xf) + multigam_game_gfx_bank)));
167228   }
168229   else
169230   {
170      logerror( "Unmapped multigam_mapper2_w: offset = %04X, data = %02X\n", offset, data );
231      logerror("Unmapped multigam_mapper2_w: offset = %04X, data = %02X\n", offset, data);
171232   }
172233}
173234
r5325r5326
210271
211272static void multigam3_mmc3_scanline_cb( const device_config *device, int scanline, int vblank, int blanked )
212273{
213   if ( !vblank && !blanked )
274   if (!vblank && !blanked)
214275   {
215      if ( --multigam3_mmc3_scanline_counter == -1 )
276      if (--multigam3_mmc3_scanline_counter == -1)
216277      {
217278         multigam3_mmc3_scanline_counter = multigam3_mmc3_scanline_latch;
218279         generic_pulse_irq_line(cputag_get_cpu(device->machine, "maincpu"), 0);
r5325r5326
227288   /* basically, a MMC3 mapper from the nes */
228289   static int multigam3_mmc3_command;
229290
230   switch( offset & 0x7001 )
291   switch(offset & 0x7001)
231292   {
232293      case 0x0000:
233294         multigam3_mmc3_command = data;
234295
235         if ( multigam3_mmc3_last_bank != ( data & 0xc0 ) )
296         if (multigam3_mmc3_last_bank != (data & 0xc0))
236297         {
237298            int bank;
238            UINT8 *prg = memory_region( space->machine, "maincpu" );
239            UINT8 *src = memory_region( space->machine, "user1" );
299            UINT8 *prg = memory_region(space->machine, "maincpu");
300            UINT8 *src = memory_region(space->machine, "user1");
240301
241302            /* reset the banks */
242            if ( multigam3_mmc3_command & 0x40 )
303            if (multigam3_mmc3_command & 0x40)
243304            {
244305               /* high bank */
245306               bank = multigam3_mmc3_banks[0] * 0x2000 + 0xa0000;
246307
247               memcpy( &prg[0x0c000], &src[bank], 0x2000 );
248               memcpy( &prg[0x08000], &src[0xa0000 + 0x3c000], 0x2000 );
308               memcpy(&prg[0x0c000], &src[bank], 0x2000);
309               memcpy(&prg[0x08000], &src[0xa0000 + 0x3c000], 0x2000);
249310            }
250311            else
251312            {
252313               /* low bank */
253314               bank = multigam3_mmc3_banks[0] * 0x2000 + 0xa0000;
254315
255               memcpy( &prg[0x08000], &src[bank], 0x2000 );
256               memcpy( &prg[0x0c000], &src[0xa0000 + 0x3c000], 0x2000 );
316               memcpy(&prg[0x08000], &src[bank], 0x2000);
317               memcpy(&prg[0x0c000], &src[0xa0000 + 0x3c000], 0x2000);
257318            }
258319
259320            /* mid bank */
260321            bank = multigam3_mmc3_banks[1] * 0x2000 + 0xa0000;
261            memcpy( &prg[0x0a000], &src[bank], 0x2000 );
322            memcpy(&prg[0x0a000], &src[bank], 0x2000);
262323
263324            multigam3_mmc3_last_bank = data & 0xc0;
264325         }
r5325r5326
267328      case 0x0001:
268329         {
269330            UINT8 cmd = multigam3_mmc3_command & 0x07;
270            int page = ( multigam3_mmc3_command & 0x80 ) >> 5;
331            int page = (multigam3_mmc3_command & 0x80) >> 5;
271332            int bank;
272333
273            switch( cmd )
334            switch (cmd)
274335            {
275336               case 0:   /* char banking */
276337               case 1: /* char banking */
277338                  data &= 0xfe;
278                  page ^= ( cmd << 1 );
279                  ppu2c0x_set_videorom_bank( ppu, page, 2, 0x180 + data, 64 );
339                  page ^= (cmd << 1);
340                  set_videorom_bank(space->machine, page, 2, 0x180 + data, 1);
280341               break;
281342
282343               case 2: /* char banking */
r5325r5326
284345               case 4: /* char banking */
285346               case 5: /* char banking */
286347                  page ^= cmd + 2;
287                  ppu2c0x_set_videorom_bank( ppu, page, 1, 0x180 + data, 64 );
348                  set_videorom_bank(space->machine, page, 1, 0x180 + data, 1);
288349               break;
289350
290351               case 6: /* program banking */
291352               {
292                  UINT8 *prg = memory_region( space->machine, "maincpu" );
293                  UINT8 *src = memory_region( space->machine, "user1" );
294                  if ( multigam3_mmc3_command & 0x40 )
353                  UINT8 *prg = memory_region(space->machine, "maincpu");
354                  UINT8 *src = memory_region(space->machine, "user1");
355                  if (multigam3_mmc3_command & 0x40)
295356                  {
296357                     /* high bank */
297358                     multigam3_mmc3_banks[0] = data & 0x1f;
298                     bank = ( multigam3_mmc3_banks[0] ) * 0x2000 + 0xa0000;
359                     bank = (multigam3_mmc3_banks[0]) * 0x2000 + 0xa0000;
299360
300                     memcpy( &prg[0x0c000], &src[bank], 0x2000 );
301                     memcpy( &prg[0x08000], &src[0xa0000 + 0x3c000], 0x2000 );
361                     memcpy(&prg[0x0c000], &src[bank], 0x2000);
362                     memcpy(&prg[0x08000], &src[0xa0000 + 0x3c000], 0x2000);
302363                  }
303364                  else
304365                  {
305366                     /* low bank */
306367                     multigam3_mmc3_banks[0] = data & 0x1f;
307                     bank = ( multigam3_mmc3_banks[0] ) * 0x2000 + 0xa0000;
368                     bank = (multigam3_mmc3_banks[0]) * 0x2000 + 0xa0000;
308369
309                     memcpy( &prg[0x08000], &src[bank], 0x2000 );
310                     memcpy( &prg[0x0c000], &src[0xa0000 + 0x3c000], 0x2000 );
370                     memcpy(&prg[0x08000], &src[bank], 0x2000);
371                     memcpy(&prg[0x0c000], &src[0xa0000 + 0x3c000], 0x2000);
311372                  }
312373               }
313374               break;
r5325r5326
315376               case 7: /* program banking */
316377                  {
317378                     /* mid bank */
318                     UINT8 *prg = memory_region( space->machine, "maincpu" );
319                     UINT8 *src = memory_region( space->machine, "user1" );
379                     UINT8 *prg = memory_region(space->machine, "maincpu");
380                     UINT8 *src = memory_region(space->machine, "user1");
320381
321382                     multigam3_mmc3_banks[1] = data & 0x1f;
322383                     bank = multigam3_mmc3_banks[1] * 0x2000 + 0xa0000;
323384
324                     memcpy( &prg[0x0a000], &src[bank], 0x2000 );
385                     memcpy(&prg[0x0a000], &src[bank], 0x2000);
325386                  }
326387               break;
327388            }
r5325r5326
329390      break;
330391
331392      case 0x2000: /* mirroring */
332         if( !multigam3_mmc3_4screen )
393         if (!multigam3_mmc3_4screen)
333394         {
334            if ( data & 0x40 )
335               ppu2c0x_set_mirroring( ppu, PPU_MIRROR_HIGH );
395            if (data & 0x40)
396               set_mirroring(PPU_MIRROR_HIGH);
336397            else
337               ppu2c0x_set_mirroring( ppu, ( data & 1 ) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT );
398               set_mirroring((data & 1) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
338399         }
339400      break;
340401
r5325r5326
351412      break;
352413
353414      case 0x6000: /* disable irqs */
354         ppu2c0x_set_scanline_callback( ppu, 0 );
415         ppu2c0x_set_scanline_callback(ppu, 0);
355416      break;
356417
357418      case 0x6001: /* enable irqs */
358         ppu2c0x_set_scanline_callback( ppu, multigam3_mmc3_scanline_cb );
419         ppu2c0x_set_scanline_callback(ppu, multigam3_mmc3_scanline_cb);
359420      break;
360421   }
361422}
362423
363424static void multigam_init_smb3(running_machine *machine)
364425{
365   UINT8* dst = memory_region( machine, "maincpu" );
366   UINT8* src = memory_region( machine, "user1" );
426   UINT8* dst = memory_region(machine, "maincpu");
427   UINT8* src = memory_region(machine, "user1");
367428
368429   memcpy(&dst[0x8000], &src[0xa0000 + 0x3c000], 0x4000);
369430   memcpy(&dst[0xc000], &src[0xa0000 + 0x3c000], 0x4000);
r5325r5326
383444
384445static WRITE8_HANDLER(multigm3_mapper2_w)
385446{
386   if ( multigam_game_gfx_bank & 0x80 )
447   if (multigam_game_gfx_bank & 0x80)
387448   {
388      const device_config *ppu = devtag_get_device(space->machine, "ppu");
389      ppu2c0x_set_videorom_bank( ppu, 0, 8, (multigam_game_gfx_bank & 0xfc)  + (data & 0x3), 512 );
449      set_videorom_bank(space->machine, 0, 8, (multigam_game_gfx_bank & 0xfc)  + (data & 0x3), 8);
390450   }
391451   else
392452   {
393      logerror( "Unmapped multigam_mapper2_w: offset = %04X, data = %02X\n", offset, data );
453      logerror("Unmapped multigam_mapper2_w: offset = %04X, data = %02X\n", offset, data);
394454   }
395455};
396456
397457static WRITE8_HANDLER(multigm3_switch_prg_rom)
398458{
399459   /* switch PRG rom */
400   UINT8* dst = memory_region( space->machine, "maincpu" );
401   UINT8* src = memory_region( space->machine, "user1" );
460   UINT8* dst = memory_region(space->machine, "maincpu");
461   UINT8* src = memory_region(space->machine, "user1");
402462
403   if ( data == 0xa8 )
463   if (data == 0xa8)
404464   {
405465      multigam_init_smb3(space->machine);
406466      return;
r5325r5326
411471      memory_set_bankptr(space->machine, 1, memory_region(space->machine, "maincpu") + 0x6000);
412472   }
413473
414   if ( data & 0x80 )
474   if (data & 0x80)
415475   {
416      if ( data & 0x01 )
476      if (data & 0x01)
417477      {
418478         data &= ~0x01;
419479      }
420      memcpy( &dst[0x8000], &src[(data & 0x7f) * 0x4000], 0x8000 );
480      memcpy(&dst[0x8000], &src[(data & 0x7f) * 0x4000], 0x8000);
421481   }
422482   else
423483   {
424      memcpy( &dst[0x8000], &src[data*0x4000], 0x4000 );
425      memcpy( &dst[0xc000], &src[data*0x4000], 0x4000 );
484      memcpy(&dst[0x8000], &src[data*0x4000], 0x4000);
485      memcpy(&dst[0xc000], &src[data*0x4000], 0x4000);
426486   }
427487};
428488
r5325r5326
530590
531591static PALETTE_INIT( multigam )
532592{
533   ppu2c0x_init_palette(machine, 0 );
593   ppu2c0x_init_palette(machine, 0);
534594}
535595
536596static void ppu_irq( const device_config *device, int *ppu_regs )
537597{
538   cputag_set_input_line(device->machine, "maincpu", INPUT_LINE_NMI, PULSE_LINE );
598   cputag_set_input_line(device->machine, "maincpu", INPUT_LINE_NMI, PULSE_LINE);
539599}
540600
541601/* our ppu interface                                            */
r5325r5326
555615static VIDEO_UPDATE( multigam )
556616{
557617   /* render the ppu */
558   ppu2c0x_render( devtag_get_device(screen->machine, "ppu"), bitmap, 0, 0, 0, 0 );
618   ppu2c0x_render(devtag_get_device(screen->machine, "ppu"), bitmap, 0, 0, 0, 0);
559619   return 0;
560620}
561621
r5325r5326
580640   multigm3_switch_prg_rom(space, 0, 0x01 );
581641};
582642
643static MACHINE_START( multigam )
644{
645   nt_ram = auto_alloc_array(machine, UINT8, 0x1000);
646   memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0x2000, 0x3eff, 0, 0, multigam_nt_r, multigam_nt_w);
647   memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0x0000, 0x1fff, 0, 0, SMH_BANK(1), 0);
648   memory_set_bankptr(machine, 1, memory_region(machine, "gfx1"));
649}
583650
651static MACHINE_START( multigm3 )
652{
653   nt_ram = auto_alloc_array(machine, UINT8, 0x1000);
654   memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0x2000, 0x3eff, 0, 0, multigam_nt_r, multigam_nt_w);
655
656   memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0x0000, 0x03ff, 0, 0, SMH_BANK(1), 0);
657   memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0x0400, 0x07ff, 0, 0, SMH_BANK(2), 0);
658   memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0x0800, 0x0bff, 0, 0, SMH_BANK(3), 0);
659   memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0x0c00, 0x0fff, 0, 0, SMH_BANK(4), 0);
660   memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0x1000, 0x13ff, 0, 0, SMH_BANK(5), 0);
661   memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0x1400, 0x17ff, 0, 0, SMH_BANK(6), 0);
662   memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0x1800, 0x1bff, 0, 0, SMH_BANK(7), 0);
663   memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0x1c00, 0x1fff, 0, 0, SMH_BANK(8), 0);
664};
665
584666static MACHINE_DRIVER_START( multigam )
585667   /* basic machine hardware */
586668   MDRV_CPU_ADD("maincpu", N2A03, N2A03_DEFAULTCLOCK)
587669   MDRV_CPU_PROGRAM_MAP(multigam_map)
588670
589671   MDRV_MACHINE_RESET( multigam )
672   MDRV_MACHINE_START( multigam )
590673
591674   /* video hardware */
592675   MDRV_SCREEN_ADD("screen", RASTER)
r5325r5326
620703   MDRV_CPU_MODIFY("maincpu")
621704   MDRV_CPU_PROGRAM_MAP(multigm3_map)
622705
706   MDRV_MACHINE_START( multigm3 )
623707   MDRV_MACHINE_RESET( multigm3 )
624708MACHINE_DRIVER_END
625709
r5325r5326
704788static DRIVER_INIT( multigam )
705789{
706790   const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
707   multigam_switch_prg_rom( space, 0x0, 0x01 );
791   multigam_switch_prg_rom(space, 0x0, 0x01);
708792}
709793
710794static void multigm3_decrypt(UINT8* mem, int memsize, const UINT8* decode_nibble)
r5325r5326
727811
728812   multigmc_mmc3_6000_ram = auto_alloc_array(machine, UINT8, 0x2000);
729813
730   multigam_switch_prg_rom( space, 0x0, 0x01 );
814   multigam_switch_prg_rom(space, 0x0, 0x01);
731815}
732816
733817GAME( 1992, multigam, 0,        multigam, multigam, multigam, ROT0, "unknown", "Multi Game (set 1)", 0 )
src/mame/drivers/cham24.c
r5325r5326
6060#include "sound/nes_apu.h"
6161#include "video/ppu2c0x.h"
6262
63static UINT8* nt_ram;
64static UINT8* nt_page[4];
65
66void cham24_set_mirroring( int mirroring )
67{
68   switch(mirroring)
69   {
70   case PPU_MIRROR_LOW:
71      nt_page[0] = nt_page[1] = nt_page[2] = nt_page[3] = nt_ram;
72      break;
73   case PPU_MIRROR_HIGH:
74      nt_page[0] = nt_page[1] = nt_page[2] = nt_page[3] = nt_ram + 0x400;
75      break;
76   case PPU_MIRROR_HORZ:
77      nt_page[0] = nt_ram;
78      nt_page[1] = nt_ram;
79      nt_page[2] = nt_ram + 0x400;
80      nt_page[3] = nt_ram + 0x400;
81      break;
82   case PPU_MIRROR_VERT:
83      nt_page[0] = nt_ram;
84      nt_page[1] = nt_ram + 0x400;
85      nt_page[2] = nt_ram;
86      nt_page[3] = nt_ram + 0x400;
87      break;
88   case PPU_MIRROR_NONE:
89   default:
90      nt_page[0] = nt_ram;
91      nt_page[1] = nt_ram + 0x400;
92      nt_page[2] = nt_ram + 0x800;
93      nt_page[3] = nt_ram + 0xc00;
94      break;
95   }
96}
97
98static WRITE8_HANDLER( nt_w )
99{
100   int page = ((offset & 0xc00) >> 10);
101   nt_page[page][offset & 0x3ff] = data;
102}
103
104static READ8_HANDLER( nt_r )
105{
106   int page = ((offset & 0xc00) >> 10);
107   return nt_page[page][offset & 0x3ff];
108
109}
110
63111static WRITE8_HANDLER( sprite_dma_w )
64112{
65   int source = ( data & 7 );
66   ppu2c0x_spriteram_dma( space, devtag_get_device(space->machine, "ppu"), source );
113   int source = (data & 7);
114   ppu2c0x_spriteram_dma(space, devtag_get_device(space->machine, "ppu"), source);
67115}
68116
69117static READ8_DEVICE_HANDLER( psg_4015_r )
r5325r5326
93141
94142static WRITE8_HANDLER( cham24_IN0_w )
95143{
96   if ( data & 0xfe )
144   if (data & 0xfe)
97145   {
98      //logerror( "Unhandled cham24_IN0_w write: data = %02X\n", data );
146      //logerror("Unhandled cham24_IN0_w write: data = %02X\n", data);
99147   }
100148
101   if ( data & 0x01 )
149   if (data & 0x01)
102150   {
103151      return;
104152   }
r5325r5326
123171   UINT32 prg_bank = (offset >> 7) & 0x1f;
124172   UINT32 prg_bank_page_size = (offset >> 12) & 0x01;
125173   UINT32 gfx_mirroring = (offset >> 13) & 0x01;
126   const device_config *ppu = devtag_get_device(space->machine, "ppu");
127174
128   UINT8* dst = memory_region( space->machine, "maincpu" );
129   UINT8* src = memory_region( space->machine, "user1" );
175   UINT8* dst = memory_region(space->machine, "maincpu");
176   UINT8* src = memory_region(space->machine, "user1");
130177
131178   // switch PPU VROM bank
132   ppu2c0x_set_videorom_bank( ppu, 0, 8, gfx_bank, 512 );
179   memory_set_bankptr(space->machine, 1, memory_region(space->machine, "gfx1") + (0x2000 * gfx_bank));
133180
134181   // set gfx mirroring
135   ppu2c0x_set_mirroring( ppu, gfx_mirroring != 0 ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT );
182   cham24_set_mirroring(gfx_mirroring != 0 ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
136183
137184   // switch PRG bank
138   if ( prg_bank_page_size == 0 )
185   if (prg_bank_page_size == 0)
139186   {
140187      // 32K
141      memcpy( &dst[0x8000], &src[prg_bank * 0x8000], 0x8000 );
188      memcpy(&dst[0x8000], &src[prg_bank * 0x8000], 0x8000);
142189   }
143190   else
144191   {
145      if ( prg_16k_bank_page == 1 )
192      if (prg_16k_bank_page == 1)
146193      {
147194         // upper half of 32K page
148         memcpy( &dst[0x8000], &src[(prg_bank * 0x8000) + 0x4000], 0x4000 );
149         memcpy( &dst[0xC000], &src[(prg_bank * 0x8000) + 0x4000], 0x4000 );
195         memcpy(&dst[0x8000], &src[(prg_bank * 0x8000) + 0x4000], 0x4000);
196         memcpy(&dst[0xC000], &src[(prg_bank * 0x8000) + 0x4000], 0x4000);
150197      }
151198      else
152199      {
153200         // lower half of 32K page
154         memcpy( &dst[0x8000], &src[(prg_bank * 0x8000)], 0x4000 );
155         memcpy( &dst[0xC000], &src[(prg_bank * 0x8000)], 0x4000 );
201         memcpy(&dst[0x8000], &src[(prg_bank * 0x8000)], 0x4000);
202         memcpy(&dst[0xC000], &src[(prg_bank * 0x8000)], 0x4000);
156203      }
157204   }
158205}
r5325r5326
188235   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2)
189236   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2)
190237   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2)
191
192238INPUT_PORTS_END
193239
194240static const nes_interface cham24_interface_1 =
r5325r5326
199245static MACHINE_RESET( cham24 )
200246{
201247   /* switch PRG rom */
202   UINT8* dst = memory_region( machine, "maincpu" );
203   UINT8* src = memory_region( machine, "user1" );
248   UINT8* dst = memory_region(machine, "maincpu");
249   UINT8* src = memory_region(machine, "user1");
204250
205   memcpy( &dst[0x8000], &src[0x0f8000], 0x4000 );
206   memcpy( &dst[0xc000], &src[0x0f8000], 0x4000 );
251   memcpy(&dst[0x8000], &src[0x0f8000], 0x4000);
252   memcpy(&dst[0xc000], &src[0x0f8000], 0x4000);
207253}
208254
209255static PALETTE_INIT( cham24 )
210256{
211   ppu2c0x_init_palette(machine, 0 );
257   ppu2c0x_init_palette(machine, 0);
212258}
213259
214260static void ppu_irq( const device_config *device, int *ppu_regs )
215261{
216   cputag_set_input_line(device->machine, "maincpu", INPUT_LINE_NMI, PULSE_LINE );
262   cputag_set_input_line(device->machine, "maincpu", INPUT_LINE_NMI, PULSE_LINE);
217263}
218264
219265/* our ppu interface                                            */
r5325r5326
233279static VIDEO_UPDATE( cham24 )
234280{
235281   /* render the ppu */
236   ppu2c0x_render( devtag_get_device(screen->machine, "ppu"), bitmap, 0, 0, 0, 0 );
282   ppu2c0x_render(devtag_get_device(screen->machine, "ppu"), bitmap, 0, 0, 0, 0);
237283   return 0;
238284}
239285
240286static DRIVER_INIT( cham24 )
241287{
288   /* uses 8K swapping, all ROM!*/
289   memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0x0000, 0x1fff, 0, 0, SMH_BANK(1), 0);
290   memory_set_bankptr(machine, 1, memory_region(machine, "gfx1"));
291
292   /* need nametable ram, though. I doubt this uses more than 2k, but it starts up configured for 4 */
293   nt_ram = auto_alloc_array(machine, UINT8, 0x1000);
294
295   /* and read/write handlers */
296   memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0x2000, 0x3eff, 0, 0, nt_r, nt_w);
242297}
243298
244299static GFXDECODE_START( cham24 )
src/mame/drivers/playch10.c
r5325r5326
702702   MDRV_CPU_PROGRAM_MAP(cart_map)
703703
704704   MDRV_MACHINE_RESET(pc10)
705   MDRV_MACHINE_START(pc10)
705706
706707   // video hardware
707708   MDRV_GFXDECODE(playch10)
r5325r5326
746747static MACHINE_DRIVER_START( playch10_hboard )
747748   MDRV_IMPORT_FROM(playch10)
748749   MDRV_VIDEO_START(playch10_hboard)
750   MDRV_MACHINE_START(playch10_hboard)
749751
750752   MDRV_DEVICE_REMOVE("ppu")
751753   MDRV_PPU2C03B_ADD("ppu", playch10_ppu_interface)
src/mess/machine/nes.c
r5325r5326
7070   return state->cart;
7171}
7272
73static void init_nes_core (running_machine *machine)
73static void init_nes_core(running_machine *machine)
7474{
7575   const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
7676
r5325r5326
157157      }
158158      else
159159      {
160         logerror ("Mapper %d is not yet supported, defaulting to no mapper.\n",nes.mapper);
160         logerror("Mapper %d is not yet supported, defaulting to no mapper.\n",nes.mapper);
161161         mmc_write_low = mmc_write_mid = mmc_write = NULL;
162162         mmc_read_low = NULL;
163163      }
r5325r5326
171171   /* memory subsystem is set up. When this routine is called */
172172   /* everything is ready, so we can just copy over the data */
173173   /* we loaded before. */
174   memcpy (nes_battery_ram, battery_data, BATTERY_SIZE);
174   memcpy(nes_battery_ram, battery_data, BATTERY_SIZE);
175175}
176176
177177int nes_ppu_vidaccess( const device_config *device, int address, int data )
r5325r5326
199199   nes.mid_ram_enable = 1;
200200
201201   /* Reset the mapper variables. Will also mark the char-gen ram as dirty */
202   mapper_reset (machine, nes.mapper);
202   mapper_reset(machine, nes.mapper);
203203
204204   /* Reset the serial input ports */
205205   in_0.shift = 0;
206206   in_1.shift = 0;
207207
208   cputag_reset( machine, "maincpu" );
208   cputag_reset(machine, "maincpu");
209209}
210210
211211MACHINE_START( nes )
r5325r5326
223223
224224
225225
226 READ8_HANDLER ( nes_IN0_r )
226READ8_HANDLER( nes_IN0_r )
227227{
228228   nes_state *state = space->machine->driver_data;
229229   int ret;
r5325r5326
242242      UINT32 pix, color_base;
243243
244244      /* get the pixel at the gun position */
245      pix = ppu2c0x_get_pixel( state->ppu, x, y );
245      pix = ppu2c0x_get_pixel(state->ppu, x, y);
246246
247247      /* get the color base from the ppu */
248      color_base = ppu2c0x_get_colorbase( state->ppu );
248      color_base = ppu2c0x_get_colorbase(state->ppu);
249249
250250      /* look at the screen and see if the cursor is over a bright pixel */
251      if ( ( pix == color_base + 0x20 ) || ( pix == color_base + 0x30 ) ||
252          ( pix == color_base + 0x33 ) || ( pix == color_base + 0x34 ) )
251      if ((pix == color_base + 0x20) || (pix == color_base + 0x30) ||
252         (pix == color_base + 0x33) || (pix == color_base + 0x34))
253253      {
254254         ret &= ~0x08; /* sprite hit */
255255      }
r5325r5326
261261   }
262262
263263   if (LOG_JOY)
264      logerror ("joy 0 read, val: %02x, pc: %04x, bits read: %d, chan0: %08x\n", ret, cpu_get_pc( space->cpu ), in_0.shift, in_0.i0);
264      logerror("joy 0 read, val: %02x, pc: %04x, bits read: %d, chan0: %08x\n", ret, cpu_get_pc(space->cpu), in_0.shift, in_0.i0);
265265
266266   in_0.shift++;
267267   return ret;
268268}
269269
270 READ8_HANDLER ( nes_IN1_r )
270READ8_HANDLER( nes_IN1_r )
271271{
272272   nes_state *state = space->machine->driver_data;
273273   int ret;
r5325r5326
287287      UINT32 pix, color_base;
288288
289289      /* get the pixel at the gun position */
290      pix = ppu2c0x_get_pixel( state->ppu, x, y );
290      pix = ppu2c0x_get_pixel(state->ppu, x, y);
291291
292292      /* get the color base from the ppu */
293      color_base = ppu2c0x_get_colorbase( state->ppu );
293      color_base = ppu2c0x_get_colorbase(state->ppu);
294294
295295      /* look at the screen and see if the cursor is over a bright pixel */
296      if ( ( pix == color_base + 0x20 ) || ( pix == color_base + 0x30 ) ||
297          ( pix == color_base + 0x33 ) || ( pix == color_base + 0x34 ) )
296      if ((pix == color_base + 0x20) || (pix == color_base + 0x30) ||
297         (pix == color_base + 0x33) || (pix == color_base + 0x34))
298298      {
299299         ret &= ~0x08; /* sprite hit */
300300      }
r5325r5326
318318   }
319319
320320   if (LOG_JOY)
321      logerror ("joy 1 read, val: %02x, pc: %04x, bits read: %d, chan0: %08x\n", ret, cpu_get_pc( space->cpu ), in_1.shift, in_1.i0);
321      logerror("joy 1 read, val: %02x, pc: %04x, bits read: %d, chan0: %08x\n", ret, cpu_get_pc(space->cpu), in_1.shift, in_1.i0);
322322
323323   in_1.shift++;
324324   return ret;
r5325r5326
393393   }
394394}
395395
396WRITE8_HANDLER ( nes_IN0_w )
396WRITE8_HANDLER( nes_IN0_w )
397397{
398398   int cfg;
399399   nes_input in_2;
r5325r5326
402402   if (data & 0x01) return;
403403
404404   if (LOG_JOY)
405      logerror ("joy 0 bits read: %d\n", in_0.shift);
405      logerror("joy 0 bits read: %d\n", in_0.shift);
406406
407407   /* Toggling bit 0 high then low resets both controllers */
408408   in_0.shift = 0;
r5325r5326
428428
429429
430430
431WRITE8_HANDLER ( nes_IN1_w )
431WRITE8_HANDLER( nes_IN1_w )
432432{
433433}
434434
r5325r5326
450450
451451   if ((magic[0] != 'N') || (magic[1] != 'E') || (magic[2] != 'S'))
452452   {
453      logerror("BAD section hit during LOAD ROM.\n");
453      logerror("%s is NOT a file in iNES format.\n", image_filename(image));
454454      return INIT_FAIL;
455455   }
456456
r5325r5326
458458
459459   if (mapinfo)
460460   {
461      if (4 == sscanf(mapinfo,"%d %d %d %d",&mapint1,&mapint2,&mapint3,&mapint4))
461      if (4 == sscanf(mapinfo,"%d %d %d %d", &mapint1, &mapint2, &mapint3, &mapint4))
462462      {
463463         nes.mapper = mapint1;
464464         local_options = mapint2;
r5325r5326
481481   {
482482      // image_extrainfo() resets the file position back to start.
483483      // Let's skip past the magic header once again.
484      image_fseek (image, 4, SEEK_SET);
484      image_fseek(image, 4, SEEK_SET);
485485
486      image_fread (image, &nes.prg_chunks, 1);
487      image_fread (image, &nes.chr_chunks, 1);
486      image_fread(image, &nes.prg_chunks, 1);
487      image_fread(image, &nes.chr_chunks, 1);
488488      /* Read the first ROM option byte (offset 6) */
489      image_fread (image, &m, 1);
489      image_fread(image, &m, 1);
490490
491491      /* Interpret the iNES header flags */
492492      nes.mapper = (m & 0xf0) >> 4;
r5325r5326
494494
495495
496496      /* Read the second ROM option byte (offset 7) */
497      image_fread (image, &m, 1);
497      image_fread(image, &m, 1);
498498
499499      /* Check for skanky headers */
500      image_fread (image, &skank, 8);
500      image_fread(image, &skank, 8);
501501
502502      /* If the header has junk in the unused bytes, assume the extra mapper byte is also invalid */
503503      /* We only check the first 4 unused bytes for now */
r5325r5326
525525   if (nes.four_screen_vram) logerror("-- 4-screen VRAM\n");
526526
527527   /* Free the regions that were allocated by the ROM loader */
528   memory_region_free (image->machine, "maincpu");
529   memory_region_free (image->machine, "gfx1");
528   memory_region_free(image->machine, "maincpu");
529   memory_region_free(image->machine, "gfx1");
530530
531531   /* Allocate them again with the proper size */
532532   memory_region_alloc(image->machine, "maincpu", 0x10000 + (nes.prg_chunks + 1) * 0x4000,0);
r5325r5326
539539   nes.wram = memory_region(image->machine, "user1");
540540
541541   /* Position past the header */
542   image_fseek (image, 16, SEEK_SET);
542   image_fseek(image, 16, SEEK_SET);
543543
544544   /* Load the 0x200 byte trainer at 0x7000 if it exists */
545545   if (nes.trainer)
546546   {
547      image_fread (image, &nes.wram[0x1000], 0x200);
547      image_fread(image, &nes.wram[0x1000], 0x200);
548548   }
549549
550550   /* Read in the program chunks */
551551   if (nes.prg_chunks == 1)
552552   {
553      image_fread (image, &nes.rom[0x14000], 0x4000);
553      image_fread(image, &nes.rom[0x14000], 0x4000);
554554      /* Mirror this bank into $8000 */
555      memcpy (&nes.rom[0x10000], &nes.rom [0x14000], 0x4000);
555      memcpy(&nes.rom[0x10000], &nes.rom [0x14000], 0x4000);
556556   }
557557   else
558      image_fread (image, &nes.rom[0x10000], 0x4000 * nes.prg_chunks);
558      image_fread(image, &nes.rom[0x10000], 0x4000 * nes.prg_chunks);
559559
560560#if SPLIT_PRG
561561   {
r5325r5326
564564
565565      for (i = 0; i < nes.prg_chunks; i ++)
566566      {
567         sprintf (outname, "%s.p%d", battery_name, i);
568         prgout = fopen (outname, "wb");
567         sprintf(outname, "%s.p%d", battery_name, i);
568         prgout = fopen(outname, "wb");
569569         if (prgout)
570570         {
571            fwrite (&nes.rom[0x10000 + 0x4000 * i], 1, 0x4000, prgout);
572            fclose (prgout);
571            fwrite(&nes.rom[0x10000 + 0x4000 * i], 1, 0x4000, prgout);
572            fclose(prgout);
573573         }
574574      }
575575   }
r5325r5326
582582   /* Read in any chr chunks */
583583   if (nes.chr_chunks > 0)
584584   {
585      image_fread (image, nes.vrom, nes.chr_chunks * 0x2000);
585      image_fread(image, nes.vrom, nes.chr_chunks * 0x2000);
586586      if (nes.mapper == 2)
587587         logerror("Warning: VROM has been found in VRAM-based mapper. Either the mapper is set wrong or the ROM image is incorrect.\n");
588588   }
r5325r5326
634634   if ((magic[0] == 'F') && (magic[1] == 'D') && (magic[2] == 'S'))
635635   {
636636      /* Skip past the redundant header */
637      image_fseek (image, 0x10, SEEK_SET);
637      image_fseek(image, 0x10, SEEK_SET);
638638   }
639639   else
640640      /* otherwise, point to the start of the image */
641      image_fseek (image, 0, SEEK_SET);
641      image_fseek(image, 0, SEEK_SET);
642642
643643   /* read in all the sides */
644   while (!image_feof (image))
644   while (!image_feof(image))
645645   {
646646      nes_fds.sides ++;
647647      nes_fds.data = image_realloc(image, nes_fds.data, nes_fds.sides * 65500);
648648      if (!nes_fds.data)
649649         return INIT_FAIL;
650      image_fread (image, nes_fds.data + ((nes_fds.sides - 1) * 65500), 65500);
650      image_fread(image, nes_fds.data + ((nes_fds.sides - 1) * 65500), 65500);
651651   }
652652
653653   logerror("Number of sides: %d\n", nes_fds.sides);

Previous 15994 Revisions Next


© 1998-2018 The MESS Team