From 52b97dd3307e50e3f9c60e62ca277cf2d96c66b9 Mon Sep 17 00:00:00 2001 From: wilbertpol Date: Sun, 4 Dec 2022 14:12:47 +0000 Subject: msx/slot/cartridge.cpp: Stop copying software memory region contents. (#10629) * bus/msx/cart: Replaced fatal errors with image_init_result and a descriptive message. --- src/devices/bus/msx/beecard/beecard.cpp | 9 +- src/devices/bus/msx/cart/arc.cpp | 19 ++- src/devices/bus/msx/cart/arc.h | 4 +- src/devices/bus/msx/cart/ascii.cpp | 105 +++++++++++----- src/devices/bus/msx/cart/ascii.h | 10 +- src/devices/bus/msx/cart/beepack.cpp | 7 +- src/devices/bus/msx/cart/beepack.h | 4 +- src/devices/bus/msx/cart/bm_012.h | 4 +- src/devices/bus/msx/cart/cartridge.cpp | 67 ----------- src/devices/bus/msx/cart/cartridge.h | 55 --------- src/devices/bus/msx/cart/crossblaim.cpp | 19 ++- src/devices/bus/msx/cart/crossblaim.h | 4 +- src/devices/bus/msx/cart/disk.cpp | 129 +++++++++++++------- src/devices/bus/msx/cart/dooly.cpp | 23 ++-- src/devices/bus/msx/cart/dooly.h | 4 +- src/devices/bus/msx/cart/easi_speech.cpp | 17 ++- src/devices/bus/msx/cart/easi_speech.h | 4 +- src/devices/bus/msx/cart/fmpac.cpp | 31 +++-- src/devices/bus/msx/cart/fmpac.h | 4 +- src/devices/bus/msx/cart/fs_sr022.cpp | 22 +++- src/devices/bus/msx/cart/fs_sr022.h | 4 +- src/devices/bus/msx/cart/halnote.cpp | 35 ++++-- src/devices/bus/msx/cart/halnote.h | 4 +- src/devices/bus/msx/cart/hfox.cpp | 21 +++- src/devices/bus/msx/cart/hfox.h | 4 +- src/devices/bus/msx/cart/holy_quran.cpp | 28 +++-- src/devices/bus/msx/cart/holy_quran.h | 4 +- src/devices/bus/msx/cart/ink.cpp | 14 ++- src/devices/bus/msx/cart/ink.h | 4 +- src/devices/bus/msx/cart/kanji.cpp | 58 +++++++-- src/devices/bus/msx/cart/kanji.h | 9 +- src/devices/bus/msx/cart/konami.cpp | 173 ++++++++++++++++++++------- src/devices/bus/msx/cart/konami.h | 20 ++-- src/devices/bus/msx/cart/korean.cpp | 63 +++++++--- src/devices/bus/msx/cart/korean.h | 8 +- src/devices/bus/msx/cart/majutsushi.cpp | 21 +++- src/devices/bus/msx/cart/majutsushi.h | 4 +- src/devices/bus/msx/cart/moonsound.h | 2 +- src/devices/bus/msx/cart/msx_audio.cpp | 62 +++++++--- src/devices/bus/msx/cart/msx_audio.h | 8 +- src/devices/bus/msx/cart/msxdos2.cpp | 17 ++- src/devices/bus/msx/cart/msxdos2.h | 4 +- src/devices/bus/msx/cart/nomapper.cpp | 16 ++- src/devices/bus/msx/cart/nomapper.h | 4 +- src/devices/bus/msx/cart/rtype.cpp | 19 ++- src/devices/bus/msx/cart/rtype.h | 4 +- src/devices/bus/msx/cart/softcard.cpp | 7 +- src/devices/bus/msx/cart/softcard.h | 4 +- src/devices/bus/msx/cart/super_swangi.cpp | 19 ++- src/devices/bus/msx/cart/super_swangi.h | 4 +- src/devices/bus/msx/cart/superloderunner.cpp | 17 ++- src/devices/bus/msx/cart/superloderunner.h | 4 +- src/devices/bus/msx/cart/yamaha.h | 2 +- src/devices/bus/msx/slot/cartridge.cpp | 104 ++++++++-------- src/devices/bus/msx/slot/cartridge.h | 36 ++++++ src/devices/bus/msx/softcard/softcard.cpp | 8 +- src/mame/msx/msx.cpp | 3 - 57 files changed, 860 insertions(+), 499 deletions(-) diff --git a/src/devices/bus/msx/beecard/beecard.cpp b/src/devices/bus/msx/beecard/beecard.cpp index 5885a892445..bdba157d5da 100644 --- a/src/devices/bus/msx/beecard/beecard.cpp +++ b/src/devices/bus/msx/beecard/beecard.cpp @@ -27,7 +27,7 @@ protected: // device-level overrides virtual void device_start() override { } - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; }; @@ -38,16 +38,19 @@ bee_card_nomapper_device::bee_card_nomapper_device(const machine_config &mconfig { } -void bee_card_nomapper_device::initialize_cartridge() +image_init_result bee_card_nomapper_device::initialize_cartridge(std::string &message) { if (!cart_rom_region()) { - fatalerror("bee_card_nomapper: ROM region not setup\n"); + message = "bee_card_nomapper_device: Required region 'rom' was not found."; + return image_init_result::FAIL; } page(1)->install_rom(0x4000, 0x7fff, cart_rom_region()->base()); if (cart_rom_region()->bytes() == 0x8000) page(2)->install_rom(0x8000, 0xbfff, cart_rom_region()->base() + 0x4000); + + return image_init_result::PASS; } } // anonymous namespace diff --git a/src/devices/bus/msx/cart/arc.cpp b/src/devices/bus/msx/cart/arc.cpp index 45d31457690..04f77d11677 100644 --- a/src/devices/bus/msx/cart/arc.cpp +++ b/src/devices/bus/msx/cart/arc.cpp @@ -28,15 +28,24 @@ void msx_cart_arc_device::device_reset() m_7f = 0; } -void msx_cart_arc_device::initialize_cartridge() +image_init_result msx_cart_arc_device::initialize_cartridge(std::string &message) { - if (get_rom_size() != 0x8000) + if (!cart_rom_region()) { - fatalerror("arc: Invalid ROM size\n"); + message = "msx_cart_arc_device: Required region 'rom' was not found."; + return image_init_result::FAIL; } - page(1)->install_rom(0x4000, 0x7fff, get_rom_base()); - page(2)->install_rom(0x8000, 0xbfff, get_rom_base() + 0x4000); + if (cart_rom_region()->bytes() != 0x8000) + { + message = "msx_cart_arc_device: Region 'rom' has unsupported size."; + return image_init_result::FAIL; + } + + page(1)->install_rom(0x4000, 0x7fff, cart_rom_region()->base()); + page(2)->install_rom(0x8000, 0xbfff, cart_rom_region()->base() + 0x4000); + + return image_init_result::PASS; } void msx_cart_arc_device::io_7f_w(u8 data) diff --git a/src/devices/bus/msx/cart/arc.h b/src/devices/bus/msx/cart/arc.h index 02d67c239e6..1ca0829b708 100644 --- a/src/devices/bus/msx/cart/arc.h +++ b/src/devices/bus/msx/cart/arc.h @@ -5,7 +5,7 @@ #pragma once -#include "cartridge.h" +#include "bus/msx/slot/cartridge.h" DECLARE_DEVICE_TYPE(MSX_CART_ARC, msx_cart_arc_device) @@ -16,7 +16,7 @@ class msx_cart_arc_device : public device_t, public msx_cart_interface public: msx_cart_arc_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: // device-level overrides diff --git a/src/devices/bus/msx/cart/ascii.cpp b/src/devices/bus/msx/cart/ascii.cpp index f183afca6f1..7faa12f3c55 100644 --- a/src/devices/bus/msx/cart/ascii.cpp +++ b/src/devices/bus/msx/cart/ascii.cpp @@ -24,20 +24,27 @@ void msx_cart_ascii8_device::device_reset() m_rombank[i]->set_entry(0); } -void msx_cart_ascii8_device::initialize_cartridge() +image_init_result msx_cart_ascii8_device::initialize_cartridge(std::string &message) { - u32 size = get_rom_size(); - u16 banks = size / BANK_SIZE; + if (!cart_rom_region()) + { + message = "msx_cart_ascii8_device: Required region 'rom' was not found."; + return image_init_result::FAIL; + } + + const u32 size = cart_rom_region()->bytes(); + const u16 banks = size / BANK_SIZE; if (size > 256 * BANK_SIZE || size != banks * BANK_SIZE || (~(banks - 1) % banks)) { - fatalerror("ascii8: Invalid ROM size\n"); + message = "msx_cart_ascii8_device: Region 'rom' has unsupported size."; + return image_init_result::FAIL; } m_bank_mask = banks - 1; for (int i = 0; i < 4; i++) - m_rombank[i]->configure_entries(0, banks, get_rom_base(), BANK_SIZE); + m_rombank[i]->configure_entries(0, banks, cart_rom_region()->base(), BANK_SIZE); page(1)->install_read_bank(0x4000, 0x5fff, m_rombank[0]); page(1)->install_read_bank(0x6000, 0x7fff, m_rombank[1]); @@ -47,6 +54,8 @@ void msx_cart_ascii8_device::initialize_cartridge() page(1)->install_write_handler(0x7800, 0x7fff, write8smo_delegate(*this, FUNC(msx_cart_ascii8_device::bank_w<3>))); page(2)->install_read_bank(0x8000, 0x9fff, m_rombank[2]); page(2)->install_read_bank(0xa000, 0xbfff, m_rombank[3]); + + return image_init_result::PASS; } template @@ -71,25 +80,34 @@ void msx_cart_ascii16_device::device_reset() m_rombank[1]->set_entry(0); } -void msx_cart_ascii16_device::initialize_cartridge() +image_init_result msx_cart_ascii16_device::initialize_cartridge(std::string &message) { - u32 size = get_rom_size(); - u16 banks = size / BANK_SIZE; + if (!cart_rom_region()) + { + message = "msx_cart_ascii16_device: Required region 'rom' was not found."; + return image_init_result::FAIL; + } + + const u32 size = cart_rom_region()->bytes(); + const u16 banks = size / BANK_SIZE; if (size > 256 * BANK_SIZE || size != banks * BANK_SIZE || (~(banks - 1) % banks)) { - fatalerror("ascii16: Invalid ROM size\n"); + message = "msx_cart_ascii16_device: Region 'rom' has unsupported size."; + return image_init_result::FAIL; } m_bank_mask = banks - 1; for (int i = 0; i < 2; i++) - m_rombank[i]->configure_entries(0, banks, get_rom_base(), BANK_SIZE); + m_rombank[i]->configure_entries(0, banks, cart_rom_region()->base(), BANK_SIZE); page(1)->install_read_bank(0x4000, 0x7fff, m_rombank[0]); page(1)->install_write_handler(0x6000, 0x67ff, write8smo_delegate(*this, FUNC(msx_cart_ascii16_device::bank_w<0>))); page(1)->install_write_handler(0x7000, 0x77ff, write8smo_delegate(*this, FUNC(msx_cart_ascii16_device::bank_w<1>))); page(2)->install_read_bank(0x8000, 0xbfff, m_rombank[1]); + + return image_init_result::PASS; } template @@ -121,36 +139,52 @@ void msx_cart_ascii8_sram_device::device_reset() m_view3.select(0); } -void msx_cart_ascii8_sram_device::initialize_cartridge() +image_init_result msx_cart_ascii8_sram_device::initialize_cartridge(std::string &message) { - u32 size = get_rom_size(); - u16 banks = size / BANK_SIZE; + if (!cart_rom_region()) + { + message = "msx_cart_ascii8_sram_device: Required region 'rom' was not found."; + return image_init_result::FAIL; + } + + if (!cart_sram_region()) + { + message = "msx_cart_ascii8_sram_device: Required region 'sram' was not found."; + return image_init_result::FAIL; + } + + const u32 size = cart_rom_region()->bytes(); + const u16 banks = size / BANK_SIZE; if (size > 128 * BANK_SIZE || size != banks * BANK_SIZE || (~(banks - 1) % banks)) { - fatalerror("ascii8_sram: Invalid ROM size\n"); + message = "msx_cart_ascii8_sram_device: Region 'rom' has unsupported size."; + return image_init_result::FAIL; } - if (get_sram_size() != 0x2000) + if (cart_sram_region()->bytes() < 0x2000) { - fatalerror("ascii8_sram: Unsupported SRAM size\n"); + message = "msx_cart_ascii8_sram_device: Region 'sram' has unsupported size."; + return image_init_result::FAIL; } m_bank_mask = banks - 1; m_sram_select_mask = banks; for (int i = 0; i < 4; i++) - m_rombank[i]->configure_entries(0, banks, get_rom_base(), BANK_SIZE); + m_rombank[i]->configure_entries(0, banks, cart_rom_region()->base(), BANK_SIZE); page(1)->install_read_bank(0x4000, 0x5fff, m_rombank[0]); page(1)->install_read_bank(0x6000, 0x7fff, m_rombank[1]); page(1)->install_write_handler(0x6000, 0x7fff, write8sm_delegate(*this, FUNC(msx_cart_ascii8_sram_device::mapper_write))); page(2)->install_view(0x8000, 0x9fff, m_view2); m_view2[0].install_read_bank(0x8000, 0x9fff, m_rombank[2]); - m_view2[1].install_ram(0x8000, 0x9fff, get_sram_base()); + m_view2[1].install_ram(0x8000, 0x9fff, cart_sram_region()->base()); page(2)->install_view(0xa000, 0xbfff, m_view3); m_view3[0].install_read_bank(0xa000, 0xbfff, m_rombank[3]); - m_view3[1].install_ram(0xa000, 0xbfff, get_sram_base()); + m_view3[1].install_ram(0xa000, 0xbfff, cart_sram_region()->base()); + + return image_init_result::PASS; } void msx_cart_ascii8_sram_device::mapper_write(offs_t offset, u8 data) @@ -198,32 +232,49 @@ void msx_cart_ascii16_sram_device::device_reset() m_rombank[1]->set_entry(0); } -void msx_cart_ascii16_sram_device::initialize_cartridge() +image_init_result msx_cart_ascii16_sram_device::initialize_cartridge(std::string &message) { - u32 size = get_rom_size(); - u16 banks = size / BANK_SIZE; + if (!cart_rom_region()) + { + message = "msx_cart_ascii16_sram_device: Required region 'rom' was not found."; + return image_init_result::FAIL; + } + + if (!cart_sram_region()) + { + message = "msx_cart_ascii16_sram_device: Required region 'sram' was not found."; + return image_init_result::FAIL; + } + + const u32 size = cart_rom_region()->bytes(); + const u16 banks = size / BANK_SIZE; if (size > 128 * BANK_SIZE || size != banks * BANK_SIZE || (~(banks - 1) % banks)) { - fatalerror("ascii16_sram: Invalid ROM size\n"); + message = "msx_cart_ascii16_sram_device: Region 'rom' has unsupported size."; + return image_init_result::FAIL; } - if (get_sram_size() != 0x800) + + if (cart_sram_region()->bytes() < 0x800) { - fatalerror("ascii16_sram: Unsupported SRAM size\n"); + message = "msx_cart_ascii16_sram_device: Region 'sram' has unsupported size."; + return image_init_result::FAIL; } m_bank_mask = banks - 1; m_sram_select_mask = banks; for (int i = 0; i < 2; i++) - m_rombank[i]->configure_entries(0, banks, get_rom_base(), BANK_SIZE); + m_rombank[i]->configure_entries(0, banks, cart_rom_region()->base(), BANK_SIZE); page(1)->install_read_bank(0x4000, 0x7fff, m_rombank[0]); page(1)->install_write_handler(0x6000, 0x67ff, write8smo_delegate(*this, FUNC(msx_cart_ascii16_sram_device::mapper_write_6000))); page(1)->install_write_handler(0x7000, 0x77ff, write8smo_delegate(*this, FUNC(msx_cart_ascii16_sram_device::mapper_write_7000))); page(2)->install_view(0x8000, 0xbfff, m_view); m_view[0].install_read_bank(0x8000, 0xbfff, m_rombank[1]); - m_view[1].install_ram(0x8000, 0x87ff, 0x3800, get_sram_base()); + m_view[1].install_ram(0x8000, 0x87ff, 0x3800, cart_sram_region()->base()); + + return image_init_result::PASS; } void msx_cart_ascii16_sram_device::mapper_write_6000(u8 data) diff --git a/src/devices/bus/msx/cart/ascii.h b/src/devices/bus/msx/cart/ascii.h index 61a5fe5061a..b6dd2e6a54e 100644 --- a/src/devices/bus/msx/cart/ascii.h +++ b/src/devices/bus/msx/cart/ascii.h @@ -5,7 +5,7 @@ #pragma once -#include "cartridge.h" +#include "bus/msx/slot/cartridge.h" DECLARE_DEVICE_TYPE(MSX_CART_ASCII8, msx_cart_ascii8_device) @@ -19,7 +19,7 @@ class msx_cart_ascii8_device : public device_t, public msx_cart_interface public: msx_cart_ascii8_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: // device-level overrides @@ -41,7 +41,7 @@ class msx_cart_ascii16_device : public device_t, public msx_cart_interface public: msx_cart_ascii16_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: // device-level overrides @@ -63,7 +63,7 @@ class msx_cart_ascii8_sram_device : public device_t, public msx_cart_interface public: msx_cart_ascii8_sram_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: // device-level overrides @@ -88,7 +88,7 @@ class msx_cart_ascii16_sram_device : public device_t, public msx_cart_interface public: msx_cart_ascii16_sram_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: // device-level overrides diff --git a/src/devices/bus/msx/cart/beepack.cpp b/src/devices/bus/msx/cart/beepack.cpp index 6567dc96a03..e370c66ca81 100644 --- a/src/devices/bus/msx/cart/beepack.cpp +++ b/src/devices/bus/msx/cart/beepack.cpp @@ -72,7 +72,12 @@ image_init_result msx_cart_beepack_device::call_load() } } - m_beecard->initialize_cartridge(); + std::string message; + image_init_result result = m_beecard->initialize_cartridge(message); + if (image_init_result::PASS != result) + seterror(image_error::INVALIDIMAGE, message.c_str()); + + return result; } return image_init_result::PASS; } diff --git a/src/devices/bus/msx/cart/beepack.h b/src/devices/bus/msx/cart/beepack.h index 9926f831124..1dd4368b7bb 100644 --- a/src/devices/bus/msx/cart/beepack.h +++ b/src/devices/bus/msx/cart/beepack.h @@ -5,7 +5,7 @@ #pragma once -#include "cartridge.h" +#include "bus/msx/slot/cartridge.h" #include "imagedev/cartrom.h" @@ -41,7 +41,7 @@ protected: class bee_card_interface : public device_interface { public: - virtual void initialize_cartridge() { } + virtual image_init_result initialize_cartridge(std::string &message) { return image_init_result::PASS; } void set_views(memory_view::memory_view_entry *page0, memory_view::memory_view_entry *page1, memory_view::memory_view_entry *page2, memory_view::memory_view_entry *page3); protected: diff --git a/src/devices/bus/msx/cart/bm_012.h b/src/devices/bus/msx/cart/bm_012.h index dbafa49f2d0..9adc5a78ceb 100644 --- a/src/devices/bus/msx/cart/bm_012.h +++ b/src/devices/bus/msx/cart/bm_012.h @@ -5,9 +5,9 @@ #pragma once -#include "cartridge.h" -#include "cpu/z80/tmpz84c015.h" #include "bus/midi/midi.h" +#include "bus/msx/slot/cartridge.h" +#include "cpu/z80/tmpz84c015.h" DECLARE_DEVICE_TYPE(MSX_CART_BM_012, msx_cart_bm_012_device) diff --git a/src/devices/bus/msx/cart/cartridge.cpp b/src/devices/bus/msx/cart/cartridge.cpp index 115a1a918c2..9715e54e3f2 100644 --- a/src/devices/bus/msx/cart/cartridge.cpp +++ b/src/devices/bus/msx/cart/cartridge.cpp @@ -80,73 +80,6 @@ void msx_cart(device_slot_interface &device) } -msx_cart_interface::msx_cart_interface(const machine_config &mconfig, device_t &device) - : device_interface(device, "msxcart") - , m_exp(nullptr) -{ - for (int i = 0; i < 4; i++) - m_page[i] = nullptr; -} - -void msx_cart_interface::rom_alloc(u32 size) -{ - m_rom.resize(size); - std::fill_n(m_rom.begin(), size, 0xff); -} - -void msx_cart_interface::rom_vlm5030_alloc(u32 size) -{ - m_rom_vlm5030.resize(size); - std::fill_n(m_rom_vlm5030.begin(), size, 0xff); -} - -void msx_cart_interface::ram_alloc(u32 size) -{ - m_ram.resize(size); - std::fill_n(m_ram.begin(), size, 0x00); -} - -void msx_cart_interface::sram_alloc(u32 size) -{ - m_sram.resize(size); - std::fill_n(m_sram.begin(), size, 0x00); -} - -void msx_cart_interface::kanji_alloc(u32 size) -{ - m_kanji.resize(size); - std::fill_n(m_kanji.begin(), size, 0x00); -} - -WRITE_LINE_MEMBER(msx_cart_interface::irq_out) -{ - m_exp->irq_out(state); -} - -address_space &msx_cart_interface::memory_space() const -{ - return m_exp->memory_space(); -} - -address_space &msx_cart_interface::io_space() const -{ - return m_exp->io_space(); -} - -cpu_device &msx_cart_interface::maincpu() const -{ - return m_exp->maincpu(); -} - -void msx_cart_interface::set_views(memory_view::memory_view_entry *page0, memory_view::memory_view_entry *page1, memory_view::memory_view_entry *page2, memory_view::memory_view_entry *page3) -{ - m_page[0] = page0; - m_page[1] = page1; - m_page[2] = page2; - m_page[3] = page3; -} - - // Several yamaha machines had 60 pin expansion slots. The pinouts of these slots was // exactly the same as the regular 50 pin cartridge slots. The lowest 10 pins are simply // not connected. diff --git a/src/devices/bus/msx/cart/cartridge.h b/src/devices/bus/msx/cart/cartridge.h index ac0fb3edb22..dc87b82ced1 100644 --- a/src/devices/bus/msx/cart/cartridge.h +++ b/src/devices/bus/msx/cart/cartridge.h @@ -10,59 +10,4 @@ void msx_cart(device_slot_interface &device); void msx_yamaha_60pin(device_slot_interface &device); // 60 pin expansion slots as found in yamaha machines -class msx_slot_cartridge_device; - -class msx_cart_interface : public device_interface -{ - friend class msx_slot_cartridge_device; - -public: - // This is called after loading cartridge contents and allows the cartridge - // implementation to perform some additional initialization based on the - // cartridge contents. - virtual void initialize_cartridge() { } - virtual void interface_pre_start() override { assert(m_exp != nullptr); } - - void set_views(memory_view::memory_view_entry *page0, memory_view::memory_view_entry *page1, memory_view::memory_view_entry *page2, memory_view::memory_view_entry *page3); - - DECLARE_WRITE_LINE_MEMBER(irq_out); - address_space &memory_space() const; - address_space &io_space() const; - cpu_device &maincpu() const; - - // ROM/RAM/SRAM management - // Mainly used by the cartridge slot when loading images - void rom_alloc(u32 size); - void ram_alloc(u32 size); - void rom_vlm5030_alloc(u32 size); - void sram_alloc(u32 size); - void kanji_alloc(u32 size); - - u8* get_rom_base() { return &m_rom[0]; } - u8* get_rom_vlm5030_base() { return &m_rom_vlm5030[0]; } - u8* get_ram_base() { return &m_ram[0]; } - u8* get_sram_base() { return &m_sram[0]; } - u8* get_kanji_base() { return &m_kanji[0]; } - u32 get_rom_size() { return m_rom.size(); } - u32 get_rom_vlm5030_size() { return m_rom_vlm5030.size(); } - u32 get_ram_size() { return m_ram.size(); } - u32 get_sram_size() { return m_sram.size(); } - u32 get_kanji_size() { return m_kanji.size(); } - memory_view::memory_view_entry *page(int i) { return m_page[i]; } - -protected: - msx_cart_interface(const machine_config &mconfig, device_t &device); - - std::vector m_rom; - std::vector m_ram; - std::vector m_rom_vlm5030; - std::vector m_sram; - std::vector m_kanji; - memory_view::memory_view_entry *m_page[4]; - -private: - msx_slot_cartridge_device *m_exp; -}; - - #endif // MAME_BUS_MSX_CART_CARTRIDGE_H diff --git a/src/devices/bus/msx/cart/crossblaim.cpp b/src/devices/bus/msx/cart/crossblaim.cpp index 1d30ec07f4f..2c3dedfd91c 100644 --- a/src/devices/bus/msx/cart/crossblaim.cpp +++ b/src/devices/bus/msx/cart/crossblaim.cpp @@ -13,18 +13,27 @@ msx_cart_crossblaim_device::msx_cart_crossblaim_device(const machine_config &mco { } -void msx_cart_crossblaim_device::initialize_cartridge() +image_init_result msx_cart_crossblaim_device::initialize_cartridge(std::string &message) { - if (get_rom_size() != 0x10000) + if (!cart_rom_region()) { - fatalerror("crossblaim: Invalid ROM size\n"); + message = "msx_cart_crossblaim_device: Required region 'rom' was not found."; + return image_init_result::FAIL; } - m_rombank->configure_entries(0, 4, get_rom_base(), 0x4000); + if (cart_rom_region()->bytes() != 0x10000) + { + message = "msx_cart_crossblaim_device: Region 'rom' has unsupported size."; + return image_init_result::FAIL; + } - page(1)->install_rom(0x4000, 0x7fff, get_rom_base()); + m_rombank->configure_entries(0, 4, cart_rom_region()->base(), 0x4000); + + page(1)->install_rom(0x4000, 0x7fff, cart_rom_region()->base()); page(1)->install_write_handler(0x4045, 0x4045, write8smo_delegate(*this, FUNC(msx_cart_crossblaim_device::mapper_write))); page(2)->install_read_bank(0x8000, 0xbfff, m_rombank); + + return image_init_result::PASS; } void msx_cart_crossblaim_device::mapper_write(u8 data) diff --git a/src/devices/bus/msx/cart/crossblaim.h b/src/devices/bus/msx/cart/crossblaim.h index 98858990a83..5f484f6a304 100644 --- a/src/devices/bus/msx/cart/crossblaim.h +++ b/src/devices/bus/msx/cart/crossblaim.h @@ -5,7 +5,7 @@ #pragma once -#include "cartridge.h" +#include "bus/msx/slot/cartridge.h" DECLARE_DEVICE_TYPE(MSX_CART_CROSSBLAIM, msx_cart_crossblaim_device) @@ -16,7 +16,7 @@ class msx_cart_crossblaim_device : public device_t, public msx_cart_interface public: msx_cart_crossblaim_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: // device-level overrides diff --git a/src/devices/bus/msx/cart/disk.cpp b/src/devices/bus/msx/cart/disk.cpp index 42488cb122b..029b1fcfea5 100644 --- a/src/devices/bus/msx/cart/disk.cpp +++ b/src/devices/bus/msx/cart/disk.cpp @@ -104,8 +104,7 @@ #include "emu.h" #include "disk.h" -#include "cartridge.h" - +#include "bus/msx/slot/cartridge.h" #include "imagedev/floppy.h" #include "machine/wd_fdc.h" #include "machine/upd765.h" @@ -174,7 +173,7 @@ void msx_floppies(device_slot_interface &device) class msx_cart_disk_device : public device_t, public msx_cart_interface { public: - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: msx_cart_disk_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock, int fdc_regs_start_page, int fdc_regs_end_page) @@ -216,12 +215,21 @@ void msx_cart_disk_device::floppy_formats(format_registration &fr) fr.add(FLOPPY_DMK_FORMAT); } -void msx_cart_disk_device::initialize_cartridge() +image_init_result msx_cart_disk_device::initialize_cartridge(std::string &message) { - if (get_rom_size() != 0x4000) + if (!cart_rom_region()) { - fatalerror("msx_cart_disk_device: Invalid ROM size\n"); + message = "msx_cart_disk_device: Required region 'rom' was not found."; + return image_init_result::FAIL; } + + if (cart_rom_region()->bytes() != 0x4000) + { + message = "msx_cart_disk_device: Region 'rom' has unsupported size."; + return image_init_result::FAIL; + } + + return image_init_result::PASS; } void msx_cart_disk_device::softlist_35(machine_config &config) @@ -300,7 +308,7 @@ protected: class disk_type1_device : public disk_wd_device { public: - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: disk_type1_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock, int fdc_regs_start_page = PAGE1, int fdc_regs_end_page = PAGE2) @@ -333,11 +341,13 @@ void disk_type1_device::device_start() save_item(NAME(m_control)); } -void disk_type1_device::initialize_cartridge() +image_init_result disk_type1_device::initialize_cartridge(std::string &message) { - disk_wd_device::initialize_cartridge(); + image_init_result result = disk_wd_device::initialize_cartridge(message); + if (image_init_result::PASS != result) + return result; - page(1)->install_rom(0x4000, 0x7fff, get_rom_base()); + page(1)->install_rom(0x4000, 0x7fff, cart_rom_region()->base()); for (int i = m_fdc_regs_start_page; i <= m_fdc_regs_end_page; i++) { const offs_t base = 0x4000 * i; @@ -355,6 +365,8 @@ void disk_type1_device::initialize_cartridge() page(i)->install_write_handler(base + 0x3ffc, base + 0x3ffc, write8smo_delegate(*this, FUNC(disk_type1_device::set_side_control))); page(i)->install_write_handler(base + 0x3ffd, base + 0x3ffd, write8smo_delegate(*this, FUNC(disk_type1_device::set_control))); } + + return image_init_result::PASS; } void disk_type1_device::device_post_load() @@ -574,7 +586,7 @@ protected: class disk_type2_device : public disk_wd_device { public: - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: disk_type2_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock, int fdc_regs_start_page = PAGE1, int fdc_regs_end_page = PAGE2) @@ -606,11 +618,13 @@ void disk_type2_device::device_post_load() set_control(m_control); } -void disk_type2_device::initialize_cartridge() +image_init_result disk_type2_device::initialize_cartridge(std::string &message) { - disk_wd_device::initialize_cartridge(); + image_init_result result = disk_wd_device::initialize_cartridge(message); + if (image_init_result::PASS != result) + return result; - page(1)->install_rom(0x4000, 0x7fff, get_rom_base()); + page(1)->install_rom(0x4000, 0x7fff, cart_rom_region()->base()); for (int i = m_fdc_regs_start_page; i <= m_fdc_regs_end_page; i++) { const offs_t base = 0x4000 * i; @@ -625,6 +639,8 @@ void disk_type2_device::initialize_cartridge() page(i)->install_write_handler(base + 0x3fbb, base + 0x3fbb, write8smo_delegate(*m_fdc, FUNC(wd_fdc_analog_device_base::data_w))); page(i)->install_write_handler(base + 0x3fbc, base + 0x3fbc, write8smo_delegate(*this, FUNC(disk_type2_device::set_control))); } + + return image_init_result::PASS; } void disk_type2_device::set_control(u8 data) @@ -705,7 +721,7 @@ protected: class disk_type5_device : public disk_wd_device { public: - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: disk_type5_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock) @@ -728,11 +744,13 @@ void disk_type5_device::device_start() save_item(NAME(m_control)); } -void disk_type5_device::initialize_cartridge() +image_init_result disk_type5_device::initialize_cartridge(std::string &message) { - disk_wd_device::initialize_cartridge(); + image_init_result result = disk_wd_device::initialize_cartridge(message); + if (image_init_result::PASS != result) + return result; - page(1)->install_rom(0x4000, 0x7fff, get_rom_base()); + page(1)->install_rom(0x4000, 0x7fff, cart_rom_region()->base()); // Install IO read/write handlers io_space().install_write_handler(0xd0, 0xd0, write8smo_delegate(*m_fdc, FUNC(wd_fdc_analog_device_base::cmd_w))); @@ -745,6 +763,8 @@ void disk_type5_device::initialize_cartridge() io_space().install_read_handler(0xd2, 0xd2, read8smo_delegate(*m_fdc, FUNC(wd_fdc_analog_device_base::sector_r))); io_space().install_read_handler(0xd3, 0xd3, read8smo_delegate(*m_fdc, FUNC(wd_fdc_analog_device_base::data_r))); io_space().install_read_handler(0xd4, 0xd4, read8smo_delegate(*this, FUNC(disk_type5_device::status_r))); + + return image_init_result::PASS; } void disk_type5_device::device_post_load() @@ -824,7 +844,7 @@ public: : disk_tc8566_device(mconfig, MSX_CART_FSFD1A, tag, owner, clock) { } - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: // device-level overrides @@ -836,11 +856,13 @@ protected: } }; -void fsfd1a_device::initialize_cartridge() +image_init_result fsfd1a_device::initialize_cartridge(std::string &message) { - disk_tc8566_device::initialize_cartridge(); + image_init_result result = disk_tc8566_device::initialize_cartridge(message); + if (image_init_result::PASS != result) + return result; - page(1)->install_rom(0x4000, 0x7fff, get_rom_base()); + page(1)->install_rom(0x4000, 0x7fff, cart_rom_region()->base()); for (int i = m_fdc_regs_start_page; i <= m_fdc_regs_end_page; i++) { const offs_t base = 0x4000 * i; @@ -850,6 +872,8 @@ void fsfd1a_device::initialize_cartridge() page(i)->install_write_handler(base + 0x3ff9, base + 0x3ff9, write8smo_delegate(*m_fdc, FUNC(tc8566af_device::cr1_w))); page(i)->install_write_handler(base + 0x3ffb, base + 0x3ffb, write8smo_delegate(*m_fdc, FUNC(tc8566af_device::fifo_w))); } + + return image_init_result::PASS; } @@ -863,7 +887,7 @@ public: , m_control(0) { } - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: // device-level overrides @@ -892,16 +916,24 @@ void fd03_device::device_start() save_item(NAME(m_control)); } -void fd03_device::initialize_cartridge() +image_init_result fd03_device::initialize_cartridge(std::string &message) { - if (get_rom_size() != 0x4000 && get_rom_size() != 0x8000) + if (!cart_rom_region()) { - fatalerror("fd03_device: Invalid ROM size\n"); + message = "fd03_device:: Required region 'rom' was not found."; + return image_init_result::FAIL; } - page(1)->install_rom(0x4000, 0x7fff, get_rom_base()); - if (get_rom_size() >= 0x8000) - page(2)->install_rom(0x8000,0xbfff, get_rom_base() + 0x4000); + if (cart_rom_region()->bytes() != 0x4000 && cart_rom_region()->bytes() != 0x8000) + { + message = "fd03_device: Region 'rom' has unsupported size."; + return image_init_result::FAIL; + } + + page(1)->install_rom(0x4000, 0x7fff, cart_rom_region()->base()); + if (cart_rom_region()->bytes() >= 0x8000) + page(2)->install_rom(0x8000,0xbfff, cart_rom_region()->base() + 0x4000); + for (int i = m_fdc_regs_start_page; i <= m_fdc_regs_end_page; i++) { const offs_t base = 0x4000 * i; @@ -918,6 +950,8 @@ void fd03_device::initialize_cartridge() page(i)->install_write_handler(base + 0x3fe0, base + 0x3fef, write8smo_delegate(*this, FUNC(fd03_device::set_control))); page(i)->install_write_handler(base + 0x3ff0, base + 0x3fff, write8smo_delegate(*this, FUNC(fd03_device::dskchg_w))); } + + return image_init_result::PASS; } void fd03_device::device_post_load() @@ -1004,7 +1038,7 @@ public: , m_drive_select1(0) { } - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: // device-level overrides @@ -1039,11 +1073,13 @@ void hxf101pe_device::device_start() save_item(NAME(m_drive_select1)); } -void hxf101pe_device::initialize_cartridge() +image_init_result hxf101pe_device::initialize_cartridge(std::string &message) { - disk_wd_device::initialize_cartridge(); + image_init_result result = disk_wd_device::initialize_cartridge(message); + if (image_init_result::PASS != result) + return result; - page(1)->install_rom(0x4000, 0x7fff, get_rom_base()); + page(1)->install_rom(0x4000, 0x7fff, cart_rom_region()->base()); page(1)->install_read_handler(0x7ff0, 0x7ff0, 0, 0x0008, 0, read8smo_delegate(*m_fdc, FUNC(wd_fdc_analog_device_base::status_r))); page(1)->install_read_handler(0x7ff1, 0x7ff1, 0, 0x0008, 0, read8smo_delegate(*m_fdc, FUNC(wd_fdc_analog_device_base::track_r))); page(1)->install_read_handler(0x7ff2, 0x7ff2, 0, 0x0008, 0, read8smo_delegate(*m_fdc, FUNC(wd_fdc_analog_device_base::sector_r))); @@ -1059,6 +1095,8 @@ void hxf101pe_device::initialize_cartridge() page(1)->install_write_handler(0x7ff4, 0x7ff4, 0, 0x0008, 0, write8smo_delegate(*this, FUNC(hxf101pe_device::side_motor_w))); page(1)->install_write_handler(0x7ff5, 0x7ff5, 0, 0x0008, 0, write8smo_delegate(*this, FUNC(hxf101pe_device::select0_w))); page(1)->install_write_handler(0x7ff6, 0x7ff6, 0, 0x0008, 0, write8smo_delegate(*this, FUNC(hxf101pe_device::select1_w))); + + return image_init_result::PASS; } void hxf101pe_device::device_post_load() @@ -1153,7 +1191,7 @@ public: , m_control(0) { } - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: // device-level overrides @@ -1174,11 +1212,14 @@ void mfd001_device::device_add_mconfig(machine_config &config) add_mconfig(config, MB8877); } -void mfd001_device::initialize_cartridge() +image_init_result mfd001_device::initialize_cartridge(std::string &message) { - disk_wd_device::initialize_cartridge(); + image_init_result result = disk_wd_device::initialize_cartridge(message); + if (image_init_result::PASS != result) + return result; + + page(1)->install_rom(0x4000, 0x7fff, cart_rom_region()->base()); - page(1)->install_rom(0x4000, 0x7fff, get_rom_base()); for (int i = m_fdc_regs_start_page; i <= m_fdc_regs_end_page; i++) { const offs_t base = 0x4000 * i; @@ -1193,6 +1234,8 @@ void mfd001_device::initialize_cartridge() page(i)->install_write_handler(base + 0x3ffb, base + 0x3ffb, write8smo_delegate(*m_fdc, FUNC(wd_fdc_analog_device_base::data_w))); page(i)->install_write_handler(base + 0x3ffc, base + 0x3ffc, write8smo_delegate(*this, FUNC(mfd001_device::control_w))); } + + return image_init_result::PASS; } void mfd001_device::device_start() @@ -1251,7 +1294,7 @@ public: , m_control(0) { } - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: // device-level overrides @@ -1276,11 +1319,13 @@ void avdpf550_device::device_start() save_item(NAME(m_control)); } -void avdpf550_device::initialize_cartridge() +image_init_result avdpf550_device::initialize_cartridge(std::string &message) { - disk_wd_device::initialize_cartridge(); + image_init_result result = disk_wd_device::initialize_cartridge(message); + if (image_init_result::PASS != result) + return result; - page(1)->install_rom(0x4000, 0x7fff, get_rom_base()); + page(1)->install_rom(0x4000, 0x7fff, cart_rom_region()->base()); // Install IO read/write handlers io_space().install_write_handler(0xd0, 0xd0, write8smo_delegate(*m_fdc, FUNC(wd_fdc_analog_device_base::cmd_w))); @@ -1293,6 +1338,8 @@ void avdpf550_device::initialize_cartridge() io_space().install_read_handler(0xd2, 0xd2, read8smo_delegate(*m_fdc, FUNC(wd_fdc_analog_device_base::sector_r))); io_space().install_read_handler(0xd3, 0xd3, read8smo_delegate(*m_fdc, FUNC(wd_fdc_analog_device_base::data_r))); io_space().install_read_handler(0xd4, 0xd4, read8smo_delegate(*this, FUNC(avdpf550_device::status_r))); + + return image_init_result::PASS; } void avdpf550_device::device_post_load() diff --git a/src/devices/bus/msx/cart/dooly.cpp b/src/devices/bus/msx/cart/dooly.cpp index 7bbc15253a5..b46df578034 100644 --- a/src/devices/bus/msx/cart/dooly.cpp +++ b/src/devices/bus/msx/cart/dooly.cpp @@ -21,32 +21,41 @@ void msx_cart_dooly_device::device_reset() m_view2.select(0); } -void msx_cart_dooly_device::initialize_cartridge() +image_init_result msx_cart_dooly_device::initialize_cartridge(std::string &message) { - if (get_rom_size() != 0x8000) + if (!cart_rom_region()) { - fatalerror("dooly: Invalid ROM size\n"); + message = "msx_cart_dooly_device: Required region 'rom' was not found."; + return image_init_result::FAIL; + } + + if (cart_rom_region()->bytes() != 0x8000) + { + message = "msx_cart_dooly_device: Region 'rom' has unsupported size."; + return image_init_result::FAIL; } page(1)->install_view(0x4000, 0x7fff, m_view1); - m_view1[0].install_rom(0x4000, 0x7fff, get_rom_base()); + m_view1[0].install_rom(0x4000, 0x7fff, cart_rom_region()->base()); m_view1[1].install_read_handler(0x4000, 0x7fff, read8sm_delegate(*this, FUNC(msx_cart_dooly_device::mode4_page1_r))); page(2)->install_view(0x8000, 0xbfff, m_view2); - m_view2[0].install_rom(0x8000, 0xbfff, get_rom_base() + 0x4000); + m_view2[0].install_rom(0x8000, 0xbfff, cart_rom_region()->base() + 0x4000); m_view2[1].install_read_handler(0x8000, 0xbfff, read8sm_delegate(*this, FUNC(msx_cart_dooly_device::mode4_page2_r))); page(1)->install_write_handler(0x4000, 0x7fff, write8smo_delegate(*this, FUNC(msx_cart_dooly_device::prot_w))); page(2)->install_write_handler(0x8000, 0xbfff, write8smo_delegate(*this, FUNC(msx_cart_dooly_device::prot_w))); + + return image_init_result::PASS; } u8 msx_cart_dooly_device::mode4_page1_r(offs_t offset) { - return bitswap<8>(get_rom_base()[offset], 7, 6, 5, 4, 3, 1, 0, 2); + return bitswap<8>(cart_rom_region()->base()[offset], 7, 6, 5, 4, 3, 1, 0, 2); } u8 msx_cart_dooly_device::mode4_page2_r(offs_t offset) { - return bitswap<8>(get_rom_base()[0x4000 | offset], 7, 6, 5, 4, 3, 1, 0, 2); + return bitswap<8>(cart_rom_region()->base()[0x4000 | offset], 7, 6, 5, 4, 3, 1, 0, 2); } void msx_cart_dooly_device::prot_w(u8 data) diff --git a/src/devices/bus/msx/cart/dooly.h b/src/devices/bus/msx/cart/dooly.h index b2093c5bc24..f509a6dad65 100644 --- a/src/devices/bus/msx/cart/dooly.h +++ b/src/devices/bus/msx/cart/dooly.h @@ -5,7 +5,7 @@ #pragma once -#include "cartridge.h" +#include "bus/msx/slot/cartridge.h" DECLARE_DEVICE_TYPE(MSX_CART_DOOLY, msx_cart_dooly_device) @@ -16,7 +16,7 @@ class msx_cart_dooly_device : public device_t, public msx_cart_interface public: msx_cart_dooly_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: // device-level overrides diff --git a/src/devices/bus/msx/cart/easi_speech.cpp b/src/devices/bus/msx/cart/easi_speech.cpp index cd206164802..c13d1f5950a 100644 --- a/src/devices/bus/msx/cart/easi_speech.cpp +++ b/src/devices/bus/msx/cart/easi_speech.cpp @@ -40,16 +40,25 @@ void msx_cart_easispeech_device::device_add_mconfig(machine_config &config) m_speech->add_route(ALL_OUTPUTS, ":speaker", 1.00); } -void msx_cart_easispeech_device::initialize_cartridge() +image_init_result msx_cart_easispeech_device::initialize_cartridge(std::string &message) { - if (get_rom_size() != 0x2000) + if (!cart_rom_region()) { - fatalerror("easispeech: Invalid ROM size\n"); + message = "msx_cart_easispeech_device: Required region 'rom' was not found."; + return image_init_result::FAIL; } - page(1)->install_rom(0x4000, 0x5fff, 0x2000, get_rom_base()); + if (cart_rom_region()->bytes() != 0x2000) + { + message = "msx_cart_easispeech_device: Region 'rom' has unsupported size."; + return image_init_result::FAIL; + } + + page(1)->install_rom(0x4000, 0x5fff, 0x2000, cart_rom_region()->base()); page(2)->install_read_handler(0x8000, 0x8000, read8smo_delegate(*this, FUNC(msx_cart_easispeech_device::speech_r))); page(2)->install_write_handler(0x8000, 0x8000, write8smo_delegate(*this, FUNC(msx_cart_easispeech_device::speech_w))); + + return image_init_result::PASS; } u8 msx_cart_easispeech_device::speech_r() diff --git a/src/devices/bus/msx/cart/easi_speech.h b/src/devices/bus/msx/cart/easi_speech.h index 50881eeee7f..b07b46e920f 100644 --- a/src/devices/bus/msx/cart/easi_speech.h +++ b/src/devices/bus/msx/cart/easi_speech.h @@ -5,7 +5,7 @@ #pragma once -#include "cartridge.h" +#include "bus/msx/slot/cartridge.h" #include "sound/sp0256.h" @@ -17,7 +17,7 @@ class msx_cart_easispeech_device : public device_t, public msx_cart_interface public: msx_cart_easispeech_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: // device-level overrides diff --git a/src/devices/bus/msx/cart/fmpac.cpp b/src/devices/bus/msx/cart/fmpac.cpp index ab32020980f..7a223e986fc 100644 --- a/src/devices/bus/msx/cart/fmpac.cpp +++ b/src/devices/bus/msx/cart/fmpac.cpp @@ -59,18 +59,33 @@ void msx_cart_fmpac_device::device_reset() } -void msx_cart_fmpac_device::initialize_cartridge() +image_init_result msx_cart_fmpac_device::initialize_cartridge(std::string &message) { - if (get_rom_size() != 0x10000) + if (!cart_rom_region()) { - fatalerror("fmpac: Invalid ROM size\n"); + message = "msx_cart_fmpac_device: Required region 'rom' was not found."; + return image_init_result::FAIL; } - if (get_sram_size() != 0x2000) + + if (!cart_sram_region()) + { + message = "msx_cart_fmpac_device: Required region 'sram' was not found."; + return image_init_result::FAIL; + } + + if (cart_rom_region()->bytes() != 0x10000) { - fatalerror("fmpac: Invalid SRAM size\n"); + message = "msx_cart_fmpac_device: Region 'rom' has unsupported size."; + return image_init_result::FAIL; } - m_rombank->configure_entries(0, 4, get_rom_base(), 0x4000); + if (cart_sram_region()->bytes() < 0x2000) + { + message = "msx_cart_fmpac_device: Region 'sram' has unsupported size."; + return image_init_result::FAIL; + } + + m_rombank->configure_entries(0, 4, cart_rom_region()->base(), 0x4000); page(1)->install_view(0x4000, 0x7fff, m_view); m_view[0].install_read_bank(0x4000, 0x7fff, m_rombank); @@ -81,13 +96,15 @@ void msx_cart_fmpac_device::initialize_cartridge() m_view[0].install_read_handler(0x7ff7, 0x7ff7, read8smo_delegate(*this, FUNC(msx_cart_fmpac_device::bank_r))); m_view[0].install_write_handler(0x7ff7, 0x7ff7, write8smo_delegate(*this, FUNC(msx_cart_fmpac_device::bank_w))); - m_view[1].install_ram(0x4000, 0x5fff, get_sram_base()); + m_view[1].install_ram(0x4000, 0x5fff, cart_sram_region()->base()); m_view[1].install_write_handler(0x5ffe, 0x5fff, write8sm_delegate(*this, FUNC(msx_cart_fmpac_device::sram_unlock))); m_view[1].install_write_handler(0x7ff4, 0x7ff5, write8sm_delegate(*this, FUNC(msx_cart_fmpac_device::write_ym2413))); m_view[1].install_read_handler(0x7ff6, 0x7ff6, read8smo_delegate(*this, FUNC(msx_cart_fmpac_device::control_r))); m_view[1].install_write_handler(0x7ff6, 0x7ff6, write8smo_delegate(*this, FUNC(msx_cart_fmpac_device::control_w))); m_view[1].install_read_handler(0x7ff7, 0x7ff7, read8smo_delegate(*this, FUNC(msx_cart_fmpac_device::bank_r))); m_view[1].install_write_handler(0x7ff7, 0x7ff7, write8smo_delegate(*this, FUNC(msx_cart_fmpac_device::bank_w))); + + return image_init_result::PASS; } void msx_cart_fmpac_device::sram_unlock(offs_t offset, u8 data) diff --git a/src/devices/bus/msx/cart/fmpac.h b/src/devices/bus/msx/cart/fmpac.h index 1e3ef69c14b..f63e517780c 100644 --- a/src/devices/bus/msx/cart/fmpac.h +++ b/src/devices/bus/msx/cart/fmpac.h @@ -5,7 +5,7 @@ #pragma once -#include "cartridge.h" +#include "bus/msx/slot/cartridge.h" #include "sound/ymopl.h" @@ -17,7 +17,7 @@ class msx_cart_fmpac_device : public device_t, public msx_cart_interface public: msx_cart_fmpac_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: virtual void device_start() override; diff --git a/src/devices/bus/msx/cart/fs_sr022.cpp b/src/devices/bus/msx/cart/fs_sr022.cpp index fd19f43547a..4c5ab2d98d4 100644 --- a/src/devices/bus/msx/cart/fs_sr022.cpp +++ b/src/devices/bus/msx/cart/fs_sr022.cpp @@ -25,18 +25,28 @@ void msx_cart_fs_sr022_device::device_reset() m_bunsetsu_address = 0; } -void msx_cart_fs_sr022_device::initialize_cartridge() +image_init_result msx_cart_fs_sr022_device::initialize_cartridge(std::string &message) { - if (get_rom_size() != 0x40000) + if (!cart_rom_region()) { - fatalerror("fs_sr022: Invalid ROM size\n"); + message = "msx_cart_fs_sr022_device: Required region 'rom' was not found."; + return image_init_result::FAIL; } - m_bunsetsu_rom = get_rom_base() + 0x20000; - page(1)->install_rom(0x4000, 0x7fff, get_rom_base()); - page(2)->install_rom(0x8000, 0xbfff, get_rom_base() + 0x4000); + if (cart_rom_region()->bytes() != 0x40000) + { + message = "msx_cart_fs_sr022_device: Region 'rom' has unsupported size."; + return image_init_result::FAIL; + } + + m_bunsetsu_rom = cart_rom_region()->base() + 0x20000; + + page(1)->install_rom(0x4000, 0x7fff, cart_rom_region()->base()); + page(2)->install_rom(0x8000, 0xbfff, cart_rom_region()->base() + 0x4000); page(2)->install_read_handler(0xbfff, 0xbfff, read8smo_delegate(*this, FUNC(msx_cart_fs_sr022_device::buns_r))); page(2)->install_write_handler(0xbffc, 0xbffe, write8sm_delegate(*this, FUNC(msx_cart_fs_sr022_device::buns_w))); + + return image_init_result::PASS; } u8 msx_cart_fs_sr022_device::buns_r() diff --git a/src/devices/bus/msx/cart/fs_sr022.h b/src/devices/bus/msx/cart/fs_sr022.h index a939b4b414a..22bb0c72c5a 100644 --- a/src/devices/bus/msx/cart/fs_sr022.h +++ b/src/devices/bus/msx/cart/fs_sr022.h @@ -5,7 +5,7 @@ #pragma once -#include "cartridge.h" +#include "bus/msx/slot/cartridge.h" DECLARE_DEVICE_TYPE(MSX_CART_FS_SR022, msx_cart_fs_sr022_device) @@ -16,7 +16,7 @@ class msx_cart_fs_sr022_device : public device_t, public msx_cart_interface public: msx_cart_fs_sr022_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: // device-level overrides diff --git a/src/devices/bus/msx/cart/halnote.cpp b/src/devices/bus/msx/cart/halnote.cpp index 5bbed142a27..c7e42401d8c 100644 --- a/src/devices/bus/msx/cart/halnote.cpp +++ b/src/devices/bus/msx/cart/halnote.cpp @@ -25,27 +25,42 @@ void msx_cart_halnote_device::device_reset() m_view1.select(0); } -void msx_cart_halnote_device::initialize_cartridge() +image_init_result msx_cart_halnote_device::initialize_cartridge(std::string &message) { - if (get_rom_size() != 0x100000) + if (!cart_rom_region()) { - fatalerror("halnote: Invalid ROM size\n"); + message = "msx_cart_halnote_device: Required region 'rom' was not found."; + return image_init_result::FAIL; } - if (get_sram_size() != 0x4000) + + if (!cart_sram_region()) + { + message = "msx_cart_halnote_device: Required region 'sram' was not found."; + return image_init_result::FAIL; + } + + if (cart_rom_region()->bytes() != 0x100000) { - fatalerror("halnote: Invalid SRAM size\n"); + message = "msx_cart_halnote_device: Region 'rom' has unsupported size."; + return image_init_result::FAIL; + } + + if (cart_sram_region()->bytes() < 0x4000) + { + message = "msx_cart_halnote_device: Region 'sram' has unsupported size."; + return image_init_result::FAIL; } for (int i = 0; i < 4; i++) { - m_rombank[i]->configure_entries(0, 0x80, get_rom_base(), 0x2000); + m_rombank[i]->configure_entries(0, 0x80, cart_rom_region()->base(), 0x2000); } - m_rombank[4]->configure_entries(0, 0x100, get_rom_base() + 0x80000, 0x800); - m_rombank[5]->configure_entries(0, 0x100, get_rom_base() + 0x80000, 0x800); + m_rombank[4]->configure_entries(0, 0x100, cart_rom_region()->base() + 0x80000, 0x800); + m_rombank[5]->configure_entries(0, 0x100, cart_rom_region()->base() + 0x80000, 0x800); page(0)->install_view(0x0000, 0x3fff, m_view0); m_view0[0]; - m_view0[1].install_ram(0x0000, 0x3fff, get_sram_base()); + m_view0[1].install_ram(0x0000, 0x3fff, cart_sram_region()->base()); page(1)->install_read_bank(0x4000, 0x5fff, m_rombank[0]); page(1)->install_write_handler(0x4fff, 0x4fff, write8smo_delegate(*this, FUNC(msx_cart_halnote_device::bank0_w))); page(1)->install_view(0x6000, 0x7fff, m_view1); @@ -63,6 +78,8 @@ void msx_cart_halnote_device::initialize_cartridge() page(2)->install_write_handler(0x8fff, 0x8fff, write8smo_delegate(*this, FUNC(msx_cart_halnote_device::bank2_w))); page(2)->install_read_bank(0xa000, 0xbfff, m_rombank[3]); page(2)->install_write_handler(0xafff, 0xafff, write8smo_delegate(*this, FUNC(msx_cart_halnote_device::bank3_w))); + + return image_init_result::PASS; } void msx_cart_halnote_device::bank0_w(u8 data) diff --git a/src/devices/bus/msx/cart/halnote.h b/src/devices/bus/msx/cart/halnote.h index edfde67c7a3..87a3d584f81 100644 --- a/src/devices/bus/msx/cart/halnote.h +++ b/src/devices/bus/msx/cart/halnote.h @@ -5,7 +5,7 @@ #pragma once -#include "cartridge.h" +#include "bus/msx/slot/cartridge.h" DECLARE_DEVICE_TYPE(MSX_CART_HALNOTE, msx_cart_halnote_device) @@ -16,7 +16,7 @@ class msx_cart_halnote_device : public device_t, public msx_cart_interface public: msx_cart_halnote_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: // device-level overrides diff --git a/src/devices/bus/msx/cart/hfox.cpp b/src/devices/bus/msx/cart/hfox.cpp index 5945e399e35..9a749614d3c 100644 --- a/src/devices/bus/msx/cart/hfox.cpp +++ b/src/devices/bus/msx/cart/hfox.cpp @@ -20,25 +20,34 @@ void msx_cart_hfox_device::device_reset() m_rombank[1]->set_entry(0); } -void msx_cart_hfox_device::initialize_cartridge() +image_init_result msx_cart_hfox_device::initialize_cartridge(std::string &message) { - u32 size = get_rom_size(); - u16 banks = size / 0x8000; + if (!cart_rom_region()) + { + message = "msx_cart_hfox_device: Required region 'rom' was not found."; + return image_init_result::FAIL; + } + + const u32 size = cart_rom_region()->bytes(); + const u16 banks = size / 0x8000; if (size > 256 * 0x8000 || size < 0x10000 || size != banks * 0x8000 || (~(banks - 1) % banks)) { - fatalerror("hfox: Invalid ROM size\n"); + message = "msx_cart_hfox_device: Region 'rom' has unsupported size."; + return image_init_result::FAIL; } m_bank_mask = banks - 1; - m_rombank[0]->configure_entries(0, 4, get_rom_base(), 0x8000); - m_rombank[1]->configure_entries(0, 4, get_rom_base() + 0x4000, 0x8000); + m_rombank[0]->configure_entries(0, 4, cart_rom_region()->base(), 0x8000); + m_rombank[1]->configure_entries(0, 4, cart_rom_region()->base() + 0x4000, 0x8000); page(1)->install_read_bank(0x4000, 0x7fff, m_rombank[0]); page(1)->install_write_handler(0x6000, 0x6000, write8smo_delegate(*this, FUNC(msx_cart_hfox_device::bank_w<0>))); page(1)->install_write_handler(0x7000, 0x7000, write8smo_delegate(*this, FUNC(msx_cart_hfox_device::bank_w<1>))); page(2)->install_read_bank(0x8000, 0xbfff, m_rombank[1]); + + return image_init_result::PASS; } template diff --git a/src/devices/bus/msx/cart/hfox.h b/src/devices/bus/msx/cart/hfox.h index 3b6fed970f8..2b500629e1f 100644 --- a/src/devices/bus/msx/cart/hfox.h +++ b/src/devices/bus/msx/cart/hfox.h @@ -5,7 +5,7 @@ #pragma once -#include "cartridge.h" +#include "bus/msx/slot/cartridge.h" DECLARE_DEVICE_TYPE(MSX_CART_HFOX, msx_cart_hfox_device) @@ -16,7 +16,7 @@ class msx_cart_hfox_device : public device_t, public msx_cart_interface public: msx_cart_hfox_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: // device-level overrides diff --git a/src/devices/bus/msx/cart/holy_quran.cpp b/src/devices/bus/msx/cart/holy_quran.cpp index cc87db1b435..b9e178f4694 100644 --- a/src/devices/bus/msx/cart/holy_quran.cpp +++ b/src/devices/bus/msx/cart/holy_quran.cpp @@ -25,14 +25,21 @@ msx_cart_holy_quran_device::msx_cart_holy_quran_device(const machine_config &mco { } -void msx_cart_holy_quran_device::initialize_cartridge() +image_init_result msx_cart_holy_quran_device::initialize_cartridge(std::string &message) { - u32 size = get_rom_size(); - u16 banks = size / BANK_SIZE; + if (!cart_rom_region()) + { + message = "msx_cart_holy_quran_device: Required region 'rom' was not found."; + return image_init_result::FAIL; + } + + const u32 size = cart_rom_region()->bytes(); + const u16 banks = size / BANK_SIZE; if (size > 256 * BANK_SIZE || size < 0x10000 || size != banks * BANK_SIZE || (~(banks - 1) % banks)) { - fatalerror("holy_quran: Invalid ROM size\n"); + message = "msx_cart_holy_quran_device: Region 'rom' has unsupported size."; + return image_init_result::FAIL; } m_bank_mask = banks - 1; @@ -44,8 +51,9 @@ void msx_cart_holy_quran_device::initialize_cartridge() for (int i = 0; i < 0x100; i++) lookup_prot[i] = bitswap<8>(i,6,2,4,0,1,5,7,3) ^ 0x4d; + u8 *rom = cart_rom_region()->base(); for (u32 i = 0; i < size; i++) - m_decrypted[i] = lookup_prot[m_rom[i]]; + m_decrypted[i] = lookup_prot[rom[i]]; for (int i = 0; i < 4; i++) m_rombank[i]->configure_entries(0, banks, m_decrypted.data(), BANK_SIZE); @@ -63,6 +71,8 @@ void msx_cart_holy_quran_device::initialize_cartridge() m_view2[0].install_read_handler(0x8000, 0xbfff, read8sm_delegate(*this, FUNC(msx_cart_holy_quran_device::read2))); m_view2[1].install_read_bank(0x8000, 0x9fff, m_rombank[2]); m_view2[1].install_read_bank(0xa000, 0xbfff, m_rombank[3]); + + return image_init_result::PASS; } void msx_cart_holy_quran_device::device_reset() @@ -75,9 +85,9 @@ void msx_cart_holy_quran_device::device_reset() u8 msx_cart_holy_quran_device::read(offs_t offset) { - u8 data = m_rom[offset]; + u8 data = cart_rom_region()->base()[offset]; // The decryption should actually start working after the first M1 cycle executing something from the cartridge. - if (offset + 0x4000 == ((m_rom[3] << 8) | m_rom[2]) && !machine().side_effects_disabled()) + if (offset + 0x4000 == ((cart_rom_region()->base()[3] << 8) | cart_rom_region()->base()[2]) && !machine().side_effects_disabled()) { // Switch to decrypted contents m_view1.select(1); @@ -88,9 +98,9 @@ u8 msx_cart_holy_quran_device::read(offs_t offset) u8 msx_cart_holy_quran_device::read2(offs_t offset) { - u8 data = m_rom[offset + 0x4000]; + u8 data = cart_rom_region()->base()[offset + 0x4000]; // The decryption should actually start working after the first M1 cycle executing something from the cartridge. - if (offset + 0x8000 == ((m_rom[3] << 8) | m_rom[2]) && !machine().side_effects_disabled()) + if (offset + 0x8000 == ((cart_rom_region()->base()[3] << 8) | cart_rom_region()->base()[2]) && !machine().side_effects_disabled()) { // Switch to decrypted contents m_view1.select(1); diff --git a/src/devices/bus/msx/cart/holy_quran.h b/src/devices/bus/msx/cart/holy_quran.h index c9898bc10a0..0cd66a2dd97 100644 --- a/src/devices/bus/msx/cart/holy_quran.h +++ b/src/devices/bus/msx/cart/holy_quran.h @@ -5,7 +5,7 @@ #pragma once -#include "cartridge.h" +#include "bus/msx/slot/cartridge.h" DECLARE_DEVICE_TYPE(MSX_CART_HOLY_QURAN, msx_cart_holy_quran_device) @@ -16,7 +16,7 @@ class msx_cart_holy_quran_device : public device_t, public msx_cart_interface public: msx_cart_holy_quran_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: // device-level overrides diff --git a/src/devices/bus/msx/cart/ink.cpp b/src/devices/bus/msx/cart/ink.cpp index abf48b37154..45b77f77034 100644 --- a/src/devices/bus/msx/cart/ink.cpp +++ b/src/devices/bus/msx/cart/ink.cpp @@ -36,12 +36,18 @@ void msx_cart_ink_device::device_add_mconfig(machine_config &config) AMD_29F040(config, m_flash); } -void msx_cart_ink_device::initialize_cartridge() +image_init_result msx_cart_ink_device::initialize_cartridge(std::string &message) { - size_t size = std::min(0x80000, get_rom_size()); + if (!cart_rom_region()) + { + message = "msx_cart_ink_device: Required region 'rom' was not found."; + return image_init_result::FAIL; + } + + const size_t size = std::min(0x80000, cart_rom_region()->bytes()); u8 *flash = memregion("flash")->base(); - memcpy(flash, get_rom_base(), size); + memcpy(flash, cart_rom_region()->base(), size); page(0)->install_rom(0x0000, 0x3fff, flash); page(1)->install_rom(0x4000, 0x7fff, flash + 0x4000); @@ -51,6 +57,8 @@ void msx_cart_ink_device::initialize_cartridge() page(1)->install_write_handler(0x4000, 0x7fff, write8sm_delegate(*this, FUNC(msx_cart_ink_device::write_page<1>))); page(2)->install_write_handler(0x8000, 0xbfff, write8sm_delegate(*this, FUNC(msx_cart_ink_device::write_page<2>))); page(3)->install_write_handler(0xc000, 0xffff, write8sm_delegate(*this, FUNC(msx_cart_ink_device::write_page<3>))); + + return image_init_result::PASS; } template diff --git a/src/devices/bus/msx/cart/ink.h b/src/devices/bus/msx/cart/ink.h index 33f7da4fd74..c8c6c2d0104 100644 --- a/src/devices/bus/msx/cart/ink.h +++ b/src/devices/bus/msx/cart/ink.h @@ -5,7 +5,7 @@ #pragma once -#include "cartridge.h" +#include "bus/msx/slot/cartridge.h" #include "machine/intelfsh.h" @@ -17,7 +17,7 @@ class msx_cart_ink_device : public device_t, public msx_cart_interface public: msx_cart_ink_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: // device-level overrides diff --git a/src/devices/bus/msx/cart/kanji.cpp b/src/devices/bus/msx/cart/kanji.cpp index 215121d7559..6b28136727f 100644 --- a/src/devices/bus/msx/cart/kanji.cpp +++ b/src/devices/bus/msx/cart/kanji.cpp @@ -46,25 +46,46 @@ void msx_cart_kanji_device::device_start() save_item(NAME(m_kanji_address)); } -void msx_cart_kanji_device::initialize_cartridge() +image_init_result msx_cart_kanji_device::validate_kanji_regions(std::string &message) { - u32 size = get_kanji_size(); + if (!cart_kanji_region()) + { + message = "msx_cart_kanji_device: Required region 'kanji' was not found."; + return image_init_result::FAIL; + } - if (size != 0x20000) + if (cart_kanji_region()->bytes() != 0x20000) { - fatalerror("kanji: Invalid ROM size\n"); + message = "msx_cart_kanji_device: Region 'rom' has unsupported size."; + return image_init_result::FAIL; } - m_kanji_mask = size - 1; + return image_init_result::PASS; +} + +void msx_cart_kanji_device::install_kanji_handlers() +{ + m_kanji_mask = cart_kanji_region()->bytes() - 1; // Install IO read/write handlers io_space().install_write_handler(0xd8, 0xd9, write8sm_delegate(*this, FUNC(msx_cart_kanji_device::kanji_w))); io_space().install_read_handler(0xd9, 0xd9, read8sm_delegate(*this, FUNC(msx_cart_kanji_device::kanji_r))); } +image_init_result msx_cart_kanji_device::initialize_cartridge(std::string &message) +{ + image_init_result result = validate_kanji_regions(message); + if (image_init_result::PASS != result) + return result; + + install_kanji_handlers(); + + return image_init_result::PASS; +} + u8 msx_cart_kanji_device::kanji_r(offs_t offset) { - u8 result = get_kanji_base()[m_kanji_address]; + u8 result = cart_kanji_region()->base()[m_kanji_address]; if (!machine().side_effects_disabled()) { @@ -114,23 +135,34 @@ void msx_cart_msxwrite_device::device_reset() m_rombank[1]->set_entry(0); if (BIT(m_kanji_switch->read(), 0)) - msx_cart_kanji_device::initialize_cartridge(); + install_kanji_handlers(); } -void msx_cart_msxwrite_device::initialize_cartridge() +image_init_result msx_cart_msxwrite_device::initialize_cartridge(std::string &message) { - u32 size = get_rom_size(); - u16 banks = size / BANK_SIZE; + image_init_result result = validate_kanji_regions(message); + if (image_init_result::PASS != result) + return result; + + if (!cart_rom_region()) + { + message = "msx_cart_msxwrite_device: Required region 'rom' was not found."; + return image_init_result::FAIL; + } + + const u32 size = cart_rom_region()->bytes(); + const u16 banks = size / BANK_SIZE; if (size > 256 * BANK_SIZE || size != banks * BANK_SIZE || (~(banks - 1) % banks)) { - fatalerror("msxwrite: Invalid ROM size\n"); + message = "msx_cart_msxwrite_device: Region 'rom' has unsupported size."; + return image_init_result::FAIL; } m_bank_mask = banks - 1; for (int i = 0; i < 2; i++) - m_rombank[i]->configure_entries(0, banks, get_rom_base(), BANK_SIZE); + m_rombank[i]->configure_entries(0, banks, cart_rom_region()->base(), BANK_SIZE); page(1)->install_read_bank(0x4000, 0x7fff, m_rombank[0]); // The rom writes to 6fff and 7fff for banking, unknown whether @@ -138,6 +170,8 @@ void msx_cart_msxwrite_device::initialize_cartridge() page(1)->install_write_handler(0x6fff, 0x6fff, write8smo_delegate(*this, FUNC(msx_cart_msxwrite_device::bank_w<0>))); page(1)->install_write_handler(0x7fff, 0x7fff, write8smo_delegate(*this, FUNC(msx_cart_msxwrite_device::bank_w<1>))); page(2)->install_read_bank(0x8000, 0xbfff, m_rombank[1]); + + return image_init_result::PASS; } template diff --git a/src/devices/bus/msx/cart/kanji.h b/src/devices/bus/msx/cart/kanji.h index 83a7798b941..15e3bd6cd03 100644 --- a/src/devices/bus/msx/cart/kanji.h +++ b/src/devices/bus/msx/cart/kanji.h @@ -5,7 +5,7 @@ #pragma once -#include "cartridge.h" +#include "bus/msx/slot/cartridge.h" DECLARE_DEVICE_TYPE(MSX_CART_KANJI, msx_cart_kanji_device) @@ -17,7 +17,7 @@ class msx_cart_kanji_device : public device_t, public msx_cart_interface public: msx_cart_kanji_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: msx_cart_kanji_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock); @@ -26,6 +26,9 @@ protected: virtual void device_start() override; virtual void device_reset() override; + image_init_result validate_kanji_regions(std::string &message); + void install_kanji_handlers(); + u8 kanji_r(offs_t offset); void kanji_w(offs_t offset, u8 data); @@ -39,7 +42,7 @@ class msx_cart_msxwrite_device : public msx_cart_kanji_device public: msx_cart_msxwrite_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: // device-level overrides diff --git a/src/devices/bus/msx/cart/konami.cpp b/src/devices/bus/msx/cart/konami.cpp index 6b942c73489..7742dda5540 100644 --- a/src/devices/bus/msx/cart/konami.cpp +++ b/src/devices/bus/msx/cart/konami.cpp @@ -30,20 +30,27 @@ void msx_cart_konami_device::device_reset() m_rombank[i]->set_entry(i); } -void msx_cart_konami_device::initialize_cartridge() +image_init_result msx_cart_konami_device::initialize_cartridge(std::string &message) { - u32 size = get_rom_size(); - u16 banks = size / 0x2000; + if (!cart_rom_region()) + { + message = "msx_cart_konami_device: Required region 'rom' was not found."; + return image_init_result::FAIL; + } + + const u32 size = cart_rom_region()->bytes(); + const u16 banks = size / 0x2000; if (size > 256 * 0x2000 || size < 4 * 0x2000 || size != banks * 0x2000 || (~(banks - 1) % banks)) { - fatalerror("konami: Invalid ROM size\n"); + message = "msx_cart_konami_device: Region 'rom' has unsupported size."; + return image_init_result::FAIL; } m_bank_mask = banks - 1; for (int i = 0; i < 4; i++) - m_rombank[i]->configure_entries(0, banks, get_rom_base(), 0x2000); + m_rombank[i]->configure_entries(0, banks, cart_rom_region()->base(), 0x2000); page(0)->install_read_bank(0x0000, 0x1fff, m_rombank[0]); page(0)->install_read_bank(0x2000, 0x3fff, m_rombank[1]); @@ -57,6 +64,8 @@ void msx_cart_konami_device::initialize_cartridge() page(2)->install_write_handler(0xa000, 0xa7ff, 0, 0x1000, 0, write8smo_delegate(*this, FUNC(msx_cart_konami_device::bank_w<3>))); page(3)->install_read_bank(0xc000, 0xdfff, m_rombank[2]); page(3)->install_read_bank(0xe000, 0xffff, m_rombank[3]); + + return image_init_result::PASS; } template @@ -92,20 +101,27 @@ void msx_cart_konami_scc_device::device_reset() m_rombank[i]->set_entry(i); } -void msx_cart_konami_scc_device::initialize_cartridge() +image_init_result msx_cart_konami_scc_device::initialize_cartridge(std::string &message) { - u32 size = get_rom_size(); - u16 banks = size / 0x2000; + if (!cart_rom_region()) + { + message = "msx_cart_konami_scc_device: Required region 'rom' was not found."; + return image_init_result::FAIL; + } + + const u32 size = cart_rom_region()->bytes(); + const u16 banks = size / 0x2000; if (size > 256 * 0x2000 || size < 0x8000 || size != banks * 0x2000 || (~(banks - 1) % banks)) { - fatalerror("konami_scc: Invalid ROM size\n"); + message = "msx_cart_konami_scc_device: Region 'rom' has unsupported size."; + return image_init_result::FAIL; } m_bank_mask = banks - 1; for (int i = 0; i < 4; i++) - m_rombank[i]->configure_entries(0, banks, get_rom_base(), 0x2000); + m_rombank[i]->configure_entries(0, banks, cart_rom_region()->base(), 0x2000); page(0)->install_read_bank(0x0000, 0x1fff, m_rombank[2]); page(0)->install_read_bank(0x2000, 0x3fff, m_rombank[3]); @@ -131,6 +147,8 @@ void msx_cart_konami_scc_device::initialize_cartridge() page(2)->install_write_handler(0xb000, 0xb7ff, write8smo_delegate(*this, FUNC(msx_cart_konami_scc_device::bank_w<3>))); page(3)->install_read_bank(0xc000, 0xdfff, m_rombank[0]); page(3)->install_read_bank(0xe000, 0xffff, m_rombank[1]); + + return image_init_result::PASS; } template @@ -169,27 +187,42 @@ void msx_cart_gamemaster2_device::device_reset() m_view2.select(0); } -void msx_cart_gamemaster2_device::initialize_cartridge() +image_init_result msx_cart_gamemaster2_device::initialize_cartridge(std::string &message) { - u32 size = get_rom_size(); - u16 banks = size / 0x2000; + if (!cart_rom_region()) + { + message = "msx_cart_gamemaster2_device: Required region 'rom' was not found."; + return image_init_result::FAIL; + } + + if (!cart_sram_region()) + { + message = "msx_cart_gamemaster2_device: Required region 'sram' was not found."; + return image_init_result::FAIL; + } + + const u32 size = cart_rom_region()->bytes(); + const u16 banks = size / 0x2000; if (size != 0x20000) { - fatalerror("gamemaster2: Invalid ROM size\n"); + message = "msx_cart_gamemaster2_device: Region 'rom' has unsupported size."; + return image_init_result::FAIL; } - if (get_sram_size() != 0x2000) + + if (cart_sram_region()->bytes() != 0x2000) { - fatalerror("gamemaster2: Invalid SRAM size\n"); + message = "msx_cart_gamemaster2_device: Region 'sram' has unsupported size."; + return image_init_result::FAIL; } for (int i = 0; i < 3; i++) { - m_rombank[i]->configure_entries(0, banks, get_rom_base(), 0x2000); - m_rambank[i]->configure_entries(0, 2, get_sram_base(), 0x1000); + m_rombank[i]->configure_entries(0, banks, cart_rom_region()->base(), 0x2000); + m_rambank[i]->configure_entries(0, 2, cart_sram_region()->base(), 0x1000); } - page(1)->install_rom(0x4000, 0x5fff, get_rom_base()); + page(1)->install_rom(0x4000, 0x5fff, cart_rom_region()->base()); page(1)->install_view(0x6000, 0x7fff, m_view0); m_view0[0].install_read_bank(0x6000, 0x7fff, m_rombank[0]); @@ -209,6 +242,8 @@ void msx_cart_gamemaster2_device::initialize_cartridge() m_view2[1].install_read_bank(0xa000, 0xafff, m_rambank[2]); m_view2[1].install_write_handler(0xa000, 0xafff, write8smo_delegate(*this, FUNC(msx_cart_gamemaster2_device::bank_w<2>))); m_view2[1].install_readwrite_bank(0xb000, 0xbfff, m_rambank[2]); + + return image_init_result::PASS; } template @@ -242,16 +277,25 @@ void msx_cart_synthesizer_device::device_add_mconfig(machine_config &config) DAC_8BIT_R2R(config, m_dac, 0).add_route(ALL_OUTPUTS, "speaker", 0.3); // unknown DAC } -void msx_cart_synthesizer_device::initialize_cartridge() +image_init_result msx_cart_synthesizer_device::initialize_cartridge(std::string &message) { - if (get_rom_size() != 0x8000) + if (!cart_rom_region()) { - fatalerror("synthesizer: Invalid ROM size\n"); + message = "msx_cart_synthesizer_device: Required region 'rom' was not found."; + return image_init_result::FAIL; } - page(1)->install_rom(0x4000, 0x7fff, get_rom_base()); + if (cart_rom_region()->bytes() != 0x8000) + { + message = "msx_cart_synthesizer_device: Region 'rom' has unsupported size."; + return image_init_result::FAIL; + } + + page(1)->install_rom(0x4000, 0x7fff, cart_rom_region()->base()); page(1)->install_write_handler(0x4000, 0x4000, 0, 0x3fef, 0, write8smo_delegate(m_dac, FUNC(dac_byte_interface::write))); - page(2)->install_rom(0x8000, 0xbfff, get_rom_base() + 0x4000); + page(2)->install_rom(0x8000, 0xbfff, cart_rom_region()->base() + 0x4000); + + return image_init_result::PASS; } @@ -299,11 +343,11 @@ void msx_cart_konami_sound_device::device_reset() switch_bank<3>(); } -void msx_cart_konami_sound_device::initialize_cartridge() +image_init_result msx_cart_konami_sound_device::initialize_cartridge(std::string &message) { for (int i = 0; i < 4; i++) { - m_rambank[i]->configure_entries(0, 8, get_ram_base(), 0x2000); + m_rambank[i]->configure_entries(0, 8, cart_ram_region()->base(), 0x2000); } // TODO Mirrors at 0000-3fff and c000-ffff @@ -383,6 +427,8 @@ void msx_cart_konami_sound_device::initialize_cartridge() m_view3[VIEW_SCC | VIEW_INVALID| VIEW_RAM].install_read_handler(0xb8c0, 0xb8c0, 0, 0x071f, 0, read8smo_delegate(m_k052539, FUNC(k051649_device::k051649_test_r))); page(2)->install_write_handler(0xbffe, 0xbfff, write8smo_delegate(*this, FUNC(msx_cart_konami_sound_device::control_w))); + + return image_init_result::PASS; } void msx_cart_konami_sound_device::control_w(u8 data) @@ -442,14 +488,21 @@ msx_cart_konami_sound_snatcher_device::msx_cart_konami_sound_snatcher_device(con { } -void msx_cart_konami_sound_snatcher_device::initialize_cartridge() +image_init_result msx_cart_konami_sound_snatcher_device::initialize_cartridge(std::string &message) { - if (get_ram_size() != 0x10000) + if (!cart_ram_region()) { - fatalerror("sound_snatcher: Invalid RAM size\n"); + message = "msx_cart_konami_sound_snatcher_device: Required region 'ram' was not found."; + return image_init_result::FAIL; } - msx_cart_konami_sound_device::initialize_cartridge(); + if (cart_ram_region()->bytes() != 0x10000) + { + message = "msx_cart_konami_sound_snatcher_device: Region 'ram' has unsupported size."; + return image_init_result::FAIL; + } + + return msx_cart_konami_sound_device::initialize_cartridge(message); } @@ -459,13 +512,21 @@ msx_cart_konami_sound_sdsnatcher_device::msx_cart_konami_sound_sdsnatcher_device { } -void msx_cart_konami_sound_sdsnatcher_device::initialize_cartridge() +image_init_result msx_cart_konami_sound_sdsnatcher_device::initialize_cartridge(std::string &message) { - if (get_ram_size() != 0x10000) + if (!cart_ram_region()) + { + message = "msx_cart_konami_sound_sdsnatcher_device: Required region 'ram' was not found."; + return image_init_result::FAIL; + } + + if (cart_ram_region()->bytes() != 0x10000) { - fatalerror("sound_sdsnatcher: Invalid RAM size\n"); + message = "msx_cart_konami_sound_sdsnatcher_device: Region 'ram' has unsupported size."; + return image_init_result::FAIL; } - msx_cart_konami_sound_device::initialize_cartridge(); + + return msx_cart_konami_sound_device::initialize_cartridge(message); } @@ -499,19 +560,37 @@ void msx_cart_keyboard_master_device::device_start() io_space().install_read_handler(0x00, 0x00, read8smo_delegate(*this, FUNC(msx_cart_keyboard_master_device::io_00_r))); } -void msx_cart_keyboard_master_device::initialize_cartridge() +image_init_result msx_cart_keyboard_master_device::initialize_cartridge(std::string &message) { - if (get_rom_size() != 0x4000) + if (!cart_rom_region()) + { + message = "msx_cart_keyboard_master_device: Required region 'rom' was not found."; + return image_init_result::FAIL; + } + + if (!cart_vlm5030_region()) { - fatalerror("keyboard_master: Invalid ROM size\n"); + message = "msx_cart_keyboard_master_device: Required region 'vlm5030' was not found."; + return image_init_result::FAIL; } - page(1)->install_rom(0x4000, 0x7fff, get_rom_base()); + if (cart_rom_region()->bytes() != 0x4000) + { + message = "msx_cart_keyboard_master_device: Region 'rom' has unsupported size."; + return image_init_result::FAIL; + } + + page(1)->install_rom(0x4000, 0x7fff, cart_rom_region()->base()); + + return image_init_result::PASS; } uint8_t msx_cart_keyboard_master_device::read_vlm(offs_t offset) { - return m_rom_vlm5030[offset]; + if (offset < cart_vlm5030_region()->bytes()) + return cart_vlm5030_region()->base()[offset]; + else + return 0xff; } void msx_cart_keyboard_master_device::io_20_w(uint8_t data) @@ -541,17 +620,25 @@ void msx_cart_ec701_device::device_reset() m_view.select(0); } -void msx_cart_ec701_device::initialize_cartridge() +image_init_result msx_cart_ec701_device::initialize_cartridge(std::string &message) { - m_rombank->configure_entries(0, 24, get_rom_base() + 0x20000, 0x4000); + if (!cart_rom_region()) + { + message = "msx_cart_ec701_device: Required region 'rom' was not found."; + return image_init_result::FAIL; + } + + m_rombank->configure_entries(0, 24, cart_rom_region()->base() + 0x20000, 0x4000); page(1)->install_view(0x4000, 0x7fff, m_view); - m_view[0].install_rom(0x4000, 0x7fff, get_rom_base()); + m_view[0].install_rom(0x4000, 0x7fff, cart_rom_region()->base()); m_view[1].install_read_bank(0x4000, 0x7fff, m_rombank); m_view[2].nop_read(0x4000, 0x7fff); - page(2)->install_rom(0x8000, 0xbfff, get_rom_base() + 0x4000); + page(2)->install_rom(0x8000, 0xbfff, cart_rom_region()->base() + 0x4000); page(2)->install_write_handler(0xbff8, 0xbfff, write8smo_delegate(*this, FUNC(msx_cart_ec701_device::bank_w))); + + return image_init_result::PASS; } void msx_cart_ec701_device::bank_w(u8 data) diff --git a/src/devices/bus/msx/cart/konami.h b/src/devices/bus/msx/cart/konami.h index c250e373525..d35e58c794e 100644 --- a/src/devices/bus/msx/cart/konami.h +++ b/src/devices/bus/msx/cart/konami.h @@ -5,7 +5,7 @@ #pragma once -#include "cartridge.h" +#include "bus/msx/slot/cartridge.h" #include "sound/k051649.h" #include "sound/vlm5030.h" #include "sound/dac.h" @@ -26,7 +26,7 @@ class msx_cart_konami_device : public device_t, public msx_cart_interface public: msx_cart_konami_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: // device-level overrides @@ -46,7 +46,7 @@ class msx_cart_konami_scc_device : public device_t, public msx_cart_interface public: msx_cart_konami_scc_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: // device-level overrides @@ -71,7 +71,7 @@ class msx_cart_gamemaster2_device : public device_t, public msx_cart_interface public: msx_cart_gamemaster2_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: // device-level overrides @@ -94,7 +94,7 @@ class msx_cart_synthesizer_device : public device_t, public msx_cart_interface public: msx_cart_synthesizer_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: // device-level overrides @@ -110,7 +110,7 @@ private: class msx_cart_konami_sound_device : public device_t, public msx_cart_interface { public: - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: msx_cart_konami_sound_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock, u8 min_rambank, u8 max_rambank); @@ -151,7 +151,7 @@ class msx_cart_konami_sound_snatcher_device : public msx_cart_konami_sound_devic public: msx_cart_konami_sound_snatcher_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; }; @@ -160,7 +160,7 @@ class msx_cart_konami_sound_sdsnatcher_device : public msx_cart_konami_sound_dev public: msx_cart_konami_sound_sdsnatcher_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; }; @@ -176,7 +176,7 @@ protected: virtual void device_add_mconfig(machine_config &config) override; - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; private: required_device m_vlm5030; @@ -200,7 +200,7 @@ protected: virtual void device_start() override { } virtual void device_reset() override; - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; private: void bank_w(u8 data); diff --git a/src/devices/bus/msx/cart/korean.cpp b/src/devices/bus/msx/cart/korean.cpp index 6ba0ffe1d0f..243e6d14084 100644 --- a/src/devices/bus/msx/cart/korean.cpp +++ b/src/devices/bus/msx/cart/korean.cpp @@ -22,26 +22,35 @@ void msx_cart_korean_80in1_device::device_reset() m_rombank[i]->set_entry(i); } -void msx_cart_korean_80in1_device::initialize_cartridge() +image_init_result msx_cart_korean_80in1_device::initialize_cartridge(std::string &message) { - u32 size = get_rom_size(); - u16 banks = size / 0x2000; + if (!cart_rom_region()) + { + message = "msx_cart_korean_80in1_device: Required region 'rom' was not found."; + return image_init_result::FAIL; + } + + const u32 size = cart_rom_region()->bytes(); + const u16 banks = size / 0x2000; if (size > 256 * 0x2000 || size < 0x8000 || size != banks * 0x2000 || (~(banks - 1) % banks)) { - fatalerror("korean_80in1: Invalid ROM size\n"); + message = "msx_cart_korean_80in1_device: Region 'rom' has unsupported size."; + return image_init_result::FAIL; } m_bank_mask = banks - 1; for (int i = 0; i < 4; i++) - m_rombank[i]->configure_entries(0, banks, get_rom_base(), 0x2000); + m_rombank[i]->configure_entries(0, banks, cart_rom_region()->base(), 0x2000); page(1)->install_read_bank(0x4000, 0x5fff, m_rombank[0]); page(1)->install_write_handler(0x4000, 0x4003, write8sm_delegate(*this, FUNC(msx_cart_korean_80in1_device::bank_w))); page(1)->install_read_bank(0x6000, 0x7fff, m_rombank[1]); page(2)->install_read_bank(0x8000, 0x9fff, m_rombank[2]); page(2)->install_read_bank(0xa000, 0xbfff, m_rombank[3]); + + return image_init_result::PASS; } void msx_cart_korean_80in1_device::bank_w(offs_t offset, u8 data) @@ -76,21 +85,28 @@ void msx_cart_korean_90in1_device::device_reset() m_rombank[2]->set_entry(0); } -void msx_cart_korean_90in1_device::initialize_cartridge() +image_init_result msx_cart_korean_90in1_device::initialize_cartridge(std::string &message) { - u32 size = get_rom_size(); - u16 banks = size / 0x4000; + if (!cart_rom_region()) + { + message = "msx_cart_korean_90in1_device: Required region 'rom' was not found."; + return image_init_result::FAIL; + } + + const u32 size = cart_rom_region()->bytes(); + const u16 banks = size / 0x4000; if (size > 64 * 0x4000 || size < 0x8000 || size != banks * 0x4000 || (~(banks - 1) % banks)) { - fatalerror("korean_90in1: Invalid ROM size\n"); + message = "msx_cart_korean_90in1_device: Region 'rom' has unsupported size."; + return image_init_result::FAIL; } m_bank_mask = banks - 1; - m_rombank[0]->configure_entries(0, banks, get_rom_base(), 0x4000); - m_rombank[1]->configure_entries(0, banks, get_rom_base(), 0x4000); - m_rombank[2]->configure_entries(0, banks, get_rom_base() + 0x2000, 0x4000); + m_rombank[0]->configure_entries(0, banks, cart_rom_region()->base(), 0x4000); + m_rombank[1]->configure_entries(0, banks, cart_rom_region()->base(), 0x4000); + m_rombank[2]->configure_entries(0, banks, cart_rom_region()->base() + 0x2000, 0x4000); page(1)->install_read_bank(0x4000, 0x7fff, m_rombank[0]); @@ -99,6 +115,8 @@ void msx_cart_korean_90in1_device::initialize_cartridge() m_view[0].install_read_bank(0xa000, 0xbfff, m_rombank[2]); m_view[1].install_read_bank(0x8000, 0x9fff, m_rombank[2]); m_view[1].install_read_bank(0xa000, 0xbfff, m_rombank[1]); + + return image_init_result::PASS; } void msx_cart_korean_90in1_device::banking(u8 data) @@ -131,24 +149,33 @@ void msx_cart_korean_126in1_device::device_reset() m_rombank[1]->set_entry(1); } -void msx_cart_korean_126in1_device::initialize_cartridge() +image_init_result msx_cart_korean_126in1_device::initialize_cartridge(std::string &message) { - u32 size = get_rom_size(); - u16 banks = size / 0x4000; + if (!cart_rom_region()) + { + message = "msx_cart_korean_126in1_device: Required region 'rom' was not found."; + return image_init_result::FAIL; + } + + const u32 size = cart_rom_region()->bytes(); + const u16 banks = size / 0x4000; if (size > 256 * 0x4000 || size < 0x8000 || size != banks * 0x4000 || (~(banks - 1) % banks)) { - fatalerror("korean_126in1: Invalid ROM size\n"); + message = "msx_cart_korean_126in1_device: Region 'rom' has unsupported size."; + return image_init_result::FAIL; } m_bank_mask = banks - 1; - m_rombank[0]->configure_entries(0, banks, get_rom_base(), 0x4000); - m_rombank[1]->configure_entries(0, banks, get_rom_base(), 0x4000); + m_rombank[0]->configure_entries(0, banks, cart_rom_region()->base(), 0x4000); + m_rombank[1]->configure_entries(0, banks, cart_rom_region()->base(), 0x4000); page(1)->install_read_bank(0x4000, 0x7fff, m_rombank[0]); page(1)->install_write_handler(0x4000, 0x4001, write8sm_delegate(*this, FUNC(msx_cart_korean_126in1_device::bank_w))); page(2)->install_read_bank(0x8000, 0xbfff, m_rombank[1]); + + return image_init_result::PASS; } void msx_cart_korean_126in1_device::bank_w(offs_t offset, uint8_t data) diff --git a/src/devices/bus/msx/cart/korean.h b/src/devices/bus/msx/cart/korean.h index 1ca5c6479e4..8f8026478af 100644 --- a/src/devices/bus/msx/cart/korean.h +++ b/src/devices/bus/msx/cart/korean.h @@ -5,7 +5,7 @@ #pragma once -#include "cartridge.h" +#include "bus/msx/slot/cartridge.h" DECLARE_DEVICE_TYPE(MSX_CART_KOREAN_80IN1, msx_cart_korean_80in1_device) @@ -18,7 +18,7 @@ class msx_cart_korean_80in1_device : public device_t, public msx_cart_interface public: msx_cart_korean_80in1_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: // device-level overrides @@ -39,7 +39,7 @@ class msx_cart_korean_90in1_device : public device_t, public msx_cart_interface public: msx_cart_korean_90in1_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: // device-level overrides @@ -60,7 +60,7 @@ class msx_cart_korean_126in1_device : public device_t, public msx_cart_interface public: msx_cart_korean_126in1_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: // device-level overrides diff --git a/src/devices/bus/msx/cart/majutsushi.cpp b/src/devices/bus/msx/cart/majutsushi.cpp index 65ae0bf42c0..8e1c7cfe875 100644 --- a/src/devices/bus/msx/cart/majutsushi.cpp +++ b/src/devices/bus/msx/cart/majutsushi.cpp @@ -24,19 +24,26 @@ void msx_cart_majutsushi_device::device_add_mconfig(machine_config &config) DAC_8BIT_R2R(config, m_dac, 0).add_route(ALL_OUTPUTS, "speaker", 0.05); // unknown DAC } -void msx_cart_majutsushi_device::initialize_cartridge() +image_init_result msx_cart_majutsushi_device::initialize_cartridge(std::string &message) { - if (get_rom_size() != 0x20000) + if (!cart_rom_region()) { - fatalerror("majutsushi: Invalid ROM size\n"); + message = "msx_cart_majutsushi_device: Required region 'rom' was not found."; + return image_init_result::FAIL; + } + + if (cart_rom_region()->bytes() != 0x20000) + { + message = "msx_cart_majutsushi_device: Region 'rom' has unsupported size."; + return image_init_result::FAIL; } for (int i = 0; i < 3; i++) - m_rombank[i]->configure_entries(0, 16, get_rom_base(), 0x2000); + m_rombank[i]->configure_entries(0, 16, cart_rom_region()->base(), 0x2000); - page(0)->install_rom(0x0000, 0x1fff, get_rom_base()); + page(0)->install_rom(0x0000, 0x1fff, cart_rom_region()->base()); page(0)->install_read_bank(0x2000, 0x3fff, m_rombank[0]); - page(1)->install_rom(0x4000, 0x5fff, get_rom_base()); + page(1)->install_rom(0x4000, 0x5fff, cart_rom_region()->base()); page(1)->install_write_handler(0x5000, 0x5000, 0, 0x0fff, 0, write8smo_delegate(m_dac, FUNC(dac_byte_interface::write))); page(1)->install_read_bank(0x6000, 0x7fff, m_rombank[0]); page(1)->install_write_handler(0x6000, 0x6000, 0, 0x1fff, 0, write8smo_delegate(*this, FUNC(msx_cart_majutsushi_device::bank_w<0>))); @@ -46,6 +53,8 @@ void msx_cart_majutsushi_device::initialize_cartridge() page(2)->install_write_handler(0xa000, 0xa000, 0, 0x1fff, 0, write8smo_delegate(*this, FUNC(msx_cart_majutsushi_device::bank_w<2>))); page(3)->install_read_bank(0xc000, 0xdfff, m_rombank[1]); page(3)->install_read_bank(0xe000, 0xffff, m_rombank[2]); + + return image_init_result::PASS; } template diff --git a/src/devices/bus/msx/cart/majutsushi.h b/src/devices/bus/msx/cart/majutsushi.h index 3e400099715..0d3090827e5 100644 --- a/src/devices/bus/msx/cart/majutsushi.h +++ b/src/devices/bus/msx/cart/majutsushi.h @@ -5,7 +5,7 @@ #pragma once -#include "cartridge.h" +#include "bus/msx/slot/cartridge.h" #include "sound/dac.h" @@ -17,7 +17,7 @@ class msx_cart_majutsushi_device : public device_t, public msx_cart_interface public: msx_cart_majutsushi_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: // device-level overrides diff --git a/src/devices/bus/msx/cart/moonsound.h b/src/devices/bus/msx/cart/moonsound.h index 548619ea987..d84c7ea3adf 100644 --- a/src/devices/bus/msx/cart/moonsound.h +++ b/src/devices/bus/msx/cart/moonsound.h @@ -5,7 +5,7 @@ #pragma once -#include "cartridge.h" +#include "bus/msx/slot/cartridge.h" #include "sound/ymopl.h" diff --git a/src/devices/bus/msx/cart/msx_audio.cpp b/src/devices/bus/msx/cart/msx_audio.cpp index 6197832eda7..2ff9580d101 100644 --- a/src/devices/bus/msx/cart/msx_audio.cpp +++ b/src/devices/bus/msx/cart/msx_audio.cpp @@ -98,15 +98,24 @@ void msx_cart_msx_audio_hxmu900_device::device_start() io_space().install_read_handler(0xc0, 0xc1, read8sm_delegate(*m_y8950, FUNC(y8950_device::read))); } -void msx_cart_msx_audio_hxmu900_device::initialize_cartridge() +image_init_result msx_cart_msx_audio_hxmu900_device::initialize_cartridge(std::string &message) { - if (get_rom_size() < 0x8000) + if (!cart_rom_region()) { - fatalerror("msx_audio: Invalid ROM size\n"); + message = "msx_cart_msx_audio_hxmu900_device: Required region 'rom' was not found."; + return image_init_result::FAIL; } - page(1)->install_rom(0x4000, 0x7fff, get_rom_base()); - page(2)->install_rom(0x8000, 0xbfff, get_rom_base() + 0x4000); + if (cart_rom_region()->bytes() < 0x8000) + { + message = "msx_cart_msx_audio_hxmu900_device: Region 'rom' has unsupported size."; + return image_init_result::FAIL; + } + + page(1)->install_rom(0x4000, 0x7fff, cart_rom_region()->base()); + page(2)->install_rom(0x8000, 0xbfff, cart_rom_region()->base() + 0x4000); + + return image_init_result::PASS; } ROM_START(msx_hxmu) @@ -188,14 +197,24 @@ void msx_cart_msx_audio_nms1205_device::device_start() io_space().install_read_handler(0x04, 0x05, read8sm_delegate(*m_acia6850, FUNC(acia6850_device::read))); } -void msx_cart_msx_audio_nms1205_device::initialize_cartridge() +image_init_result msx_cart_msx_audio_nms1205_device::initialize_cartridge(std::string &message) { - if (get_rom_size() < 0x8000) + if (!cart_rom_region()) + { + message = "msx_cart_msx_audio_nms1205_device: Required region 'rom' was not found."; + return image_init_result::FAIL; + } + + if (cart_rom_region()->bytes() < 0x8000) { - fatalerror("msx_audio: Invalid ROM size\n"); + message = "msx_cart_msx_audio_nms1205_device: Region 'rom' has unsupported size."; + return image_init_result::FAIL; } - page(1)->install_rom(0x4000, 0x7fff, get_rom_base()); - page(2)->install_rom(0x8000, 0xbfff, get_rom_base() + 0x4000); + + page(1)->install_rom(0x4000, 0x7fff, cart_rom_region()->base()); + page(2)->install_rom(0x8000, 0xbfff, cart_rom_region()->base() + 0x4000); + + return image_init_result::PASS; } @@ -269,30 +288,39 @@ void msx_cart_msx_audio_fsca1_device::device_reset() m_rombank[1]->set_entry(0); } -void msx_cart_msx_audio_fsca1_device::initialize_cartridge() +image_init_result msx_cart_msx_audio_fsca1_device::initialize_cartridge(std::string &message) { - if (get_rom_size() < 0x20000) + if (!cart_rom_region()) + { + message = "msx_cart_msx_audio_fsca1_device: Required region 'rom' was not found."; + return image_init_result::FAIL; + } + + if (cart_rom_region()->bytes() < 0x20000) { - fatalerror("msx_audio_fsca1: Invalid ROM size\n"); + message = "msx_cart_msx_audio_fsca1_device: Region 'rom' has unsupported size"; + return image_init_result::FAIL; } - m_rombank[0]->configure_entries(0, 4, get_rom_base(), 0x8000); - m_rombank[1]->configure_entries(0, 4, get_rom_base() + 0x4000, 0x8000); + m_rombank[0]->configure_entries(0, 4, cart_rom_region()->base(), 0x8000); + m_rombank[1]->configure_entries(0, 4, cart_rom_region()->base() + 0x4000, 0x8000); page(0)->install_view(0x0000, 0x3fff, m_view0); m_view0[0].install_read_bank(0x0000, 0x3fff, m_rombank[0]); - m_view0[0].install_ram(0x3000, 0x3fff, get_sram_base()); + m_view0[0].install_ram(0x3000, 0x3fff, cart_sram_region()->base()); m_view0[1].install_read_bank(0x0000, 0x3fff, m_rombank[0]); page(1)->install_view(0x4000, 0x7fff, m_view1); m_view1[0].install_read_bank(0x4000, 0x7ffd, m_rombank[1]); - m_view1[0].install_ram(0x7000, 0x7ffd, get_sram_base()); + m_view1[0].install_ram(0x7000, 0x7ffd, cart_sram_region()->base()); m_view1[1].install_read_bank(0x4000, 0x7ffd, m_rombank[1]); page(1)->install_write_handler(0x7ffe, 0x7ffe, write8smo_delegate(*this, FUNC(msx_cart_msx_audio_fsca1_device::bank_w))); page(1)->install_write_handler(0x7fff, 0x7fff, write8smo_delegate(*this, FUNC(msx_cart_msx_audio_fsca1_device::write_7fff))); page(2)->install_read_bank(0x8000, 0xbfff, m_rombank[0]); page(3)->install_read_bank(0xc000, 0xffff, m_rombank[1]); + + return image_init_result::PASS; } void msx_cart_msx_audio_fsca1_device::bank_w(u8 data) diff --git a/src/devices/bus/msx/cart/msx_audio.h b/src/devices/bus/msx/cart/msx_audio.h index c40b7cefdd5..7bd6434d7eb 100644 --- a/src/devices/bus/msx/cart/msx_audio.h +++ b/src/devices/bus/msx/cart/msx_audio.h @@ -5,7 +5,7 @@ #pragma once -#include "cartridge.h" +#include "bus/msx/slot/cartridge.h" #include "sound/ymopl.h" #include "machine/6850acia.h" #include "bus/midi/midi.h" @@ -21,7 +21,7 @@ class msx_cart_msx_audio_hxmu900_device : public device_t, public msx_cart_inter public: msx_cart_msx_audio_hxmu900_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: virtual void device_start() override; @@ -40,7 +40,7 @@ class msx_cart_msx_audio_nms1205_device : public device_t, public msx_cart_inter public: msx_cart_msx_audio_nms1205_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: virtual void device_start() override; @@ -65,7 +65,7 @@ class msx_cart_msx_audio_fsca1_device : public device_t, public msx_cart_interfa public: msx_cart_msx_audio_fsca1_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: virtual void device_start() override; diff --git a/src/devices/bus/msx/cart/msxdos2.cpp b/src/devices/bus/msx/cart/msxdos2.cpp index 1deb7081051..10d92918eb3 100644 --- a/src/devices/bus/msx/cart/msxdos2.cpp +++ b/src/devices/bus/msx/cart/msxdos2.cpp @@ -23,17 +23,26 @@ void msx_cart_msxdos2_device::device_reset() m_rombank->set_entry(1); } -void msx_cart_msxdos2_device::initialize_cartridge() +image_init_result msx_cart_msxdos2_device::initialize_cartridge(std::string &message) { - if (get_rom_size() != 0x10000) + if (!cart_rom_region()) { - fatalerror("msxdos2: Invalid ROM size\n"); + message = "msx_cart_msxdos2_device: Required region 'rom' was not found."; + return image_init_result::FAIL; } - m_rombank->configure_entries(0, 4, get_rom_base(), 0x4000); + if (cart_rom_region()->bytes() != 0x10000) + { + message = "msx_cart_msxdos2_device: Region 'rom' has unsupported size."; + return image_init_result::FAIL; + } + + m_rombank->configure_entries(0, 4, cart_rom_region()->base(), 0x4000); page(1)->install_read_bank(0x4000, 0x7fff, m_rombank); page(1)->install_write_handler(0x7ffe, 0x7ffe, write8smo_delegate(*this, FUNC(msx_cart_msxdos2_device::bank_w))); + + return image_init_result::PASS; } void msx_cart_msxdos2_device::bank_w(u8 data) diff --git a/src/devices/bus/msx/cart/msxdos2.h b/src/devices/bus/msx/cart/msxdos2.h index d515a1e0b7f..6f0212a3da8 100644 --- a/src/devices/bus/msx/cart/msxdos2.h +++ b/src/devices/bus/msx/cart/msxdos2.h @@ -5,7 +5,7 @@ #pragma once -#include "cartridge.h" +#include "bus/msx/slot/cartridge.h" DECLARE_DEVICE_TYPE(MSX_CART_MSXDOS2, msx_cart_msxdos2_device) @@ -16,7 +16,7 @@ class msx_cart_msxdos2_device : public device_t, public msx_cart_interface public: msx_cart_msxdos2_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: // device-level overrides diff --git a/src/devices/bus/msx/cart/nomapper.cpp b/src/devices/bus/msx/cart/nomapper.cpp index ed4676237ca..db1f530a4a6 100644 --- a/src/devices/bus/msx/cart/nomapper.cpp +++ b/src/devices/bus/msx/cart/nomapper.cpp @@ -31,7 +31,7 @@ void msx_cart_nomapper_device::install_memory() { if (page(i)) { - page(i)->install_rom(start_address, std::min(start_address + 0x3fff, m_end_address - 1), get_rom_base() + rom_offset); + page(i)->install_rom(start_address, std::min(start_address + 0x3fff, m_end_address - 1), cart_rom_region()->base() + rom_offset); } rom_offset += 0x4000; start_address += 0x4000; @@ -39,10 +39,16 @@ void msx_cart_nomapper_device::install_memory() } } -void msx_cart_nomapper_device::initialize_cartridge() +image_init_result msx_cart_nomapper_device::initialize_cartridge(std::string &message) { - u32 size = get_rom_size(); - u8 *rom = get_rom_base(); + if (!cart_rom_region()) + { + message = "msx_cart_nomapper_device: Required region 'rom' was not found."; + return image_init_result::FAIL; + } + + const u32 size = cart_rom_region()->bytes(); + u8 *rom = cart_rom_region()->base(); // determine start address, default to 0x4000 m_start_address = 0x4000; @@ -103,4 +109,6 @@ void msx_cart_nomapper_device::initialize_cartridge() m_end_address = std::min(m_start_address + size, 0x10000); install_memory(); + + return image_init_result::PASS; } diff --git a/src/devices/bus/msx/cart/nomapper.h b/src/devices/bus/msx/cart/nomapper.h index fd037c44403..f479216d7ae 100644 --- a/src/devices/bus/msx/cart/nomapper.h +++ b/src/devices/bus/msx/cart/nomapper.h @@ -5,7 +5,7 @@ #pragma once -#include "cartridge.h" +#include "bus/msx/slot/cartridge.h" DECLARE_DEVICE_TYPE(MSX_CART_NOMAPPER, msx_cart_nomapper_device) @@ -19,7 +19,7 @@ public: // device-level overrides virtual void device_start() override { } - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; private: uint32_t m_start_address; diff --git a/src/devices/bus/msx/cart/rtype.cpp b/src/devices/bus/msx/cart/rtype.cpp index affcc4c843d..2fdf17e24ed 100644 --- a/src/devices/bus/msx/cart/rtype.cpp +++ b/src/devices/bus/msx/cart/rtype.cpp @@ -13,18 +13,27 @@ msx_cart_rtype_device::msx_cart_rtype_device(const machine_config &mconfig, cons { } -void msx_cart_rtype_device::initialize_cartridge() +image_init_result msx_cart_rtype_device::initialize_cartridge(std::string &message) { - if (get_rom_size() != 0x80000 && get_rom_size() != 0x60000) + if (!cart_rom_region()) { - fatalerror("rtype: Invalid ROM size\n"); + message = "msx_cart_rtype_device: Required region 'rom' was not found."; + return image_init_result::FAIL; } - m_rombank->configure_entries(0, 24, get_rom_base(), 0x4000); + if (cart_rom_region()->bytes() != 0x80000 && cart_rom_region()->bytes() != 0x60000) + { + message = "msx_cart_rtype_device: Region 'rom' has unsupported size."; + return image_init_result::FAIL; + } - page(1)->install_rom(0x4000, 0x7fff, get_rom_base() + 15 * 0x4000); + m_rombank->configure_entries(0, 24, cart_rom_region()->base(), 0x4000); + + page(1)->install_rom(0x4000, 0x7fff, cart_rom_region()->base() + 15 * 0x4000); page(1)->install_write_handler(0x7000, 0x7fff, write8smo_delegate(*this, FUNC(msx_cart_rtype_device::bank_w))); page(2)->install_read_bank(0x8000, 0xbfff, m_rombank); + + return image_init_result::PASS; } void msx_cart_rtype_device::bank_w(u8 data) diff --git a/src/devices/bus/msx/cart/rtype.h b/src/devices/bus/msx/cart/rtype.h index b82b9db7f27..c844b2ad107 100644 --- a/src/devices/bus/msx/cart/rtype.h +++ b/src/devices/bus/msx/cart/rtype.h @@ -5,7 +5,7 @@ #pragma once -#include "cartridge.h" +#include "bus/msx/slot/cartridge.h" DECLARE_DEVICE_TYPE(MSX_CART_RTYPE, msx_cart_rtype_device) @@ -16,7 +16,7 @@ class msx_cart_rtype_device : public device_t, public msx_cart_interface public: msx_cart_rtype_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: // device-level overrides diff --git a/src/devices/bus/msx/cart/softcard.cpp b/src/devices/bus/msx/cart/softcard.cpp index b5f5583b26d..dccc03097f2 100644 --- a/src/devices/bus/msx/cart/softcard.cpp +++ b/src/devices/bus/msx/cart/softcard.cpp @@ -72,7 +72,12 @@ image_init_result msx_cart_softcard_device::call_load() } } - m_softcard->initialize_cartridge(); + std::string message; + image_init_result result = m_softcard->initialize_cartridge(message); + if (image_init_result::PASS != result) + seterror(image_error::INVALIDIMAGE, message.c_str()); + + return result; } return image_init_result::PASS; } diff --git a/src/devices/bus/msx/cart/softcard.h b/src/devices/bus/msx/cart/softcard.h index 6174b0939a8..cc53184a4cc 100644 --- a/src/devices/bus/msx/cart/softcard.h +++ b/src/devices/bus/msx/cart/softcard.h @@ -5,7 +5,7 @@ #pragma once -#include "cartridge.h" +#include "bus/msx/slot/cartridge.h" #include "imagedev/cartrom.h" @@ -41,7 +41,7 @@ protected: class softcard_interface : public device_interface { public: - virtual void initialize_cartridge() { } + virtual image_init_result initialize_cartridge(std::string &message) { return image_init_result::PASS; } void set_views(memory_view::memory_view_entry *page0, memory_view::memory_view_entry *page1, memory_view::memory_view_entry *page2, memory_view::memory_view_entry *page3); protected: diff --git a/src/devices/bus/msx/cart/super_swangi.cpp b/src/devices/bus/msx/cart/super_swangi.cpp index 61025db82e2..aaf418e0f5f 100644 --- a/src/devices/bus/msx/cart/super_swangi.cpp +++ b/src/devices/bus/msx/cart/super_swangi.cpp @@ -14,18 +14,27 @@ msx_cart_super_swangi_device::msx_cart_super_swangi_device(const machine_config { } -void msx_cart_super_swangi_device::initialize_cartridge() +image_init_result msx_cart_super_swangi_device::initialize_cartridge(std::string &message) { - if (get_rom_size() < 0x10000) + if (!cart_rom_region()) { - fatalerror("super_swangi: Invalid ROM size\n"); + message = "msx_cart_super_swangi_device: Required region 'rom' was not found."; + return image_init_result::FAIL; } - m_rombank->configure_entries(0, 4, get_rom_base(), 0x4000); + if (cart_rom_region()->bytes() < 0x10000) + { + message = "msx_cart_super_swangi_device: Region 'rom' has unsupported size."; + return image_init_result::FAIL; + } - page(1)->install_rom(0x4000, 0x7fff, get_rom_base()); + m_rombank->configure_entries(0, 4, cart_rom_region()->base(), 0x4000); + + page(1)->install_rom(0x4000, 0x7fff, cart_rom_region()->base()); page(2)->install_read_bank(0x8000, 0xbfff, m_rombank); page(2)->install_write_handler(0x8000, 0x8000, write8smo_delegate(*this, FUNC(msx_cart_super_swangi_device::bank_w))); + + return image_init_result::PASS; } void msx_cart_super_swangi_device::bank_w(u8 data) diff --git a/src/devices/bus/msx/cart/super_swangi.h b/src/devices/bus/msx/cart/super_swangi.h index ba6f1fefedd..cbf141bb892 100644 --- a/src/devices/bus/msx/cart/super_swangi.h +++ b/src/devices/bus/msx/cart/super_swangi.h @@ -5,7 +5,7 @@ #pragma once -#include "cartridge.h" +#include "bus/msx/slot/cartridge.h" DECLARE_DEVICE_TYPE(MSX_CART_SUPER_SWANGI, msx_cart_super_swangi_device) @@ -16,7 +16,7 @@ class msx_cart_super_swangi_device : public device_t, public msx_cart_interface public: msx_cart_super_swangi_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: // device-level overrides diff --git a/src/devices/bus/msx/cart/superloderunner.cpp b/src/devices/bus/msx/cart/superloderunner.cpp index 70df5248f4e..23d3ebf44b0 100644 --- a/src/devices/bus/msx/cart/superloderunner.cpp +++ b/src/devices/bus/msx/cart/superloderunner.cpp @@ -19,16 +19,25 @@ void msx_cart_superloderunner_device::device_start() memory_space().install_write_handler(0x0000, 0x0000, write8smo_delegate(*this, FUNC(msx_cart_superloderunner_device::bank_w))); } -void msx_cart_superloderunner_device::initialize_cartridge() +image_init_result msx_cart_superloderunner_device::initialize_cartridge(std::string &message) { - if (get_rom_size() != 0x20000) + if (!cart_rom_region()) { - fatalerror("superloderunner: Invalid ROM size\n"); + message = "msx_cart_superloderunner_device: Required region 'rom' was not found."; + return image_init_result::FAIL; } - m_rombank->configure_entries(0, 8, get_rom_base(), 0x4000); + if (cart_rom_region()->bytes() != 0x20000) + { + message = "msx_cart_superloderunner_device: Region 'rom' has unsupported size."; + return image_init_result::FAIL; + } + + m_rombank->configure_entries(0, 8, cart_rom_region()->base(), 0x4000); page(2)->install_read_bank(0x8000, 0xbfff, m_rombank); + + return image_init_result::PASS; } void msx_cart_superloderunner_device::bank_w(u8 data) diff --git a/src/devices/bus/msx/cart/superloderunner.h b/src/devices/bus/msx/cart/superloderunner.h index 0d41897ea37..a248da9267a 100644 --- a/src/devices/bus/msx/cart/superloderunner.h +++ b/src/devices/bus/msx/cart/superloderunner.h @@ -5,7 +5,7 @@ #pragma once -#include "cartridge.h" +#include "bus/msx/slot/cartridge.h" DECLARE_DEVICE_TYPE(MSX_CART_SUPERLODERUNNER, msx_cart_superloderunner_device) @@ -16,7 +16,7 @@ class msx_cart_superloderunner_device : public device_t, public msx_cart_interfa public: msx_cart_superloderunner_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; protected: // device-level overrides diff --git a/src/devices/bus/msx/cart/yamaha.h b/src/devices/bus/msx/cart/yamaha.h index 00bd49d1960..f5b794dadfd 100644 --- a/src/devices/bus/msx/cart/yamaha.h +++ b/src/devices/bus/msx/cart/yamaha.h @@ -5,7 +5,7 @@ #pragma once -#include "cartridge.h" +#include "bus/msx/slot/cartridge.h" #include "msx_audio_kb.h" #include "sound/ymopm.h" #include "machine/ym2148.h" diff --git a/src/devices/bus/msx/slot/cartridge.cpp b/src/devices/bus/msx/slot/cartridge.cpp index 4d7b81bfb0f..aa9f3c55c90 100644 --- a/src/devices/bus/msx/slot/cartridge.cpp +++ b/src/devices/bus/msx/slot/cartridge.cpp @@ -96,7 +96,6 @@ void msx_slot_cartridge_device::device_resolve_objects() m_cartridge = dynamic_cast(get_card_device()); if (m_cartridge) { - m_cartridge->m_exp = this; m_cartridge->set_views(page(0), page(1), page(2), page(3)); } } @@ -111,44 +110,7 @@ image_init_result msx_slot_cartridge_device::call_load() { if (m_cartridge) { - if (loaded_through_softlist()) - { - // Allocate and copy rom contents - u32 length = get_software_region_length("rom"); - m_cartridge->rom_alloc(length); - if (length > 0) - { - u8 *rom_base = m_cartridge->get_rom_base(); - memcpy(rom_base, get_software_region("rom"), length); - } - - // Allocate and copy vlm5030 rom contents - length = get_software_region_length("vlm5030"); - m_cartridge->rom_vlm5030_alloc(length); - if (length > 0) - { - u8 *rom_base = m_cartridge->get_rom_vlm5030_base(); - memcpy(rom_base, get_software_region("vlm5030"), length); - } - - // Allocate ram - length = get_software_region_length("ram"); - m_cartridge->ram_alloc(length); - - // Allocate sram - length = get_software_region_length("sram"); - m_cartridge->sram_alloc(length); - - // Allocate and copy kanji rom contents - length = get_software_region_length("kanji"); - m_cartridge->kanji_alloc(length); - if (length > 0) - { - u8 *rom_base = m_cartridge->get_kanji_base(); - memcpy(rom_base, get_software_region("kanji"), length); - } - } - else + if (!loaded_through_softlist()) { u32 length = this->length(); @@ -169,11 +131,8 @@ image_init_result msx_slot_cartridge_device::call_load() length_aligned *= 2; } - m_cartridge->rom_alloc(length_aligned); - m_cartridge->ram_alloc(0); - m_cartridge->sram_alloc(0); - - if (fread(m_cartridge->get_rom_base(), length) != length) + memory_region *const romregion = machine().memory().region_alloc(subtag("rom"), length_aligned, 1, ENDIANNESS_LITTLE); + if (fread(romregion->base(), length) != length) { seterror(image_error::UNSPECIFIED, "Unable to fully read file"); return image_init_result::FAIL; @@ -186,12 +145,17 @@ image_init_result msx_slot_cartridge_device::call_load() } } - m_cartridge->m_exp = this; - m_cartridge->initialize_cartridge(); + std::string message; + image_init_result result = m_cartridge->initialize_cartridge(message); + if (image_init_result::PASS != result) + { + seterror(image_error::INVALIDIMAGE, message.c_str()); + return result; + } - if (m_cartridge->get_sram_size() > 0) + if (m_cartridge->cart_sram_region()) { - battery_load(m_cartridge->get_sram_base(), m_cartridge->get_sram_size(), 0x00); + battery_load(m_cartridge->cart_sram_region()->base(), m_cartridge->cart_sram_region()->bytes(), 0x00); } } return image_init_result::PASS; @@ -200,12 +164,9 @@ image_init_result msx_slot_cartridge_device::call_load() void msx_slot_cartridge_device::call_unload() { - if (m_cartridge) + if (m_cartridge && m_cartridge->cart_sram_region()) { - if (m_cartridge->get_sram_size() > 0) - { - battery_save(m_cartridge->get_sram_base(), m_cartridge->get_sram_size()); - } + battery_save(m_cartridge->cart_sram_region()->base(), m_cartridge->cart_sram_region()->bytes()); } } @@ -360,3 +321,40 @@ msx_slot_yamaha_expansion_device::msx_slot_yamaha_expansion_device(const machine void msx_slot_yamaha_expansion_device::device_start() { } + + +msx_cart_interface::msx_cart_interface(const machine_config &mconfig, device_t &device) + : device_interface(device, "msxcart") + , m_exp(dynamic_cast(device.owner())) +{ + for (int i = 0; i < 4; i++) + m_page[i] = nullptr; +} + +WRITE_LINE_MEMBER(msx_cart_interface::irq_out) +{ + m_exp->irq_out(state); +} + +address_space &msx_cart_interface::memory_space() const +{ + return m_exp->memory_space(); +} + +address_space &msx_cart_interface::io_space() const +{ + return m_exp->io_space(); +} + +cpu_device &msx_cart_interface::maincpu() const +{ + return m_exp->maincpu(); +} + +void msx_cart_interface::set_views(memory_view::memory_view_entry *page0, memory_view::memory_view_entry *page1, memory_view::memory_view_entry *page2, memory_view::memory_view_entry *page3) +{ + m_page[0] = page0; + m_page[1] = page1; + m_page[2] = page2; + m_page[3] = page3; +} diff --git a/src/devices/bus/msx/slot/cartridge.h b/src/devices/bus/msx/slot/cartridge.h index 5133899a9f3..736b7b36326 100644 --- a/src/devices/bus/msx/slot/cartridge.h +++ b/src/devices/bus/msx/slot/cartridge.h @@ -14,6 +14,8 @@ DECLARE_DEVICE_TYPE(MSX_SLOT_CARTRIDGE, msx_slot_cartridge_device) DECLARE_DEVICE_TYPE(MSX_SLOT_YAMAHA_EXPANSION, msx_slot_yamaha_expansion_device) +class msx_cart_interface; + class msx_slot_cartridge_device : public device_t , public device_cartrom_image_interface , public device_slot_interface @@ -52,6 +54,7 @@ protected: }; + class msx_slot_yamaha_expansion_device : public msx_slot_cartridge_device { public: @@ -67,4 +70,37 @@ protected: }; + +class msx_cart_interface : public device_interface +{ + friend class msx_slot_cartridge_device; + +public: + // This is called after loading cartridge contents and allows the cartridge + // implementation to perform some additional initialization based on the + // cartridge contents. + virtual image_init_result initialize_cartridge(std::string &message) { return image_init_result::PASS; } + virtual void interface_pre_start() override { assert(m_exp != nullptr); } + + void set_views(memory_view::memory_view_entry *page0, memory_view::memory_view_entry *page1, memory_view::memory_view_entry *page2, memory_view::memory_view_entry *page3); + +protected: + msx_cart_interface(const machine_config &mconfig, device_t &device); + + memory_region *cart_rom_region() { return m_exp ? m_exp->memregion("rom") : nullptr; } + memory_region *cart_vlm5030_region() { return m_exp ? m_exp->memregion("vlm5030") : nullptr; } + memory_region *cart_kanji_region() { return m_exp ? m_exp->memregion("kanji") : nullptr; } + memory_region *cart_ram_region() { return m_exp ? m_exp->memregion("ram") : nullptr; } + memory_region *cart_sram_region() { return m_exp ? m_exp->memregion("sram") : nullptr; } + DECLARE_WRITE_LINE_MEMBER(irq_out); + address_space &memory_space() const; + address_space &io_space() const; + cpu_device &maincpu() const; + memory_view::memory_view_entry *page(int i) { return m_page[i]; } + +private: + msx_slot_cartridge_device *m_exp; + memory_view::memory_view_entry *m_page[4]; +}; + #endif // MAME_BUS_MSX_SLOT_CARTRIDGE_H diff --git a/src/devices/bus/msx/softcard/softcard.cpp b/src/devices/bus/msx/softcard/softcard.cpp index a489749de8a..b9f9a890227 100644 --- a/src/devices/bus/msx/softcard/softcard.cpp +++ b/src/devices/bus/msx/softcard/softcard.cpp @@ -26,7 +26,7 @@ protected: // device-level overrides virtual void device_start() override { } - virtual void initialize_cartridge() override; + virtual image_init_result initialize_cartridge(std::string &message) override; }; @@ -37,16 +37,18 @@ softcard_nomapper_device::softcard_nomapper_device(const machine_config &mconfig { } -void softcard_nomapper_device::initialize_cartridge() +image_init_result softcard_nomapper_device::initialize_cartridge(std::string &message) { if (!cart_rom_region()) { - fatalerror("softcard_nomapper: ROM region not setup\n"); + message = "softcard_nomapper: Required region 'rom' was not found."; + return image_init_result::FAIL; } page(1)->install_rom(0x4000, 0x7fff, cart_rom_region()->base()); page(2)->install_rom(0x8000, 0xbfff, cart_rom_region()->base() + 0x4000); + return image_init_result::PASS; } } // anonymous namespace diff --git a/src/mame/msx/msx.cpp b/src/mame/msx/msx.cpp index 16982bbf811..3f1086e4261 100644 --- a/src/mame/msx/msx.cpp +++ b/src/mame/msx/msx.cpp @@ -26,9 +26,6 @@ ** ** ** Todo/known issues: -** - Get rid of trampolines. -** - Get rid of code duplication between msx_slot and msx_cart (eg, kanji roms, disk interfaces) -** - Use standard game controller slot interface for joystick and mouse ** - general: - Add support for kana lock ** - - Expansion slots not emulated ** - kanji: The direct rom dump from FS-A1FX shows that the kanji font roms are accessed slightly differently. Most -- cgit v1.2.3