From d71c72ba746503934102788e5dcbb487c6134396 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Fri, 29 Sep 2023 01:56:51 +1000 Subject: Miscellaneous change roll-up: render/drawbgfx.cpp: Return an error if Wayland EGL surface can't be created for additional windows. emu/emucore.h: Added explicitly defaulted copy and move constructors for emu_fatalerror. Fixed apparent misunderstanding of const. Returning const value types and casting to const value types is pointless outside very narrow use cases. Putting const value type parameters in interfaces just makes trouble. cpu/adsp2100: Use count_leading_ones_32 where it's simple rather than inverting and counting leading zeroes. util/multibyte.h: Don't pollute global namespace, constexpr implies inline, make narrowing casts explicit. imagedev/simh_tape_image.h: inline is implied for member functions with bodies supplied at declaration. Tidied up some ugly casts in various places. --- docs/source/index.rst | 2 +- src/devices/cpu/adsp2100/2100ops.hxx | 4 +- src/devices/imagedev/simh_tape_image.h | 4 +- src/devices/machine/smc91c9x.cpp | 3 +- src/emu/emucore.h | 2 + src/lib/formats/dmk_dsk.cpp | 2 +- src/lib/formats/td0_dsk.cpp | 2 +- src/lib/util/multibyte.h | 280 ++++++++++++++++----------------- src/lib/util/simh_tape_file.cpp | 174 ++++++++++---------- src/lib/util/simh_tape_file.h | 62 ++++---- src/lib/util/tape_file_interface.h | 40 ++--- src/osd/modules/render/drawbgfx.cpp | 58 ++++--- src/tools/imgtool/modules/fat.cpp | 42 ++--- src/tools/imgtool/modules/os9.cpp | 10 +- src/tools/imgtool/modules/pc_flop.cpp | 8 +- 15 files changed, 346 insertions(+), 347 deletions(-) diff --git a/docs/source/index.rst b/docs/source/index.rst index e1d6cb2960b..e2e54a4ee2b 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -11,7 +11,7 @@ MAME Documentation ================== .. note:: - This documentation is a work in progress. You can track the status of these topics through MAME's `issue tracker `_. Learn how you can `contribute `_. + This documentation is a work in progress. You can track the status of these topics through MAME's `issue tracker `_. Learn how you can :ref:`contribute `. .. toctree:: :titlesonly: diff --git a/src/devices/cpu/adsp2100/2100ops.hxx b/src/devices/cpu/adsp2100/2100ops.hxx index bd2df9acce6..be8f4524a7a 100644 --- a/src/devices/cpu/adsp2100/2100ops.hxx +++ b/src/devices/cpu/adsp2100/2100ops.hxx @@ -2097,7 +2097,7 @@ void adsp21xx_device::shift_op(uint32_t op) if (xop < 0) { SET_SS; - res = count_leading_zeros_32(~xop) - 16 - 1; + res = count_leading_ones_32(xop) - 16 - 1; } else { @@ -2120,7 +2120,7 @@ void adsp21xx_device::shift_op(uint32_t op) if (xop < 0) { SET_SS; - res = count_leading_zeros_32(~xop) - 16 - 1; + res = count_leading_ones_32(xop) - 16 - 1; } else { diff --git a/src/devices/imagedev/simh_tape_image.h b/src/devices/imagedev/simh_tape_image.h index 95f1c70b2e3..cb98056b837 100644 --- a/src/devices/imagedev/simh_tape_image.h +++ b/src/devices/imagedev/simh_tape_image.h @@ -30,8 +30,8 @@ public: virtual void call_unload() override; // miscellaneous - inline void set_interface(const char *interface) { m_interface = interface; } - inline simh_tape_file *get_file() const { return m_file.get(); } + void set_interface(const char *interface) { m_interface = interface; } + simh_tape_file *get_file() const { return m_file.get(); } protected: // construction diff --git a/src/devices/machine/smc91c9x.cpp b/src/devices/machine/smc91c9x.cpp index a27c1f7d281..e237d186b95 100644 --- a/src/devices/machine/smc91c9x.cpp +++ b/src/devices/machine/smc91c9x.cpp @@ -12,8 +12,9 @@ #include "smc91c9x.h" #include "multibyte.h" -#include + #include +#include /*************************************************************************** DEBUGGING diff --git a/src/emu/emucore.h b/src/emu/emucore.h index d87ea5ca3af..ca54f5208cd 100644 --- a/src/emu/emucore.h +++ b/src/emu/emucore.h @@ -228,6 +228,8 @@ class emu_exception : public std::exception { }; class emu_fatalerror : public emu_exception { public: + emu_fatalerror(emu_fatalerror const &) = default; + emu_fatalerror(emu_fatalerror &&) = default; emu_fatalerror(util::format_argument_pack const &args); emu_fatalerror(int _exitcode, util::format_argument_pack const &args); diff --git a/src/lib/formats/dmk_dsk.cpp b/src/lib/formats/dmk_dsk.cpp index 0af637076a0..6517ba9c273 100644 --- a/src/lib/formats/dmk_dsk.cpp +++ b/src/lib/formats/dmk_dsk.cpp @@ -15,8 +15,8 @@ TODO: #include "dmk_dsk.h" #include "coretmpl.h" -#include "multibyte.h" #include "ioprocs.h" +#include "multibyte.h" namespace { diff --git a/src/lib/formats/td0_dsk.cpp b/src/lib/formats/td0_dsk.cpp index 65dd42f47ca..079a1768c25 100644 --- a/src/lib/formats/td0_dsk.cpp +++ b/src/lib/formats/td0_dsk.cpp @@ -849,7 +849,7 @@ bool td0_format::load(util::random_read &io, uint32_t form_factor, const std::ve uint64_t image_size; if(io.length(image_size)) return false; - if(io.read_at(12, &imagebuf[0], image_size - 12, actual) || actual != image_size - 12) + if(io.read_at(12, &imagebuf[0], image_size - 12, actual) || actual != (image_size - 12)) return false; } diff --git a/src/lib/util/multibyte.h b/src/lib/util/multibyte.h index 706361d9df5..6af34de83ed 100644 --- a/src/lib/util/multibyte.h +++ b/src/lib/util/multibyte.h @@ -1,163 +1,153 @@ // license:BSD-3-Clause // copyright-holders:Mietek Bak - -#ifndef MAME_LIB_UTIL_MULTIBYTE_H -#define MAME_LIB_UTIL_MULTIBYTE_H +#ifndef MAME_UTIL_MULTIBYTE_H +#define MAME_UTIL_MULTIBYTE_H #pragma once #include "coretmpl.h" #include "osdcomm.h" -using osd::u8; -using osd::u16; -using osd::u32; -using osd::u64; -using osd::s8; -using osd::s16; -using osd::s32; -using osd::s64; - ////////////////////////////////////////////////////////////////////////////// // unsigned big-endian -inline constexpr u16 get_u16be(const u8 *const buf) noexcept +constexpr osd::u16 get_u16be(osd::u8 const *buf) noexcept { - return ((const u16)buf[0] << 8) - | ((const u16)buf[1] << 0); + return (osd::u16(buf[0]) << 8) + | (osd::u16(buf[1]) << 0); } -inline constexpr u32 get_u24be(const u8 *const buf) noexcept +constexpr osd::u32 get_u24be(osd::u8 const *buf) noexcept { - return ((const u32)buf[0] << 16) - | ((const u32)buf[1] << 8) - | ((const u32)buf[2] << 0); + return (osd::u32(buf[0]) << 16) + | (osd::u32(buf[1]) << 8) + | (osd::u32(buf[2]) << 0); } -inline constexpr u32 get_u32be(const u8 *const buf) noexcept +constexpr osd::u32 get_u32be(osd::u8 const *buf) noexcept { - return ((const u32)buf[0] << 24) - | ((const u32)buf[1] << 16) - | ((const u32)buf[2] << 8) - | ((const u32)buf[3] << 0); + return (osd::u32(buf[0]) << 24) + | (osd::u32(buf[1]) << 16) + | (osd::u32(buf[2]) << 8) + | (osd::u32(buf[3]) << 0); } -inline constexpr u64 get_u48be(const u8 *const buf) noexcept +constexpr osd::u64 get_u48be(osd::u8 const *buf) noexcept { - return ((const u64)buf[0] << 40) - | ((const u64)buf[1] << 32) - | ((const u64)buf[2] << 24) - | ((const u64)buf[3] << 16) - | ((const u64)buf[4] << 8) - | ((const u64)buf[5] << 0); + return (osd::u64(buf[0]) << 40) + | (osd::u64(buf[1]) << 32) + | (osd::u64(buf[2]) << 24) + | (osd::u64(buf[3]) << 16) + | (osd::u64(buf[4]) << 8) + | (osd::u64(buf[5]) << 0); } -inline constexpr u64 get_u64be(const u8 *const buf) noexcept +constexpr osd::u64 get_u64be(osd::u8 const *buf) noexcept { - return ((const u64)buf[0] << 56) - | ((const u64)buf[1] << 48) - | ((const u64)buf[2] << 40) - | ((const u64)buf[3] << 32) - | ((const u64)buf[4] << 24) - | ((const u64)buf[5] << 16) - | ((const u64)buf[6] << 8) - | ((const u64)buf[7] << 0); + return (osd::u64(buf[0]) << 56) + | (osd::u64(buf[1]) << 48) + | (osd::u64(buf[2]) << 40) + | (osd::u64(buf[3]) << 32) + | (osd::u64(buf[4]) << 24) + | (osd::u64(buf[5]) << 16) + | (osd::u64(buf[6]) << 8) + | (osd::u64(buf[7]) << 0); } -inline void put_u16be(u8 *buf, const u16 data) noexcept +inline void put_u16be(osd::u8 *buf, osd::u16 data) noexcept { - buf[0] = data >> 8; - buf[1] = data >> 0; + buf[0] = osd::u8(data >> 8); + buf[1] = osd::u8(data >> 0); } -inline void put_u24be(u8 *buf, const u32 data) noexcept +inline void put_u24be(osd::u8 *buf, osd::u32 data) noexcept { - buf[0] = data >> 16; - buf[1] = data >> 8; - buf[2] = data >> 0; + buf[0] = osd::u8(data >> 16); + buf[1] = osd::u8(data >> 8); + buf[2] = osd::u8(data >> 0); } -inline void put_u32be(u8 *buf, const u32 data) noexcept +inline void put_u32be(osd::u8 *buf, osd::u32 data) noexcept { - buf[0] = data >> 24; - buf[1] = data >> 16; - buf[2] = data >> 8; - buf[3] = data >> 0; + buf[0] = osd::u8(data >> 24); + buf[1] = osd::u8(data >> 16); + buf[2] = osd::u8(data >> 8); + buf[3] = osd::u8(data >> 0); } -inline void put_u48be(u8 *buf, const u64 data) noexcept +inline void put_u48be(osd::u8 *buf, osd::u64 data) noexcept { - buf[0] = data >> 40; - buf[1] = data >> 32; - buf[2] = data >> 24; - buf[3] = data >> 16; - buf[4] = data >> 8; - buf[5] = data >> 0; + buf[0] = osd::u8(data >> 40); + buf[1] = osd::u8(data >> 32); + buf[2] = osd::u8(data >> 24); + buf[3] = osd::u8(data >> 16); + buf[4] = osd::u8(data >> 8); + buf[5] = osd::u8(data >> 0); } -inline void put_u64be(u8 *buf, const u64 data) noexcept +inline void put_u64be(osd::u8 *buf, osd::u64 data) noexcept { - buf[0] = data >> 56; - buf[1] = data >> 48; - buf[2] = data >> 40; - buf[3] = data >> 32; - buf[4] = data >> 24; - buf[5] = data >> 16; - buf[6] = data >> 8; - buf[7] = data >> 0; + buf[0] = osd::u8(data >> 56); + buf[1] = osd::u8(data >> 48); + buf[2] = osd::u8(data >> 40); + buf[3] = osd::u8(data >> 32); + buf[4] = osd::u8(data >> 24); + buf[5] = osd::u8(data >> 16); + buf[6] = osd::u8(data >> 8); + buf[7] = osd::u8(data >> 0); } ////////////////////////////////////////////////////////////////////////////// // signed big-endian -inline constexpr s16 get_s16be(const u8 *const buf) noexcept +constexpr osd::s16 get_s16be(osd::u8 const *buf) noexcept { return get_u16be(buf); } -inline constexpr s32 get_s24be(const u8 *const buf) noexcept +constexpr osd::s32 get_s24be(osd::u8 const *buf) noexcept { return util::sext(get_u24be(buf), 24); } -inline constexpr s32 get_s32be(const u8 *const buf) noexcept +constexpr osd::s32 get_s32be(osd::u8 const *buf) noexcept { return get_u32be(buf); } -inline constexpr s64 get_s48be(const u8 *const buf) noexcept +constexpr osd::s64 get_s48be(osd::u8 const *buf) noexcept { return util::sext(get_u48be(buf), 48); } -inline constexpr s64 get_s64be(const u8 *const buf) noexcept +constexpr osd::s64 get_s64be(osd::u8 const *buf) noexcept { return get_u64be(buf); } -inline void put_s16be(u8 *buf, const s16 data) noexcept +inline void put_s16be(osd::u8 *buf, osd::s16 data) noexcept { put_u16be(buf, data); } -inline void put_s24be(u8 *buf, const s32 data) noexcept +inline void put_s24be(osd::u8 *buf, osd::s32 data) noexcept { put_u24be(buf, data); } -inline void put_s32be(u8 *buf, const s32 data) noexcept +inline void put_s32be(osd::u8 *buf, osd::s32 data) noexcept { put_u32be(buf, data); } -inline void put_s48be(u8 *buf, const s64 data) noexcept +inline void put_s48be(osd::u8 *buf, osd::s64 data) noexcept { put_u48be(buf, data); } -inline void put_s64be(u8 *buf, const s64 data) noexcept +inline void put_s64be(osd::u8 *buf, osd::s64 data) noexcept { put_u64be(buf, data); } @@ -166,146 +156,146 @@ inline void put_s64be(u8 *buf, const s64 data) noexcept // unsigned little-endian -inline constexpr u16 get_u16le(const u8 *const buf) noexcept +constexpr osd::u16 get_u16le(osd::u8 const *buf) noexcept { - return ((const u16)buf[0] << 0) - | ((const u16)buf[1] << 8); + return (osd::u16(buf[0]) << 0) + | (osd::u16(buf[1]) << 8); } -inline constexpr u32 get_u24le(const u8 *const buf) noexcept +constexpr osd::u32 get_u24le(osd::u8 const *buf) noexcept { - return ((const u32)buf[0] << 0) - | ((const u32)buf[1] << 8) - | ((const u32)buf[2] << 16); + return (osd::u32(buf[0]) << 0) + | (osd::u32(buf[1]) << 8) + | (osd::u32(buf[2]) << 16); } -inline constexpr u32 get_u32le(const u8 *const buf) noexcept +constexpr osd::u32 get_u32le(osd::u8 const *buf) noexcept { - return ((const u32)buf[0] << 0) - | ((const u32)buf[1] << 8) - | ((const u32)buf[2] << 16) - | ((const u32)buf[3] << 24); + return (osd::u32(buf[0]) << 0) + | (osd::u32(buf[1]) << 8) + | (osd::u32(buf[2]) << 16) + | (osd::u32(buf[3]) << 24); } -inline constexpr u64 get_u48le(const u8 *const buf) noexcept +constexpr osd::u64 get_u48le(osd::u8 const *buf) noexcept { - return ((const u64)buf[0] << 0) - | ((const u64)buf[1] << 8) - | ((const u64)buf[2] << 16) - | ((const u64)buf[3] << 24) - | ((const u64)buf[4] << 32) - | ((const u64)buf[5] << 40); + return (osd::u64(buf[0]) << 0) + | (osd::u64(buf[1]) << 8) + | (osd::u64(buf[2]) << 16) + | (osd::u64(buf[3]) << 24) + | (osd::u64(buf[4]) << 32) + | (osd::u64(buf[5]) << 40); } -inline constexpr u64 get_u64le(const u8 *const buf) noexcept +constexpr osd::u64 get_u64le(osd::u8 const *buf) noexcept { - return ((const u64)buf[0] << 0) - | ((const u64)buf[1] << 8) - | ((const u64)buf[2] << 16) - | ((const u64)buf[3] << 24) - | ((const u64)buf[4] << 32) - | ((const u64)buf[5] << 40) - | ((const u64)buf[6] << 48) - | ((const u64)buf[7] << 56); + return (osd::u64(buf[0]) << 0) + | (osd::u64(buf[1]) << 8) + | (osd::u64(buf[2]) << 16) + | (osd::u64(buf[3]) << 24) + | (osd::u64(buf[4]) << 32) + | (osd::u64(buf[5]) << 40) + | (osd::u64(buf[6]) << 48) + | (osd::u64(buf[7]) << 56); } -inline void put_u16le(u8 *buf, const u16 data) noexcept +inline void put_u16le(osd::u8 *buf, osd::u16 data) noexcept { - buf[0] = data >> 0; - buf[1] = data >> 8; + buf[0] = osd::u8(data >> 0); + buf[1] = osd::u8(data >> 8); } -inline void put_u24le(u8 *buf, const u32 data) noexcept +inline void put_u24le(osd::u8 *buf, osd::u32 data) noexcept { - buf[0] = data >> 0; - buf[1] = data >> 8; - buf[2] = data >> 16; + buf[0] = osd::u8(data >> 0); + buf[1] = osd::u8(data >> 8); + buf[2] = osd::u8(data >> 16); } -inline void put_u32le(u8 *buf, const u32 data) noexcept +inline void put_u32le(osd::u8 *buf, osd::u32 data) noexcept { - buf[0] = data >> 0; - buf[1] = data >> 8; - buf[2] = data >> 16; - buf[3] = data >> 24; + buf[0] = osd::u8(data >> 0); + buf[1] = osd::u8(data >> 8); + buf[2] = osd::u8(data >> 16); + buf[3] = osd::u8(data >> 24); } -inline void put_u48le(u8 *buf, const u64 data) noexcept +inline void put_u48le(osd::u8 *buf, osd::u64 data) noexcept { - buf[0] = data >> 0; - buf[1] = data >> 8; - buf[2] = data >> 16; - buf[3] = data >> 24; - buf[4] = data >> 32; - buf[5] = data >> 40; + buf[0] = osd::u8(data >> 0); + buf[1] = osd::u8(data >> 8); + buf[2] = osd::u8(data >> 16); + buf[3] = osd::u8(data >> 24); + buf[4] = osd::u8(data >> 32); + buf[5] = osd::u8(data >> 40); } -inline void put_u64le(u8 *buf, const u64 data) noexcept +inline void put_u64le(osd::u8 *buf, osd::u64 data) noexcept { - buf[0] = data >> 0; - buf[1] = data >> 8; - buf[2] = data >> 16; - buf[3] = data >> 24; - buf[4] = data >> 32; - buf[5] = data >> 40; - buf[6] = data >> 48; - buf[7] = data >> 56; + buf[0] = osd::u8(data >> 0); + buf[1] = osd::u8(data >> 8); + buf[2] = osd::u8(data >> 16); + buf[3] = osd::u8(data >> 24); + buf[4] = osd::u8(data >> 32); + buf[5] = osd::u8(data >> 40); + buf[6] = osd::u8(data >> 48); + buf[7] = osd::u8(data >> 56); } ////////////////////////////////////////////////////////////////////////////// // signed little-endian -inline constexpr s16 get_s16le(const u8 *const buf) noexcept +constexpr osd::s16 get_s16le(osd::u8 const *buf) noexcept { return get_u16le(buf); } -inline constexpr s32 get_s24le(const u8 *const buf) noexcept +constexpr osd::s32 get_s24le(osd::u8 const *buf) noexcept { return util::sext(get_u24le(buf), 24); } -inline constexpr s32 get_s32le(const u8 *const buf) noexcept +constexpr osd::s32 get_s32le(osd::u8 const *buf) noexcept { return get_u32le(buf); } -inline constexpr s64 get_s48le(const u8 *const buf) noexcept +constexpr osd::s64 get_s48le(osd::u8 const *buf) noexcept { return util::sext(get_u48le(buf), 48); } -inline constexpr s64 get_s64le(const u8 *const buf) noexcept +constexpr osd::s64 get_s64le(osd::u8 const *buf) noexcept { return get_u64le(buf); } -inline void put_s16le(u8 *buf, const s16 data) noexcept +inline void put_s16le(osd::u8 *buf, osd::s16 data) noexcept { put_u16le(buf, data); } -inline void put_s24le(u8 *buf, const s32 data) noexcept +inline void put_s24le(osd::u8 *buf, osd::s32 data) noexcept { put_u24le(buf, data); } -inline void put_s32le(u8 *buf, const s32 data) noexcept +inline void put_s32le(osd::u8 *buf, osd::s32 data) noexcept { put_u32le(buf, data); } -inline void put_s48le(u8 *buf, const s64 data) noexcept +inline void put_s48le(osd::u8 *buf, osd::s64 data) noexcept { put_u48le(buf, data); } -inline void put_s64le(u8 *buf, const s64 data) noexcept +inline void put_s64le(osd::u8 *buf, osd::s64 data) noexcept { put_u64le(buf, data); } ////////////////////////////////////////////////////////////////////////////// -#endif // MAME_LIB_UTIL_MULTIBYTE_H +#endif // MAME_UTIL_MULTIBYTE_H diff --git a/src/lib/util/simh_tape_file.cpp b/src/lib/util/simh_tape_file.cpp index 24756b782ec..4fe1af5ae88 100644 --- a/src/lib/util/simh_tape_file.cpp +++ b/src/lib/util/simh_tape_file.cpp @@ -4,41 +4,41 @@ // best read together with SIMH magtape spec (rev 17 Jan 2022) // http://simh.trailing-edge.com/docs/simh_magtape.pdf -#include "multibyte.h" #include "simh_tape_file.h" #include "ioprocs.h" +#include "multibyte.h" #include +#include #include #include -#include #include ////////////////////////////////////////////////////////////////////////////// // constants and helpers -enum class simh_marker : u32 { +enum class simh_marker : osd::u32 { TAPE_MARK = 0x00000000, // filemark; TODO: SIMH doesn't define setmarks ERASE_GAP = 0xfffffffe, EOM = 0xffffffff }; -inline const bool is_simh_marker_half_gap_forward(const simh_marker marker) +inline bool is_simh_marker_half_gap_forward(const simh_marker marker) { // this function is used when we're reading normally (from BOM to EOM); returns true for erase gap markers that have been half overwritten - return (const u32)marker == 0xfffeffff; + return osd::u32(marker) == 0xfffeffff; } -inline const bool is_simh_marker_half_gap_reverse(const simh_marker marker) +inline bool is_simh_marker_half_gap_reverse(const simh_marker marker) { // this function is used when we're reading in reverse (from EOM to BOM); returns true for erase gap markers that have been half overwritten - return (const u32)marker >= 0xffff0000 && (const u32)marker <= 0xfffffffd; + return osd::u32(marker) >= 0xffff0000 && osd::u32(marker) <= 0xfffffffd; } -inline const bool is_simh_marker_eod_forward(const simh_marker marker) +inline bool is_simh_marker_eod_forward(const simh_marker marker) { // this function is used when we're reading normally (from BOM to EOM); returns true for markers that we consider EOD return marker == simh_marker::ERASE_GAP @@ -46,7 +46,7 @@ inline const bool is_simh_marker_eod_forward(const simh_marker marker) || marker == simh_marker::EOM; // logical EOM } -inline const bool is_simh_marker_eod_reverse(const simh_marker marker) +inline bool is_simh_marker_eod_reverse(const simh_marker marker) { // this function is used when we're reading in reverse (from EOM to BOM); returns true for markers that we consider EOD return marker == simh_marker::ERASE_GAP @@ -54,7 +54,7 @@ inline const bool is_simh_marker_eod_reverse(const simh_marker marker) || marker == simh_marker::EOM; // logical EOM } -enum class simh_marker_class : u8 { +enum class simh_marker_class : osd::u8 { GOOD_DATA_RECORD = 0x0, PRIVATE_DATA_RECORD_1 = 0x1, PRIVATE_DATA_RECORD_2 = 0x2, @@ -73,21 +73,21 @@ enum class simh_marker_class : u8 { RESERVED_MARKER = 0xf }; -inline const simh_marker_class get_simh_marker_class(const simh_marker marker) +inline simh_marker_class get_simh_marker_class(const simh_marker marker) { - return (const simh_marker_class)((const u32)marker >> 28); + return simh_marker_class(osd::u32(marker) >> 28); } -inline const u32 get_simh_marker_value(const simh_marker marker) +inline osd::u32 get_simh_marker_value(const simh_marker marker) { - return (const u32)marker & 0x0fffffff; + return osd::u32(marker) & 0x0fffffff; } ////////////////////////////////////////////////////////////////////////////// // construction -simh_tape_file::simh_tape_file(util::random_read_write &file, const u64 file_size, const bool read_only, const bool create) +simh_tape_file::simh_tape_file(util::random_read_write &file, osd::u64 file_size, bool read_only, bool create) : m_file(file) , m_file_size(file_size) , m_read_only(read_only) @@ -110,14 +110,14 @@ simh_tape_file::~simh_tape_file() // internal operations -void simh_tape_file::raw_seek(const u64 pos) const +void simh_tape_file::raw_seek(const osd::u64 pos) const { std::error_condition err = m_file.seek(pos, SEEK_SET); if (err) // error: we failed to seek to expected byte offset throw std::runtime_error(std::string("failed seek: ") + err.message()); } -void simh_tape_file::raw_read(u8 *const buf, const u32 len) const +void simh_tape_file::raw_read(osd::u8 *const buf, const osd::u32 len) const { size_t actual_len; std::error_condition err = m_file.read(buf, len, actual_len); @@ -125,7 +125,7 @@ void simh_tape_file::raw_read(u8 *const buf, const u32 len) const throw std::runtime_error(std::string("failed read: ") + (err ? err.message() : std::string("unexpected length"))); } -void simh_tape_file::raw_write(const u8 *const buf, const u32 len) const +void simh_tape_file::raw_write(const osd::u8 *const buf, const osd::u32 len) const { size_t actual_len; std::error_condition err = m_file.write(buf, len, actual_len); @@ -133,42 +133,42 @@ void simh_tape_file::raw_write(const u8 *const buf, const u32 len) const throw std::runtime_error(std::string("failed write: ") + (err ? err.message() : std::string("unexpected length"))); } -void simh_tape_file::read_bytes(const u64 pos, u8 *const buf, const u32 len) const +void simh_tape_file::read_bytes(const osd::u64 pos, osd::u8 *const buf, const osd::u32 len) const { raw_seek(pos); raw_read(buf, len); } -const u32 simh_tape_file::read_word(const u64 pos) const +osd::u32 simh_tape_file::read_word(const osd::u64 pos) const { - const u32 tmp_len = 4; - u8 tmp_buf[tmp_len]; + const osd::u32 tmp_len = 4; + osd::u8 tmp_buf[tmp_len]; raw_seek(pos); raw_read(tmp_buf, tmp_len); return get_u32le(tmp_buf); } -void simh_tape_file::write_bytes(const u64 pos, const u8 *const buf, const u32 len) const +void simh_tape_file::write_bytes(const osd::u64 pos, const osd::u8 *const buf, const osd::u32 len) const { raw_seek(pos); raw_write(buf, len); } -void simh_tape_file::write_byte_repeat(const u64 pos, const u8 data, const u32 len) const +void simh_tape_file::write_byte_repeat(const osd::u64 pos, const osd::u8 data, const osd::u32 len) const { - const u32 tmp_len = 4096; - u8 tmp_buf[tmp_len]; + const osd::u32 tmp_len = 4096; + osd::u8 tmp_buf[tmp_len]; memset(tmp_buf, data, std::min(len, tmp_len)); raw_seek(pos); - for (u32 i = 0; i < len / tmp_len; i++) + for (osd::u32 i = 0; i < len / tmp_len; i++) raw_write(tmp_buf, tmp_len); raw_write(tmp_buf, len % tmp_len); } -void simh_tape_file::write_word(const u64 pos, const u32 data) const +void simh_tape_file::write_word(const osd::u64 pos, const osd::u32 data) const { - const u32 tmp_len = 4; - u8 tmp_buf[tmp_len]; + const osd::u32 tmp_len = 4; + osd::u8 tmp_buf[tmp_len]; put_u32le(tmp_buf, data); raw_seek(pos); raw_write(tmp_buf, tmp_len); @@ -178,7 +178,7 @@ void simh_tape_file::write_word(const u64 pos, const u32 data) const // position-preserving operations -const std::pair simh_tape_file::read_position() const +std::pair simh_tape_file::read_position() const { // this module only keeps track of current tape position, therefore this function scans from BOM to find and return current block address, taking linear time; TODO: this module could be rewritten to also keep track of current block address, therefore enabling this function to only take constant time assert(m_pos <= m_file_size); @@ -190,13 +190,13 @@ const std::pair simh_tape_file::read_position() co return std::pair(tape_status::EOM, 0); // we need to count how many blocks are between BOM and us - u32 blocks_num = 0; - u64 tmp_pos = 0; + osd::u32 blocks_num = 0; + osd::u64 tmp_pos = 0; while (tmp_pos < m_pos) { if (tmp_pos + 4 > m_file_size) // error: truncated marker throw std::runtime_error("truncated marker"); - const simh_marker marker = (const simh_marker)read_word(tmp_pos); + const simh_marker marker = simh_marker(read_word(tmp_pos)); if (marker == simh_marker::TAPE_MARK) { // we skip filemarks tmp_pos += 4; continue; @@ -205,9 +205,9 @@ const std::pair simh_tape_file::read_position() co return std::pair(is_ew() ? tape_status::UNKNOWN_EW : tape_status::UNKNOWN, 0); const simh_marker_class marker_class = get_simh_marker_class(marker); - const u32 block_len = get_simh_marker_value(marker); - const u32 pad_len = block_len % 2; // pad odd-length blocks with 1 byte - const u32 read_len = 4 + block_len + pad_len + 4; + const osd::u32 block_len = get_simh_marker_value(marker); + const osd::u32 pad_len = block_len % 2; // pad odd-length blocks with 1 byte + const osd::u32 read_len = 4 + block_len + pad_len + 4; switch (marker_class) { case simh_marker_class::PRIVATE_MARKER: // we skip other markers case simh_marker_class::RESERVED_MARKER: @@ -240,24 +240,24 @@ const std::pair simh_tape_file::read_position() co // non-destructive operations -void simh_tape_file::rewind(const bool eom) +void simh_tape_file::rewind(bool eom) { assert(m_pos <= m_file_size); assert(m_pos % 2 == 0); m_pos = eom ? m_file_size : 0; } -const tape_status simh_tape_file::locate_block(const u32 req_block_addr) +tape_status simh_tape_file::locate_block(osd::u32 req_block_addr) { assert(m_pos <= m_file_size); assert(m_pos % 2 == 0); - u32 blocks_num = 0; + osd::u32 blocks_num = 0; m_pos = 0; while (m_pos < m_file_size) { if (m_pos + 4 > m_file_size) // error: truncated marker throw std::runtime_error("truncated marker"); - const simh_marker marker = (const simh_marker)read_word(m_pos); + const simh_marker marker = simh_marker(read_word(m_pos)); if (marker == simh_marker::TAPE_MARK) { // we skip filemarks m_pos += 4; continue; @@ -266,9 +266,9 @@ const tape_status simh_tape_file::locate_block(const u32 req_block_addr) return is_ew() ? tape_status::EOD_EW : tape_status::EOD; const simh_marker_class marker_class = get_simh_marker_class(marker); - const u32 block_len = get_simh_marker_value(marker); - const u32 pad_len = block_len % 2; // pad odd-length blocks with 1 byte - const u32 read_len = 4 + block_len + pad_len + 4; + const osd::u32 block_len = get_simh_marker_value(marker); + const osd::u32 pad_len = block_len % 2; // pad odd-length blocks with 1 byte + const osd::u32 read_len = 4 + block_len + pad_len + 4; switch (marker_class) { case simh_marker_class::PRIVATE_MARKER: // we skip other markers case simh_marker_class::RESERVED_MARKER: @@ -296,7 +296,7 @@ const tape_status simh_tape_file::locate_block(const u32 req_block_addr) return tape_status::EOM; } -const tape_status simh_tape_file::space_eod() +tape_status simh_tape_file::space_eod() { assert(m_pos <= m_file_size); assert(m_pos % 2 == 0); @@ -304,7 +304,7 @@ const tape_status simh_tape_file::space_eod() if (m_pos + 4 > m_file_size) // error: truncated marker throw std::runtime_error("truncated marker"); - const simh_marker marker = (const simh_marker)read_word(m_pos); + const simh_marker marker = simh_marker(read_word(m_pos)); if (marker == simh_marker::TAPE_MARK) { // we skip filemarks m_pos += 4; continue; @@ -313,9 +313,9 @@ const tape_status simh_tape_file::space_eod() return tape_status::OK; const simh_marker_class marker_class = get_simh_marker_class(marker); - const u32 block_len = get_simh_marker_value(marker); - const u32 pad_len = block_len % 2; // pad odd-length blocks with 1 byte - const u32 read_len = 4 + block_len + pad_len + 4; + const osd::u32 block_len = get_simh_marker_value(marker); + const osd::u32 pad_len = block_len % 2; // pad odd-length blocks with 1 byte + const osd::u32 read_len = 4 + block_len + pad_len + 4; switch (marker_class) { case simh_marker_class::PRIVATE_MARKER: // we skip other markers case simh_marker_class::RESERVED_MARKER: @@ -334,17 +334,17 @@ const tape_status simh_tape_file::space_eod() return tape_status::EOM; } -const std::pair simh_tape_file::space_blocks(const u32 req_blocks_num) +std::pair simh_tape_file::space_blocks(osd::u32 req_blocks_num) { assert(m_pos <= m_file_size); assert(m_pos % 2 == 0); assert(req_blocks_num > 0); - u32 blocks_num = 0; + osd::u32 blocks_num = 0; while (m_pos < m_file_size) { if (m_pos + 4 > m_file_size) // error: truncated marker throw std::runtime_error("truncated marker"); - const simh_marker marker = (const simh_marker)read_word(m_pos); + const simh_marker marker = simh_marker(read_word(m_pos)); if (marker == simh_marker::TAPE_MARK) { // error: we reached filemark m_pos += 4; return std::pair(is_ew() ? tape_status::FILEMARK_EW : tape_status::FILEMARK, blocks_num); @@ -353,9 +353,9 @@ const std::pair simh_tape_file::space_blocks(const return std::pair(is_ew() ? tape_status::EOD_EW : tape_status::EOD, blocks_num); const simh_marker_class marker_class = get_simh_marker_class(marker); - const u32 block_len = get_simh_marker_value(marker); - const u32 pad_len = block_len % 2; // pad odd-length blocks with 1 byte - const u32 read_len = 4 + block_len + pad_len + 4; + const osd::u32 block_len = get_simh_marker_value(marker); + const osd::u32 pad_len = block_len % 2; // pad odd-length blocks with 1 byte + const osd::u32 read_len = 4 + block_len + pad_len + 4; switch (marker_class) { case simh_marker_class::PRIVATE_MARKER: // we skip other markers case simh_marker_class::RESERVED_MARKER: @@ -383,19 +383,19 @@ const std::pair simh_tape_file::space_blocks(const return std::pair(tape_status::EOM, blocks_num); } -const std::pair simh_tape_file::space_filemarks(const u32 req_filemarks_num, const bool setmarks, const bool sequential) +std::pair simh_tape_file::space_filemarks(osd::u32 req_filemarks_num, bool setmarks, bool sequential) { assert(m_pos <= m_file_size); assert(m_pos % 2 == 0); assert(req_filemarks_num > 0); assert(!setmarks); // TODO: SIMH doesn't define setmarks assert(!sequential); // TODO: support spacing over sequential filemarks, once we have good way to test it - u32 filemarks_num = 0; + osd::u32 filemarks_num = 0; while (m_pos < m_file_size) { if (m_pos + 4 > m_file_size) // error: truncated marker throw std::runtime_error("truncated marker"); - const simh_marker marker = (const simh_marker)read_word(m_pos); + const simh_marker marker = simh_marker(read_word(m_pos)); if (marker == simh_marker::TAPE_MARK) { // we count filemarks m_pos += 4; filemarks_num++; @@ -408,9 +408,9 @@ const std::pair simh_tape_file::space_filemarks(co return std::pair(is_ew() ? tape_status::EOD_EW : tape_status::EOD, filemarks_num); const simh_marker_class marker_class = get_simh_marker_class(marker); - const u32 block_len = get_simh_marker_value(marker); - const u32 pad_len = block_len % 2; // pad odd-length blocks with 1 byte - const u32 read_len = 4 + block_len + pad_len + 4; + const osd::u32 block_len = get_simh_marker_value(marker); + const osd::u32 pad_len = block_len % 2; // pad odd-length blocks with 1 byte + const osd::u32 read_len = 4 + block_len + pad_len + 4; switch (marker_class) { case simh_marker_class::PRIVATE_MARKER: // we skip other markers case simh_marker_class::RESERVED_MARKER: @@ -429,17 +429,17 @@ const std::pair simh_tape_file::space_filemarks(co return std::pair(tape_status::EOM, filemarks_num); } -const std::pair simh_tape_file::space_blocks_reverse(const u32 req_blocks_num) +std::pair simh_tape_file::space_blocks_reverse(osd::u32 req_blocks_num) { assert(m_pos <= m_file_size); assert(m_pos % 2 == 0); assert(req_blocks_num > 0); - u32 blocks_num = 0; + osd::u32 blocks_num = 0; while (m_pos > 0) { if (m_pos - 4 < 0) // error: truncated marker throw std::runtime_error("truncated marker"); - const simh_marker marker = (const simh_marker)read_word(m_pos - 4); + const simh_marker marker = simh_marker(read_word(m_pos - 4)); if (marker == simh_marker::TAPE_MARK) { // error: we reached filemark m_pos -= 4; return std::pair(is_ew() ? tape_status::FILEMARK_EW : tape_status::FILEMARK, blocks_num); @@ -448,9 +448,9 @@ const std::pair simh_tape_file::space_blocks_rever return std::pair(is_ew() ? tape_status::EOD_EW : tape_status::EOD, blocks_num); const simh_marker_class marker_class = get_simh_marker_class(marker); - const u32 block_len = get_simh_marker_value(marker); - const u32 pad_len = block_len % 2; // pad odd-length blocks with 1 byte - const u32 read_len = 4 + block_len + pad_len + 4; + const osd::u32 block_len = get_simh_marker_value(marker); + const osd::u32 pad_len = block_len % 2; // pad odd-length blocks with 1 byte + const osd::u32 read_len = 4 + block_len + pad_len + 4; switch (marker_class) { case simh_marker_class::PRIVATE_MARKER: // we skip other markers case simh_marker_class::RESERVED_MARKER: @@ -478,19 +478,19 @@ const std::pair simh_tape_file::space_blocks_rever return std::pair(tape_status::BOM, blocks_num); } -const std::pair simh_tape_file::space_filemarks_reverse(const u32 req_filemarks_num, const bool setmarks, const bool sequential) +std::pair simh_tape_file::space_filemarks_reverse(osd::u32 req_filemarks_num, bool setmarks, bool sequential) { assert(m_pos <= m_file_size); assert(m_pos % 2 == 0); assert(req_filemarks_num > 0); assert(!setmarks); // TODO: SIMH doesn't define setmarks assert(!sequential); // TODO: support spacing over sequential filemarks, once we have good way to test it - u32 filemarks_num = 0; + osd::u32 filemarks_num = 0; while (m_pos > 0) { if (m_pos - 4 < 0) // error: truncated marker throw std::runtime_error("truncated marker"); - const simh_marker marker = (const simh_marker)read_word(m_pos - 4); + const simh_marker marker = simh_marker(read_word(m_pos - 4)); if (marker == simh_marker::TAPE_MARK) { // we count filemarks m_pos -= 4; filemarks_num++; @@ -503,9 +503,9 @@ const std::pair simh_tape_file::space_filemarks_re return std::pair(is_ew() ? tape_status::EOD_EW : tape_status::EOD, filemarks_num); const simh_marker_class marker_class = get_simh_marker_class(marker); - const u32 block_len = get_simh_marker_value(marker); - const u32 pad_len = block_len % 2; // pad odd-length blocks with 1 byte - const u32 read_len = 4 + block_len + pad_len + 4; + const osd::u32 block_len = get_simh_marker_value(marker); + const osd::u32 pad_len = block_len % 2; // pad odd-length blocks with 1 byte + const osd::u32 read_len = 4 + block_len + pad_len + 4; switch (marker_class) { case simh_marker_class::PRIVATE_MARKER: // we skip other markers case simh_marker_class::RESERVED_MARKER: @@ -524,7 +524,7 @@ const std::pair simh_tape_file::space_filemarks_re return std::pair(tape_status::BOM, filemarks_num); } -const std::pair simh_tape_file::read_block(u8 *buf, const u32 buf_size) +std::pair simh_tape_file::read_block(osd::u8 *buf, osd::u32 buf_size) { assert(m_pos <= m_file_size); assert(m_pos % 2 == 0); @@ -532,7 +532,7 @@ const std::pair simh_tape_file::read_block(u8 *buf if (m_pos + 4 > m_file_size) // error: truncated marker throw std::runtime_error("truncated marker"); - const simh_marker marker = (const simh_marker)read_word(m_pos); + const simh_marker marker = simh_marker(read_word(m_pos)); if (marker == simh_marker::TAPE_MARK) { // error: we reached filemark m_pos += 4; return std::pair(is_ew() ? tape_status::FILEMARK_EW : tape_status::FILEMARK, 0); @@ -541,9 +541,9 @@ const std::pair simh_tape_file::read_block(u8 *buf return std::pair(is_ew() ? tape_status::EOD_EW : tape_status::EOD, 0); const simh_marker_class marker_class = get_simh_marker_class(marker); - const u32 block_len = get_simh_marker_value(marker); - const u32 pad_len = block_len % 2; // pad odd-length blocks with 1 byte - const u32 read_len = 4 + block_len + pad_len + 4; + const osd::u32 block_len = get_simh_marker_value(marker); + const osd::u32 pad_len = block_len % 2; // pad odd-length blocks with 1 byte + const osd::u32 read_len = 4 + block_len + pad_len + 4; switch (marker_class) { case simh_marker_class::PRIVATE_MARKER: // we skip other markers case simh_marker_class::RESERVED_MARKER: @@ -577,23 +577,23 @@ const std::pair simh_tape_file::read_block(u8 *buf // destructive operations -void simh_tape_file::erase(const bool eom) +void simh_tape_file::erase(bool eom) { assert(!m_read_only); assert(m_pos <= m_file_size); assert(m_pos % 2 == 0); - const u32 write_len = m_file_size - m_pos; // we always erase entire remainder of tape + const osd::u32 write_len = m_file_size - m_pos; // we always erase entire remainder of tape write_byte_repeat(m_pos, 0xff, write_len); // we assume simh_marker::EOM == 0xffffffff m_pos += write_len; } -const tape_status simh_tape_file::write_block(const u8 *const buf, const u32 req_block_len) +tape_status simh_tape_file::write_block(const osd::u8 *buf, osd::u32 req_block_len) { assert(!m_read_only); assert(m_pos <= m_file_size); assert(m_pos % 2 == 0); - const u32 pad_len = req_block_len % 2; // pad odd-length blocks with 1 byte - const u32 write_len = 4 + req_block_len + pad_len + 4; + const osd::u32 pad_len = req_block_len % 2; // pad odd-length blocks with 1 byte + const osd::u32 write_len = 4 + req_block_len + pad_len + 4; if (m_pos + write_len >= m_file_size) // error: we reached physical EOM return tape_status::EOM; @@ -605,18 +605,18 @@ const tape_status simh_tape_file::write_block(const u8 *const buf, const u32 req return is_ew() ? tape_status::EW : tape_status::OK; // success: we wrote another block } -const tape_status simh_tape_file::write_filemarks(const u32 req_filemarks_num, const bool setmarks) +tape_status simh_tape_file::write_filemarks(osd::u32 req_filemarks_num, bool setmarks) { assert(!m_read_only); assert(m_pos <= m_file_size); assert(m_pos % 2 == 0); assert(!setmarks); // TODO: SIMH doesn't define setmarks - const u32 write_len = req_filemarks_num * 4; + const osd::u32 write_len = req_filemarks_num * 4; if (m_pos + write_len >= m_file_size) // error: we reached physical EOM return tape_status::EOM; - for (u32 i = 0; i < write_len; i += 4) - write_word(m_pos + i, (const u32)simh_marker::TAPE_MARK); + for (osd::u32 i = 0; i < write_len; i += 4) + write_word(m_pos + i, osd::u32(simh_marker::TAPE_MARK)); m_pos += write_len; return is_ew() ? tape_status::EW : tape_status::OK; // success: we wrote all filemarks } diff --git a/src/lib/util/simh_tape_file.h b/src/lib/util/simh_tape_file.h index 38edad71541..62c704a376b 100644 --- a/src/lib/util/simh_tape_file.h +++ b/src/lib/util/simh_tape_file.h @@ -1,15 +1,15 @@ // license:BSD-3-Clause // copyright-holders:Mietek Bak - -#ifndef MAME_LIB_UTIL_SIMH_TAPE_FILE_H -#define MAME_LIB_UTIL_SIMH_TAPE_FILE_H +#ifndef MAME_UTIL_SIMH_TAPE_FILE_H +#define MAME_UTIL_SIMH_TAPE_FILE_H #pragma once #include "tape_file_interface.h" - #include "utilfwd.h" +#include "osdcomm.h" + #include ////////////////////////////////////////////////////////////////////////////// @@ -18,48 +18,48 @@ class simh_tape_file : public tape_file_interface { public: // construction and destruction - simh_tape_file(util::random_read_write &file, const u64 file_size, const bool read_only, const bool create = false); + simh_tape_file(util::random_read_write &file, osd::u64 file_size, bool read_only, bool create = false); virtual ~simh_tape_file(); // position-preserving operations - virtual const bool is_read_only() const override { return m_read_only; } - virtual const bool is_ew() const override { return m_pos + 32768 >= m_file_size; } // 32KB from EOM; TODO: ANSI says EW should be 10ft from EOM regardless of density - virtual const u8 get_density_code() const override { return 0; } // TODO: SIMH doesn't define density - virtual const std::pair read_position() const override; + virtual bool is_read_only() const override { return m_read_only; } + virtual bool is_ew() const override { return m_pos + 32768 >= m_file_size; } // 32KB from EOM; TODO: ANSI says EW should be 10ft from EOM regardless of density + virtual osd::u8 get_density_code() const override { return 0; } // TODO: SIMH doesn't define density + virtual std::pair read_position() const override; // non-destructive operations - virtual void rewind(const bool eom) override; - virtual const tape_status locate_block(const u32 req_block_addr) override; - virtual const tape_status space_eod() override; - virtual const std::pair space_blocks(const u32 req_blocks_num) override; - virtual const std::pair space_blocks_reverse(const u32 req_blocks_num) override; - virtual const std::pair space_filemarks(const u32 req_marks_num, const bool setmarks = false, const bool sequential = false) override; - virtual const std::pair space_filemarks_reverse(const u32 req_marks_num, const bool setmarks = false, const bool sequential = false) override; - virtual const std::pair read_block(u8 *const buf, const u32 buf_size) override; + virtual void rewind(bool eom) override; + virtual tape_status locate_block(osd::u32 req_block_addr) override; + virtual tape_status space_eod() override; + virtual std::pair space_blocks(osd::u32 req_blocks_num) override; + virtual std::pair space_blocks_reverse(osd::u32 req_blocks_num) override; + virtual std::pair space_filemarks(osd::u32 req_marks_num, bool setmarks = false, bool sequential = false) override; + virtual std::pair space_filemarks_reverse(osd::u32 req_marks_num, bool setmarks = false, bool sequential = false) override; + virtual std::pair read_block(osd::u8 *buf, osd::u32 buf_size) override; // destructive operations - virtual void erase(const bool eom) override; - virtual const tape_status write_block(const u8 *const buf, const u32 len) override; - virtual const tape_status write_filemarks(const u32 req_marks_num, const bool setmarks = false) override; + virtual void erase(bool eom) override; + virtual tape_status write_block(const osd::u8 *buf, osd::u32 len) override; + virtual tape_status write_filemarks(osd::u32 req_marks_num, bool setmarks = false) override; protected: // internal operations - void raw_seek(const u64 pos) const; - void raw_read(u8 *const buf, const u32 len) const; - void raw_write(const u8 *const buf, const u32 len) const; - void read_bytes(const u64 pos, u8 *const buf, const u32 len) const; - const u32 read_word(const u64 pos) const; - void write_bytes(const u64 pos, const u8 *const buf, const u32 len) const; - void write_byte_repeat(const u64 pos, const u8 data, const u32 len) const; - void write_word(const u64 pos, const u32 data) const; + void raw_seek(const osd::u64 pos) const; + void raw_read(osd::u8 *const buf, const osd::u32 len) const; + void raw_write(const osd::u8 *const buf, const osd::u32 len) const; + void read_bytes(const osd::u64 pos, osd::u8 *const buf, const osd::u32 len) const; + osd::u32 read_word(const osd::u64 pos) const; + void write_bytes(const osd::u64 pos, const osd::u8 *const buf, const osd::u32 len) const; + void write_byte_repeat(const osd::u64 pos, const osd::u8 data, const osd::u32 len) const; + void write_word(const osd::u64 pos, const osd::u32 data) const; // state util::random_read_write &m_file; // tape image file - u64 m_file_size; // size of tape image file + osd::u64 m_file_size; // size of tape image file bool m_read_only; // should we disallow destructive operations on tape image - u64 m_pos; // tape position + osd::u64 m_pos; // tape position }; ////////////////////////////////////////////////////////////////////////////// -#endif // MAME_LIB_UTIL_SIMH_TAPE_FILE_H +#endif // MAME_UTIL_SIMH_TAPE_FILE_H diff --git a/src/lib/util/tape_file_interface.h b/src/lib/util/tape_file_interface.h index 13c3f559b66..8003c05777f 100644 --- a/src/lib/util/tape_file_interface.h +++ b/src/lib/util/tape_file_interface.h @@ -1,16 +1,16 @@ // license:BSD-3-Clause // copyright-holders:Mietek Bak - -#ifndef MAME_LIB_UTIL_TAPE_FILE_INTERFACE_H -#define MAME_LIB_UTIL_TAPE_FILE_INTERFACE_H +#ifndef MAME_UTIL_TAPE_FILE_INTERFACE_H +#define MAME_UTIL_TAPE_FILE_INTERFACE_H #pragma once +#include #include ////////////////////////////////////////////////////////////////////////////// -enum class tape_status : u8 { +enum class tape_status : std::uint8_t { OK, // oll korrekt BOM, // beginning of medium EW, // early warning @@ -32,27 +32,27 @@ public: virtual ~tape_file_interface() {} // position-preserving operations - virtual const bool is_read_only() const = 0; - virtual const bool is_ew() const = 0; - virtual const u8 get_density_code() const = 0; - virtual const std::pair read_position() const = 0; + virtual bool is_read_only() const = 0; + virtual bool is_ew() const = 0; + virtual std::uint8_t get_density_code() const = 0; + virtual std::pair read_position() const = 0; // non-destructive operations - virtual void rewind(const bool eom) = 0; - virtual const tape_status locate_block(const u32 req_block_addr) = 0; - virtual const tape_status space_eod() = 0; - virtual const std::pair space_blocks(const u32 req_blocks_num) = 0; - virtual const std::pair space_filemarks(const u32 req_marks_num, const bool setmarks = false, const bool sequential = false) = 0; - virtual const std::pair space_blocks_reverse(const u32 req_blocks_num) = 0; - virtual const std::pair space_filemarks_reverse(const u32 req_marks_num, const bool setmarks = false, const bool sequential = false) = 0; - virtual const std::pair read_block(u8 *const buf, const u32 buf_size) = 0; + virtual void rewind(bool eom) = 0; + virtual tape_status locate_block(std::uint32_t req_block_addr) = 0; + virtual tape_status space_eod() = 0; + virtual std::pair space_blocks(std::uint32_t req_blocks_num) = 0; + virtual std::pair space_filemarks(std::uint32_t req_marks_num, bool setmarks = false, bool sequential = false) = 0; + virtual std::pair space_blocks_reverse(std::uint32_t req_blocks_num) = 0; + virtual std::pair space_filemarks_reverse(std::uint32_t req_marks_num, bool setmarks = false, bool sequential = false) = 0; + virtual std::pair read_block(std::uint8_t *buf, std::uint32_t buf_size) = 0; // destructive operations - virtual void erase(const bool eom) = 0; - virtual const tape_status write_block(const u8 *const buf, const u32 len) = 0; - virtual const tape_status write_filemarks(const u32 req_marks_num, const bool setmarks = false) = 0; + virtual void erase(bool eom) = 0; + virtual tape_status write_block(const std::uint8_t *buf, std::uint32_t len) = 0; + virtual tape_status write_filemarks(std::uint32_t req_marks_num, bool setmarks = false) = 0; }; ////////////////////////////////////////////////////////////////////////////// -#endif // MAME_LIB_UTIL_TAPE_FILE_INTERFACE_H +#endif // MAME_UTIL_TAPE_FILE_INTERFACE_H diff --git a/src/osd/modules/render/drawbgfx.cpp b/src/osd/modules/render/drawbgfx.cpp index 19da01898e1..36758914961 100644 --- a/src/osd/modules/render/drawbgfx.cpp +++ b/src/osd/modules/render/drawbgfx.cpp @@ -532,37 +532,40 @@ uint32_t renderer_bgfx::s_height[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //============================================================ #ifdef OSD_SDL -static void *sdlNativeWindowHandle(SDL_Window *window) +static std::pair sdlNativeWindowHandle(SDL_Window *window) { SDL_SysWMinfo wmi; SDL_VERSION(&wmi.version); if (!SDL_GetWindowWMInfo(window, &wmi)) - return nullptr; + return std::make_pair(nullptr, false); switch (wmi.subsystem) { #if defined(SDL_VIDEO_DRIVER_WINDOWS) case SDL_SYSWM_WINDOWS: - return wmi.info.win.window; + return std::make_pair(wmi.info.win.window, true); #endif #if defined(SDL_VIDEO_DRIVER_X11) case SDL_SYSWM_X11: - return (void *)uintptr_t(wmi.info.x11.window); + return std::make_pair((void *)uintptr_t(wmi.info.x11.window), true); #endif #if defined(SDL_VIDEO_DRIVER_COCOA) case SDL_SYSWM_COCOA: - return wmi.info.cocoa.window; + return std::make_pair(wmi.info.cocoa.window, true); #endif #if defined(SDL_VIDEO_DRIVER_WAYLAND) && SDL_VERSION_ATLEAST(2, 0, 16) && defined(SDLMAME_USE_WAYLAND) case SDL_SYSWM_WAYLAND: - return osd::create_wl_egl_window(window, wmi.info.wl.surface); + { + void *const platform_window = osd::create_wl_egl_window(window, wmi.info.wl.surface); + return std::make_pair(platform_window, platform_window != nullptr); + } #endif #if defined(SDL_VIDEO_DRIVER_ANDROID) case SDL_SYSWM_ANDROID: - return wmi.info.android.window; + return std::make_pair(wmi.info.android.window, true); #endif default: - return nullptr; + return std::make_pair(nullptr, false); } } #endif // OSD_SDL @@ -654,20 +657,6 @@ int renderer_bgfx::create() m_textures = std::make_unique(); m_targets = std::make_unique(*m_textures); - m_shaders = std::make_unique(); - m_effects = std::make_unique(*m_shaders); - - // Create program from shaders. - m_gui_effect[0] = m_effects->get_or_load_effect(m_module().options(), "gui_opaque"); - m_gui_effect[1] = m_effects->get_or_load_effect(m_module().options(), "gui_blend"); - m_gui_effect[2] = m_effects->get_or_load_effect(m_module().options(), "gui_multiply"); - m_gui_effect[3] = m_effects->get_or_load_effect(m_module().options(), "gui_add"); - - m_screen_effect[0] = m_effects->get_or_load_effect(m_module().options(), "screen_opaque"); - m_screen_effect[1] = m_effects->get_or_load_effect(m_module().options(), "screen_blend"); - m_screen_effect[2] = m_effects->get_or_load_effect(m_module().options(), "screen_multiply"); - m_screen_effect[3] = m_effects->get_or_load_effect(m_module().options(), "screen_add"); - if (window().index() != 0) { #ifdef OSD_WINDOWS @@ -675,7 +664,14 @@ int renderer_bgfx::create() #elif defined(OSD_MAC) m_framebuffer = m_targets->create_backbuffer(GetOSWindow(dynamic_cast(window()).platform_window()), s_width[window().index()], s_height[window().index()]); #else - m_framebuffer = m_targets->create_backbuffer(sdlNativeWindowHandle(dynamic_cast(window()).platform_window()), s_width[window().index()], s_height[window().index()]); + auto const [winhdl, success] = sdlNativeWindowHandle(dynamic_cast(window()).platform_window()); + if (!success) + { + m_targets.reset(); + m_textures.reset(); + return -1; + } + m_framebuffer = m_targets->create_backbuffer(winhdl, s_width[window().index()], s_height[window().index()]); #endif bgfx::touch(window().index()); @@ -683,6 +679,20 @@ int renderer_bgfx::create() m_ortho_view->set_backbuffer(m_framebuffer); } + m_shaders = std::make_unique(); + m_effects = std::make_unique(*m_shaders); + + // Create program from shaders. + m_gui_effect[0] = m_effects->get_or_load_effect(m_module().options(), "gui_opaque"); + m_gui_effect[1] = m_effects->get_or_load_effect(m_module().options(), "gui_blend"); + m_gui_effect[2] = m_effects->get_or_load_effect(m_module().options(), "gui_multiply"); + m_gui_effect[3] = m_effects->get_or_load_effect(m_module().options(), "gui_add"); + + m_screen_effect[0] = m_effects->get_or_load_effect(m_module().options(), "screen_opaque"); + m_screen_effect[1] = m_effects->get_or_load_effect(m_module().options(), "screen_blend"); + m_screen_effect[2] = m_effects->get_or_load_effect(m_module().options(), "screen_multiply"); + m_screen_effect[3] = m_effects->get_or_load_effect(m_module().options(), "screen_add"); + const uint32_t max_prescale_size = std::min(2u * std::max(wdim.width(), wdim.height()), m_module().max_texture_size()); m_chains = std::make_unique( window().machine(), @@ -1355,7 +1365,7 @@ bool renderer_bgfx::update_dimensions() #elif defined(OSD_MAC) m_framebuffer = m_targets->create_backbuffer(GetOSWindow(dynamic_cast(window()).platform_window()), width, height); #else - m_framebuffer = m_targets->create_backbuffer(sdlNativeWindowHandle(dynamic_cast(window()).platform_window()), width, height); + m_framebuffer = m_targets->create_backbuffer(sdlNativeWindowHandle(dynamic_cast(window()).platform_window()).first, width, height); #endif if (m_ortho_view) { diff --git a/src/tools/imgtool/modules/fat.cpp b/src/tools/imgtool/modules/fat.cpp index ca7c8291a74..f61d073b5f8 100644 --- a/src/tools/imgtool/modules/fat.cpp +++ b/src/tools/imgtool/modules/fat.cpp @@ -423,7 +423,7 @@ static imgtoolerr_t fat_partition_open(imgtool::partition &partition, uint64_t f if (info->sectors_per_cluster == 0) return IMGTOOLERR_CORRUPTIMAGE; - info->total_sectors = total_sectors_l + (((uint64_t) total_sectors_h) << 16); + info->total_sectors = total_sectors_l + (uint64_t(total_sectors_h) << 16); available_sectors = info->total_sectors - info->reserved_sectors - (info->sectors_per_fat * info->fat_count) - (info->root_entries * FAT_DIRENT_SIZE + FAT_SECLEN - 1) / FAT_SECLEN; @@ -526,13 +526,13 @@ static imgtoolerr_t fat_partition_create(imgtool::image &image, uint64_t first_b header[14] = reserved_sectors; header[16] = fat_count; put_u16le(&header[17], root_dir_count); - put_u16le(&header[19], (uint16_t) (block_count >> 0)); + put_u16le(&header[19], uint16_t(block_count >> 0)); header[21] = media_descriptor; put_u16le(&header[22], sectors_per_fat); put_u16le(&header[24], sectors_per_track); put_u16le(&header[26], heads); put_u32le(&header[28], hidden_sectors); - put_u32le(&header[32], (uint32_t) (block_count >> 16)); + put_u32le(&header[32], uint32_t(block_count >> 16)); header[36] = 0xFF; header[38] = 0x28; header[39] = std::rand(); @@ -554,14 +554,14 @@ static imgtoolerr_t fat_partition_create(imgtool::image &image, uint64_t first_b if (boot_sector_offset <= 129) { header[0] = 0xEB; /* JMP rel8 */ - header[1] = (uint8_t) (boot_sector_offset - 2); /* (offset) */ + header[1] = uint8_t(boot_sector_offset - 2); /* (offset) */ header[2] = 0x90; /* NOP */ } else { header[0] = 0xE9; /* JMP rel16 */ - header[1] = (uint8_t) ((boot_sector_offset - 2) >> 0); /* (offset) */ - header[2] = (uint8_t) ((boot_sector_offset - 2) >> 8); /* (offset) */ + header[1] = uint8_t((boot_sector_offset - 2) >> 0); /* (offset) */ + header[2] = uint8_t((boot_sector_offset - 2) >> 8); /* (offset) */ } err = image.write_block(first_block, header); @@ -579,9 +579,9 @@ static imgtoolerr_t fat_partition_create(imgtool::image &image, uint64_t first_b // FIXME: this causes a corrupt PC floppy image since it doubles the FAT partition header - works without it though #if 0 /* set first two FAT entries */ - first_fat_entries = ((uint64_t) media_descriptor) | 0xFFFFFF00; - first_fat_entries &= (((uint64_t) 1) << fat_bits) - 1; - first_fat_entries |= ((((uint64_t) 1) << fat_bits) - 1) << fat_bits; + first_fat_entries = uint64_t(media_descriptor) | 0xFFFFFF00; + first_fat_entries &= (uint64_t(1) << fat_bits) - 1; + first_fat_entries |= ((uint64_t(1) << fat_bits) - 1) << fat_bits; first_fat_entries = little_endianize_int64(first_fat_entries); for (i = 0; i < fat_count; i++) @@ -707,8 +707,8 @@ static uint32_t fat_get_fat_entry(imgtool::partition &partition, const uint8_t * entry &= bit_mask; if (i == 0) - last_entry = (uint32_t) entry; - else if (last_entry != (uint32_t) entry) + last_entry = uint32_t(entry); + else if (last_entry != uint32_t(entry)) return 1; /* if the FATs disagree; mark this as reserved */ } @@ -740,8 +740,8 @@ static void fat_set_fat_entry(imgtool::partition &partition, uint8_t *fat_table, * disk_info->sectors_per_fat) + (bit_index / 8), sizeof(entry)); entry = little_endianize_int64(entry); - entry &= (~((uint64_t) 0xFFFFFFFF >> (32 - disk_info->fat_bits)) << (bit_index % 8)) | ((1 << (bit_index % 8)) - 1); - entry |= ((uint64_t) value) << (bit_index % 8); + entry &= (~(uint64_t(0xFFFFFFFF) >> (32 - disk_info->fat_bits)) << (bit_index % 8)) | ((1 << (bit_index % 8)) - 1); + entry |= uint64_t(value) << (bit_index % 8); entry = little_endianize_int64(entry); memcpy(fat_table + (i * FAT_SECLEN @@ -1229,7 +1229,7 @@ static void fat_canonicalize_sfn(char *sfn, const uint8_t *sfn_bytes) memcpy(sfn, sfn_bytes, 8); rtrim(sfn); if (sfn[0] == 0x05) - sfn[0] = (char) 0xE5; + sfn[0] = char(0xE5); if ((sfn_bytes[8] != ' ') || (sfn_bytes[9] != ' ') || (sfn_bytes[10] != ' ')) { strcat(sfn, "."); @@ -1452,13 +1452,13 @@ static imgtoolerr_t fat_construct_dirent(const char *filename, creation_policy_t /* append to short filename, if possible */ if ((ch < 32) || (ch > 128)) short_char = '\0'; - else if (isalnum((char) ch)) - short_char = toupper((char) ch); - else if (strchr(".!#$%^()-@^_`{}~", (char) ch)) - short_char = (char) ch; + else if (isalnum(char(ch))) + short_char = toupper(char(ch)); + else if (strchr(".!#$%^()-@^_`{}~", char(ch))) + short_char = char(ch); else short_char = '\0'; /* illegal SFN char */ - canonical_short_char = fat_canonicalize_sfn_char((char) ch); + canonical_short_char = fat_canonicalize_sfn_char(char(ch)); if (!short_char || (short_char != canonical_short_char)) { if (toupper(short_char) == toupper(canonical_short_char)) @@ -1606,7 +1606,7 @@ static void fat_bump_dirent(imgtool::partition &partition, uint8_t *entry, size_ sfn_entry = &entry[entry_len - FAT_DIRENT_SIZE]; digit_place = 1; - for (pos = 7; (pos >= 0) && isdigit((char) sfn_entry[pos]); pos--) + for (pos = 7; (pos >= 0) && isdigit(char(sfn_entry[pos])); pos--) { val += (sfn_entry[pos] - '0') * digit_place; digit_place *= 10; @@ -1946,7 +1946,7 @@ static imgtoolerr_t fat_partition_writefile(imgtool::partition &partition, const if (file.directory) return IMGTOOLERR_FILENOTFOUND; - bytes_left = (uint32_t) sourcef.size(); + bytes_left = uint32_t(sourcef.size()); err = fat_set_file_size(partition, &file, bytes_left); if (err) diff --git a/src/tools/imgtool/modules/os9.cpp b/src/tools/imgtool/modules/os9.cpp index 33c4210b18a..97fdcb9e209 100644 --- a/src/tools/imgtool/modules/os9.cpp +++ b/src/tools/imgtool/modules/os9.cpp @@ -99,17 +99,13 @@ static void pick_string(const void *ptr, size_t offset, size_t length, char *des -static void place_string(void *ptr, size_t length, const char *s) +static void place_string(uint8_t *bptr, size_t length, const char *s) { - size_t i; - uint8_t b; - uint8_t *bptr = (uint8_t *) ptr; - bptr[0] = 0x80; - for (i = 0; s[i] && (i < length); i++) + for (size_t i = 0; s[i] && (i < length); i++) { - b = ((uint8_t) s[i]) & 0x7F; + uint8_t b = ((uint8_t) s[i]) & 0x7F; if (s[i+1] == '\0') b |= 0x80; bptr[i] = b; diff --git a/src/tools/imgtool/modules/pc_flop.cpp b/src/tools/imgtool/modules/pc_flop.cpp index 423336c6744..6a242d16abf 100644 --- a/src/tools/imgtool/modules/pc_flop.cpp +++ b/src/tools/imgtool/modules/pc_flop.cpp @@ -36,8 +36,8 @@ static imgtoolerr_t fat_image_create(imgtool::image &image, imgtool::stream::ptr memset(buffer, 0, sizeof(buffer)); put_u16le(&buffer[24], sectors); put_u16le(&buffer[26], heads); - put_u16le(&buffer[19], (uint16_t) (((uint64_t) tracks * heads * sectors) >> 0)); - put_u32le(&buffer[32], (uint16_t) (((uint64_t) tracks * heads * sectors) >> 16)); + put_u16le(&buffer[19], uint16_t((uint64_t(tracks) * heads * sectors) >> 0)); + put_u32le(&buffer[32], uint16_t((uint64_t(tracks) * heads * sectors) >> 16)); err = image.write_block(0, buffer); if (err) goto done; @@ -47,7 +47,7 @@ static imgtoolerr_t fat_image_create(imgtool::image &image, imgtool::stream::ptr imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_CREATE_PARTITION); /* actually create the partition */ - err = fat_partition_create(image, 0, ((uint64_t) tracks) * heads * sectors); + err = fat_partition_create(image, 0, uint64_t(tracks) * heads * sectors); if (err) goto done; @@ -68,7 +68,7 @@ static imgtoolerr_t fat_image_get_geometry(imgtool::image &image, uint32_t *trac return err; total_sectors = get_u16le(&buffer[19]) - | (uint64_t)(get_u32le(&buffer[32]) << 16); + | uint64_t(get_u32le(&buffer[32]) << 16); *sectors = get_u16le(&buffer[24]); *heads = get_u16le(&buffer[26]); -- cgit v1.2.3