Previous 199869 Revisions Next

r32463 Monday 29th September, 2014 at 18:01:24 UTC by Fabio Priuli
(MESS) consolidation + cleanup, part2. nw.
[src/emu/bus/nes]bootleg.c kaiser.c mmc5.c nes_ines.inc nes_pcb.inc nes_slot.c nes_slot.h nes_unif.inc sunsoft.c
[src/mess/video]nes.c

trunk/src/emu/bus/nes/bootleg.c
r32462r32463
759759READ8_MEMBER(nes_asn_device::read_m)
760760{
761761   LOG_MMC(("Ai Senshi Nicol read_m, offset: %04x\n", offset));
762   return m_prg[((m_latch * 0x2000) + (offset & 0x1fff)) & (m_prg.count() - 1)];
762   return m_prg[((m_latch * 0x2000) + (offset & 0x1fff)) & (m_prg_size - 1)];
763763}
764764
765765
r32462r32463
923923READ8_MEMBER(nes_whirl2706_device::read_m)
924924{
925925   LOG_MMC(("whirl2706 read_m, offset: %04x\n", offset));
926   return m_prg[(m_latch * 0x2000 + (offset & 0x1fff)) & (m_prg.count() - 1)];
926   return m_prg[(m_latch * 0x2000 + (offset & 0x1fff)) & (m_prg_size - 1)];
927927}
928928
929929/*-------------------------------------------------
r32462r32463
10601060READ8_MEMBER(nes_smb2ja_device::read_m)
10611061{
10621062   LOG_MMC(("smb2ja read_m, offset: %04x\n", offset));
1063   return m_prg[(0xfe * 0x2000 + (offset & 0x1fff)) & (m_prg.count() - 1)];
1063   return m_prg[(0xfe * 0x2000 + (offset & 0x1fff)) & (m_prg_size - 1)];
10641064}
10651065
10661066/*-------------------------------------------------
r32462r32463
11181118READ8_MEMBER(nes_smb2jb_device::read_m)
11191119{
11201120   LOG_MMC(("smb2jb read_m, offset: %04x\n", offset));
1121   return m_prg[((0x0f * 0x2000) + (offset & 0x1fff)) & (m_prg.count() - 1)];
1121   return m_prg[((0x0f * 0x2000) + (offset & 0x1fff)) & (m_prg_size - 1)];
11221122}
11231123
11241124/* This goes to 0x4020-0x403f & 0x40a0-0x40bf */
trunk/src/emu/bus/nes/sunsoft.c
r32462r32463
555555   LOG_MMC(("Sunsoft FME7 read_m, offset: %04x\n", offset));
556556
557557   if (!(m_wram_bank & 0x40))  // is PRG ROM
558      return m_prg[((bank * 0x2000) + offset) & (m_prg.count() - 1)];
558      return m_prg[((bank * 0x2000) + offset) & (m_prg_size - 1)];
559559   else if (m_wram_bank & 0x80)    // is PRG RAM
560560   {
561561      if (m_battery)
trunk/src/emu/bus/nes/kaiser.c
r32462r32463
378378READ8_MEMBER(nes_ks7032_device::read_m)
379379{
380380   LOG_MMC(("ks7032 read_m, offset: %04x\n", offset));
381   return m_prg[((m_reg[4] * 0x2000) + (offset & 0x1fff)) & (m_prg.count() - 1)];
381   return m_prg[((m_reg[4] * 0x2000) + (offset & 0x1fff)) & (m_prg_size - 1)];
382382}
383383
384384/*-------------------------------------------------
trunk/src/emu/bus/nes/mmc5.c
r32462r32463
380380         break;
381381   }
382382
383   return m_vrom[helper & (m_vrom.bytes() - 1)];
383   return m_vrom[helper & (m_vrom_size - 1)];
384384}
385385
386386inline UINT8 nes_exrom_device::split_chr_r(UINT32 offset)
387387{
388388   UINT32 helper = (m_split_bank * 0x1000) + (offset & 0x3f8) + (m_split_yst & 7);
389   return m_vrom[helper & (m_vrom.bytes() - 1)];
389   return m_vrom[helper & (m_vrom_size - 1)];
390390}
391391
392392inline UINT8 nes_exrom_device::bg_ex1_chr_r(UINT32 offset)
393393{
394394   UINT32 helper = (m_ex1_bank * 0x1000) + (offset & 0xfff);
395   return m_vrom[helper & (m_vrom.bytes() - 1)];
395   return m_vrom[helper & (m_vrom_size - 1)];
396396}
397397
398398READ8_MEMBER(nes_exrom_device::chr_r)
trunk/src/emu/bus/nes/nes_slot.c
r32462r32463
104104
105105device_nes_cart_interface::device_nes_cart_interface(const machine_config &mconfig, device_t &device)
106106                  : device_slot_card_interface(mconfig, device),
107                  m_prg(NULL),
108                  m_vrom(NULL),
107109                  m_ciram(NULL),
110                  m_prg_size(0),
111                  m_vrom_size(0),
108112                  m_mapper_sram(NULL),
109113                  m_mapper_sram_size(0),
110114                  m_ce_mask(0),
r32462r32463
140144//  pointer allocators
141145//-------------------------------------------------
142146
143void device_nes_cart_interface::prg_alloc(size_t size)
147void device_nes_cart_interface::prg_alloc(size_t size, const char *tag)
144148{
145   m_prg.resize(size);
146   m_prg_chunks = size / 0x4000;
147   if (size % 0x2000)
149   if (m_prg == NULL)
148150   {
149      // A few pirate carts have PRG made of 32K + 2K or some weird similar config
150      // in this case we treat the banking as if this 'extra' PRG is not present and
151      // the pcb code has to handle it by accessing directly m_prg!
152      printf("Warning! The loaded PRG has size not a multiple of 8KB (0x%X)\n", (UINT32)size);
153      m_prg_chunks--;
154   }
155   
156   m_prg_mask = ((m_prg_chunks << 1) - 1);
157   
158//      printf("first mask %x!\n", m_prg_mask);
159   if ((m_prg_chunks << 1) & m_prg_mask)
160   {
161      int mask_bits = 0, temp = (m_prg_chunks << 1), mapsize;
162      // contrary to what happens with later systems, like e.g. SNES or MD,
163      // only half a dozen of NES carts have PRG which is not a power of 2
164      // so we use this bank_map only as an exception
165//          printf("uneven rom!\n");
166     
167      // 1. redefine mask as (next power of 2)-1
168      for (; temp; )
151      astring tempstring(tag);
152      tempstring.cat(NESSLOT_PRGROM_REGION_TAG);
153      m_prg = device().machine().memory().region_alloc(tempstring, size, 1, ENDIANNESS_LITTLE)->base();
154      m_prg_size = size;
155      m_prg_chunks = size / 0x4000;
156      if (size % 0x2000)
169157      {
170         mask_bits++;
171         temp >>= 1;
158         // A few pirate carts have PRG made of 32K + 2K or some weird similar config
159         // in this case we treat the banking as if this 'extra' PRG is not present and
160         // the pcb code has to handle it by accessing directly m_prg!
161         printf("Warning! The loaded PRG has size not a multiple of 8KB (0x%X)\n", (UINT32)size);
162         m_prg_chunks--;
172163      }
173      m_prg_mask = (1 << mask_bits) - 1;
174//          printf("new mask %x!\n", m_prg_mask);
175      mapsize = (1 << mask_bits)/2;
176164     
177      // 2. create a bank_map for banks in the range mask/2 -> mask
178      m_prg_bank_map.resize(mapsize);
165      m_prg_mask = ((m_prg_chunks << 1) - 1);
179166     
180      // 3. fill the bank_map accounting for mirrors
181      int j;
182      for (j = mapsize; j < (m_prg_chunks << 1); j++)
183         m_prg_bank_map[j - mapsize] = j;
184     
185      while (j % mapsize)
167//      printf("first mask %x!\n", m_prg_mask);
168      if ((m_prg_chunks << 1) & m_prg_mask)
186169      {
187         int k = 0, repeat_banks;
188         while ((j % (mapsize >> k)) && k < mask_bits)
189            k++;
190         repeat_banks = j % (mapsize >> (k - 1));
191         for (int l = 0; l < repeat_banks; l++)
192            m_prg_bank_map[(j - mapsize) + l] = m_prg_bank_map[(j - mapsize) + l - repeat_banks];
193         j += repeat_banks;
194      }
195     
196// check bank map!
170         int mask_bits = 0, temp = (m_prg_chunks << 1), mapsize;
171         // contrary to what happens with later systems, like e.g. SNES or MD,
172         // only half a dozen of NES carts have PRG which is not a power of 2
173         // so we use this bank_map only as an exception
174//          printf("uneven rom!\n");
175         
176         // 1. redefine mask as (next power of 2)-1
177         for (; temp; )
178         {
179            mask_bits++;
180            temp >>= 1;
181         }
182         m_prg_mask = (1 << mask_bits) - 1;
183//          printf("new mask %x!\n", m_prg_mask);
184         mapsize = (1 << mask_bits)/2;
185         
186         // 2. create a bank_map for banks in the range mask/2 -> mask
187         m_prg_bank_map.resize(mapsize);
188         
189         // 3. fill the bank_map accounting for mirrors
190         int j;
191         for (j = mapsize; j < (m_prg_chunks << 1); j++)
192            m_prg_bank_map[j - mapsize] = j;
193         
194         while (j % mapsize)
195         {
196            int k = 0, repeat_banks;
197            while ((j % (mapsize >> k)) && k < mask_bits)
198               k++;
199            repeat_banks = j % (mapsize >> (k - 1));
200            for (int l = 0; l < repeat_banks; l++)
201               m_prg_bank_map[(j - mapsize) + l] = m_prg_bank_map[(j - mapsize) + l - repeat_banks];
202            j += repeat_banks;
203         }
204         
205         // check bank map!
197206//          for (int i = 0; i < mapsize; i++)
198207//          {
199208//              printf("bank %3d = %3d\t", i, m_prg_bank_map[i]);
200209//              if ((i%8) == 7)
201210//                  printf("\n");
202211//          }
212      }
203213   }
204214}
205215
206void device_nes_cart_interface::prgram_alloc(size_t size)
216void device_nes_cart_interface::vrom_alloc(size_t size, const char *tag)
207217{
208   m_prgram.resize(size);
218   if (m_vrom == NULL)
219   {
220      astring tempstring(tag);
221      tempstring.cat(NESSLOT_CHRROM_REGION_TAG);
222      m_vrom = device().machine().memory().region_alloc(tempstring, size, 1, ENDIANNESS_LITTLE)->base();
223      m_vrom_size = size;
224      m_vrom_chunks = size / 0x2000;
225   }
209226}
210227
211void device_nes_cart_interface::vrom_alloc(size_t size)
228void device_nes_cart_interface::prgram_alloc(size_t size)
212229{
213   m_vrom.resize(size);
214   m_vrom_chunks = size / 0x2000;
230   m_prgram.resize(size);
215231}
216232
217233void device_nes_cart_interface::vram_alloc(size_t size)
r32462r32463
669685      {
670686         if (m_prg_bank_mem[i])
671687         {
672            m_prg_bank_mem[i]->configure_entries(0, m_prg.count() / 0x2000, m_prg, 0x2000);
688            m_prg_bank_mem[i]->configure_entries(0, m_prg_size / 0x2000, m_prg, 0x2000);
673689            m_prg_bank_mem[i]->set_entry(i);
674690            m_prg_bank[i] = i;
675691         }
r32462r32463
732748                  device_slot_interface(mconfig, *this),
733749                  m_crc_hack(0),
734750                  m_pcb_id(NO_BOARD),
735                  m_must_be_loaded(1),
736                  m_empty(TRUE)
751                  m_must_be_loaded(1)
737752{
738753}
739754
r32462r32463
770785void nes_cart_slot_device::pcb_start(UINT8 *ciram_ptr)
771786{
772787   if (m_cart)
773      m_cart->pcb_start(machine(), ciram_ptr, cart_mounted());
788      m_cart->pcb_start(machine(), ciram_ptr, exists());
774789}
775790
776791void nes_cart_slot_device::pcb_reset()
r32462r32463
835850            }
836851
837852            call_load_ines();
838            m_empty = FALSE;
839853         }
840854         else if ((magic[0] == 'U') && (magic[1] == 'N') && (magic[2] == 'I') && (magic[3] == 'F')) /* If header starts with 'UNIF' it is UNIF */
841855         {
r32462r32463
846860            }
847861
848862            call_load_unif();
849            m_empty = FALSE;
850863         }
851864         else
852865         {
r32462r32463
855868         }
856869      }
857870      else
858      {
859871         call_load_pcb();
860         m_empty = FALSE;
861      }
862872   }
863873
864874   return IMAGE_INIT_PASS;
trunk/src/emu/bus/nes/nes_ines.inc
r32462r32463
718718
719719   // SETUP step 5: allocate pointers for PRG/VROM
720720   if (prg_size)
721      m_cart->prg_alloc(prg_size);
721      m_cart->prg_alloc(prg_size, tag());
722722   if (vrom_size)
723      m_cart->vrom_alloc(vrom_size);
723      m_cart->vrom_alloc(vrom_size, tag());
724724
725725   // if there is a trainer, skip it for the moment
726726   if (m_cart->get_trainer())
trunk/src/emu/bus/nes/nes_slot.h
r32462r32463
176176   // hack until disk system is made modern!
177177   virtual void disk_flip_side() { }
178178
179   void prg_alloc(size_t size);
179   void prg_alloc(size_t size, const char *tag);
180   void vrom_alloc(size_t size, const char *tag);
180181   void prgram_alloc(size_t size);
181   void vrom_alloc(size_t size);
182182   void vram_alloc(size_t size);
183183   void battery_alloc(size_t size);
184184
r32462r32463
204204   UINT8* get_battery_base() { return m_battery; }
205205   UINT8* get_mapper_sram_base() { return m_mapper_sram; }
206206
207   UINT32 get_prg_size() { return m_prg.bytes(); }
207   UINT32 get_prg_size() { return m_prg_size; }
208208   UINT32 get_prgram_size() { return m_prgram.bytes(); }
209   UINT32 get_vrom_size() { return m_vrom.bytes(); }
209   UINT32 get_vrom_size() { return m_vrom_size; }
210210   UINT32 get_vram_size() { return m_vram.bytes(); }
211211   UINT32 get_battery_size() { return m_battery.bytes(); }
212212   UINT32 get_mapper_sram_size() { return m_mapper_sram_size; }
r32462r32463
226226protected:
227227
228228   // internal state
229   dynamic_buffer m_prg;
229   UINT8 *m_prg;
230   UINT8 *m_vrom;
231   UINT8 *m_ciram;
230232   dynamic_buffer m_prgram;
231   dynamic_buffer m_vrom;
232233   dynamic_buffer m_vram;
233234   dynamic_buffer m_battery;
234   UINT8 *m_ciram;
235   UINT32 m_prg_size;
236   UINT32 m_vrom_size;
235237
236238   // HACK: to reduce tagmap lookups for PPU-related IRQs, we add a hook to the
237239   // main NES CPU here, even if it does not belong to this device.
r32462r32463
364366   const char * get_default_card_unif(UINT8 *ROM, UINT32 len);
365367   const char * nes_get_slot(int pcb_id);
366368   int nes_get_pcb_id(const char *slot);
367   bool cart_mounted() { return !m_empty; }
368369
369370   // reading and writing
370371   virtual DECLARE_READ8_MEMBER(read_l);
r32462r32463
396397   device_nes_cart_interface*      m_cart;
397398   int m_pcb_id;
398399   bool                            m_must_be_loaded;
399   bool                            m_empty;
400400};
401401
402402// device type definition
r32462r32463
407407 DEVICE CONFIGURATION MACROS
408408 ***************************************************************************/
409409
410#define NESSLOT_PRGROM_REGION_TAG ":cart:prg_rom"
411#define NESSLOT_CHRROM_REGION_TAG ":cart:chr_rom"
412
413
410414#define MCFG_NES_CARTRIDGE_ADD(_tag, _slot_intf, _def_slot) \
411415   MCFG_DEVICE_ADD(_tag, NES_CART_SLOT, 0) \
412416   MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, _def_slot, false)
r32462r32463
414418#define MCFG_NES_CARTRIDGE_NOT_MANDATORY                                     \
415419   static_cast<nes_cart_slot_device *>(device)->set_must_be_loaded(FALSE);
416420
421
417422// Hacky configuration to add a slot with fixed disksys interface
418423#define MCFG_DISKSYS_ADD(_tag, _slot_intf, _def_slot) \
419424   MCFG_DEVICE_ADD(_tag, NES_CART_SLOT, 0) \
trunk/src/emu/bus/nes/nes_unif.inc
r32462r32463
466466   // SETUP steps 5/6: allocate pointers for PRG/VROM and load the data!
467467   if (prg_size == 0x4000)
468468   {
469      m_cart->prg_alloc(0x8000);
469      m_cart->prg_alloc(0x8000, tag());
470470      memcpy(m_cart->get_prg_base(), temp_prg, 0x4000);
471471      memcpy(m_cart->get_prg_base() + 0x4000, m_cart->get_prg_base(), 0x4000);
472472   }
473473   else
474474   {
475      m_cart->prg_alloc(prg_size);
475      m_cart->prg_alloc(prg_size, tag());
476476      memcpy(m_cart->get_prg_base(), temp_prg, prg_size);
477477   }
478478
r32462r32463
481481
482482   if (vrom_size)
483483   {
484      m_cart->vrom_alloc(vrom_size);
484      m_cart->vrom_alloc(vrom_size, tag());
485485      memcpy(m_cart->get_vrom_base(), temp_chr, vrom_size);
486486   }
487487
trunk/src/emu/bus/nes/nes_pcb.inc
r32462r32463
556556   logerror("-- PRG WRAM: %d\n",  prgram_size);
557557
558558   // SETUP steps 5/6: allocate pointers for PRG/VROM and load the data!
559   m_cart->prg_alloc(prg_size);
559   m_cart->prg_alloc(prg_size, tag());
560560   memcpy(m_cart->get_prg_base(), get_software_region("prg"), prg_size);
561561   if (vrom_size)
562562   {
563      m_cart->vrom_alloc(vrom_size);
563      m_cart->vrom_alloc(vrom_size, tag());
564564      memcpy(m_cart->get_vrom_base(), get_software_region("chr"), vrom_size);
565565   }
566566
trunk/src/mess/video/nes.c
r32462r32463
3939   // if this is a disk system game, check for the flip-disk key
4040   if (m_cartslot &&
4141       (m_cartslot->get_pcb_id() == STD_DISKSYS   // first scenario = disksys in m_cartslot (= famicom)
42         || !m_cartslot->cart_mounted()))   // second scenario = disk via fixed internal option (= fds)
42         || !m_cartslot->exists()))   // second scenario = disk via fixed internal option (= fds)
4343   {
4444      // latch this input so it doesn't go at warp speed
4545      if ((m_io_disksel->read_safe(0) & 0x01) && (!m_last_frame_flip))
r32462r32463
6060   // render the ppu
6161   m_ppu->render(bitmap, 0, 0, 0, 0);
6262
63   if (m_cartslot2 && !m_cartslot2->cart_mounted())
63   if (m_cartslot2 && !m_cartslot2->exists())
6464   {
6565      // latch this input so it doesn't go at warp speed
6666      if ((m_io_disksel->read_safe(0) & 0x01) && (!m_last_frame_flip))

Previous 199869 Revisions Next


© 1997-2024 The MAME Team