diff options
Diffstat (limited to 'src/devices/bus')
39 files changed, 113 insertions, 111 deletions
diff --git a/src/devices/bus/a7800/a78_slot.cpp b/src/devices/bus/a7800/a78_slot.cpp index 4a7392fc3f6..d55412058d1 100644 --- a/src/devices/bus/a7800/a78_slot.cpp +++ b/src/devices/bus/a7800/a78_slot.cpp @@ -491,7 +491,7 @@ image_verify_result a78_cart_slot_device::verify_header(char *header) if (strncmp(magic, header + 1, 9)) { logerror("Not a valid A7800 image\n"); - seterror(IMAGE_ERROR_UNSPECIFIED, "File is not a valid A7800 image"); + seterror(image_error::INVALIDIMAGE, "File is not a valid A7800 image"); return image_verify_result::FAIL; } diff --git a/src/devices/bus/acorn/system/8k.cpp b/src/devices/bus/acorn/system/8k.cpp index ecbd69c930f..b2e1c7bb3d2 100644 --- a/src/devices/bus/acorn/system/8k.cpp +++ b/src/devices/bus/acorn/system/8k.cpp @@ -144,7 +144,7 @@ image_init_result acorn_8k_device::load_rom(device_image_interface &image, gener // socket accepts 2K and 4K ROM only if (size != 0x0800 && size != 0x1000) { - image.seterror(IMAGE_ERROR_UNSPECIFIED, "Invalid size: Only 2K/4K is supported"); + image.seterror(image_error::INVALIDIMAGE, "Invalid size: Only 2K/4K is supported"); return image_init_result::FAIL; } diff --git a/src/devices/bus/apf/slot.cpp b/src/devices/bus/apf/slot.cpp index 0d44530a8b6..c43738fae2a 100644 --- a/src/devices/bus/apf/slot.cpp +++ b/src/devices/bus/apf/slot.cpp @@ -152,7 +152,7 @@ image_init_result apf_cart_slot_device::call_load() if (size > 0x3800) { - seterror(IMAGE_ERROR_UNSPECIFIED, "Image extends beyond the expected size for an APF cart"); + seterror(image_error::INVALIDIMAGE, "Image extends beyond the expected size for an APF cart"); return image_init_result::FAIL; } diff --git a/src/devices/bus/aquarius/slot.cpp b/src/devices/bus/aquarius/slot.cpp index 825e03f39d5..88be36900f4 100644 --- a/src/devices/bus/aquarius/slot.cpp +++ b/src/devices/bus/aquarius/slot.cpp @@ -91,7 +91,7 @@ image_init_result aquarius_cartridge_slot_device::call_load() if (size % 0x1000) { - seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid ROM size"); + seterror(image_error::INVALIDIMAGE, "Invalid ROM size"); return image_init_result::FAIL; } diff --git a/src/devices/bus/ata/idehd.cpp b/src/devices/bus/ata/idehd.cpp index 15a079963de..dd1a8f932ec 100644 --- a/src/devices/bus/ata/idehd.cpp +++ b/src/devices/bus/ata/idehd.cpp @@ -838,7 +838,7 @@ void ide_hdd_device::device_reset() // build the features page uint32_t metalength; - if (m_handle && m_handle->read_metadata (HARD_DISK_IDENT_METADATA_TAG, 0, &m_buffer[0], 512, metalength) == CHDERR_NONE) + if (m_handle && !m_handle->read_metadata(HARD_DISK_IDENT_METADATA_TAG, 0, &m_buffer[0], 512, metalength)) { for( int w = 0; w < 256; w++ ) { diff --git a/src/devices/bus/bbc/1mhzbus/datacentre.cpp b/src/devices/bus/bbc/1mhzbus/datacentre.cpp index 05ba11a3bab..f21d5af1d54 100644 --- a/src/devices/bus/bbc/1mhzbus/datacentre.cpp +++ b/src/devices/bus/bbc/1mhzbus/datacentre.cpp @@ -328,7 +328,7 @@ QUICKLOAD_LOAD_MEMBER(bbc_datacentre_device::quickload_cb) } else { - image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid filetype, must be SSD, DSD, or IMG"); + image.seterror(image_error::INVALIDIMAGE, "Invalid filetype, must be SSD, DSD, or IMG"); return image_init_result::FAIL; } diff --git a/src/devices/bus/bbc/rom/slot.cpp b/src/devices/bus/bbc/rom/slot.cpp index 8a315e12234..65acb920bca 100644 --- a/src/devices/bus/bbc/rom/slot.cpp +++ b/src/devices/bus/bbc/rom/slot.cpp @@ -122,7 +122,7 @@ image_init_result bbc_romslot_device::call_load() if (size % 0x2000) { - seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid ROM size"); + seterror(image_error::INVALIDIMAGE, "Invalid ROM size"); return image_init_result::FAIL; } diff --git a/src/devices/bus/c64/exp.cpp b/src/devices/bus/c64/exp.cpp index e4cc42f61d8..cf20f18fe45 100644 --- a/src/devices/bus/c64/exp.cpp +++ b/src/devices/bus/c64/exp.cpp @@ -191,7 +191,7 @@ image_init_result c64_expansion_slot_device::call_load() if ((m_card->m_roml_size & (m_card->m_roml_size - 1)) || (m_card->m_romh_size & (m_card->m_romh_size - 1))) { - seterror(IMAGE_ERROR_UNSPECIFIED, "ROM size must be power of 2"); + seterror(image_error::INVALIDIMAGE, "ROM size must be power of 2"); return image_init_result::FAIL; } } diff --git a/src/devices/bus/cgenie/expansion/floppy.cpp b/src/devices/bus/cgenie/expansion/floppy.cpp index b6f0a9c30ac..ee914179d10 100644 --- a/src/devices/bus/cgenie/expansion/floppy.cpp +++ b/src/devices/bus/cgenie/expansion/floppy.cpp @@ -181,7 +181,7 @@ DEVICE_IMAGE_LOAD_MEMBER( cgenie_fdc_device::socket_load ) if (size > 0x1000) { - image.seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported ROM size"); + image.seterror(image_error::INVALIDIMAGE, "Unsupported ROM size"); return image_init_result::FAIL; } diff --git a/src/devices/bus/coco/coco_dwsock.cpp b/src/devices/bus/coco/coco_dwsock.cpp index b970458c91c..a69ac57b4c4 100644 --- a/src/devices/bus/coco/coco_dwsock.cpp +++ b/src/devices/bus/coco/coco_dwsock.cpp @@ -82,18 +82,14 @@ beckerport_device::~beckerport_device() void beckerport_device::device_start() { - char chAddress[64]; - - /* format address string for opening the port */ - snprintf(chAddress, sizeof(chAddress), "socket.%s:%d", m_hostname, m_dwtcpport); - - osd_printf_verbose("Connecting to Drivewire server on %s:%d... ", m_hostname, m_dwtcpport); + osd_printf_verbose("%s: Connecting to Drivewire server on %s:%d... ", tag(), m_hostname, m_dwtcpport); u64 filesize; // unused - osd_file::error filerr = osd_file::open(chAddress, 0, m_pSocket, filesize); - if (filerr != osd_file::error::NONE) + /* format address string for opening the port */ + std::error_condition filerr = osd_file::open(util::string_format("socket.%s:%d", m_hostname, m_dwtcpport), 0, m_pSocket, filesize); + if (filerr) { - osd_printf_verbose("Error: osd_open returned error %i!\n", (int) filerr); + osd_printf_verbose("Error: osd_open returned error %s:%d %s!\n", filerr.category().name(), filerr.value(), filerr.message()); return; } @@ -108,7 +104,7 @@ void beckerport_device::device_stop() { if (m_pSocket) { - printf("Closing connection to Drivewire server\n"); + printf("%s: Closing connection to Drivewire server\n", tag()); m_pSocket.reset(); } } @@ -140,23 +136,24 @@ u8 beckerport_device::read(offs_t offset) if (!m_rx_pending) { /* Try to read from dws */ - osd_file::error filerr = m_pSocket->read(m_buf, 0, sizeof(m_buf), m_rx_pending); - if (filerr != osd_file::error::NONE && filerr != osd_file::error::FAILURE) // osd_file::error::FAILURE means no data available, so don't throw error message - fprintf(stderr, "coco_dwsock.c: beckerport_device::read() socket read operation failed with osd_file::error %i\n", int(filerr)); + std::error_condition filerr = m_pSocket->read(m_buf, 0, sizeof(m_buf), m_rx_pending); + if (filerr) + osd_printf_error("%s: coco_dwsock.c: beckerport_device::read() socket read operation failed with error %s:%d %s\n", tag(), filerr.category().name(), filerr.value(), filerr.message()); else m_head = 0; } - //printf("beckerport_device: status read. %i bytes remaining.\n", m_rx_pending); + //logerror("beckerport_device: status read. %i bytes remaining.\n", m_rx_pending); data = (m_rx_pending > 0) ? 2 : 0; break; case DWS_DATA: - if (!m_rx_pending) { - fprintf(stderr, "coco_dwsock.c: beckerport_device::read() buffer underrun\n"); + if (!m_rx_pending) + { + osd_printf_error("%s: coco_dwsock.c: beckerport_device::read() buffer underrun\n", tag()); break; } data = m_buf[m_head++]; m_rx_pending--; - //printf("beckerport_device: data read 1 byte (0x%02x). %i bytes remaining.\n", data&0xff, m_rx_pending); + //logerror("beckerport_device: data read 1 byte (0x%02x). %i bytes remaining.\n", data&0xff, m_rx_pending); break; default: fprintf(stderr, "%s: read from bad offset %d\n", __FILE__, offset); @@ -172,7 +169,7 @@ u8 beckerport_device::read(offs_t offset) void beckerport_device::write(offs_t offset, u8 data) { char d = char(data); - osd_file::error filerr; + std::error_condition filerr; u32 written; if (!m_pSocket) @@ -181,13 +178,13 @@ void beckerport_device::write(offs_t offset, u8 data) switch (offset) { case DWS_STATUS: - //printf("beckerport_write: error: write (0x%02x) to status register\n", d); + //logerror("beckerport_write: error: write (0x%02x) to status register\n", d); break; case DWS_DATA: filerr = m_pSocket->write(&d, 0, 1, written); - if (filerr != osd_file::error::NONE) - fprintf(stderr, "coco_dwsock.c: beckerport_device::write() socket write operation failed with osd_file::error %i\n", int(filerr)); - //printf("beckerport_write: data write one byte (0x%02x)\n", d & 0xff); + if (filerr) + osd_printf_error("%s: coco_dwsock.c: beckerport_device::write() socket write operation failed with error %s:%d %s\n", tag(), filerr.category().name(), filerr.value(), filerr.message()); + //logerror("beckerport_write: data write one byte (0x%02x)\n", d & 0xff); break; default: fprintf(stderr, "%s: write to bad offset %d\n", __FILE__, offset); diff --git a/src/devices/bus/crvision/slot.cpp b/src/devices/bus/crvision/slot.cpp index ecab87796e4..ce1e2a5ea1e 100644 --- a/src/devices/bus/crvision/slot.cpp +++ b/src/devices/bus/crvision/slot.cpp @@ -145,7 +145,7 @@ image_init_result crvision_cart_slot_device::call_load() if (size > 0x4800) { - seterror(IMAGE_ERROR_UNSPECIFIED, "Image extends beyond the expected size for an APF cart"); + seterror(image_error::INVALIDIMAGE, "Image extends beyond the expected size for an APF cart"); return image_init_result::FAIL; } diff --git a/src/devices/bus/electron/cart/ap5.cpp b/src/devices/bus/electron/cart/ap5.cpp index cc4c951a154..90c4188d7b1 100644 --- a/src/devices/bus/electron/cart/ap5.cpp +++ b/src/devices/bus/electron/cart/ap5.cpp @@ -161,7 +161,7 @@ image_init_result electron_ap5_device::load_rom(device_image_interface &image, g // socket accepts 8K and 16K ROM only if (size != 0x2000 && size != 0x4000) { - image.seterror(IMAGE_ERROR_UNSPECIFIED, "Invalid size: Only 8K/16K is supported"); + image.seterror(image_error::INVALIDIMAGE, "Invalid size: Only 8K/16K is supported"); return image_init_result::FAIL; } diff --git a/src/devices/bus/electron/cart/romp144.cpp b/src/devices/bus/electron/cart/romp144.cpp index de947454fd8..8bdeab7cc34 100644 --- a/src/devices/bus/electron/cart/romp144.cpp +++ b/src/devices/bus/electron/cart/romp144.cpp @@ -147,7 +147,7 @@ image_init_result electron_romp144_device::load_rom(device_image_interface &imag // socket accepts 8K and 16K ROM only if (size != 0x2000 && size != 0x4000) { - image.seterror(IMAGE_ERROR_UNSPECIFIED, "Invalid size: Only 8K/16K is supported"); + image.seterror(image_error::INVALIDIMAGE, "Invalid size: Only 8K/16K is supported"); return image_init_result::FAIL; } diff --git a/src/devices/bus/electron/cart/slot.cpp b/src/devices/bus/electron/cart/slot.cpp index 489cb567c4d..342cd3ae4f8 100644 --- a/src/devices/bus/electron/cart/slot.cpp +++ b/src/devices/bus/electron/cart/slot.cpp @@ -132,7 +132,7 @@ image_init_result electron_cartslot_device::call_load() if (size % 0x2000) { - seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size"); + seterror(image_error::INVALIDIMAGE, "Unsupported cartridge size"); return image_init_result::FAIL; } @@ -152,7 +152,7 @@ image_init_result electron_cartslot_device::call_load() if ((upsize % 0x2000 && upsize != 0) || (losize % 0x2000 && losize != 0) || (romsize % 0x2000 && romsize != 0)) { - seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size"); + seterror(image_error::INVALIDIMAGE, "Unsupported cartridge size"); return image_init_result::FAIL; } diff --git a/src/devices/bus/electron/plus1.cpp b/src/devices/bus/electron/plus1.cpp index 5bf61578b2b..4b2c3ba9dad 100644 --- a/src/devices/bus/electron/plus1.cpp +++ b/src/devices/bus/electron/plus1.cpp @@ -522,7 +522,7 @@ image_init_result electron_ap6_device::load_rom(device_image_interface &image, g // socket accepts 8K and 16K ROM only if (size != 0x2000 && size != 0x4000) { - image.seterror(IMAGE_ERROR_UNSPECIFIED, "Invalid size: Only 8K/16K is supported"); + image.seterror(image_error::INVALIDIMAGE, "Invalid size: Only 8K/16K is supported"); return image_init_result::FAIL; } diff --git a/src/devices/bus/electron/plus2.cpp b/src/devices/bus/electron/plus2.cpp index d379f053047..82e75bd6030 100644 --- a/src/devices/bus/electron/plus2.cpp +++ b/src/devices/bus/electron/plus2.cpp @@ -231,7 +231,7 @@ image_init_result electron_plus2_device::load_rom(device_image_interface &image, // socket accepts 8K and 16K ROM only if (size != 0x2000 && size != 0x4000) { - image.seterror(IMAGE_ERROR_UNSPECIFIED, "Invalid size: Only 8K/16K is supported"); + image.seterror(image_error::INVALIDIMAGE, "Invalid size: Only 8K/16K is supported"); return image_init_result::FAIL; } diff --git a/src/devices/bus/electron/rombox.cpp b/src/devices/bus/electron/rombox.cpp index 920419c2d66..47040271e7f 100644 --- a/src/devices/bus/electron/rombox.cpp +++ b/src/devices/bus/electron/rombox.cpp @@ -185,7 +185,7 @@ image_init_result electron_rombox_device::load_rom(device_image_interface &image // socket accepts 8K and 16K ROM only if (size != 0x2000 && size != 0x4000) { - image.seterror(IMAGE_ERROR_UNSPECIFIED, "Invalid size: Only 8K/16K is supported"); + image.seterror(image_error::INVALIDIMAGE, "Invalid size: Only 8K/16K is supported"); return image_init_result::FAIL; } diff --git a/src/devices/bus/electron/romboxp.cpp b/src/devices/bus/electron/romboxp.cpp index e6cfd472989..59d83bc4121 100644 --- a/src/devices/bus/electron/romboxp.cpp +++ b/src/devices/bus/electron/romboxp.cpp @@ -328,7 +328,7 @@ image_init_result electron_romboxp_device::load_rom(device_image_interface &imag // socket accepts 8K and 16K ROM only if (size != 0x2000 && size != 0x4000) { - image.seterror(IMAGE_ERROR_UNSPECIFIED, "Invalid size: Only 8K/16K is supported"); + image.seterror(image_error::INVALIDIMAGE, "Invalid size: Only 8K/16K is supported"); return image_init_result::FAIL; } diff --git a/src/devices/bus/electron/sidewndr.cpp b/src/devices/bus/electron/sidewndr.cpp index e66ac800f3c..a2ab8011b09 100644 --- a/src/devices/bus/electron/sidewndr.cpp +++ b/src/devices/bus/electron/sidewndr.cpp @@ -174,7 +174,7 @@ image_init_result electron_sidewndr_device::load_rom(device_image_interface &ima // socket accepts 8K and 16K ROM only if (size != 0x2000 && size != 0x4000) { - image.seterror(IMAGE_ERROR_UNSPECIFIED, "Invalid size: Only 8K/16K is supported"); + image.seterror(image_error::INVALIDIMAGE, "Invalid size: Only 8K/16K is supported"); return image_init_result::FAIL; } diff --git a/src/devices/bus/gamate/slot.cpp b/src/devices/bus/gamate/slot.cpp index 625e4103482..3f98a30927d 100644 --- a/src/devices/bus/gamate/slot.cpp +++ b/src/devices/bus/gamate/slot.cpp @@ -134,7 +134,7 @@ image_init_result gamate_cart_slot_device::call_load() if (len > 0x80000) { - seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size"); + seterror(image_error::INVALIDIMAGE, "Unsupported cartridge size"); return image_init_result::FAIL; } diff --git a/src/devices/bus/gameboy/gb_slot.cpp b/src/devices/bus/gameboy/gb_slot.cpp index a408b9d15ff..79708f95314 100644 --- a/src/devices/bus/gameboy/gb_slot.cpp +++ b/src/devices/bus/gameboy/gb_slot.cpp @@ -267,7 +267,7 @@ image_init_result gb_cart_slot_device_base::call_load() /* Verify that the file contains 16kb blocks */ if ((len == 0) || ((len % 0x4000) != 0)) { - seterror(IMAGE_ERROR_UNSPECIFIED, "Invalid rom file size\n"); + seterror(image_error::INVALIDIMAGE, "Invalid ROM file size\n"); return image_init_result::FAIL; } } diff --git a/src/devices/bus/gba/gba_slot.cpp b/src/devices/bus/gba/gba_slot.cpp index 06ec379cf77..ac036718e2d 100644 --- a/src/devices/bus/gba/gba_slot.cpp +++ b/src/devices/bus/gba/gba_slot.cpp @@ -625,7 +625,7 @@ image_init_result gba_cart_slot_device::call_load() uint32_t size = loaded_through_softlist() ? get_software_region_length("rom") : length(); if (size > 0x4000000) { - seterror(IMAGE_ERROR_UNSPECIFIED, "Attempted loading a cart larger than 64MB"); + seterror(image_error::INVALIDIMAGE, "Attempted loading a cart larger than 64MB"); return image_init_result::FAIL; } diff --git a/src/devices/bus/isa/sc499.cpp b/src/devices/bus/isa/sc499.cpp index c313dd84148..bc942ede9e8 100644 --- a/src/devices/bus/isa/sc499.cpp +++ b/src/devices/bus/isa/sc499.cpp @@ -16,7 +16,7 @@ #include "emu.h" #include "sc499.h" -#include "formats/ioprocs.h" + #define VERBOSE 0 @@ -1310,18 +1310,17 @@ void sc499_ctape_image_device::write_block(int block_num, uint8_t *ptr) image_init_result sc499_ctape_image_device::call_load() { - uint32_t size; - io_generic io; - io.file = (device_image_interface *)this; - io.procs = &image_ioprocs; - io.filler = 0xff; - - size = io_generic_size(&io); - m_ctape_data.resize(size); - - io_generic_read(&io, &m_ctape_data[0], 0, size); - - return image_init_result::PASS; + try + { + auto const size = length(); + m_ctape_data.resize(size); + if (!fseek(0, SEEK_SET) && (fread(m_ctape_data.data(), size) == size)) + return image_init_result::PASS; + } + catch (...) + { + } + return image_init_result::FAIL; } void sc499_ctape_image_device::call_unload() diff --git a/src/devices/bus/m5/slot.cpp b/src/devices/bus/m5/slot.cpp index a1b9d551b23..a75599bb807 100644 --- a/src/devices/bus/m5/slot.cpp +++ b/src/devices/bus/m5/slot.cpp @@ -166,7 +166,7 @@ image_init_result m5_cart_slot_device::call_load() if (size > 0x5000 && m_type == M5_STD) { - seterror(IMAGE_ERROR_UNSPECIFIED, "Image extends beyond the expected size for an M5 cart"); + seterror(image_error::INVALIDIMAGE, "Image extends beyond the expected size for an M5 cart"); return image_init_result::FAIL; } diff --git a/src/devices/bus/mc10/mc10_cart.cpp b/src/devices/bus/mc10/mc10_cart.cpp index e8addd9939a..088b3ca8c81 100644 --- a/src/devices/bus/mc10/mc10_cart.cpp +++ b/src/devices/bus/mc10/mc10_cart.cpp @@ -96,14 +96,14 @@ image_init_result mc10cart_slot_device::call_load() memory_region *romregion(loaded_through_softlist() ? memregion("rom") : nullptr); if (loaded_through_softlist() && !romregion) { - seterror(IMAGE_ERROR_INVALIDIMAGE, "Software list item has no 'rom' data area"); + seterror(image_error::INVALIDIMAGE, "Software list item has no 'rom' data area"); return image_init_result::FAIL; } u32 const len(loaded_through_softlist() ? romregion->bytes() : length()); if (len > m_cart->max_rom_length()) { - seterror(IMAGE_ERROR_UNSUPPORTED, "Unsupported cartridge size"); + seterror(image_error::INVALIDIMAGE, "Unsupported cartridge size"); return image_init_result::FAIL; } @@ -114,7 +114,7 @@ image_init_result mc10cart_slot_device::call_load() u32 const cnt(fread(romregion->base(), len)); if (cnt != len) { - seterror(IMAGE_ERROR_UNSPECIFIED, "Error reading cartridge file"); + seterror(image_error::UNSPECIFIED, "Error reading cartridge file"); return image_init_result::FAIL; } } diff --git a/src/devices/bus/msx_slot/cartridge.cpp b/src/devices/bus/msx_slot/cartridge.cpp index 87b89f93c78..30c9f0a2b00 100644 --- a/src/devices/bus/msx_slot/cartridge.cpp +++ b/src/devices/bus/msx_slot/cartridge.cpp @@ -165,7 +165,7 @@ image_init_result msx_slot_cartridge_device::call_load() if (fread(m_cartridge->get_rom_base(), length) != length) { - seterror(IMAGE_ERROR_UNSPECIFIED, "Unable to fully read file"); + seterror(image_error::UNSPECIFIED, "Unable to fully read file"); return image_init_result::FAIL; } diff --git a/src/devices/bus/nes/nes_slot.cpp b/src/devices/bus/nes/nes_slot.cpp index 812aa738399..f75694bd041 100644 --- a/src/devices/bus/nes/nes_slot.cpp +++ b/src/devices/bus/nes/nes_slot.cpp @@ -887,7 +887,7 @@ image_init_result nes_cart_slot_device::call_load() else { logerror("%s is NOT a file in either iNES or UNIF format.\n", filename()); - seterror(IMAGE_ERROR_UNSPECIFIED, "File is neither iNES or UNIF format"); + seterror(image_error::INVALIDIMAGE, "File is neither iNES or UNIF format"); return image_init_result::FAIL; } } diff --git a/src/devices/bus/nubus/nubus_image.cpp b/src/devices/bus/nubus/nubus_image.cpp index 8c94882cd4f..80875c6bd41 100644 --- a/src/devices/bus/nubus/nubus_image.cpp +++ b/src/devices/bus/nubus/nubus_image.cpp @@ -295,8 +295,9 @@ void nubus_image_device::file_cmd_w(uint32_t data) std::string fullpath(filectx.curdir); fullpath += PATH_SEPARATOR; fullpath.append(std::begin(filectx.filename), std::find(std::begin(filectx.filename), std::end(filectx.filename), '\0')); - if (osd_file::open(fullpath, OPEN_FLAG_READ, filectx.fd, filectx.filelen) != osd_file::error::NONE) - osd_printf_error("Error opening %s\n", fullpath); + std::error_condition const filerr = osd_file::open(fullpath, OPEN_FLAG_READ, filectx.fd, filectx.filelen); + if (filerr) + osd_printf_error("%s: Error opening %s (%s:%d %s)\n", tag(), fullpath, filerr.category().name(), filerr.value(), filerr.message()); filectx.bytecount = 0; } break; @@ -306,8 +307,9 @@ void nubus_image_device::file_cmd_w(uint32_t data) fullpath += PATH_SEPARATOR; fullpath.append(std::begin(filectx.filename), std::find(std::begin(filectx.filename), std::end(filectx.filename), '\0')); uint64_t filesize; // unused, but it's an output from the open call - if (osd_file::open(fullpath, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, filectx.fd, filesize) != osd_file::error::NONE) - osd_printf_error("Error opening %s\n", fullpath); + std::error_condition const filerr = osd_file::open(fullpath, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, filectx.fd, filesize); + if (filerr) + osd_printf_error("%s: Error opening %s (%s:%d %s)\n", tag(), fullpath, filerr.category().name(), filerr.value(), filerr.message()); filectx.bytecount = 0; } break; diff --git a/src/devices/bus/plus4/exp.cpp b/src/devices/bus/plus4/exp.cpp index fb0387908ef..487de7ea3c2 100644 --- a/src/devices/bus/plus4/exp.cpp +++ b/src/devices/bus/plus4/exp.cpp @@ -118,7 +118,7 @@ image_init_result plus4_expansion_slot_device::call_load() if ((m_card->m_c1l_size & (m_card->m_c1l_size - 1)) || (m_card->m_c1h_size & (m_card->m_c1h_size - 1)) || (m_card->m_c2l_size & (m_card->m_c2l_size - 1)) || (m_card->m_c2h_size & (m_card->m_c2h_size - 1))) { - seterror(IMAGE_ERROR_UNSPECIFIED, "ROM size must be power of 2"); + seterror(image_error::INVALIDIMAGE, "ROM size must be power of 2"); return image_init_result::FAIL; } } diff --git a/src/devices/bus/scv/slot.cpp b/src/devices/bus/scv/slot.cpp index 65081801f30..86dc2d810c1 100644 --- a/src/devices/bus/scv/slot.cpp +++ b/src/devices/bus/scv/slot.cpp @@ -157,7 +157,7 @@ image_init_result scv_cart_slot_device::call_load() if (len > 0x20000) { - seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size"); + seterror(image_error::INVALIDIMAGE, "Unsupported cartridge size"); return image_init_result::FAIL; } diff --git a/src/devices/bus/sega8/sega8_slot.cpp b/src/devices/bus/sega8/sega8_slot.cpp index 8330fc68915..8a998e71bf0 100644 --- a/src/devices/bus/sega8/sega8_slot.cpp +++ b/src/devices/bus/sega8/sega8_slot.cpp @@ -397,7 +397,7 @@ image_init_result sega8_cart_slot_device::call_load() if (m_is_card && len > 0x8000) { - seterror(IMAGE_ERROR_UNSPECIFIED, "Attempted loading a card larger than 32KB"); + seterror(image_error::INVALIDIMAGE, "Attempted loading a card larger than 32KB"); return image_init_result::FAIL; } diff --git a/src/devices/bus/spectrum/intf2.cpp b/src/devices/bus/spectrum/intf2.cpp index 7442dfe49a9..afce2005a99 100644 --- a/src/devices/bus/spectrum/intf2.cpp +++ b/src/devices/bus/spectrum/intf2.cpp @@ -99,7 +99,7 @@ DEVICE_IMAGE_LOAD_MEMBER(spectrum_intf2_device::cart_load) if (size != 0x4000) { - image.seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size"); + image.seterror(image_error::INVALIDIMAGE, "Unsupported cartridge size"); return image_init_result::FAIL; } diff --git a/src/devices/bus/ti99/gromport/cartridges.cpp b/src/devices/bus/ti99/gromport/cartridges.cpp index 20831395a0c..2f5a558d29b 100644 --- a/src/devices/bus/ti99/gromport/cartridges.cpp +++ b/src/devices/bus/ti99/gromport/cartridges.cpp @@ -16,6 +16,10 @@ #include "cartridges.h" #include "corestr.h" +#include "ioprocs.h" +#include "unzip.h" +#include "xmlfile.h" + #define LOG_WARN (1U<<1) // Warnings #define LOG_CONFIG (1U<<2) // Configuration @@ -260,14 +264,14 @@ image_init_result ti99_cartridge_device::call_load() auto reader = std::make_unique<rpk_reader>(pcbdefs); try { - m_rpk = reader->open(machine().options(), filename(), machine().system().name); + m_rpk = reader->open(machine().options(), image_core_file(), machine().system().name); m_pcbtype = m_rpk->get_type(); } catch (rpk_exception& err) { LOGMASKED(LOG_WARN, "Failed to load cartridge '%s': %s\n", basename(), err.to_string().c_str()); m_rpk = nullptr; - m_err = IMAGE_ERROR_INVALIDIMAGE; + m_err = image_error::INVALIDIMAGE; return image_init_result::FAIL; } } @@ -1553,8 +1557,8 @@ void ti99_cartridge_device::rpk::close() throw emu_fatalerror("ti99_cartridge_device::rpk::close: Buffer is null or length is 0"); emu_file file(m_options.nvram_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); - osd_file::error filerr = file.open(socket.second->get_pathname()); - if (filerr == osd_file::error::NONE) + std::error_condition const filerr = file.open(socket.second->get_pathname()); + if (!filerr) file.write(socket.second->get_contents(), socket.second->get_content_length()); } @@ -1641,8 +1645,8 @@ std::unique_ptr<ti99_cartridge_device::rpk_socket> ti99_cartridge_device::rpk_re catch (std::bad_alloc const &) { throw rpk_exception(RPK_OUT_OF_MEMORY); } // and unzip file from the zip file - util::archive_file::error ziperr = zip.decompress(contents.get(), length); - if (ziperr != util::archive_file::error::NONE) + std::error_condition const ziperr = zip.decompress(contents.get(), length); + if (ziperr) { if (ziperr == util::archive_file::error::UNSUPPORTED) throw rpk_exception(RPK_ZIP_UNSUPPORTED); else throw rpk_exception(RPK_ZIP_ERROR); @@ -1727,9 +1731,9 @@ std::unique_ptr<ti99_cartridge_device::rpk_socket> ti99_cartridge_device::rpk_re // try to open the battery file and read it if possible emu_file file(options.nvram_directory(), OPEN_FLAG_READ); - osd_file::error filerr = file.open(ram_pname); + std::error_condition const filerr = file.open(ram_pname); int bytes_read = 0; - if (filerr == osd_file::error::NONE) + if (!filerr) bytes_read = file.read(contents.get(), length); // fill remaining bytes (if necessary) @@ -1747,33 +1751,30 @@ std::unique_ptr<ti99_cartridge_device::rpk_socket> ti99_cartridge_device::rpk_re system_name - name of the driver (also just for NVRAM handling) -------------------------------------------------*/ -ti99_cartridge_device::rpk* ti99_cartridge_device::rpk_reader::open(emu_options &options, const char *filename, const char *system_name) +ti99_cartridge_device::rpk* ti99_cartridge_device::rpk_reader::open(emu_options &options, util::core_file &file, const char *system_name) { - util::archive_file::error ziperr; - - util::archive_file::ptr zipfile; - - std::vector<char> layout_text; - - int i; - auto newrpk = new rpk(options, system_name); try { - /* open the ZIP file */ - ziperr = util::archive_file::open_zip(filename, zipfile); - if (ziperr != util::archive_file::error::NONE) throw rpk_exception(RPK_NOT_ZIP_FORMAT); + // open the ZIP file + auto reader = util::core_file_read(file); + if (!reader) throw rpk_exception(RPK_OUT_OF_MEMORY); + + std::error_condition ziperr; + util::archive_file::ptr zipfile; + ziperr = util::archive_file::open_zip(std::move(reader), zipfile); + if (ziperr) throw rpk_exception(RPK_NOT_ZIP_FORMAT); - /* find the layout.xml file */ + // find the layout.xml file if (find_file(*zipfile, "layout.xml", 0) < 0) throw rpk_exception(RPK_MISSING_LAYOUT); - /* reserve space for the layout file contents (+1 for the termination) */ - layout_text.resize(zipfile->current_uncompressed_length() + 1); + // reserve space for the layout file contents (+1 for the termination) + std::vector<char> layout_text(zipfile->current_uncompressed_length() + 1); - /* uncompress the layout text */ + // uncompress the layout text ziperr = zipfile->decompress(&layout_text[0], zipfile->current_uncompressed_length()); - if (ziperr != util::archive_file::error::NONE) + if (ziperr) { if (ziperr == util::archive_file::error::UNSUPPORTED) throw rpk_exception(RPK_ZIP_UNSUPPORTED); else throw rpk_exception(RPK_ZIP_ERROR); @@ -1781,7 +1782,7 @@ ti99_cartridge_device::rpk* ti99_cartridge_device::rpk_reader::open(emu_options layout_text[zipfile->current_uncompressed_length()] = '\0'; // Null-terminate - /* parse the layout text */ + // parse the layout text util::xml::file::ptr const layout_xml = util::xml::file::string_read(&layout_text[0], nullptr); if (!layout_xml) throw rpk_exception(RPK_XML_ERROR); @@ -1808,7 +1809,7 @@ ti99_cartridge_device::rpk* ti99_cartridge_device::rpk_reader::open(emu_options if (!pcb_type) throw rpk_exception(RPK_INVALID_LAYOUT, "<pcb> must have a 'type' attribute"); LOGMASKED(LOG_RPK, "[RPK handler] Cartridge says it has PCB type '%s'\n", *pcb_type); - i=0; + int i=0; do { if (*pcb_type == m_types[i].name) diff --git a/src/devices/bus/ti99/gromport/cartridges.h b/src/devices/bus/ti99/gromport/cartridges.h index db2de6b2672..df94321a5f9 100644 --- a/src/devices/bus/ti99/gromport/cartridges.h +++ b/src/devices/bus/ti99/gromport/cartridges.h @@ -8,12 +8,15 @@ #pragma once -#include "emuopts.h" +#include "gromport.h" + #include "machine/tmc0430.h" + +#include "emuopts.h" #include "softlist_dev.h" -#include "gromport.h" -#include "unzip.h" -#include "xmlfile.h" + +#include "utilfwd.h" + namespace bus::ti99::gromport { @@ -137,7 +140,7 @@ private: public: rpk_reader(const pcb_type *types) : m_types(types) { } - rpk *open(emu_options &options, const char *filename, const char *system_name); + rpk *open(emu_options &options, util::core_file &file, const char *system_name); private: int find_file(util::archive_file &zip, const char *filename, uint32_t crc); diff --git a/src/devices/bus/vboy/slot.cpp b/src/devices/bus/vboy/slot.cpp index 083c0db745b..70dd9e05063 100644 --- a/src/devices/bus/vboy/slot.cpp +++ b/src/devices/bus/vboy/slot.cpp @@ -54,14 +54,14 @@ image_init_result vboy_cart_slot_device::call_load() memory_region *romregion(loaded_through_softlist() ? memregion("rom") : nullptr); if (loaded_through_softlist() && !romregion) { - seterror(IMAGE_ERROR_INVALIDIMAGE, "Software list item has no 'rom' data area"); + seterror(image_error::INVALIDIMAGE, "Software list item has no 'rom' data area"); return image_init_result::FAIL; } u32 const len(loaded_through_softlist() ? romregion->bytes() : length()); if ((0x0000'0003 & len) || (0x0100'0000 < len)) { - seterror(IMAGE_ERROR_UNSUPPORTED, "Unsupported cartridge size (must be a multiple of 4 bytes no larger than 16 MiB)"); + seterror(image_error::INVALIDIMAGE, "Unsupported cartridge size (must be a multiple of 4 bytes no larger than 16 MiB)"); return image_init_result::FAIL; } @@ -72,7 +72,7 @@ image_init_result vboy_cart_slot_device::call_load() u32 const cnt(fread(romregion->base(), len)); if (cnt != len) { - seterror(IMAGE_ERROR_UNSPECIFIED, "Error reading cartridge file"); + seterror(image_error::UNSPECIFIED, "Error reading cartridge file"); return image_init_result::FAIL; } } diff --git a/src/devices/bus/vc4000/slot.cpp b/src/devices/bus/vc4000/slot.cpp index f33e5623639..8de01177448 100644 --- a/src/devices/bus/vc4000/slot.cpp +++ b/src/devices/bus/vc4000/slot.cpp @@ -176,7 +176,7 @@ image_init_result vc4000_cart_slot_device::call_load() if (size > 0x1800) { - seterror(IMAGE_ERROR_UNSPECIFIED, "Image extends beyond the expected size for a VC4000 cart"); + seterror(image_error::INVALIDIMAGE, "Image extends beyond the expected size for a VC4000 cart"); return image_init_result::FAIL; } diff --git a/src/devices/bus/vcs/vcs_slot.cpp b/src/devices/bus/vcs/vcs_slot.cpp index 28d402322d5..5efcc4ba32d 100644 --- a/src/devices/bus/vcs/vcs_slot.cpp +++ b/src/devices/bus/vcs/vcs_slot.cpp @@ -200,7 +200,7 @@ image_init_result vcs_cart_slot_device::call_load() break; default: - seterror(IMAGE_ERROR_UNSUPPORTED, "Invalid rom file size" ); + seterror(image_error::INVALIDIMAGE, "Invalid ROM file size" ); return image_init_result::FAIL; } diff --git a/src/devices/bus/vectrex/slot.cpp b/src/devices/bus/vectrex/slot.cpp index 014b6c9516c..9e3ebd14fa6 100644 --- a/src/devices/bus/vectrex/slot.cpp +++ b/src/devices/bus/vectrex/slot.cpp @@ -145,7 +145,7 @@ image_init_result vectrex_cart_slot_device::call_load() if (size > 0x10000) { - seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size"); + seterror(image_error::INVALIDIMAGE, "Unsupported cartridge size"); return image_init_result::FAIL; } @@ -160,7 +160,7 @@ image_init_result vectrex_cart_slot_device::call_load() // Verify the file is accepted by the Vectrex bios if (memcmp(ROM, "g GCE", 5)) { - seterror(IMAGE_ERROR_UNSPECIFIED, "Invalid image"); + seterror(image_error::INVALIDIMAGE, "Invalid image"); return image_init_result::FAIL; } diff --git a/src/devices/bus/vsmile/vsmile_slot.cpp b/src/devices/bus/vsmile/vsmile_slot.cpp index 59f039c685d..9c2906826c9 100644 --- a/src/devices/bus/vsmile/vsmile_slot.cpp +++ b/src/devices/bus/vsmile/vsmile_slot.cpp @@ -139,7 +139,7 @@ image_init_result vsmile_cart_slot_device::call_load() uint32_t size = loaded_through_softlist() ? get_software_region_length("rom") : length(); if (size > 0x1000000) { - seterror(IMAGE_ERROR_UNSPECIFIED, "Attempted loading a cart larger than 16MB"); + seterror(image_error::INVALIDIMAGE, "Attempted loading a cart larger than 16MB"); return image_init_result::FAIL; } |