Previous 15994 Revisions Next

r3355 Wednesday 1st October, 2008 at 07:47:46 UTC by Fabio Priuli
[SNES] Improved SRAM (carts requiring 512 kbits might be working now) and memory handling. MAME part submitted to MAMEDevs as well.
[src/mame/drivers]nss.c snesb.c
[src/mame/includes]snes.h
[src/mame/machine]snes.c
[src/mess/drivers]snes.c
[src/mess/machine]snescart.c

src/mame/machine/snes.c
r3354r3355
1515#include "driver.h"
1616#include "includes/snes.h"
1717#include "cpu/g65816/g65816.h"
18#ifdef MESS
19#include "image.h"
20#endif
2118
2219// add-on chip emulators
2320#include "machine/snesdsp1.c"
r3354r3355
6057   UINT8 oldrol;
6158} joypad[4];
6259
60
61/*************************************
62
63   Timers
64
65*************************************/
66
6367// utility function - latches the H/V counters.  Used by IRQ, writes to WRIO, etc.
6468static void snes_latch_counters(running_machine *machine)
6569{
r3354r3355
270274   timer_adjust_oneshot(snes_scanline_timer, video_screen_get_time_until_pos(machine->primary_screen, nextscan, 0), 0);
271275}
272276
273static void snes_init_ram(running_machine *machine)
274{
275   int i;
276277
277   /* Init DSP1 */
278   DSP1_reset(machine);
279278
280   /* Init VRAM */
281   memset( snes_vram, 0, SNES_VRAM_SIZE );
279/*************************************
282280
283   /* Init Colour RAM */
284   memset( (UINT8 *)snes_cgram, 0, SNES_CGRAM_SIZE);
281   Input Handlers
285282
286   /* Init oam RAM */
287   memset( snes_oam, 0xff, SNES_OAM_SIZE );
283*************************************/
288284
289   /* Init work RAM - 0x55 isn't exactly right but it's close */
290   /* make sure it happens to the 65816 (CPU 0) */
291   cpuintrf_push_context(0);
292   for (i = 0; i < (128*1024); i++)
293   {
294      program_write_byte(0x7e0000 + i, 0x55);
295   }
296   cpuintrf_pop_context();
297
298   /* Inititialize registers/variables */
299   snes_ppu.update_windows = 1;
300   snes_ppu.beam.latch_vert = 0;
301   snes_ppu.beam.latch_horz = 0;
302   snes_ppu.beam.current_vert = 0;
303   snes_ppu.beam.current_horz = 0;
304   snes_ppu.beam.last_visible_line = 240;
305   snes_ppu.mode = 0;
306   cgram_address = 0;
307   vram_read_offset = 2;
308   joy1l = joy1h = joy2l = joy2h = joy3l = joy3h = 0;
309
310   // set up some known register power-up defaults
311   snes_ram[WRIO] = 0xff;
312   snes_ram[VMAIN] = 0x80;
313
314   /* init timers and stop them */
315   snes_scanline_timer = timer_alloc(snes_scanline_tick, NULL);
316   timer_adjust_oneshot(snes_scanline_timer, attotime_never, 0);
317   snes_hblank_timer = timer_alloc(snes_hblank_tick, NULL);
318   timer_adjust_oneshot(snes_hblank_timer, attotime_never, 0);
319   snes_nmi_timer = timer_alloc(snes_nmi_tick, NULL);
320   timer_adjust_oneshot(snes_nmi_timer, attotime_never, 0);
321   snes_hirq_timer = timer_alloc(snes_hirq_tick_callback, NULL);
322   timer_adjust_oneshot(snes_hirq_timer, attotime_never, 0);
323
324   // SNES hcounter has a 0-339 range.  hblank starts at counter 260.
325   // clayfighter sets an HIRQ at 260, apparently it wants it to be before hdma kicks off, so we'll delay 2 pixels.
326   hblank_offset = 268;
327   timer_adjust_oneshot(snes_hblank_timer, video_screen_get_time_until_pos(machine->primary_screen, ((snes_ram[STAT78] & 0x10) == SNES_NTSC) ? SNES_VTOTAL_NTSC-1 : SNES_VTOTAL_PAL-1, hblank_offset), 0);
328
329   // check if DSP1 is present (maybe not 100%?)
330   has_dsp1 = ((snes_r_bank1(machine,0xffd6) >= 3) && (snes_r_bank1(machine,0xffd6) <= 5)) ? 1 : 0;
331
332   // init frame counter so first line is 0
333   if( ATTOSECONDS_TO_HZ(video_screen_get_frame_period(machine->primary_screen).attoseconds) >= 59 )
334   {
335      snes_ppu.beam.current_vert = SNES_VTOTAL_NTSC;
336   }
337   else
338   {
339      snes_ppu.beam.current_vert = SNES_VTOTAL_PAL;
340   }
341}
342
343/* should we treat this as nvram in MAME? */
344static OPBASE_HANDLER(spc_opbase)
345{
346   opbase->rom = opbase->ram = spc_ram;
347   return ~0;
348}
349
350static OPBASE_HANDLER(snes_opbase)
351{
352   opbase->rom = opbase->ram = snes_ram;
353   return ~0;
354}
355
356MACHINE_START( snes )
357{
358   snes_vram = auto_malloc(SNES_VRAM_SIZE);
359   snes_cgram = auto_malloc(SNES_CGRAM_SIZE);
360   snes_oam = auto_malloc(SNES_OAM_SIZE);
361   memory_set_opbase_handler(0, snes_opbase);
362   memory_set_opbase_handler(1, spc_opbase);
363
364   // power-on sets these registers like this
365   snes_ram[WRIO] = 0xff;
366   snes_ram[WRMPYA] = 0xff;
367   snes_ram[WRDIVL] = 0xff;
368   snes_ram[WRDIVH] = 0xff;
369}
370
371MACHINE_RESET( snes )
372{
373   snes_init_ram(machine);
374
375   /* Set STAT78 to NTSC or PAL */
376   if( ATTOSECONDS_TO_HZ(video_screen_get_frame_period(machine->primary_screen).attoseconds) >= 59.0f )
377      snes_ram[STAT78] = SNES_NTSC;
378   else /* if( ATTOSECONDS_TO_HZ(video_screen_get_frame_period(machine->primary_screen).attoseconds) == 50.0f ) */
379      snes_ram[STAT78] = SNES_PAL;
380
381   // reset does this to these registers
382   snes_ram[NMITIMEN] = 0;
383   snes_ram[HTIMEL] = 0xff;
384   snes_ram[HTIMEH] = 0x1;
385   snes_ram[VTIMEL] = 0xff;
386   snes_ram[VTIMEH] = 0x1;
387
388   snes_htmult = 1;
389}
390
391/* Handle reading of Mode 20 SRAM */
392/* 0x700000 - 0x77ffff */
393READ8_HANDLER( snes_r_sram )
394{
395   UINT8 value = 0xff;
396   int mask;
397
398   // limit SRAM size to what's actually present
399   mask = (snes_cart.sram * 1024) - 1;
400   offset &= mask;
401
402   if( snes_cart.sram > 0 )
403   {
404      value = snes_ram[0x700000 + offset];
405   }
406
407   return value;
408}
409
410WRITE8_HANDLER( snes_w_sram )
411{
412   int mask;
413
414   // limit SRAM size to what's actually present
415   mask = (snes_cart.sram * 1024) - 1;
416   offset &= mask;
417
418   if( snes_cart.sram > 0 )
419   {
420      snes_ram[0x700000 + offset] = data;
421   }
422}
423
424/* 0x000000 - 0x2fffff */
425READ8_HANDLER( snes_r_bank1 )
426{
427   UINT16 address = offset & 0xffff;
428
429   if ((snes_cart.mode == SNES_MODE_20) && (has_dsp1))
430   {
431      if ((address >= 0x8000) && (offset >= 0x200000))
432      {
433         if (address >= 0xc000)
434            return DSP1_getSr();
435         else
436            return DSP1_getDr();
437      }
438   }
439
440   if( address <= 0x1fff )                        /* Mirror of Low RAM */
441   {
442      return program_read_byte(0x7e0000 + address );
443   }
444   else if( address >= 0x2000 && address <= 0x5fff )   /* I/O */
445   {
446      return snes_r_io( machine, address );
447   }
448   else if( address >= 0x6000 && address <= 0x7fff )   /* Reserved */
449   {
450      if( snes_cart.mode == SNES_MODE_20 )
451      {
452         return 0xff;
453      }
454      else
455      {
456         if (address >= 0x7000)
457            return DSP1_getSr();
458         else
459            return DSP1_getDr();
460      }
461   }
462   else
463      return snes_ram[offset];
464
465   return 0xff;
466}
467
468/* 0x300000 - 0x3fffff */
469READ8_HANDLER( snes_r_bank2 )
470{
471   UINT16 address = offset & 0xffff;
472
473   if ((snes_cart.mode == SNES_MODE_20) && (has_dsp1))
474   {
475      if (address >= 0x8000)
476      {
477         if (address >= 0xc000)
478            return DSP1_getSr();
479         else
480            return DSP1_getDr();
481      }
482   }
483
484   if( address <= 0x1fff )                        /* Mirror of Low RAM */
485      return program_read_byte(0x7e0000 + address );
486   else if( address >= 0x2000 && address <= 0x5fff )   /* I/O */
487      return snes_r_io( machine, address );
488   else if( address >= 0x6000 && address <= 0x7fff )
489   {
490      if( snes_cart.mode == SNES_MODE_20 )
491      {
492         return 0xff;                  /* Reserved */
493      }
494      else   /* MODE_21 */
495      {
496         int mask;
497
498         offset -= 0x6000;
499
500         // limit SRAM size to what's actually present
501         mask = (snes_cart.sram * 1024) - 1;
502         offset &= mask;
503         return snes_ram[0x306000 + offset];   /* sram */
504      }
505   }
506   else
507      return snes_ram[0x300000 + offset];
508
509   return 0xff;
510}
511
512/* 0x400000 - 0x5fffff */
513READ8_HANDLER( snes_r_bank3 )
514{
515   UINT16 address = offset & 0xffff;
516
517   if( snes_cart.mode == SNES_MODE_20 && address <= 0x7fff )
518      return 0xff;      /* Reserved */
519   else
520      return snes_ram[0x400000 + offset];
521
522   return 0xff;
523}
524
525/* 0x600000 - 0x6fffff */
526READ8_HANDLER( snes_r_bank6 )
527{
528   UINT16 address = offset & 0xffff;
529
530   if (address < 0x8000)
531   {
532      if (address >= 0x4000)
533         return DSP1_getSr();
534      else
535         return DSP1_getDr();
536   }
537   else
538      return snes_ram[0x600000 + offset];
539
540   return 0xff;
541}
542
543/* 0x800000 - 0xffffff */
544READ8_HANDLER( snes_r_bank4 )
545{
546   if (offset <= 0x3fffff)
547   {
548      if ((offset & 0xffff) < 0x8000)
549         return program_read_byte( offset );
550      else
551         return snes_ram[0x800000 + offset];
552   }
553   else if ( offset <= 0x5fffff )
554   {
555      if( snes_cart.mode == SNES_MODE_20 && (offset & 0xffff) < 0x8000)
556         return program_read_byte( offset );
557      else
558         return snes_ram[0x800000 + offset];
559   }
560   else
561   {
562      if( snes_cart.mode == SNES_MODE_20 )
563         return 0xff;
564      else
565         return snes_ram[offset + 0x800000];
566   }     
567
568   return 0xff;
569}
570
571/* 0x000000 - 0x2fffff */
572WRITE8_HANDLER( snes_w_bank1 )
573{
574   UINT16 address = offset & 0xffff;
575
576   if ((address >= 0x8000) && (offset >= 0x200000))
577   {
578      DSP1_setDr(data);
579      return;
580   }
581
582   if( address <= 0x1fff )                        /* Mirror of Low RAM */
583      program_write_byte(0x7e0000 + address, data );
584   else if( address >= 0x2000 && address <= 0x5fff )   /* I/O */
585      snes_w_io( machine, address, data );
586   else if( address >= 0x6000 && address <= 0x7fff )   /* Reserved */
587      if( snes_cart.mode == SNES_MODE_20 )
588      logerror( "Attempt to write to reserved address: %X\n", offset );
589   else
590      {
591         DSP1_setDr(data);
592         return;
593      }
594   else
595      logerror( "Attempt to write to ROM address: %X\n", offset );
596}
597
598/* 0x300000 - 0x3fffff */
599WRITE8_HANDLER( snes_w_bank2 )
600{
601   UINT16 address = offset & 0xffff;
602
603   if (address >= 0x8000)
604   {
605      DSP1_setDr(data);
606      return;
607   }
608
609   if( address <= 0x1fff )                        /* Mirror of Low RAM */
610      program_write_byte(0x7e0000 + address, data );
611   else if( address >= 0x2000 && address <= 0x5fff )   /* I/O */
612      snes_w_io( machine, address, data );
613   else if( address >= 0x6000 && address <= 0x7fff )
614   {
615      if( snes_cart.mode == SNES_MODE_20 )         /* Reserved */
616         logerror( "Attempt to write to reserved address: %X\n", offset );
617      else /* MODE_21 */
618      {
619         int mask;
620
621         offset -= 0x6000;
622
623         // limit SRAM size to what's actually present
624         mask = (snes_cart.sram * 1024) - 1;
625         offset &= mask;
626         snes_ram[0x306000 + offset] = data;  /* sram */
627      }
628   }
629   else
630      logerror( "Attempt to write to ROM address: %X\n", offset );
631}
632
633/* 0x600000 - 0x6fffff */
634WRITE8_HANDLER( snes_w_bank6 )
635{
636   UINT16 address = offset & 0xffff;
637
638   if (address < 0x8000)
639   {
640      DSP1_setDr(data);
641      return;
642   }
643}
644
645/* 0x800000 - 0xffffff */
646WRITE8_HANDLER( snes_w_bank4 )
647{
648   if( snes_cart.mode == SNES_MODE_20 )
649   {
650      if( offset <= 0x2fffff )
651         snes_w_bank1( machine, offset, data );
652      else if( offset >= 0x300000 && offset <= 0x3fffff )
653         snes_w_bank2( machine, offset - 0x300000, data );
654   }
655   else /* MODE_21 */
656   {
657      if( offset <= 0x2fffff )
658         snes_w_bank1( machine, offset, data );
659      else if( offset >= 0x300000 && offset <= 0x3fffff )
660         snes_w_bank2( machine, offset - 0x300000, data );
661      else
662         logerror( "Attempt to write to ROM address: %X\n", offset );
663   }
664}
665
666285/*
667286 * DR   - Double read : address is read twice to return a 16bit value.
668287 * low  - This is the low byte of a 16 or 24 bit value
r3354r3355
14691088   snes_ram[offset] = data;
14701089}
14711090
1091/*************************************
1092
1093   Memory Handlers
1094
1095*************************************/
1096
1097/*
1098There are at least 4 different kind of boards for SNES carts, which we denote with
1099mode_20, mode_21, mode_22 and mode_25. Below is a layout of the memory for each of
1100them, as described on the SNES dev manual. Notice we mirror ROM at loading time
1101where necessary (e.g. banks 0x80 to 0xff at address 0x8000 for mode_20).
1102
1103MODE_20
1104     banks 0x00      0x20          0x40      0x60       0x70     0x7e  0x80   0xc0   0xff
1105address               |             |         |          |        |     |      |      |
11060xffff  ------------------------------------------------------------------------------|
1107             ROM      |     ROM /   |   ROM   |  ROM     |  ROM / |     | 0x00 | 0x40 |
1108                 |     DSP     |         |          |  SRAM? |     |  to  |  to  |
11090x8000  ----------------------------------------------------------|     | 0x3f | 0x7f |
1110                   Reserv           |         |          |        |  W  |      |      |
1111                                  |         |          |   S    |  R  |  m   |  m   |
11120x6000  ----------------------------|         |  DSP /   |   R    |  A  |  i   |  i   |
1113                     I/O            |  Reserv |          |   A    |  M  |  r   |  r   |
11140x2000  ----------------------------|         |  Reserv  |   M    |     |  r   |  r   |
1115          Low RAM (from 0x7e)    |         |          |        |     |  o   |  o   |
1116                                  |         |          |        |     |  r   |  r   |
11170x0000  -------------------------------------------------------------------------------
1118
1119MODE_22 is the same, but banks 0x40 to 0x7e at address 0x000 to 0x7fff contain ROM (of
1120course mirrored also at 0xc0 to 0xff). Mode 22 is quite similar to the board SHVC-2P3B
1121shown on SNES Dev manual. It is used also in SDD-1 games (only for the first blocks of
1122data). DSP data & status can be either at banks 0x20 to 0x40 at address 0x8000 or at
1123banks 0x60 to 0x6f at address 0x0000.
1124
1125
1126MODE_21
1127     banks 0x00      0x10          0x30      0x40   0x7e  0x80      0xc0   0xff
1128address               |             |         |      |     |         |      |
11290xffff  --------------------------------------------------------------------|
1130                         mirror               | 0xc0 |     | mirror  |      |
1131                 upper half ROM          |  to  |     | up half |      |
1132                 from 0xc0 to 0xff        | 0xff |     |   ROM   |      |
11330x8000  --------------------------------------|      |     |---------|      |
1134             DSP /    |    Reserv   |  SRAM   |      |  W  |         |      |
1135          Reserv    |             |         |  m   |  R  |   0x00  |  R   |
11360x6000  --------------------------------------|  i   |  A  |    to   |  O   |
1137                    I/O                 |  r   |  M  |   0x3f  |  M   |
11380x2000  --------------------------------------|  r   |     |  mirror |      |
1139                Low RAM (from 0x7e)        |  o   |     |         |      |
1140                                   |  r   |     |         |      |
11410x0000  ---------------------------------------------------------------------
1142
1143
1144MODE_25 is very similar to MODE_21, but it is tought for images whose roms is larger than
1145the available banks at 0xc0 to 0xff.
1146
1147     banks 0x00      0x20      0x3e       0x40    0x7e  0x80      0xb0     0xc0    0xff
1148address               |         |          |       |     |         |        |       |
11490xffff  ----------------------------------------------------------------------------|
1150             mirror         |   Last   |       |     |       ROM        |       |
1151           upper half ROM    | 0.5Mbits |       |     |      mirror      |       |
1152          from 0x40 to 0x7e  |   ROM    |  ROM  |     |      up half     |  ROM  |
11530x8000  -----------------------------------|       |     |------------------|       |
1154             DSP /    |      Reserv        | next  |  W  | Reserv  |  SRAM  | first |
1155          Reserv    |                    |       |  R  |         |        |       |
11560x6000  -----------------------------------|  31   |  A  |------------------|  32   |
1157                 I/O                  | Mbits |  M  |        0x00      | Mbits |
11580x2000  -----------------------------------|       |     |         to       |       |
1159             Low RAM (from 0x7e)        |       |     |        0x3f      |       |
1160                                 |       |     |       mirror     |       |
11610x0000  -----------------------------------------------------------------------------
1162
1163
1164*/
1165
1166
1167/* 0x000000 - 0x2fffff */
1168READ8_HANDLER( snes_r_bank1 )
1169{
1170   UINT8 value;
1171   UINT16 address = offset & 0xffff;
1172
1173   if (address < 0x2000)                                 /* Mirror of Low RAM */
1174      value = program_read_byte(0x7e0000 + address);
1175   else if (address < 0x6000)                              /* I/O */
1176      value = snes_r_io(machine, address);
1177   else if (address < 0x8000)
1178   {
1179      if ((snes_cart.mode == SNES_MODE_21) && has_dsp1 && (offset < 0x100000))
1180         value = (address < 0x7000) ? DSP1_getDr() : DSP1_getSr();
1181      else
1182         value = 0xff;                                 /* Reserved */
1183   }
1184   else if ((snes_cart.mode == SNES_MODE_20) && has_dsp1 && (offset >= 0x200000))
1185      value = (address < 0xc000) ? DSP1_getDr() : DSP1_getSr();   /* This is not mentioned in the SNES dev manual, fwiw */
1186   else
1187      value = snes_ram[offset];
1188
1189   return value;
1190}
1191
1192/* 0x300000 - 0x3fffff */
1193READ8_HANDLER( snes_r_bank2 )
1194{
1195   UINT8 value;
1196   UINT16 address = offset & 0xffff;
1197
1198   if (address < 0x2000)                                 /* Mirror of Low RAM */
1199      value = program_read_byte(0x7e0000 + address);
1200   else if (address < 0x6000)                              /* I/O */
1201      value = snes_r_io(machine, address);
1202   else if (address < 0x8000)                              /* SRAM for mode_21, Reserved othewise */
1203   {
1204      if ((snes_cart.mode == SNES_MODE_21) && (snes_cart.sram > 0))
1205      {
1206         int mask = ((snes_cart.sram * 1024) - 1);            /* Limit SRAM size to what's actually present */
1207         offset -= 0x6000;
1208         value = snes_ram[0x306000 + (offset & mask)];
1209      }
1210      else
1211         value = 0xff;
1212   }
1213   /* some dsp1 games use these banks 0x30 to 0x3f at address 0x8000 */
1214   else if ((snes_cart.mode == SNES_MODE_20) && has_dsp1)
1215      value = (address < 0xc000) ? DSP1_getDr() : DSP1_getSr();
1216   else
1217      value = snes_ram[0x300000 + offset];
1218
1219   return value;
1220}
1221
1222/* 0x400000 - 0x5fffff */
1223READ8_HANDLER( snes_r_bank3 )
1224{
1225   UINT8 value;
1226   UINT16 address = offset & 0xffff;
1227
1228   if (snes_cart.mode & 5)                     /* Mode 20 & 22 */
1229   {
1230      if ((address < 0x8000) && (snes_cart.mode == SNES_MODE_20))
1231         value =  0xff;                     /* Reserved */
1232      else
1233         value = snes_ram[0x400000 + offset];
1234   }
1235   else                                 /* Mode 21 & 25 */
1236      value = snes_ram[0x400000 + offset];
1237
1238   return value;
1239}
1240
1241/* 0x600000 - 0x6fffff */
1242READ8_HANDLER( snes_r_bank4 )
1243{
1244   UINT8 value;
1245   UINT16 address = offset & 0xffff;
1246
1247   if (snes_cart.mode & 5)                     /* Mode 20 & 22 */
1248   {
1249      if (address >= 0x8000)
1250         value = snes_ram[0x600000 + offset];
1251      /* some other dsp1 games use these banks 0x60 to 0x6f at address 0x0000 */
1252      else if (has_dsp1)
1253         value = (address >= 0x4000) ? DSP1_getSr() : DSP1_getDr();
1254      else
1255         value = 0xff;                     /* Reserved */
1256   }
1257   else if (snes_cart.mode & 0x0a)               /* Mode 21 & 25 */
1258      value = snes_ram[0x600000 + offset];
1259
1260   return value;
1261}
1262
1263/* 0x700000 - 0x7dffff */
1264READ8_HANDLER( snes_r_bank5 )
1265{
1266   UINT8 value;
1267   UINT16 address = offset & 0xffff;
1268
1269   if ((snes_cart.mode & 5) &&(address < 0x8000))      /* Mode 20 & 22 */
1270   {
1271      if (snes_cart.sram > 0)
1272      {
1273         int mask = ((snes_cart.sram * 1024) - 1) | 0xff0000;   /* Limit SRAM size to what's actually present */
1274         value = snes_ram[0x700000 + (offset & mask)];
1275      }
1276      else
1277         value = 0xff;                        /* Reserved */
1278   }
1279   else
1280      value = snes_ram[0x700000 + offset];
1281
1282   return value;
1283}
1284
1285/* 0x800000 - 0xbfffff */
1286READ8_HANDLER( snes_r_bank6 )
1287{
1288   UINT8 value;
1289   UINT16 address = offset & 0xffff;
1290
1291   if (address < 0x8000)
1292   {
1293      if (snes_cart.mode != SNES_MODE_25)
1294         value = program_read_byte(offset);
1295      else                     /* Mode 25 has SRAM not mirrored from lower banks */
1296      {
1297         if (address < 0x6000)
1298            value = program_read_byte(offset);
1299         else if ((offset >= 0x300000) && (snes_cart.sram > 0))
1300         {
1301            int mask = ((snes_cart.sram * 1024) - 1);      /* Limit SRAM size to what's actually present */
1302            offset -= 0x6000;
1303            value = snes_ram[0x806000 + (offset & mask)];   /* SRAM */
1304         }
1305         else                  /* Area 0x6000-0x8000 with offset < 0x300000 is reserved */
1306            value = 0xff;
1307      }
1308   }
1309   else
1310      value = snes_ram[0x800000 + offset];
1311
1312   return value;
1313}
1314
1315/* 0xc00000 - 0xffffff */
1316READ8_HANDLER( snes_r_bank7 )
1317{
1318   UINT8 value;
1319   UINT16 address = offset & 0xffff;
1320
1321   if (snes_cart.mode & 5)            /* Mode 20 & 22 */
1322   {
1323      if (address < 0x8000)
1324         value = program_read_byte(0x400000 + offset);
1325      else
1326         value = snes_ram[0xc00000 + offset];
1327   }
1328   else                        /* Mode 21 & 25 */
1329      value = snes_ram[0xc00000 + offset];
1330
1331   return value;
1332}
1333
1334
1335/* 0x000000 - 0x2fffff */
1336WRITE8_HANDLER( snes_w_bank1 )
1337{
1338   UINT16 address = offset & 0xffff;
1339
1340   if (address < 0x2000)                     /* Mirror of Low RAM */
1341      program_write_byte(0x7e0000 + address, data);
1342   else if (address < 0x6000)                  /* I/O */
1343      snes_w_io(machine, address, data);
1344   else if (address < 0x8000)
1345   {
1346      if ((snes_cart.mode == SNES_MODE_21) && has_dsp1 && (offset < 0x100000))
1347         DSP1_setDr(data);
1348      else
1349         logerror( "Attempt to write to reserved address: %X\n", offset );
1350   }
1351   else if ((snes_cart.mode == SNES_MODE_20) && has_dsp1 && (offset >= 0x200000))
1352      DSP1_setDr(data);         /* This is not mentioned in the SNES dev manual, fwiw */
1353   else
1354      logerror( "Attempt to write to ROM address: %X\n", offset );
1355}
1356
1357/* 0x300000 - 0x3fffff */
1358WRITE8_HANDLER( snes_w_bank2 )
1359{
1360   UINT16 address = offset & 0xffff;
1361
1362   if (address < 0x2000)                     /* Mirror of Low RAM */
1363      program_write_byte(0x7e0000 + address, data);
1364   else if (address < 0x6000)                  /* I/O */
1365      snes_w_io(machine, address, data);
1366   else if (address < 0x8000)                  /* SRAM for mode_21, Reserved othewise */
1367   {
1368      if ((snes_cart.mode == SNES_MODE_21) && (snes_cart.sram > 0))
1369      {
1370         int mask = ((snes_cart.sram * 1024) - 1);         /* Limit SRAM size to what's actually present */
1371         offset -= 0x6000;
1372         snes_ram[0x306000 + (offset & mask)] = data;
1373      }
1374      else
1375         logerror("Attempt to write to reserved address: %X\n", offset + 0x300000);
1376   }   
1377   /* some dsp1 games use these banks 0x30 to 0x3f at address 0x8000 */
1378   else if ((snes_cart.mode == SNES_MODE_20) && has_dsp1)
1379      DSP1_setDr(data);
1380   else
1381      logerror("Attempt to write to ROM address: %X\n", offset + 0x300000);
1382}
1383
1384/* 0x600000 - 0x6fffff */
1385WRITE8_HANDLER( snes_w_bank4 )
1386{
1387   UINT16 address = offset & 0xffff;
1388
1389   if (snes_cart.mode & 5)               /* Mode 20 & 22 */
1390   {
1391      if (address >= 0x8000)
1392         logerror("Attempt to write to ROM address: %X\n", offset + 0x600000);
1393      else if (has_dsp1)
1394         DSP1_setDr(data);
1395      else
1396         logerror("Attempt to write to reserved address: %X\n", offset + 0x600000);
1397   }
1398   else if (snes_cart.mode & 0x0a)
1399      logerror("Attempt to write to ROM address: %X\n", offset + 0x600000);
1400}
1401
1402/* 0x700000 - 0x7dffff */
1403WRITE8_HANDLER( snes_w_bank5 )
1404{
1405   UINT16 address = offset & 0xffff;
1406
1407   if ((snes_cart.mode & 5) && (address < 0x8000))         /* Mode 20 & 22 */
1408   {
1409      if (snes_cart.sram > 0)
1410      {
1411         int mask = ((snes_cart.sram * 1024) - 1) | 0xff0000;   /* Limit SRAM size to what's actually present */
1412         snes_ram[0x700000 + (offset & mask)] = data;
1413      }
1414      else
1415         logerror("Attempt to write to reserved address: %X\n", offset + 0x600000);
1416   }
1417   else if (snes_cart.mode & 0x0a)
1418      logerror("Attempt to write to ROM address: %X\n", offset + 0x700000);
1419}
1420
1421
1422/* 0x800000 - 0xbfffff */
1423WRITE8_HANDLER( snes_w_bank6 )
1424{
1425   UINT16 address = offset & 0xffff;
1426
1427   if (address < 0x8000)
1428   {
1429      if (snes_cart.mode != SNES_MODE_25)
1430      {
1431         if (offset < 0x300000)
1432            snes_w_bank1(machine, offset, data);
1433         else
1434            snes_w_bank2(machine, offset - 0x300000, data);
1435      }
1436      else   /* Mode 25 has SRAM not mirrored from lower banks */
1437      {
1438         if (address < 0x6000)
1439         {
1440            if (offset < 0x300000)
1441               snes_w_bank1(machine, offset, data);
1442            else
1443               snes_w_bank2(machine, offset - 0x300000, data);
1444         }
1445         else if ((offset >= 0x300000) && (snes_cart.sram > 0))
1446         {
1447            int mask = ((snes_cart.sram * 1024) - 1);         /* Limit SRAM size to what's actually present */
1448            offset -= 0x6000;
1449            snes_ram[0xb06000 + (offset & mask)] = data;
1450         }
1451         else   /* Area in 0x6000-0x8000 && offset < 0x300000 is Reserved! */
1452            logerror("Attempt to write to reserved address: %X\n", offset + 0x800000);     
1453      }
1454   }
1455   else
1456      logerror("Attempt to write to ROM address: %X\n", offset + 0x800000);
1457}
1458
1459
1460/* 0xc00000 - 0xffffff */
1461WRITE8_HANDLER( snes_w_bank7 )
1462{
1463   UINT16 address = offset & 0xffff;
1464
1465   if (snes_cart.mode & 5)            /* Mode 20 & 22 */
1466   {
1467      if (address < 0x8000)
1468      {
1469         if (offset >= 0x3e0000)
1470            logerror("Attempt to write to banks 0xfe - 0xff address: %X\n", offset);
1471         else if (offset >= 0x300000)
1472            snes_w_bank5(machine, offset - 0x300000, data);
1473         else if (offset >= 0x200000)
1474            snes_w_bank4(machine, offset - 0x200000, data);
1475      }
1476      else
1477         logerror("Attempt to write to ROM address: %X\n", offset + 0xc00000);
1478   }
1479   else if (snes_cart.mode & 0x0a)
1480      logerror("Attempt to write to ROM address: %X\n", offset + 0xc00000);
1481}
1482
1483
1484/*************************************
1485
1486   Driver Init
1487
1488*************************************/
1489
1490static void snes_init_ram(running_machine *machine)
1491{
1492   int i;
1493
1494   /* Init DSP1 */
1495   DSP1_reset(machine);
1496
1497   /* Init VRAM */
1498   memset( snes_vram, 0, SNES_VRAM_SIZE );
1499
1500   /* Init Colour RAM */
1501   memset( (UINT8 *)snes_cgram, 0, SNES_CGRAM_SIZE);
1502
1503   /* Init oam RAM */
1504   memset( snes_oam, 0xff, SNES_OAM_SIZE );
1505
1506   /* Init work RAM - 0x55 isn't exactly right but it's close */
1507   /* make sure it happens to the 65816 (CPU 0) */
1508   cpuintrf_push_context(0);
1509   for (i = 0; i < (128*1024); i++)
1510   {
1511      program_write_byte(0x7e0000 + i, 0x55);
1512   }
1513   cpuintrf_pop_context();
1514
1515   /* Inititialize registers/variables */
1516   snes_ppu.update_windows = 1;
1517   snes_ppu.beam.latch_vert = 0;
1518   snes_ppu.beam.latch_horz = 0;
1519   snes_ppu.beam.current_vert = 0;
1520   snes_ppu.beam.current_horz = 0;
1521   snes_ppu.beam.last_visible_line = 240;
1522   snes_ppu.mode = 0;
1523   cgram_address = 0;
1524   vram_read_offset = 2;
1525   joy1l = joy1h = joy2l = joy2h = joy3l = joy3h = 0;
1526
1527   // set up some known register power-up defaults
1528   snes_ram[WRIO] = 0xff;
1529   snes_ram[VMAIN] = 0x80;
1530
1531   /* init timers and stop them */
1532   snes_scanline_timer = timer_alloc(snes_scanline_tick, NULL);
1533   timer_adjust_oneshot(snes_scanline_timer, attotime_never, 0);
1534   snes_hblank_timer = timer_alloc(snes_hblank_tick, NULL);
1535   timer_adjust_oneshot(snes_hblank_timer, attotime_never, 0);
1536   snes_nmi_timer = timer_alloc(snes_nmi_tick, NULL);
1537   timer_adjust_oneshot(snes_nmi_timer, attotime_never, 0);
1538   snes_hirq_timer = timer_alloc(snes_hirq_tick_callback, NULL);
1539   timer_adjust_oneshot(snes_hirq_timer, attotime_never, 0);
1540
1541   // SNES hcounter has a 0-339 range.  hblank starts at counter 260.
1542   // clayfighter sets an HIRQ at 260, apparently it wants it to be before hdma kicks off, so we'll delay 2 pixels.
1543   hblank_offset = 268;
1544   timer_adjust_oneshot(snes_hblank_timer, video_screen_get_time_until_pos(machine->primary_screen, ((snes_ram[STAT78] & 0x10) == SNES_NTSC) ? SNES_VTOTAL_NTSC-1 : SNES_VTOTAL_PAL-1, hblank_offset), 0);
1545
1546   // check if DSP1 is present (maybe not 100%?)
1547   has_dsp1 = ((snes_r_bank1(machine,0xffd6) >= 3) && (snes_r_bank1(machine,0xffd6) <= 5)) ? 1 : 0;
1548
1549   // init frame counter so first line is 0
1550   if( ATTOSECONDS_TO_HZ(video_screen_get_frame_period(machine->primary_screen).attoseconds) >= 59 )
1551   {
1552      snes_ppu.beam.current_vert = SNES_VTOTAL_NTSC;
1553   }
1554   else
1555   {
1556      snes_ppu.beam.current_vert = SNES_VTOTAL_PAL;
1557   }
1558}
1559
1560void snes_hdma_init()
1561{
1562   UINT8 mask = 1, dma = 0, i;
1563
1564   snes_hdma_chnl = snes_ram[HDMAEN];
1565   for( i = 0; i < 8; i++ )
1566   {
1567      if( snes_ram[HDMAEN] & mask )
1568      {
1569         snes_ram[SNES_DMA_BASE + dma + 8] = snes_ram[SNES_DMA_BASE + dma + 2];
1570         snes_ram[SNES_DMA_BASE + dma + 9] = snes_ram[SNES_DMA_BASE + dma + 3];
1571         snes_ram[SNES_DMA_BASE + dma + 0xa] = 0;
1572      }
1573      dma += 0x10;
1574      mask <<= 1;
1575   }
1576}
1577
1578
1579/* should we treat this as nvram in MAME? */
1580static OPBASE_HANDLER(spc_opbase)
1581{
1582   opbase->rom = opbase->ram = spc_ram;
1583   return ~0;
1584}
1585
1586static OPBASE_HANDLER(snes_opbase)
1587{
1588   opbase->rom = opbase->ram = snes_ram;
1589   return ~0;
1590}
1591
1592MACHINE_START( snes )
1593{
1594   snes_vram = auto_malloc(SNES_VRAM_SIZE);
1595   snes_cgram = auto_malloc(SNES_CGRAM_SIZE);
1596   snes_oam = auto_malloc(SNES_OAM_SIZE);
1597   memory_set_opbase_handler(0, snes_opbase);
1598   memory_set_opbase_handler(1, spc_opbase);
1599
1600   // power-on sets these registers like this
1601   snes_ram[WRIO] = 0xff;
1602   snes_ram[WRMPYA] = 0xff;
1603   snes_ram[WRDIVL] = 0xff;
1604   snes_ram[WRDIVH] = 0xff;
1605}
1606
1607MACHINE_RESET( snes )
1608{
1609   snes_init_ram(machine);
1610
1611   /* Set STAT78 to NTSC or PAL */
1612   if( ATTOSECONDS_TO_HZ(video_screen_get_frame_period(machine->primary_screen).attoseconds) >= 59.0f )
1613      snes_ram[STAT78] = SNES_NTSC;
1614   else /* if( ATTOSECONDS_TO_HZ(video_screen_get_frame_period(machine->primary_screen).attoseconds) == 50.0f ) */
1615      snes_ram[STAT78] = SNES_PAL;
1616
1617   // reset does this to these registers
1618   snes_ram[NMITIMEN] = 0;
1619   snes_ram[HTIMEL] = 0xff;
1620   snes_ram[HTIMEH] = 0x1;
1621   snes_ram[VTIMEL] = 0xff;
1622   snes_ram[VTIMEH] = 0x1;
1623
1624   snes_htmult = 1;
1625}
1626
1627
14721628/* for mame we use an init, maybe we will need more for the different games */
14731629DRIVER_INIT( snes )
14741630{
r3354r3355
15911747   }
15921748}
15931749
1594void snes_hdma_init()
1595{
1596   UINT8 mask = 1, dma = 0, i;
15971750
1598   snes_hdma_chnl = snes_ram[HDMAEN];
1599   for( i = 0; i < 8; i++ )
1600   {
1601      if( snes_ram[HDMAEN] & mask )
1602      {
1603         snes_ram[SNES_DMA_BASE + dma + 8] = snes_ram[SNES_DMA_BASE + dma + 2];
1604         snes_ram[SNES_DMA_BASE + dma + 9] = snes_ram[SNES_DMA_BASE + dma + 3];
1605         snes_ram[SNES_DMA_BASE + dma + 0xa] = 0;
1606      }
1607      dma += 0x10;
1608      mask <<= 1;
1609   }
1610}
1751/*************************************
16111752
1753   HDMA
1754
1755*************************************/
1756
1757
16121758void snes_hdma()
16131759{
16141760   UINT8 mask = 1, dma = 0, i, contmode;
src/mame/includes/snes.h
r3354r3355
359359extern MACHINE_START( snes );
360360extern MACHINE_RESET( snes );
361361
362extern READ8_HANDLER( snes_r_io );
363extern WRITE8_HANDLER( snes_w_io );
364
362365extern READ8_HANDLER( snes_r_bank1 );
363366extern READ8_HANDLER( snes_r_bank2 );
364367extern READ8_HANDLER( snes_r_bank3 );
365368extern READ8_HANDLER( snes_r_bank4 );
369extern READ8_HANDLER( snes_r_bank5 );
366370extern READ8_HANDLER( snes_r_bank6 );
367extern READ8_HANDLER( snes_r_io );
368extern READ8_HANDLER( snes_r_sram );
371extern READ8_HANDLER( snes_r_bank7 );
369372extern WRITE8_HANDLER( snes_w_bank1 );
370373extern WRITE8_HANDLER( snes_w_bank2 );
374extern WRITE8_HANDLER( snes_w_bank3 );
371375extern WRITE8_HANDLER( snes_w_bank4 );
376extern WRITE8_HANDLER( snes_w_bank5 );
372377extern WRITE8_HANDLER( snes_w_bank6 );
373extern WRITE8_HANDLER( snes_w_io );
374extern WRITE8_HANDLER( snes_w_sram );
378extern WRITE8_HANDLER( snes_w_bank7 );
375379
380
381
376382extern void snes_gdma( UINT8 channels );
377383extern void snes_hdma_init(void);
378384extern void snes_hdma(void);
src/mame/drivers/snesb.c
r3354r3355
130130   AM_RANGE(0x000000, 0x2fffff) AM_READWRITE(snes_r_bank1, snes_w_bank1)   /* I/O and ROM (repeats for each bank) */
131131   AM_RANGE(0x300000, 0x3fffff) AM_READWRITE(snes_r_bank2, snes_w_bank2)   /* I/O and ROM (repeats for each bank) */
132132   AM_RANGE(0x400000, 0x5fffff) AM_READWRITE(snes_r_bank3, SMH_ROM)   /* ROM (and reserved in Mode 20) */
133   AM_RANGE(0x600000, 0x6fffff) AM_READWRITE(snes_r_bank6, snes_w_bank6)   /* used by Mode 20 DSP-1 */
134   AM_RANGE(0x700000, 0x77ffff) AM_READWRITE(snes_r_sram, snes_w_sram)   /* 256KB Mode 20 save ram + reserved from 0x8000 - 0xffff */
133   AM_RANGE(0x600000, 0x6fffff) AM_READWRITE(snes_r_bank4, snes_w_bank4)   /* used by Mode 20 DSP-1 */
134   AM_RANGE(0x700000, 0x7dffff) AM_READWRITE(snes_r_bank5, snes_w_bank5)
135135   AM_RANGE(0x7e0000, 0x7fffff) AM_RAM               /* 8KB Low RAM, 24KB High RAM, 96KB Expanded RAM */
136   AM_RANGE(0x800000, 0xffffff) AM_READWRITE(snes_r_bank4, snes_w_bank4)   /* Mirror and ROM */
136   AM_RANGE(0x800000, 0xbfffff) AM_READWRITE(snes_r_bank6, snes_w_bank6)   /* Mirror and ROM */
137   AM_RANGE(0xc00000, 0xffffff) AM_READWRITE(snes_r_bank7, snes_w_bank7)   /* Mirror and ROM */
137138ADDRESS_MAP_END
138139
139140static READ8_HANDLER( spc_ram_100_r )
src/mame/drivers/nss.c
r3354r3355
299299   AM_RANGE(0x000000, 0x2fffff) AM_READWRITE(snes_r_bank1, snes_w_bank1)   /* I/O and ROM (repeats for each bank) */
300300   AM_RANGE(0x300000, 0x3fffff) AM_READWRITE(snes_r_bank2, snes_w_bank2)   /* I/O and ROM (repeats for each bank) */
301301   AM_RANGE(0x400000, 0x5fffff) AM_READWRITE(snes_r_bank3, SMH_ROM)   /* ROM (and reserved in Mode 20) */
302   AM_RANGE(0x600000, 0x6fffff) AM_READWRITE(snes_r_bank6, snes_w_bank6)   /* used by Mode 20 DSP-1 */
303   AM_RANGE(0x700000, 0x77ffff) AM_READWRITE(snes_r_sram, snes_w_sram)   /* 256KB Mode 20 save ram + reserved from 0x8000 - 0xffff */
304   AM_RANGE(0x780000, 0x7dffff) AM_NOP               /* Reserved */
302   AM_RANGE(0x600000, 0x6fffff) AM_READWRITE(snes_r_bank4, snes_w_bank4)   /* used by Mode 20 DSP-1 */
303   AM_RANGE(0x700000, 0x7dffff) AM_READWRITE(snes_r_bank5, snes_w_bank5)
305304   AM_RANGE(0x7e0000, 0x7fffff) AM_RAM               /* 8KB Low RAM, 24KB High RAM, 96KB Expanded RAM */
306   AM_RANGE(0x800000, 0xffffff) AM_READWRITE(snes_r_bank4, snes_w_bank4)   /* Mirror and ROM */
305   AM_RANGE(0x800000, 0xbfffff) AM_READWRITE(snes_r_bank6, snes_w_bank6)   /* Mirror and ROM */
306   AM_RANGE(0xc00000, 0xffffff) AM_READWRITE(snes_r_bank7, snes_w_bank7)   /* Mirror and ROM */
307307ADDRESS_MAP_END
308308
309309static READ8_HANDLER( spc_ram_100_r )
src/mess/machine/snescart.c
r3354r3355
164164   UINT8 ii;
165165   UINT8 *battery_ram, *ptr;
166166
167   battery_ram = malloc_or_die( snes_cart.sram_max );
167   battery_ram = malloc_or_die(snes_cart.sram_max);
168168   ptr = battery_ram;
169   image_battery_load( image_from_devtype_and_index(IO_CARTSLOT,0), battery_ram, snes_cart.sram_max );
169   image_battery_load(image_from_devtype_and_index(IO_CARTSLOT,0), battery_ram, snes_cart.sram_max);
170170
171   if( snes_cart.mode == SNES_MODE_20 )
171   if (snes_cart.mode == SNES_MODE_20)
172172   {
173      for( ii = 0; ii < 8; ii++ )
173      /* There could be some larger image needing banks 0x70 to 0x7f at address 0x8000 for ROM
174       * mirroring. These should be treated separately or data would be overwritten by SRAM */
175      for (ii = 0; ii < 16; ii++)
174176      {
175         memmove( &snes_ram[0x700000 + (ii * 0x010000)], ptr, 0x7fff );
176         ptr += 0x7fff;
177         /* loading */
178         memmove(&snes_ram[0x700000 + (ii * 0x010000)], ptr, 0xffff);
179         /* mirroring */
180         memcpy(&snes_ram[0xf00000 + (ii * 0x010000)], &snes_ram[0x700000 + (ii * 0x010000)], 0xffff);
181         ptr += 0xffff;
177182      }
178183   }
179   else
184   else if (snes_cart.mode == SNES_MODE_21)
180185   {
181      for( ii = 0; ii < 16; ii++ )
186      for (ii = 0; ii < 16; ii++)
182187      {
183         memmove( &snes_ram[0x306000 + (ii * 0x010000)], ptr, 0x1fff );
188         /* loading */
189         memmove(&snes_ram[0x306000 + (ii * 0x010000)], ptr, 0x1fff);
190         /* mirroring */
191         memcpy(&snes_ram[0xb06000 + (ii * 0x010000)], &snes_ram[0x306000 + (ii * 0x010000)], 0x1fff);
184192         ptr += 0x1fff;
185193      }
186194   }
195   else if (snes_cart.mode == SNES_MODE_25)
196   {
197      for (ii = 0; ii < 16; ii++)
198      {
199         memmove(&snes_ram[0xb06000 + (ii * 0x010000)], ptr, 0x1fff);
200         ptr += 0x1fff;
201      }
202   }
187203
188   free( battery_ram );
204   free(battery_ram);
189205}
190206
191207/* Saves the battery backed RAM from the appropriate memory area */
r3354r3355
194210   UINT8 ii;
195211   UINT8 *battery_ram, *ptr;
196212
197   battery_ram = malloc_or_die( snes_cart.sram_max );
213   battery_ram = malloc_or_die(snes_cart.sram_max);
198214   ptr = battery_ram;
199215
200   if( snes_cart.mode == SNES_MODE_20 )
216   if (snes_cart.mode == SNES_MODE_20)
201217   {
202      for( ii = 0; ii < 8; ii++ )
218      for (ii = 0; ii < 16; ii++)
203219      {
204         memmove( ptr, &snes_ram[0x700000 + (ii * 0x010000)], 0x8000 );
205         ptr += 0x8000;
220         memmove(ptr, &snes_ram[0x700000 + (ii * 0x010000)], 0x10000);
221         ptr += 0x10000;
206222      }
207223   }
208   else
224   else if (snes_cart.mode == SNES_MODE_21)
209225   {
210      for( ii = 0; ii < 16; ii++ )
226      for (ii = 0; ii < 16; ii++)
211227      {
212         memmove( ptr, &snes_ram[0x306000 + (ii * 0x010000)], 0x2000 );
228         memmove(ptr, &snes_ram[0x306000 + (ii * 0x010000)], 0x2000);
213229         ptr += 0x2000;
214230      }
215231   }
232   else if (snes_cart.mode == SNES_MODE_25)
233   {
234      for (ii = 0; ii < 16; ii++)
235      {
236         memmove(ptr, &snes_ram[0xb06000 + (ii * 0x010000)], 0x2000);
237         ptr += 0x2000;
238      }
239   }
216240
217   image_battery_save( image_from_devtype_and_index(IO_CARTSLOT,0), battery_ram, snes_cart.sram_max );
241   image_battery_save(image_from_devtype_and_index(IO_CARTSLOT,0), battery_ram, snes_cart.sram_max);
218242
219   free( battery_ram );
243   free(battery_ram);
220244}
221245
222246static void snes_machine_stop(running_machine *machine)
r3354r3355
413437      else
414438         snes_cart.mode = SNES_MODE_20;   // LoRom
415439
416      snes_cart.sram_max = 0x40000;
440      /* a few games require 512k, however we store twice as much to be sure to cover the various mirrors */
441      snes_cart.sram_max = 0x100000;
417442   }
418443   else if( valid_mode21 >= valid_mode25 )
419444   {
r3354r3355
480505      /* Extendend HiROM carts start to load data in banks 0xc0 to 0xff. However, they exceed the
481506       * available space in these banks, and continue loading at banks 0x40 to 0x7f. The top half
482507       * (address range 0x8000 - 0xffff) of each bank is also mirrored either to banks 0x00 to 0x3f
483       * (for data in banks 0x40 to 0x7f) or to banks 0x80 to 0xbf (for data in banks 0xc0 to 0xff)
508       * (for data in banks 0x40 to 0x7f) or to banks 0x80 to 0xbf (for data in banks 0xc0 to 0xff).
509       * Notice that banks 0x7e and 0x7f are overwritten by WRAM, but they could contain data at
510       * address > 0x8000 because the mirrors at 0x3e and 0x3f are not overwritten.
484511       */
485512         /* Reading the first 64 blocks */
486513         while (read_blocks < 64 && read_blocks < total_blocks)
src/mess/drivers/snes.c
r3354r3355
3939static ADDRESS_MAP_START( snes_map, ADDRESS_SPACE_PROGRAM, 8)
4040   AM_RANGE(0x000000, 0x2fffff) AM_READWRITE(snes_r_bank1, snes_w_bank1)   /* I/O and ROM (repeats for each bank) */
4141   AM_RANGE(0x300000, 0x3fffff) AM_READWRITE(snes_r_bank2, snes_w_bank2)   /* I/O and ROM (repeats for each bank) */
42   AM_RANGE(0x400000, 0x5fffff) AM_READWRITE(snes_r_bank3, SMH_ROM)   /* ROM (and reserved in Mode 20) */
43   AM_RANGE(0x600000, 0x6fffff) AM_READWRITE(snes_r_bank6, snes_w_bank6)   /* used by Mode 20 DSP-1 */
44   AM_RANGE(0x700000, 0x77ffff) AM_READWRITE(snes_r_sram, snes_w_sram)   /* 256KB Mode 20 save ram + reserved from 0x8000 - 0xffff */
45   AM_RANGE(0x780000, 0x7dffff) AM_NOP               /* Reserved */
42   AM_RANGE(0x400000, 0x5fffff) AM_READWRITE(snes_r_bank3, SMH_ROM)      /* ROM (and reserved in Mode 20) */
43   AM_RANGE(0x600000, 0x6fffff) AM_READWRITE(snes_r_bank4, snes_w_bank4)   /* used by Mode 20 DSP-1 */
44   AM_RANGE(0x700000, 0x7dffff) AM_READWRITE(snes_r_bank5, snes_w_bank5)
4645   AM_RANGE(0x7e0000, 0x7fffff) AM_RAM               /* 8KB Low RAM, 24KB High RAM, 96KB Expanded RAM */
47   AM_RANGE(0x800000, 0xffffff) AM_READWRITE(snes_r_bank4, snes_w_bank4)   /* Mirror and ROM */
46   AM_RANGE(0x800000, 0xbfffff) AM_READWRITE(snes_r_bank6, snes_w_bank6)   /* Mirror and ROM */
47   AM_RANGE(0xc00000, 0xffffff) AM_READWRITE(snes_r_bank7, snes_w_bank7)   /* Mirror and ROM */
4848ADDRESS_MAP_END
4949
5050static READ8_HANDLER( spc_ram_100_r )

Previous 15994 Revisions Next


© 1998-2018 The MESS Team