Previous 199869 Revisions Next

r21644 Wednesday 6th March, 2013 at 16:15:08 UTC by Fabio Priuli
experimental merging of snes memory handlers. please test your favorite SNES games against previous code
(or against latest release) and report regressions.
[src/mame/drivers]nss.c sfcbox.c snesb.c
[src/mame/includes]snes.h
[src/mame/machine]snes.c
[src/mess/drivers]snes.c

trunk/src/mess/drivers/snes.c
r21643r21644
195195      return space.read_byte(offset + 0x800000);     // [00-7f] same as [80-ff]
196196
197197   // base cart access
198   if (offset < 0x300000)
199      return snes_r_bank1(space, offset, 0xff);
200   else if (offset < 0x400000)
201      return snes_r_bank2(space, offset - 0x300000, 0xff);
202   else if (offset < 0x600000)
203      return snes_r_bank3(space, offset - 0x400000, 0xff);
204   else if (offset < 0x700000)
205      return snes_r_bank4(space, offset - 0x600000, 0xff);
206   else
207      return snes_r_bank5(space, offset - 0x700000, 0xff);
198   return snes_r_bank1(space, offset, 0xff);
208199}
209200
210201READ8_MEMBER( snes_console_state::snes_hi_r )
r21643r21644
290281      return superfx_access_ram(m_superfx) ? m_sfx_ram[offset & 0xfffff] : snes_open_bus_r(space, 0);
291282
292283   // base cart access
293   if (offset < 0x400000)
294      return snes_r_bank6(space, offset, 0xff);
295   else
296      return snes_r_bank7(space, offset - 0x400000, 0xff);
284   return snes_r_bank2(space, offset, 0xff);
297285}
298286
299287WRITE8_MEMBER( snes_console_state::snes_lo_w )
r21643r21644
367355   {   space.write_byte(offset + 0x800000, data); return; }       // [00-7f] same as [80-ff]
368356
369357   // base cart access
370   if (offset < 0x300000)
371      snes_w_bank1(space, offset, data, 0xff);
372   else if (offset < 0x400000)
373      snes_w_bank2(space, offset - 0x300000, data, 0xff);
374   else if (offset < 0x600000)
375      return;
376   else if (offset < 0x700000)
377      snes_w_bank4(space, offset - 0x600000, data, 0xff);
378   else
379      snes_w_bank5(space, offset - 0x700000, data, 0xff);
358   snes_w_bank1(space, offset, data, 0xff);
380359}
381360
382361WRITE8_MEMBER( snes_console_state::snes_hi_w )
r21643r21644
459438   {   m_sfx_ram[offset & 0xfffff] = data; return; }
460439
461440   // base cart access
462   if (offset < 0x400000)
463      snes_w_bank6(space, offset, data, 0xff);
464   else
465      snes_w_bank7(space, offset, data - 0x400000, 0xff);
441   snes_w_bank2(space, offset, data, 0xff);
466442}
467443
468444READ8_MEMBER( snes_console_state::superfx_r_bank1 )
r21643r21644
23982374   switch (state->m_type)
23992375   {
24002376      case SNES_MODE21:
2401         machine.device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x000000, 0x7dffff, read8_delegate(FUNC(snsnew_state::snes21_lo_r),state), write8_delegate(FUNC(snsnew_state::snes21_lo_w),state));
2402         machine.device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x800000, 0xffffff, read8_delegate(FUNC(snsnew_state::snes21_hi_r),state), write8_delegate(FUNC(snsnew_state::snes21_hi_w),state));
2403         set_5a22_map(*state->m_maincpu);
2377//         machine.device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x000000, 0x7dffff, read8_delegate(FUNC(snsnew_state::snes21_lo_r),state), write8_delegate(FUNC(snsnew_state::snes21_lo_w),state));
2378//         machine.device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x800000, 0xffffff, read8_delegate(FUNC(snsnew_state::snes21_hi_r),state), write8_delegate(FUNC(snsnew_state::snes21_hi_w),state));
2379//         set_5a22_map(*state->m_maincpu);
24042380         break;
24052381      case SNES_DSP_MODE21:
2406//          machine.device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x000000, 0x7dffff, read8_delegate(FUNC(snsnew_state::snes21_lo_r),state), write8_delegate(FUNC(snsnew_state::snes21_lo_w),state));
2407//          machine.device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x800000, 0xffffff, read8_delegate(FUNC(snsnew_state::snes21_hi_r),state), write8_delegate(FUNC(snsnew_state::snes21_hi_w),state));
2408//          machine.device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x006000, 0x007fff, 0x9f0000, 0, read8_delegate(FUNC(device_sns_cart_interface::chip_read),state->m_slotcart->m_cart));
2409//          machine.device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0x006000, 0x007fff, 0x9f0000, 0, write8_delegate(FUNC(device_sns_cart_interface::chip_write),state->m_slotcart->m_cart));
2410//          set_5a22_map(*state->m_maincpu);
2382//         machine.device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x000000, 0x7dffff, read8_delegate(FUNC(snsnew_state::snes21_lo_r),state), write8_delegate(FUNC(snsnew_state::snes21_lo_w),state));
2383//         machine.device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x800000, 0xffffff, read8_delegate(FUNC(snsnew_state::snes21_hi_r),state), write8_delegate(FUNC(snsnew_state::snes21_hi_w),state));
2384//         machine.device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x006000, 0x007fff, 0, 0x9f0000, read8_delegate(FUNC(device_sns_cart_interface::chip_read),state->m_slotcart->m_cart));
2385//         machine.device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0x006000, 0x007fff, 0, 0x9f0000, write8_delegate(FUNC(device_sns_cart_interface::chip_write),state->m_slotcart->m_cart));
2386//         set_5a22_map(*state->m_maincpu);
24112387         break;
24122388      case SNES_SRTC:
2413//          machine.device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x000000, 0x7dffff, read8_delegate(FUNC(snsnew_state::snes21_lo_r),state), write8_delegate(FUNC(snsnew_state::snes21_lo_w),state));
2414//          machine.device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x800000, 0xffffff, read8_delegate(FUNC(snsnew_state::snes21_hi_r),state), write8_delegate(FUNC(snsnew_state::snes21_hi_w),state));
2415//          machine.device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x002800, 0x002800, 0xbf0000, 0, read8_delegate(FUNC(device_sns_cart_interface::chip_read),state->m_slotcart->m_cart));
2416//          machine.device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0x002801, 0x002801, 0xbf0000, 0, write8_delegate(FUNC(device_sns_cart_interface::chip_write),state->m_slotcart->m_cart));
2417//          set_5a22_map(*state->m_maincpu);
2389//         machine.device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x000000, 0x7dffff, read8_delegate(FUNC(snsnew_state::snes21_lo_r),state), write8_delegate(FUNC(snsnew_state::snes21_lo_w),state));
2390//         machine.device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x800000, 0xffffff, read8_delegate(FUNC(snsnew_state::snes21_hi_r),state), write8_delegate(FUNC(snsnew_state::snes21_hi_w),state));
2391//         machine.device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x002800, 0x002800, 0, 0xbf0000, read8_delegate(FUNC(device_sns_cart_interface::chip_read),state->m_slotcart->m_cart));
2392//         machine.device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0x002801, 0x002801, 0, 0xbf0000, write8_delegate(FUNC(device_sns_cart_interface::chip_write),state->m_slotcart->m_cart));
2393//         set_5a22_map(*state->m_maincpu);
24182394         break;
24192395   }
24202396}
trunk/src/mame/drivers/snesb.c
r21643r21644
237237
238238
239239static ADDRESS_MAP_START( snesb_map, AS_PROGRAM, 8, snesb_state )
240   AM_RANGE(0x000000, 0x2fffff) AM_READWRITE_LEGACY(snes_r_bank1, snes_w_bank1)    /* I/O and ROM (repeats for each bank) */
241   AM_RANGE(0x300000, 0x3fffff) AM_READWRITE_LEGACY(snes_r_bank2, snes_w_bank2)    /* I/O and ROM (repeats for each bank) */
242   AM_RANGE(0x400000, 0x5fffff) AM_READ_LEGACY(snes_r_bank3)                       /* ROM (and reserved in Mode 20) */
243   AM_RANGE(0x600000, 0x6fffff) AM_READWRITE_LEGACY(snes_r_bank4, snes_w_bank4)    /* used by Mode 20 DSP-1 */
244   AM_RANGE(0x700000, 0x7dffff) AM_READWRITE_LEGACY(snes_r_bank5, snes_w_bank5)
245   AM_RANGE(0x7e0000, 0x7fffff) AM_RAM                                     /* 8KB Low RAM, 24KB High RAM, 96KB Expanded RAM */
246   AM_RANGE(0x800000, 0xbfffff) AM_READWRITE_LEGACY(snes_r_bank6, snes_w_bank6)    /* Mirror and ROM */
247   AM_RANGE(0xc00000, 0xffffff) AM_READWRITE_LEGACY(snes_r_bank7, snes_w_bank7)    /* Mirror and ROM */
240   AM_RANGE(0x000000, 0x7dffff) AM_READWRITE_LEGACY(snes_r_bank1, snes_w_bank1)
241   AM_RANGE(0x7e0000, 0x7fffff) AM_RAM                 /* 8KB Low RAM, 24KB High RAM, 96KB Expanded RAM */
242   AM_RANGE(0x800000, 0xffffff) AM_READWRITE_LEGACY(snes_r_bank2, snes_w_bank2)    /* Mirror and ROM */
248243ADDRESS_MAP_END
249244
250245READ8_MEMBER(snesb_state::spc_ram_100_r)
trunk/src/mame/drivers/sfcbox.c
r21643r21644
161161}
162162
163163static ADDRESS_MAP_START( snes_map, AS_PROGRAM, 8, sfcbox_state )
164   AM_RANGE(0x000000, 0x2fffff) AM_READWRITE_LEGACY(snes_r_bank1, snes_w_bank1)    /* I/O and ROM (repeats for each bank) */
165   AM_RANGE(0x300000, 0x3fffff) AM_READWRITE_LEGACY(snes_r_bank2, snes_w_bank2)    /* I/O and ROM (repeats for each bank) */
166   AM_RANGE(0x400000, 0x5fffff) AM_READ_LEGACY(snes_r_bank3)                       /* ROM (and reserved in Mode 20) */
167   AM_RANGE(0x600000, 0x6fffff) AM_READWRITE_LEGACY(snes_r_bank4, snes_w_bank4)    /* used by Mode 20 DSP-1 */
168   AM_RANGE(0x700000, 0x7dffff) AM_READWRITE_LEGACY(snes_r_bank5, snes_w_bank5)
164   AM_RANGE(0x000000, 0x7dffff) AM_READWRITE_LEGACY(snes_r_bank1, snes_w_bank1)
169165   AM_RANGE(0x7e0000, 0x7fffff) AM_RAM                 /* 8KB Low RAM, 24KB High RAM, 96KB Expanded RAM */
170   AM_RANGE(0x800000, 0xbfffff) AM_READWRITE_LEGACY(snes_r_bank6, snes_w_bank6)    /* Mirror and ROM */
171   AM_RANGE(0xc00000, 0xffffff) AM_READWRITE_LEGACY(snes_r_bank7, snes_w_bank7)    /* Mirror and ROM */
166   AM_RANGE(0x800000, 0xffffff) AM_READWRITE_LEGACY(snes_r_bank2, snes_w_bank2)    /* Mirror and ROM */
172167ADDRESS_MAP_END
173168
174169READ8_MEMBER(sfcbox_state::spc_ram_100_r)
trunk/src/mame/drivers/nss.c
r21643r21644
345345
346346
347347static ADDRESS_MAP_START( snes_map, AS_PROGRAM, 8, nss_state )
348   AM_RANGE(0x000000, 0x2fffff) AM_READWRITE_LEGACY(snes_r_bank1, snes_w_bank1)    /* I/O and ROM (repeats for each bank) */
349   AM_RANGE(0x300000, 0x3fffff) AM_READWRITE_LEGACY(snes_r_bank2, snes_w_bank2)    /* I/O and ROM (repeats for each bank) */
350   AM_RANGE(0x400000, 0x5fffff) AM_READ_LEGACY(snes_r_bank3)                       /* ROM (and reserved in Mode 20) */
351   AM_RANGE(0x600000, 0x6fffff) AM_READWRITE_LEGACY(snes_r_bank4, snes_w_bank4)    /* used by Mode 20 DSP-1 */
352   AM_RANGE(0x700000, 0x7dffff) AM_READWRITE_LEGACY(snes_r_bank5, snes_w_bank5)
348   AM_RANGE(0x000000, 0x7dffff) AM_READWRITE_LEGACY(snes_r_bank1, snes_w_bank1)
353349   AM_RANGE(0x7e0000, 0x7fffff) AM_RAM                 /* 8KB Low RAM, 24KB High RAM, 96KB Expanded RAM */
354   AM_RANGE(0x800000, 0xbfffff) AM_READWRITE_LEGACY(snes_r_bank6, snes_w_bank6)    /* Mirror and ROM */
355   AM_RANGE(0xc00000, 0xffffff) AM_READWRITE_LEGACY(snes_r_bank7, snes_w_bank7)    /* Mirror and ROM */
350   AM_RANGE(0x800000, 0xffffff) AM_READWRITE_LEGACY(snes_r_bank2, snes_w_bank2)    /* Mirror and ROM */
356351ADDRESS_MAP_END
357352
358353READ8_MEMBER(nss_state::spc_ram_100_r)
trunk/src/mame/machine/snes.c
r21643r21644
676676
677677*/
678678
679/* 0x000000 - 0x2fffff */
679/* 0x000000 - 0x7dffff */
680680READ8_HANDLER( snes_r_bank1 )
681681{
682682   snes_state *state = space.machine().driver_data<snes_state>();
683683   UINT8 value = 0xff;
684684   UINT16 address = offset & 0xffff;
685685
686   if (address < 0x2000)                                           /* Mirror of Low RAM */
687      value = space.read_byte(0x7e0000 + address);
688   else if (address < 0x6000)                                      /* I/O */
689      value = state->snes_r_io(space, address);
690   else if (address < 0x8000)
686   if (offset < 0x400000)
691687   {
692      logerror("(PC=%06x) snes_r_bank1: Unmapped external chip read: %04x\n", space.device().safe_pc(), address);
693      value = snes_open_bus_r(space, 0);                              /* Reserved */
694   }
695   else
696      value = snes_ram[offset];   //ROM
697
698   return value;
699}
700
701/* 0x300000 - 0x3fffff */
702READ8_HANDLER( snes_r_bank2 )
703{
704   snes_state *state = space.machine().driver_data<snes_state>();
705   UINT8 value = 0xff;
706   UINT16 address = offset & 0xffff;
707
708   if (address < 0x2000)                                           /* Mirror of Low RAM */
709      value = space.read_byte(0x7e0000 + address);
710   else if (address < 0x6000)                                      /* I/O */
711      value = state->snes_r_io(space, address);
712   else if (address < 0x8000)                                      /* SRAM for mode_21, Reserved othewise */
713   {
714      if (state->m_cart[0].mode == SNES_MODE_21 && state->m_cart[0].m_nvram_size > 0)
688      if (address < 0x2000)                                           /* Mirror of Low RAM */
689         value = space.read_byte(0x7e0000 + address);
690      else if (address < 0x6000)                                      /* I/O */
691         value = state->snes_r_io(space, address);
692      else if (address < 0x8000)
715693      {
716         /* Donkey Kong Country checks this and detects a copier if 0x800 is not masked out due to sram size */
717         /* OTOH Secret of Mana does not work properly if sram is not mirrored on later banks */
718         int mask = (state->m_cart[0].m_nvram_size - 1) & 0x7fff; /* Limit SRAM size to what's actually present */
719         value = state->m_cart[0].m_nvram[(offset - 0x6000) & mask];
694         if (offset >= 0x300000 && state->m_cart[0].mode == SNES_MODE_21 && state->m_cart[0].m_nvram_size > 0)
695         {
696            /* Donkey Kong Country checks this and detects a copier if 0x800 is not masked out due to sram size */
697            /* OTOH Secret of Mana does not work properly if sram is not mirrored on later banks */
698            int mask = (state->m_cart[0].m_nvram_size - 1) & 0x7fff; /* Limit SRAM size to what's actually present */
699            value = state->m_cart[0].m_nvram[(offset - 0x6000) & mask];
700         }
701         else
702            value = snes_open_bus_r(space, 0);                              /* Reserved */
720703      }
721704      else
722      {
723         logerror("(PC=%06x) snes_r_bank2: Unmapped external chip read: %04x\n", space.device().safe_pc(), address );
724         value = snes_open_bus_r(space, 0);
725      }
705         value = snes_ram[offset];   //ROM
726706   }
727   else
728      value = snes_ram[0x300000 + offset];    //ROM
729
730   return value;
731}
732
733/* 0x400000 - 0x5fffff */
734READ8_HANDLER( snes_r_bank3 )
735{
736   snes_state *state = space.machine().driver_data<snes_state>();
737   UINT8 value = 0xff;
738   UINT16 address = offset & 0xffff;
739
740   if (state->m_cart[0].mode & 5)  /* Mode 20 & 22 */
707   else if (offset < 0x700000)
741708   {
742      if (address < 0x8000 && state->m_cart[0].mode == SNES_MODE_20)
743         value = snes_open_bus_r(space, 0);                          /* Reserved */
709      if (state->m_cart[0].mode & 5 && address < 0x8000)  /* Mode 20 & 22 in 0x0000-0x7fff */
710         value = snes_open_bus_r(space, 0);
744711      else
745         value = snes_ram[0x400000 + offset];    //ROM
712         value = snes_ram[offset];    //ROM
746713   }
747   else                                            /* Mode 21 & 25 */
748      value = snes_ram[0x400000 + offset];    //ROM
749
750   return value;
751}
752
753/* 0x600000 - 0x6fffff */
754READ8_HANDLER( snes_r_bank4 )
755{
756   snes_state *state = space.machine().driver_data<snes_state>();
757   UINT8 value = 0xff;
758   UINT16 address = offset & 0xffff;
759
760   if (state->m_cart[0].mode & 5)                         /* Mode 20 & 22 */
761   {
762      if (address >= 0x8000)
763         value = snes_ram[0x600000 + offset];    //ROM
764      else
765      {
766         logerror("(PC=%06x) snes_r_bank4: Unmapped external chip read: %04x\n", space.device().safe_pc(), address);
767         value = snes_open_bus_r(space, 0);                          /* Reserved */
768      }
769   }
770   else if (state->m_cart[0].mode & 0x0a)                  /* Mode 21 & 25 */
771      value = snes_ram[0x600000 + offset];    //ROM
772
773   return value;
774}
775
776/* 0x700000 - 0x7dffff */
777READ8_HANDLER( snes_r_bank5 )
778{
779   snes_state *state = space.machine().driver_data<snes_state>();
780   UINT8 value;
781   UINT16 address = offset & 0xffff;
782
783   if (state->m_cart[0].mode & 5 && address < 0x8000)     /* Mode 20 & 22 */
784   {
785      if (state->m_cart[0].m_nvram_size > 0x8000)
786      {
787         // In this case, SRAM is mapped in 0x8000 chunks at diff offsets: 0x700000-0x707fff, 0x710000-0x717fff, etc.
788         int mask = state->m_cart[0].m_nvram_size - 1;
789         offset = (offset / 0x10000) * 0x8000 + (offset & 0x7fff);
790         value = state->m_cart[0].m_nvram[offset & mask];
791      }
792      else if (state->m_cart[0].m_nvram_size > 0)
793      {
794         int mask = state->m_cart[0].m_nvram_size - 1;   /* Limit SRAM size to what's actually present */
795         value = state->m_cart[0].m_nvram[offset & mask];
796      }
797      else
798      {
799         logerror("(PC=%06x) snes_r_bank5: Unmapped external chip read: %04x\n", space.device().safe_pc(), address);
800         value = snes_open_bus_r(space, 0);                              /* Reserved */
801      }
802   }
803714   else
804      value = snes_ram[0x700000 + offset];    //ROM
805
806   return value;
807}
808
809/* 0x800000 - 0xbfffff */
810READ8_HANDLER( snes_r_bank6 )
811{
812   UINT8 value = 0;
813
814   if ((offset & 0xffff) < 0x8000)
815      value = space.read_byte(offset);
816   else
817      value = snes_ram[0x800000 + offset];    //ROM
818
819   return value;
820}
821
822/* 0xc00000 - 0xffffff */
823READ8_HANDLER( snes_r_bank7 )
824{
825   snes_state *state = space.machine().driver_data<snes_state>();
826   UINT8 value = 0;
827   UINT16 address = offset & 0xffff;
828
829   if (state->m_cart[0].mode & 5 && address < 0x8000)      /* Mode 20 & 22 in 0x0000-0x7fff */
830715   {
831      if (offset < 0x300000)
832         value = space.read_byte(0x400000 + offset);
833      else
716      if (state->m_cart[0].mode & 5 && address < 0x8000)     /* Mode 20 & 22 */
834717      {
835718         if (state->m_cart[0].m_nvram_size > 0x8000)
836719         {
r21643r21644
846729         }
847730         else
848731         {
849            logerror("(PC=%06x) snes_r_bank7: Unmapped external chip read: %04x\n", space.device().safe_pc(), address);
732            logerror("(PC=%06x) snes_r_bank1: Unmapped external chip read: %X\n", space.device().safe_pc(), offset);
850733            value = snes_open_bus_r(space, 0);                              /* Reserved */
851734         }
852735      }
736      else
737         value = snes_ram[offset];    //ROM
853738   }
854   else
855      value = snes_ram[0xc00000 + offset];    //ROM
856
739   
857740   return value;
858741}
859742
860743
861/* 0x000000 - 0x2fffff */
862WRITE8_HANDLER( snes_w_bank1 )
744/* 0x800000 - 0xffffff */
745READ8_HANDLER( snes_r_bank2 )
863746{
864747   snes_state *state = space.machine().driver_data<snes_state>();
748   UINT8 value = 0;
865749   UINT16 address = offset & 0xffff;
866750
867   if (address < 0x2000)                           /* Mirror of Low RAM */
868      space.write_byte(0x7e0000 + address, data);
869   else if (address < 0x6000)                      /* I/O */
870      state->snes_w_io(space, address, data);
871   else if (address < 0x8000)
872      logerror("(PC=%06x) snes_w_bank1: Attempt to write to reserved address: %x = %02x\n", space.device().safe_pc(), offset, data);
751   if (offset < 0x400000)
752   {
753      if (address < 0x8000)
754         value = space.read_byte(offset);
755      else
756         value = snes_ram[0x800000 + offset];    //ROM
757   }
873758   else
874      logerror("(PC=%06x) Attempt to write to ROM address: %X\n", space.device().safe_pc(), offset);
875}
876
877/* 0x300000 - 0x3fffff */
878WRITE8_HANDLER( snes_w_bank2 )
879{
880   snes_state *state = space.machine().driver_data<snes_state>();
881   UINT16 address = offset & 0xffff;
882
883   if (address < 0x2000)                           /* Mirror of Low RAM */
884      space.write_byte(0x7e0000 + address, data);
885   else if (address < 0x6000)                      /* I/O */
886      state->snes_w_io(space, address, data);
887   else if (address < 0x8000)                      /* SRAM for mode_21, Reserved othewise */
888759   {
889      if (state->m_cart[0].mode == SNES_MODE_21 && state->m_cart[0].m_nvram_size > 0)
760      if (state->m_cart[0].mode & 5 && address < 0x8000)      /* Mode 20 & 22 in 0x0000-0x7fff */
890761      {
891         /* Donkey Kong Country checks this and detects a copier if 0x800 is not masked out due to sram size */
892         /* OTOH Secret of Mana does not work properly if sram is not mirrored on later banks */
893         int mask = (state->m_cart[0].m_nvram_size - 1) & 0x7fff; /* Limit SRAM size to what's actually present */
894         state->m_cart[0].m_nvram[(offset - 0x6000) & mask] = data;
762         if (offset < 0x700000)
763            value = space.read_byte(offset);
764         else
765         {
766            if (state->m_cart[0].m_nvram_size > 0x8000)
767            {
768               // In this case, SRAM is mapped in 0x8000 chunks at diff offsets: 0x700000-0x707fff, 0x710000-0x717fff, etc.
769               int mask = state->m_cart[0].m_nvram_size - 1;
770               offset = (offset / 0x10000) * 0x8000 + (offset & 0x7fff);
771               value = state->m_cart[0].m_nvram[offset & mask];
772            }
773            else if (state->m_cart[0].m_nvram_size > 0)
774            {
775               int mask = state->m_cart[0].m_nvram_size - 1;   /* Limit SRAM size to what's actually present */
776               value = state->m_cart[0].m_nvram[offset & mask];
777            }
778            else
779            {
780               logerror("(PC=%06x) snes_r_bank2: Unmapped external chip read: %X\n", space.device().safe_pc(), offset);
781               value = snes_open_bus_r(space, 0);                              /* Reserved */
782            }
783         }
895784      }
896785      else
897         logerror("(PC=%06x) snes_w_bank2: Attempt to write to reserved address: %X = %02x\n", space.device().safe_pc(), offset + 0x300000, data);
786         value = snes_ram[0x800000 + offset];    //ROM
898787   }
899   else
900      logerror("(PC=%06x) Attempt to write to ROM address: %X\n", space.device().safe_pc(), offset + 0x300000);
788     
789   return value;
901790}
902791
903/* 0x600000 - 0x6fffff */
904WRITE8_HANDLER( snes_w_bank4 )
792
793/* 0x000000 - 0x7dffff */
794WRITE8_HANDLER( snes_w_bank1 )
905795{
906796   snes_state *state = space.machine().driver_data<snes_state>();
907797   UINT16 address = offset & 0xffff;
908798
909   if (state->m_cart[0].mode & 5)                 /* Mode 20 & 22 */
799   if (offset < 0x400000)
910800   {
911      if (address >= 0x8000)
912         logerror("(PC=%06x) Attempt to write to ROM address: %X\n", space.device().safe_pc(), offset + 0x600000);
801      if (address < 0x2000)                           /* Mirror of Low RAM */
802         space.write_byte(0x7e0000 + address, data);
803      else if (address < 0x6000)                      /* I/O */
804         state->snes_w_io(space, address, data);
805      else if (address < 0x8000)
806      {
807         if (offset >= 0x300000 && state->m_cart[0].mode == SNES_MODE_21 && state->m_cart[0].m_nvram_size > 0)
808         {
809            /* Donkey Kong Country checks this and detects a copier if 0x800 is not masked out due to sram size */
810            /* OTOH Secret of Mana does not work properly if sram is not mirrored on later banks */
811            int mask = (state->m_cart[0].m_nvram_size - 1) & 0x7fff; /* Limit SRAM size to what's actually present */
812            state->m_cart[0].m_nvram[(offset - 0x6000) & mask] = data;
813         }
814         else
815            logerror("(PC=%06x) snes_w_bank1: Attempt to write to reserved address: %X = %02X\n", space.device().safe_pc(), offset, data);
816      }         
913817      else
914         logerror("(PC=%06x) snes_w_bank4: Attempt to write to reserved address: %X = %02x\n", space.device().safe_pc(), offset + 0x600000, data);
818         logerror("(PC=%06x) Attempt to write to ROM address: %X\n", space.device().safe_pc(), offset);
915819   }
916   else if (state->m_cart[0].mode & 0x0a)
917      logerror("(PC=%06x) Attempt to write to ROM address: %X\n", space.device().safe_pc(), offset + 0x600000);
918}
919
920/* 0x700000 - 0x7dffff */
921WRITE8_HANDLER( snes_w_bank5 )
922{
923   snes_state *state = space.machine().driver_data<snes_state>();
924   UINT16 address = offset & 0xffff;
925
926   if (state->m_cart[0].mode & 5 && address < 0x8000)       /* Mode 20 & 22 */
820   else if (offset >= 0x600000 && offset < 0x700000)
927821   {
928      if (state->m_cart[0].m_nvram_size > 0x8000)
929      {
930         // In this case, SRAM is mapped in 0x8000 chunks at diff offsets: 0x700000-0x707fff, 0x710000-0x717fff, etc.
931         int mask = state->m_cart[0].m_nvram_size - 1;
932         offset = (offset / 0x10000) * 0x8000 + (offset & 0x7fff);
933         state->m_cart[0].m_nvram[offset & mask] = data;
934      }
935      else if (state->m_cart[0].m_nvram_size > 0)
936      {
937         int mask = state->m_cart[0].m_nvram_size - 1;   /* Limit SRAM size to what's actually present */
938         state->m_cart[0].m_nvram[offset & mask] = data;
939      }
822      if (state->m_cart[0].mode & 5 && address < 0x8000)        /* Mode 20 & 22 */
823         logerror("(PC=%06x) snes_w_bank1: Attempt to write to reserved address: %X = %02X\n", space.device().safe_pc(), offset, data);
940824      else
941         logerror("(PC=%06x) snes_w_bank5: Attempt to write to reserved address: %X = %02x\n", space.device().safe_pc(), offset + 0x700000, data);
825         logerror("(PC=%06x) Attempt to write to ROM address: %X\n", space.device().safe_pc(), offset);
942826   }
943   else
944      logerror("(PC=%06x) Attempt to write to ROM address: %X\n", space.device().safe_pc(), offset + 0x700000);
945}
946
947
948/* 0x800000 - 0xbfffff */
949WRITE8_HANDLER( snes_w_bank6 )
950{
951   if ((offset & 0xffff) < 0x8000)
952      space.write_byte(offset, data);
953   else
954      logerror("(PC=%06x) Attempt to write to ROM address: %X\n", space.device().safe_pc(), offset + 0x800000);
955}
956
957
958/* 0xc00000 - 0xffffff */
959WRITE8_HANDLER( snes_w_bank7 )
960{
961   snes_state *state = space.machine().driver_data<snes_state>();
962   UINT16 address = offset & 0xffff;
963
964   if (state->m_cart[0].mode & 5 && address < 0x8000)      /* Mode 20 & 22 in 0x0000-0x7fff */
827   else if (offset >= 0x700000)
965828   {
966      if (offset >= 0x300000)
829      if (state->m_cart[0].mode & 5 && address < 0x8000)         /* Mode 20 & 22 */
967830      {
968831         if (state->m_cart[0].m_nvram_size > 0x8000)
969832         {
r21643r21644
971834            int mask = state->m_cart[0].m_nvram_size - 1;
972835            offset = (offset / 0x10000) * 0x8000 + (offset & 0x7fff);
973836            state->m_cart[0].m_nvram[offset & mask] = data;
974            return;
975837         }
976838         else if (state->m_cart[0].m_nvram_size > 0)
977839         {
978840            int mask = state->m_cart[0].m_nvram_size - 1;   /* Limit SRAM size to what's actually present */
979841            state->m_cart[0].m_nvram[offset & mask] = data;
980            return;
981842         }
843         else
844            logerror("(PC=%06x) snes_w_bank1: Attempt to write to reserved address: %X = %02X\n", space.device().safe_pc(), offset, data);
982845      }
983846      else
984         logerror("(PC=%06x) snes_w_bank7: Attempt to write to ROM address: %X = %02x\n", space.device().safe_pc(), offset + 0xc00000, data);
847         logerror("(PC=%06x) Attempt to write to ROM address: %X\n", space.device().safe_pc(), offset);
985848   }
986   else if (state->m_cart[0].mode & 0x0a)
987      logerror("(PC=%06x) Attempt to write to ROM address: %X\n", space.device().safe_pc(), offset + 0xc00000);
988849}
989850
851/* 0x800000 - 0xffffff */
852WRITE8_HANDLER( snes_w_bank2 )
853{
854   snes_state *state = space.machine().driver_data<snes_state>();
855   UINT16 address = offset & 0xffff;
856   
857   if (offset < 0x400000)
858   {
859      if (address < 0x8000)
860         space.write_byte(offset, data);
861      else
862         logerror("(PC=%06x) Attempt to write to ROM address: %X\n", space.device().safe_pc(), offset + 0x800000);
863   }
864   else
865   {
866      if (state->m_cart[0].mode & 5 && address < 0x8000)      /* Mode 20 & 22 in 0x0000-0x7fff */
867      {
868         if (offset < 0x700000)
869            space.write_byte(offset, data);
870         else
871         {
872            if (state->m_cart[0].m_nvram_size > 0x8000)
873            {
874               // In this case, SRAM is mapped in 0x8000 chunks at diff offsets: 0x700000-0x707fff, 0x710000-0x717fff, etc.
875               int mask = state->m_cart[0].m_nvram_size - 1;
876               offset = (offset / 0x10000) * 0x8000 + (offset & 0x7fff);
877               state->m_cart[0].m_nvram[offset & mask] = data;
878            }
879            else if (state->m_cart[0].m_nvram_size > 0)
880            {
881               int mask = state->m_cart[0].m_nvram_size - 1;   /* Limit SRAM size to what's actually present */
882               state->m_cart[0].m_nvram[offset & mask] = data;
883            }
884            else
885               logerror("(PC=%06x) snes_w_bank2: Attempt to write to reserved address: %X = %02X\n", space.device().safe_pc(), offset, data);
886         }
887      }
888      else
889         logerror("(PC=%06x) Attempt to write to ROM address: %X\n", space.device().safe_pc(), offset);
890   }
891}
990892
893
991894/*************************************
992895
993896    Input Callbacks
trunk/src/mame/includes/snes.h
r21643r21644
757757
758758extern DECLARE_READ8_HANDLER( snes_r_bank1 );
759759extern DECLARE_READ8_HANDLER( snes_r_bank2 );
760extern DECLARE_READ8_HANDLER( snes_r_bank3 );
761extern DECLARE_READ8_HANDLER( snes_r_bank4 );
762extern DECLARE_READ8_HANDLER( snes_r_bank5 );
763extern DECLARE_READ8_HANDLER( snes_r_bank6 );
764extern DECLARE_READ8_HANDLER( snes_r_bank7 );
765760extern DECLARE_WRITE8_HANDLER( snes_w_bank1 );
766761extern DECLARE_WRITE8_HANDLER( snes_w_bank2 );
767extern DECLARE_WRITE8_HANDLER( snes_w_bank4 );
768extern DECLARE_WRITE8_HANDLER( snes_w_bank5 );
769extern DECLARE_WRITE8_HANDLER( snes_w_bank6 );
770extern DECLARE_WRITE8_HANDLER( snes_w_bank7 );
771762
772763extern UINT8  *snes_ram;            /* Main memory */
773764

Previous 199869 Revisions Next


© 1997-2024 The MAME Team