diff options
Diffstat (limited to 'src/devices/bus/vic10/exp.cpp')
-rw-r--r-- | src/devices/bus/vic10/exp.cpp | 102 |
1 files changed, 38 insertions, 64 deletions
diff --git a/src/devices/bus/vic10/exp.cpp b/src/devices/bus/vic10/exp.cpp index 26ad1980448..2e050b40cc3 100644 --- a/src/devices/bus/vic10/exp.cpp +++ b/src/devices/bus/vic10/exp.cpp @@ -7,9 +7,11 @@ **********************************************************************/ #include "emu.h" -#include "emuopts.h" #include "exp.h" +#include "formats/cbm_crt.h" + +#include <tuple> //************************************************************************** @@ -28,11 +30,8 @@ DEFINE_DEVICE_TYPE(VIC10_EXPANSION_SLOT, vic10_expansion_slot_device, "vic10_exp // device_vic10_expansion_card_interface - constructor //------------------------------------------------- -device_vic10_expansion_card_interface::device_vic10_expansion_card_interface(const machine_config &mconfig, device_t &device) - : device_slot_card_interface(mconfig,device), - m_lorom(*this, "lorom"), - m_exram(*this, "exram"), - m_uprom(*this, "uprom") +device_vic10_expansion_card_interface::device_vic10_expansion_card_interface(const machine_config &mconfig, device_t &device) : + device_interface(device, "vic10exp") { m_slot = dynamic_cast<vic10_expansion_slot_device *>(device.owner()); } @@ -58,8 +57,8 @@ device_vic10_expansion_card_interface::~device_vic10_expansion_card_interface() vic10_expansion_slot_device::vic10_expansion_slot_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : device_t(mconfig, VIC10_EXPANSION_SLOT, tag, owner, clock), - device_slot_interface(mconfig, *this), - device_image_interface(mconfig, *this), + device_single_card_slot_interface<device_vic10_expansion_card_interface>(mconfig, *this), + device_cartrom_image_interface(mconfig, *this), m_write_irq(*this), m_write_res(*this), m_write_cnt(*this), @@ -70,50 +69,12 @@ vic10_expansion_slot_device::vic10_expansion_slot_device(const machine_config &m //------------------------------------------------- -// device_validity_check - -//------------------------------------------------- - -void vic10_expansion_slot_device::device_validity_check(validity_checker &valid) const -{ - device_t *const carddev = get_card_device(); - if (carddev && !dynamic_cast<device_vic10_expansion_card_interface *>(carddev)) - osd_printf_error("Card device %s (%s) does not implement device_vic10_expansion_card_interface\n", carddev->tag(), carddev->name()); -} - - -//------------------------------------------------- // device_start - device-specific startup //------------------------------------------------- void vic10_expansion_slot_device::device_start() { - device_t *const carddev = get_card_device(); - m_card = dynamic_cast<device_vic10_expansion_card_interface *>(carddev); - if (carddev && !m_card) - fatalerror("Card device %s (%s) does not implement device_vic10_expansion_card_interface\n", carddev->tag(), carddev->name()); - - // resolve callbacks - m_write_irq.resolve_safe(); - m_write_res.resolve_safe(); - m_write_cnt.resolve_safe(); - m_write_sp.resolve_safe(); - - // inherit bus clock - if (clock() == 0) - { - vic10_expansion_slot_device *root = machine().device<vic10_expansion_slot_device>(VIC10_EXPANSION_SLOT_TAG); - assert(root); - set_unscaled_clock(root->clock()); - } -} - - -//------------------------------------------------- -// device_reset - device-specific reset -//------------------------------------------------- - -void vic10_expansion_slot_device::device_reset() -{ + m_card = get_card_device(); } @@ -121,28 +82,37 @@ void vic10_expansion_slot_device::device_reset() // call_load - //------------------------------------------------- -image_init_result vic10_expansion_slot_device::call_load() +std::pair<std::error_condition, std::string> vic10_expansion_slot_device::call_load() { + std::error_condition err; + if (m_card) { - size_t size; - if (!loaded_through_softlist()) { - size = length(); + util::core_file &file = image_core_file(); + size_t const size = length(); if (is_filetype("80")) { - fread(m_card->m_lorom, 0x2000); + size_t actual; + std::tie(err, m_card->m_lorom, actual) = read(file, 0x2000); + if (!err && (actual != 0x2000)) + err = std::errc::io_error; - if (size == 0x4000) + if (!err && (size == 0x4000)) { - fread(m_card->m_uprom, 0x2000); + std::tie(err, m_card->m_uprom, actual) = read(file, 0x2000); + if (!err && (actual != 0x2000)) + err = std::errc::io_error; } } else if (is_filetype("e0")) { - fread(m_card->m_uprom, size); + size_t actual; + std::tie(err, m_card->m_uprom, actual) = read(file, size); + if (!err && (actual != size)) + err = std::errc::io_error; } else if (is_filetype("crt")) { @@ -151,20 +121,24 @@ image_init_result vic10_expansion_slot_device::call_load() int exrom = 1; int game = 1; - if (cbm_crt_read_header(image_core_file(), &roml_size, &romh_size, &exrom, &game)) + if (cbm_crt_read_header(file, &roml_size, &romh_size, &exrom, &game)) { uint8_t *roml = nullptr; uint8_t *romh = nullptr; - m_card->m_lorom.allocate(roml_size); - m_card->m_uprom.allocate(romh_size); + m_card->m_lorom = std::make_unique<uint8_t[]>(roml_size); + m_card->m_uprom = std::make_unique<uint8_t[]>(romh_size); - if (roml_size) roml = m_card->m_lorom; - if (romh_size) romh = m_card->m_lorom; + if (roml_size) roml = m_card->m_lorom.get(); + if (romh_size) romh = m_card->m_lorom.get(); - cbm_crt_read_data(image_core_file(), roml, romh); + cbm_crt_read_data(file, roml, romh); } } + else + { + err = image_error::INVALIDIMAGE; + } } else { @@ -174,7 +148,7 @@ image_init_result vic10_expansion_slot_device::call_load() } } - return image_init_result::PASS; + return std::make_pair(err, std::string()); } @@ -221,8 +195,8 @@ void vic10_expansion_slot_device::cd_w(offs_t offset, uint8_t data, int lorom, i } } -READ_LINE_MEMBER( vic10_expansion_slot_device::p0_r ) { int state = 0; if (m_card != nullptr) state = m_card->vic10_p0_r(); return state; } -WRITE_LINE_MEMBER( vic10_expansion_slot_device::p0_w ) { if (m_card != nullptr) m_card->vic10_p0_w(state); } +int vic10_expansion_slot_device::p0_r() { int state = 0; if (m_card != nullptr) state = m_card->vic10_p0_r(); return state; } +void vic10_expansion_slot_device::p0_w(int state) { if (m_card != nullptr) m_card->vic10_p0_w(state); } //------------------------------------------------- |