summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/c64/exp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/bus/c64/exp.cpp')
-rw-r--r--src/devices/bus/c64/exp.cpp33
1 files changed, 27 insertions, 6 deletions
diff --git a/src/devices/bus/c64/exp.cpp b/src/devices/bus/c64/exp.cpp
index 93d664e8517..7a53fadbf14 100644
--- a/src/devices/bus/c64/exp.cpp
+++ b/src/devices/bus/c64/exp.cpp
@@ -11,6 +11,8 @@
#include "formats/cbm_crt.h"
+#include <tuple>
+
//**************************************************************************
@@ -97,6 +99,8 @@ void c64_expansion_slot_device::device_reset()
std::pair<std::error_condition, std::string> c64_expansion_slot_device::call_load()
{
+ std::error_condition err;
+
if (m_card)
{
m_card->m_roml_size = 0;
@@ -108,11 +112,16 @@ std::pair<std::error_condition, std::string> c64_expansion_slot_device::call_loa
if (!loaded_through_softlist())
{
+ util::core_file &file = image_core_file();
size = length();
if (is_filetype("80"))
{
- fread(m_card->m_roml, size);
+ std::size_t actual;
+ std::tie(err, m_card->m_roml, actual) = read(file, size);
+ if (!err && (actual != size))
+ err = std::errc::io_error;
+
m_card->m_roml_size = size;
m_card->m_exrom = 0;
@@ -123,7 +132,11 @@ std::pair<std::error_condition, std::string> c64_expansion_slot_device::call_loa
}
else if (is_filetype("a0"))
{
- fread(m_card->m_romh, 0x2000);
+ std::size_t actual;
+ std::tie(err, m_card->m_roml, actual) = read(file, 0x2000);
+ if (!err && (actual != 0x2000))
+ err = std::errc::io_error;
+
m_card->m_romh_size = 0x2000;
m_card->m_exrom = 0;
@@ -131,14 +144,18 @@ std::pair<std::error_condition, std::string> c64_expansion_slot_device::call_loa
}
else if (is_filetype("e0"))
{
- fread(m_card->m_romh, 0x2000);
+ std::size_t actual;
+ std::tie(err, m_card->m_roml, actual) = read(file, 0x2000);
+ if (!err && (actual != 0x2000))
+ err = std::errc::io_error;
+
m_card->m_romh_size = 0x2000;
m_card->m_game = 0;
}
else if (is_filetype("crt"))
{
- if (cbm_crt_read_header(image_core_file(), &m_card->m_roml_size, &m_card->m_romh_size, &m_card->m_exrom, &m_card->m_game))
+ if (cbm_crt_read_header(file, &m_card->m_roml_size, &m_card->m_romh_size, &m_card->m_exrom, &m_card->m_game))
{
uint8_t *roml = nullptr;
uint8_t *romh = nullptr;
@@ -149,9 +166,13 @@ std::pair<std::error_condition, std::string> c64_expansion_slot_device::call_loa
if (m_card->m_roml_size) roml = m_card->m_roml.get();
if (m_card->m_romh_size) romh = m_card->m_romh.get();
- cbm_crt_read_data(image_core_file(), roml, romh);
+ cbm_crt_read_data(file, roml, romh);
}
}
+ else
+ {
+ err = image_error::INVALIDIMAGE;
+ }
}
else
{
@@ -187,7 +208,7 @@ std::pair<std::error_condition, std::string> c64_expansion_slot_device::call_loa
return std::make_pair(image_error::INVALIDLENGTH, "ROM size must be power of 2");
}
- return std::make_pair(std::error_condition(), std::string());
+ return std::make_pair(err, std::string());
}