diff --git a/src/devices/machine/s3c24xx.hxx b/src/devices/machine/s3c24xx.hxx index ca7bc05a90d..adb57cd1977 100644 --- a/src/devices/machine/s3c24xx.hxx +++ b/src/devices/machine/s3c24xx.hxx @@ -19,7 +19,6 @@ #define CLOCK_MULTIPLIER 1 -#define BIT(x,n) (((x)>>(n))&1) #define BITS(x,m,n) (((x)>>(n))&(((UINT32)1<<((m)-(n)+1))-1)) #define CLR_BITS(x,m,n) ((x) & ~((((UINT32)1 << ((m) - (n) + 1)) - 1) << n)) diff --git a/src/devices/machine/s3c44b0.cpp b/src/devices/machine/s3c44b0.cpp index 19579a1aa03..bf81606cf12 100644 --- a/src/devices/machine/s3c44b0.cpp +++ b/src/devices/machine/s3c44b0.cpp @@ -284,7 +284,6 @@ void s3c44b0_device::device_reset() #define CLOCK_MULTIPLIER 1 -#define BIT(x,n) (((x)>>(n))&1) #define BITS(x,m,n) (((x)>>(n))&(((UINT32)1<<((m)-(n)+1))-1)) #define CLR_BITS(x,m,n) ((x) & ~((((UINT32)1 << ((m) - (n) + 1)) - 1) << n)) diff --git a/src/devices/video/gf4500.cpp b/src/devices/video/gf4500.cpp index d4b7e86f056..4ad49d4acf7 100644 --- a/src/devices/video/gf4500.cpp +++ b/src/devices/video/gf4500.cpp @@ -26,7 +26,6 @@ static inline void ATTR_PRINTF(3,4) verboselog( device_t &device, int n_level, c } } -#define BIT(x,n) (((x)>>(n))&1) #define BITS(x,m,n) (((x)>>(n))&(((UINT32)1<<((m)-(n)+1))-1)) #define GF4500_FRAMEBUF_OFFSET 0x20000 diff --git a/src/emu/emucore.h b/src/emu/emucore.h index a8e464f0b8b..c9b7900b010 100644 --- a/src/emu/emucore.h +++ b/src/emu/emucore.h @@ -7,10 +7,10 @@ General core utilities and macros used throughout the emulator. ***************************************************************************/ -#pragma once +#ifndef MAME_EMU_EMUCORE_H +#define MAME_EMU_EMUCORE_H -#ifndef __EMUCORE_H__ -#define __EMUCORE_H__ +#pragma once // standard C includes #include @@ -240,36 +240,24 @@ inline TYPE operator--(TYPE &value, int) { TYPE const old(value); --value; retur #define ENDIAN_VALUE_NE_NNE(endian,neval,nneval) (((endian) == ENDIANNESS_NATIVE) ? (neval) : (nneval)) -// useful macros to deal with bit shuffling encryptions -#define BIT(x,n) (((x)>>(n))&1) +// useful functions to deal with bit shuffling encryptions +#define BIT(x, n) (((x) >> (n)) & 1) -#define BITSWAP8(val,B7,B6,B5,B4,B3,B2,B1,B0) \ - ((BIT(val,B7) << 7) | (BIT(val,B6) << 6) | (BIT(val,B5) << 5) | (BIT(val,B4) << 4) | \ - (BIT(val,B3) << 3) | (BIT(val,B2) << 2) | (BIT(val,B1) << 1) | (BIT(val,B0) << 0)) +template constexpr T bitswap(T val, U b) +{ + return BIT(val, b) << 0U; +} -#define BITSWAP16(val,B15,B14,B13,B12,B11,B10,B9,B8,B7,B6,B5,B4,B3,B2,B1,B0) \ - ((BIT(val,B15) << 15) | (BIT(val,B14) << 14) | (BIT(val,B13) << 13) | (BIT(val,B12) << 12) | \ - (BIT(val,B11) << 11) | (BIT(val,B10) << 10) | (BIT(val, B9) << 9) | (BIT(val, B8) << 8) | \ - (BIT(val, B7) << 7) | (BIT(val, B6) << 6) | (BIT(val, B5) << 5) | (BIT(val, B4) << 4) | \ - (BIT(val, B3) << 3) | (BIT(val, B2) << 2) | (BIT(val, B1) << 1) | (BIT(val, B0) << 0)) +template constexpr T bitswap(T val, U b, V... c) +{ + return (BIT(val, b) << sizeof...(c)) | bitswap(val, c...); +} -#define BITSWAP24(val,B23,B22,B21,B20,B19,B18,B17,B16,B15,B14,B13,B12,B11,B10,B9,B8,B7,B6,B5,B4,B3,B2,B1,B0) \ - ((BIT(val,B23) << 23) | (BIT(val,B22) << 22) | (BIT(val,B21) << 21) | (BIT(val,B20) << 20) | \ - (BIT(val,B19) << 19) | (BIT(val,B18) << 18) | (BIT(val,B17) << 17) | (BIT(val,B16) << 16) | \ - (BIT(val,B15) << 15) | (BIT(val,B14) << 14) | (BIT(val,B13) << 13) | (BIT(val,B12) << 12) | \ - (BIT(val,B11) << 11) | (BIT(val,B10) << 10) | (BIT(val, B9) << 9) | (BIT(val, B8) << 8) | \ - (BIT(val, B7) << 7) | (BIT(val, B6) << 6) | (BIT(val, B5) << 5) | (BIT(val, B4) << 4) | \ - (BIT(val, B3) << 3) | (BIT(val, B2) << 2) | (BIT(val, B1) << 1) | (BIT(val, B0) << 0)) - -#define BITSWAP32(val,B31,B30,B29,B28,B27,B26,B25,B24,B23,B22,B21,B20,B19,B18,B17,B16,B15,B14,B13,B12,B11,B10,B9,B8,B7,B6,B5,B4,B3,B2,B1,B0) \ - ((BIT(val,B31) << 31) | (BIT(val,B30) << 30) | (BIT(val,B29) << 29) | (BIT(val,B28) << 28) | \ - (BIT(val,B27) << 27) | (BIT(val,B26) << 26) | (BIT(val,B25) << 25) | (BIT(val,B24) << 24) | \ - (BIT(val,B23) << 23) | (BIT(val,B22) << 22) | (BIT(val,B21) << 21) | (BIT(val,B20) << 20) | \ - (BIT(val,B19) << 19) | (BIT(val,B18) << 18) | (BIT(val,B17) << 17) | (BIT(val,B16) << 16) | \ - (BIT(val,B15) << 15) | (BIT(val,B14) << 14) | (BIT(val,B13) << 13) | (BIT(val,B12) << 12) | \ - (BIT(val,B11) << 11) | (BIT(val,B10) << 10) | (BIT(val, B9) << 9) | (BIT(val, B8) << 8) | \ - (BIT(val, B7) << 7) | (BIT(val, B6) << 6) | (BIT(val, B5) << 5) | (BIT(val, B4) << 4) | \ - (BIT(val, B3) << 3) | (BIT(val, B2) << 2) | (BIT(val, B1) << 1) | (BIT(val, B0) << 0)) +// legacy names for backwards compatibility +template constexpr T BITSWAP8(T val, U... b) { return bitswap(val, b...); } +template constexpr T BITSWAP16(T val, U... b) { return bitswap(val, b...); } +template constexpr T BITSWAP24(T val, U... b) { return bitswap(val, b...); } +template constexpr T BITSWAP32(T val, U... b) { return bitswap(val, b...); } @@ -426,4 +414,4 @@ inline UINT64 d2u(double d) return u.vv; } -#endif /* __EMUCORE_H__ */ +#endif /* MAME_EMU_EMUCORE_H */ diff --git a/src/mame/drivers/gizmondo.cpp b/src/mame/drivers/gizmondo.cpp index ed39f36a293..a520c72fc7f 100644 --- a/src/mame/drivers/gizmondo.cpp +++ b/src/mame/drivers/gizmondo.cpp @@ -39,7 +39,6 @@ SYSINTR_GPS = INT_EINT3, INT_EINT8_23 (EINT18) #define VERBOSE_LEVEL ( 0 ) -#define BIT(x,n) (((x)>>(n))&1) #define BITS(x,m,n) (((x)>>(n))&(((UINT32)1<<((m)-(n)+1))-1)) class gizmondo_state : public driver_device diff --git a/src/mame/drivers/gp32.cpp b/src/mame/drivers/gp32.cpp index f7c4c1c2f4c..0addf2d91c2 100644 --- a/src/mame/drivers/gp32.cpp +++ b/src/mame/drivers/gp32.cpp @@ -43,7 +43,6 @@ static inline void ATTR_PRINTF(3,4) verboselog(device_t &device, int n_level, co #define MPLLCON 1 #define UPLLCON 2 -#define BIT(x,n) (((x)>>(n))&1) #define BITS(x,m,n) (((x)>>(n))&((1<<((m)-(n)+1))-1))