Previous 199869 Revisions Next

r22740 Friday 10th May, 2013 at 15:13:53 UTC by Fabio Priuli
snes.c: minor cleanup in the code used by nss and other snes-based arcade drivers. nw.
[src/mame/includes]snes.h
[src/mame/machine]snes.c

trunk/src/mame/machine/snes.c
r22739r22740
678678   UINT8 value = 0xff;
679679   UINT8 base_bank = (offset < 0x800000) ? 0x80 : 0x00;
680680
681   switch (m_cart[0].mode)
681   switch (m_cart.mode)
682682   {
683683      case SNES_MODE_20:
684684      case SNES_MODE_22:
685         addr = (m_cart[0].rom_bank_map[offset/0x10000] * 0x8000) + (offset & 0x7fff);
686         value = m_cart[0].m_rom[addr];
685         addr = (m_cart.rom_bank_map[offset/0x10000] * 0x8000) + (offset & 0x7fff);
686         value = m_cart.m_rom[addr];
687687         break;
688688      case SNES_MODE_21:
689689      case SNES_MODE_25:
690690         offset &= 0x3fffff;
691         addr = (m_cart[0].rom_bank_map[base_bank + (offset/0x8000)] * 0x8000) + (offset & 0x7fff);
692         value = m_cart[0].m_rom[addr];
691         addr = (m_cart.rom_bank_map[base_bank + (offset/0x8000)] * 0x8000) + (offset & 0x7fff);
692         value = m_cart.m_rom[addr];
693693         break;
694694   }
695695
r22739r22740
710710         value = snes_r_io(space, address);
711711      else if (address < 0x8000)
712712      {
713         if (offset >= 0x300000 && m_cart[0].mode == SNES_MODE_21 && m_cart[0].m_nvram_size > 0)
713         if (offset >= 0x300000 && m_cart.mode == SNES_MODE_21 && m_cart.m_nvram_size > 0)
714714         {
715715            /* Donkey Kong Country checks this and detects a copier if 0x800 is not masked out due to sram size */
716716            /* OTOH Secret of Mana does not work properly if sram is not mirrored on later banks */
717            int mask = (m_cart[0].m_nvram_size - 1) & 0x7fff; /* Limit SRAM size to what's actually present */
718            value = m_cart[0].m_nvram[(offset - 0x6000) & mask];
717            int mask = (m_cart.m_nvram_size - 1) & 0x7fff; /* Limit SRAM size to what's actually present */
718            value = m_cart.m_nvram[(offset - 0x6000) & mask];
719719         }
720720         else
721721            value = snes_open_bus_r(space, 0);                              /* Reserved */
r22739r22740
725725   }
726726   else if (offset < 0x700000)
727727   {
728      if (m_cart[0].mode & 5 && address < 0x8000)  /* Mode 20 & 22 in 0x0000-0x7fff */
728      if (m_cart.mode & 5 && address < 0x8000)  /* Mode 20 & 22 in 0x0000-0x7fff */
729729         value = snes_open_bus_r(space, 0);
730730      else
731731         value = snes_rom_access(offset);    //ROM
732732   }
733733   else
734734   {
735      if (m_cart[0].mode & 5 && address < 0x8000)     /* Mode 20 & 22 */
735      if (m_cart.mode & 5 && address < 0x8000)     /* Mode 20 & 22 */
736736      {
737         if (m_cart[0].m_nvram_size > 0x8000)
737         if (m_cart.m_nvram_size > 0x8000)
738738         {
739739            // In this case, SRAM is mapped in 0x8000 chunks at diff offsets: 0x700000-0x707fff, 0x710000-0x717fff, etc.
740            int mask = m_cart[0].m_nvram_size - 1;
740            int mask = m_cart.m_nvram_size - 1;
741741            offset = (offset / 0x10000) * 0x8000 + (offset & 0x7fff);
742            value = m_cart[0].m_nvram[offset & mask];
742            value = m_cart.m_nvram[offset & mask];
743743         }
744         else if (m_cart[0].m_nvram_size > 0)
744         else if (m_cart.m_nvram_size > 0)
745745         {
746            int mask = m_cart[0].m_nvram_size - 1;   /* Limit SRAM size to what's actually present */
747            value = m_cart[0].m_nvram[offset & mask];
746            int mask = m_cart.m_nvram_size - 1;   /* Limit SRAM size to what's actually present */
747            value = m_cart.m_nvram[offset & mask];
748748         }
749749         else
750750         {
r22739r22740
775775   }
776776   else
777777   {
778      if (m_cart[0].mode & 5 && address < 0x8000)      /* Mode 20 & 22 in 0x0000-0x7fff */
778      if (m_cart.mode & 5 && address < 0x8000)      /* Mode 20 & 22 in 0x0000-0x7fff */
779779      {
780780         if (offset < 0x700000)
781781            value = space.read_byte(offset);
782782         else
783783         {
784            if (m_cart[0].m_nvram_size > 0x8000)
784            if (m_cart.m_nvram_size > 0x8000)
785785            {
786786               // In this case, SRAM is mapped in 0x8000 chunks at diff offsets: 0x700000-0x707fff, 0x710000-0x717fff, etc.
787               int mask = m_cart[0].m_nvram_size - 1;
787               int mask = m_cart.m_nvram_size - 1;
788788               offset = (offset / 0x10000) * 0x8000 + (offset & 0x7fff);
789               value = m_cart[0].m_nvram[offset & mask];
789               value = m_cart.m_nvram[offset & mask];
790790            }
791            else if (m_cart[0].m_nvram_size > 0)
791            else if (m_cart.m_nvram_size > 0)
792792            {
793               int mask = m_cart[0].m_nvram_size - 1;   /* Limit SRAM size to what's actually present */
794               value = m_cart[0].m_nvram[offset & mask];
793               int mask = m_cart.m_nvram_size - 1;   /* Limit SRAM size to what's actually present */
794               value = m_cart.m_nvram[offset & mask];
795795            }
796796            else
797797            {
r22739r22740
821821         snes_w_io(space, address, data);
822822      else if (address < 0x8000)
823823      {
824         if (offset >= 0x300000 && m_cart[0].mode == SNES_MODE_21 && m_cart[0].m_nvram_size > 0)
824         if (offset >= 0x300000 && m_cart.mode == SNES_MODE_21 && m_cart.m_nvram_size > 0)
825825         {
826826            /* Donkey Kong Country checks this and detects a copier if 0x800 is not masked out due to sram size */
827827            /* OTOH Secret of Mana does not work properly if sram is not mirrored on later banks */
828            int mask = (m_cart[0].m_nvram_size - 1) & 0x7fff; /* Limit SRAM size to what's actually present */
829            m_cart[0].m_nvram[(offset - 0x6000) & mask] = data;
828            int mask = (m_cart.m_nvram_size - 1) & 0x7fff; /* Limit SRAM size to what's actually present */
829            m_cart.m_nvram[(offset - 0x6000) & mask] = data;
830830         }
831831         else
832832            logerror("(PC=%06x) snes_w_bank1: Attempt to write to reserved address: %X = %02X\n", space.device().safe_pc(), offset, data);
r22739r22740
836836   }
837837   else if (offset >= 0x600000 && offset < 0x700000)
838838   {
839      if (m_cart[0].mode & 5 && address < 0x8000)        /* Mode 20 & 22 */
839      if (m_cart.mode & 5 && address < 0x8000)        /* Mode 20 & 22 */
840840         logerror("(PC=%06x) snes_w_bank1: Attempt to write to reserved address: %X = %02X\n", space.device().safe_pc(), offset, data);
841841      else
842842         logerror("(PC=%06x) Attempt to write to ROM address: %X\n", space.device().safe_pc(), offset);
843843   }
844844   else if (offset >= 0x700000)
845845   {
846      if (m_cart[0].mode & 5 && address < 0x8000)         /* Mode 20 & 22 */
846      if (m_cart.mode & 5 && address < 0x8000)         /* Mode 20 & 22 */
847847      {
848         if (m_cart[0].m_nvram_size > 0x8000)
848         if (m_cart.m_nvram_size > 0x8000)
849849         {
850850            // In this case, SRAM is mapped in 0x8000 chunks at diff offsets: 0x700000-0x707fff, 0x710000-0x717fff, etc.
851            int mask = m_cart[0].m_nvram_size - 1;
851            int mask = m_cart.m_nvram_size - 1;
852852            offset = (offset / 0x10000) * 0x8000 + (offset & 0x7fff);
853            m_cart[0].m_nvram[offset & mask] = data;
853            m_cart.m_nvram[offset & mask] = data;
854854         }
855         else if (m_cart[0].m_nvram_size > 0)
855         else if (m_cart.m_nvram_size > 0)
856856         {
857            int mask = m_cart[0].m_nvram_size - 1;   /* Limit SRAM size to what's actually present */
858            m_cart[0].m_nvram[offset & mask] = data;
857            int mask = m_cart.m_nvram_size - 1;   /* Limit SRAM size to what's actually present */
858            m_cart.m_nvram[offset & mask] = data;
859859         }
860860         else
861861            logerror("(PC=%06x) snes_w_bank1: Attempt to write to reserved address: %X = %02X\n", space.device().safe_pc(), offset, data);
r22739r22740
879879   }
880880   else
881881   {
882      if (m_cart[0].mode & 5 && address < 0x8000)      /* Mode 20 & 22 in 0x0000-0x7fff */
882      if (m_cart.mode & 5 && address < 0x8000)      /* Mode 20 & 22 in 0x0000-0x7fff */
883883      {
884884         if (offset < 0x700000)
885885            space.write_byte(offset, data);
886886         else
887887         {
888            if (m_cart[0].m_nvram_size > 0x8000)
888            if (m_cart.m_nvram_size > 0x8000)
889889            {
890890               // In this case, SRAM is mapped in 0x8000 chunks at diff offsets: 0x700000-0x707fff, 0x710000-0x717fff, etc.
891               int mask = m_cart[0].m_nvram_size - 1;
891               int mask = m_cart.m_nvram_size - 1;
892892               offset = (offset / 0x10000) * 0x8000 + (offset & 0x7fff);
893               m_cart[0].m_nvram[offset & mask] = data;
893               m_cart.m_nvram[offset & mask] = data;
894894            }
895            else if (m_cart[0].m_nvram_size > 0)
895            else if (m_cart.m_nvram_size > 0)
896896            {
897               int mask = m_cart[0].m_nvram_size - 1;   /* Limit SRAM size to what's actually present */
898               m_cart[0].m_nvram[offset & mask] = data;
897               int mask = m_cart.m_nvram_size - 1;   /* Limit SRAM size to what's actually present */
898               m_cart.m_nvram[offset & mask] = data;
899899            }
900900            else
901901               logerror("(PC=%06x) snes_w_bank2: Attempt to write to reserved address: %X = %02X\n", space.device().safe_pc(), offset, data);
r22739r22740
11521152   int i;
11531153   // setup the rom_bank_map array to faster ROM read
11541154   for (i = 0; i < size / 0x8000; i++)
1155      m_cart[0].rom_bank_map[i] = i;
1155      m_cart.rom_bank_map[i] = i;
11561156
11571157   // fill up remaining blocks with mirrors
11581158   while (i % 256)
r22739r22740
11621162         j++;
11631163      repeat_banks = i % (256 >> (j - 1));
11641164      for (int k = 0; k < repeat_banks; k++)
1165         m_cart[0].rom_bank_map[i + k] = m_cart[0].rom_bank_map[i + k - repeat_banks];
1165         m_cart.rom_bank_map[i + k] = m_cart.rom_bank_map[i + k - repeat_banks];
11661166      i += repeat_banks;
11671167   }
11681168}
r22739r22740
11701170/* for mame we use an init, maybe we will need more for the different games */
11711171DRIVER_INIT_MEMBER(snes_state,snes)
11721172{
1173   m_cart[0].m_rom_size = memregion("user3")->bytes();
1174   m_cart[0].m_rom = memregion("user3")->base();
1175   rom_map_setup(m_cart[0].m_rom_size);
1173   m_cart.m_rom_size = memregion("user3")->bytes();
1174   m_cart.m_rom = memregion("user3")->base();
1175   rom_map_setup(m_cart.m_rom_size);
11761176
1177   m_cart[0].m_nvram_size = 0;
1178   if (m_cart[0].m_rom[0x7fd8] > 0)
1177   m_cart.m_nvram_size = 0;
1178   if (m_cart.m_rom[0x7fd8] > 0)
11791179   {
1180      UINT32 nvram_size = (1024 << m_cart[0].m_rom[0x7fd8]);
1180      UINT32 nvram_size = (1024 << m_cart.m_rom[0x7fd8]);
11811181      if (nvram_size > 0x40000)
11821182         nvram_size = 0x40000;
11831183
1184      m_cart[0].m_nvram = auto_alloc_array_clear(machine(), UINT8, nvram_size);
1185      m_cart[0].m_nvram_size = nvram_size;
1184      m_cart.m_nvram = auto_alloc_array_clear(machine(), UINT8, nvram_size);
1185      m_cart.m_nvram_size = nvram_size;
11861186   }
11871187
11881188   /* all NSS games seem to use MODE 20 */
1189   m_cart[0].mode = SNES_MODE_20;
1190   m_has_addon_chip = HAS_NONE;
1189   m_cart.mode = SNES_MODE_20;
11911190}
11921191
11931192DRIVER_INIT_MEMBER(snes_state,snes_hirom)
11941193{
1195   m_cart[0].m_rom_size = memregion("user3")->bytes();
1196   m_cart[0].m_rom = memregion("user3")->base();
1197   rom_map_setup(m_cart[0].m_rom_size);
1194   m_cart.m_rom_size = memregion("user3")->bytes();
1195   m_cart.m_rom = memregion("user3")->base();
1196   rom_map_setup(m_cart.m_rom_size);
11981197
1199   m_cart[0].m_nvram_size = 0;
1200   if (m_cart[0].m_rom[0xffd8] > 0)
1198   m_cart.m_nvram_size = 0;
1199   if (m_cart.m_rom[0xffd8] > 0)
12011200   {
1202      UINT32 nvram_size = (1024 << m_cart[0].m_rom[0xffd8]);
1201      UINT32 nvram_size = (1024 << m_cart.m_rom[0xffd8]);
12031202      if (nvram_size > 0x40000)
12041203         nvram_size = 0x40000;
12051204
1206      m_cart[0].m_nvram = auto_alloc_array_clear(machine(), UINT8, nvram_size);
1207      m_cart[0].m_nvram_size = nvram_size;
1205      m_cart.m_nvram = auto_alloc_array_clear(machine(), UINT8, nvram_size);
1206      m_cart.m_nvram_size = nvram_size;
12081207   }
12091208
1210   m_cart[0].mode = SNES_MODE_21;
1211   m_has_addon_chip = HAS_NONE;
1209   m_cart.mode = SNES_MODE_21;
12121210}
12131211
12141212
trunk/src/mame/includes/snes.h
r22739r22740
644644   read8_delegate      m_oldjoy2_read;
645645
646646   /* cart related */
647   UINT8 m_has_addon_chip;
648   snes_cart_info m_cart[2];   // the second one is used by MESS for Sufami Turbo and, eventually, BS-X
647   snes_cart_info m_cart;   // used by NSS/SFCBox only! to be moved in a derived class!
649648   void rom_map_setup(UINT32 size);
650649
651650   snes_ppu_class        m_ppu;

Previous 199869 Revisions Next


© 1997-2024 The MAME Team