Previous 199869 Revisions Next

r21700 Friday 8th March, 2013 at 10:23:47 UTC by Fabio Priuli
small modernization + small cleanup. nw.
[src/mame/drivers]nss.c sfcbox.c snesb.c
[src/mame/includes]snes.h
[src/mame/machine]snes.c

trunk/src/mame/machine/snes.c
r21699r21700
676676
677677*/
678678
679static UINT8 snes_rom_access(running_machine &machine, UINT32 offset)
679inline UINT8 snes_state::snes_rom_access(UINT32 offset)
680680{
681   snes_state *state = machine.driver_data<snes_state>();
682681   UINT32 addr;
683682   UINT8 value = 0xff;
684683   UINT8 base_bank = (offset < 0x800000) ? 0x80 : 0x00;
685684
686   switch (state->m_cart[0].mode)
685   switch (m_cart[0].mode)
687686   {
688687      case SNES_MODE_20:
689688      case SNES_MODE_22:
690         addr = (state->m_cart[0].rom_bank_map[offset/0x10000] * 0x8000) + (offset & 0x7fff);
691         value = state->m_cart[0].m_rom[addr];
689         addr = (m_cart[0].rom_bank_map[offset/0x10000] * 0x8000) + (offset & 0x7fff);
690         value = m_cart[0].m_rom[addr];
692691         break;
693692      case SNES_MODE_21:
694693      case SNES_MODE_25:
695694         offset &= 0x3fffff;
696         addr = (state->m_cart[0].rom_bank_map[base_bank + (offset/0x8000)] * 0x8000) + (offset & 0x7fff);
697         value = state->m_cart[0].m_rom[addr];
695         addr = (m_cart[0].rom_bank_map[base_bank + (offset/0x8000)] * 0x8000) + (offset & 0x7fff);
696         value = m_cart[0].m_rom[addr];
698697         break;
699698   }
700699
r21699r21700
702701}
703702
704703/* 0x000000 - 0x7dffff */
705READ8_HANDLER( snes_r_bank1 )
704READ8_MEMBER(snes_state::snes_r_bank1)
706705{
707   snes_state *state = space.machine().driver_data<snes_state>();
708706   UINT8 value = 0xff;
709707   UINT16 address = offset & 0xffff;
710708
r21699r21700
713711      if (address < 0x2000)                                           /* Mirror of Low RAM */
714712         value = space.read_byte(0x7e0000 + address);
715713      else if (address < 0x6000)                                      /* I/O */
716         value = state->snes_r_io(space, address);
714         value = snes_r_io(space, address);
717715      else if (address < 0x8000)
718716      {
719         if (offset >= 0x300000 && state->m_cart[0].mode == SNES_MODE_21 && state->m_cart[0].m_nvram_size > 0)
717         if (offset >= 0x300000 && m_cart[0].mode == SNES_MODE_21 && m_cart[0].m_nvram_size > 0)
720718         {
721719            /* Donkey Kong Country checks this and detects a copier if 0x800 is not masked out due to sram size */
722720            /* OTOH Secret of Mana does not work properly if sram is not mirrored on later banks */
723            int mask = (state->m_cart[0].m_nvram_size - 1) & 0x7fff; /* Limit SRAM size to what's actually present */
724            value = state->m_cart[0].m_nvram[(offset - 0x6000) & mask];
721            int mask = (m_cart[0].m_nvram_size - 1) & 0x7fff; /* Limit SRAM size to what's actually present */
722            value = m_cart[0].m_nvram[(offset - 0x6000) & mask];
725723         }
726724         else
727725            value = snes_open_bus_r(space, 0);                              /* Reserved */
728726      }
729727      else
730         value = snes_rom_access(space.machine(), offset);   //ROM
728         value = snes_rom_access(offset);   //ROM
731729   }
732730   else if (offset < 0x700000)
733731   {
734      if (state->m_cart[0].mode & 5 && address < 0x8000)  /* Mode 20 & 22 in 0x0000-0x7fff */
732      if (m_cart[0].mode & 5 && address < 0x8000)  /* Mode 20 & 22 in 0x0000-0x7fff */
735733         value = snes_open_bus_r(space, 0);
736734      else
737         value = snes_rom_access(space.machine(), offset);    //ROM
735         value = snes_rom_access(offset);    //ROM
738736   }
739737   else
740738   {
741      if (state->m_cart[0].mode & 5 && address < 0x8000)     /* Mode 20 & 22 */
739      if (m_cart[0].mode & 5 && address < 0x8000)     /* Mode 20 & 22 */
742740      {
743         if (state->m_cart[0].m_nvram_size > 0x8000)
741         if (m_cart[0].m_nvram_size > 0x8000)
744742         {
745743            // In this case, SRAM is mapped in 0x8000 chunks at diff offsets: 0x700000-0x707fff, 0x710000-0x717fff, etc.
746            int mask = state->m_cart[0].m_nvram_size - 1;
744            int mask = m_cart[0].m_nvram_size - 1;
747745            offset = (offset / 0x10000) * 0x8000 + (offset & 0x7fff);
748            value = state->m_cart[0].m_nvram[offset & mask];
746            value = m_cart[0].m_nvram[offset & mask];
749747         }
750         else if (state->m_cart[0].m_nvram_size > 0)
748         else if (m_cart[0].m_nvram_size > 0)
751749         {
752            int mask = state->m_cart[0].m_nvram_size - 1;   /* Limit SRAM size to what's actually present */
753            value = state->m_cart[0].m_nvram[offset & mask];
750            int mask = m_cart[0].m_nvram_size - 1;   /* Limit SRAM size to what's actually present */
751            value = m_cart[0].m_nvram[offset & mask];
754752         }
755753         else
756754         {
r21699r21700
759757         }
760758      }
761759      else
762         value = snes_rom_access(space.machine(), offset);    //ROM
760         value = snes_rom_access(offset);    //ROM
763761   }
764762
765763   return value;
r21699r21700
767765
768766
769767/* 0x800000 - 0xffffff */
770READ8_HANDLER( snes_r_bank2 )
768READ8_MEMBER(snes_state::snes_r_bank2)
771769{
772   snes_state *state = space.machine().driver_data<snes_state>();
773770   UINT8 value = 0;
774771   UINT16 address = offset & 0xffff;
775772
r21699r21700
778775      if (address < 0x8000)
779776         value = space.read_byte(offset);
780777      else
781         value = snes_rom_access(space.machine(), 0x800000 + offset);    //ROM
778         value = snes_rom_access(0x800000 + offset);    //ROM
782779   }
783780   else
784781   {
785      if (state->m_cart[0].mode & 5 && address < 0x8000)      /* Mode 20 & 22 in 0x0000-0x7fff */
782      if (m_cart[0].mode & 5 && address < 0x8000)      /* Mode 20 & 22 in 0x0000-0x7fff */
786783      {
787784         if (offset < 0x700000)
788785            value = space.read_byte(offset);
789786         else
790787         {
791            if (state->m_cart[0].m_nvram_size > 0x8000)
788            if (m_cart[0].m_nvram_size > 0x8000)
792789            {
793790               // In this case, SRAM is mapped in 0x8000 chunks at diff offsets: 0x700000-0x707fff, 0x710000-0x717fff, etc.
794               int mask = state->m_cart[0].m_nvram_size - 1;
791               int mask = m_cart[0].m_nvram_size - 1;
795792               offset = (offset / 0x10000) * 0x8000 + (offset & 0x7fff);
796               value = state->m_cart[0].m_nvram[offset & mask];
793               value = m_cart[0].m_nvram[offset & mask];
797794            }
798            else if (state->m_cart[0].m_nvram_size > 0)
795            else if (m_cart[0].m_nvram_size > 0)
799796            {
800               int mask = state->m_cart[0].m_nvram_size - 1;   /* Limit SRAM size to what's actually present */
801               value = state->m_cart[0].m_nvram[offset & mask];
797               int mask = m_cart[0].m_nvram_size - 1;   /* Limit SRAM size to what's actually present */
798               value = m_cart[0].m_nvram[offset & mask];
802799            }
803800            else
804801            {
r21699r21700
808805         }
809806      }
810807      else
811         value = snes_rom_access(space.machine(), 0x800000 + offset);    //ROM
808         value = snes_rom_access(0x800000 + offset);    //ROM
812809   }
813810
814811   return value;
r21699r21700
816813
817814
818815/* 0x000000 - 0x7dffff */
819WRITE8_HANDLER( snes_w_bank1 )
816WRITE8_MEMBER(snes_state::snes_w_bank1)
820817{
821   snes_state *state = space.machine().driver_data<snes_state>();
822818   UINT16 address = offset & 0xffff;
823819
824820   if (offset < 0x400000)
r21699r21700
826822      if (address < 0x2000)                           /* Mirror of Low RAM */
827823         space.write_byte(0x7e0000 + address, data);
828824      else if (address < 0x6000)                      /* I/O */
829         state->snes_w_io(space, address, data);
825         snes_w_io(space, address, data);
830826      else if (address < 0x8000)
831827      {
832         if (offset >= 0x300000 && state->m_cart[0].mode == SNES_MODE_21 && state->m_cart[0].m_nvram_size > 0)
828         if (offset >= 0x300000 && m_cart[0].mode == SNES_MODE_21 && m_cart[0].m_nvram_size > 0)
833829         {
834830            /* Donkey Kong Country checks this and detects a copier if 0x800 is not masked out due to sram size */
835831            /* OTOH Secret of Mana does not work properly if sram is not mirrored on later banks */
836            int mask = (state->m_cart[0].m_nvram_size - 1) & 0x7fff; /* Limit SRAM size to what's actually present */
837            state->m_cart[0].m_nvram[(offset - 0x6000) & mask] = data;
832            int mask = (m_cart[0].m_nvram_size - 1) & 0x7fff; /* Limit SRAM size to what's actually present */
833            m_cart[0].m_nvram[(offset - 0x6000) & mask] = data;
838834         }
839835         else
840836            logerror("(PC=%06x) snes_w_bank1: Attempt to write to reserved address: %X = %02X\n", space.device().safe_pc(), offset, data);
r21699r21700
844840   }
845841   else if (offset >= 0x600000 && offset < 0x700000)
846842   {
847      if (state->m_cart[0].mode & 5 && address < 0x8000)        /* Mode 20 & 22 */
843      if (m_cart[0].mode & 5 && address < 0x8000)        /* Mode 20 & 22 */
848844         logerror("(PC=%06x) snes_w_bank1: Attempt to write to reserved address: %X = %02X\n", space.device().safe_pc(), offset, data);
849845      else
850846         logerror("(PC=%06x) Attempt to write to ROM address: %X\n", space.device().safe_pc(), offset);
851847   }
852848   else if (offset >= 0x700000)
853849   {
854      if (state->m_cart[0].mode & 5 && address < 0x8000)         /* Mode 20 & 22 */
850      if (m_cart[0].mode & 5 && address < 0x8000)         /* Mode 20 & 22 */
855851      {
856         if (state->m_cart[0].m_nvram_size > 0x8000)
852         if (m_cart[0].m_nvram_size > 0x8000)
857853         {
858854            // In this case, SRAM is mapped in 0x8000 chunks at diff offsets: 0x700000-0x707fff, 0x710000-0x717fff, etc.
859            int mask = state->m_cart[0].m_nvram_size - 1;
855            int mask = m_cart[0].m_nvram_size - 1;
860856            offset = (offset / 0x10000) * 0x8000 + (offset & 0x7fff);
861            state->m_cart[0].m_nvram[offset & mask] = data;
857            m_cart[0].m_nvram[offset & mask] = data;
862858         }
863         else if (state->m_cart[0].m_nvram_size > 0)
859         else if (m_cart[0].m_nvram_size > 0)
864860         {
865            int mask = state->m_cart[0].m_nvram_size - 1;   /* Limit SRAM size to what's actually present */
866            state->m_cart[0].m_nvram[offset & mask] = data;
861            int mask = m_cart[0].m_nvram_size - 1;   /* Limit SRAM size to what's actually present */
862            m_cart[0].m_nvram[offset & mask] = data;
867863         }
868864         else
869865            logerror("(PC=%06x) snes_w_bank1: Attempt to write to reserved address: %X = %02X\n", space.device().safe_pc(), offset, data);
r21699r21700
874870}
875871
876872/* 0x800000 - 0xffffff */
877WRITE8_HANDLER( snes_w_bank2 )
873WRITE8_MEMBER(snes_state::snes_w_bank2)
878874{
879   snes_state *state = space.machine().driver_data<snes_state>();
880875   UINT16 address = offset & 0xffff;
881876
882877   if (offset < 0x400000)
r21699r21700
888883   }
889884   else
890885   {
891      if (state->m_cart[0].mode & 5 && address < 0x8000)      /* Mode 20 & 22 in 0x0000-0x7fff */
886      if (m_cart[0].mode & 5 && address < 0x8000)      /* Mode 20 & 22 in 0x0000-0x7fff */
892887      {
893888         if (offset < 0x700000)
894889            space.write_byte(offset, data);
895890         else
896891         {
897            if (state->m_cart[0].m_nvram_size > 0x8000)
892            if (m_cart[0].m_nvram_size > 0x8000)
898893            {
899894               // In this case, SRAM is mapped in 0x8000 chunks at diff offsets: 0x700000-0x707fff, 0x710000-0x717fff, etc.
900               int mask = state->m_cart[0].m_nvram_size - 1;
895               int mask = m_cart[0].m_nvram_size - 1;
901896               offset = (offset / 0x10000) * 0x8000 + (offset & 0x7fff);
902               state->m_cart[0].m_nvram[offset & mask] = data;
897               m_cart[0].m_nvram[offset & mask] = data;
903898            }
904            else if (state->m_cart[0].m_nvram_size > 0)
899            else if (m_cart[0].m_nvram_size > 0)
905900            {
906               int mask = state->m_cart[0].m_nvram_size - 1;   /* Limit SRAM size to what's actually present */
907               state->m_cart[0].m_nvram[offset & mask] = data;
901               int mask = m_cart[0].m_nvram_size - 1;   /* Limit SRAM size to what's actually present */
902               m_cart[0].m_nvram[offset & mask] = data;
908903            }
909904            else
910905               logerror("(PC=%06x) snes_w_bank2: Attempt to write to reserved address: %X = %02X\n", space.device().safe_pc(), offset, data);
r21699r21700
12061201/* for mame we use an init, maybe we will need more for the different games */
12071202DRIVER_INIT_MEMBER(snes_state,snes)
12081203{
1209   UINT8 *rom = memregion("user3")->base();
12101204   snes_ram = auto_alloc_array_clear(machine(), UINT8, 0x1400000);
12111205
12121206   m_cart[0].m_rom_size = memregion("user3")->bytes();
1213   m_cart[0].m_rom = auto_alloc_array_clear(machine(), UINT8, m_cart[0].m_rom_size);
1214   memcpy(m_cart[0].m_rom, rom, m_cart[0].m_rom_size);
1207   m_cart[0].m_rom = memregion("user3")->base();
12151208   rom_map_setup(m_cart[0].m_rom_size);
12161209
12171210   m_cart[0].m_nvram_size = 0;
1218   if (rom[0x7fd8] > 0)
1211   if (m_cart[0].m_rom[0x7fd8] > 0)
12191212   {
1220      UINT32 nvram_size = (1024 << rom[0x7fd8]);
1213      UINT32 nvram_size = (1024 << m_cart[0].m_rom[0x7fd8]);
12211214      if (nvram_size > 0x40000)
12221215         nvram_size = 0x40000;
12231216
r21699r21700
12321225
12331226DRIVER_INIT_MEMBER(snes_state,snes_hirom)
12341227{
1235   UINT8  *rom = memregion("user3")->base();
12361228   snes_ram = auto_alloc_array(machine(), UINT8, 0x1400000);
12371229   memset(snes_ram, 0, 0x1400000);
12381230
12391231   m_cart[0].m_rom_size = memregion("user3")->bytes();
1240   m_cart[0].m_rom = auto_alloc_array_clear(machine(), UINT8, m_cart[0].m_rom_size);
1241   memcpy(m_cart[0].m_rom, rom, m_cart[0].m_rom_size);
1232   m_cart[0].m_rom = memregion("user3")->base();
12421233   rom_map_setup(m_cart[0].m_rom_size);
12431234
12441235   m_cart[0].m_nvram_size = 0;
1245   if (rom[0xffd8] > 0)
1236   if (m_cart[0].m_rom[0xffd8] > 0)
12461237   {
1247      UINT32 nvram_size = (1024 << rom[0xffd8]);
1238      UINT32 nvram_size = (1024 << m_cart[0].m_rom[0xffd8]);
12481239      if (nvram_size > 0x40000)
12491240         nvram_size = 0x40000;
12501241
trunk/src/mame/includes/snes.h
r21699r21700
682682   void hdma_init(address_space &space);
683683   void hdma_update(address_space &space, int dma);
684684   void hirq_tick();
685   inline UINT8 snes_rom_access(UINT32 offset);
685686   
686687   void snes_init_ram();
687688   
r21699r21700
689690   DECLARE_READ8_MEMBER(nss_oldjoy1_read);
690691   DECLARE_READ8_MEMBER(nss_oldjoy2_read);
691692
693   DECLARE_READ8_MEMBER(snes_r_io);
694   DECLARE_WRITE8_MEMBER(snes_w_io);   
692695   DECLARE_READ8_MEMBER(snes_io_dma_r);
693696   DECLARE_WRITE8_MEMBER(snes_io_dma_w);
697   DECLARE_READ8_MEMBER(snes_r_bank1);
698   DECLARE_READ8_MEMBER(snes_r_bank2);
699   DECLARE_WRITE8_MEMBER(snes_w_bank1);
700   DECLARE_WRITE8_MEMBER(snes_w_bank2);
694701   TIMER_CALLBACK_MEMBER(snes_nmi_tick);
695702   TIMER_CALLBACK_MEMBER(snes_hirq_tick_callback);
696703   TIMER_CALLBACK_MEMBER(snes_reset_oam_address);
r21699r21700
701708   DECLARE_WRITE_LINE_MEMBER(snes_extern_irq_w);
702709   DECLARE_DEVICE_IMAGE_LOAD_MEMBER(snes_cart);
703710   DECLARE_DEVICE_IMAGE_LOAD_MEMBER(sufami_cart);
704   DECLARE_READ8_MEMBER( snes_r_io );
705   DECLARE_WRITE8_MEMBER( snes_w_io );   
706711   virtual void video_start();   
707712};
708713
r21699r21700
757762
758763DECLARE_READ8_HANDLER( snes_open_bus_r );
759764
760extern DECLARE_READ8_HANDLER( snes_r_bank1 );
761extern DECLARE_READ8_HANDLER( snes_r_bank2 );
762extern DECLARE_WRITE8_HANDLER( snes_w_bank1 );
763extern DECLARE_WRITE8_HANDLER( snes_w_bank2 );
764
765765extern UINT8  *snes_ram;            /* Main memory */
766766
767767#endif /* _SNES_H_ */
trunk/src/mame/drivers/sfcbox.c
r21699r21700
161161}
162162
163163static ADDRESS_MAP_START( snes_map, AS_PROGRAM, 8, sfcbox_state )
164   AM_RANGE(0x000000, 0x7dffff) AM_READWRITE_LEGACY(snes_r_bank1, snes_w_bank1)
164   AM_RANGE(0x000000, 0x7dffff) AM_READWRITE(snes_r_bank1, snes_w_bank1)
165165   AM_RANGE(0x7e0000, 0x7fffff) AM_RAM                 /* 8KB Low RAM, 24KB High RAM, 96KB Expanded RAM */
166   AM_RANGE(0x800000, 0xffffff) AM_READWRITE_LEGACY(snes_r_bank2, snes_w_bank2)    /* Mirror and ROM */
166   AM_RANGE(0x800000, 0xffffff) AM_READWRITE(snes_r_bank2, snes_w_bank2)    /* Mirror and ROM */
167167ADDRESS_MAP_END
168168
169169READ8_MEMBER(sfcbox_state::spc_ram_100_r)
trunk/src/mame/drivers/nss.c
r21699r21700
345345
346346
347347static ADDRESS_MAP_START( snes_map, AS_PROGRAM, 8, nss_state )
348   AM_RANGE(0x000000, 0x7dffff) AM_READWRITE_LEGACY(snes_r_bank1, snes_w_bank1)
348   AM_RANGE(0x000000, 0x7dffff) AM_READWRITE(snes_r_bank1, snes_w_bank1)
349349   AM_RANGE(0x7e0000, 0x7fffff) AM_RAM                 /* 8KB Low RAM, 24KB High RAM, 96KB Expanded RAM */
350   AM_RANGE(0x800000, 0xffffff) AM_READWRITE_LEGACY(snes_r_bank2, snes_w_bank2)    /* Mirror and ROM */
350   AM_RANGE(0x800000, 0xffffff) AM_READWRITE(snes_r_bank2, snes_w_bank2)    /* Mirror and ROM */
351351ADDRESS_MAP_END
352352
353353READ8_MEMBER(nss_state::spc_ram_100_r)
trunk/src/mame/drivers/snesb.c
r21699r21700
237237
238238
239239static ADDRESS_MAP_START( snesb_map, AS_PROGRAM, 8, snesb_state )
240   AM_RANGE(0x000000, 0x7dffff) AM_READWRITE_LEGACY(snes_r_bank1, snes_w_bank1)
240   AM_RANGE(0x000000, 0x7dffff) AM_READWRITE(snes_r_bank1, snes_w_bank1)
241241   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 */
242   AM_RANGE(0x800000, 0xffffff) AM_READWRITE(snes_r_bank2, snes_w_bank2)    /* Mirror and ROM */
243243ADDRESS_MAP_END
244244
245245READ8_MEMBER(snesb_state::spc_ram_100_r)

Previous 199869 Revisions Next


© 1997-2024 The MAME Team