Merge pull request #8056 from JosJuice/more-enums-to-constexpr

Turn more enum constants into constexpr
This commit is contained in:
Léo Lam 2019-05-10 18:52:52 +02:00 committed by GitHub
commit e7bc86881d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 129 additions and 180 deletions

View File

@ -59,29 +59,49 @@ constexpr u64 BUFFER_TRANSFER_RATE = 32 * 1024 * 1024;
namespace DVDInterface namespace DVDInterface
{ {
// "low" error codes
constexpr u32 ERROR_READY = 0x0000000; // Ready.
constexpr u32 ERROR_COVER_L = 0x01000000; // Cover is opened.
constexpr u32 ERROR_CHANGE_DISK = 0x02000000; // Disk change.
constexpr u32 ERROR_NO_DISK = 0x03000000; // No disk.
constexpr u32 ERROR_MOTOR_STOP_L = 0x04000000; // Motor stop.
constexpr u32 ERROR_NO_DISKID_L = 0x05000000; // Disk ID not read.
// "high" error codes
constexpr u32 ERROR_NONE = 0x000000; // No error.
constexpr u32 ERROR_MOTOR_STOP_H = 0x020400; // Motor stopped.
constexpr u32 ERROR_NO_DISKID_H = 0x020401; // Disk ID not read.
constexpr u32 ERROR_COVER_H = 0x023a00; // Medium not present / Cover opened.
constexpr u32 ERROR_SEEK_NDONE = 0x030200; // No seek complete.
constexpr u32 ERROR_READ = 0x031100; // Unrecovered read error.
constexpr u32 ERROR_PROTOCOL = 0x040800; // Transfer protocol error.
constexpr u32 ERROR_INV_CMD = 0x052000; // Invalid command operation code.
constexpr u32 ERROR_AUDIO_BUF = 0x052001; // Audio Buffer not set.
constexpr u32 ERROR_BLOCK_OOB = 0x052100; // Logical block address out of bounds.
constexpr u32 ERROR_INV_FIELD = 0x052400; // Invalid field in command packet.
constexpr u32 ERROR_INV_AUDIO = 0x052401; // Invalid audio command.
constexpr u32 ERROR_INV_PERIOD = 0x052402; // Configuration out of permitted period.
constexpr u32 ERROR_END_USR_AREA = 0x056300; // End of user area encountered on this track.
constexpr u32 ERROR_MEDIUM = 0x062800; // Medium may have changed.
constexpr u32 ERROR_MEDIUM_REQ = 0x0b5a01; // Operator medium removal request.
// internal hardware addresses // internal hardware addresses
enum constexpr u32 DI_STATUS_REGISTER = 0x00;
{ constexpr u32 DI_COVER_REGISTER = 0x04;
DI_STATUS_REGISTER = 0x00, constexpr u32 DI_COMMAND_0 = 0x08;
DI_COVER_REGISTER = 0x04, constexpr u32 DI_COMMAND_1 = 0x0C;
DI_COMMAND_0 = 0x08, constexpr u32 DI_COMMAND_2 = 0x10;
DI_COMMAND_1 = 0x0C, constexpr u32 DI_DMA_ADDRESS_REGISTER = 0x14;
DI_COMMAND_2 = 0x10, constexpr u32 DI_DMA_LENGTH_REGISTER = 0x18;
DI_DMA_ADDRESS_REGISTER = 0x14, constexpr u32 DI_DMA_CONTROL_REGISTER = 0x1C;
DI_DMA_LENGTH_REGISTER = 0x18, constexpr u32 DI_IMMEDIATE_DATA_BUFFER = 0x20;
DI_DMA_CONTROL_REGISTER = 0x1C, constexpr u32 DI_CONFIG_REGISTER = 0x24;
DI_IMMEDIATE_DATA_BUFFER = 0x20,
DI_CONFIG_REGISTER = 0x24
};
// debug commands which may be ORd // debug commands which may be ORd
enum constexpr u32 STOP_DRIVE = 0;
{ constexpr u32 START_DRIVE = 0x100;
STOP_DRIVE = 0, constexpr u32 ACCEPT_COPY = 0x4000;
START_DRIVE = 0x100, constexpr u32 DISC_CHECK = 0x8000;
ACCEPT_COPY = 0x4000,
DISC_CHECK = 0x8000,
};
// DI Status Register // DI Status Register
union UDISR union UDISR

View File

@ -24,36 +24,6 @@ class Mapping;
namespace DVDInterface namespace DVDInterface
{ {
// Not sure about endianness here. I'll just name them like this...
enum DIErrorLow
{
ERROR_READY = 0x00000000, // Ready.
ERROR_COVER_L = 0x01000000, // Cover is opened.
ERROR_CHANGE_DISK = 0x02000000, // Disk change.
ERROR_NO_DISK = 0x03000000, // No disk.
ERROR_MOTOR_STOP_L = 0x04000000, // Motor stop.
ERROR_NO_DISKID_L = 0x05000000 // Disk ID not read.
};
enum DIErrorHigh
{
ERROR_NONE = 0x000000, // No error.
ERROR_MOTOR_STOP_H = 0x020400, // Motor stopped.
ERROR_NO_DISKID_H = 0x020401, // Disk ID not read.
ERROR_COVER_H = 0x023a00, // Medium not present / Cover opened.
ERROR_SEEK_NDONE = 0x030200, // No seek complete.
ERROR_READ = 0x031100, // Unrecovered read error.
ERROR_PROTOCOL = 0x040800, // Transfer protocol error.
ERROR_INV_CMD = 0x052000, // Invalid command operation code.
ERROR_AUDIO_BUF = 0x052001, // Audio Buffer not set.
ERROR_BLOCK_OOB = 0x052100, // Logical block address out of bounds.
ERROR_INV_FIELD = 0x052400, // Invalid field in command packet.
ERROR_INV_AUDIO = 0x052401, // Invalid audio command.
ERROR_INV_PERIOD = 0x052402, // Configuration out of permitted period.
ERROR_END_USR_AREA = 0x056300, // End of user area encountered on this track.
ERROR_MEDIUM = 0x062800, // Medium may have changed.
ERROR_MEDIUM_REQ = 0x0b5a01 // Operator medium removal request.
};
enum DICommand enum DICommand
{ {
DVDLowInquiry = 0x12, DVDLowInquiry = 0x12,

View File

@ -88,47 +88,43 @@ public:
ControllerEmu::ControlGroup* GetGroup(ClassicGroup group); ControllerEmu::ControlGroup* GetGroup(ClassicGroup group);
enum static constexpr u16 PAD_RIGHT = 0x80;
{ static constexpr u16 PAD_DOWN = 0x40;
PAD_RIGHT = 0x80, static constexpr u16 TRIGGER_L = 0x20;
PAD_DOWN = 0x40, static constexpr u16 BUTTON_MINUS = 0x10;
TRIGGER_L = 0x20, static constexpr u16 BUTTON_HOME = 0x08;
BUTTON_MINUS = 0x10, static constexpr u16 BUTTON_PLUS = 0x04;
BUTTON_HOME = 0x08, static constexpr u16 TRIGGER_R = 0x02;
BUTTON_PLUS = 0x04, static constexpr u16 NOTHING = 0x01;
TRIGGER_R = 0x02, static constexpr u16 BUTTON_ZL = 0x8000;
NOTHING = 0x01, static constexpr u16 BUTTON_B = 0x4000;
BUTTON_ZL = 0x8000, static constexpr u16 BUTTON_Y = 0x2000;
BUTTON_B = 0x4000, static constexpr u16 BUTTON_A = 0x1000;
BUTTON_Y = 0x2000, static constexpr u16 BUTTON_X = 0x0800;
BUTTON_A = 0x1000, static constexpr u16 BUTTON_ZR = 0x0400;
BUTTON_X = 0x0800, static constexpr u16 PAD_LEFT = 0x0200;
BUTTON_ZR = 0x0400, static constexpr u16 PAD_UP = 0x0100;
PAD_LEFT = 0x0200,
PAD_UP = 0x0100,
};
enum static constexpr u8 CAL_STICK_CENTER = 0x80;
{ static constexpr u8 CAL_STICK_RANGE = 0x7f;
CAL_STICK_CENTER = 0x80, static constexpr int CAL_STICK_BITS = 8;
CAL_STICK_RANGE = 0x7f,
CAL_STICK_BITS = 8,
LEFT_STICK_BITS = 6, static constexpr int LEFT_STICK_BITS = 6;
LEFT_STICK_CENTER_X = CAL_STICK_CENTER >> (CAL_STICK_BITS - LEFT_STICK_BITS), static constexpr u8 LEFT_STICK_CENTER_X = CAL_STICK_CENTER >> (CAL_STICK_BITS - LEFT_STICK_BITS);
LEFT_STICK_CENTER_Y = CAL_STICK_CENTER >> (CAL_STICK_BITS - LEFT_STICK_BITS), static constexpr u8 LEFT_STICK_CENTER_Y = CAL_STICK_CENTER >> (CAL_STICK_BITS - LEFT_STICK_BITS);
LEFT_STICK_RADIUS = CAL_STICK_RANGE >> (CAL_STICK_BITS - LEFT_STICK_BITS), static constexpr u8 LEFT_STICK_RADIUS = CAL_STICK_RANGE >> (CAL_STICK_BITS - LEFT_STICK_BITS);
RIGHT_STICK_BITS = 5, static constexpr int RIGHT_STICK_BITS = 5;
RIGHT_STICK_CENTER_X = CAL_STICK_CENTER >> (CAL_STICK_BITS - RIGHT_STICK_BITS), static constexpr u8 RIGHT_STICK_CENTER_X = CAL_STICK_CENTER >>
RIGHT_STICK_CENTER_Y = CAL_STICK_CENTER >> (CAL_STICK_BITS - RIGHT_STICK_BITS), (CAL_STICK_BITS - RIGHT_STICK_BITS);
RIGHT_STICK_RADIUS = CAL_STICK_RANGE >> (CAL_STICK_BITS - RIGHT_STICK_BITS), static constexpr u8 RIGHT_STICK_CENTER_Y = CAL_STICK_CENTER >>
(CAL_STICK_BITS - RIGHT_STICK_BITS);
static constexpr u8 RIGHT_STICK_RADIUS = CAL_STICK_RANGE >> (CAL_STICK_BITS - RIGHT_STICK_BITS);
LEFT_TRIGGER_RANGE = 0x1F, static constexpr u8 LEFT_TRIGGER_RANGE = 0x1F;
RIGHT_TRIGGER_RANGE = 0x1F, static constexpr u8 RIGHT_TRIGGER_RANGE = 0x1F;
};
static const u8 STICK_GATE_RADIUS = 0x16; static constexpr u8 STICK_GATE_RADIUS = 0x16;
private: private:
ControllerEmu::Buttons* m_buttons; ControllerEmu::Buttons* m_buttons;

View File

@ -67,8 +67,8 @@ public:
{ {
None = 0b1111111, None = 0b1111111,
Bass = 0b1011011, Bass = 0b1011011,
// TODO: Implement HiHat. // TODO: Implement HiHatPedal.
// HiHat = 0b0011011, // HiHatPedal = 0b0011011,
Red = 0b1011001, Red = 0b1011001,
Yellow = 0b1010001, Yellow = 0b1010001,
Blue = 0b1001111, Blue = 0b1001111,
@ -86,25 +86,18 @@ public:
void DoState(PointerWrap& p) override; void DoState(PointerWrap& p) override;
enum : u8 // FYI: The low/high bits of the button byte are "random" when velocity data is present.
{ // static constexpr u8 HAVE_VELOCITY_DATA = 0b10000001;
BUTTON_PLUS = 0x04, static constexpr u8 BUTTON_PLUS = 0x04;
BUTTON_MINUS = 0x10, static constexpr u8 BUTTON_MINUS = 0x10;
// FYI: The low/high bits of the button byte are "random" when velocity data is present. // FYI: The hi-hat pedal sets no bits here.
// HAVE_VELOCITY_DATA = 0b10000001, static constexpr u8 PAD_BASS = 0x04;
}; static constexpr u8 PAD_BLUE = 0x08;
static constexpr u8 PAD_GREEN = 0x10;
enum : u8 static constexpr u8 PAD_YELLOW = 0x20;
{ static constexpr u8 PAD_RED = 0x40;
// FYI: HiHat sets no bits here. static constexpr u8 PAD_ORANGE = 0x80;
PAD_BASS = 0x04,
PAD_BLUE = 0x08,
PAD_GREEN = 0x10,
PAD_YELLOW = 0x20,
PAD_RED = 0x40,
PAD_ORANGE = 0x80,
};
// Note: My hardware's octagon stick produced the complete range of values (0 - 0x3f) // Note: My hardware's octagon stick produced the complete range of values (0 - 0x3f)
// It also had perfect center values of 0x20 with absolutely no "play". // It also had perfect center values of 0x20 with absolutely no "play".

View File

@ -57,19 +57,16 @@ public:
ControllerEmu::ControlGroup* GetGroup(GuitarGroup group); ControllerEmu::ControlGroup* GetGroup(GuitarGroup group);
enum static constexpr u16 BUTTON_PLUS = 0x04;
{ static constexpr u16 BUTTON_MINUS = 0x10;
BUTTON_PLUS = 0x04, static constexpr u16 BAR_DOWN = 0x40;
BUTTON_MINUS = 0x10,
BAR_DOWN = 0x40,
BAR_UP = 0x0100, static constexpr u16 BAR_UP = 0x0100;
FRET_YELLOW = 0x0800, static constexpr u16 FRET_YELLOW = 0x0800;
FRET_GREEN = 0x1000, static constexpr u16 FRET_GREEN = 0x1000;
FRET_BLUE = 0x2000, static constexpr u16 FRET_BLUE = 0x2000;
FRET_RED = 0x4000, static constexpr u16 FRET_RED = 0x4000;
FRET_ORANGE = 0x8000, static constexpr u16 FRET_ORANGE = 0x8000;
};
static const u8 STICK_CENTER = 0x20; static const u8 STICK_CENTER = 0x20;
static const u8 STICK_RADIUS = 0x1f; static const u8 STICK_RADIUS = 0x1f;

View File

@ -78,24 +78,15 @@ public:
ControllerEmu::ControlGroup* GetGroup(NunchukGroup group); ControllerEmu::ControlGroup* GetGroup(NunchukGroup group);
enum static constexpr u8 BUTTON_C = 0x02;
{ static constexpr u8 BUTTON_Z = 0x01;
BUTTON_C = 0x02,
BUTTON_Z = 0x01,
};
enum static constexpr u8 ACCEL_ZERO_G = 0x80;
{ static constexpr u8 ACCEL_ONE_G = 0xB3;
ACCEL_ZERO_G = 0x80,
ACCEL_ONE_G = 0xB3,
};
enum static constexpr u8 STICK_CENTER = 0x80;
{ static constexpr u8 STICK_RADIUS = 0x7F;
STICK_CENTER = 0x80, static constexpr u8 STICK_GATE_RADIUS = 0x52;
STICK_RADIUS = 0x7F,
STICK_GATE_RADIUS = 0x52,
};
void LoadDefaults(const ControllerInterface& ciface) override; void LoadDefaults(const ControllerInterface& ciface) override;

View File

@ -63,21 +63,18 @@ public:
ControllerEmu::ControlGroup* GetGroup(TurntableGroup group); ControllerEmu::ControlGroup* GetGroup(TurntableGroup group);
enum static constexpr u16 BUTTON_EUPHORIA = 0x1000;
{
BUTTON_EUPHORIA = 0x1000,
BUTTON_L_GREEN = 0x0800, static constexpr u16 BUTTON_L_GREEN = 0x0800;
BUTTON_L_RED = 0x20, static constexpr u16 BUTTON_L_RED = 0x20;
BUTTON_L_BLUE = 0x8000, static constexpr u16 BUTTON_L_BLUE = 0x8000;
BUTTON_R_GREEN = 0x2000, static constexpr u16 BUTTON_R_GREEN = 0x2000;
BUTTON_R_RED = 0x02, static constexpr u16 BUTTON_R_RED = 0x02;
BUTTON_R_BLUE = 0x0400, static constexpr u16 BUTTON_R_BLUE = 0x0400;
BUTTON_MINUS = 0x10, static constexpr u16 BUTTON_MINUS = 0x10;
BUTTON_PLUS = 0x04, static constexpr u16 BUTTON_PLUS = 0x04;
};
static constexpr int STICK_BIT_COUNT = 6; static constexpr int STICK_BIT_COUNT = 6;
static constexpr u8 STICK_CENTER = (1 << STICK_BIT_COUNT) / 2; static constexpr u8 STICK_CENTER = (1 << STICK_BIT_COUNT) / 2;

View File

@ -83,27 +83,21 @@ void UpdateCalibrationDataChecksum(T& data, int cksum_bytes)
class Wiimote : public ControllerEmu::EmulatedController class Wiimote : public ControllerEmu::EmulatedController
{ {
public: public:
enum : u8 static constexpr u8 ACCEL_ZERO_G = 0x80;
{ static constexpr u8 ACCEL_ONE_G = 0x9A;
ACCEL_ZERO_G = 0x80,
ACCEL_ONE_G = 0x9A,
};
enum : u16 static constexpr u16 PAD_LEFT = 0x01;
{ static constexpr u16 PAD_RIGHT = 0x02;
PAD_LEFT = 0x01, static constexpr u16 PAD_DOWN = 0x04;
PAD_RIGHT = 0x02, static constexpr u16 PAD_UP = 0x08;
PAD_DOWN = 0x04, static constexpr u16 BUTTON_PLUS = 0x10;
PAD_UP = 0x08,
BUTTON_PLUS = 0x10,
BUTTON_TWO = 0x0100, static constexpr u16 BUTTON_TWO = 0x0100;
BUTTON_ONE = 0x0200, static constexpr u16 BUTTON_ONE = 0x0200;
BUTTON_B = 0x0400, static constexpr u16 BUTTON_B = 0x0400;
BUTTON_A = 0x0800, static constexpr u16 BUTTON_A = 0x0800;
BUTTON_MINUS = 0x1000, static constexpr u16 BUTTON_MINUS = 0x1000;
BUTTON_HOME = 0x8000, static constexpr u16 BUTTON_HOME = 0x8000;
};
explicit Wiimote(unsigned int index); explicit Wiimote(unsigned int index);

View File

@ -31,29 +31,20 @@ using Report = std::vector<u8>;
constexpr u32 WIIMOTE_DEFAULT_TIMEOUT = 1000; constexpr u32 WIIMOTE_DEFAULT_TIMEOUT = 1000;
// Communication channels // Communication channels
enum WiimoteChannel constexpr u8 WC_OUTPUT = 0x11;
{ constexpr u8 WC_INPUT = 0x13;
WC_OUTPUT = 0x11,
WC_INPUT = 0x13,
};
// The 4 most significant bits of the first byte of an outgoing command must be // The 4 most significant bits of the first byte of an outgoing command must be
// 0x50 if sending on the command channel and 0xA0 if sending on the interrupt // 0x50 if sending on the command channel and 0xA0 if sending on the interrupt
// channel. On Mac and Linux we use interrupt channel; on Windows, command. // channel. On Mac and Linux we use interrupt channel; on Windows, command.
enum WiimoteReport
{
#ifdef _WIN32 #ifdef _WIN32
WR_SET_REPORT = 0x50 constexpr u8 WR_SET_REPORT = 0x50;
#else #else
WR_SET_REPORT = 0xA0 constexpr u8 WR_SET_REPORT = 0xA0;
#endif #endif
};
enum WiimoteBT constexpr u8 BT_INPUT = 0x01;
{ constexpr u8 BT_OUTPUT = 0x02;
BT_INPUT = 0x01,
BT_OUTPUT = 0x02
};
class Wiimote class Wiimote
{ {