diff options
| author | 2026-02-03 19:05:15 -0500 | |
|---|---|---|
| committer | 2026-02-03 19:05:15 -0500 | |
| commit | e6bc966bed649c05a03755ca5f2848d9cef7d1f1 (patch) | |
| tree | e52bc00afa2d4d7b9e90e0ed21da5607342c348b | |
| parent | 879bcb8b8cb00d7f513f5cb81a48c51af4bafb53 (diff) | |
romentry.h: Replace various macros with constexprs and inline functions; mark ROM_OPTIONAL as deprecated
| -rw-r--r-- | src/emu/romentry.h | 132 | ||||
| -rw-r--r-- | src/emu/romload.h | 6 |
2 files changed, 71 insertions, 67 deletions
diff --git a/src/emu/romentry.h b/src/emu/romentry.h index 2a315c2a03e..56bb6cd2cd5 100644 --- a/src/emu/romentry.h +++ b/src/emu/romentry.h @@ -25,8 +25,8 @@ CONSTANTS ***************************************************************************/ -/* ----- type constants ----- */ -#define ROMENTRY_TYPEMASK 0x0000000f /* type of entry */ +// ----- type constants ----- +static constexpr u32 ROMENTRY_TYPEMASK = 0x0000000f; // type of entry enum { ROMENTRYTYPE_ROM = 0, // starts loading a ROM file @@ -43,85 +43,87 @@ enum ROMENTRYTYPE_COUNT }; -/* ----- per-region constants ----- */ -#define ROMREGION_WIDTHMASK 0x00000300 /* native width of region, as power of 2 */ -#define ROMREGION_8BIT 0x00000000 /* (non-CPU regions only) */ -#define ROMREGION_16BIT 0x00000100 -#define ROMREGION_32BIT 0x00000200 -#define ROMREGION_64BIT 0x00000300 +// ----- per-region constants ----- -#define ROMREGION_ENDIANMASK 0x00000400 /* endianness of the region */ -#define ROMREGION_LE 0x00000000 /* (non-CPU regions only) */ -#define ROMREGION_BE 0x00000400 +static constexpr u32 ROMREGION_WIDTHMASK = 0x00000300; // native width of region, as power of 2 +static constexpr u32 ROMREGION_8BIT = 0x00000000; // (non-CPU regions only) +static constexpr u32 ROMREGION_16BIT = 0x00000100; +static constexpr u32 ROMREGION_32BIT = 0x00000200; +static constexpr u32 ROMREGION_64BIT = 0x00000300; -#define ROMREGION_INVERTMASK 0x00000800 /* invert the bits of the region */ -#define ROMREGION_NOINVERT 0x00000000 -#define ROMREGION_INVERT 0x00000800 +static constexpr u32 ROMREGION_ENDIANMASK = 0x00000400; // endianness of the region +static constexpr u32 ROMREGION_LE = 0x00000000; // (non-CPU regions only) +static constexpr u32 ROMREGION_BE = 0x00000400; -#define ROMREGION_ERASEMASK 0x00002000 /* erase the region before loading */ -#define ROMREGION_NOERASE 0x00000000 -#define ROMREGION_ERASE 0x00002000 +static constexpr u32 ROMREGION_INVERTMASK = 0x00000800; // invert the bits of the region +static constexpr u32 ROMREGION_NOINVERT = 0x00000000; +static constexpr u32 ROMREGION_INVERT = 0x00000800; -#define ROMREGION_DATATYPEMASK 0x00004000 /* type of region (ROM versus disk) */ -#define ROMREGION_DATATYPEROM 0x00000000 -#define ROMREGION_DATATYPEDISK 0x00004000 +static constexpr u32 ROMREGION_ERASEMASK = 0x00002000; // erase the region before loading +static constexpr u32 ROMREGION_NOERASE = 0x00000000; +static constexpr u32 ROMREGION_ERASE = 0x00002000; -#define ROMREGION_ERASEVALMASK 0x00ff0000 /* value to erase the region to */ -#define ROMREGION_ERASEVAL(x) ((((x) & 0xff) << 16) | ROMREGION_ERASE) -#define ROMREGION_ERASE00 ROMREGION_ERASEVAL(0) -#define ROMREGION_ERASEFF ROMREGION_ERASEVAL(0xff) +static constexpr u32 ROMREGION_DATATYPEMASK = 0x00004000; // type of region (ROM versus disk) +static constexpr u32 ROMREGION_DATATYPEROM = 0x00000000; +static constexpr u32 ROMREGION_DATATYPEDISK = 0x00004000; +static constexpr u32 ROMREGION_ERASEVALMASK = 0x00ff0000; // value to erase the region to +inline constexpr u32 ROMREGION_ERASEVAL(u8 x) { return (u32(x) << 16) | ROMREGION_ERASE; } +static constexpr u32 ROMREGION_ERASE00 = ROMREGION_ERASEVAL(0); +static constexpr u32 ROMREGION_ERASEFF = ROMREGION_ERASEVAL(0xff); - /* ----- per-ROM constants ----- */ -#define DISK_READONLYMASK 0x00000010 /* is the disk read-only? */ -#define DISK_READWRITE 0x00000000 -#define DISK_READONLY 0x00000010 +// ----- per-ROM constants ----- -#define ROM_OPTIONALMASK 0x00000020 /* optional - won't hurt if it's not there */ -#define ROM_REQUIRED 0x00000000 -#define ROM_OPTIONAL 0x00000020 +static constexpr u32 DISK_READONLYMASK = 0x00000010; // is the disk read-only? +static constexpr u32 DISK_READWRITE = 0x00000000; +static constexpr u32 DISK_READONLY = 0x00000010; -#define ROM_REVERSEMASK 0x00000040 /* reverse the byte order within a group */ -#define ROM_NOREVERSE 0x00000000 -#define ROM_REVERSE 0x00000040 +static constexpr u32 ROM_OPTIONALMASK = 0x00000020; // optional - won't hurt if it's not there +static constexpr u32 ROM_REQUIRED = 0x00000000; +[[deprecated("use image devices, slot devices or BIOS options for truly optional files")]] +static constexpr u32 ROM_OPTIONAL = 0x00000020; -#define ROM_INHERITFLAGSMASK 0x00000080 /* inherit all flags from previous definition */ -#define ROM_INHERITFLAGS 0x00000080 +static constexpr u32 ROM_REVERSEMASK = 0x00000040; // reverse the byte order within a group +static constexpr u32 ROM_NOREVERSE = 0x00000000; +static constexpr u32 ROM_REVERSE = 0x00000040; -#define ROM_GROUPMASK 0x00000f00 /* load data in groups of this size + 1 */ -#define ROM_GROUPSIZE(n) ((((n) - 1) & 15) << 8) -#define ROM_GROUPBYTE ROM_GROUPSIZE(1) -#define ROM_GROUPWORD ROM_GROUPSIZE(2) -#define ROM_GROUPDWORD ROM_GROUPSIZE(4) +static constexpr u32 ROM_INHERITFLAGSMASK = 0x00000080; // inherit all flags from previous definition +static constexpr u32 ROM_INHERITFLAGS = 0x00000080; -#define ROM_SKIPMASK 0x0000f000 /* skip this many bytes after each group */ -#define ROM_SKIP(n) (((n) & 15) << 12) -#define ROM_NOSKIP ROM_SKIP(0) +static constexpr u32 ROM_GROUPMASK = 0x00000f00; // load data in groups of this size + 1 +inline constexpr u32 ROM_GROUPSIZE(int n) { return ((n - 1) & 15) << 8; } +static constexpr u32 ROM_GROUPBYTE = ROM_GROUPSIZE(1); +static constexpr u32 ROM_GROUPWORD = ROM_GROUPSIZE(2); +static constexpr u32 ROM_GROUPDWORD = ROM_GROUPSIZE(4); -#define ROM_BITWIDTHMASK 0x000f0000 /* width of data in bits */ -#define ROM_BITWIDTH(n) (((n) & 15) << 16) -#define ROM_NIBBLE ROM_BITWIDTH(4) -#define ROM_FULLBYTE ROM_BITWIDTH(8) +static constexpr u32 ROM_SKIPMASK = 0x0000f000; // skip this many bytes after each group +inline constexpr u32 ROM_SKIP(int n) { return (n & 15) << 12; } +static constexpr u32 ROM_NOSKIP = ROM_SKIP(0); -#define ROM_BITSHIFTMASK 0x00f00000 /* left-shift count for the bits */ -#define ROM_BITSHIFT(n) (((n) & 15) << 20) -#define ROM_NOSHIFT ROM_BITSHIFT(0) -#define ROM_SHIFT_NIBBLE_LO ROM_BITSHIFT(0) -#define ROM_SHIFT_NIBBLE_HI ROM_BITSHIFT(4) +static constexpr u32 ROM_BITWIDTHMASK = 0x000f0000; // width of data in bits +static constexpr u32 ROM_BITWIDTH(int n) { return u32(n & 15) << 16; } +static constexpr u32 ROM_NIBBLE = ROM_BITWIDTH(4); +static constexpr u32 ROM_FULLBYTE = ROM_BITWIDTH(8); -#define ROM_BIOSFLAGSMASK 0xff000000 /* only loaded if value matches device bios value */ -#define ROM_BIOS(n) ((((n) + 1) & 255) << 24) +static constexpr u32 ROM_BITSHIFTMASK = 0x00f00000; // left-shift count for the bits */ +inline constexpr u32 ROM_BITSHIFT(int n) { return u32(n & 15) << 20; } +static constexpr u32 ROM_NOSHIFT = ROM_BITSHIFT(0); +static constexpr u32 ROM_SHIFT_NIBBLE_LO = ROM_BITSHIFT(0); +static constexpr u32 ROM_SHIFT_NIBBLE_HI = ROM_BITSHIFT(4); -#define ROM_INHERITEDFLAGS (ROM_GROUPMASK | ROM_SKIPMASK | ROM_REVERSEMASK | ROM_BITWIDTHMASK | ROM_BITSHIFTMASK | ROM_BIOSFLAGSMASK) +static constexpr u32 ROM_BIOSFLAGSMASK = 0xff000000; // only loaded if value matches device bios value +inline constexpr u32 ROM_BIOS(int n) { return u32((n + 1) & 255) << 24; } +static constexpr u32 ROM_INHERITEDFLAGS = ROM_GROUPMASK | ROM_SKIPMASK | ROM_REVERSEMASK | ROM_BITWIDTHMASK | ROM_BITSHIFTMASK | ROM_BIOSFLAGSMASK; -/* ----- start/stop macros ----- */ + +// ----- start/stop macros ----- #define ROM_NAME(name) rom_##name #define ROM_START(name) static const tiny_rom_entry ROM_NAME(name)[] = { #define ROM_END { nullptr, nullptr, 0, 0, ROMENTRYTYPE_END } }; -/* ----- ROM region macros ----- */ +// ----- ROM region macros ----- #define ROM_REGION(length,tag,flags) { tag, nullptr, 0, length, ROMENTRYTYPE_REGION | (flags) }, #define ROM_REGION16_LE(length,tag,flags) ROM_REGION(length, tag, (flags) | ROMREGION_16BIT | ROMREGION_LE) #define ROM_REGION16_BE(length,tag,flags) ROM_REGION(length, tag, (flags) | ROMREGION_16BIT | ROMREGION_BE) @@ -131,13 +133,13 @@ enum #define ROM_REGION64_BE(length,tag,flags) ROM_REGION(length, tag, (flags) | ROMREGION_64BIT | ROMREGION_BE) -/* ----- core ROM loading macros ----- */ +// ----- core ROM loading macros ----- #define ROMX_LOAD(name,offset,length,hash,flags) { name, hash, offset, length, ROMENTRYTYPE_ROM | (flags) }, #define ROM_LOAD(name,offset,length,hash) ROMX_LOAD(name, offset, length, hash, 0) #define ROM_LOAD_OPTIONAL(name,offset,length,hash) ROMX_LOAD(name, offset, length, hash, ROM_OPTIONAL) -/* ----- specialized loading macros ----- */ +// ----- specialized loading macros ----- #define ROM_LOAD_NIB_HIGH(name,offset,length,hash) ROMX_LOAD(name, offset, length, hash, ROM_NIBBLE | ROM_SHIFT_NIBBLE_HI) #define ROM_LOAD_NIB_LOW(name,offset,length,hash) ROMX_LOAD(name, offset, length, hash, ROM_NIBBLE | ROM_SHIFT_NIBBLE_LO) #define ROM_LOAD16_BYTE(name,offset,length,hash) ROMX_LOAD(name, offset, length, hash, ROM_SKIP(1)) @@ -153,11 +155,11 @@ enum #define ROM_LOAD64_DWORD_SWAP(name,offset,length,hash) ROMX_LOAD(name, offset, length, hash, ROM_GROUPDWORD | ROM_REVERSE | ROM_SKIP(4)) -/* ----- ROM_RELOAD related macros ----- */ +// ----- ROM_RELOAD related macros ----- #define ROM_RELOAD(offset,length) { nullptr, nullptr, offset, length, ROMENTRYTYPE_RELOAD | ROM_INHERITFLAGS }, #define ROM_RELOAD_PLAIN(offset,length) { nullptr, nullptr, offset, length, ROMENTRYTYPE_RELOAD }, -/* ----- additional ROM-related macros ----- */ +// ----- additional ROM-related macros ----- #define ROM_CONTINUE(offset,length) { nullptr, nullptr, (offset), (length), ROMENTRYTYPE_CONTINUE | ROM_INHERITFLAGS }, #define ROM_IGNORE(length) { nullptr, nullptr, 0, (length), ROMENTRYTYPE_IGNORE | ROM_INHERITFLAGS }, #define ROM_FILL(offset,length,value) { nullptr, (const char *)(value), (offset), (length), ROMENTRYTYPE_FILL }, @@ -165,15 +167,15 @@ enum #define ROM_COPY(srctag,srcoffs,offset,length) { (srctag), (const char *)(srcoffs), (offset), (length), ROMENTRYTYPE_COPY }, -/* ----- system BIOS macros ----- */ +// ----- system BIOS macros ----- #define ROM_SYSTEM_BIOS(value,name,description) { name, description, 0, 0, ROMENTRYTYPE_SYSTEM_BIOS | ROM_BIOS(value) }, #define ROM_DEFAULT_BIOS(name) { name, nullptr, 0, 0, ROMENTRYTYPE_DEFAULT_BIOS }, -/* ----- game parameter macro ----- */ +// ----- game parameter macro ----- #define ROM_PARAMETER(tag, value) { tag, value, 0, 0, ROMENTRYTYPE_PARAMETER }, -/* ----- disk loading macros ----- */ +// ----- disk loading macros ----- #define DISK_REGION(tag) ROM_REGION(1, tag, ROMREGION_DATATYPEDISK) #define DISK_IMAGE(name,idx,hash) ROMX_LOAD(name, idx, 0, hash, DISK_READWRITE) #define DISK_IMAGE_READONLY(name,idx,hash) ROMX_LOAD(name, idx, 0, hash, DISK_READONLY) diff --git a/src/emu/romload.h b/src/emu/romload.h index 4462068dcf2..4bb42874bed 100644 --- a/src/emu/romload.h +++ b/src/emu/romload.h @@ -73,7 +73,8 @@ template <typename T> inline bool ROMREGION_ISDISKDATA(T const &r) { return template <typename T> inline u32 ROM_GETOFFSET(T const &r) { return ROMENTRY_UNWRAP(r).get_offset(); } template <typename T> inline u32 ROM_GETLENGTH(T const &r) { return ROMENTRY_UNWRAP(r).get_length(); } template <typename T> inline u32 ROM_GETFLAGS(T const &r) { return ROMENTRY_UNWRAP(r).get_flags(); } -template <typename T> inline bool ROM_ISOPTIONAL(T const &r) { return (ROM_GETFLAGS(r) & ROM_OPTIONALMASK) == ROM_OPTIONAL; } +// HACK: avoid warnings about deprecated ROM_OPTIONAL in every source file that includes this header +template <typename T> inline bool ROM_ISOPTIONAL(T const &r) { return (ROM_GETFLAGS(r) & ROM_OPTIONALMASK) == /* ROM_OPTIONAL */ ROM_OPTIONALMASK; } template <typename T> inline u32 ROM_GETGROUPSIZE(T const &r) { return ((ROM_GETFLAGS(r) & ROM_GROUPMASK) >> 8) + 1; } template <typename T> inline u32 ROM_GETSKIPCOUNT(T const &r) { return (ROM_GETFLAGS(r) & ROM_SKIPMASK) >> 12; } template <typename T> inline bool ROM_ISREVERSED(T const &r) { return (ROM_GETFLAGS(r) & ROM_REVERSEMASK) == ROM_REVERSE; } @@ -129,7 +130,8 @@ public: constexpr u32 get_length() const { return length; } constexpr u32 get_flags() const { return flags; } constexpr char const *get_hashdata() const { return hashdata; } - constexpr bool is_optional() const { return (flags & ROM_OPTIONALMASK) == ROM_OPTIONAL; } + // HACK: avoid warnings about deprecated ROM_OPTIONAL in every source file that includes this header + constexpr bool is_optional() const { return (flags & ROM_OPTIONALMASK) == /* ROM_OPTIONAL */ fROM_OPTIONALMASK; } constexpr u32 get_groupsize() const { return ((flags & ROM_GROUPMASK) >> 8) + 1; } constexpr u32 get_skipcount() const { return (flags & ROM_SKIPMASK) >> 12; } constexpr bool is_reversed() const { return (flags & ROM_REVERSEMASK) == ROM_REVERSE; } |
