diff options
Diffstat (limited to 'src/emu/diimage.h')
-rw-r--r-- | src/emu/diimage.h | 82 |
1 files changed, 69 insertions, 13 deletions
diff --git a/src/emu/diimage.h b/src/emu/diimage.h index 6e5f74d7484..67d20c43402 100644 --- a/src/emu/diimage.h +++ b/src/emu/diimage.h @@ -156,37 +156,93 @@ public: void message(const char *format, ...) ATTR_PRINTF(2,3); bool exists() const noexcept { return !m_image_name.empty(); } + + // get image file path/name const char *filename() const noexcept { return m_image_name.empty() ? nullptr : m_image_name.c_str(); } const char *basename() const noexcept { return m_basename.empty() ? nullptr : m_basename.c_str(); } const char *basename_noext() const noexcept { return m_basename_noext.empty() ? nullptr : m_basename_noext.c_str(); } const std::string &filetype() const noexcept { return m_filetype; } bool is_filetype(std::string_view candidate_filetype) const; + bool is_open() const noexcept { return bool(m_file); } util::core_file &image_core_file() const noexcept { return *m_file; } - u64 length() { check_for_file(); return m_file->size(); } bool is_readonly() const noexcept { return m_readonly; } - u32 fread(void *buffer, u32 length) { check_for_file(); return m_file->read(buffer, length); } - u32 fread(std::unique_ptr<u8[]> &ptr, u32 length) { ptr = std::make_unique<u8[]>(length); return fread(ptr.get(), length); } - u32 fread(std::unique_ptr<u8[]> &ptr, u32 length, offs_t offset) { ptr = std::make_unique<u8[]>(length); return fread(ptr.get() + offset, length - offset); } - u32 fwrite(const void *buffer, u32 length) { check_for_file(); return m_file->write(buffer, length); } - int fseek(s64 offset, int whence) { check_for_file(); return m_file->seek(offset, whence); } - u64 ftell() { check_for_file(); return m_file->tell(); } - int fgetc() { char ch; if (fread(&ch, 1) != 1) ch = '\0'; return ch; } - char *fgets(char *buffer, u32 length) { check_for_file(); return m_file->gets(buffer, length); } - int image_feof() { check_for_file(); return m_file->eof(); } - void *ptr() { check_for_file(); return const_cast<void *>(m_file->buffer()); } - // configuration access + // image file I/O wrappers + // TODO: move away from using these and let implementations use the I/O interface directly + // FIXME: don't swallow errors + u64 length() + { + check_for_file(); + u64 result = 0; + m_file->length(result); + return result; + } + u32 fread(void *buffer, u32 length) + { + check_for_file(); + size_t actual; + m_file->read(buffer, length, actual); + return actual; + } + u32 fwrite(const void *buffer, u32 length) + { + check_for_file(); + size_t actual; + m_file->write(buffer, length, actual); + return actual; + } + std::error_condition fseek(s64 offset, int whence) + { + check_for_file(); + return m_file->seek(offset, whence); + } + u64 ftell() + { + check_for_file(); + u64 result = 0; + m_file->tell(result); + return result; + } + int fgetc() + { + char ch; + if (fread(&ch, 1) != 1) + ch = '\0'; + return ch; + } + char *fgets(char *buffer, u32 length) + { + check_for_file(); + return m_file->gets(buffer, length); + } + bool image_feof() + { + check_for_file(); + return m_file->eof(); + } + const void *ptr() + { + check_for_file(); + return m_file->buffer(); + } + + // allocate and read into buffers + u32 fread(std::unique_ptr<u8 []> &ptr, u32 length) { ptr = std::make_unique<u8 []>(length); return fread(ptr.get(), length); } + u32 fread(std::unique_ptr<u8 []> &ptr, u32 length, offs_t offset) { ptr = std::make_unique<u8 []>(length); return fread(ptr.get() + offset, length - offset); } + + // access to software list item information const software_info *software_entry() const noexcept; const software_part *part_entry() const noexcept { return m_software_part_ptr; } const char *software_list_name() const noexcept { return m_software_list_name.c_str(); } bool loaded_through_softlist() const noexcept { return m_software_part_ptr != nullptr; } + // working directory void set_working_directory(std::string_view working_directory) { m_working_directory = working_directory; } - void set_working_directory(const char *working_directory) { m_working_directory = working_directory; } void set_working_directory(std::string &&working_directory) { m_working_directory = std::move(working_directory); } const std::string &working_directory() const { return m_working_directory; } + // access to software list properties and ROM data areas u8 *get_software_region(const char *tag); u32 get_software_region_length(const char *tag); const char *get_feature(const char *feature_name) const; |