diff options
author | 2024-02-25 02:27:26 +1100 | |
---|---|---|
committer | 2024-02-25 02:27:26 +1100 | |
commit | 1615b8551a3a73532ac234973cfb04dd8ed98ba4 (patch) | |
tree | 25575506b4117afa614b94b4370af7f16eb9dbb5 /src/lib/formats/cbm_crt.cpp | |
parent | 334ec12e0043ef939be418283235e3dbe5a005fe (diff) |
util/ioprocs.cpp: Added wrappers for common patterns. (#11608)
emu/diimage.h: Removed fread overloads that allocate memory for output.
util/core_file.cpp: Changed output size of load to size_t.
Diffstat (limited to 'src/lib/formats/cbm_crt.cpp')
-rw-r--r-- | src/lib/formats/cbm_crt.cpp | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/lib/formats/cbm_crt.cpp b/src/lib/formats/cbm_crt.cpp index b088507208f..6bc9e0f8d23 100644 --- a/src/lib/formats/cbm_crt.cpp +++ b/src/lib/formats/cbm_crt.cpp @@ -46,6 +46,8 @@ #include "osdcore.h" // osd_printf_* +#include <tuple> + //************************************************************************** // MACROS/CONSTANTS @@ -137,8 +139,7 @@ std::string cbm_crt_get_card(util::core_file &file) { // read the header cbm_crt_header header; - size_t actual; - std::error_condition err = file.read(&header, CRT_HEADER_LENGTH, actual); + auto const [err, actual] = read(file, &header, CRT_HEADER_LENGTH); if (!err && (CRT_HEADER_LENGTH == actual) && !memcmp(header.signature, CRT_SIGNATURE, 16)) { @@ -157,11 +158,13 @@ std::string cbm_crt_get_card(util::core_file &file) bool cbm_crt_read_header(util::core_file &file, size_t *roml_size, size_t *romh_size, int *exrom, int *game) { + std::error_condition err; size_t actual; // read the header cbm_crt_header header; - if (file.read(&header, CRT_HEADER_LENGTH, actual)) + std::tie(err, actual) = read(file, &header, CRT_HEADER_LENGTH); + if (err) return false; if ((CRT_HEADER_LENGTH != actual) || (memcmp(header.signature, CRT_SIGNATURE, 16) != 0)) @@ -184,7 +187,8 @@ bool cbm_crt_read_header(util::core_file &file, size_t *roml_size, size_t *romh_ while (!file.eof()) { cbm_crt_chip chip; - if (file.read(&chip, CRT_CHIP_LENGTH, actual) || (CRT_CHIP_LENGTH != actual)) + std::tie(err, actual) = read(file, &chip, CRT_CHIP_LENGTH); + if (err || (CRT_CHIP_LENGTH != actual)) return false; const uint16_t address = get_u16be(chip.start_address); @@ -228,21 +232,22 @@ bool cbm_crt_read_data(util::core_file &file, uint8_t *roml, uint8_t *romh) while (!file.eof()) { + std::error_condition err; size_t actual; cbm_crt_chip chip; - if (file.read(&chip, CRT_CHIP_LENGTH, actual) || (CRT_CHIP_LENGTH != actual)) + std::tie(err, actual) = read(file, &chip, CRT_CHIP_LENGTH); + if (err || (CRT_CHIP_LENGTH != actual)) return false; const uint16_t address = get_u16be(chip.start_address); const uint16_t size = get_u16be(chip.image_size); - std::error_condition err; switch (address) { - case 0x8000: err = file.read(roml + roml_offset, size, actual); roml_offset += size; break; - case 0xa000: err = file.read(romh + romh_offset, size, actual); romh_offset += size; break; - case 0xe000: err = file.read(romh + romh_offset, size, actual); romh_offset += size; break; + case 0x8000: std::tie(err, actual) = read(file, roml + roml_offset, size); roml_offset += size; break; + case 0xa000: std::tie(err, actual) = read(file, romh + romh_offset, size); romh_offset += size; break; + case 0xe000: std::tie(err, actual) = read(file, romh + romh_offset, size); romh_offset += size; break; // FIXME: surely one needs to report an error or skip over the data if the load address is not recognised? } if (err) // TODO: check size - all bets are off if the address isn't recognised anyway |