diff options
author | 2023-09-16 20:35:42 -0400 | |
---|---|---|
committer | 2023-09-16 20:36:49 -0400 | |
commit | be3919035b45458b47c335914a80d3b31bf7f43c (patch) | |
tree | fd05abc1657cd7c13b14c4e3299554a45897239b /src | |
parent | 102aa77cccaf030fac6ec1d934f69a692c02b67a (diff) |
acorn/z88_impexp.cpp, nascom/nascom1.cpp: Modernize file I/O
Diffstat (limited to 'src')
-rw-r--r-- | src/mame/acorn/z88_impexp.cpp | 13 | ||||
-rw-r--r-- | src/mame/nascom/nascom1.cpp | 19 |
2 files changed, 23 insertions, 9 deletions
diff --git a/src/mame/acorn/z88_impexp.cpp b/src/mame/acorn/z88_impexp.cpp index 214767746dd..bd712c875af 100644 --- a/src/mame/acorn/z88_impexp.cpp +++ b/src/mame/acorn/z88_impexp.cpp @@ -176,11 +176,16 @@ std::pair<std::error_condition, std::string> z88_impexp_device::call_load() // file data m_queue.push(0x1b); m_queue.push('F'); - while (!image_feof()) + + util::core_file &file = image_core_file(); + std::error_condition err; + while (true) { + size_t actual; uint8_t b; - if (fread(&b, 1) != 1) - return std::make_pair(image_error::UNSPECIFIED, std::string()); + err = file.read(&b, 1, actual); + if (err || actual != 1) + break; // Escape non printable characters if ((b < 0x20 || b >= 0x7f) && b != 0x0a && b != 0x0d && b != 0x09) @@ -205,7 +210,7 @@ std::pair<std::error_condition, std::string> z88_impexp_device::call_load() m_queue.push('E'); queue(); - return std::make_pair(std::error_condition(), std::string()); + return std::make_pair(err, std::string()); } diff --git a/src/mame/nascom/nascom1.cpp b/src/mame/nascom/nascom1.cpp index 6bba0de3df6..d1e50e3ccd1 100644 --- a/src/mame/nascom/nascom1.cpp +++ b/src/mame/nascom/nascom1.cpp @@ -319,9 +319,12 @@ TIMER_DEVICE_CALLBACK_MEMBER( nascom2_state::nascom2_kansas_r ) template<int Dest> SNAPSHOT_LOAD_MEMBER(nascom_state::snapshot_cb) { + util::core_file &file = image.image_core_file(); uint8_t line[29]; - while (image.fread(&line, sizeof(line)) == sizeof(line)) + std::error_condition err; + size_t actual; + while (!(err = file.read(&line, sizeof(line), actual)) && actual == sizeof(line)) { unsigned int addr, b[8], dummy; @@ -346,13 +349,15 @@ SNAPSHOT_LOAD_MEMBER(nascom_state::snapshot_cb) return std::make_pair(image_error::INVALIDIMAGE, "Unsupported file format"); } dummy = 0x00; - while (!image.image_feof() && dummy != 0x0a && dummy != 0x1f) + while (dummy != 0x0a && dummy != 0x1f) { - image.fread(&dummy, 1); + err = file.read(&dummy, 1, actual); + if (err || actual != 1) + return std::make_pair(err, std::string()); } } - return std::make_pair(std::error_condition(), std::string()); + return std::make_pair(err, std::string()); } @@ -372,7 +377,11 @@ std::pair<std::error_condition, std::string> nascom2_state::load_cart( return std::make_pair(image_error::INVALIDLENGTH, "Unsupported image file size (must be no more than 4K)"); slot->rom_alloc(slot->length(), GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE); - slot->fread(slot->get_rom_base(), slot->length()); + + size_t actual; + std::error_condition const err = slot->image_core_file().read(slot->get_rom_base(), slot->length(), actual); + if (err || actual != slot->length()) + return std::make_pair(err ? err : std::errc::io_error, std::string()); // we just assume that socket1 should be loaded to 0xc000 and socket2 to 0xd000 switch (slot_id) |