Previous 199869 Revisions Next

r29478 Wednesday 9th April, 2014 at 10:53:46 UTC by Fabio Priuli
(MESS) snes_slot.c: nuked some auto_allocs, using dynamic_buffer instead. nw.
[src/emu/bus/snes]sa1.c snes_slot.c snes_slot.h

trunk/src/emu/bus/snes/sa1.c
r29477r29478
823823      return 0xff;    // this should probably never happen, or are there SA-1 games with no BWRAM?
824824
825825   if (offset < 0x100000)
826      return m_nvram[offset & (m_nvram_size - 1)];
826      return m_nvram[offset & (m_nvram.count() - 1)];
827827
828828   // Bitmap BWRAM
829829   offset -= 0x100000;
r29477r29478
844844   }
845845
846846   // only return the correct bits
847   return (m_nvram[offset & (m_nvram_size - 1)] >> shift) & mask;
847   return (m_nvram[offset & (m_nvram.count() - 1)] >> shift) & mask;
848848}
849849
850850void sns_sa1_device::write_bwram(UINT32 offset, UINT8 data)
r29477r29478
856856
857857   if (offset < 0x100000)
858858   {
859      m_nvram[offset & (m_nvram_size - 1)] = data;
859      m_nvram[offset & (m_nvram.count() - 1)] = data;
860860      return;
861861   }
862862
r29477r29478
879879   }
880880
881881   // only change the correct bits, keeping the rest untouched
882   m_nvram[offset & (m_nvram_size - 1)] = (m_nvram[offset & (m_nvram_size - 1)] & ~mask) | data;
882   m_nvram[offset & (m_nvram.count() - 1)] = (m_nvram[offset & (m_nvram.count() - 1)] & ~mask) | data;
883883}
884884
885885
trunk/src/emu/bus/snes/snes_slot.c
r29477r29478
6767//-------------------------------------------------
6868
6969device_sns_cart_interface::device_sns_cart_interface(const machine_config &mconfig, device_t &device)
70   : device_slot_card_interface(mconfig, device),
71      m_rom(NULL),
72      m_nvram(NULL),
73      m_bios(NULL),
74      m_rtc_ram(NULL),
75      m_rom_size(0),
76      m_nvram_size(0),
77      m_bios_size(0),
78      m_rtc_ram_size(0)
70   : device_slot_card_interface(mconfig, device)
7971{
8072}
8173
r29477r29478
9284//  rom_alloc - alloc the space for the cart
9385//-------------------------------------------------
9486
95void device_sns_cart_interface::rom_alloc(running_machine &machine, UINT32 size)
87void device_sns_cart_interface::rom_alloc(UINT32 size)
9688{
97   if (m_rom == NULL)
98   {
99      m_rom = auto_alloc_array_clear(machine, UINT8, size);
100      m_rom_size = size;
101   }
89   m_rom.resize(size);
10290}
10391
10492
r29477r29478
10694//  nvram_alloc - alloc the space for the nvram
10795//-------------------------------------------------
10896
109void device_sns_cart_interface::nvram_alloc(running_machine &machine, UINT32 size)
97void device_sns_cart_interface::nvram_alloc(UINT32 size)
11098{
11199   if (m_nvram == NULL)
112100   {
113      m_nvram = auto_alloc_array_clear(machine, UINT8, size);
114      m_nvram_size = size;
115      state_save_register_item_pointer(machine, "SNES_CART", this->device().tag(), 0, m_nvram, m_nvram_size);
101      m_nvram.resize(size);
102      device().save_item(NAME(m_nvram));
116103   }
117104}
118105
r29477r29478
124111//  saved by the device itself)
125112//-------------------------------------------------
126113
127void device_sns_cart_interface::rtc_ram_alloc(running_machine &machine, UINT32 size)
114void device_sns_cart_interface::rtc_ram_alloc(UINT32 size)
128115{
129116   if (m_rtc_ram == NULL)
130117   {
131      m_rtc_ram = auto_alloc_array_clear(machine, UINT8, size);
132      m_rtc_ram_size = size;
133      state_save_register_item_pointer(machine, "SNES_CART", this->device().tag(), 0, m_rtc_ram, m_rtc_ram_size);
118      m_rtc_ram.resize(size);
119      device().save_item(NAME(m_rtc_ram));
134120   }
135121}
136122
r29477r29478
140126//  (optional) add-on CPU bios
141127//-------------------------------------------------
142128
143void device_sns_cart_interface::addon_bios_alloc(running_machine &machine, UINT32 size)
129void device_sns_cart_interface::addon_bios_alloc(UINT32 size)
144130{
145   if (m_bios == NULL)
146   {
147      m_bios = auto_alloc_array_clear(machine, UINT8, size);
148      m_bios_size = size;
149   }
131   m_bios.resize(size);
150132}
151133
152134
r29477r29478
638620
639621      len = (software_entry() == NULL) ? (length() - offset) : get_software_region_length("rom");
640622
641      m_cart->rom_alloc(machine(), len);
623      m_cart->rom_alloc(len);
642624      ROM = m_cart->get_rom_base();
643625      if (software_entry() == NULL)
644626         fread(ROM, len);
r29477r29478
652634      {
653635         if (get_software_region("addon"))
654636         {
655            m_cart->addon_bios_alloc(machine(), get_software_region_length("addon"));
637            m_cart->addon_bios_alloc(get_software_region_length("addon"));
656638            memcpy(m_cart->get_addon_bios_base(), get_software_region("addon"), get_software_region_length("addon"));
657639         }
658640      }
r29477r29478
746728         if ((m_cart->get_rom_size() & 0x7fff) == 0x2800)
747729         {
748730            logerror("Found NEC DSP dump at the bottom of the ROM.\n");
749            m_cart->addon_bios_alloc(machine(), 0x2800);
731            m_cart->addon_bios_alloc(0x2800);
750732            memcpy(m_cart->get_addon_bios_base(), m_cart->get_rom_base() + (m_cart->get_rom_size() - 0x2800), 0x2800);
751733            m_cart->rom_map_setup(m_cart->get_rom_size() - 0x2800);
752734         }
r29477r29478
754736         if ((m_cart->get_rom_size() & 0x7fff) == 0x2000)
755737         {
756738            logerror("Found NEC DSP dump (byuu's version) at the bottom of the ROM.\n");
757            m_cart->addon_bios_alloc(machine(), 0x2800);
739            m_cart->addon_bios_alloc(0x2800);
758740            for (int i = 0; i < 0x800; i++)
759741            {
760742               memcpy(m_cart->get_addon_bios_base() + i * 4 + 2, m_cart->get_rom_base() + (m_cart->get_rom_size() - 0x2000) + i * 3 + 0, 1);
r29477r29478
772754         if ((m_cart->get_rom_size() & 0x3ffff) == 0x11000)
773755         {
774756            logerror("Found Seta DSP dump at the bottom of the ROM.\n");
775            m_cart->addon_bios_alloc(machine(), 0x11000);
757            m_cart->addon_bios_alloc(0x11000);
776758            memcpy(m_cart->get_addon_bios_base(), m_cart->get_rom_base() + (m_cart->get_rom_size() - 0x11000), 0x11000);
777759            m_cart->rom_map_setup(m_cart->get_rom_size() - 0x11000);
778760         }
r29477r29478
780762         if ((m_cart->get_rom_size() & 0xffff) == 0xd000)
781763         {
782764            logerror("Found Seta DSP dump (byuu's version) at the bottom of the ROM.\n");
783            m_cart->addon_bios_alloc(machine(), 0x11000);
765            m_cart->addon_bios_alloc(0x11000);
784766            for (int i = 0; i < 0x4000; i++)
785767            {
786768               memcpy(m_cart->get_addon_bios_base() + i * 4 + 2, m_cart->get_rom_base() + (m_cart->get_rom_size() - 0xd000) + i * 3 + 0, 1);
r29477r29478
796778         if ((m_cart->get_rom_size() & 0x7fff) == 0x0c00)
797779         {
798780            logerror("Found CX4 dump at the bottom of the ROM.\n");
799            m_cart->addon_bios_alloc(machine(), 0x0c00);
781            m_cart->addon_bios_alloc(0x0c00);
800782            memcpy(m_cart->get_addon_bios_base(), m_cart->get_rom_base() + (m_cart->get_rom_size() - 0x0c00), 0x0c00);
801783            m_cart->rom_map_setup(m_cart->get_rom_size() - 0x0c00);
802784         }
r29477r29478
805787         if ((m_cart->get_rom_size() & 0x3ffff) == 0x28000)
806788         {
807789            logerror("Found ST018 dump at the bottom of the ROM.\n");
808            m_cart->addon_bios_alloc(machine(), 0x28000);
790            m_cart->addon_bios_alloc(0x28000);
809791            memcpy(m_cart->get_addon_bios_base(), m_cart->get_rom_base() + (m_cart->get_rom_size() - 0x28000), 0x28000);
810792            m_cart->rom_map_setup(m_cart->get_rom_size() - 0x28000);
811793         }
r29477r29478
822804      {
823805         case ADDON_DSP1:
824806            ROM = machine().root_device().memregion(region)->base();
825            m_cart->addon_bios_alloc(machine(), 0x2800);
807            m_cart->addon_bios_alloc(0x2800);
826808            memcpy(m_cart->get_addon_bios_base(), ROM, 0x2800);
827809            break;
828810         case ADDON_DSP1B:
829811            ROM = machine().root_device().memregion(region)->base();
830            m_cart->addon_bios_alloc(machine(), 0x2800);
812            m_cart->addon_bios_alloc(0x2800);
831813            memcpy(m_cart->get_addon_bios_base(), ROM, 0x2800);
832814            break;
833815         case ADDON_DSP2:
834816            ROM = machine().root_device().memregion(region)->base();
835            m_cart->addon_bios_alloc(machine(), 0x2800);
817            m_cart->addon_bios_alloc(0x2800);
836818            memcpy(m_cart->get_addon_bios_base(), ROM, 0x2800);
837819            break;
838820         case ADDON_DSP3:
839821            ROM = machine().root_device().memregion(region)->base();
840            m_cart->addon_bios_alloc(machine(), 0x2800);
822            m_cart->addon_bios_alloc(0x2800);
841823            memcpy(m_cart->get_addon_bios_base(), ROM, 0x2800);
842824            break;
843825         case ADDON_DSP4:
844826            ROM = machine().root_device().memregion(region)->base();
845            m_cart->addon_bios_alloc(machine(), 0x2800);
827            m_cart->addon_bios_alloc(0x2800);
846828            memcpy(m_cart->get_addon_bios_base(), ROM, 0x2800);
847829            break;
848830         case ADDON_ST010:
849831            ROM = machine().root_device().memregion(region)->base();
850            m_cart->addon_bios_alloc(machine(), 0x11000);
832            m_cart->addon_bios_alloc(0x11000);
851833            memcpy(m_cart->get_addon_bios_base(), ROM, 0x11000);
852834            break;
853835         case ADDON_ST011:
854836            ROM = machine().root_device().memregion(region)->base();
855            m_cart->addon_bios_alloc(machine(), 0x11000);
837            m_cart->addon_bios_alloc(0x11000);
856838            memcpy(m_cart->get_addon_bios_base(), ROM, 0x11000);
857839            break;
858840      }
r29477r29478
883865   }
884866
885867   if (size)
886      m_cart->nvram_alloc(machine(), size);
868      m_cart->nvram_alloc(size);
887869
888870   if (m_type == SNES_STROM)
889      m_cart->nvram_alloc(machine(), 0x20000);
871      m_cart->nvram_alloc(0x20000);
890872   if (m_type == SNES_BSX)
891      m_cart->nvram_alloc(machine(), 0x8000);
873      m_cart->nvram_alloc(0x8000);
892874
893875   // setup also RTC SRAM, when needed (to be removed when RTCs are converted to devices)
894876   if (m_type == SNES_SRTC)
895      m_cart->rtc_ram_alloc(machine(), 13);
877      m_cart->rtc_ram_alloc(13);
896878   if (m_type == SNES_SPC7110_RTC)
897      m_cart->rtc_ram_alloc(machine(), 16);
879      m_cart->rtc_ram_alloc(16);
898880}
899881
900882
trunk/src/emu/bus/snes/snes_slot.h
r29477r29478
9191   ADDON_Z80GB
9292};
9393
94// ======================> sns_cart_interface
95
96struct sns_cart_interface
97{
98};
99
100
10194// ======================> device_sns_cart_interface
10295
10396class device_sns_cart_interface : public device_slot_card_interface
r29477r29478
110103   // reading and writing
111104   virtual DECLARE_READ8_MEMBER(read_l) { return 0xff; }   // ROM access in range [00-7f]
112105   virtual DECLARE_READ8_MEMBER(read_h) { return 0xff; }   // ROM access in range [80-ff]
113   virtual DECLARE_READ8_MEMBER(read_ram) { if (m_nvram) { UINT32 mask = m_nvram_size - 1; return m_nvram[offset & mask]; } else return 0xff; }   // NVRAM access
106   virtual DECLARE_READ8_MEMBER(read_ram) { if (m_nvram) { UINT32 mask = m_nvram.count() - 1; return m_nvram[offset & mask]; } else return 0xff; }   // NVRAM access
114107   virtual DECLARE_WRITE8_MEMBER(write_l) {}   // used by carts with subslots
115108   virtual DECLARE_WRITE8_MEMBER(write_h) {}   // used by carts with subslots
116   virtual DECLARE_WRITE8_MEMBER(write_ram) { if (m_nvram) { UINT32 mask = m_nvram_size - 1; m_nvram[offset & mask] = data; return; } } // NVRAM access
109   virtual DECLARE_WRITE8_MEMBER(write_ram) { if (m_nvram) { UINT32 mask = m_nvram.count() - 1; m_nvram[offset & mask] = data; return; } } // NVRAM access
117110   virtual DECLARE_READ8_MEMBER(chip_read) { return 0xff; }
118111   virtual DECLARE_WRITE8_MEMBER(chip_write) {}
119112   virtual void speedup_addon_bios_access() {};
120113
121   void rom_alloc(running_machine &machine, UINT32 size);
122   void nvram_alloc(running_machine &machine, UINT32 size);
123   void rtc_ram_alloc(running_machine &machine, UINT32 size);
124   void addon_bios_alloc(running_machine &machine, UINT32 size);
114   void rom_alloc(UINT32 size);
115   void nvram_alloc(UINT32 size);
116   void rtc_ram_alloc(UINT32 size);
117   void addon_bios_alloc(UINT32 size);
125118   UINT8* get_rom_base() { return m_rom; };
126119   UINT8* get_nvram_base() { return m_nvram; };
127120   UINT8* get_addon_bios_base() { return m_bios; };
128121   UINT8* get_rtc_ram_base() { return m_rtc_ram; };
129   UINT32 get_rom_size() { return m_rom_size; };
130   UINT32 get_nvram_size() { return m_nvram_size; };
131   UINT32 get_addon_bios_size() { return m_bios_size; };
132   UINT32 get_rtc_ram_size() { return m_rtc_ram_size; };
122   UINT32 get_rom_size() { return m_rom.count(); };
123   UINT32 get_nvram_size() { return m_nvram.count(); };
124   UINT32 get_addon_bios_size() { return m_bios.count(); };
125   UINT32 get_rtc_ram_size() { return m_rtc_ram.count(); };
133126
134127   void rom_map_setup(UINT32 size);
135128
136129   // internal state
137   UINT8  *m_rom;
138   UINT8  *m_nvram;
139   UINT8  *m_bios;
140   UINT8  *m_rtc_ram;  // temp pointer to save RTC ram to nvram (will disappear when RTCs become devices)
141   UINT32 m_rom_size;
142   UINT32 m_nvram_size;
143   UINT32 m_bios_size;
144   UINT32 m_rtc_ram_size;  // temp
130   dynamic_buffer m_rom;
131   dynamic_buffer m_nvram;
132   dynamic_buffer m_bios;
133   dynamic_buffer m_rtc_ram;  // temp pointer to save RTC ram to nvram (will disappear when RTCs become devices)
145134
146135   UINT8 rom_bank_map[256];    // 32K chunks of rom
147136};
r29477r29478
150139// ======================> base_sns_cart_slot_device
151140
152141class base_sns_cart_slot_device : public device_t,
153                        public sns_cart_interface,
154142                        public device_image_interface,
155143                        public device_slot_interface
156144{

Previous 199869 Revisions Next


© 1997-2024 The MAME Team