Previous 199869 Revisions Next

r21585 Tuesday 5th March, 2013 at 07:46:08 UTC by Fabio Priuli
snes: shuffling some code around (part 5). nw.
[src/mame/machine]snes.c
[src/mess/drivers]snes.c

trunk/src/mame/machine/snes.c
r21584r21585
403403      return spc_port_out(state->m_spc700, space, offset & 0x3);
404404   }
405405
406   if (state->m_has_addon_chip == HAS_SUPERFX && state->m_superfx != NULL)
407   {
408      if (offset >= 0x3000 && offset < 0x3300)
409      {
410         return superfx_mmio_read(state->m_superfx, offset);
411      }
412   }
413
406   // DMA accesses are from 4300 to 437f
414407   if (offset >= DMAP0 && offset < 0x4380)
415408   {
416409      return snes_io_dma_r(space, offset);
r21584r21585
513506      return;
514507   }
515508
516   if (state->m_has_addon_chip == HAS_SUPERFX && state->m_superfx != NULL)
517   {
518      if (offset >= 0x3000 && offset < 0x3300)
519      {
520         superfx_mmio_write(state->m_superfx, offset, data);
521         return;
522      }
523   }
524
509   // DMA accesses are from 4300 to 437f
525510   if (offset >= DMAP0 && offset < 0x4380)
526511   {
527512      snes_io_dma_w(space, offset, data);
r21584r21585
731716   }
732717   else if (address < 0x8000)
733718   {
734      if (state->m_has_addon_chip == HAS_SUPERFX && state->m_superfx != NULL)
735      {
736         if (superfx_access_ram(state->m_superfx))
737            value = snes_ram[0xf00000 + (offset & 0x1fff)]; // here it should be 0xe00000 but there are mirroring issues
738         else
739            value = snes_open_bus_r(space, 0);
740      }
741      else
742      {
743         logerror("(PC=%06x) snes_r_bank1: Unmapped external chip read: %04x\n",space.device().safe_pc(),address);
744         value = snes_open_bus_r(space, 0);                              /* Reserved */
745      }
719      logerror("(PC=%06x) snes_r_bank1: Unmapped external chip read: %04x\n",space.device().safe_pc(),address);
720      value = snes_open_bus_r(space, 0);                              /* Reserved */
746721   }
747722   else
748723      value = snes_ram[offset];
r21584r21585
768743   }
769744   else if (address < 0x8000)                                      /* SRAM for mode_21, Reserved othewise */
770745   {
771      if (state->m_has_addon_chip == HAS_SUPERFX && state->m_superfx != NULL)
746      if (state->m_cart[0].mode == SNES_MODE_21 && state->m_cart[0].sram > 0)
772747      {
773         if (superfx_access_ram(state->m_superfx))
774            value = snes_ram[0xf00000 + (offset & 0x1fff)]; // here it should be 0xe00000 but there are mirroring issues
775         else
776            value = snes_open_bus_r(space, 0);
777      }
778      else if ((state->m_cart[0].mode == SNES_MODE_21) && (state->m_cart[0].sram > 0))
779      {
780748         /* Donkey Kong Country checks this and detects a copier if 0x800 is not masked out due to sram size */
781749         /* OTOH Secret of Mana does not work properly if sram is not mirrored on later banks */
782750         int mask = (state->m_cart[0].sram - 1) & 0x7fff; /* Limit SRAM size to what's actually present */
r21584r21585
801769   UINT8 value = 0xff;
802770   UINT16 address = offset & 0xffff;
803771
804   if (state->m_has_addon_chip == HAS_SUPERFX && state->m_superfx != NULL)
772   if (state->m_cart[0].mode & 5)  /* Mode 20 & 22 */
805773   {
806      if (superfx_access_rom(state->m_superfx))
807         value = snes_ram[0x400000 + offset];
808      else
809      {
810         static const UINT8 sfx_data[16] = {
811            0x00, 0x01, 0x00, 0x01, 0x04, 0x01, 0x00, 0x01,
812            0x00, 0x01, 0x08, 0x01, 0x00, 0x01, 0x0c, 0x01,
813         };
814         return sfx_data[offset & 0x0f];
815      }
816   }
817   else if ((state->m_cart[0].mode & 5) && !(state->m_has_addon_chip == HAS_SUPERFX))  /* Mode 20 & 22 */
818   {
819774      if ((address < 0x8000) && (state->m_cart[0].mode == SNES_MODE_20))
820775         value = snes_open_bus_r(space, 0);                          /* Reserved */
821776      else
822777         value = snes_ram[0x400000 + offset];
823778   }
824   else                                            /* Mode 21 & 25 + SuperFX games */
779   else                                            /* Mode 21 & 25 */
825780      value = snes_ram[0x400000 + offset];
826781
827782   return value;
r21584r21585
834789   UINT8 value = 0xff;
835790   UINT16 address = offset & 0xffff;
836791
837   if (state->m_has_addon_chip == HAS_SUPERFX && state->m_superfx != NULL)
792   if (state->m_cart[0].mode & 5)                         /* Mode 20 & 22 */
838793   {
839      if (superfx_access_ram(state->m_superfx))
840         value = snes_ram[0xe00000 + offset];
841      else
842         value = snes_open_bus_r(space, 0);
843   }
844   else if (state->m_cart[0].mode & 5)                         /* Mode 20 & 22 */
845   {
846794      if (address >= 0x8000)
847795         value = snes_ram[0x600000 + offset];
848796      else
r21584r21585
864812   UINT8 value;
865813   UINT16 address = offset & 0xffff;
866814
867   if (state->m_has_addon_chip == HAS_SUPERFX && state->m_superfx != NULL)
815   if ((state->m_cart[0].mode & 5) && (address < 0x8000))     /* Mode 20 & 22 */
868816   {
869      if (superfx_access_ram(state->m_superfx))
870         value = snes_ram[0xf00000 + offset];
871      else
872         value = snes_open_bus_r(space, 0);
873   }
874   else if ((state->m_cart[0].mode & 5) && (address < 0x8000))     /* Mode 20 & 22 */
875   {
876817      if (state->m_cart[0].sram > 0x8000)
877818      {
878819         // In this case, SRAM is mapped in 0x8000 chunks at diff offsets: 0x700000-0x707fff, 0x710000-0x717fff, etc.
r21584r21585
904845   UINT8 value = 0;
905846   UINT16 address = offset & 0xffff;
906847
907   if (state->m_has_addon_chip == HAS_SUPERFX)
908      value = space.read_byte(offset);
909   else if (address < 0x8000)
848   if (address < 0x8000)
910849   {
911850      if (state->m_cart[0].mode != SNES_MODE_25)
912851         value = space.read_byte(offset);
r21584r21585
939878   UINT8 value = 0;
940879   UINT16 address = offset & 0xffff;
941880
942   if (state->m_has_addon_chip == HAS_SUPERFX && state->m_superfx != NULL)
881   if (state->m_cart[0].mode & 5)      /* Mode 20 & 22 */
943882   {
944      if (offset < 0x200000)  // ROM
945      {
946         if (superfx_access_rom(state->m_superfx))
947            value = snes_ram[0xc00000 + offset];
948         else
949         {
950            static const UINT8 sfx_data[16] = {
951               0x00, 0x01, 0x00, 0x01, 0x04, 0x01, 0x00, 0x01,
952               0x00, 0x01, 0x08, 0x01, 0x00, 0x01, 0x0c, 0x01,
953            };
954            return sfx_data[offset & 0x0f];
955         }
956      }
957      else    // RAM
958      {
959         offset -= 0x200000;
960         if (superfx_access_ram(state->m_superfx))
961            value = snes_ram[0xe00000 + offset];
962         else
963            value = snes_open_bus_r(space, 0);
964      }
965   }
966   else if ((state->m_cart[0].mode & 5) && !(state->m_has_addon_chip == HAS_SUPERFX))      /* Mode 20 & 22 */
967   {
968883      if (address < 0x8000)
969884         value = space.read_byte(0x400000 + offset);
970885      else
971886         value = snes_ram[0xc00000 + offset];
972887   }
973   else                                /* Mode 21 & 25 + SuperFX Games */
888   else                                /* Mode 21 & 25 */
974889      value = snes_ram[0xc00000 + offset];
975890
976891   return value;
r21584r21585
993908         snes_w_io(space, address, data);
994909   }
995910   else if (address < 0x8000)
996   {
997      if (state->m_has_addon_chip == HAS_SUPERFX)
998         snes_ram[0xf00000 + (offset & 0x1fff)] = data;  // here it should be 0xe00000 but there are mirroring issues
999      else
1000         logerror("snes_w_bank1: Attempt to write to reserved address: %x = %02x\n", offset, data);
1001   }
911      logerror("snes_w_bank1: Attempt to write to reserved address: %x = %02x\n", offset, data);
1002912   else
1003913      logerror( "(PC=%06x) Attempt to write to ROM address: %X\n",space.device().safe_pc(),offset );
1004914}
r21584r21585
1020930   }
1021931   else if (address < 0x8000)                      /* SRAM for mode_21, Reserved othewise */
1022932   {
1023      if (state->m_has_addon_chip == HAS_SUPERFX)
1024         snes_ram[0xf00000 + (offset & 0x1fff)] = data;  // here it should be 0xe00000 but there are mirroring issues
1025      else if ((state->m_cart[0].mode == SNES_MODE_21) && (state->m_cart[0].sram > 0))
933      if ((state->m_cart[0].mode == SNES_MODE_21) && (state->m_cart[0].sram > 0))
1026934      {
1027935         /* Donkey Kong Country checks this and detects a copier if 0x800 is not masked out due to sram size */
1028936         /* OTOH Secret of Mana does not work properly if sram is not mirrored on later banks */
r21584r21585
1042950   snes_state *state = space.machine().driver_data<snes_state>();
1043951   UINT16 address = offset & 0xffff;
1044952
1045   if (state->m_has_addon_chip == HAS_SUPERFX)
1046      snes_ram[0xe00000 + offset] = data;
1047   else if (state->m_cart[0].mode & 5)                 /* Mode 20 & 22 */
953   if (state->m_cart[0].mode & 5)                 /* Mode 20 & 22 */
1048954   {
1049955      if (address >= 0x8000)
1050956         logerror("(PC=%06x) Attempt to write to ROM address: %X\n",space.device().safe_pc(),offset + 0x600000);
r21584r21585
1061967   snes_state *state = space.machine().driver_data<snes_state>();
1062968   UINT16 address = offset & 0xffff;
1063969
1064   if (state->m_has_addon_chip == HAS_SUPERFX)
1065      snes_ram[0xf00000 + offset] = data;
1066   else if ((state->m_cart[0].mode & 5) && (address < 0x8000))         /* Mode 20 & 22 */
970   if ((state->m_cart[0].mode & 5) && (address < 0x8000))         /* Mode 20 & 22 */
1067971   {
1068972      if (state->m_cart[0].sram > 0x8000)
1069973      {
r21584r21585
1091995   snes_state *state = space.machine().driver_data<snes_state>();
1092996   UINT16 address = offset & 0xffff;
1093997
1094   if (state->m_has_addon_chip == HAS_SUPERFX)
1095      space.write_byte(offset, data);
1096   else if (address < 0x8000)
998   if (address < 0x8000)
1097999   {
10981000      if (state->m_cart[0].mode != SNES_MODE_25)
10991001         space.write_byte(offset, data);
r21584r21585
11211023   snes_state *state = space.machine().driver_data<snes_state>();
11221024   UINT16 address = offset & 0xffff;
11231025
1124   if (state->m_has_addon_chip == HAS_SUPERFX)
1026   if (state->m_cart[0].mode & 5)             /* Mode 20 & 22 */
11251027   {
1126      if (offset >= 0x200000)
1127      {
1128         offset -= 0x200000;
1129         snes_ram[0xe00000 + offset] = data;     // SFX RAM
1130      }
1131      else
1132         logerror("(PC=%06x) Attempt to write to ROM address: %X\n",space.device().safe_pc(),offset + 0xc00000);
1133   }
1134   else if (state->m_cart[0].mode & 5)             /* Mode 20 & 22 */
1135   {
11361028      if (address < 0x8000)
11371029      {
11381030         if (offset >= 0x3e0000)
trunk/src/mess/drivers/snes.c
r21584r21585
160160   if ((state->m_has_addon_chip == HAS_SPC7110 || state->m_has_addon_chip == HAS_SPC7110_RTC)
161161      && offset >= 0x500000 && offset < 0x510000)
162162      return spc7110_mmio_read(space, 0x4800);
163   if (state->m_has_addon_chip == HAS_SUPERFX && state->m_superfx != NULL
164      && offset < 0x400000)
165   {   
166      if (address >= 0x3000 && address < 0x3300)
167         return superfx_mmio_read(state->m_superfx, address);
168      if (address >= 0x6000 && address < 0x8000)    // here it should be snes_ram[0xe00000+...] but there are mirroring issues
169         return superfx_access_ram(state->m_superfx) ? snes_ram[0xf00000 + (offset & 0x1fff)] : snes_open_bus_r(space, 0);
170   }
171   if (state->m_has_addon_chip == HAS_SUPERFX && state->m_superfx != NULL
172      && offset >= 0x400000 && offset < 0x600000)
173   {
174      if (superfx_access_rom(state->m_superfx))
175         return snes_ram[offset];
176      else
177      {
178         static const UINT8 sfx_data[16] = {
179            0x00, 0x01, 0x00, 0x01, 0x04, 0x01, 0x00, 0x01,
180            0x00, 0x01, 0x08, 0x01, 0x00, 0x01, 0x0c, 0x01,
181         };
182         return sfx_data[offset & 0x0f];
183      }
184   }
185   if (state->m_has_addon_chip == HAS_SUPERFX && state->m_superfx != NULL
186      && offset >= 0x600000)
187      return superfx_access_ram(state->m_superfx) ? snes_ram[0x800000 + offset] : snes_open_bus_r(space, 0);
163188   
164189   // base cart access
165190   if (offset < 0x300000)
r21584r21585
231256   if ((state->m_has_addon_chip == HAS_SPC7110 || state->m_has_addon_chip == HAS_SPC7110_RTC)
232257      && offset >= 0x500000)
233258      return spc7110_bank7_read(space, offset - 0x400000);
259   if (state->m_has_addon_chip == HAS_SUPERFX && state->m_superfx != NULL)
260      return space.read_byte(offset);      // [80-ff] same as [00-7f]
234261   
235262   // base cart access
236263   if (offset < 0x400000)
r21584r21585
307334      if (offset >= 0x300000 && offset < 0x310000 && address >= 0x6000 && address < 0x8000)
308335      {   snes_ram[0x306000 + (address & 0x1fff)] = data;   return;   }
309336   }
337   if (state->m_has_addon_chip == HAS_SUPERFX && state->m_superfx != NULL
338       && offset < 0x400000)
339   {   
340      if (address >= 0x3000 && address < 0x3300)
341      {   superfx_mmio_write(state->m_superfx, address, data);   return;   }
342      if (address >= 0x6000 && address < 0x8000)    // here it should be snes_ram[0xe00000+...] but there are mirroring issues
343      {   snes_ram[0xf00000 + (offset & 0x1fff)] = data;   return;   }
344   }
345   if (state->m_has_addon_chip == HAS_SUPERFX && state->m_superfx != NULL
346      && offset >= 0x600000)
347   {   snes_ram[0x800000 + offset] = data;   return;   }
310348   
311349   // base cart access
312350   if (offset < 0x300000)
r21584r21585
389427      if (offset >= 0x300000 && offset < 0x310000 && address >= 0x6000 && address < 0x8000)
390428      {   snes_ram[0x306000 + (address & 0x1fff)] = data;   return;   }
391429   }
430   if (state->m_has_addon_chip == HAS_SUPERFX && state->m_superfx != NULL)
431   {   space.write_byte(offset, data);   return;   }      // [80-ff] same as [00-7f]
392432   
393433   // base cart access
394434   if (offset < 0x400000)
r21584r21585
16031643      if (address >= 0x8000)
16041644         return state->m_slotcart->m_cart->read_h(space, offset);   //ROM
16051645   }
1606   if (offset < 0x600000)
1646   else if (offset < 0x600000)
16071647      return state->m_slotcart->m_cart->read_h(space, offset);   //ROM
16081648   
16091649   return state->m_slotcart->m_cart->read_h(space, offset);   //RAM
r21584r21585
16321672      if (address >= 0x8000)
16331673         return state->m_slotcart->m_cart->read_l(space, offset);   //ROM
16341674   }
1635   if (offset < 0x600000)
1675   else if (offset < 0x600000)
16361676      return state->m_slotcart->m_cart->read_l(space, offset);   //ROM
16371677   
16381678   return state->m_slotcart->m_cart->read_l(space, offset);   //RAM

Previous 199869 Revisions Next


© 1997-2024 The MAME Team