diff options
author | 2013-12-20 16:04:11 +0000 | |
---|---|---|
committer | 2013-12-20 16:04:11 +0000 | |
commit | 8c7486fa5d9eb873577770a92bc524770ed402ba (patch) | |
tree | 7343677631c224588f7113cd61c40747293de5b8 | |
parent | 7afab9bda2b90efc60412ec7ef3215466b53fb21 (diff) |
(MESS) Used shared_ptr instead of UINT8* in the Commodore cartridges. (nw)
53 files changed, 225 insertions, 712 deletions
diff --git a/src/emu/bus/c64/16kb.c b/src/emu/bus/c64/16kb.c index e92eff8704f..2e05459f4bd 100644 --- a/src/emu/bus/c64/16kb.c +++ b/src/emu/bus/c64/16kb.c @@ -102,7 +102,9 @@ ioport_constructor c64_16kb_cartridge_device::device_input_ports() const c64_16kb_cartridge_device::c64_16kb_cartridge_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : device_t(mconfig, C64_16KB, "C64 16KB EPROM cartridge", tag, owner, clock, "c64_16kb", __FILE__), device_c64_expansion_card_interface(mconfig, *this), - m_sw1(*this, "SW1") + m_sw1(*this, "SW1"), + m_rom_low(*this, "roml"), + m_rom_high(*this, "romh") { } @@ -113,8 +115,6 @@ c64_16kb_cartridge_device::c64_16kb_cartridge_device(const machine_config &mconf void c64_16kb_cartridge_device::device_start() { - m_roml = memregion("roml")->base(); - m_romh = memregion("romh")->base(); } @@ -139,11 +139,11 @@ UINT8 c64_16kb_cartridge_device::c64_cd_r(address_space &space, offs_t offset, U { if (!roml) { - data = m_roml[offset & 0x1fff]; + data = m_rom_low->base()[offset & 0x1fff]; } else if (!romh) { - data = m_romh[offset & 0x1fff]; + data = m_rom_high->base()[offset & 0x1fff]; } return data; diff --git a/src/emu/bus/c64/16kb.h b/src/emu/bus/c64/16kb.h index ddfdad85b25..3e0e16a5d9d 100644 --- a/src/emu/bus/c64/16kb.h +++ b/src/emu/bus/c64/16kb.h @@ -49,6 +49,8 @@ protected: private: required_ioport m_sw1; + required_memory_region m_rom_low; + required_memory_region m_rom_high; }; diff --git a/src/emu/bus/c64/dqbb.c b/src/emu/bus/c64/dqbb.c index f7b4b2a504a..dbbdc5f1d8b 100644 --- a/src/emu/bus/c64/dqbb.c +++ b/src/emu/bus/c64/dqbb.c @@ -53,7 +53,7 @@ c64_dqbb_cartridge_device::c64_dqbb_cartridge_device(const machine_config &mconf void c64_dqbb_cartridge_device::device_start() { // allocate memory - c64_nvram_pointer(machine(), 0x4000); + m_nvram.allocate(0x4000); // state saving save_item(NAME(m_cs)); diff --git a/src/emu/bus/c64/dqbb.h b/src/emu/bus/c64/dqbb.h index 46ffd277fca..75a02e7d745 100644 --- a/src/emu/bus/c64/dqbb.h +++ b/src/emu/bus/c64/dqbb.h @@ -42,8 +42,8 @@ protected: // device_nvram_interface overrides virtual void nvram_default() { } - virtual void nvram_read(emu_file &file) { if (m_nvram != NULL) { file.read(m_nvram, m_nvram_size); } } - virtual void nvram_write(emu_file &file) { if (m_nvram != NULL) { file.write(m_nvram, m_nvram_size); } } + virtual void nvram_read(emu_file &file) { if (m_nvram != NULL) { file.read(m_nvram, m_nvram.bytes()); } } + virtual void nvram_write(emu_file &file) { if (m_nvram != NULL) { file.write(m_nvram, m_nvram.bytes()); } } // device_c64_expansion_card_interface overrides virtual UINT8 c64_cd_r(address_space &space, offs_t offset, UINT8 data, int sphi2, int ba, int roml, int romh, int io1, int io2); diff --git a/src/emu/bus/c64/easyflash.c b/src/emu/bus/c64/easyflash.c index cc50bc2d5a4..aee84fed48f 100644 --- a/src/emu/bus/c64/easyflash.c +++ b/src/emu/bus/c64/easyflash.c @@ -89,6 +89,7 @@ c64_easyflash_cartridge_device::c64_easyflash_cartridge_device(const machine_con m_flash_roml(*this, AM29F040_0_TAG), m_flash_romh(*this, AM29F040_1_TAG), m_jp1(*this, "JP1"), + m_ram(*this, "ram"), m_bank(0), m_mode(0) { @@ -102,7 +103,7 @@ c64_easyflash_cartridge_device::c64_easyflash_cartridge_device(const machine_con void c64_easyflash_cartridge_device::device_start() { // allocate memory - c64_ram_pointer(machine(), 0x100); + m_ram.allocate(0x100); // state saving save_item(NAME(m_bank)); diff --git a/src/emu/bus/c64/easyflash.h b/src/emu/bus/c64/easyflash.h index 14a6a2472b8..4e7b1091abd 100644 --- a/src/emu/bus/c64/easyflash.h +++ b/src/emu/bus/c64/easyflash.h @@ -53,6 +53,7 @@ private: required_device<amd_29f040_device> m_flash_roml; required_device<amd_29f040_device> m_flash_romh; required_ioport m_jp1; + optional_shared_ptr<UINT8> m_ram; UINT8 m_bank; UINT8 m_mode; diff --git a/src/emu/bus/c64/exp.c b/src/emu/bus/c64/exp.c index 8d0ef2ee017..01ca45beba1 100644 --- a/src/emu/bus/c64/exp.c +++ b/src/emu/bus/c64/exp.c @@ -31,14 +31,9 @@ const device_type C64_EXPANSION_SLOT = &device_creator<c64_expansion_slot_device device_c64_expansion_card_interface::device_c64_expansion_card_interface(const machine_config &mconfig, device_t &device) : device_slot_card_interface(mconfig, device), - m_roml(NULL), - m_romh(NULL), - m_ram(NULL), - m_nvram(NULL), - m_nvram_size(0), - m_roml_mask(0), - m_romh_mask(0), - m_ram_mask(0), + m_roml(*this, "roml"), + m_romh(*this, "romh"), + m_nvram(*this, "nvram"), m_game(1), m_exrom(1) { @@ -55,75 +50,6 @@ device_c64_expansion_card_interface::~device_c64_expansion_card_interface() } -//------------------------------------------------- -// c64_roml_pointer - get low ROM pointer -//------------------------------------------------- - -UINT8* device_c64_expansion_card_interface::c64_roml_pointer(running_machine &machine, size_t size) -{ - if (m_roml == NULL) - { - m_roml = auto_alloc_array(machine, UINT8, size); - - m_roml_mask = size - 1; - } - - return m_roml; -} - - -//------------------------------------------------- -// c64_romh_pointer - get high ROM pointer -//------------------------------------------------- - -UINT8* device_c64_expansion_card_interface::c64_romh_pointer(running_machine &machine, size_t size) -{ - if (m_romh == NULL) - { - m_romh = auto_alloc_array(machine, UINT8, size); - - m_romh_mask = size - 1; - } - - return m_romh; -} - - -//------------------------------------------------- -// c64_ram_pointer - get RAM pointer -//------------------------------------------------- - -UINT8* device_c64_expansion_card_interface::c64_ram_pointer(running_machine &machine, size_t size) -{ - if (m_ram == NULL) - { - m_ram = auto_alloc_array(machine, UINT8, size); - - m_ram_mask = size - 1; - } - - return m_ram; -} - - -//------------------------------------------------- -// c64_ram_pointer - get NVRAM pointer -//------------------------------------------------- - -UINT8* device_c64_expansion_card_interface::c64_nvram_pointer(running_machine &machine, size_t size) -{ - if (m_nvram == NULL) - { - m_nvram = auto_alloc_array(machine, UINT8, size); - - m_nvram_mask = size - 1; - m_nvram_size = size; - } - - return m_nvram; -} - - //************************************************************************** // LIVE DEVICE @@ -202,7 +128,7 @@ bool c64_expansion_slot_device::call_load() if (!mame_stricmp(filetype(), "80")) { - fread(m_card->c64_roml_pointer(machine(), size), size); + fread(m_card->m_roml, size); m_card->m_exrom = (0); if (size == 0x4000) @@ -212,14 +138,14 @@ bool c64_expansion_slot_device::call_load() } else if (!mame_stricmp(filetype(), "a0")) { - fread(m_card->c64_romh_pointer(machine(), 0x2000), 0x2000); + fread(m_card->m_romh, 0x2000); m_card->m_exrom = 0; m_card->m_game = 0; } else if (!mame_stricmp(filetype(), "e0")) { - fread(m_card->c64_romh_pointer(machine(), 0x2000), 0x2000); + fread(m_card->m_romh, 0x2000); m_card->m_game = 0; } @@ -235,8 +161,11 @@ bool c64_expansion_slot_device::call_load() UINT8 *roml = NULL; UINT8 *romh = NULL; - if (roml_size) roml = m_card->c64_roml_pointer(machine(), roml_size); - if (romh_size) romh = m_card->c64_romh_pointer(machine(), romh_size); + m_card->m_roml.allocate(roml_size); + m_card->m_romh.allocate(romh_size); + + if (roml_size) roml = m_card->m_roml; + if (romh_size) romh = m_card->m_roml; cbm_crt_read_data(m_file, roml, romh); } @@ -252,10 +181,8 @@ bool c64_expansion_slot_device::call_load() if (size) { // Ultimax (VIC-10) cartridge - memcpy(m_card->c64_romh_pointer(machine(), size), get_software_region("uprom"), size); - - size = get_software_region_length("lorom"); - if (size) memcpy(m_card->c64_roml_pointer(machine(), size), get_software_region("lorom"), size); + load_software_region("lorom", m_card->m_roml); + load_software_region("uprom", m_card->m_romh); m_card->m_exrom = 1; m_card->m_game = 0; @@ -263,17 +190,9 @@ bool c64_expansion_slot_device::call_load() else { // Commodore 64/128 cartridge - size = get_software_region_length("roml"); - if (size) memcpy(m_card->c64_roml_pointer(machine(), size), get_software_region("roml"), size); - - size = get_software_region_length("romh"); - if (size) memcpy(m_card->c64_romh_pointer(machine(), size), get_software_region("romh"), size); - - size = get_software_region_length("ram"); - if (size) memset(m_card->c64_ram_pointer(machine(), size), 0, size); - - size = get_software_region_length("nvram"); - if (size) memset(m_card->c64_nvram_pointer(machine(), size), 0, size); + load_software_region("roml", m_card->m_roml); + load_software_region("romh", m_card->m_romh); + load_software_region("nvram", m_card->m_nvram); if (get_feature("exrom") != NULL) m_card->m_exrom = atol(get_feature("exrom")); if (get_feature("game") != NULL) m_card->m_game = atol(get_feature("game")); diff --git a/src/emu/bus/c64/exp.h b/src/emu/bus/c64/exp.h index 265a7b725a5..d1cb258fa55 100644 --- a/src/emu/bus/c64/exp.h +++ b/src/emu/bus/c64/exp.h @@ -167,35 +167,20 @@ public: device_c64_expansion_card_interface(const machine_config &mconfig, device_t &device); virtual ~device_c64_expansion_card_interface(); -protected: - // initialization - virtual UINT8* c64_roml_pointer(running_machine &machine, size_t size); - virtual UINT8* c64_romh_pointer(running_machine &machine, size_t size); - virtual UINT8* c64_ram_pointer(running_machine &machine, size_t size); - virtual UINT8* c64_nvram_pointer(running_machine &machine, size_t size); - - // runtime virtual UINT8 c64_cd_r(address_space &space, offs_t offset, UINT8 data, int sphi2, int ba, int roml, int romh, int io1, int io2) { return data; }; virtual void c64_cd_w(address_space &space, offs_t offset, UINT8 data, int sphi2, int ba, int roml, int romh, int io1, int io2) { }; virtual int c64_game_r(offs_t offset, int sphi2, int ba, int rw) { return m_game; } virtual int c64_exrom_r(offs_t offset, int sphi2, int ba, int rw) { return m_exrom; } - c64_expansion_slot_device *m_slot; - - UINT8 *m_roml; - UINT8 *m_romh; - UINT8 *m_ram; - UINT8 *m_nvram; - - size_t m_nvram_size; - - size_t m_roml_mask; - size_t m_romh_mask; - size_t m_ram_mask; - size_t m_nvram_mask; +protected: + optional_shared_ptr<UINT8> m_roml; + optional_shared_ptr<UINT8> m_romh; + optional_shared_ptr<UINT8> m_nvram; int m_game; int m_exrom; + + c64_expansion_slot_device *m_slot; }; diff --git a/src/emu/bus/c64/fcc.c b/src/emu/bus/c64/fcc.c index 3f2ceb36fef..09b5258c6d4 100644 --- a/src/emu/bus/c64/fcc.c +++ b/src/emu/bus/c64/fcc.c @@ -244,7 +244,7 @@ void c64_final_chesscard_device::c64_cd_w(address_space &space, offs_t offset, U READ8_MEMBER( c64_final_chesscard_device::nvram_r ) { - return m_nvram[offset & m_nvram_mask]; + return m_nvram[offset & m_nvram.mask()]; } @@ -254,5 +254,5 @@ READ8_MEMBER( c64_final_chesscard_device::nvram_r ) WRITE8_MEMBER( c64_final_chesscard_device::nvram_w ) { - m_nvram[offset & m_nvram_mask] = data; + m_nvram[offset & m_nvram.mask()] = data; } diff --git a/src/emu/bus/c64/fcc.h b/src/emu/bus/c64/fcc.h index 0bca67fda03..e41136cdb30 100644 --- a/src/emu/bus/c64/fcc.h +++ b/src/emu/bus/c64/fcc.h @@ -49,8 +49,8 @@ protected: // device_nvram_interface overrides virtual void nvram_default() { } - virtual void nvram_read(emu_file &file) { if (m_nvram != NULL) { file.read(m_nvram, m_nvram_size); } } - virtual void nvram_write(emu_file &file) { if (m_nvram != NULL) { file.write(m_nvram, m_nvram_size); } } + virtual void nvram_read(emu_file &file) { if (m_nvram != NULL) { file.read(m_nvram, m_nvram.bytes()); } } + virtual void nvram_write(emu_file &file) { if (m_nvram != NULL) { file.write(m_nvram, m_nvram.bytes()); } } // device_c64_expansion_card_interface overrides virtual UINT8 c64_cd_r(address_space &space, offs_t offset, UINT8 data, int sphi2, int ba, int roml, int romh, int io1, int io2); diff --git a/src/emu/bus/c64/georam.c b/src/emu/bus/c64/georam.c index ef0938150c7..a778cfad1c1 100644 --- a/src/emu/bus/c64/georam.c +++ b/src/emu/bus/c64/georam.c @@ -31,7 +31,8 @@ const device_type C64_GEORAM = &device_creator<c64_georam_cartridge_device>; c64_georam_cartridge_device::c64_georam_cartridge_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : device_t(mconfig, C64_GEORAM, "C64 GeoRAM cartridge", tag, owner, clock, "c64_georam", __FILE__), - device_c64_expansion_card_interface(mconfig, *this) + device_c64_expansion_card_interface(mconfig, *this), + m_ram(*this, "ram") { } @@ -43,7 +44,7 @@ c64_georam_cartridge_device::c64_georam_cartridge_device(const machine_config &m void c64_georam_cartridge_device::device_start() { // allocate memory - c64_ram_pointer(machine(), 0x80000); + m_ram.allocate(0x80000); // state saving save_item(NAME(m_bank)); diff --git a/src/emu/bus/c64/georam.h b/src/emu/bus/c64/georam.h index 53b94775b23..feb158d1d6f 100644 --- a/src/emu/bus/c64/georam.h +++ b/src/emu/bus/c64/georam.h @@ -43,6 +43,8 @@ protected: virtual void c64_cd_w(address_space &space, offs_t offset, UINT8 data, int sphi2, int ba, int roml, int romh, int io1, int io2); private: + optional_shared_ptr<UINT8> m_ram; + UINT16 m_bank; }; diff --git a/src/emu/bus/c64/ide64.c b/src/emu/bus/c64/ide64.c index e6e80103948..94f804a831b 100644 --- a/src/emu/bus/c64/ide64.c +++ b/src/emu/bus/c64/ide64.c @@ -103,7 +103,8 @@ c64_ide64_cartridge_device::c64_ide64_cartridge_device(const machine_config &mco m_flash_rom(*this, AT29C010A_TAG), m_rtc(*this, DS1302_TAG), m_ata(*this, ATA_TAG), - m_jp1(*this, "JP1") + m_jp1(*this, "JP1"), + m_ram(*this, "ram") { } @@ -115,7 +116,7 @@ c64_ide64_cartridge_device::c64_ide64_cartridge_device(const machine_config &mco void c64_ide64_cartridge_device::device_start() { // allocate memory - c64_ram_pointer(machine(), 0x8000); + m_ram.allocate(0x8000); // state saving save_item(NAME(m_bank)); diff --git a/src/emu/bus/c64/ide64.h b/src/emu/bus/c64/ide64.h index fb2a69ea7e0..037f561fdf0 100644 --- a/src/emu/bus/c64/ide64.h +++ b/src/emu/bus/c64/ide64.h @@ -57,6 +57,7 @@ private: required_device<ds1302_device> m_rtc; required_device<ata_interface_device> m_ata; required_ioport m_jp1; + optional_shared_ptr<UINT8> m_ram; UINT8 m_bank; UINT16 m_ata_data; diff --git a/src/emu/bus/c64/magic_formel.c b/src/emu/bus/c64/magic_formel.c index 8258e6dd3ed..267ce46464a 100644 --- a/src/emu/bus/c64/magic_formel.c +++ b/src/emu/bus/c64/magic_formel.c @@ -182,6 +182,7 @@ c64_magic_formel_cartridge_device::c64_magic_formel_cartridge_device(const machi device_t(mconfig, C64_MAGIC_FORMEL, "C64 Magic Formel cartridge", tag, owner, clock, "c64_magic_formel", __FILE__), device_c64_expansion_card_interface(mconfig, *this), m_pia(*this, MC6821_TAG), + m_ram(*this, "ram"), m_rom_bank(0), m_ram_bank(0), m_pb7_ff(0), @@ -199,6 +200,9 @@ c64_magic_formel_cartridge_device::c64_magic_formel_cartridge_device(const machi void c64_magic_formel_cartridge_device::device_start() { + // allocate memory + m_ram.allocate(0x2000); + // state saving save_item(NAME(m_rom_bank)); save_item(NAME(m_ram_bank)); diff --git a/src/emu/bus/c64/magic_formel.h b/src/emu/bus/c64/magic_formel.h index 79955b6c6ba..0e422603523 100644 --- a/src/emu/bus/c64/magic_formel.h +++ b/src/emu/bus/c64/magic_formel.h @@ -57,6 +57,7 @@ protected: private: required_device<pia6821_device> m_pia; + optional_shared_ptr<UINT8> m_ram; UINT8 m_rom_bank; UINT8 m_ram_bank; diff --git a/src/emu/bus/c64/neoram.c b/src/emu/bus/c64/neoram.c index 33a0f16b0de..f1142774a51 100644 --- a/src/emu/bus/c64/neoram.c +++ b/src/emu/bus/c64/neoram.c @@ -44,7 +44,7 @@ c64_neoram_cartridge_device::c64_neoram_cartridge_device(const machine_config &m void c64_neoram_cartridge_device::device_start() { // allocate memory - c64_nvram_pointer(machine(), 0x200000); + m_nvram.allocate(0x200000); // state saving save_item(NAME(m_bank)); diff --git a/src/emu/bus/c64/neoram.h b/src/emu/bus/c64/neoram.h index ea42810f5c6..aa173423ce5 100644 --- a/src/emu/bus/c64/neoram.h +++ b/src/emu/bus/c64/neoram.h @@ -41,8 +41,8 @@ protected: // device_nvram_interface overrides virtual void nvram_default() { } - virtual void nvram_read(emu_file &file) { if (m_nvram != NULL) { file.read(m_nvram, m_nvram_size); } } - virtual void nvram_write(emu_file &file) { if (m_nvram != NULL) { file.write(m_nvram, m_nvram_size); } } + virtual void nvram_read(emu_file &file) { if (m_nvram != NULL) { file.read(m_nvram, m_nvram.bytes()); } } + virtual void nvram_write(emu_file &file) { if (m_nvram != NULL) { file.write(m_nvram, m_nvram.bytes()); } } // device_c64_expansion_card_interface overrides virtual UINT8 c64_cd_r(address_space &space, offs_t offset, UINT8 data, int sphi2, int ba, int roml, int romh, int io1, int io2); diff --git a/src/emu/bus/c64/ocean.c b/src/emu/bus/c64/ocean.c index 261662dafa8..df68b111423 100644 --- a/src/emu/bus/c64/ocean.c +++ b/src/emu/bus/c64/ocean.c @@ -86,15 +86,15 @@ void c64_ocean_cartridge_device::device_reset() UINT8 c64_ocean_cartridge_device::c64_cd_r(address_space &space, offs_t offset, UINT8 data, int sphi2, int ba, int roml, int romh, int io1, int io2) { - if (!roml) + if (!roml && m_roml.bytes()) { offs_t addr = (m_bank << 13) | (offset & 0x1fff); - data = m_roml[addr & m_roml_mask]; + data = m_roml[addr & m_roml.mask()]; } - else if (!romh && m_romh) + else if (!romh && m_romh.bytes()) { offs_t addr = (m_bank << 13) | (offset & 0x1fff); - data = m_romh[addr & m_romh_mask]; + data = m_romh[addr & m_romh.mask()]; } else if (!io1) { diff --git a/src/emu/bus/c64/pagefox.c b/src/emu/bus/c64/pagefox.c index 4f5033814e0..2edc58983c6 100644 --- a/src/emu/bus/c64/pagefox.c +++ b/src/emu/bus/c64/pagefox.c @@ -53,7 +53,8 @@ const device_type C64_PAGEFOX = &device_creator<c64_pagefox_cartridge_device>; c64_pagefox_cartridge_device::c64_pagefox_cartridge_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : device_t(mconfig, C64_PAGEFOX, "C64 Pagefox cartridge", tag, owner, clock, "c64_pagefox", __FILE__), - device_c64_expansion_card_interface(mconfig, *this) + device_c64_expansion_card_interface(mconfig, *this), + m_ram(*this, "ram") { } @@ -64,6 +65,9 @@ c64_pagefox_cartridge_device::c64_pagefox_cartridge_device(const machine_config void c64_pagefox_cartridge_device::device_start() { + // allocate memory + m_ram.allocate(0x8000); + // state saving save_item(NAME(m_bank)); } diff --git a/src/emu/bus/c64/pagefox.h b/src/emu/bus/c64/pagefox.h index 79d7030d497..5437510b3c1 100644 --- a/src/emu/bus/c64/pagefox.h +++ b/src/emu/bus/c64/pagefox.h @@ -43,6 +43,8 @@ protected: virtual void c64_cd_w(address_space &space, offs_t offset, UINT8 data, int sphi2, int ba, int roml, int romh, int io1, int io2); private: + optional_shared_ptr<UINT8> m_ram; + UINT8 m_bank; }; diff --git a/src/emu/bus/c64/partner.c b/src/emu/bus/c64/partner.c index 1d1227e6256..a81dc50c1da 100644 --- a/src/emu/bus/c64/partner.c +++ b/src/emu/bus/c64/partner.c @@ -82,6 +82,7 @@ ioport_constructor c64_partner_cartridge_device::device_input_ports() const c64_partner_cartridge_device::c64_partner_cartridge_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : device_t(mconfig, C64_PARTNER, "C64 PARTNER 64 cartridge", tag, owner, clock, "c64_partner", __FILE__), device_c64_expansion_card_interface(mconfig, *this), + m_ram(*this, "ram"), m_a0(1), m_a6(1), m_nmi(0) @@ -96,7 +97,7 @@ c64_partner_cartridge_device::c64_partner_cartridge_device(const machine_config void c64_partner_cartridge_device::device_start() { // allocate memory - c64_ram_pointer(machine(), 0x2000); + m_ram.allocate(0x2000); } diff --git a/src/emu/bus/c64/partner.h b/src/emu/bus/c64/partner.h index 64cee99de14..bf383f2fa31 100644 --- a/src/emu/bus/c64/partner.h +++ b/src/emu/bus/c64/partner.h @@ -48,6 +48,8 @@ protected: virtual int c64_game_r(offs_t offset, int sphi2, int ba, int rw); private: + optional_shared_ptr<UINT8> m_ram; + int m_a0; int m_a6; int m_nmi; diff --git a/src/emu/bus/c64/reu.c b/src/emu/bus/c64/reu.c index 28f2e8e45b2..67723fd0885 100644 --- a/src/emu/bus/c64/reu.c +++ b/src/emu/bus/c64/reu.c @@ -86,6 +86,8 @@ c64_reu_cartridge_device::c64_reu_cartridge_device(const machine_config &mconfig device_t(mconfig, type, name, tag, owner, clock, shortname, source), device_c64_expansion_card_interface(mconfig, *this), m_dmac(*this, MOS8726R1_TAG), + m_rom(*this, "rom"), + m_ram(*this, "ram"), m_variant(variant), m_jp1(jp1), m_ram_size(ram_size) @@ -108,11 +110,8 @@ c64_reu1764_cartridge_device::c64_reu1764_cartridge_device(const machine_config void c64_reu_cartridge_device::device_start() { - // find memory region - m_roml = memregion("roml")->base(); - // allocate memory - c64_ram_pointer(machine(), m_ram_size); + m_ram.allocate(m_ram_size); // setup DMA controller m_dmac->set_unscaled_clock(m_slot->phi2()); diff --git a/src/emu/bus/c64/reu.h b/src/emu/bus/c64/reu.h index 29a8c6775e0..a2918891268 100644 --- a/src/emu/bus/c64/reu.h +++ b/src/emu/bus/c64/reu.h @@ -56,6 +56,8 @@ protected: virtual void c64_cd_w(address_space &space, offs_t offset, UINT8 data, int sphi2, int ba, int roml, int romh, int io1, int io2); required_device<mos8726_device> m_dmac; + required_memory_region m_rom; + optional_shared_ptr<UINT8> m_ram; int m_variant; int m_jp1; diff --git a/src/emu/bus/c64/ross.c b/src/emu/bus/c64/ross.c index 150a096b037..b380f22e5ea 100644 --- a/src/emu/bus/c64/ross.c +++ b/src/emu/bus/c64/ross.c @@ -70,7 +70,7 @@ UINT8 c64_ross_cartridge_device::c64_cd_r(address_space &space, offs_t offset, U { offs_t addr = (m_bank << 14) | (offset & 0x3fff); - data = m_roml[addr & m_roml_mask]; + data = m_roml[addr & m_roml.mask()]; } return data; diff --git a/src/emu/bus/c64/std.c b/src/emu/bus/c64/std.c index 066188da5e3..954854af5ed 100644 --- a/src/emu/bus/c64/std.c +++ b/src/emu/bus/c64/std.c @@ -51,19 +51,19 @@ void c64_standard_cartridge_device::device_start() UINT8 c64_standard_cartridge_device::c64_cd_r(address_space &space, offs_t offset, UINT8 data, int sphi2, int ba, int roml, int romh, int io1, int io2) { - if (!roml && m_roml_mask) + if (!roml && m_roml.bytes()) { - data = m_roml[offset & 0x1fff]; + data = m_roml[offset & m_roml.mask()]; } else if (!romh) { - if (m_romh_mask) + if (m_romh.bytes()) { - data = m_romh[offset & 0x1fff]; + data = m_romh[offset & m_romh.mask()]; } - else if (m_roml_mask == 0x3fff) + else if (m_roml.mask() == 0x3fff) { - data = m_roml[offset & 0x3fff]; + data = m_roml[offset & m_roml.mask()]; } } diff --git a/src/emu/bus/c64/westermann.c b/src/emu/bus/c64/westermann.c index 369b77c437c..4e76c0b1618 100644 --- a/src/emu/bus/c64/westermann.c +++ b/src/emu/bus/c64/westermann.c @@ -63,17 +63,17 @@ UINT8 c64_westermann_cartridge_device::c64_cd_r(address_space &space, offs_t off { if (!roml) { - data = m_roml[offset & 0x1fff]; + data = m_roml[offset & m_roml.mask()]; } else if (!romh) { - if (m_romh_mask) + if (m_romh.bytes()) { - data = m_romh[offset & 0x1fff]; + data = m_romh[offset & m_romh.mask()]; } else { - data = m_roml[offset & 0x3fff]; + data = m_roml[offset & m_roml.mask()]; } } else if (!io2) diff --git a/src/emu/bus/c64/xl80.c b/src/emu/bus/c64/xl80.c index a0956eaa115..5c1875cd59e 100644 --- a/src/emu/bus/c64/xl80.c +++ b/src/emu/bus/c64/xl80.c @@ -178,7 +178,8 @@ c64_xl80_device::c64_xl80_device(const machine_config &mconfig, const char *tag, device_t(mconfig, C64_XL80, "XL 80", tag, owner, clock, "c64_xl80", __FILE__), device_c64_expansion_card_interface(mconfig, *this), m_crtc(*this, HD46505SP_TAG), - m_char_rom(*this, HD46505SP_TAG) + m_char_rom(*this, HD46505SP_TAG), + m_ram(*this, "ram") { } @@ -190,10 +191,7 @@ c64_xl80_device::c64_xl80_device(const machine_config &mconfig, const char *tag, void c64_xl80_device::device_start() { // allocate memory - c64_ram_pointer(machine(), RAM_SIZE); - - // state saving - save_pointer(NAME(m_ram), RAM_SIZE); + m_ram.allocate(RAM_SIZE); } diff --git a/src/emu/bus/c64/xl80.h b/src/emu/bus/c64/xl80.h index 30896134fe9..a8ec1aadb53 100644 --- a/src/emu/bus/c64/xl80.h +++ b/src/emu/bus/c64/xl80.h @@ -55,6 +55,7 @@ protected: private: required_device<h46505_device> m_crtc; required_memory_region m_char_rom; + optional_shared_ptr<UINT8> m_ram; }; diff --git a/src/emu/bus/cbm2/24k.c b/src/emu/bus/cbm2/24k.c index 7cb34a96c31..b1dd15e8f0a 100644 --- a/src/emu/bus/cbm2/24k.c +++ b/src/emu/bus/cbm2/24k.c @@ -31,7 +31,8 @@ const device_type CBM2_24K = &device_creator<cbm2_24k_cartridge_device>; cbm2_24k_cartridge_device::cbm2_24k_cartridge_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : device_t(mconfig, CBM2_24K, "24K RAM/ROM cartridge", tag, owner, clock, "cbm2_24k", __FILE__), - device_cbm2_expansion_card_interface(mconfig, *this) + device_cbm2_expansion_card_interface(mconfig, *this), + m_ram(*this, "ram") { } @@ -42,7 +43,7 @@ cbm2_24k_cartridge_device::cbm2_24k_cartridge_device(const machine_config &mconf void cbm2_24k_cartridge_device::device_start() { - cbm2_ram_pointer(machine(), 0x6000); + m_ram.allocate(0x6000); } diff --git a/src/emu/bus/cbm2/24k.h b/src/emu/bus/cbm2/24k.h index bff7e2b7398..6aa28a33c22 100644 --- a/src/emu/bus/cbm2/24k.h +++ b/src/emu/bus/cbm2/24k.h @@ -39,6 +39,8 @@ protected: // device_cbm2_expansion_card_interface overrides virtual UINT8 cbm2_bd_r(address_space &space, offs_t offset, UINT8 data, int csbank1, int csbank2, int csbank3); virtual void cbm2_bd_w(address_space &space, offs_t offset, UINT8 data, int csbank1, int csbank2, int csbank3); + + optional_shared_ptr<UINT8> m_ram; }; diff --git a/src/emu/bus/cbm2/exp.c b/src/emu/bus/cbm2/exp.c index 315fa7cbe78..2017dfc8041 100644 --- a/src/emu/bus/cbm2/exp.c +++ b/src/emu/bus/cbm2/exp.c @@ -39,16 +39,9 @@ const device_type CBM2_EXPANSION_SLOT = &device_creator<cbm2_expansion_slot_devi device_cbm2_expansion_card_interface::device_cbm2_expansion_card_interface(const machine_config &mconfig, device_t &device) : device_slot_card_interface(mconfig, device), - m_bank1(NULL), - m_bank2(NULL), - m_bank3(NULL), - m_ram(NULL), - m_nvram(NULL), - m_nvram_size(0), - m_bank1_mask(0), - m_bank2_mask(0), - m_bank3_mask(0), - m_ram_mask(0) + m_bank1(*this, "bank1"), + m_bank2(*this, "bank2"), + m_bank3(*this, "bank3") { m_slot = dynamic_cast<cbm2_expansion_slot_device *>(device.owner()); } @@ -63,92 +56,6 @@ device_cbm2_expansion_card_interface::~device_cbm2_expansion_card_interface() } -//------------------------------------------------- -// cbm2_bank1_pointer - get bank 1 pointer -//------------------------------------------------- - -UINT8* device_cbm2_expansion_card_interface::cbm2_bank1_pointer(running_machine &machine, size_t size) -{ - if (m_bank1 == NULL) - { - m_bank1 = auto_alloc_array(machine, UINT8, size); - - m_bank1_mask = size - 1; - } - - return m_bank1; -} - - -//------------------------------------------------- -// cbm2_bank2_pointer - get bank 2 pointer -//------------------------------------------------- - -UINT8* device_cbm2_expansion_card_interface::cbm2_bank2_pointer(running_machine &machine, size_t size) -{ - if (m_bank2 == NULL) - { - m_bank2 = auto_alloc_array(machine, UINT8, size); - - m_bank2_mask = size - 1; - } - - return m_bank2; -} - - -//------------------------------------------------- -// cbm2_bank3_pointer - get bank 3 pointer -//------------------------------------------------- - -UINT8* device_cbm2_expansion_card_interface::cbm2_bank3_pointer(running_machine &machine, size_t size) -{ - if (m_bank3 == NULL) - { - m_bank3 = auto_alloc_array(machine, UINT8, size); - - m_bank3_mask = size - 1; - } - - return m_bank3; -} - - -//------------------------------------------------- -// cbm2_ram_pointer - get RAM pointer -//------------------------------------------------- - -UINT8* device_cbm2_expansion_card_interface::cbm2_ram_pointer(running_machine &machine, size_t size) -{ - if (m_ram == NULL) - { - m_ram = auto_alloc_array(machine, UINT8, size); - - m_ram_mask = size - 1; - } - - return m_ram; -} - - -//------------------------------------------------- -// cbm2_ram_pointer - get NVRAM pointer -//------------------------------------------------- - -UINT8* device_cbm2_expansion_card_interface::cbm2_nvram_pointer(running_machine &machine, size_t size) -{ - if (m_nvram == NULL) - { - m_nvram = auto_alloc_array(machine, UINT8, size); - - m_nvram_mask = size - 1; - m_nvram_size = size; - } - - return m_nvram; -} - - //************************************************************************** // LIVE DEVICE @@ -209,33 +116,25 @@ bool cbm2_expansion_slot_device::call_load() if (!mame_stricmp(filetype(), "20")) { - fread(m_card->cbm2_bank1_pointer(machine(), size), size); + m_card->m_bank1.allocate(size); + fread(m_card->m_bank1, size); } else if (!mame_stricmp(filetype(), "40")) { - fread(m_card->cbm2_bank2_pointer(machine(), size), size); + m_card->m_bank2.allocate(size); + fread(m_card->m_bank2, size); } else if (!mame_stricmp(filetype(), "60")) { - fread(m_card->cbm2_bank3_pointer(machine(), size), size); + m_card->m_bank3.allocate(size); + fread(m_card->m_bank3, size); } } else { - size = get_software_region_length("bank1"); - if (size) memcpy(m_card->cbm2_bank1_pointer(machine(), size), get_software_region("bank1"), size); - - size = get_software_region_length("bank2"); - if (size) memcpy(m_card->cbm2_bank2_pointer(machine(), size), get_software_region("bank2"), size); - - size = get_software_region_length("bank3"); - if (size) memcpy(m_card->cbm2_bank3_pointer(machine(), size), get_software_region("bank3"), size); - - size = get_software_region_length("ram"); - if (size) memset(m_card->cbm2_ram_pointer(machine(), size), 0, size); - - size = get_software_region_length("nvram"); - if (size) memset(m_card->cbm2_nvram_pointer(machine(), size), 0, size); + load_software_region("bank1", m_card->m_bank1); + load_software_region("bank2", m_card->m_bank2); + load_software_region("bank3", m_card->m_bank3); } } diff --git a/src/emu/bus/cbm2/exp.h b/src/emu/bus/cbm2/exp.h index be541a0df4b..c04895758da 100644 --- a/src/emu/bus/cbm2/exp.h +++ b/src/emu/bus/cbm2/exp.h @@ -116,33 +116,15 @@ public: device_cbm2_expansion_card_interface(const machine_config &mconfig, device_t &device); virtual ~device_cbm2_expansion_card_interface(); -protected: - // initialization - virtual UINT8* cbm2_bank1_pointer(running_machine &machine, size_t size); - virtual UINT8* cbm2_bank2_pointer(running_machine &machine, size_t size); - virtual UINT8* cbm2_bank3_pointer(running_machine &machine, size_t size); - virtual UINT8* cbm2_ram_pointer(running_machine &machine, size_t size); - virtual UINT8* cbm2_nvram_pointer(running_machine &machine, size_t size); - - // runtime virtual UINT8 cbm2_bd_r(address_space &space, offs_t offset, UINT8 data, int csbank1, int csbank2, int csbank3) { return data; }; virtual void cbm2_bd_w(address_space &space, offs_t offset, UINT8 data, int csbank1, int csbank2, int csbank3) { }; - cbm2_expansion_slot_device *m_slot; - - UINT8 *m_bank1; - UINT8 *m_bank2; - UINT8 *m_bank3; - UINT8 *m_ram; - UINT8 *m_nvram; - - size_t m_nvram_size; +protected: + optional_shared_ptr<UINT8> m_bank1; + optional_shared_ptr<UINT8> m_bank2; + optional_shared_ptr<UINT8> m_bank3; - size_t m_bank1_mask; - size_t m_bank2_mask; - size_t m_bank3_mask; - size_t m_ram_mask; - size_t m_nvram_mask; + cbm2_expansion_slot_device *m_slot; }; diff --git a/src/emu/bus/cbm2/std.c b/src/emu/bus/cbm2/std.c index a872201b968..a8198c8085b 100644 --- a/src/emu/bus/cbm2/std.c +++ b/src/emu/bus/cbm2/std.c @@ -51,17 +51,17 @@ void cbm2_standard_cartridge_device::device_start() UINT8 cbm2_standard_cartridge_device::cbm2_bd_r(address_space &space, offs_t offset, UINT8 data, int csbank1, int csbank2, int csbank3) { - if (!csbank1 && m_bank1_mask) + if (!csbank1 && m_bank1.bytes()) { - data = m_bank1[offset & m_bank1_mask]; + data = m_bank1[offset & m_bank1.mask()]; } - else if (!csbank2 && m_bank2_mask) + else if (!csbank2 && m_bank2.bytes()) { - data = m_bank2[offset & m_bank2_mask]; + data = m_bank2[offset & m_bank2.mask()]; } - else if (!csbank3 && m_bank3_mask) + else if (!csbank3 && m_bank3.bytes()) { - data = m_bank3[offset & m_bank3_mask]; + data = m_bank3[offset & m_bank3.mask()]; } return data; diff --git a/src/emu/bus/plus4/exp.c b/src/emu/bus/plus4/exp.c index 5be58be399e..10c24911558 100644 --- a/src/emu/bus/plus4/exp.c +++ b/src/emu/bus/plus4/exp.c @@ -39,18 +39,14 @@ const device_type PLUS4_EXPANSION_SLOT = &device_creator<plus4_expansion_slot_de device_plus4_expansion_card_interface::device_plus4_expansion_card_interface(const machine_config &mconfig, device_t &device) : device_slot_card_interface(mconfig, device), - m_c1l(NULL), - m_c1h(NULL), - m_c2l(NULL), - m_c2h(NULL), - m_ram(NULL), - m_nvram(NULL), - m_nvram_size(0), + m_c1l(*this, "c1l"), + m_c1h(*this, "c1h"), + m_c2l(*this, "c2l"), + m_c2h(*this, "c2h"), m_c1l_mask(0), m_c1h_mask(0), m_c2l_mask(0), - m_c2h_mask(0), - m_ram_mask(0) + m_c2h_mask(0) { m_slot = dynamic_cast<plus4_expansion_slot_device *>(device.owner()); } @@ -65,109 +61,6 @@ device_plus4_expansion_card_interface::~device_plus4_expansion_card_interface() } -//------------------------------------------------- -// plus4_c1l_pointer - get low ROM 1 pointer -//------------------------------------------------- - -UINT8* device_plus4_expansion_card_interface::plus4_c1l_pointer(running_machine &machine, size_t size) -{ - if (m_c1l == NULL) - { - m_c1l = auto_alloc_array(machine, UINT8, size); - - m_c1l_mask = size - 1; - } - - return m_c1l; -} - - -//------------------------------------------------- -// plus4_c1h_pointer - get low ROM 1 pointer -//------------------------------------------------- - -UINT8* device_plus4_expansion_card_interface::plus4_c1h_pointer(running_machine &machine, size_t size) -{ - if (m_c1h == NULL) - { - m_c1h = auto_alloc_array(machine, UINT8, size); - - m_c1h_mask = size - 1; - } - - return m_c1h; -} - - -//------------------------------------------------- -// plus4_c2l_pointer - get low ROM 1 pointer -//------------------------------------------------- - -UINT8* device_plus4_expansion_card_interface::plus4_c2l_pointer(running_machine &machine, size_t size) -{ - if (m_c2l == NULL) - { - m_c2l = auto_alloc_array(machine, UINT8, size); - - m_c2l_mask = size - 1; - } - - return m_c2l; -} - - -//------------------------------------------------- -// plus4_c2h_pointer - get low ROM 1 pointer -//------------------------------------------------- - -UINT8* device_plus4_expansion_card_interface::plus4_c2h_pointer(running_machine &machine, size_t size) -{ - if (m_c2h == NULL) - { - m_c2h = auto_alloc_array(machine, UINT8, size); - - m_c2h_mask = size - 1; - } - - return m_c2h; -} - - -//------------------------------------------------- -// plus4_ram_pointer - get RAM pointer -//------------------------------------------------- - -UINT8* device_plus4_expansion_card_interface::plus4_ram_pointer(running_machine &machine, size_t size) -{ - if (m_ram == NULL) - { - m_ram = auto_alloc_array(machine, UINT8, size); - - m_ram_mask = size - 1; - } - - return m_ram; -} - - -//------------------------------------------------- -// plus4_ram_pointer - get NVRAM pointer -//------------------------------------------------- - -UINT8* device_plus4_expansion_card_interface::plus4_nvram_pointer(running_machine &machine, size_t size) -{ - if (m_nvram == NULL) - { - m_nvram = auto_alloc_array(machine, UINT8, size); - - m_nvram_mask = size - 1; - m_nvram_size = size; - } - - return m_nvram; -} - - //************************************************************************** // LIVE DEVICE @@ -234,31 +127,16 @@ bool plus4_expansion_slot_device::call_load() { if (m_card) { - size_t size = 0; - if (software_entry() == NULL) { // TODO } else { - size = get_software_region_length("c1l"); - if (size) memcpy(m_card->plus4_c1l_pointer(machine(), size), get_software_region("c1l"), size); - - size = get_software_region_length("c1h"); - if (size) memcpy(m_card->plus4_c1h_pointer(machine(), size), get_software_region("c1h"), size); - - size = get_software_region_length("c2l"); - if (size) memcpy(m_card->plus4_c2l_pointer(machine(), size), get_software_region("c2l"), size); - - size = get_software_region_length("c2h"); - if (size) memcpy(m_card->plus4_c2h_pointer(machine(), size), get_software_region("c2h"), size); - - size = get_software_region_length("ram"); - if (size) memset(m_card->plus4_ram_pointer(machine(), size), 0, size); - - size = get_software_region_length("nvram"); - if (size) memset(m_card->plus4_nvram_pointer(machine(), size), 0, size); + load_software_region("c1l", m_card->m_c1l); + load_software_region("c1h", m_card->m_c1h); + load_software_region("c2l", m_card->m_c2l); + load_software_region("c2h", m_card->m_c2h); } } diff --git a/src/emu/bus/plus4/exp.h b/src/emu/bus/plus4/exp.h index 153d1d57331..3688c36a287 100644 --- a/src/emu/bus/plus4/exp.h +++ b/src/emu/bus/plus4/exp.h @@ -152,36 +152,22 @@ public: device_plus4_expansion_card_interface(const machine_config &mconfig, device_t &device); virtual ~device_plus4_expansion_card_interface(); - // initialization - virtual UINT8* plus4_c1l_pointer(running_machine &machine, size_t size); - virtual UINT8* plus4_c1h_pointer(running_machine &machine, size_t size); - virtual UINT8* plus4_c2l_pointer(running_machine &machine, size_t size); - virtual UINT8* plus4_c2h_pointer(running_machine &machine, size_t size); - virtual UINT8* plus4_ram_pointer(running_machine &machine, size_t size); - virtual UINT8* plus4_nvram_pointer(running_machine &machine, size_t size); - // runtime virtual UINT8 plus4_cd_r(address_space &space, offs_t offset, UINT8 data, int ba, int cs0, int c1l, int c2l, int cs1, int c1h, int c2h) { return data; }; virtual void plus4_cd_w(address_space &space, offs_t offset, UINT8 data, int ba, int cs0, int c1l, int c2l, int cs1, int c1h, int c2h) { }; protected: - plus4_expansion_slot_device *m_slot; - - UINT8 *m_c1l; - UINT8 *m_c1h; - UINT8 *m_c2l; - UINT8 *m_c2h; - UINT8 *m_ram; - UINT8 *m_nvram; - - size_t m_nvram_size; + optional_shared_ptr<UINT8> m_c1l; + optional_shared_ptr<UINT8> m_c1h; + optional_shared_ptr<UINT8> m_c2l; + optional_shared_ptr<UINT8> m_c2h; size_t m_c1l_mask; size_t m_c1h_mask; size_t m_c2l_mask; size_t m_c2h_mask; - size_t m_ram_mask; - size_t m_nvram_mask; + + plus4_expansion_slot_device *m_slot; }; diff --git a/src/emu/bus/plus4/std.c b/src/emu/bus/plus4/std.c index 39174d183d1..943c874ac81 100644 --- a/src/emu/bus/plus4/std.c +++ b/src/emu/bus/plus4/std.c @@ -51,21 +51,21 @@ void plus4_standard_cartridge_device::device_start() UINT8 plus4_standard_cartridge_device::plus4_cd_r(address_space &space, offs_t offset, UINT8 data, int ba, int cs0, int c1l, int c2l, int cs1, int c1h, int c2h) { - if (!c1l && m_c1l_mask) + if (!c1l && m_c1l.bytes()) { - data = m_c1l[offset & m_c1l_mask]; + data = m_c1l[offset & m_c1l.mask()]; } - else if (!c1h && m_c1h_mask) + else if (!c1h && m_c1h.bytes()) { - data = m_c1h[offset & m_c1h_mask]; + data = m_c1h[offset & m_c1h.mask()]; } - else if (!c2l && m_c2l_mask) + else if (!c2l && m_c2l.bytes()) { - data = m_c2l[offset & m_c2l_mask]; + data = m_c2l[offset & m_c2l.mask()]; } - else if (!c2h && m_c2h_mask) + else if (!c2h && m_c2h.bytes()) { - data = m_c2h[offset & m_c2h_mask]; + data = m_c2h[offset & m_c2h.mask()]; } return data; diff --git a/src/emu/bus/plus4/std.h b/src/emu/bus/plus4/std.h index 6a50a762ce2..127bf66aa2f 100644 --- a/src/emu/bus/plus4/std.h +++ b/src/emu/bus/plus4/std.h @@ -39,6 +39,8 @@ protected: // device_plus4_expansion_card_interface overrides virtual UINT8 plus4_cd_r(address_space &space, offs_t offset, UINT8 data, int ba, int cs0, int c1l, int c2l, int cs1, int c1h, int c2h); + + }; diff --git a/src/emu/bus/vic10/exp.c b/src/emu/bus/vic10/exp.c index 67f4b39b195..4fe8dc5cc54 100644 --- a/src/emu/bus/vic10/exp.c +++ b/src/emu/bus/vic10/exp.c @@ -33,9 +33,9 @@ const device_type VIC10_EXPANSION_SLOT = &device_creator<vic10_expansion_slot_de device_vic10_expansion_card_interface::device_vic10_expansion_card_interface(const machine_config &mconfig, device_t &device) : device_slot_card_interface(mconfig,device), - m_exram(NULL), - m_lorom(NULL), - m_uprom(NULL) + m_lorom(*this, "lorom"), + m_exram(*this, "exram"), + m_uprom(*this, "uprom") { m_slot = dynamic_cast<vic10_expansion_slot_device *>(device.owner()); } @@ -51,52 +51,6 @@ device_vic10_expansion_card_interface::~device_vic10_expansion_card_interface() -//------------------------------------------------- -// vic10_lorom_pointer - get lower ROM pointer -//------------------------------------------------- - -UINT8* device_vic10_expansion_card_interface::vic10_lorom_pointer(running_machine &machine, size_t size) -{ - if (m_lorom == NULL) - { - m_lorom = auto_alloc_array(machine, UINT8, size); - } - - return m_lorom; -} - - -//------------------------------------------------- -// vic10_uprom_pointer - get upper ROM pointer -//------------------------------------------------- - -UINT8* device_vic10_expansion_card_interface::vic10_uprom_pointer(running_machine &machine, size_t size) -{ - if (m_uprom == NULL) - { - m_uprom = auto_alloc_array(machine, UINT8, size); - } - - return m_uprom; -} - - -//------------------------------------------------- -// vic10_exram_pointer - get expanded RAM pointer -//------------------------------------------------- - -UINT8* device_vic10_expansion_card_interface::vic10_exram_pointer(running_machine &machine, size_t size) -{ - if (m_exram == NULL) - { - m_exram = auto_alloc_array(machine, UINT8, size); - } - - return m_exram; -} - - - //************************************************************************** // LIVE DEVICE //************************************************************************** @@ -170,14 +124,17 @@ bool vic10_expansion_slot_device::call_load() if (!mame_stricmp(filetype(), "80")) { - fread(m_card->vic10_lorom_pointer(machine(), 0x2000), 0x2000); + fread(m_card->m_lorom, 0x2000); if (size == 0x4000) { - fread(m_card->vic10_uprom_pointer(machine(), 0x2000), 0x2000); + fread(m_card->m_uprom, 0x2000); } } - else if (!mame_stricmp(filetype(), "e0")) fread(m_card->vic10_uprom_pointer(machine(), size), size); + else if (!mame_stricmp(filetype(), "e0")) + { + fread(m_card->m_uprom, size); + } else if (!mame_stricmp(filetype(), "crt")) { size_t roml_size = 0; @@ -190,8 +147,11 @@ bool vic10_expansion_slot_device::call_load() UINT8 *roml = NULL; UINT8 *romh = NULL; - if (roml_size) roml = m_card->vic10_lorom_pointer(machine(), roml_size); - if (romh_size) romh = m_card->vic10_uprom_pointer(machine(), romh_size); + m_card->m_lorom.allocate(roml_size); + m_card->m_uprom.allocate(romh_size); + + if (roml_size) roml = m_card->m_lorom; + if (romh_size) romh = m_card->m_lorom; cbm_crt_read_data(m_file, roml, romh); } @@ -199,14 +159,9 @@ bool vic10_expansion_slot_device::call_load() } else { - size = get_software_region_length("lorom"); - if (size) memcpy(m_card->vic10_lorom_pointer(machine(), size), get_software_region("lorom"), size); - - size = get_software_region_length("uprom"); - if (size) memcpy(m_card->vic10_uprom_pointer(machine(), size), get_software_region("uprom"), size); - - size = get_software_region_length("exram"); - if (size) m_card->vic10_exram_pointer(machine(), size); + load_software_region("lorom", m_card->m_lorom); + load_software_region("exram", m_card->m_exram); + load_software_region("uprom", m_card->m_uprom); } } diff --git a/src/emu/bus/vic10/exp.h b/src/emu/bus/vic10/exp.h index 68236430fea..828cb182f86 100644 --- a/src/emu/bus/vic10/exp.h +++ b/src/emu/bus/vic10/exp.h @@ -152,13 +152,6 @@ public: device_vic10_expansion_card_interface(const machine_config &mconfig, device_t &device); virtual ~device_vic10_expansion_card_interface(); -protected: - // initialization - virtual UINT8* vic10_exram_pointer(running_machine &machine, size_t size); - virtual UINT8* vic10_lorom_pointer(running_machine &machine, size_t size); - virtual UINT8* vic10_uprom_pointer(running_machine &machine, size_t size); - - // runtime virtual UINT8 vic10_cd_r(address_space &space, offs_t offset, UINT8 data, int lorom, int uprom, int exram) { return data; }; virtual void vic10_cd_w(address_space &space, offs_t offset, UINT8 data, int lorom, int uprom, int exram) { }; virtual int vic10_p0_r() { return 0; }; @@ -166,11 +159,12 @@ protected: virtual void vic10_sp_w(int state) { }; virtual void vic10_cnt_w(int state) { }; - vic10_expansion_slot_device *m_slot; +protected: + optional_shared_ptr<UINT8> m_lorom; + optional_shared_ptr<UINT8> m_exram; + optional_shared_ptr<UINT8> m_uprom; - UINT8 *m_exram; - UINT8 *m_lorom; - UINT8 *m_uprom; + vic10_expansion_slot_device *m_slot; }; diff --git a/src/emu/bus/vic10/std.c b/src/emu/bus/vic10/std.c index f7afdcf7c3c..dfdecd34f81 100644 --- a/src/emu/bus/vic10/std.c +++ b/src/emu/bus/vic10/std.c @@ -51,17 +51,17 @@ void vic10_standard_cartridge_device::device_start() UINT8 vic10_standard_cartridge_device::vic10_cd_r(address_space &space, offs_t offset, UINT8 data, int lorom, int uprom, int exram) { - if (!lorom && (m_lorom != NULL)) + if (!lorom && m_lorom.bytes()) { - data = m_lorom[offset & 0x1fff]; + data = m_lorom[offset & m_lorom.mask()]; } - else if (!exram && (m_exram != NULL)) + else if (!exram && m_exram.bytes()) { - data = m_exram[offset & 0x7ff]; + data = m_exram[offset & m_exram.mask()]; } - else if (!uprom && (m_uprom != NULL)) + else if (!uprom && m_uprom.bytes()) { - data = m_uprom[offset & 0x1fff]; + data = m_uprom[offset & m_uprom.mask()]; } return data; @@ -74,8 +74,8 @@ UINT8 vic10_standard_cartridge_device::vic10_cd_r(address_space &space, offs_t o void vic10_standard_cartridge_device::vic10_cd_w(address_space &space, offs_t offset, UINT8 data, int lorom, int uprom, int exram) { - if (!exram && (m_exram != NULL)) + if (!exram && m_exram.bytes()) { - m_exram[offset & 0x7ff] = data; + m_exram[offset & m_exram.mask()] = data; } } diff --git a/src/emu/bus/vic10/std.h b/src/emu/bus/vic10/std.h index ca5fc55f593..2aa7e3574f7 100644 --- a/src/emu/bus/vic10/std.h +++ b/src/emu/bus/vic10/std.h @@ -26,7 +26,7 @@ // ======================> vic10_standard_cartridge_device class vic10_standard_cartridge_device : public device_t, - public device_vic10_expansion_card_interface + public device_vic10_expansion_card_interface { public: // construction/destruction diff --git a/src/emu/bus/vic20/exp.c b/src/emu/bus/vic20/exp.c index 4dcd2de9e56..5c99fd7c80f 100644 --- a/src/emu/bus/vic20/exp.c +++ b/src/emu/bus/vic20/exp.c @@ -33,112 +33,17 @@ const device_type VIC20_EXPANSION_SLOT = &device_creator<vic20_expansion_slot_de device_vic20_expansion_card_interface::device_vic20_expansion_card_interface(const machine_config &mconfig, device_t &device) : device_slot_card_interface(mconfig, device), - m_blk1(NULL), - m_blk2(NULL), - m_blk3(NULL), - m_blk5(NULL), - m_ram(NULL), - m_nvram(NULL), - m_nvram_size(0) + m_blk1(*this, "blk1"), + m_blk2(*this, "blk2"), + m_blk3(*this, "blk3"), + m_blk5(*this, "blk5"), + m_nvram(*this, "nvram") { m_slot = dynamic_cast<vic20_expansion_slot_device *>(device.owner()); } //------------------------------------------------- -// vic20_blk1_pointer - get block 1 pointer -//------------------------------------------------- - -UINT8* device_vic20_expansion_card_interface::vic20_blk1_pointer(running_machine &machine, size_t size) -{ - if (m_blk1 == NULL) - { - m_blk1 = auto_alloc_array(machine, UINT8, size); - } - - return m_blk1; -} - - -//------------------------------------------------- -// vic20_blk2_pointer - get block 2 pointer -//------------------------------------------------- - -UINT8* device_vic20_expansion_card_interface::vic20_blk2_pointer(running_machine &machine, size_t size) -{ - if (m_blk2 == NULL) - { - m_blk2 = auto_alloc_array(machine, UINT8, size); - } - - return m_blk2; -} - - -//------------------------------------------------- -// vic20_blk3_pointer - get block 3 pointer -//------------------------------------------------- - -UINT8* device_vic20_expansion_card_interface::vic20_blk3_pointer(running_machine &machine, size_t size) -{ - if (m_blk3 == NULL) - { - m_blk3 = auto_alloc_array(machine, UINT8, size); - } - - return m_blk3; -} - - -//------------------------------------------------- -// vic20_blk5_pointer - get block 5 pointer -//------------------------------------------------- - -UINT8* device_vic20_expansion_card_interface::vic20_blk5_pointer(running_machine &machine, size_t size) -{ - if (m_blk5 == NULL) - { - m_blk5 = auto_alloc_array(machine, UINT8, size); - } - - return m_blk5; -} - - -//------------------------------------------------- -// vic20_ram_pointer - get RAM pointer -//------------------------------------------------- - -UINT8* device_vic20_expansion_card_interface::vic20_ram_pointer(running_machine &machine, size_t size) -{ - if (m_ram == NULL) - { - m_ram = auto_alloc_array(machine, UINT8, size); - } - - return m_ram; -} - - -//------------------------------------------------- -// vic20_nvram_pointer - get NVRAM pointer -//------------------------------------------------- - -UINT8* device_vic20_expansion_card_interface::vic20_nvram_pointer(running_machine &machine, size_t size) -{ - if (m_nvram == NULL) - { - m_nvram = auto_alloc_array(machine, UINT8, size); - - m_nvram_mask = size - 1; - m_nvram_size = size; - } - - return m_nvram; -} - - -//------------------------------------------------- // ~device_vic20_expansion_card_interface - destructor //------------------------------------------------- @@ -211,16 +116,14 @@ bool vic20_expansion_slot_device::call_load() { if (m_card) { - size_t size = 0; - if (software_entry() == NULL) { - if (!mame_stricmp(filetype(), "20")) fread(m_card->vic20_blk1_pointer(machine(), 0x2000), 0x2000); - else if (!mame_stricmp(filetype(), "40")) fread(m_card->vic20_blk2_pointer(machine(), 0x2000), 0x2000); - else if (!mame_stricmp(filetype(), "60")) fread(m_card->vic20_blk3_pointer(machine(), 0x2000), 0x2000); - else if (!mame_stricmp(filetype(), "70")) fread(m_card->vic20_blk3_pointer(machine(), 0x2000) + 0x1000, 0x1000); - else if (!mame_stricmp(filetype(), "a0")) fread(m_card->vic20_blk5_pointer(machine(), 0x2000), 0x2000); - else if (!mame_stricmp(filetype(), "b0")) fread(m_card->vic20_blk5_pointer(machine(), 0x2000) + 0x1000, 0x1000); + if (!mame_stricmp(filetype(), "20")) fread(m_card->m_blk1, 0x2000); + else if (!mame_stricmp(filetype(), "40")) fread(m_card->m_blk2, 0x2000); + else if (!mame_stricmp(filetype(), "60")) fread(m_card->m_blk3, 0x2000); + else if (!mame_stricmp(filetype(), "70")) fread(m_card->m_blk3, 0x2000, 0x1000); + else if (!mame_stricmp(filetype(), "a0")) fread(m_card->m_blk5, 0x2000); + else if (!mame_stricmp(filetype(), "b0")) fread(m_card->m_blk5, 0x2000, 0x1000); else if (!mame_stricmp(filetype(), "crt")) { // read the header @@ -230,36 +133,22 @@ bool vic20_expansion_slot_device::call_load() switch (address) { - case 0x2000: fread(m_card->vic20_blk1_pointer(machine(), 0x2000), 0x2000); break; - case 0x4000: fread(m_card->vic20_blk2_pointer(machine(), 0x2000), 0x2000); break; - case 0x6000: fread(m_card->vic20_blk3_pointer(machine(), 0x2000), 0x2000); break; - case 0x7000: fread(m_card->vic20_blk3_pointer(machine(), 0x2000) + 0x1000, 0x1000); break; - case 0xa000: fread(m_card->vic20_blk5_pointer(machine(), 0x2000), 0x2000); break; - case 0xb000: fread(m_card->vic20_blk5_pointer(machine(), 0x2000) + 0x1000, 0x1000); break; + case 0x2000: fread(m_card->m_blk1, 0x2000); break; + case 0x4000: fread(m_card->m_blk2, 0x2000); break; + case 0x6000: fread(m_card->m_blk3, 0x2000); break; + case 0x7000: fread(m_card->m_blk3, 0x2000, 0x1000); break; + case 0xa000: fread(m_card->m_blk5, 0x2000); break; + case 0xb000: fread(m_card->m_blk5, 0x2000, 0x1000); break; default: return IMAGE_INIT_FAIL; } } } else { - size = get_software_region_length("blk1"); - if (size) memcpy(m_card->vic20_blk1_pointer(machine(), size), get_software_region("blk1"), size); - - size = get_software_region_length("blk2"); - if (size) memcpy(m_card->vic20_blk2_pointer(machine(), size), get_software_region("blk2"), size); - - size = get_software_region_length("blk3"); - if (size) memcpy(m_card->vic20_blk3_pointer(machine(), size), get_software_region("blk3"), size); - - size = get_software_region_length("blk5"); - if (size) memcpy(m_card->vic20_blk5_pointer(machine(), size), get_software_region("blk5"), size); - - size = get_software_region_length("ram"); - if (size) memcpy(m_card->vic20_ram_pointer(machine(), size), get_software_region("ram"), size); - - size = get_software_region_length("nvram"); - if (size) memcpy(m_card->vic20_nvram_pointer(machine(), size), get_software_region("nvram"), size); - + load_software_region("blk1", m_card->m_blk1); + load_software_region("blk2", m_card->m_blk2); + load_software_region("blk3", m_card->m_blk3); + load_software_region("blk5", m_card->m_blk5); } } diff --git a/src/emu/bus/vic20/exp.h b/src/emu/bus/vic20/exp.h index 099af84dfd1..c1c7389be60 100644 --- a/src/emu/bus/vic20/exp.h +++ b/src/emu/bus/vic20/exp.h @@ -144,31 +144,17 @@ public: device_vic20_expansion_card_interface(const machine_config &mconfig, device_t &device); virtual ~device_vic20_expansion_card_interface(); -protected: - // initialization - virtual UINT8* vic20_blk1_pointer(running_machine &machine, size_t size); - virtual UINT8* vic20_blk2_pointer(running_machine &machine, size_t size); - virtual UINT8* vic20_blk3_pointer(running_machine &machine, size_t size); - virtual UINT8* vic20_blk5_pointer(running_machine &machine, size_t size); - virtual UINT8* vic20_ram_pointer(running_machine &machine, size_t size); - virtual UINT8* vic20_nvram_pointer(running_machine &machine, size_t size); - - // runtime virtual UINT8 vic20_cd_r(address_space &space, offs_t offset, UINT8 data, int ram1, int ram2, int ram3, int blk1, int blk2, int blk3, int blk5, int io2, int io3) { return data; }; virtual void vic20_cd_w(address_space &space, offs_t offset, UINT8 data, int ram1, int ram2, int ram3, int blk1, int blk2, int blk3, int blk5, int io2, int io3) { }; - vic20_expansion_slot_device *m_slot; - - UINT8 *m_blk1; - UINT8 *m_blk2; - UINT8 *m_blk3; - UINT8 *m_blk5; - UINT8 *m_ram; - UINT8 *m_nvram; - - size_t m_nvram_size; +protected: + optional_shared_ptr<UINT8> m_blk1; + optional_shared_ptr<UINT8> m_blk2; + optional_shared_ptr<UINT8> m_blk3; + optional_shared_ptr<UINT8> m_blk5; + optional_shared_ptr<UINT8> m_nvram; - size_t m_nvram_mask; + vic20_expansion_slot_device *m_slot; }; diff --git a/src/emu/bus/vic20/megacart.c b/src/emu/bus/vic20/megacart.c index 32b562a053c..582bd3de6d9 100644 --- a/src/emu/bus/vic20/megacart.c +++ b/src/emu/bus/vic20/megacart.c @@ -21,10 +21,10 @@ const device_type VIC20_MEGACART = &device_creator<vic20_megacart_device>; //------------------------------------------------- -// MACHINE_DRIVER( vic1112 ) +// MACHINE_DRIVER( vic20_megacart ) //------------------------------------------------- -static MACHINE_CONFIG_FRAGMENT( vic1112 ) +static MACHINE_CONFIG_FRAGMENT( vic20_megacart ) MACHINE_CONFIG_END @@ -36,7 +36,7 @@ MACHINE_CONFIG_END machine_config_constructor vic20_megacart_device::device_mconfig_additions() const { - return MACHINE_CONFIG_NAME( vic1112 ); + return MACHINE_CONFIG_NAME( vic20_megacart ); } @@ -64,6 +64,8 @@ vic20_megacart_device::vic20_megacart_device(const machine_config &mconfig, cons void vic20_megacart_device::device_start() { + m_nvram.allocate(0x2000); + // state saving save_item(NAME(m_nvram_en)); } diff --git a/src/emu/bus/vic20/megacart.h b/src/emu/bus/vic20/megacart.h index 021ae0f56a9..6440925ed9f 100644 --- a/src/emu/bus/vic20/megacart.h +++ b/src/emu/bus/vic20/megacart.h @@ -43,8 +43,8 @@ protected: // device_nvram_interface overrides virtual void nvram_default() { } - virtual void nvram_read(emu_file &file) { if (m_nvram != NULL) { file.read(m_nvram, m_nvram_size); } } - virtual void nvram_write(emu_file &file) { if (m_nvram != NULL) { file.write(m_nvram, m_nvram_size); } } + virtual void nvram_read(emu_file &file) { file.read(m_nvram, m_nvram.bytes()); } + virtual void nvram_write(emu_file &file) { file.write(m_nvram, m_nvram.bytes()); } // device_vic20_expansion_card_interface overrides virtual UINT8 vic20_cd_r(address_space &space, offs_t offset, UINT8 data, int ram1, int ram2, int ram3, int blk1, int blk2, int blk3, int blk5, int io2, int io3); diff --git a/src/emu/bus/vic20/vic1110.c b/src/emu/bus/vic20/vic1110.c index b387489667d..aea20954cf5 100644 --- a/src/emu/bus/vic20/vic1110.c +++ b/src/emu/bus/vic20/vic1110.c @@ -71,6 +71,7 @@ ioport_constructor vic1110_device::device_input_ports() const vic1110_device::vic1110_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : device_t(mconfig, VIC1110, "VIC1110", tag, owner, clock, "vic1110", __FILE__), device_vic20_expansion_card_interface(mconfig, *this), + m_ram(*this, "ram"), m_sw(*this, "SW") { } @@ -83,7 +84,7 @@ vic1110_device::vic1110_device(const machine_config &mconfig, const char *tag, d void vic1110_device::device_start() { // allocate memory - vic20_ram_pointer(machine(), 0x2000); + m_ram.allocate(0x2000); } diff --git a/src/emu/bus/vic20/vic1110.h b/src/emu/bus/vic20/vic1110.h index 9758115283a..33241beedb5 100644 --- a/src/emu/bus/vic20/vic1110.h +++ b/src/emu/bus/vic20/vic1110.h @@ -44,6 +44,7 @@ protected: virtual void vic20_cd_w(address_space &space, offs_t offset, UINT8 data, int ram1, int ram2, int ram3, int blk1, int blk2, int blk3, int blk5, int io2, int io3); private: + optional_shared_ptr<UINT8> m_ram; required_ioport m_sw; }; diff --git a/src/emu/bus/vic20/vic1111.c b/src/emu/bus/vic20/vic1111.c index 29e4ff6f16c..35cfa72f2c4 100644 --- a/src/emu/bus/vic20/vic1111.c +++ b/src/emu/bus/vic20/vic1111.c @@ -31,7 +31,8 @@ const device_type VIC1111 = &device_creator<vic1111_device>; vic1111_device::vic1111_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : device_t(mconfig, VIC1111, "VIC1111", tag, owner, clock, "vic1111", __FILE__), - device_vic20_expansion_card_interface(mconfig, *this) + device_vic20_expansion_card_interface(mconfig, *this), + m_ram(*this, "ram") { } @@ -43,7 +44,7 @@ vic1111_device::vic1111_device(const machine_config &mconfig, const char *tag, d void vic1111_device::device_start() { // allocate memory - m_ram = auto_alloc_array(machine(), UINT8, 0x4000); + m_ram.allocate(0x4000); } diff --git a/src/emu/bus/vic20/vic1111.h b/src/emu/bus/vic20/vic1111.h index 4ed922e254d..3743b335188 100644 --- a/src/emu/bus/vic20/vic1111.h +++ b/src/emu/bus/vic20/vic1111.h @@ -39,6 +39,9 @@ protected: // device_vic20_expansion_card_interface overrides virtual UINT8 vic20_cd_r(address_space &space, offs_t offset, UINT8 data, int ram1, int ram2, int ram3, int blk1, int blk2, int blk3, int blk5, int io2, int io3); virtual void vic20_cd_w(address_space &space, offs_t offset, UINT8 data, int ram1, int ram2, int ram3, int blk1, int blk2, int blk3, int blk5, int io2, int io3); + +private: + optional_shared_ptr<UINT8> m_ram; }; diff --git a/src/emu/bus/vic20/vic1210.c b/src/emu/bus/vic20/vic1210.c index c843bb75e90..d4236182142 100644 --- a/src/emu/bus/vic20/vic1210.c +++ b/src/emu/bus/vic20/vic1210.c @@ -32,7 +32,8 @@ const device_type VIC1210 = &device_creator<vic1210_device>; vic1210_device::vic1210_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : device_t(mconfig, VIC1210, "VIC1210", tag, owner, clock, "vic1210", __FILE__), - device_vic20_expansion_card_interface(mconfig, *this) + device_vic20_expansion_card_interface(mconfig, *this), + m_ram(*this, "ram") { } @@ -44,7 +45,7 @@ vic1210_device::vic1210_device(const machine_config &mconfig, const char *tag, d void vic1210_device::device_start() { // allocate memory - m_ram = auto_alloc_array(machine(), UINT8, 0xc00); + m_ram.allocate(0xc00); } diff --git a/src/emu/bus/vic20/vic1210.h b/src/emu/bus/vic20/vic1210.h index 6a38852b3d6..8e30bf23090 100644 --- a/src/emu/bus/vic20/vic1210.h +++ b/src/emu/bus/vic20/vic1210.h @@ -40,6 +40,9 @@ protected: // device_vic20_expansion_card_interface overrides virtual UINT8 vic20_cd_r(address_space &space, offs_t offset, UINT8 data, int ram1, int ram2, int ram3, int blk1, int blk2, int blk3, int blk5, int io2, int io3); virtual void vic20_cd_w(address_space &space, offs_t offset, UINT8 data, int ram1, int ram2, int ram3, int blk1, int blk2, int blk3, int blk5, int io2, int io3); + +private: + optional_shared_ptr<UINT8> m_ram; }; |