From 4916f13f4728e5cad7bb84cf6ca4b5a29da6f0f2 Mon Sep 17 00:00:00 2001 From: Fabio Priuli Date: Thu, 1 May 2014 17:33:20 +0000 Subject: [PATCH] (MESS) saturn: replaced auto_allocs with dynamic_arrays, and reduced BRAM & DRAM allocation to actual RAM size. nw. --- src/emu/bus/saturn/bram.c | 11 ++++++----- src/emu/bus/saturn/bram.h | 4 ++-- src/emu/bus/saturn/dram.c | 32 ++++++++++++++++++-------------- src/emu/bus/saturn/dram.h | 2 +- src/emu/bus/saturn/rom.c | 2 +- src/emu/bus/saturn/sat_slot.c | 19 ++++--------------- src/emu/bus/saturn/sat_slot.h | 22 +++++++++------------- 7 files changed, 41 insertions(+), 51 deletions(-) diff --git a/src/emu/bus/saturn/bram.c b/src/emu/bus/saturn/bram.c index 64c5250b57e..aa7440d5010 100644 --- a/src/emu/bus/saturn/bram.c +++ b/src/emu/bus/saturn/bram.c @@ -58,10 +58,11 @@ saturn_bram32mb_device::saturn_bram32mb_device(const machine_config &mconfig, co void saturn_bram_device::device_start() { - // TODO: only allocate the real amount of RAM - m_ext_bram = auto_alloc_array_clear(machine(), UINT8, 0x400000); - m_ext_bram_size = 0x400000; - save_pointer(NAME(m_ext_bram), 0x400000); + if (m_ext_bram == NULL) + { + m_ext_bram.resize(m_size); + save_item(NAME(m_ext_bram)); + } } void saturn_bram_device::device_reset() @@ -72,7 +73,7 @@ void saturn_bram_device::nvram_default() { static const UINT8 init[16] = { 'B', 'a', 'c', 'k', 'U', 'p', 'R', 'a', 'm', ' ', 'F', 'o', 'r', 'm', 'a', 't' }; - memset(m_ext_bram, 0, m_ext_bram_size); + memset(m_ext_bram, 0, m_ext_bram.bytes()); for (int i = 0; i < 32; i++) { diff --git a/src/emu/bus/saturn/bram.h b/src/emu/bus/saturn/bram.h index fe137e6c489..67ed47ea104 100644 --- a/src/emu/bus/saturn/bram.h +++ b/src/emu/bus/saturn/bram.h @@ -20,8 +20,8 @@ public: // device_nvram_interface overrides virtual void nvram_default(); - virtual void nvram_read(emu_file &file) { if (m_ext_bram != NULL) { file.read(m_ext_bram, m_ext_bram_size); } } - virtual void nvram_write(emu_file &file) { if (m_ext_bram != NULL) { file.write(m_ext_bram, m_ext_bram_size); } } + virtual void nvram_read(emu_file &file) { if (m_ext_bram != NULL) { file.read(m_ext_bram, m_ext_bram.bytes()); } } + virtual void nvram_write(emu_file &file) { if (m_ext_bram != NULL) { file.write(m_ext_bram, m_ext_bram.bytes()); } } // reading and writing virtual DECLARE_READ32_MEMBER(read_ext_bram); diff --git a/src/emu/bus/saturn/dram.c b/src/emu/bus/saturn/dram.c index de800e60b15..65b161d0197 100644 --- a/src/emu/bus/saturn/dram.c +++ b/src/emu/bus/saturn/dram.c @@ -25,13 +25,13 @@ saturn_dram_device::saturn_dram_device(const machine_config &mconfig, device_typ } saturn_dram8mb_device::saturn_dram8mb_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) - : saturn_dram_device(mconfig, SATURN_DRAM_8MB, "Saturn Data RAM 8Mbit Cart", tag, owner, clock, 0x400000/4, "sat_dram_8mb", __FILE__) + : saturn_dram_device(mconfig, SATURN_DRAM_8MB, "Saturn Data RAM 8Mbit Cart", tag, owner, clock, 0x100000, "sat_dram_8mb", __FILE__) { m_cart_type = 0x5a; } saturn_dram32mb_device::saturn_dram32mb_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) - : saturn_dram_device(mconfig, SATURN_DRAM_32MB, "Saturn Data RAM 32Mbit Cart", tag, owner, clock, 0x800000/4, "sat_dram_32mb", __FILE__) + : saturn_dram_device(mconfig, SATURN_DRAM_32MB, "Saturn Data RAM 32Mbit Cart", tag, owner, clock, 0x400000, "sat_dram_32mb", __FILE__) { m_cart_type = 0x5c; } @@ -43,13 +43,17 @@ saturn_dram32mb_device::saturn_dram32mb_device(const machine_config &mconfig, co void saturn_dram_device::device_start() { - // TODO: only allocate the real amount of RAM - m_ext_dram0 = auto_alloc_array_clear(machine(), UINT32, 0x400000/4); - m_ext_dram1 = auto_alloc_array_clear(machine(), UINT32, 0x400000/4); - m_ext_dram0_size = 0x400000; - m_ext_dram1_size = 0x400000; - save_pointer(NAME(m_ext_dram0), 0x400000/4); - save_pointer(NAME(m_ext_dram1), 0x400000/4); + if (m_ext_dram0 == NULL) + { + m_ext_dram0.resize((m_size/2)/sizeof(UINT32)); + save_item(NAME(m_ext_dram0)); + } + + if (m_ext_dram1 == NULL) + { + m_ext_dram1.resize((m_size/2)/sizeof(UINT32)); + save_item(NAME(m_ext_dram1)); + } } void saturn_dram_device::device_reset() @@ -61,11 +65,11 @@ void saturn_dram_device::device_reset() mapper specific handlers -------------------------------------------------*/ -// RAM: two DRAM chips are present in the cart +// RAM: two DRAM chips are present in the cart, thus accesses only go up to m_size/2! READ32_MEMBER(saturn_dram_device::read_ext_dram0) { - if (offset < m_size/2) + if (offset < (m_size/2)/4) return m_ext_dram0[offset]; else { @@ -76,7 +80,7 @@ READ32_MEMBER(saturn_dram_device::read_ext_dram0) READ32_MEMBER(saturn_dram_device::read_ext_dram1) { - if (offset < m_size/2) + if (offset < (m_size/2)/4) return m_ext_dram1[offset]; else { @@ -87,7 +91,7 @@ READ32_MEMBER(saturn_dram_device::read_ext_dram1) WRITE32_MEMBER(saturn_dram_device::write_ext_dram0) { - if (offset < m_size/2) + if (offset < (m_size/2)/4) COMBINE_DATA(&m_ext_dram0[offset]); else osd_printf_error("DRAM0 write beyond its boundary! offs: %X data: %X\n", offset, data); @@ -95,7 +99,7 @@ WRITE32_MEMBER(saturn_dram_device::write_ext_dram0) WRITE32_MEMBER(saturn_dram_device::write_ext_dram1) { - if (offset < m_size/2) + if (offset < (m_size/2)/4) COMBINE_DATA(&m_ext_dram1[offset]); else osd_printf_error("DRAM1 write beyond its boundary! offs: %X data: %X\n", offset, data); diff --git a/src/emu/bus/saturn/dram.h b/src/emu/bus/saturn/dram.h index 3a7e27a3e52..bc19e2a866a 100644 --- a/src/emu/bus/saturn/dram.h +++ b/src/emu/bus/saturn/dram.h @@ -23,7 +23,7 @@ public: virtual DECLARE_WRITE32_MEMBER(write_ext_dram0); virtual DECLARE_WRITE32_MEMBER(write_ext_dram1); - UINT32 m_size; // this is the size of DRAM0 + DRAM1 in dword units, so accesses to each bank go up to (m_size/2)-1 + UINT32 m_size; // this is the size of DRAM0 + DRAM1, so accesses to each bank go up to ((m_size/2)/4)-1 }; class saturn_dram8mb_device : public saturn_dram_device diff --git a/src/emu/bus/saturn/rom.c b/src/emu/bus/saturn/rom.c index c7fc84cbd81..a3718e8192d 100644 --- a/src/emu/bus/saturn/rom.c +++ b/src/emu/bus/saturn/rom.c @@ -49,5 +49,5 @@ void saturn_rom_device::device_reset() READ32_MEMBER(saturn_rom_device::read_rom) { - return m_rom[offset & (m_rom_size - 1)]; + return m_rom[offset & (m_rom.count() - 1)]; } diff --git a/src/emu/bus/saturn/sat_slot.c b/src/emu/bus/saturn/sat_slot.c index 8db3368ed4a..aad83a89906 100644 --- a/src/emu/bus/saturn/sat_slot.c +++ b/src/emu/bus/saturn/sat_slot.c @@ -35,15 +35,7 @@ const device_type SATURN_CART_SLOT = &device_creator; //------------------------------------------------- device_sat_cart_interface::device_sat_cart_interface(const machine_config &mconfig, device_t &device) - : device_slot_card_interface(mconfig, device), - m_rom(NULL), - m_ext_dram0(NULL), - m_ext_dram1(NULL), - m_ext_bram(NULL), - m_rom_size(0), - m_ext_dram0_size(0), - m_ext_dram1_size(0), - m_ext_bram_size(0) + : device_slot_card_interface(mconfig, device) { } @@ -60,13 +52,10 @@ device_sat_cart_interface::~device_sat_cart_interface() // rom_alloc - alloc the space for the cart //------------------------------------------------- -void device_sat_cart_interface::rom_alloc(running_machine &machine, UINT32 size) +void device_sat_cart_interface::rom_alloc(UINT32 size) { if (m_rom == NULL) - { - m_rom = auto_alloc_array_clear(machine, UINT32, size/4); - m_rom_size = size; - } + m_rom.resize(size/sizeof(UINT32)); } @@ -134,7 +123,7 @@ bool sat_cart_slot_device::call_load() else len = length(); - m_cart->rom_alloc(machine(), len); + m_cart->rom_alloc(len); ROM = m_cart->get_rom_base(); if (software_entry() != NULL) diff --git a/src/emu/bus/saturn/sat_slot.h b/src/emu/bus/saturn/sat_slot.h index 9dc0070cd07..6e93dffe34d 100644 --- a/src/emu/bus/saturn/sat_slot.h +++ b/src/emu/bus/saturn/sat_slot.h @@ -29,28 +29,24 @@ public: virtual int get_cart_type() { return m_cart_type; }; - void rom_alloc(running_machine &machine, UINT32 size); + void rom_alloc(UINT32 size); UINT32* get_rom_base() { return m_rom; } UINT32* get_ext_dram0_base() { return m_ext_dram0; } UINT32* get_ext_dram1_base() { return m_ext_dram1; } UINT8* get_ext_bram_base() { return m_ext_bram; } - UINT32 get_rom_size() { return m_rom_size; } - UINT32 get_ext_dram0_size() { return m_ext_dram0_size; } - UINT32 get_ext_dram1_size() { return m_ext_dram1_size; } - UINT32 get_ext_bram_size() { return m_ext_bram_size; } + UINT32 get_rom_size() { return m_rom.bytes(); } + UINT32 get_ext_dram0_size() { return m_ext_dram0.bytes(); } + UINT32 get_ext_dram1_size() { return m_ext_dram1.bytes(); } + UINT32 get_ext_bram_size() { return m_ext_bram.bytes(); } protected: int m_cart_type; // internal state - UINT32 *m_rom; - UINT32 *m_ext_dram0; - UINT32 *m_ext_dram1; - UINT8 *m_ext_bram; - UINT32 m_rom_size; - UINT32 m_ext_dram0_size; - UINT32 m_ext_dram1_size; - UINT32 m_ext_bram_size; + dynamic_array m_rom; + dynamic_array m_ext_dram0; + dynamic_array m_ext_dram1; + dynamic_buffer m_ext_bram; };